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
17 * Szabo, Janos Zoltan – initial implementation
19 * Zalanyi, Balazs Andor
21 ******************************************************************************/
27 #ifdef TITAN_RUNTIME_2
28 #include "Struct_of.hh"
29 #include "RefdIndex.hh"
30 struct TTCN_Typedescriptor_t;
31 struct Erroneous_descriptor_t;
36 class Module_Param_Name;
37 class Module_Param_Length_Restriction;
40 UNINITIALIZED_TEMPLATE = -1,
46 COMPLEMENTED_LIST = 5,
59 #ifdef TITAN_RUNTIME_2
60 #define VIRTUAL_IF_RUNTIME_2 virtual
62 #define VIRTUAL_IF_RUNTIME_2
67 template_sel template_selection;
71 Base_Template(template_sel other_value);
72 // Compiler-generated copy constructor and assignment are acceptable
74 static void check_single_selection(template_sel other_value);
75 void set_selection(template_sel other_value);
76 void set_selection(const Base_Template& other_value);
78 void log_generic() const;
79 void log_ifpresent() const;
81 void encode_text_base(Text_Buf& text_buf) const;
82 void decode_text_base(Text_Buf& text_buf);
85 inline template_sel get_selection() const { return template_selection; }
89 VIRTUAL_IF_RUNTIME_2 boolean is_omit() const;
90 VIRTUAL_IF_RUNTIME_2 boolean is_any_or_omit() const;
91 /** Returns FALSE if \a template_selection is \a UNINITIALIZED_TEMPLATE,
93 VIRTUAL_IF_RUNTIME_2 boolean is_bound() const
94 { return UNINITIALIZED_TEMPLATE != template_selection; }
95 VIRTUAL_IF_RUNTIME_2 boolean is_value() const
96 { return !is_ifpresent && template_selection==SPECIFIC_VALUE; }
97 VIRTUAL_IF_RUNTIME_2 void clean_up()
98 { template_selection = UNINITIALIZED_TEMPLATE; }
99 /** return the name of template restriction \a tr */
100 static const char* get_res_name(template_res tr);
102 /** Initialize this object (or one of its fields/elements) with a
103 * module parameter value. The module parameter may contain references to
104 * other module parameters or module parameter expressions, which are processed
105 * by this method to calculated the final result.
106 * @note Sets the 'ifpresent' flag if either the reference (if any) or the
107 * (referenced) module parameter value have their 'ifpresent' flag
108 * @note If both the reference (if any) and the (referenced) module parameter
109 * have a length restriction, then the reference's length restriction is used.
110 * @note A temporary object is used when setting VALUE_LIST or COMPLEMENT_LIST
111 * templates, as the list of templates might contain a reference to this object.
112 * @param param module parameter value (its ID specifies which object is to be set) */
113 VIRTUAL_IF_RUNTIME_2 void set_param(Module_Param& param);
114 /** Create a module parameter value equivalent to this object (or one of its
116 * @param param_name module parameter ID, specifies which object to convert */
117 VIRTUAL_IF_RUNTIME_2 Module_Param* get_param(Module_Param_Name& param_name) const;
119 /** not a component by default (component templates will return true) */
120 inline boolean is_component() { return FALSE; }
122 #ifdef TITAN_RUNTIME_2
123 /** set the value of the object pointed to by \a value */
124 virtual void valueofv(Base_Type* value) const = 0;
125 virtual void set_value(template_sel other_value) = 0;
126 virtual void copy_value(const Base_Type* other_value) = 0;
128 virtual Base_Template* clone() const = 0;
129 virtual const TTCN_Typedescriptor_t* get_descriptor() const = 0;
131 virtual void log() const = 0;
133 // virtual functions for match and log_match
134 virtual boolean matchv(const Base_Type* other_value, boolean legacy) const = 0;
135 virtual void log_matchv(const Base_Type* match_value, boolean legacy) const = 0;
137 virtual void encode_text(Text_Buf& text_buf) const = 0;
138 virtual void decode_text(Text_Buf& text_buf) = 0;
139 virtual boolean is_present(boolean legacy = FALSE) const = 0;
140 virtual boolean match_omit(boolean legacy = FALSE) const = 0;
142 virtual void check_restriction(template_res t_res, const char* t_name=NULL,
143 boolean legacy = FALSE) const;
145 virtual ~Base_Template() { }
149 class Restricted_Length_Template : public Base_Template
150 #ifdef TITAN_RUNTIME_2
151 , public RefdIndexInterface
155 enum length_restriction_type_t {
156 NO_LENGTH_RESTRICTION = 0,
157 SINGLE_LENGTH_RESTRICTION = 1,
158 RANGE_LENGTH_RESTRICTION =2
159 } length_restriction_type;
163 int min_length, max_length;
164 boolean max_length_set;
166 } length_restriction;
168 Restricted_Length_Template();
169 Restricted_Length_Template(template_sel other_value);
170 // Compiler-generated copy constructor and assignment are acceptable
172 void set_selection(template_sel new_selection);
173 void set_selection(const Restricted_Length_Template& other_value);
176 boolean match_length(int value_length) const;
179 int check_section_is_single(int min_size, boolean has_any_or_none,
180 const char* operation_name,
181 const char* type_name_prefix,
182 const char* type_name) const;
184 void log_restricted() const;
185 void log_match_length(int value_length) const;
187 void encode_text_restricted(Text_Buf& text_buf) const;
188 void decode_text_restricted(Text_Buf& text_buf);
190 void set_length_range(const Module_Param& param);
191 Module_Param_Length_Restriction* get_length_range() const;
195 void set_single_length(int single_length);
196 void set_min_length(int min_length);
197 void set_max_length(int max_length);
199 boolean is_omit() const;
200 boolean is_any_or_omit() const;
203 #ifndef TITAN_RUNTIME_2
205 class Record_Of_Template : public Restricted_Length_Template {
207 struct Pair_of_elements;
208 Pair_of_elements *permutation_intervals;
209 unsigned int number_of_permutations;
211 Record_Of_Template();
212 Record_Of_Template(template_sel new_selection);
213 Record_Of_Template(const Record_Of_Template& other_value);
214 ~Record_Of_Template();
216 void clean_up_intervals();
218 void set_selection(template_sel new_selection);
219 void set_selection(const Record_Of_Template& other_value);
221 void encode_text_permutation(Text_Buf& text_buf) const;
222 void decode_text_permutation(Text_Buf& text_buf);
224 Record_Of_Template& operator=(const Record_Of_Template& other_value);
227 void add_permutation(unsigned int start_index, unsigned int end_index);
229 /** Removes all permutations set on this template, used when template variables
230 * are given new values. */
231 void remove_all_permutations() { clean_up_intervals(); }
233 unsigned int get_number_of_permutations() const;
234 unsigned int get_permutation_start(unsigned int index_value) const;
235 unsigned int get_permutation_end(unsigned int index_value) const;
236 unsigned int get_permutation_size(unsigned int index_value) const;
237 boolean permutation_starts_at(unsigned int index_value) const;
238 boolean permutation_ends_at(unsigned int index_value) const;
245 class Set_Of_Template : public Restricted_Length_Template {
250 Base_Template** value_elements; // instances of a class derived from Base_Template
254 Set_Of_Template** list_value; // instances of a class derived from Set_Of_Template
257 Erroneous_descriptor_t* err_descr;
260 Set_Of_Template(template_sel new_selection);
261 /** Copy constructor not implemented */
262 Set_Of_Template(const Set_Of_Template& other_value);
263 /** Assignment disabled */
264 Set_Of_Template& operator=(const Set_Of_Template& other_value);
267 void copy_template(const Set_Of_Template& other_value);
268 void copy_optional(const Base_Type* other_value);
271 Base_Template* clone() const;
272 void copy_value(const Base_Type* other_value);
275 int size_of() const { return size_of(TRUE); }
276 int lengthof() const { return size_of(FALSE); }
278 void set_size(int new_size);
279 void set_type(template_sel template_type, int list_length);
280 boolean is_value() const;
281 void valueofv(Base_Type* value) const;
282 void set_value(template_sel other_value);
284 Base_Template* get_at(int index_value);
285 Base_Template* get_at(const INTEGER& index_value);
286 const Base_Template* get_at(int index_value) const;
287 const Base_Template* get_at(const INTEGER& index_value) const;
289 int size_of(boolean is_size) const;
290 Set_Of_Template* get_list_item(int list_index);
291 Base_Template* get_set_item(int set_index);
293 void substr_(int index, int returncount, Record_Of_Type* rec_of) const;
294 void replace_(int index, int len, const Set_Of_Template* repl, Record_Of_Type* rec_of) const;
295 void replace_(int index, int len, const Record_Of_Type* repl, Record_Of_Type* rec_of) const;
300 boolean matchv(const Base_Type* other_value, boolean legacy) const;
301 void log_matchv(const Base_Type* match_value, boolean legacy) const;
302 /** create an instance of this */
303 virtual Set_Of_Template* create() const = 0;
304 /** create an instance of the element class */
305 virtual Base_Template* create_elem() const = 0;
307 // used for both set of and record of types
308 static boolean match_function_specific(
309 const Base_Type *value_ptr, int value_index,
310 const Restricted_Length_Template *template_ptr, int template_index,
312 // 2 static functions only for set of types
313 static boolean match_function_set(
314 const Base_Type *value_ptr, int value_index,
315 const Restricted_Length_Template *template_ptr, int template_index,
317 static void log_function(const Base_Type *value_ptr,
318 const Restricted_Length_Template *template_ptr,
319 int index_value, int index_template, boolean legacy);
321 void encode_text(Text_Buf& text_buf) const;
322 void decode_text(Text_Buf& text_buf);
323 boolean is_present(boolean legacy = FALSE) const;
324 boolean match_omit(boolean legacy = FALSE) const;
326 void set_param(Module_Param& param);
327 Module_Param* get_param(Module_Param_Name& param_name) const;
329 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
330 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
333 class Record_Of_Template : public Restricted_Length_Template {
338 Base_Template **value_elements; // instances of a class derived from Base_Template
342 Record_Of_Template** list_value; // instances of a class derived from Record_Of_Template
345 Erroneous_descriptor_t* err_descr;
347 struct Pair_of_elements;
348 Pair_of_elements *permutation_intervals;
349 unsigned int number_of_permutations;
351 Record_Of_Template();
352 Record_Of_Template(template_sel new_selection);
353 /** Copy constructor not implemented */
354 Record_Of_Template(const Record_Of_Template& other_value);
355 /** Assignment disabled */
356 Record_Of_Template& operator=(const Record_Of_Template& other_value);
357 ~Record_Of_Template();
359 void clean_up_intervals();
361 void set_selection(template_sel new_selection);
362 void set_selection(const Record_Of_Template& other_value);
364 void encode_text_permutation(Text_Buf& text_buf) const;
365 void decode_text_permutation(Text_Buf& text_buf);
367 void copy_template(const Record_Of_Template& other_value);
368 void copy_optional(const Base_Type* other_value);
371 Base_Template* clone() const;
372 void copy_value(const Base_Type* other_value);
375 void add_permutation(unsigned int start_index, unsigned int end_index);
377 /** Removes all permutations set on this template, used when template variables
378 * are given new values. */
379 void remove_all_permutations() { clean_up_intervals(); }
381 unsigned int get_number_of_permutations() const;
382 unsigned int get_permutation_start(unsigned int index_value) const;
383 unsigned int get_permutation_end(unsigned int index_value) const;
384 unsigned int get_permutation_size(unsigned int index_value) const;
385 boolean permutation_starts_at(unsigned int index_value) const;
386 boolean permutation_ends_at(unsigned int index_value) const;
388 void set_size(int new_size);
389 void set_type(template_sel template_type, int list_length);
390 boolean is_value() const;
391 void valueofv(Base_Type* value) const;
392 void set_value(template_sel other_value);
394 Base_Template* get_at(int index_value);
395 Base_Template* get_at(const INTEGER& index_value);
396 const Base_Template* get_at(int index_value) const;
397 const Base_Template* get_at(const INTEGER& index_value) const;
399 int size_of(boolean is_size) const;
400 Record_Of_Template* get_list_item(int list_index);
402 void substr_(int index, int returncount, Record_Of_Type* rec_of) const;
403 void replace_(int index, int len, const Record_Of_Template* repl, Record_Of_Type* rec_of) const;
404 void replace_(int index, int len, const Record_Of_Type* repl, Record_Of_Type* rec_of) const;
407 int size_of() const { return size_of(TRUE); }
408 int lengthof() const { return size_of(FALSE); }
412 boolean matchv(const Base_Type* other_value, boolean legacy) const;
413 void log_matchv(const Base_Type* match_value, boolean legacy) const;
414 /** create an instance of this */
415 virtual Record_Of_Template* create() const = 0;
416 /** create an instance of the element class */
417 virtual Base_Template* create_elem() const = 0;
419 // used for both set of and record of types
420 static boolean match_function_specific(
421 const Base_Type *value_ptr, int value_index,
422 const Restricted_Length_Template *template_ptr, int template_index, boolean legacy);
424 void encode_text(Text_Buf& text_buf) const;
425 void decode_text(Text_Buf& text_buf);
426 boolean is_present(boolean legacy = FALSE) const;
427 boolean match_omit(boolean legacy = FALSE) const;
429 void set_param(Module_Param& param);
430 Module_Param* get_param(Module_Param_Name& param_name) const;
432 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
433 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
436 class Record_Template : public Base_Template
442 Base_Template** value_elements;
446 Record_Template** list_value;
449 Erroneous_descriptor_t* err_descr;
451 /** create value elements by calling their constructor */
452 virtual void set_specific() = 0;
454 void copy_optional(const Base_Type* other_value);
455 void copy_template(const Record_Template& other_value);
458 Record_Template(template_sel other_value);
459 /** Copy constructor not implemented */
460 Record_Template(const Record_Template& other_value);
461 /** Assignment disabled */
462 Record_Template& operator=(const Record_Template& other_value);
466 void copy_value(const Base_Type* other_value);
469 void set_type(template_sel template_type, int list_length);
470 Record_Template* get_list_item(int list_index) const;
474 boolean is_value() const;
475 void valueofv(Base_Type* value) const;
476 void set_value(template_sel other_value);
479 Base_Template* get_at(int index_value);
480 const Base_Template* get_at(int index_value) const;
482 /** create an instance by calling the default constructor */
483 virtual Record_Template* create() const = 0;
485 virtual const char* fld_name(int /*field_index*/) const { return ""; }
488 Base_Template* clone() const;
492 boolean matchv(const Base_Type* other_value, boolean legacy) const;
493 void log_matchv(const Base_Type* match_value, boolean legacy) const;
495 void encode_text(Text_Buf& text_buf) const;
496 void decode_text(Text_Buf& text_buf);
497 boolean is_present(boolean legacy = FALSE) const;
498 boolean match_omit(boolean legacy = FALSE) const;
500 void set_param(Module_Param& param);
501 Module_Param* get_param(Module_Param_Name& param_name) const;
503 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
504 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
507 class Empty_Record_Template : public Base_Template
512 Empty_Record_Template** list_value;
515 void copy_optional(const Base_Type* other_value);
516 void copy_template(const Empty_Record_Template& other_value);
518 Empty_Record_Template();
519 Empty_Record_Template(template_sel other_value);
520 /** Copy constructor not implemented */
521 Empty_Record_Template(const Empty_Record_Template& other_value);
522 /** Assignment disabled */
523 Empty_Record_Template& operator=(const Empty_Record_Template& other_value);
524 ~Empty_Record_Template();
527 void copy_value(const Base_Type* other_value);
530 void set_type(template_sel template_type, int list_length);
531 Empty_Record_Template* get_list_item(int list_index) const;
535 boolean is_value() const;
536 void valueofv(Base_Type* value) const;
537 void set_value(template_sel other_value);
540 /** create an instance by calling the default constructor */
541 virtual Empty_Record_Template* create() const = 0;
544 Base_Template* clone() const;
548 boolean matchv(const Base_Type* other_value, boolean legacy) const;
549 void log_matchv(const Base_Type* match_value, boolean legacy) const;
551 void encode_text(Text_Buf& text_buf) const;
552 void decode_text(Text_Buf& text_buf);
553 boolean is_present(boolean legacy = FALSE) const;
554 boolean match_omit(boolean legacy = FALSE) const;
556 void set_param(Module_Param& param);
557 Module_Param* get_param(Module_Param_Name& param_name) const;
560 #undef VIRTUAL_IF_RUNTIME_2