Sync with 5.4.3
[deliverable/titan.core.git] / core / Octetstring.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 OCTETSTRING_HH
9#define OCTETSTRING_HH
10
11#include "Basetype.hh"
12#include "Template.hh"
13#include "Optional.hh"
14#include "Error.hh"
15
16class INTEGER;
17class BITSTRING;
18class HEXSTRING;
19class CHARSTRING;
20class OCTETSTRING_ELEMENT;
21class Module_Param;
22
23// octetstring value class
24
25class 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
41protected: // 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
49public:
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);
3abe9331 116 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
117
118 void encode_text(Text_Buf& text_buf) const;
119 void decode_text(Text_Buf& text_buf);
120
121public:
122 void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
123 TTCN_EncDec::coding_t p_coding, ...) const;
124
125 void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
126 TTCN_EncDec::coding_t p_coding, ...);
127
128 ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td,
129 unsigned p_coding) const;
130#ifdef TITAN_RUNTIME_2
131 ASN_BER_TLV_t* BER_encode_negtest_raw() const;
132 virtual int encode_raw(TTCN_Buffer& p_buf) const;
133 virtual int RAW_encode_negtest_raw(RAW_enc_tree& p_myleaf) const;
3f84031e 134 /** Adds this octetstring to the end of a JSON buffer as raw data.
135 * Used during the negative testing of the JSON encoder.
136 * @return The number of bytes added. */
137 int JSON_encode_negtest_raw(JSON_Tokenizer&) const;
970ed795
EL
138#endif
139 boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td,
140 const ASN_BER_TLV_t& p_tlv, unsigned L_form);
141
142 /** Encodes the value of the variable according to the
143 * TTCN_Typedescriptor_t. It must be public because called by
144 * another types during encoding. Returns the length of encoded data*/
145 int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const;
146 /** Decodes the value of the variable according to the
147 * TTCN_Typedescriptor_t. It must be public because called by
148 * another types during encoding. Returns the number of decoded
149 * bits. */
150 int RAW_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer& buff, int limit,
151 raw_order_t top_bit_ord, boolean no_err=FALSE,
152 int sel_field=-1, boolean first_call=TRUE);
153 int TEXT_encode(const TTCN_Typedescriptor_t&,
154 TTCN_Buffer&) const;
155 int TEXT_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, Limit_Token_List&,
156 boolean no_err=FALSE, boolean first_call=TRUE);
157 int XER_encode(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf,
af710487 158 unsigned int flavor, int indent, embed_values_enc_struct_t*) const;
970ed795 159 int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
feade998 160 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*);
970ed795
EL
161
162 /** Encodes accordingly to the JSON encoding rules.
163 * Returns the length of the encoded data. */
164 int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const;
165
166 /** Decodes accordingly to the JSON encoding rules.
167 * Returns the length of the decoded data. */
168 int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean);
169};
170
171
172class OCTETSTRING_ELEMENT {
173 boolean bound_flag;
174 OCTETSTRING& str_val;
175 int octet_pos;
176
177public:
178 OCTETSTRING_ELEMENT(boolean par_bound_flag, OCTETSTRING& par_str_val,
179 int par_octet_pos);
180
181 OCTETSTRING_ELEMENT& operator=(const OCTETSTRING& other_value);
182 OCTETSTRING_ELEMENT& operator=(const OCTETSTRING_ELEMENT& other_value);
183
184 boolean operator==(const OCTETSTRING& other_value) const;
185 boolean operator==(const OCTETSTRING_ELEMENT& other_value) const;
186 inline boolean operator!=(const OCTETSTRING& other_value) const
187 { return !(*this == other_value); }
188 inline boolean operator!=(const OCTETSTRING_ELEMENT& other_value) const
189 { return !(*this == other_value); }
190
191 OCTETSTRING operator+(const OCTETSTRING& other_value) const;
192 OCTETSTRING operator+(const OCTETSTRING_ELEMENT& other_value) const;
193
194 OCTETSTRING operator~() const;
195 OCTETSTRING operator&(const OCTETSTRING& other_value) const;
196 OCTETSTRING operator&(const OCTETSTRING_ELEMENT& other_value) const;
197 OCTETSTRING operator|(const OCTETSTRING& other_value) const;
198 OCTETSTRING operator|(const OCTETSTRING_ELEMENT& other_value) const;
199 OCTETSTRING operator^(const OCTETSTRING& other_value) const;
200 OCTETSTRING operator^(const OCTETSTRING_ELEMENT& other_value) const;
201
202 inline boolean is_bound() const { return bound_flag; }
203 inline boolean is_present() const { return bound_flag; }
204 inline boolean is_value() const { return bound_flag; }
205 inline void must_bound(const char *err_msg) const
206 { if (!bound_flag) TTCN_error("%s", err_msg); }
207
208 unsigned char get_octet() const;
209
210 void log() const;
211};
212
213// octetstring template class
214
215class OCTETSTRING_template : public Restricted_Length_Template {
216#ifdef __SUNPRO_CC
217public:
218#endif
219 struct octetstring_pattern_struct;
220private:
221 OCTETSTRING single_value;
222 union {
223 struct {
224 unsigned int n_values;
225 OCTETSTRING_template *list_value;
226 } value_list;
227 octetstring_pattern_struct *pattern_value;
228 };
229
230 void copy_template(const OCTETSTRING_template& other_value);
231 static boolean match_pattern(const octetstring_pattern_struct *string_pattern,
232 const OCTETSTRING::octetstring_struct *string_value);
233
234public:
235 OCTETSTRING_template();
236 OCTETSTRING_template(template_sel other_value);
237 OCTETSTRING_template(const OCTETSTRING& other_value);
238 OCTETSTRING_template(const OCTETSTRING_ELEMENT& other_value);
239 OCTETSTRING_template(const OPTIONAL<OCTETSTRING>& other_value);
240 OCTETSTRING_template(unsigned int n_elements,
241 const unsigned short *pattern_elements);
242 OCTETSTRING_template(const OCTETSTRING_template& other_value);
243 ~OCTETSTRING_template();
244 void clean_up();
245
246 OCTETSTRING_template& operator=(template_sel other_value);
247 OCTETSTRING_template& operator=(const OCTETSTRING& other_value);
248 OCTETSTRING_template& operator=(const OCTETSTRING_ELEMENT& other_value);
249 OCTETSTRING_template& operator=(const OPTIONAL<OCTETSTRING>& other_value);
250 OCTETSTRING_template& operator=(const OCTETSTRING_template& other_value);
251
252 OCTETSTRING_ELEMENT operator[](int index_value);
253 OCTETSTRING_ELEMENT operator[](const INTEGER& index_value);
254 const OCTETSTRING_ELEMENT operator[](int index_value) const;
255 const OCTETSTRING_ELEMENT operator[](const INTEGER& index_value) const;
256
3abe9331 257 boolean match(const OCTETSTRING& other_value, boolean legacy = FALSE) const;
970ed795
EL
258 const OCTETSTRING& valueof() const;
259
260 int lengthof() const;
261
262 void set_type(template_sel template_type, unsigned int list_length);
263 OCTETSTRING_template& list_item(unsigned int list_index);
264
265 void log() const;
3abe9331 266 void log_match(const OCTETSTRING& match_value, boolean legacy = FALSE) const;
970ed795
EL
267
268 void set_param(Module_Param& param);
3abe9331 269 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
270
271 void encode_text(Text_Buf& text_buf) const;
272 void decode_text(Text_Buf& text_buf);
273
3abe9331 274 boolean is_present(boolean legacy = FALSE) const;
275 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
276#ifdef TITAN_RUNTIME_2
277 void valueofv(Base_Type* value) const { *(static_cast<OCTETSTRING*>(value)) = valueof(); }
278 void set_value(template_sel other_value) { *this = other_value; }
279 void copy_value(const Base_Type* other_value) { *this = *(static_cast<const OCTETSTRING*>(other_value)); }
280 Base_Template* clone() const { return new OCTETSTRING_template(*this); }
281 const TTCN_Typedescriptor_t* get_descriptor() const { return &OCTETSTRING_descr_; }
3abe9331 282 boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const OCTETSTRING*>(other_value)), legacy); }
283 void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const OCTETSTRING*>(match_value)), legacy); }
970ed795 284#else
3abe9331 285 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
286#endif
287};
288
289#endif
This page took 0.033661 seconds and 5 git commands to generate.