Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB | |
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 | * Contributors: | |
9 | * | |
10 | * Balasko, Jeno | |
11 | * Baranyi, Botond | |
12 | * Beres, Szabolcs | |
13 | * Delic, Adam | |
14 | * Forstner, Matyas | |
15 | * Kovacs, Ferenc | |
16 | * Raduly, Csaba | |
17 | * Szabados, Kristof | |
18 | * Szabo, Bence Janos | |
19 | * Szabo, Janos Zoltan – initial implementation | |
20 | * Szalai, Gabor | |
21 | * Tatarka, Gabor | |
22 | * | |
23 | ******************************************************************************/ | |
970ed795 EL |
24 | #ifndef HEXSTRING_HH |
25 | #define HEXSTRING_HH | |
26 | ||
27 | #include "Basetype.hh" | |
28 | #include "Template.hh" | |
29 | #include "Optional.hh" | |
30 | #include "Error.hh" | |
31 | ||
32 | class INTEGER; | |
33 | class BITSTRING; | |
34 | class OCTETSTRING; | |
35 | class CHARSTRING; | |
36 | class HEXSTRING_ELEMENT; | |
37 | ||
38 | class Module_Param; | |
39 | ||
40 | class HEXSTRING : public Base_Type { | |
41 | ||
42 | friend class HEXSTRING_ELEMENT; | |
43 | friend class HEXSTRING_template; | |
44 | ||
45 | friend HEXSTRING bit2hex(const BITSTRING& value); | |
46 | friend HEXSTRING int2hex(const INTEGER& value, int length); | |
47 | friend HEXSTRING oct2hex(const OCTETSTRING& value); | |
48 | friend HEXSTRING str2hex(const CHARSTRING& value); | |
49 | friend HEXSTRING substr(const HEXSTRING& value, int index, int returncount); | |
50 | friend HEXSTRING replace(const HEXSTRING& value, int index, int len, const HEXSTRING& repl); | |
51 | ||
52 | struct hexstring_struct; | |
53 | hexstring_struct *val_ptr; | |
54 | ||
55 | void init_struct(int n_nibbles); | |
56 | unsigned char get_nibble(int nibble_index) const; | |
57 | void set_nibble(int nibble_index, unsigned char new_value); | |
58 | void copy_value(); | |
59 | void clear_unused_nibble() const; | |
60 | HEXSTRING(int n_nibbles); | |
61 | ||
62 | public: | |
63 | HEXSTRING(); | |
64 | HEXSTRING(int init_n_nibbles, const unsigned char* init_nibbles); | |
65 | HEXSTRING(const HEXSTRING& other_value); | |
66 | HEXSTRING(const HEXSTRING_ELEMENT& other_value); | |
67 | ~HEXSTRING(); | |
68 | void clean_up(); | |
69 | ||
70 | HEXSTRING& operator=(const HEXSTRING& other_value); | |
71 | HEXSTRING& operator=(const HEXSTRING_ELEMENT& other_value); | |
72 | ||
73 | boolean operator==(const HEXSTRING& other_value) const; | |
74 | boolean operator==(const HEXSTRING_ELEMENT& other_value) const; | |
75 | ||
76 | inline boolean operator!=(const HEXSTRING& other_value) const | |
77 | { return !(*this == other_value); } | |
78 | inline boolean operator!=(const HEXSTRING_ELEMENT& other_value) const | |
79 | { return !(*this == other_value); } | |
80 | ||
81 | HEXSTRING operator+(const HEXSTRING& other_value) const; | |
82 | HEXSTRING operator+(const HEXSTRING_ELEMENT& other_value) const; | |
83 | ||
84 | HEXSTRING operator~() const; | |
85 | HEXSTRING operator&(const HEXSTRING& other_value) const; | |
86 | HEXSTRING operator&(const HEXSTRING_ELEMENT& other_value) const; | |
87 | HEXSTRING operator|(const HEXSTRING& other_value) const; | |
88 | HEXSTRING operator|(const HEXSTRING_ELEMENT& other_value) const; | |
89 | HEXSTRING operator^(const HEXSTRING& other_value) const; | |
90 | HEXSTRING operator^(const HEXSTRING_ELEMENT& other_value) const; | |
91 | ||
92 | HEXSTRING operator<<(int shift_count) const; | |
93 | HEXSTRING operator<<(const INTEGER& shift_count) const; | |
94 | HEXSTRING operator>>(int shift_count) const; | |
95 | HEXSTRING operator>>(const INTEGER& shift_count) const; | |
96 | HEXSTRING operator<<=(int rotate_count) const; | |
97 | HEXSTRING operator<<=(const INTEGER& rotate_count) const; | |
98 | HEXSTRING operator>>=(int rotate_count) const; | |
99 | HEXSTRING operator>>=(const INTEGER& rotate_count) const; | |
100 | ||
101 | HEXSTRING_ELEMENT operator[](int index_value); | |
102 | HEXSTRING_ELEMENT operator[](const INTEGER& index_value); | |
103 | const HEXSTRING_ELEMENT operator[](int index_value) const; | |
104 | const HEXSTRING_ELEMENT operator[](const INTEGER& index_value) const; | |
105 | ||
106 | inline boolean is_bound() const { return val_ptr != NULL; } | |
107 | inline boolean is_value() const { return val_ptr != NULL; } | |
108 | inline void must_bound(const char *err_msg) const | |
109 | { if (val_ptr == NULL) TTCN_error("%s", err_msg); } | |
110 | ||
111 | int lengthof() const; | |
112 | ||
113 | operator const unsigned char*() const; | |
114 | ||
115 | #ifdef TITAN_RUNTIME_2 | |
116 | boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const HEXSTRING*>(other_value)); } | |
117 | void set_value(const Base_Type* other_value) { *this = *(static_cast<const HEXSTRING*>(other_value)); } | |
118 | Base_Type* clone() const { return new HEXSTRING(*this); } | |
119 | const TTCN_Typedescriptor_t* get_descriptor() const { return &HEXSTRING_descr_; } | |
120 | #else | |
121 | inline boolean is_present() const { return is_bound(); } | |
122 | #endif | |
123 | ||
124 | void log() const; | |
125 | void set_param(Module_Param& param); | |
3abe9331 | 126 | Module_Param* get_param(Module_Param_Name& param_name) const; |
127 | ||
970ed795 EL |
128 | void encode_text(Text_Buf& text_buf) const; |
129 | void decode_text(Text_Buf& text_buf); | |
130 | void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, | |
131 | TTCN_EncDec::coding_t p_coding, ...) const; | |
132 | ||
133 | void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, | |
134 | TTCN_EncDec::coding_t p_coding, ...); | |
135 | /** Encodes the value of the variable according to the | |
136 | * TTCN_Typedescriptor_t. It must be public because called by | |
137 | * another types during encoding. Returns the length of encoded data*/ | |
138 | int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const; | |
139 | /** Decodes the value of the variable according to the | |
140 | * TTCN_Typedescriptor_t. It must be public because called by | |
141 | * another types during encoding. Returns the number of decoded | |
142 | * bits. */ | |
143 | int RAW_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, int, raw_order_t, | |
144 | boolean no_err=FALSE, int sel_field=-1, boolean first_call=TRUE); | |
145 | int XER_encode(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, | |
af710487 | 146 | unsigned int flavor, int indent, embed_values_enc_struct_t*) const; |
970ed795 | 147 | int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader, |
feade998 | 148 | unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*); |
970ed795 EL |
149 | |
150 | /** Encodes accordingly to the JSON encoding rules. | |
151 | * Returns the length of the encoded data. */ | |
152 | int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const; | |
153 | ||
154 | /** Decodes accordingly to the JSON encoding rules. | |
155 | * Returns the length of the decoded data. */ | |
156 | int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean); | |
157 | }; | |
158 | ||
159 | class HEXSTRING_ELEMENT { | |
160 | boolean bound_flag; | |
161 | HEXSTRING& str_val; | |
162 | int nibble_pos; | |
163 | ||
164 | public: | |
165 | HEXSTRING_ELEMENT(boolean par_bound_flag, HEXSTRING& par_str_val, | |
166 | int par_nibble_pos); | |
167 | ||
168 | HEXSTRING_ELEMENT& operator=(const HEXSTRING& other_value); | |
169 | HEXSTRING_ELEMENT& operator=(const HEXSTRING_ELEMENT& other_value); | |
170 | ||
171 | boolean operator==(const HEXSTRING& other_value) const; | |
172 | boolean operator==(const HEXSTRING_ELEMENT& other_value) const; | |
173 | ||
174 | inline boolean operator!=(const HEXSTRING& other_value) const | |
175 | { return !(*this == other_value); } | |
176 | inline boolean operator!=(const HEXSTRING_ELEMENT& other_value) const | |
177 | { return !(*this == other_value); } | |
178 | ||
179 | HEXSTRING operator+(const HEXSTRING& other_value) const; | |
180 | HEXSTRING operator+(const HEXSTRING_ELEMENT& other_value) const; | |
181 | ||
182 | HEXSTRING operator~() const; | |
183 | HEXSTRING operator&(const HEXSTRING& other_value) const; | |
184 | HEXSTRING operator&(const HEXSTRING_ELEMENT& other_value) const; | |
185 | HEXSTRING operator|(const HEXSTRING& other_value) const; | |
186 | HEXSTRING operator|(const HEXSTRING_ELEMENT& other_value) const; | |
187 | HEXSTRING operator^(const HEXSTRING& other_value) const; | |
188 | HEXSTRING operator^(const HEXSTRING_ELEMENT& other_value) const; | |
189 | ||
190 | inline boolean is_bound() const { return bound_flag; } | |
191 | inline boolean is_present() const { return bound_flag; } | |
192 | inline boolean is_value() const { return bound_flag; } | |
193 | inline void must_bound(const char *err_msg) const | |
194 | { if (!bound_flag) TTCN_error("%s", err_msg); } | |
195 | ||
196 | unsigned char get_nibble() const; | |
197 | ||
198 | void log() const; | |
199 | }; | |
200 | ||
201 | // hexstring template class | |
202 | ||
203 | class HEXSTRING_template : public Restricted_Length_Template { | |
204 | #ifdef __SUNPRO_CC | |
205 | public: | |
206 | #endif | |
207 | struct hexstring_pattern_struct; | |
208 | private: | |
209 | HEXSTRING single_value; | |
210 | union { | |
211 | struct { | |
212 | unsigned int n_values; | |
213 | HEXSTRING_template *list_value; | |
214 | } value_list; | |
215 | hexstring_pattern_struct *pattern_value; | |
216 | }; | |
217 | ||
218 | void copy_template(const HEXSTRING_template& other_value); | |
219 | static boolean match_pattern(const hexstring_pattern_struct *string_pattern, | |
220 | const HEXSTRING::hexstring_struct *string_value); | |
221 | ||
222 | public: | |
223 | HEXSTRING_template(); | |
224 | HEXSTRING_template(template_sel other_value); | |
225 | HEXSTRING_template(const HEXSTRING& other_value); | |
226 | HEXSTRING_template(const HEXSTRING_ELEMENT& other_value); | |
227 | HEXSTRING_template(const OPTIONAL<HEXSTRING>& other_value); | |
228 | HEXSTRING_template(unsigned int n_elements, | |
229 | const unsigned char *pattern_elements); | |
230 | HEXSTRING_template(const HEXSTRING_template& other_value); | |
231 | ~HEXSTRING_template(); | |
232 | void clean_up(); | |
233 | ||
234 | HEXSTRING_template& operator=(template_sel other_value); | |
235 | HEXSTRING_template& operator=(const HEXSTRING& other_value); | |
236 | HEXSTRING_template& operator=(const HEXSTRING_ELEMENT& other_value); | |
237 | HEXSTRING_template& operator=(const OPTIONAL<HEXSTRING>& other_value); | |
238 | HEXSTRING_template& operator=(const HEXSTRING_template& other_value); | |
239 | ||
240 | HEXSTRING_ELEMENT operator[](int index_value); | |
241 | HEXSTRING_ELEMENT operator[](const INTEGER& index_value); | |
242 | const HEXSTRING_ELEMENT operator[](int index_value) const; | |
243 | const HEXSTRING_ELEMENT operator[](const INTEGER& index_value) const; | |
244 | ||
3abe9331 | 245 | boolean match(const HEXSTRING& other_value, boolean legacy = FALSE) const; |
970ed795 EL |
246 | const HEXSTRING& valueof() const; |
247 | ||
248 | int lengthof() const; | |
249 | ||
250 | void set_type(template_sel template_type, unsigned int list_length); | |
251 | HEXSTRING_template& list_item(unsigned int list_index); | |
252 | ||
253 | void log() const; | |
3abe9331 | 254 | void log_match(const HEXSTRING& match_value, boolean legacy = FALSE) const; |
970ed795 EL |
255 | |
256 | void set_param(Module_Param& param); | |
3abe9331 | 257 | Module_Param* get_param(Module_Param_Name& param_name) const; |
970ed795 EL |
258 | |
259 | void encode_text(Text_Buf& text_buf) const; | |
260 | void decode_text(Text_Buf& text_buf); | |
261 | ||
3abe9331 | 262 | boolean is_present(boolean legacy = FALSE) const; |
263 | boolean match_omit(boolean legacy = FALSE) const; | |
970ed795 EL |
264 | #ifdef TITAN_RUNTIME_2 |
265 | void valueofv(Base_Type* value) const { *(static_cast<HEXSTRING*>(value)) = valueof(); } | |
266 | void set_value(template_sel other_value) { *this = other_value; } | |
267 | void copy_value(const Base_Type* other_value) { *this = *(static_cast<const HEXSTRING*>(other_value)); } | |
268 | Base_Template* clone() const { return new HEXSTRING_template(*this); } | |
269 | const TTCN_Typedescriptor_t* get_descriptor() const { return &HEXSTRING_descr_; } | |
3abe9331 | 270 | boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const HEXSTRING*>(other_value)), legacy); } |
271 | void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const HEXSTRING*>(match_value)), legacy); } | |
970ed795 | 272 | #else |
3abe9331 | 273 | void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const; |
970ed795 EL |
274 | #endif |
275 | }; | |
276 | ||
277 | #endif |