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