Commit | Line | Data |
---|---|---|
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 BASETYPE_HH | |
9 | #define BASETYPE_HH | |
10 | ||
11 | #include "Types.h" | |
12 | #include "Encdec.hh" | |
13 | #include "RInt.hh" | |
14 | #include "JSON_Tokenizer.hh" | |
970ed795 EL |
15 | #ifdef TITAN_RUNTIME_2 |
16 | #include "Struct_of.hh" | |
af710487 | 17 | #include "XER.hh" |
a38c6d4c | 18 | #include "Vector.hh" |
19 | #include "RefdIndex.hh" | |
970ed795 EL |
20 | #endif |
21 | ||
22 | struct ASN_BERdescriptor_t; | |
23 | struct ASN_BER_TLV_t; | |
24 | struct TTCN_RAWdescriptor_t; | |
25 | struct TTCN_TEXTdescriptor_t; | |
26 | struct XERdescriptor_t; | |
27 | struct TTCN_JSONdescriptor_t; | |
28 | class XmlReaderWrap; | |
29 | class Module_Param; | |
3abe9331 | 30 | class Module_Param_Name; |
af710487 | 31 | struct embed_values_enc_struct_t; |
32 | struct embed_values_dec_struct_t; | |
970ed795 EL |
33 | |
34 | /** @brief Type descriptor | |
35 | * | |
36 | * There is one type descriptor object for each type. | |
37 | * Descriptors for built-in types are supplied by the runtime. | |
38 | * Descriptors for user-defined types are written by the compiler | |
39 | * in the generated code. | |
40 | */ | |
41 | struct TTCN_Typedescriptor_t { | |
42 | const char * const name; /**< Name of the type, e.g INTEGER, REAL, verdicttype, etc */ | |
43 | const ASN_BERdescriptor_t * const ber; /**< Information for BER coding */ | |
44 | const TTCN_RAWdescriptor_t * const raw; /**< Information for RAW coding */ | |
45 | const TTCN_TEXTdescriptor_t * const text; /**< Information for TEXT coding */ | |
46 | const XERdescriptor_t * const xer; /**< Information for XER */ | |
47 | const TTCN_JSONdescriptor_t * const json; /**< Information for JSON coding */ | |
a38c6d4c | 48 | const TTCN_Typedescriptor_t * const oftype_descr; /**< Record-of element's type descriptor */ |
970ed795 EL |
49 | /** ASN subtype |
50 | * | |
51 | * Used by classes implementing more than one ASN.1 type | |
52 | * (OBJID and UNIVERSAL_CHARSTRING). | |
53 | */ | |
54 | enum { | |
55 | DONTCARE, | |
56 | UNIVERSALSTRING, BMPSTRING, UTF8STRING, | |
57 | TELETEXSTRING, VIDEOTEXSTRING, GRAPHICSTRING, GENERALSTRING, | |
58 | OBJID, ROID | |
59 | } const asnbasetype; | |
60 | }; | |
61 | ||
62 | #ifdef TITAN_RUNTIME_2 | |
63 | ||
64 | struct Erroneous_value_t { | |
65 | const bool raw; | |
66 | const Base_Type * const errval; // NULL if `omit' | |
67 | const TTCN_Typedescriptor_t* type_descr; // NULL if `omit' or raw | |
68 | }; | |
69 | ||
70 | struct Erroneous_values_t { | |
71 | const int field_index; | |
72 | const char* field_qualifier; | |
73 | const Erroneous_value_t * const before; | |
74 | const Erroneous_value_t * const value; | |
75 | const Erroneous_value_t * const after; | |
76 | }; | |
77 | ||
78 | struct Erroneous_descriptor_t { | |
79 | const int field_index; | |
80 | const int omit_before; // -1 if none | |
81 | const char* omit_before_qualifier; // NULL if none | |
82 | const int omit_after; // -1 if none | |
83 | const char* omit_after_qualifier; // NULL if none | |
84 | const int values_size; | |
85 | const Erroneous_values_t * const values_vec; | |
86 | const int embedded_size; | |
87 | const Erroneous_descriptor_t * const embedded_vec; | |
88 | /** search in values_vec for the field with index field_idx */ | |
89 | const Erroneous_values_t* get_field_err_values(int field_idx) const; | |
90 | /** search in embedded_vec for the field with index field_idx */ | |
91 | const Erroneous_descriptor_t* get_field_emb_descr(int field_idx) const; | |
92 | /** if the current element of values_vec has index field_idx then returns it and increments values_idx */ | |
93 | const Erroneous_values_t* next_field_err_values(const int field_idx, int& values_idx) const; | |
94 | /** if the current element of embedded_vec has index field_idx then returns it and increments edescr_idx */ | |
95 | const Erroneous_descriptor_t* next_field_emb_descr(const int field_idx, int& edescr_idx) const; | |
96 | void log() const; | |
97 | void log_() const; | |
98 | }; | |
99 | ||
100 | #endif | |
101 | ||
102 | class TTCN_Type_list; | |
103 | class RAW_enc_tree; | |
104 | class Limit_Token_List; | |
105 | #ifdef TITAN_RUNTIME_2 | |
106 | class Text_Buf; | |
107 | #endif | |
108 | ||
109 | #ifdef TITAN_RUNTIME_2 | |
110 | #define VIRTUAL_IF_RUNTIME_2 virtual | |
111 | #else | |
112 | #define VIRTUAL_IF_RUNTIME_2 | |
113 | #endif | |
114 | ||
115 | /** | |
116 | * The base class for all types in TTCN-3 runtime environment. | |
117 | * | |
118 | * Uses the compiler-generated default constructor, copy constructor | |
119 | * and assignment operator (they do nothing because the class is empty). | |
120 | */ | |
121 | class Base_Type { | |
122 | public: | |
123 | ||
124 | /** Whether the value is present. | |
125 | * Note: this is not the TTCN-3 ispresent(), kept for backward compatibility! | |
126 | * causes DTE, must be used only if the field is OPTIONAL<> | |
127 | */ | |
128 | VIRTUAL_IF_RUNTIME_2 boolean ispresent() const; | |
129 | ||
130 | VIRTUAL_IF_RUNTIME_2 void log() const; | |
131 | ||
132 | /** Check whether the XML encoding of the type can begin with an XML element | |
133 | * having the specified name and namespace. | |
134 | * | |
135 | * This function checks for the "starter tag" of the type. This usually | |
136 | * means the tag should match the name in the XER descriptor, | |
137 | * with a few notable exceptions: | |
138 | * | |
139 | * - If the type is untagged, then | |
140 | * - if it's a record, all fields up to the the first non-optional field | |
141 | * are checked; | |
142 | * - if it's a record-of, the element is checked. | |
143 | * - A \c universal \c charstring with ANY-ELEMENT can begin with any tag. | |
144 | * | |
145 | * @param name the XML element name (local name) | |
146 | * @param uri the namespace URI of the element | |
147 | * @param xd XER descriptor | |
148 | * @param flavor one or more bits from XER_flavor. Only XER_EXTENDED counts | |
149 | * @return TRUE if the XML element can begin the XER encoding of the type, | |
150 | * FALSE otherwise. | |
151 | */ | |
152 | static boolean can_start(const char *name, const char *uri, | |
153 | XERdescriptor_t const& xd, unsigned int flavor); | |
154 | ||
155 | #ifdef TITAN_RUNTIME_2 | |
3abe9331 | 156 | /** Initialize this object (or one of its fields/elements) with a |
157 | * module parameter value. The module parameter may contain references to | |
158 | * other module parameters or module parameter expressions, which are processed | |
159 | * by this method to calculated the final result. | |
160 | * @param param module parameter value (its ID specifies which object is to be set) */ | |
970ed795 | 161 | virtual void set_param(Module_Param& param) = 0; |
3abe9331 | 162 | /** Create a module parameter value equivalent to this object (or one of its |
163 | * fields/elements) | |
164 | * @param param_name module parameter ID, specifies which object to convert */ | |
165 | virtual Module_Param* get_param(Module_Param_Name& param_name) const = 0; | |
970ed795 EL |
166 | /** Whether the type is a sequence-of. |
167 | * @return \c FALSE */ | |
168 | virtual boolean is_seof() const { return FALSE; } | |
169 | ||
170 | virtual void encode_text(Text_Buf& text_buf) const = 0; | |
171 | virtual void decode_text(Text_Buf& text_buf) = 0; | |
172 | ||
173 | virtual boolean is_bound() const = 0; | |
174 | virtual boolean is_value() const { return is_bound(); } | |
175 | virtual void clean_up() = 0; | |
176 | ||
177 | /** returns if the value of this is equal to the value of the parameter. */ | |
178 | virtual boolean is_equal(const Base_Type* other_value) const = 0; | |
179 | ||
180 | /** Performs: *this = *other_value. | |
181 | * Does not take ownership of \p other_value. */ | |
182 | virtual void set_value(const Base_Type* other_value) = 0; | |
183 | ||
184 | /** creates a copy of this object, returns a pointer to it. */ | |
185 | virtual Base_Type* clone() const = 0; | |
186 | ||
187 | /** return reference to the type descriptor object for this type. */ | |
188 | virtual const TTCN_Typedescriptor_t* get_descriptor() const = 0; | |
189 | ||
190 | /** @name override in class OPTIONAL<T> | |
191 | * @{ */ | |
192 | virtual boolean is_optional() const { return FALSE; } | |
193 | ||
194 | /** Is the optional value present or omit. | |
195 | * @return \c true if present, \c false otherwise | |
196 | * used for TTCN-3 ispresent() | |
197 | **/ | |
198 | virtual boolean is_present() const; | |
199 | ||
200 | /** Access the embedded type of the optional. | |
201 | * | |
202 | * The implementation in Base_Type always causes a dynamic testcase error. | |
203 | */ | |
204 | virtual Base_Type* get_opt_value(); | |
205 | ||
206 | /** Access the embedded type of the optional. | |
207 | * | |
208 | * The implementation in Base_Type always causes a dynamic testcase error. | |
209 | */ | |
210 | virtual const Base_Type* get_opt_value() const; | |
211 | ||
212 | /** Set the optional field to \c omit. | |
213 | * The implementation in Base_Type always causes a dynamic testcase error. | |
214 | */ | |
215 | virtual void set_to_omit(); | |
216 | ||
217 | /** Set the optional field to present. | |
218 | * The implementation in Base_Type always causes a dynamic testcase error. | |
219 | */ | |
220 | virtual void set_to_present(); | |
221 | /** @} */ | |
af710487 | 222 | |
970ed795 EL |
223 | virtual ~Base_Type() { } |
224 | ||
225 | #endif | |
226 | ||
227 | /** Do nothing for non-structured types. */ | |
228 | VIRTUAL_IF_RUNTIME_2 void set_implicit_omit() { } | |
229 | ||
230 | /** @brief Encode an instance of this object | |
231 | ||
232 | Description: | |
233 | ||
234 | @param p_td type descriptor | |
235 | @param p_buf buffer | |
236 | @param p_coding coding type to select BER, RAW or TEXT coding | |
237 | ||
238 | */ | |
239 | VIRTUAL_IF_RUNTIME_2 void encode(const TTCN_Typedescriptor_t& p_td, | |
240 | TTCN_Buffer& p_buf, TTCN_EncDec::coding_t p_coding, ...) const; | |
241 | ||
242 | /** @brief Decode an instance of this object | |
243 | ||
244 | Description: | |
245 | ||
246 | @param p_td type descriptor | |
247 | @param p_buf buffer | |
248 | @param p_coding coding type to select BER, RAW or TEXT coding | |
249 | ||
250 | */ | |
251 | VIRTUAL_IF_RUNTIME_2 void decode(const TTCN_Typedescriptor_t& p_td, | |
252 | TTCN_Buffer& p_buf, TTCN_EncDec::coding_t p_coding, ...); | |
253 | ||
254 | protected: | |
255 | /** Check type descriptor for BER encoding | |
256 | * | |
257 | * @param p_td a TTCN type descriptor | |
258 | * | |
259 | * Calls TTCN_EncDec_ErrorContext::error_internal if | |
260 | * p_td has no BER descriptor. | |
261 | */ | |
262 | static void BER_chk_descr(const TTCN_Typedescriptor_t& p_td); | |
263 | ||
264 | /** Check the BER coding | |
265 | * | |
266 | * If \p p_coding is either BER_ENCODE_CER or BER_ENCODE_DER, | |
267 | * this function does nothing. Otherwise, it issues a warning | |
268 | * and sets \p p_coding to BER_ENCODE_DER. | |
269 | * | |
270 | * @param[in, out] p_coding BER coding | |
271 | * @post p_coding is either BER_ENCODE_CER or BER_ENCODE_DER | |
272 | */ | |
273 | static void BER_encode_chk_coding(unsigned& p_coding); | |
274 | ||
275 | /** Check type descriptor for XER encoding and the XER coding variant | |
276 | * | |
277 | * @param[in, out] p_coding XER coding | |
278 | * @param[in] p_td TTCN type descriptor | |
279 | * | |
280 | * If \p p_td has no XER descriptor, calls | |
281 | * TTCN_EncDec_ErrorContext::error_internal() | |
282 | * | |
283 | * If \p p_coding is one of XER_BASIC, XER_CANONICAL or XER_EXTENDED, | |
284 | * this function does nothing. Otherwise, it issues a warning | |
285 | * and sets \p p_coding to XER_BASIC. | |
286 | * | |
287 | * @post p_coding is one of XER_BASIC, XER_CANONICAL or XER_EXTENDED | |
288 | */ | |
289 | static void XER_encode_chk_coding(unsigned& p_coding, | |
290 | const TTCN_Typedescriptor_t& p_td); | |
291 | ||
292 | /** Check bound and create a 0-length TLV in case unbound is ignored. | |
293 | * | |
294 | * @param[in] p_isbound | |
295 | * @return a newly constructed and empty \c ASN_BER_TLV_t | |
296 | * if p_isbound is false, or NULL if p_isbound is true | |
297 | * @note if p_isbound is false, this function calls | |
298 | * TTCN_EncDec_ErrorContext::error with TTCN_EncDec::ET_UNBOUND. | |
299 | * If that error is not ignored, this function does not return at all. | |
300 | */ | |
301 | static ASN_BER_TLV_t* BER_encode_chk_bound(boolean p_isbound); | |
302 | ||
303 | private: | |
304 | static void BER_encode_putoctets_OCTETSTRING | |
305 | (unsigned char *target, | |
306 | unsigned int octetnum_start, unsigned int octet_count, | |
307 | int p_nof_octets, const unsigned char *p_octets_ptr); | |
308 | ||
309 | protected: | |
310 | static ASN_BER_TLV_t* BER_encode_TLV_OCTETSTRING | |
311 | (unsigned p_coding, | |
312 | int p_nof_octets, const unsigned char *p_octets_ptr); | |
313 | ||
314 | static ASN_BER_TLV_t *BER_encode_TLV_INTEGER(unsigned p_coding, | |
315 | const int_val_t& p_int_val); | |
316 | static ASN_BER_TLV_t *BER_encode_TLV_INTEGER(unsigned p_coding, | |
317 | const int& p_int_val); | |
318 | ||
319 | static void BER_encode_chk_enum_valid(const TTCN_Typedescriptor_t& p_td, | |
320 | boolean p_isvalid, int p_value); | |
321 | ||
322 | static void BER_decode_str2TLV(TTCN_Buffer& p_buf, ASN_BER_TLV_t& p_tlv, | |
323 | unsigned L_form); | |
324 | ||
325 | static boolean BER_decode_constdTLV_next(const ASN_BER_TLV_t& p_tlv, | |
326 | size_t& V_pos, | |
327 | unsigned L_form, | |
328 | ASN_BER_TLV_t& p_target_tlv); | |
329 | ||
330 | static void BER_decode_constdTLV_end(const ASN_BER_TLV_t& p_tlv, | |
331 | size_t& V_pos, | |
332 | unsigned L_form, | |
333 | ASN_BER_TLV_t& p_target_tlv, | |
334 | boolean tlv_present); | |
335 | ||
336 | static void BER_decode_strip_tags(const ASN_BERdescriptor_t& p_ber, | |
337 | const ASN_BER_TLV_t& p_tlv, | |
338 | unsigned L_form, | |
339 | ASN_BER_TLV_t& stripped_tlv); | |
340 | ||
341 | private: | |
342 | static void BER_decode_getoctets_OCTETSTRING | |
343 | (const unsigned char *source, size_t s_len, | |
344 | unsigned int& octetnum_start, | |
345 | int& p_nof_octets, unsigned char *p_octets_ptr); | |
346 | ||
347 | protected: | |
348 | static void BER_decode_TLV_OCTETSTRING | |
349 | (const ASN_BER_TLV_t& p_tlv, unsigned L_form, | |
350 | unsigned int& octetnum_start, | |
351 | int& p_nof_octets, unsigned char *p_octets_ptr); | |
352 | ||
353 | static boolean BER_decode_TLV_INTEGER(const ASN_BER_TLV_t& p_tlv, | |
354 | unsigned L_form, int_val_t& p_int_val); | |
355 | static boolean BER_decode_TLV_INTEGER(const ASN_BER_TLV_t& p_tlv, | |
356 | unsigned L_form, int& p_int_val); | |
357 | ||
358 | static boolean BER_decode_TLV_CHOICE(const ASN_BERdescriptor_t& p_ber, | |
359 | const ASN_BER_TLV_t& p_tlv, | |
360 | unsigned L_form, | |
361 | ASN_BER_TLV_t& p_target_tlv); | |
362 | ||
363 | static boolean BER_decode_CHOICE_selection(boolean select_result, | |
364 | const ASN_BER_TLV_t& p_tlv); | |
365 | ||
366 | static void BER_decode_chk_enum_valid(const TTCN_Typedescriptor_t& p_td, | |
367 | boolean p_isvalid, int p_value); | |
368 | ||
369 | public: | |
370 | VIRTUAL_IF_RUNTIME_2 ASN_BER_TLV_t* BER_encode_TLV( | |
371 | const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const; | |
372 | #ifdef TITAN_RUNTIME_2 | |
373 | virtual ASN_BER_TLV_t* BER_encode_TLV_negtest(const Erroneous_descriptor_t* /*p_err_descr*/, | |
374 | const TTCN_Typedescriptor_t& /*p_td*/, unsigned /*p_coding*/) const; | |
375 | virtual ASN_BER_TLV_t* BER_encode_negtest_raw() const; | |
376 | virtual int encode_raw(TTCN_Buffer& p_buf) const; | |
377 | virtual int RAW_encode_negtest_raw(RAW_enc_tree& p_myleaf) const; | |
378 | #endif | |
379 | ||
380 | /** Examines whether this message corresponds the tags in the | |
381 | * descriptor. If the BER descriptor contains no tags, then returns | |
382 | * TRUE. Otherwise, examines the first (outermost) tag only. */ | |
383 | #ifdef TITAN_RUNTIME_2 | |
384 | virtual | |
385 | #else | |
386 | static | |
387 | #endif | |
388 | boolean BER_decode_isMyMsg(const TTCN_Typedescriptor_t& p_td, | |
389 | const ASN_BER_TLV_t& p_tlv); | |
390 | ||
391 | /** Returns TRUE on success, FALSE otherwise. */ | |
392 | VIRTUAL_IF_RUNTIME_2 boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td, | |
393 | const ASN_BER_TLV_t& p_tlv, unsigned L_form); | |
394 | ||
395 | VIRTUAL_IF_RUNTIME_2 void BER_decode_opentypes( | |
396 | TTCN_Type_list& /*p_typelist*/, unsigned /*L_form*/) {} | |
397 | ||
398 | /** Encode with RAW coding. | |
399 | * @return the length of the encoding | |
400 | * @param p_td type descriptor | |
401 | * @param myleaf filled with RAW encoding data | |
402 | * @note Basetype::RAW_encode throws an error. */ | |
403 | VIRTUAL_IF_RUNTIME_2 int RAW_encode(const TTCN_Typedescriptor_t& p_td, | |
404 | RAW_enc_tree& myleaf) const; | |
405 | #ifdef TITAN_RUNTIME_2 | |
406 | virtual int RAW_encode_negtest(const Erroneous_descriptor_t *p_err_descr, | |
407 | const TTCN_Typedescriptor_t& p_td, RAW_enc_tree& myleaf) const; | |
408 | #endif | |
409 | ||
410 | /** Decode with RAW coding | |
411 | * | |
412 | * @param p_td type descriptor | |
413 | * @param p_buf buffer with data to be decoded | |
414 | * @param limit number of bits the decoder is allowed to use. At the top level | |
415 | * this is 8x the number of bytes in the buffer. | |
416 | * @param top_bit_ord (LSB/MSB) from TTCN_RAWdescriptor_t::top_bit_order | |
417 | * @param no_err set to TRUE if the decoder is to return errors silently, | |
418 | * without calling TTCN_EncDec_ErrorContext::error | |
419 | * @param sel_field selected field indicator for CROSSTAG, or -1 | |
420 | * @param first_call default TRUE. May be FALSE for a REPEATABLE record-of | |
421 | * inside a set, if an element has been successfully decoded. | |
422 | * @return length of decoded field, or a negative number for error | |
423 | * @note Basetype::RAW_decode throws an error. */ | |
424 | VIRTUAL_IF_RUNTIME_2 int RAW_decode( | |
425 | const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int limit, | |
426 | raw_order_t top_bit_ord, boolean no_err=FALSE, int sel_field=-1, | |
427 | boolean first_call=TRUE); | |
428 | ||
429 | ||
430 | /** Encode with TEXT encoding. | |
431 | * @return the length of the encoding | |
432 | * @param p_td type descriptor | |
433 | * @param p_buf buffer for the encoded data | |
434 | * @note Basetype::TEXT_encode throws an error. */ | |
435 | VIRTUAL_IF_RUNTIME_2 int TEXT_encode(const TTCN_Typedescriptor_t& p_td, | |
436 | TTCN_Buffer& p_buf) const; | |
437 | ||
438 | #ifdef TITAN_RUNTIME_2 | |
439 | /** Encode with TEXT encoding negative test. | |
440 | * @return the length of the encoding | |
441 | * @param p_err_descr type descriptor | |
442 | * @param p_td type descriptor | |
443 | * @param p_buf buffer for the encoded data | |
444 | * @note Basetype::TEXT_encode_negtest throws an error. */ | |
445 | virtual int TEXT_encode_negtest(const Erroneous_descriptor_t* p_err_descr, const TTCN_Typedescriptor_t& p_td, | |
446 | TTCN_Buffer& p_buf) const; | |
447 | #endif | |
448 | ||
449 | /** Decode TEXT. | |
450 | * @return decoded length | |
451 | * @note Basetype::TEXT_decode throws an error. */ | |
452 | VIRTUAL_IF_RUNTIME_2 int TEXT_decode( | |
453 | const TTCN_Typedescriptor_t&, TTCN_Buffer&, Limit_Token_List&, | |
454 | boolean no_err=FALSE, boolean first_call=TRUE); | |
455 | ||
456 | /** Write the XER encoding of the current object into the buffer. | |
457 | * | |
458 | * @param p_td type descriptor | |
459 | * @param p_buf buffer | |
460 | * @param flavor one of XER_flavor values | |
461 | * @param indent indentation level | |
af710487 | 462 | * @param emb_val embed values data (only relevant for record of types) |
970ed795 EL |
463 | * @return number of bytes written into the buffer |
464 | */ | |
465 | VIRTUAL_IF_RUNTIME_2 int XER_encode(const XERdescriptor_t& p_td, | |
af710487 | 466 | TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t* emb_val) const; |
970ed795 EL |
467 | |
468 | #ifdef TITAN_RUNTIME_2 | |
469 | virtual int XER_encode_negtest(const Erroneous_descriptor_t* /*p_err_descr*/, | |
470 | const XERdescriptor_t& /*p_td*/, TTCN_Buffer& /*p_buf*/, | |
af710487 | 471 | unsigned int /*flavor*/, int /*indent*/, embed_values_enc_struct_t* /*emb_val*/) const; |
970ed795 EL |
472 | #endif |
473 | ||
474 | /** Decode the current object from the supplied buffer. | |
475 | * | |
476 | * The XML pull parser presents a forward iterator over the XML elements. | |
477 | * @pre Upon entering this function, the current node should be the one corresponding | |
478 | * to this object, or possibly a text or whitespace node before it. | |
479 | * Code should begin like this: | |
480 | * @code | |
481 | * int Foo::XER_decode() { | |
482 | * int success=1, type; | |
483 | * for ( ; success==1; success=reader.Read() ) { | |
484 | * int type=reader.NodeType(); | |
485 | * if (XML_READER_TYPE_ELEMENT==type) { | |
486 | * verify_name( | |
487 | * } | |
488 | * } | |
489 | * } | |
490 | * @endcode | |
491 | * | |
492 | * @post Upon leaving the function, the current node should be \b past | |
493 | * the end tag, i.e. the next start tag (or any whitespace before it). | |
494 | * | |
495 | * It is important not to advance the parser too far, to avoid "stealing" | |
496 | * the content of other fields (the parser can only go forward). | |
497 | * | |
498 | * @param p_td type descriptor | |
499 | * @param reader Wrapper around the XML processor | |
500 | * @param flavor one of XER_flavor values | |
af710487 | 501 | * @param emb_val embed values data (only relevant for record of types) |
970ed795 EL |
502 | * @return number of bytes "consumed" |
503 | */ | |
504 | VIRTUAL_IF_RUNTIME_2 int XER_decode(const XERdescriptor_t& p_td, | |
af710487 | 505 | XmlReaderWrap& reader, unsigned int flavor, embed_values_dec_struct_t* emb_val); |
970ed795 EL |
506 | |
507 | /** Return an array of namespace declarations. | |
508 | * | |
509 | * @param[in] p_td XER descriptor of the type. | |
510 | * @param[out] num set to the number of strings returned. | |
511 | * @param[out] def_ns set to @p true if a default namespace was encountered | |
512 | * @return an array of strings or NULL. All the strings in the array | |
513 | * and the array itself must be deallocated by the caller (if num>0). | |
514 | * | |
515 | * The strings are in the following format: | |
516 | * @code " xmlns:prefix='uri'" @endcode | |
517 | * (the space at start allows direct concatenation of the strings) | |
518 | */ | |
519 | VIRTUAL_IF_RUNTIME_2 char ** collect_ns(const XERdescriptor_t& p_td, | |
520 | size_t& num, bool& def_ns) const; | |
521 | ||
522 | /** Copy strings from @p new_namespaces to @p collected_ns, | |
523 | * discarding duplicates. | |
524 | * | |
525 | * May reallocate @p collected_ns, in which case @p num_collected | |
526 | * is adjusted accordingly. | |
527 | * | |
528 | * @param collected_ns target array | |
529 | * @param num_collected number of already collected namespaces | |
530 | * @param new_namespaces new array | |
531 | * @param num_new number of new namespaces | |
532 | * | |
533 | * @post new_namespaces has been deallocated and set to NULL. | |
534 | */ | |
535 | static void merge_ns(char **&collected_ns, size_t& num_collected, | |
536 | char **new_namespaces, size_t num_new); | |
537 | ||
538 | typedef char** (Base_Type::*collector_fn) | |
539 | (const XERdescriptor_t& p_td, size_t& num, bool& def_ns) const; | |
540 | ||
541 | /** Start writing the XML representation | |
542 | * | |
543 | * @param[in] p_td XER descriptor | |
544 | * @param[out] p_buf buffer to write into | |
545 | * @param[in,out] flavor XER variant (basic, canonical or extended), | |
546 | * also used to pass various flags between begin_xml and its caller | |
547 | * @param[in] indent indentation level | |
548 | * @param[in] empty true if an empty-element tag is needed | |
549 | * @param[in] collector namespace collector function | |
550 | * @param[in] type_atr type identification attribute for useNil/useUnion, | |
551 | * in the following format: "xsi:type='foo'" | |
552 | * @return "omit_tag": zero if the type's own tag was written (not omitted | |
553 | * e.g. due to untagged). | |
554 | * If the XML tag was omitted, the return value is nonzero. | |
555 | * The special value -1 is returned if the XML in the buffer | |
556 | * was shortened by exactly one character. | |
557 | */ | |
558 | VIRTUAL_IF_RUNTIME_2 int begin_xml(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, | |
559 | unsigned int& flavor, int indent, bool empty, | |
560 | collector_fn collector = &Base_Type::collect_ns, const char *type_atr = NULL) const; | |
561 | /** Finish the XML representation. | |
562 | * | |
563 | * @param[in] p_td XER descriptor | |
564 | * @param[out] p_buf buffer to write into | |
565 | * @param[in] flavor XER variant (basic, canonical or extended), | |
566 | * also used to pass various flags | |
567 | * @param[in] indent indentation level | |
568 | * @param[in] empty true if an empty-element tag is needed | |
569 | */ | |
570 | VIRTUAL_IF_RUNTIME_2 void end_xml (const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, | |
571 | unsigned int flavor, int indent, bool empty) const; | |
572 | ||
573 | /** Encode JSON. | |
574 | * @return encoded length | |
575 | * @note Basetype::JSON_encode throws an error. */ | |
576 | VIRTUAL_IF_RUNTIME_2 int JSON_encode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer&) const; | |
577 | ||
578 | /** Decode JSON. | |
579 | * @return decoded length | |
580 | * @note Basetype::JSON_decode throws an error. */ | |
581 | VIRTUAL_IF_RUNTIME_2 int JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer&, boolean); | |
582 | ||
583 | /** not a component by default (components will return true) */ | |
584 | inline boolean is_component() { return FALSE; } | |
585 | }; | |
586 | ||
587 | /** | |
588 | * This class is used by BER decoding to handle | |
589 | * ComponentRelationConstraint. | |
590 | */ | |
591 | class TTCN_Type_list { | |
592 | private: | |
593 | size_t n_types; | |
594 | const Base_Type **types; | |
595 | /// Copy constructor disabled | |
596 | TTCN_Type_list(const TTCN_Type_list&); | |
597 | /// Assignment disabled | |
598 | TTCN_Type_list& operator=(const TTCN_Type_list&); | |
599 | public: | |
600 | TTCN_Type_list() : n_types(0), types(NULL) {} | |
601 | ~TTCN_Type_list(); | |
602 | void push(const Base_Type *p_type); | |
603 | const Base_Type* pop(); | |
604 | /** If \a pos is 0 then returns the outermost, otherwise the "pos"th | |
605 | * inner parent. */ | |
606 | const Base_Type* get_nth(size_t pos) const; | |
607 | }; | |
608 | ||
609 | /** @name Type descriptor objects | |
610 | @{ | |
611 | */ | |
612 | extern const TTCN_Typedescriptor_t BOOLEAN_descr_; | |
613 | extern const TTCN_Typedescriptor_t INTEGER_descr_; | |
614 | extern const TTCN_Typedescriptor_t FLOAT_descr_; | |
615 | extern const TTCN_Typedescriptor_t VERDICTTYPE_descr_; | |
616 | extern const TTCN_Typedescriptor_t OBJID_descr_; | |
617 | extern const TTCN_Typedescriptor_t BITSTRING_descr_; | |
618 | extern const TTCN_Typedescriptor_t HEXSTRING_descr_; | |
619 | extern const TTCN_Typedescriptor_t OCTETSTRING_descr_; | |
620 | extern const TTCN_Typedescriptor_t CHARSTRING_descr_; | |
621 | extern const TTCN_Typedescriptor_t UNIVERSAL_CHARSTRING_descr_; | |
622 | extern const TTCN_Typedescriptor_t COMPONENT_descr_; | |
623 | extern const TTCN_Typedescriptor_t DEFAULT_descr_; | |
624 | extern const TTCN_Typedescriptor_t ASN_NULL_descr_; | |
625 | extern const TTCN_Typedescriptor_t ASN_ANY_descr_; | |
626 | extern const TTCN_Typedescriptor_t EXTERNAL_descr_; | |
627 | extern const TTCN_Typedescriptor_t EMBEDDED_PDV_descr_; | |
628 | extern const TTCN_Typedescriptor_t CHARACTER_STRING_descr_; | |
629 | extern const TTCN_Typedescriptor_t ObjectDescriptor_descr_; | |
630 | extern const TTCN_Typedescriptor_t UTF8String_descr_; | |
631 | extern const TTCN_Typedescriptor_t ASN_ROID_descr_; | |
632 | extern const TTCN_Typedescriptor_t NumericString_descr_; | |
633 | extern const TTCN_Typedescriptor_t PrintableString_descr_; | |
634 | extern const TTCN_Typedescriptor_t TeletexString_descr_; | |
635 | extern const TTCN_Typedescriptor_t& T61String_descr_; | |
636 | extern const TTCN_Typedescriptor_t VideotexString_descr_; | |
637 | extern const TTCN_Typedescriptor_t IA5String_descr_; | |
638 | extern const TTCN_Typedescriptor_t ASN_GeneralizedTime_descr_; | |
639 | extern const TTCN_Typedescriptor_t ASN_UTCTime_descr_; | |
640 | extern const TTCN_Typedescriptor_t GraphicString_descr_; | |
641 | extern const TTCN_Typedescriptor_t VisibleString_descr_; | |
642 | extern const TTCN_Typedescriptor_t& ISO646String_descr_; | |
643 | extern const TTCN_Typedescriptor_t GeneralString_descr_; | |
644 | extern const TTCN_Typedescriptor_t UniversalString_descr_; | |
645 | extern const TTCN_Typedescriptor_t BMPString_descr_; | |
646 | /** @} */ | |
647 | ||
648 | #ifdef TITAN_RUNTIME_2 | |
649 | ||
650 | class Text_Buf; | |
651 | class INTEGER; | |
652 | ||
653 | /** The base class of all record-of types when using RT2 | |
654 | * | |
655 | */ | |
656 | // Record_Of_Template can be found in Template.hh | |
a38c6d4c | 657 | class Record_Of_Type : public Base_Type, public RefdIndexInterface |
970ed795 EL |
658 | { |
659 | friend class Set_Of_Template; | |
660 | friend class Record_Of_Template; | |
661 | protected: | |
662 | friend boolean operator==(null_type null_value, | |
663 | const Record_Of_Type& other_value); | |
664 | struct recordof_setof_struct { | |
665 | int ref_count; | |
666 | int n_elements; | |
667 | Base_Type **value_elements; | |
668 | } *val_ptr; | |
669 | Erroneous_descriptor_t* err_descr; | |
670 | ||
af710487 | 671 | struct refd_index_struct { |
672 | /** Stores the indices of elements that are referenced by 'out' and 'inout' parameters. | |
673 | * These elements must not be deleted.*/ | |
674 | Vector<int> refd_indices; | |
675 | ||
676 | /** Cached maximum value of \a refd_indices (default: -1).*/ | |
677 | int max_refd_index; | |
678 | } *refd_ind_ptr; | |
970ed795 EL |
679 | |
680 | static boolean compare_function(const Record_Of_Type *left_ptr, int left_index, const Record_Of_Type *right_ptr, int right_index); | |
af710487 | 681 | Record_Of_Type() : val_ptr(NULL), err_descr(NULL), refd_ind_ptr(NULL) {} |
970ed795 EL |
682 | Record_Of_Type(null_type other_value); |
683 | Record_Of_Type(const Record_Of_Type& other_value); | |
684 | /// Assignment disabled | |
685 | Record_Of_Type& operator=(const Record_Of_Type& other_value); | |
686 | ||
687 | /** Returns the number of actual elements in the record of (does not count the | |
688 | * unbound elements left at the end of the record of struct to make sure | |
689 | * referenced elements are not deleted). */ | |
690 | int get_nof_elements() const; | |
691 | ||
692 | /** Returns true if the indexed element is bound */ | |
693 | bool is_elem_bound(int index) const; | |
694 | ||
695 | /** Returns the highest referenced index (uses \a max_refd_index as its cache)*/ | |
696 | int get_max_refd_index(); | |
697 | ||
698 | /** Returns true if the element at the given index is referenced by an 'out' or | |
699 | * 'inout' parameter. */ | |
700 | bool is_index_refd(int index); | |
701 | ||
702 | public: | |
703 | void set_val(null_type other_value); | |
704 | ||
705 | boolean operator==(null_type other_value) const; | |
706 | boolean operator!=(null_type other_value) const; | |
707 | ||
708 | Base_Type* get_at(int index_value); | |
709 | Base_Type* get_at(const INTEGER& index_value); | |
710 | const Base_Type* get_at(int index_value) const; | |
711 | const Base_Type* get_at(const INTEGER& index_value) const; | |
712 | ||
713 | virtual boolean is_equal(const Base_Type* other_value) const; | |
714 | virtual void set_value(const Base_Type* other_value); | |
715 | ||
716 | /* following functions return rec_of or this or other_value */ | |
717 | Record_Of_Type* rotl(const INTEGER& rotate_count, Record_Of_Type* rec_of) const; | |
718 | Record_Of_Type* rotr(int rotate_count, Record_Of_Type* rec_of) const; | |
719 | Record_Of_Type* rotr(const INTEGER& rotate_count, Record_Of_Type* rec_of) const; | |
720 | Record_Of_Type* concat(const Record_Of_Type* other_value, Record_Of_Type* rec_of) const; | |
721 | /* parameter rec_of must be a newly created descendant object, these helper functions fill it */ | |
722 | void substr_(int index, int returncount, Record_Of_Type* rec_of) const; | |
723 | void replace_(int index, int len, const Record_Of_Type* repl, Record_Of_Type* rec_of) const; | |
724 | void replace_(int index, int len, const Record_Of_Template* repl, Record_Of_Type* rec_of) const; | |
725 | void replace_(int index, int len, const Set_Of_Template* repl, Record_Of_Type* rec_of) const; | |
726 | ||
727 | void set_size(int new_size); | |
728 | ||
729 | /** Implementation for isbound. | |
730 | * @return \c true if the Record_Of itself is bound, \c false otherwise. | |
731 | * Ignores elements. No need to be overridden. */ | |
732 | virtual boolean is_bound() const; | |
733 | /** Implementation for isvalue. | |
734 | * @return \c true if all elements are bound, \c false otherwise */ | |
735 | virtual boolean is_value() const; | |
736 | virtual void clean_up(); | |
737 | ||
738 | virtual boolean is_seof() const { return TRUE; } | |
739 | ||
740 | /** Implementation for the \c sizeof operation | |
741 | * @return the number of elements */ | |
742 | int size_of() const; | |
743 | int n_elem() const { return size_of(); } | |
744 | ||
745 | /** Implementation for the lengthof operation. | |
746 | * @return the index of the last bound element +1 */ | |
747 | int lengthof() const; | |
748 | virtual void log() const; | |
749 | virtual void set_param(Module_Param& param); | |
3abe9331 | 750 | virtual Module_Param* get_param(Module_Param_Name& param_name) const; |
970ed795 EL |
751 | virtual void set_implicit_omit(); |
752 | virtual void encode_text(Text_Buf& text_buf) const; | |
753 | virtual void decode_text(Text_Buf& text_buf); | |
754 | ||
755 | virtual void BER_decode_opentypes(TTCN_Type_list& p_typelist, unsigned L_form); | |
756 | ||
757 | virtual void encode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, TTCN_EncDec::coding_t, ...) const; | |
758 | virtual void decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, TTCN_EncDec::coding_t, ...); | |
759 | ||
760 | virtual ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const; | |
761 | virtual ASN_BER_TLV_t* BER_encode_TLV_negtest(const Erroneous_descriptor_t* p_err_descr, const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const; | |
762 | virtual boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv, unsigned L_form); | |
763 | ||
764 | virtual int RAW_encode_negtest(const Erroneous_descriptor_t *p_err_descr, const TTCN_Typedescriptor_t& p_td, RAW_enc_tree& myleaf) const; | |
765 | virtual int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const; | |
766 | /** Decode RAW | |
767 | * | |
768 | * @param td type descriptor | |
769 | * @param buf buffer | |
770 | * @param limit max number of bits that can be used | |
771 | * @param top_bit_ord | |
772 | * @param no_err (not used) | |
773 | * @param sel_field | |
774 | * @param first_call default true, false for second and subsequent calls | |
775 | * of a REPEATABLE record-of. Equivalent to "not repeated" | |
776 | * @return number of bits used, or a negative number in case of error | |
777 | */ | |
778 | virtual int RAW_decode(const TTCN_Typedescriptor_t& td, TTCN_Buffer& buf, int limit, | |
779 | raw_order_t top_bit_ord, boolean no_err=FALSE, int sel_field=-1, boolean first_call=TRUE); | |
780 | /// raw extension bit | |
781 | virtual int rawdec_ebv() const; | |
782 | ||
783 | virtual int TEXT_encode(const TTCN_Typedescriptor_t&, TTCN_Buffer&) const; | |
784 | virtual int TEXT_encode_negtest(const Erroneous_descriptor_t* p_err_descr, const TTCN_Typedescriptor_t&, TTCN_Buffer&) const; | |
785 | virtual int TEXT_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, Limit_Token_List&, boolean no_err=FALSE, boolean first_call=TRUE); | |
786 | ||
787 | virtual int XER_encode(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, | |
af710487 | 788 | unsigned int flavor, int indent, embed_values_enc_struct_t*) const; |
970ed795 | 789 | virtual int XER_encode_negtest(const Erroneous_descriptor_t* p_err_descr, |
af710487 | 790 | const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, unsigned flavor, int indent, embed_values_enc_struct_t*) const; |
970ed795 | 791 | /// Helper for XER_encode_negtest |
a38c6d4c | 792 | int encode_element(int i, const XERdescriptor_t& p_td, const Erroneous_values_t* err_vals, |
970ed795 | 793 | const Erroneous_descriptor_t* emb_descr, |
af710487 | 794 | TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t* emb_val) const; |
795 | virtual int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader, unsigned int, embed_values_dec_struct_t*); | |
970ed795 EL |
796 | virtual boolean isXerAttribute() const; |
797 | virtual boolean isXmlValueList() const; | |
798 | ||
799 | /** Encodes accordingly to the JSON encoding rules. | |
800 | * Returns the length of the encoded data. */ | |
801 | int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const; | |
802 | ||
803 | /** Decodes accordingly to the JSON encoding rules. | |
804 | * Returns the length of the decoded data. */ | |
805 | int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean); | |
806 | ||
807 | /** @returns \c true if this is a set-of type, | |
808 | * \c false if this is a record-of type */ | |
809 | virtual boolean is_set() const = 0; | |
970ed795 EL |
810 | /** creates an instance of the record's element class, using the default constructor */ |
811 | virtual Base_Type* create_elem() const = 0; | |
812 | ||
813 | /** Constant unbound element - return this instead of NULL in constant functions */ | |
814 | virtual const Base_Type* get_unbound_elem() const = 0; | |
815 | ||
816 | virtual char ** collect_ns(const XERdescriptor_t& p_td, size_t& num, bool& def_ns) const; | |
817 | virtual boolean can_start_v(const char *name, const char *prefix, | |
818 | XERdescriptor_t const& xd, unsigned int flavor) = 0; | |
819 | ||
820 | void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; } | |
821 | Erroneous_descriptor_t* get_err_descr() const { return err_descr; } | |
822 | ||
823 | /** Indicates that the element at the given index is referenced by an 'out' or | |
824 | * 'inout' parameter and must not be deleted. | |
825 | * Used just before the actual function call that references the element. */ | |
a38c6d4c | 826 | virtual void add_refd_index(int index); |
970ed795 EL |
827 | |
828 | /** Indicates that the element at the given index is no longer referenced by | |
829 | * an 'out' or 'inout' parameter. | |
830 | * Used immediately after the actual function call that referenced the element. */ | |
a38c6d4c | 831 | virtual void remove_refd_index(int index); |
970ed795 EL |
832 | }; |
833 | ||
834 | extern boolean operator==(null_type null_value, | |
835 | const Record_Of_Type& other_value); | |
836 | extern boolean operator!=(null_type null_value, | |
837 | const Record_Of_Type& other_value); | |
838 | ||
839 | //////////////////////////////////////////////////////////////////////////////// | |
840 | ||
841 | /** The base class of all record types when using RT2 */ | |
842 | // Record_Template can be found in Template.hh | |
843 | class Record_Type : public Base_Type { | |
844 | protected: | |
845 | struct default_struct { | |
846 | int index; | |
847 | const Base_Type* value; | |
848 | }; | |
849 | Erroneous_descriptor_t* err_descr; | |
850 | boolean bound_flag; | |
851 | public: | |
852 | Record_Type() : err_descr(NULL), bound_flag(false) {} | |
853 | ||
854 | /// @{ | |
855 | /** get pointer to a field */ | |
856 | virtual Base_Type* get_at(int index_value) = 0; | |
857 | virtual const Base_Type* get_at(int index_value) const = 0; | |
858 | /// @} | |
859 | ||
860 | /** get the index to a field based on its name and namespace URI, or -1 */ | |
861 | int get_index_byname(const char *name, const char *uri) const; | |
862 | ||
863 | /** get number of fields */ | |
864 | virtual int get_count() const = 0; | |
865 | /** number of optional fields */ | |
866 | virtual int optional_count() const { return 0; } | |
867 | ||
868 | /** virtual functions inherited from Base_Type */ | |
869 | boolean is_equal(const Base_Type* other_value) const; | |
870 | void set_value(const Base_Type* other_value); | |
871 | ||
872 | /** @returns \c true if this is a set type, | |
873 | * \c false if this is a record type */ | |
874 | virtual boolean is_set() const = 0; | |
875 | ||
876 | /** return the name of a field */ | |
877 | virtual const char* fld_name(int field_index) const = 0; | |
878 | ||
879 | /** return the descriptor of a field */ | |
880 | virtual const TTCN_Typedescriptor_t* fld_descr(int field_index) const = 0; | |
881 | ||
882 | /** return int array which contains the indexes of optional fields | |
883 | and a -1 value appended to the end, or return NULL if no optional fields, | |
884 | generated classes override if there are optional fields */ | |
885 | virtual const int* get_optional_indexes() const { return NULL; } | |
886 | /** default values and indexes, if no default fields then returns NULL, | |
887 | the last default_struct.index is -1 */ | |
888 | virtual const default_struct* get_default_indexes() const { return NULL; } | |
889 | ||
890 | /** override if it's TRUE for the specific type (if sdef->opentype_outermost) */ | |
891 | virtual boolean is_opentype_outermost() const { return FALSE; } | |
892 | ||
893 | virtual boolean default_as_optional() const { return FALSE; } | |
894 | ||
895 | virtual boolean is_bound() const; | |
896 | virtual boolean is_value() const; | |
897 | virtual void clean_up(); | |
898 | virtual void log() const; | |
899 | virtual void set_param(Module_Param& param); | |
3abe9331 | 900 | virtual Module_Param* get_param(Module_Param_Name& param_name) const; |
970ed795 EL |
901 | virtual void set_implicit_omit(); |
902 | ||
903 | int size_of() const; | |
904 | virtual void encode_text(Text_Buf& text_buf) const; | |
905 | virtual void decode_text(Text_Buf& text_buf); | |
906 | ||
907 | virtual void encode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, TTCN_EncDec::coding_t, ...) const; | |
908 | virtual void decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, TTCN_EncDec::coding_t, ...); | |
909 | ||
910 | virtual ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const; | |
911 | virtual ASN_BER_TLV_t* BER_encode_TLV_negtest(const Erroneous_descriptor_t* p_err_descr, | |
912 | const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const; | |
913 | virtual boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv, unsigned L_form); | |
914 | virtual void BER_decode_opentypes(TTCN_Type_list& p_typelist, unsigned L_form); | |
915 | ||
916 | virtual int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const; | |
917 | virtual int RAW_encode_negtest(const Erroneous_descriptor_t *, const TTCN_Typedescriptor_t&, RAW_enc_tree&) const; | |
918 | virtual int RAW_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, int, raw_order_t, boolean no_err = FALSE, int sel_field = -1, boolean first_call = TRUE); | |
919 | // Helper functions for RAW enc/dec, shall be overridden in descendants if the default behavior is not enough. | |
920 | virtual boolean raw_has_ext_bit() const { return FALSE; } | |
921 | ||
922 | virtual int TEXT_encode(const TTCN_Typedescriptor_t&, TTCN_Buffer&) const; | |
923 | virtual int TEXT_encode_negtest(const Erroneous_descriptor_t* p_err_descr, const TTCN_Typedescriptor_t&, TTCN_Buffer&) const; | |
924 | virtual int TEXT_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, Limit_Token_List&, boolean no_err=FALSE, boolean first_call=TRUE); | |
925 | ||
926 | virtual int XER_encode(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, | |
af710487 | 927 | unsigned int flavor, int indent, embed_values_enc_struct_t*) const; |
970ed795 EL |
928 | virtual int XER_encode_negtest(const Erroneous_descriptor_t* p_err_descr, |
929 | const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, | |
af710487 | 930 | unsigned int flavor, int indent, embed_values_enc_struct_t*) const; |
931 | virtual int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader, | |
932 | unsigned int, embed_values_dec_struct_t*); | |
970ed795 EL |
933 | /// @{ |
934 | /// Methods overridden in the derived (generated) class | |
935 | virtual int get_xer_num_attr() const { return 0; /* default */ } | |
936 | virtual const XERdescriptor_t* xer_descr(int field_index) const; | |
937 | /// @} | |
938 | virtual char ** collect_ns(const XERdescriptor_t& p_td, size_t& num, bool& def_ns) const; | |
939 | virtual boolean can_start_v(const char *name, const char *prefix, | |
940 | XERdescriptor_t const& xd, unsigned int flavor) = 0; | |
941 | ||
942 | /** Encodes accordingly to the JSON encoding rules. | |
943 | * Returns the length of the encoded data. */ | |
944 | int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const; | |
945 | ||
946 | /** Decodes accordingly to the JSON encoding rules. | |
947 | * Returns the length of the decoded data. */ | |
948 | int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean); | |
949 | ||
950 | void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; } | |
951 | Erroneous_descriptor_t* get_err_descr() const { return err_descr; } | |
952 | private: | |
953 | /// Helper for XER_encode_negtest | |
954 | int encode_field(int i, const Erroneous_values_t* err_vals, const Erroneous_descriptor_t* emb_descr, | |
af710487 | 955 | TTCN_Buffer& p_buf, unsigned int sub_flavor, int indent, embed_values_enc_struct_t* emb_val) const; |
970ed795 EL |
956 | }; |
957 | ||
958 | //////////////////////////////////////////////////////////////////////////////// | |
959 | class Empty_Record_Type : public Base_Type { | |
960 | protected: | |
961 | boolean bound_flag; | |
962 | ||
963 | Empty_Record_Type(); | |
964 | Empty_Record_Type(const Empty_Record_Type& other_value); | |
965 | ||
966 | public: | |
967 | boolean operator==(null_type other_value) const; | |
968 | inline boolean operator!=(null_type other_value) const { return !(*this == other_value); } | |
969 | ||
970 | /** virtual functions inherited from Base_Type */ | |
971 | virtual boolean is_equal(const Base_Type* other_value) const; | |
972 | virtual void set_value(const Base_Type* other_value); | |
973 | ||
974 | /** @returns \c true if this is a set type, | |
975 | * \c false if this is a record type */ | |
976 | virtual boolean is_set() const = 0; | |
977 | ||
978 | inline void set_null() { bound_flag = TRUE; } | |
979 | virtual boolean is_bound() const { return bound_flag; } | |
980 | virtual void clean_up() { bound_flag = FALSE; } | |
981 | virtual void log() const; | |
3abe9331 | 982 | virtual void set_param(Module_Param& param); |
983 | virtual Module_Param* get_param(Module_Param_Name& param_name) const; | |
970ed795 EL |
984 | |
985 | int size_of() const { return 0; } | |
986 | virtual void encode_text(Text_Buf& text_buf) const; | |
987 | virtual void decode_text(Text_Buf& text_buf); | |
988 | ||
989 | virtual void encode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, TTCN_EncDec::coding_t, ...) const; | |
990 | virtual void decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, TTCN_EncDec::coding_t, ...); | |
991 | ||
992 | virtual ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const; | |
993 | virtual boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv, unsigned L_form); | |
994 | ||
995 | virtual int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const; | |
996 | virtual int RAW_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, int, raw_order_t, boolean no_err=FALSE, int sel_field=-1, boolean first_call=TRUE); | |
997 | ||
998 | virtual int TEXT_encode(const TTCN_Typedescriptor_t&, TTCN_Buffer&) const; | |
999 | virtual int TEXT_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, Limit_Token_List&, boolean no_err=FALSE, boolean first_call=TRUE); | |
1000 | ||
1001 | virtual int XER_encode(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, | |
af710487 | 1002 | unsigned int flavor, int indent, embed_values_enc_struct_t*) const; |
1003 | virtual int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader, | |
1004 | unsigned int, embed_values_dec_struct_t*); | |
970ed795 EL |
1005 | |
1006 | /** Encodes accordingly to the JSON encoding rules. | |
1007 | * Returns the length of the encoded data. */ | |
1008 | virtual int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const; | |
1009 | ||
1010 | /** Decodes accordingly to the JSON encoding rules. | |
1011 | * Returns the length of the decoded data. */ | |
1012 | virtual int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean); | |
1013 | }; | |
1014 | ||
1015 | struct Enum_Type : public Base_Type { | |
1016 | virtual int as_int() const = 0; | |
1017 | virtual void from_int(int) = 0; | |
1018 | }; | |
1019 | ||
1020 | extern boolean operator==(null_type null_value, const Empty_Record_Type& other_value); | |
1021 | extern boolean operator!=(null_type null_value, const Empty_Record_Type& other_value); | |
1022 | ||
1023 | #undef VIRTUAL_IF_RUNTIME_2 | |
1024 | #endif | |
1025 | ||
1026 | template <class EXPR_TYPE> | |
1027 | class Lazy_Param { | |
1028 | protected: | |
1029 | bool expr_evaluated; | |
1030 | EXPR_TYPE expr_cache; | |
1031 | virtual void eval_expr() {} | |
1032 | public: | |
1033 | Lazy_Param(): expr_evaluated(false) {} | |
1034 | enum evaluated_state_t { EXPR_EVALED }; | |
1035 | Lazy_Param(evaluated_state_t /*p_es*/, EXPR_TYPE p_cache): expr_evaluated(true), expr_cache(p_cache) {} | |
1036 | operator EXPR_TYPE&() { | |
1037 | if (!expr_evaluated) { eval_expr(); expr_evaluated=true; } | |
1038 | return expr_cache; | |
1039 | } | |
1040 | virtual ~Lazy_Param() {} | |
1041 | }; | |
1042 | ||
1043 | #endif |