Sync with 5.4.1
[deliverable/titan.core.git] / core / Octetstring.hh
CommitLineData
970ed795 1///////////////////////////////////////////////////////////////////////////////
3abe9331 2// Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
3// All rights reserved. This program and the accompanying materials
4// are made available under the terms of the Eclipse Public License v1.0
5// which accompanies this distribution, and is available at
6// http://www.eclipse.org/legal/epl-v10.html
7///////////////////////////////////////////////////////////////////////////////
8#ifndef OCTETSTRING_HH
9#define OCTETSTRING_HH
10
11#include "Basetype.hh"
12#include "Template.hh"
13#include "Optional.hh"
14#include "Error.hh"
15
16class INTEGER;
17class BITSTRING;
18class HEXSTRING;
19class CHARSTRING;
20class OCTETSTRING_ELEMENT;
21class Module_Param;
22
23// octetstring value class
24
25class OCTETSTRING : public Base_Type {
26
27 friend class OCTETSTRING_ELEMENT;
28 friend class OCTETSTRING_template;
29 friend class TTCN_Buffer;
30
31 friend OCTETSTRING int2oct(int value, int length);
32 friend OCTETSTRING int2oct(const INTEGER& value, int length);
33 friend OCTETSTRING str2oct(const CHARSTRING& value);
34 friend OCTETSTRING bit2oct(const BITSTRING& value);
35 friend OCTETSTRING hex2oct(const HEXSTRING& value);
36 friend OCTETSTRING unichar2oct(const UNIVERSAL_CHARSTRING& invalue);
37 friend OCTETSTRING unichar2oct(const UNIVERSAL_CHARSTRING& invalue, const CHARSTRING& string_encoding);
38 friend OCTETSTRING replace(const OCTETSTRING& value, int index, int len,
39 const OCTETSTRING& repl);
40
41protected: // for ASN_ANY which is derived from OCTETSTRING
42 struct octetstring_struct;
43 octetstring_struct *val_ptr;
44
45 void init_struct(int n_octets);
46 void copy_value();
47 OCTETSTRING(int n_octets);
48
49public:
50 OCTETSTRING();
51 OCTETSTRING(int n_octets, const unsigned char* octets_ptr);
52 OCTETSTRING(const OCTETSTRING_ELEMENT& other_value);
53 OCTETSTRING(const OCTETSTRING& other_value);
54 ~OCTETSTRING();
55
56 OCTETSTRING& operator=(const OCTETSTRING& other_value);
57 OCTETSTRING& operator=(const OCTETSTRING_ELEMENT& other_value);
58
59 boolean operator==(const OCTETSTRING& other_value) const;
60 boolean operator==(const OCTETSTRING_ELEMENT& other_value) const;
61
62 inline boolean operator!=(const OCTETSTRING& other_value) const
63 { return !(*this == other_value); }
64 inline boolean operator!=(const OCTETSTRING_ELEMENT& other_value) const
65 { return !(*this == other_value); }
66
67 OCTETSTRING operator+(const OCTETSTRING& other_value) const;
68 OCTETSTRING operator+(const OCTETSTRING_ELEMENT& other_value) const;
69
70 OCTETSTRING& operator+=(const OCTETSTRING& other_value);
71 OCTETSTRING& operator+=(const OCTETSTRING_ELEMENT& other_value);
72
73 OCTETSTRING operator~() const;
74 OCTETSTRING operator&(const OCTETSTRING& other_value) const;
75 OCTETSTRING operator&(const OCTETSTRING_ELEMENT& other_value) const;
76 OCTETSTRING operator|(const OCTETSTRING& other_value) const;
77 OCTETSTRING operator|(const OCTETSTRING_ELEMENT& other_value) const;
78 OCTETSTRING operator^(const OCTETSTRING& other_value) const;
79 OCTETSTRING operator^(const OCTETSTRING_ELEMENT& other_value) const;
80
81 OCTETSTRING operator<<(int shift_count) const;
82 OCTETSTRING operator<<(const INTEGER& shift_count) const;
83 OCTETSTRING operator>>(int shift_count) const;
84 OCTETSTRING operator>>(const INTEGER& shift_count) const;
85 OCTETSTRING operator<<=(int rotate_count) const;
86 OCTETSTRING operator<<=(const INTEGER& rotate_count) const;
87 OCTETSTRING operator>>=(int rotate_count) const;
88 OCTETSTRING operator>>=(const INTEGER& rotate_count) const;
89
90 OCTETSTRING_ELEMENT operator[](int index_value);
91 OCTETSTRING_ELEMENT operator[](const INTEGER& index_value);
92 const OCTETSTRING_ELEMENT operator[](int index_value) const;
93 const OCTETSTRING_ELEMENT operator[](const INTEGER& index_value) const;
94
95 inline boolean is_bound() const { return val_ptr != NULL; }
96 inline boolean is_value() const { return val_ptr != NULL; }
97 inline void must_bound(const char *err_msg) const
98 { if (val_ptr == NULL) TTCN_error("%s", err_msg); }
99 void clean_up();
100
101 int lengthof() const;
102 operator const unsigned char*() const;
103 void dump () const;
104
105#ifdef TITAN_RUNTIME_2
106 boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const OCTETSTRING*>(other_value)); }
107 void set_value(const Base_Type* other_value) { *this = *(static_cast<const OCTETSTRING*>(other_value)); }
108 Base_Type* clone() const { return new OCTETSTRING(*this); }
109 const TTCN_Typedescriptor_t* get_descriptor() const { return &OCTETSTRING_descr_; }
110#else
111 inline boolean is_present() const { return is_bound(); }
112#endif
113
114 void log() const;
115 void set_param(Module_Param& param);
3abe9331 116 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
117
118 void encode_text(Text_Buf& text_buf) const;
119 void decode_text(Text_Buf& text_buf);
120
121public:
122 void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
123 TTCN_EncDec::coding_t p_coding, ...) const;
124
125 void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
126 TTCN_EncDec::coding_t p_coding, ...);
127
128 ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td,
129 unsigned p_coding) const;
130#ifdef TITAN_RUNTIME_2
131 ASN_BER_TLV_t* BER_encode_negtest_raw() const;
132 virtual int encode_raw(TTCN_Buffer& p_buf) const;
133 virtual int RAW_encode_negtest_raw(RAW_enc_tree& p_myleaf) const;
134#endif
135 boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td,
136 const ASN_BER_TLV_t& p_tlv, unsigned L_form);
137
138 /** Encodes the value of the variable according to the
139 * TTCN_Typedescriptor_t. It must be public because called by
140 * another types during encoding. Returns the length of encoded data*/
141 int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const;
142 /** Decodes the value of the variable according to the
143 * TTCN_Typedescriptor_t. It must be public because called by
144 * another types during encoding. Returns the number of decoded
145 * bits. */
146 int RAW_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer& buff, int limit,
147 raw_order_t top_bit_ord, boolean no_err=FALSE,
148 int sel_field=-1, boolean first_call=TRUE);
149 int TEXT_encode(const TTCN_Typedescriptor_t&,
150 TTCN_Buffer&) const;
151 int TEXT_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, Limit_Token_List&,
152 boolean no_err=FALSE, boolean first_call=TRUE);
153 int XER_encode(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf,
af710487 154 unsigned int flavor, int indent, embed_values_enc_struct_t*) const;
970ed795 155 int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
af710487 156 unsigned int flavor, embed_values_dec_struct_t*);
970ed795
EL
157
158 /** Encodes accordingly to the JSON encoding rules.
159 * Returns the length of the encoded data. */
160 int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const;
161
162 /** Decodes accordingly to the JSON encoding rules.
163 * Returns the length of the decoded data. */
164 int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean);
165};
166
167
168class OCTETSTRING_ELEMENT {
169 boolean bound_flag;
170 OCTETSTRING& str_val;
171 int octet_pos;
172
173public:
174 OCTETSTRING_ELEMENT(boolean par_bound_flag, OCTETSTRING& par_str_val,
175 int par_octet_pos);
176
177 OCTETSTRING_ELEMENT& operator=(const OCTETSTRING& other_value);
178 OCTETSTRING_ELEMENT& operator=(const OCTETSTRING_ELEMENT& other_value);
179
180 boolean operator==(const OCTETSTRING& other_value) const;
181 boolean operator==(const OCTETSTRING_ELEMENT& other_value) const;
182 inline boolean operator!=(const OCTETSTRING& other_value) const
183 { return !(*this == other_value); }
184 inline boolean operator!=(const OCTETSTRING_ELEMENT& other_value) const
185 { return !(*this == other_value); }
186
187 OCTETSTRING operator+(const OCTETSTRING& other_value) const;
188 OCTETSTRING operator+(const OCTETSTRING_ELEMENT& other_value) const;
189
190 OCTETSTRING operator~() const;
191 OCTETSTRING operator&(const OCTETSTRING& other_value) const;
192 OCTETSTRING operator&(const OCTETSTRING_ELEMENT& other_value) const;
193 OCTETSTRING operator|(const OCTETSTRING& other_value) const;
194 OCTETSTRING operator|(const OCTETSTRING_ELEMENT& other_value) const;
195 OCTETSTRING operator^(const OCTETSTRING& other_value) const;
196 OCTETSTRING operator^(const OCTETSTRING_ELEMENT& other_value) const;
197
198 inline boolean is_bound() const { return bound_flag; }
199 inline boolean is_present() const { return bound_flag; }
200 inline boolean is_value() const { return bound_flag; }
201 inline void must_bound(const char *err_msg) const
202 { if (!bound_flag) TTCN_error("%s", err_msg); }
203
204 unsigned char get_octet() const;
205
206 void log() const;
207};
208
209// octetstring template class
210
211class OCTETSTRING_template : public Restricted_Length_Template {
212#ifdef __SUNPRO_CC
213public:
214#endif
215 struct octetstring_pattern_struct;
216private:
217 OCTETSTRING single_value;
218 union {
219 struct {
220 unsigned int n_values;
221 OCTETSTRING_template *list_value;
222 } value_list;
223 octetstring_pattern_struct *pattern_value;
224 };
225
226 void copy_template(const OCTETSTRING_template& other_value);
227 static boolean match_pattern(const octetstring_pattern_struct *string_pattern,
228 const OCTETSTRING::octetstring_struct *string_value);
229
230public:
231 OCTETSTRING_template();
232 OCTETSTRING_template(template_sel other_value);
233 OCTETSTRING_template(const OCTETSTRING& other_value);
234 OCTETSTRING_template(const OCTETSTRING_ELEMENT& other_value);
235 OCTETSTRING_template(const OPTIONAL<OCTETSTRING>& other_value);
236 OCTETSTRING_template(unsigned int n_elements,
237 const unsigned short *pattern_elements);
238 OCTETSTRING_template(const OCTETSTRING_template& other_value);
239 ~OCTETSTRING_template();
240 void clean_up();
241
242 OCTETSTRING_template& operator=(template_sel other_value);
243 OCTETSTRING_template& operator=(const OCTETSTRING& other_value);
244 OCTETSTRING_template& operator=(const OCTETSTRING_ELEMENT& other_value);
245 OCTETSTRING_template& operator=(const OPTIONAL<OCTETSTRING>& other_value);
246 OCTETSTRING_template& operator=(const OCTETSTRING_template& other_value);
247
248 OCTETSTRING_ELEMENT operator[](int index_value);
249 OCTETSTRING_ELEMENT operator[](const INTEGER& index_value);
250 const OCTETSTRING_ELEMENT operator[](int index_value) const;
251 const OCTETSTRING_ELEMENT operator[](const INTEGER& index_value) const;
252
3abe9331 253 boolean match(const OCTETSTRING& other_value, boolean legacy = FALSE) const;
970ed795
EL
254 const OCTETSTRING& valueof() const;
255
256 int lengthof() const;
257
258 void set_type(template_sel template_type, unsigned int list_length);
259 OCTETSTRING_template& list_item(unsigned int list_index);
260
261 void log() const;
3abe9331 262 void log_match(const OCTETSTRING& match_value, boolean legacy = FALSE) const;
970ed795
EL
263
264 void set_param(Module_Param& param);
3abe9331 265 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
266
267 void encode_text(Text_Buf& text_buf) const;
268 void decode_text(Text_Buf& text_buf);
269
3abe9331 270 boolean is_present(boolean legacy = FALSE) const;
271 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
272#ifdef TITAN_RUNTIME_2
273 void valueofv(Base_Type* value) const { *(static_cast<OCTETSTRING*>(value)) = valueof(); }
274 void set_value(template_sel other_value) { *this = other_value; }
275 void copy_value(const Base_Type* other_value) { *this = *(static_cast<const OCTETSTRING*>(other_value)); }
276 Base_Template* clone() const { return new OCTETSTRING_template(*this); }
277 const TTCN_Typedescriptor_t* get_descriptor() const { return &OCTETSTRING_descr_; }
3abe9331 278 boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const OCTETSTRING*>(other_value)), legacy); }
279 void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const OCTETSTRING*>(match_value)), legacy); }
970ed795 280#else
3abe9331 281 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
282#endif
283};
284
285#endif
This page took 0.033883 seconds and 5 git commands to generate.