1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
13 #ifdef TITAN_RUNTIME_2
14 #include "Struct_of.hh"
15 struct TTCN_Typedescriptor_t;
16 struct Erroneous_descriptor_t;
23 UNINITIALIZED_TEMPLATE = -1,
29 COMPLEMENTED_LIST = 5,
42 #ifdef TITAN_RUNTIME_2
43 #define VIRTUAL_IF_RUNTIME_2 virtual
45 #define VIRTUAL_IF_RUNTIME_2
50 template_sel template_selection;
54 Base_Template(template_sel other_value);
55 // Compiler-generated copy constructor and assignment are acceptable
57 static void check_single_selection(template_sel other_value);
58 void set_selection(template_sel other_value);
59 void set_selection(const Base_Template& other_value);
61 void log_generic() const;
62 void log_ifpresent() const;
64 void encode_text_base(Text_Buf& text_buf) const;
65 void decode_text_base(Text_Buf& text_buf);
68 inline template_sel get_selection() const { return template_selection; }
72 VIRTUAL_IF_RUNTIME_2 boolean is_omit() const;
73 VIRTUAL_IF_RUNTIME_2 boolean is_any_or_omit() const;
74 /** Returns FALSE if \a template_selection is \a UNINITIALIZED_TEMPLATE,
76 VIRTUAL_IF_RUNTIME_2 boolean is_bound() const
77 { return UNINITIALIZED_TEMPLATE != template_selection; }
78 VIRTUAL_IF_RUNTIME_2 boolean is_value() const
79 { return !is_ifpresent && template_selection==SPECIFIC_VALUE; }
80 VIRTUAL_IF_RUNTIME_2 void clean_up()
81 { template_selection = UNINITIALIZED_TEMPLATE; }
82 /** return the name of template restriction \a tr */
83 static const char* get_res_name(template_res tr);
85 VIRTUAL_IF_RUNTIME_2 void set_param(Module_Param& param);
87 /** not a component by default (component templates will return true) */
88 inline boolean is_component() { return FALSE; }
90 #ifdef TITAN_RUNTIME_2
91 /** set the value of the object pointed to by \a value */
92 virtual void valueofv(Base_Type* value) const = 0;
93 virtual void set_value(template_sel other_value) = 0;
94 virtual void copy_value(const Base_Type* other_value) = 0;
96 virtual Base_Template* clone() const = 0;
97 virtual const TTCN_Typedescriptor_t* get_descriptor() const = 0;
99 virtual void log() const = 0;
101 // virtual functions for match and log_match
102 virtual boolean matchv(const Base_Type* other_value) const = 0;
103 virtual void log_matchv(const Base_Type* match_value) const = 0;
105 virtual void encode_text(Text_Buf& text_buf) const = 0;
106 virtual void decode_text(Text_Buf& text_buf) = 0;
107 virtual boolean is_present() const = 0;
108 virtual boolean match_omit() const = 0;
110 virtual void check_restriction(template_res t_res, const char* t_name=NULL) const;
112 virtual ~Base_Template() { }
116 class Restricted_Length_Template : public Base_Template {
118 enum length_restriction_type_t {
119 NO_LENGTH_RESTRICTION = 0,
120 SINGLE_LENGTH_RESTRICTION = 1,
121 RANGE_LENGTH_RESTRICTION =2
122 } length_restriction_type;
126 int min_length, max_length;
127 boolean max_length_set;
129 } length_restriction;
131 Restricted_Length_Template();
132 Restricted_Length_Template(template_sel other_value);
133 // Compiler-generated copy constructor and assignment are acceptable
135 void set_selection(template_sel new_selection);
136 void set_selection(const Restricted_Length_Template& other_value);
139 boolean match_length(int value_length) const;
142 int check_section_is_single(int min_size, boolean has_any_or_none,
143 const char* operation_name,
144 const char* type_name_prefix,
145 const char* type_name) const;
147 void log_restricted() const;
148 void log_match_length(int value_length) const;
150 void encode_text_restricted(Text_Buf& text_buf) const;
151 void decode_text_restricted(Text_Buf& text_buf);
153 void set_length_range(const Module_Param& param);
157 void set_single_length(int single_length);
158 void set_min_length(int min_length);
159 void set_max_length(int max_length);
161 boolean is_omit() const;
162 boolean is_any_or_omit() const;
164 // Dummy functions, only used in record of/set of value
165 void add_refd_index(int) {}
166 void remove_refd_index(int) {}
169 #ifndef TITAN_RUNTIME_2
171 class Record_Of_Template : public Restricted_Length_Template {
173 struct Pair_of_elements;
174 Pair_of_elements *permutation_intervals;
175 unsigned int number_of_permutations;
177 Record_Of_Template();
178 Record_Of_Template(template_sel new_selection);
179 Record_Of_Template(const Record_Of_Template& other_value);
180 ~Record_Of_Template();
182 void clean_up_intervals();
184 void set_selection(template_sel new_selection);
185 void set_selection(const Record_Of_Template& other_value);
187 void encode_text_permutation(Text_Buf& text_buf) const;
188 void decode_text_permutation(Text_Buf& text_buf);
190 Record_Of_Template& operator=(const Record_Of_Template& other_value);
193 void add_permutation(unsigned int start_index, unsigned int end_index);
195 /** Removes all permutations set on this template, used when template variables
196 * are given new values. */
197 void remove_all_permutations() { clean_up_intervals(); }
199 unsigned int get_number_of_permutations() const;
200 unsigned int get_permutation_start(unsigned int index_value) const;
201 unsigned int get_permutation_end(unsigned int index_value) const;
202 unsigned int get_permutation_size(unsigned int index_value) const;
203 boolean permutation_starts_at(unsigned int index_value) const;
204 boolean permutation_ends_at(unsigned int index_value) const;
211 class Set_Of_Template : public Restricted_Length_Template {
216 Base_Template** value_elements; // instances of a class derived from Base_Template
220 Set_Of_Template** list_value; // instances of a class derived from Set_Of_Template
223 Erroneous_descriptor_t* err_descr;
226 Set_Of_Template(template_sel new_selection);
227 /** Copy constructor not implemented */
228 Set_Of_Template(const Set_Of_Template& other_value);
229 /** Assignment disabled */
230 Set_Of_Template& operator=(const Set_Of_Template& other_value);
233 void copy_template(const Set_Of_Template& other_value);
234 void copy_optional(const Base_Type* other_value);
237 Base_Template* clone() const;
238 void copy_value(const Base_Type* other_value);
241 int size_of() const { return size_of(TRUE); }
242 int lengthof() const { return size_of(FALSE); }
244 void set_size(int new_size);
245 void set_type(template_sel template_type, int list_length);
246 boolean is_value() const;
247 void valueofv(Base_Type* value) const;
248 void set_value(template_sel other_value);
250 Base_Template* get_at(int index_value);
251 Base_Template* get_at(const INTEGER& index_value);
252 const Base_Template* get_at(int index_value) const;
253 const Base_Template* get_at(const INTEGER& index_value) const;
255 int size_of(boolean is_size) const;
256 Set_Of_Template* get_list_item(int list_index);
257 Base_Template* get_set_item(int set_index);
259 void substr_(int index, int returncount, Record_Of_Type* rec_of) const;
260 void replace_(int index, int len, const Set_Of_Template* repl, Record_Of_Type* rec_of) const;
261 void replace_(int index, int len, const Record_Of_Type* repl, Record_Of_Type* rec_of) const;
266 boolean matchv(const Base_Type* other_value) const;
267 void log_matchv(const Base_Type* match_value) const;
268 /** create an instance of this */
269 virtual Set_Of_Template* create() const = 0;
270 /** create an instance of the element class */
271 virtual Base_Template* create_elem() const = 0;
273 // used for both set of and record of types
274 static boolean match_function_specific(
275 const Base_Type *value_ptr, int value_index,
276 const Restricted_Length_Template *template_ptr, int template_index);
277 // 2 static functions only for set of types
278 static boolean match_function_set(
279 const Base_Type *value_ptr, int value_index,
280 const Restricted_Length_Template *template_ptr, int template_index);
281 static void log_function(const Base_Type *value_ptr,
282 const Restricted_Length_Template *template_ptr,
283 int index_value, int index_template);
285 void encode_text(Text_Buf& text_buf) const;
286 void decode_text(Text_Buf& text_buf);
287 boolean is_present() const;
288 boolean match_omit() const;
290 void set_param(Module_Param& param);
292 void check_restriction(template_res t_res, const char* t_name=NULL) const;
293 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
296 class Record_Of_Template : public Restricted_Length_Template {
301 Base_Template **value_elements; // instances of a class derived from Base_Template
305 Record_Of_Template** list_value; // instances of a class derived from Record_Of_Template
308 Erroneous_descriptor_t* err_descr;
310 struct Pair_of_elements;
311 Pair_of_elements *permutation_intervals;
312 unsigned int number_of_permutations;
314 Record_Of_Template();
315 Record_Of_Template(template_sel new_selection);
316 /** Copy constructor not implemented */
317 Record_Of_Template(const Record_Of_Template& other_value);
318 /** Assignment disabled */
319 Record_Of_Template& operator=(const Record_Of_Template& other_value);
320 ~Record_Of_Template();
322 void clean_up_intervals();
324 void set_selection(template_sel new_selection);
325 void set_selection(const Record_Of_Template& other_value);
327 void encode_text_permutation(Text_Buf& text_buf) const;
328 void decode_text_permutation(Text_Buf& text_buf);
330 void copy_template(const Record_Of_Template& other_value);
331 void copy_optional(const Base_Type* other_value);
334 Base_Template* clone() const;
335 void copy_value(const Base_Type* other_value);
338 void add_permutation(unsigned int start_index, unsigned int end_index);
340 /** Removes all permutations set on this template, used when template variables
341 * are given new values. */
342 void remove_all_permutations() { clean_up_intervals(); }
344 unsigned int get_number_of_permutations() const;
345 unsigned int get_permutation_start(unsigned int index_value) const;
346 unsigned int get_permutation_end(unsigned int index_value) const;
347 unsigned int get_permutation_size(unsigned int index_value) const;
348 boolean permutation_starts_at(unsigned int index_value) const;
349 boolean permutation_ends_at(unsigned int index_value) const;
351 void set_size(int new_size);
352 void set_type(template_sel template_type, int list_length);
353 boolean is_value() const;
354 void valueofv(Base_Type* value) const;
355 void set_value(template_sel other_value);
357 Base_Template* get_at(int index_value);
358 Base_Template* get_at(const INTEGER& index_value);
359 const Base_Template* get_at(int index_value) const;
360 const Base_Template* get_at(const INTEGER& index_value) const;
362 int size_of(boolean is_size) const;
363 Record_Of_Template* get_list_item(int list_index);
365 void substr_(int index, int returncount, Record_Of_Type* rec_of) const;
366 void replace_(int index, int len, const Record_Of_Template* repl, Record_Of_Type* rec_of) const;
367 void replace_(int index, int len, const Record_Of_Type* repl, Record_Of_Type* rec_of) const;
370 int size_of() const { return size_of(TRUE); }
371 int lengthof() const { return size_of(FALSE); }
375 boolean matchv(const Base_Type* other_value) const;
376 void log_matchv(const Base_Type* match_value) const;
377 /** create an instance of this */
378 virtual Record_Of_Template* create() const = 0;
379 /** create an instance of the element class */
380 virtual Base_Template* create_elem() const = 0;
382 // used for both set of and record of types
383 static boolean match_function_specific(
384 const Base_Type *value_ptr, int value_index,
385 const Restricted_Length_Template *template_ptr, int template_index);
387 void encode_text(Text_Buf& text_buf) const;
388 void decode_text(Text_Buf& text_buf);
389 boolean is_present() const;
390 boolean match_omit() const;
392 void set_param(Module_Param& param);
394 void check_restriction(template_res t_res, const char* t_name=NULL) const;
395 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
398 class Record_Template : public Base_Template
404 Base_Template** value_elements;
408 Record_Template** list_value;
411 Erroneous_descriptor_t* err_descr;
413 /** create value elements by calling their constructor */
414 virtual void set_specific() = 0;
416 void copy_optional(const Base_Type* other_value);
417 void copy_template(const Record_Template& other_value);
420 Record_Template(template_sel other_value);
421 /** Copy constructor not implemented */
422 Record_Template(const Record_Template& other_value);
423 /** Assignment disabled */
424 Record_Template& operator=(const Record_Template& other_value);
428 void copy_value(const Base_Type* other_value);
431 void set_type(template_sel template_type, int list_length);
432 Record_Template* get_list_item(int list_index) const;
436 boolean is_value() const;
437 void valueofv(Base_Type* value) const;
438 void set_value(template_sel other_value);
441 Base_Template* get_at(int index_value);
442 const Base_Template* get_at(int index_value) const;
444 /** create an instance by calling the default constructor */
445 virtual Record_Template* create() const = 0;
447 virtual const char* fld_name(int /*field_index*/) const { return ""; }
450 Base_Template* clone() const;
454 boolean matchv(const Base_Type* other_value) const;
455 void log_matchv(const Base_Type* match_value) const;
457 void encode_text(Text_Buf& text_buf) const;
458 void decode_text(Text_Buf& text_buf);
459 boolean is_present() const;
460 boolean match_omit() const;
462 void set_param(Module_Param& param);
464 void check_restriction(template_res t_res, const char* t_name=NULL) const;
465 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
468 class Empty_Record_Template : public Base_Template
473 Empty_Record_Template** list_value;
476 void copy_optional(const Base_Type* other_value);
477 void copy_template(const Empty_Record_Template& other_value);
479 Empty_Record_Template();
480 Empty_Record_Template(template_sel other_value);
481 /** Copy constructor not implemented */
482 Empty_Record_Template(const Empty_Record_Template& other_value);
483 /** Assignment disabled */
484 Empty_Record_Template& operator=(const Empty_Record_Template& other_value);
485 ~Empty_Record_Template();
488 void copy_value(const Base_Type* other_value);
491 void set_type(template_sel template_type, int list_length);
492 Empty_Record_Template* get_list_item(int list_index) const;
496 boolean is_value() const;
497 void valueofv(Base_Type* value) const;
498 void set_value(template_sel other_value);
501 /** create an instance by calling the default constructor */
502 virtual Empty_Record_Template* create() const = 0;
505 Base_Template* clone() const;
509 boolean matchv(const Base_Type* other_value) const;
510 void log_matchv(const Base_Type* match_value) const;
512 void encode_text(Text_Buf& text_buf) const;
513 void decode_text(Text_Buf& text_buf);
514 boolean is_present() const;
515 boolean match_omit() const;
517 void set_param(Module_Param& param);
520 #undef VIRTUAL_IF_RUNTIME_2