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
19 * Szabo, Janos Zoltan – initial implementation
23 ******************************************************************************/
27 #include "Basetype.hh"
28 #include "Template.hh"
29 #include "Optional.hh"
36 class HEXSTRING_ELEMENT;
40 class HEXSTRING : public Base_Type {
42 friend class HEXSTRING_ELEMENT;
43 friend class HEXSTRING_template;
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);
52 struct hexstring_struct;
53 hexstring_struct *val_ptr;
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);
59 void clear_unused_nibble() const;
60 HEXSTRING(int n_nibbles);
64 HEXSTRING(int init_n_nibbles, const unsigned char* init_nibbles);
65 HEXSTRING(const HEXSTRING& other_value);
66 HEXSTRING(const HEXSTRING_ELEMENT& other_value);
70 HEXSTRING& operator=(const HEXSTRING& other_value);
71 HEXSTRING& operator=(const HEXSTRING_ELEMENT& other_value);
73 boolean operator==(const HEXSTRING& other_value) const;
74 boolean operator==(const HEXSTRING_ELEMENT& other_value) const;
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); }
81 HEXSTRING operator+(const HEXSTRING& other_value) const;
82 HEXSTRING operator+(const HEXSTRING_ELEMENT& other_value) const;
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;
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;
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;
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); }
111 int lengthof() const;
113 operator const unsigned char*() const;
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_; }
121 inline boolean is_present() const { return is_bound(); }
125 void set_param(Module_Param& param);
126 Module_Param* get_param(Module_Param_Name& param_name) const;
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;
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
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,
146 unsigned int flavor, int indent, embed_values_enc_struct_t*) const;
147 int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
148 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*);
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;
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);
159 class HEXSTRING_ELEMENT {
165 HEXSTRING_ELEMENT(boolean par_bound_flag, HEXSTRING& par_str_val,
168 HEXSTRING_ELEMENT& operator=(const HEXSTRING& other_value);
169 HEXSTRING_ELEMENT& operator=(const HEXSTRING_ELEMENT& other_value);
171 boolean operator==(const HEXSTRING& other_value) const;
172 boolean operator==(const HEXSTRING_ELEMENT& other_value) const;
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); }
179 HEXSTRING operator+(const HEXSTRING& other_value) const;
180 HEXSTRING operator+(const HEXSTRING_ELEMENT& other_value) const;
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;
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); }
196 unsigned char get_nibble() const;
201 // hexstring template class
203 class HEXSTRING_template : public Restricted_Length_Template {
207 struct hexstring_pattern_struct;
209 HEXSTRING single_value;
212 unsigned int n_values;
213 HEXSTRING_template *list_value;
215 hexstring_pattern_struct *pattern_value;
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);
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();
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);
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;
245 boolean match(const HEXSTRING& other_value, boolean legacy = FALSE) const;
246 const HEXSTRING& valueof() const;
248 int lengthof() const;
250 void set_type(template_sel template_type, unsigned int list_length);
251 HEXSTRING_template& list_item(unsigned int list_index);
254 void log_match(const HEXSTRING& match_value, boolean legacy = FALSE) const;
256 void set_param(Module_Param& param);
257 Module_Param* get_param(Module_Param_Name& param_name) const;
259 void encode_text(Text_Buf& text_buf) const;
260 void decode_text(Text_Buf& text_buf);
262 boolean is_present(boolean legacy = FALSE) const;
263 boolean match_omit(boolean legacy = FALSE) const;
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_; }
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); }
273 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;