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