Sync with 5.4.3
[deliverable/titan.core.git] / core / Hexstring.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 HEXSTRING_HH
9#define HEXSTRING_HH
10
11#include "Basetype.hh"
12#include "Template.hh"
13#include "Optional.hh"
14#include "Error.hh"
15
16class INTEGER;
17class BITSTRING;
18class OCTETSTRING;
19class CHARSTRING;
20class HEXSTRING_ELEMENT;
21
22class Module_Param;
23
24class 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
46public:
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);
3abe9331 110 Module_Param* get_param(Module_Param_Name& param_name) const;
111
970ed795
EL
112 void encode_text(Text_Buf& text_buf) const;
113 void decode_text(Text_Buf& text_buf);
114 void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
115 TTCN_EncDec::coding_t p_coding, ...) const;
116
117 void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
118 TTCN_EncDec::coding_t p_coding, ...);
119 /** Encodes the value of the variable according to the
120 * TTCN_Typedescriptor_t. It must be public because called by
121 * another types during encoding. Returns the length of encoded data*/
122 int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const;
123 /** Decodes the value of the variable according to the
124 * TTCN_Typedescriptor_t. It must be public because called by
125 * another types during encoding. Returns the number of decoded
126 * bits. */
127 int RAW_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, int, raw_order_t,
128 boolean no_err=FALSE, int sel_field=-1, boolean first_call=TRUE);
129 int XER_encode(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf,
af710487 130 unsigned int flavor, int indent, embed_values_enc_struct_t*) const;
970ed795 131 int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
feade998 132 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*);
970ed795
EL
133
134 /** Encodes accordingly to the JSON encoding rules.
135 * Returns the length of the encoded data. */
136 int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const;
137
138 /** Decodes accordingly to the JSON encoding rules.
139 * Returns the length of the decoded data. */
140 int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean);
141};
142
143class HEXSTRING_ELEMENT {
144 boolean bound_flag;
145 HEXSTRING& str_val;
146 int nibble_pos;
147
148public:
149 HEXSTRING_ELEMENT(boolean par_bound_flag, HEXSTRING& par_str_val,
150 int par_nibble_pos);
151
152 HEXSTRING_ELEMENT& operator=(const HEXSTRING& other_value);
153 HEXSTRING_ELEMENT& operator=(const HEXSTRING_ELEMENT& other_value);
154
155 boolean operator==(const HEXSTRING& other_value) const;
156 boolean operator==(const HEXSTRING_ELEMENT& other_value) const;
157
158 inline boolean operator!=(const HEXSTRING& other_value) const
159 { return !(*this == other_value); }
160 inline boolean operator!=(const HEXSTRING_ELEMENT& other_value) const
161 { return !(*this == other_value); }
162
163 HEXSTRING operator+(const HEXSTRING& other_value) const;
164 HEXSTRING operator+(const HEXSTRING_ELEMENT& other_value) const;
165
166 HEXSTRING operator~() 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 HEXSTRING operator^(const HEXSTRING& other_value) const;
172 HEXSTRING operator^(const HEXSTRING_ELEMENT& other_value) const;
173
174 inline boolean is_bound() const { return bound_flag; }
175 inline boolean is_present() const { return bound_flag; }
176 inline boolean is_value() const { return bound_flag; }
177 inline void must_bound(const char *err_msg) const
178 { if (!bound_flag) TTCN_error("%s", err_msg); }
179
180 unsigned char get_nibble() const;
181
182 void log() const;
183};
184
185// hexstring template class
186
187class HEXSTRING_template : public Restricted_Length_Template {
188#ifdef __SUNPRO_CC
189public:
190#endif
191 struct hexstring_pattern_struct;
192private:
193 HEXSTRING single_value;
194 union {
195 struct {
196 unsigned int n_values;
197 HEXSTRING_template *list_value;
198 } value_list;
199 hexstring_pattern_struct *pattern_value;
200 };
201
202 void copy_template(const HEXSTRING_template& other_value);
203 static boolean match_pattern(const hexstring_pattern_struct *string_pattern,
204 const HEXSTRING::hexstring_struct *string_value);
205
206public:
207 HEXSTRING_template();
208 HEXSTRING_template(template_sel other_value);
209 HEXSTRING_template(const HEXSTRING& other_value);
210 HEXSTRING_template(const HEXSTRING_ELEMENT& other_value);
211 HEXSTRING_template(const OPTIONAL<HEXSTRING>& other_value);
212 HEXSTRING_template(unsigned int n_elements,
213 const unsigned char *pattern_elements);
214 HEXSTRING_template(const HEXSTRING_template& other_value);
215 ~HEXSTRING_template();
216 void clean_up();
217
218 HEXSTRING_template& operator=(template_sel other_value);
219 HEXSTRING_template& operator=(const HEXSTRING& other_value);
220 HEXSTRING_template& operator=(const HEXSTRING_ELEMENT& other_value);
221 HEXSTRING_template& operator=(const OPTIONAL<HEXSTRING>& other_value);
222 HEXSTRING_template& operator=(const HEXSTRING_template& other_value);
223
224 HEXSTRING_ELEMENT operator[](int index_value);
225 HEXSTRING_ELEMENT operator[](const INTEGER& index_value);
226 const HEXSTRING_ELEMENT operator[](int index_value) const;
227 const HEXSTRING_ELEMENT operator[](const INTEGER& index_value) const;
228
3abe9331 229 boolean match(const HEXSTRING& other_value, boolean legacy = FALSE) const;
970ed795
EL
230 const HEXSTRING& valueof() const;
231
232 int lengthof() const;
233
234 void set_type(template_sel template_type, unsigned int list_length);
235 HEXSTRING_template& list_item(unsigned int list_index);
236
237 void log() const;
3abe9331 238 void log_match(const HEXSTRING& match_value, boolean legacy = FALSE) const;
970ed795
EL
239
240 void set_param(Module_Param& param);
3abe9331 241 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
242
243 void encode_text(Text_Buf& text_buf) const;
244 void decode_text(Text_Buf& text_buf);
245
3abe9331 246 boolean is_present(boolean legacy = FALSE) const;
247 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
248#ifdef TITAN_RUNTIME_2
249 void valueofv(Base_Type* value) const { *(static_cast<HEXSTRING*>(value)) = valueof(); }
250 void set_value(template_sel other_value) { *this = other_value; }
251 void copy_value(const Base_Type* other_value) { *this = *(static_cast<const HEXSTRING*>(other_value)); }
252 Base_Template* clone() const { return new HEXSTRING_template(*this); }
253 const TTCN_Typedescriptor_t* get_descriptor() const { return &HEXSTRING_descr_; }
3abe9331 254 boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const HEXSTRING*>(other_value)), legacy); }
255 void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const HEXSTRING*>(match_value)), legacy); }
970ed795 256#else
3abe9331 257 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
258#endif
259};
260
261#endif
This page took 0.033596 seconds and 5 git commands to generate.