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