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