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