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