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