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 #include "RefdIndex.hh"
16 struct TTCN_Typedescriptor_t;
17 struct Erroneous_descriptor_t;
24 UNINITIALIZED_TEMPLATE = -1,
30 COMPLEMENTED_LIST = 5,
43 #ifdef TITAN_RUNTIME_2
44 #define VIRTUAL_IF_RUNTIME_2 virtual
46 #define VIRTUAL_IF_RUNTIME_2
51 template_sel template_selection;
55 Base_Template(template_sel other_value);
56 // Compiler-generated copy constructor and assignment are acceptable
58 static void check_single_selection(template_sel other_value);
59 void set_selection(template_sel other_value);
60 void set_selection(const Base_Template& other_value);
62 void log_generic() const;
63 void log_ifpresent() const;
65 void encode_text_base(Text_Buf& text_buf) const;
66 void decode_text_base(Text_Buf& text_buf);
69 inline template_sel get_selection() const { return template_selection; }
73 VIRTUAL_IF_RUNTIME_2 boolean is_omit() const;
74 VIRTUAL_IF_RUNTIME_2 boolean is_any_or_omit() const;
75 /** Returns FALSE if \a template_selection is \a UNINITIALIZED_TEMPLATE,
77 VIRTUAL_IF_RUNTIME_2 boolean is_bound() const
78 { return UNINITIALIZED_TEMPLATE != template_selection; }
79 VIRTUAL_IF_RUNTIME_2 boolean is_value() const
80 { return !is_ifpresent && template_selection==SPECIFIC_VALUE; }
81 VIRTUAL_IF_RUNTIME_2 void clean_up()
82 { template_selection = UNINITIALIZED_TEMPLATE; }
83 /** return the name of template restriction \a tr */
84 static const char* get_res_name(template_res tr);
86 VIRTUAL_IF_RUNTIME_2 void set_param(Module_Param& param);
88 /** not a component by default (component templates will return true) */
89 inline boolean is_component() { return FALSE; }
91 #ifdef TITAN_RUNTIME_2
92 /** set the value of the object pointed to by \a value */
93 virtual void valueofv(Base_Type* value) const = 0;
94 virtual void set_value(template_sel other_value) = 0;
95 virtual void copy_value(const Base_Type* other_value) = 0;
97 virtual Base_Template* clone() const = 0;
98 virtual const TTCN_Typedescriptor_t* get_descriptor() const = 0;
100 virtual void log() const = 0;
102 // virtual functions for match and log_match
103 virtual boolean matchv(const Base_Type* other_value) const = 0;
104 virtual void log_matchv(const Base_Type* match_value) const = 0;
106 virtual void encode_text(Text_Buf& text_buf) const = 0;
107 virtual void decode_text(Text_Buf& text_buf) = 0;
108 virtual boolean is_present() const = 0;
109 virtual boolean match_omit() const = 0;
111 virtual void check_restriction(template_res t_res, const char* t_name=NULL) const;
113 virtual ~Base_Template() { }
117 class Restricted_Length_Template : public Base_Template
118 #ifdef TITAN_RUNTIME_2
119 , public RefdIndexInterface
123 enum length_restriction_type_t {
124 NO_LENGTH_RESTRICTION = 0,
125 SINGLE_LENGTH_RESTRICTION = 1,
126 RANGE_LENGTH_RESTRICTION =2
127 } length_restriction_type;
131 int min_length, max_length;
132 boolean max_length_set;
134 } length_restriction;
136 Restricted_Length_Template();
137 Restricted_Length_Template(template_sel other_value);
138 // Compiler-generated copy constructor and assignment are acceptable
140 void set_selection(template_sel new_selection);
141 void set_selection(const Restricted_Length_Template& other_value);
144 boolean match_length(int value_length) const;
147 int check_section_is_single(int min_size, boolean has_any_or_none,
148 const char* operation_name,
149 const char* type_name_prefix,
150 const char* type_name) const;
152 void log_restricted() const;
153 void log_match_length(int value_length) const;
155 void encode_text_restricted(Text_Buf& text_buf) const;
156 void decode_text_restricted(Text_Buf& text_buf);
158 void set_length_range(const Module_Param& param);
162 void set_single_length(int single_length);
163 void set_min_length(int min_length);
164 void set_max_length(int max_length);
166 boolean is_omit() const;
167 boolean is_any_or_omit() const;
170 #ifndef TITAN_RUNTIME_2
172 class Record_Of_Template : public Restricted_Length_Template {
174 struct Pair_of_elements;
175 Pair_of_elements *permutation_intervals;
176 unsigned int number_of_permutations;
178 Record_Of_Template();
179 Record_Of_Template(template_sel new_selection);
180 Record_Of_Template(const Record_Of_Template& other_value);
181 ~Record_Of_Template();
183 void clean_up_intervals();
185 void set_selection(template_sel new_selection);
186 void set_selection(const Record_Of_Template& other_value);
188 void encode_text_permutation(Text_Buf& text_buf) const;
189 void decode_text_permutation(Text_Buf& text_buf);
191 Record_Of_Template& operator=(const Record_Of_Template& other_value);
194 void add_permutation(unsigned int start_index, unsigned int end_index);
196 /** Removes all permutations set on this template, used when template variables
197 * are given new values. */
198 void remove_all_permutations() { clean_up_intervals(); }
200 unsigned int get_number_of_permutations() const;
201 unsigned int get_permutation_start(unsigned int index_value) const;
202 unsigned int get_permutation_end(unsigned int index_value) const;
203 unsigned int get_permutation_size(unsigned int index_value) const;
204 boolean permutation_starts_at(unsigned int index_value) const;
205 boolean permutation_ends_at(unsigned int index_value) const;
212 class Set_Of_Template : public Restricted_Length_Template {
217 Base_Template** value_elements; // instances of a class derived from Base_Template
221 Set_Of_Template** list_value; // instances of a class derived from Set_Of_Template
224 Erroneous_descriptor_t* err_descr;
227 Set_Of_Template(template_sel new_selection);
228 /** Copy constructor not implemented */
229 Set_Of_Template(const Set_Of_Template& other_value);
230 /** Assignment disabled */
231 Set_Of_Template& operator=(const Set_Of_Template& other_value);
234 void copy_template(const Set_Of_Template& other_value);
235 void copy_optional(const Base_Type* other_value);
238 Base_Template* clone() const;
239 void copy_value(const Base_Type* other_value);
242 int size_of() const { return size_of(TRUE); }
243 int lengthof() const { return size_of(FALSE); }
245 void set_size(int new_size);
246 void set_type(template_sel template_type, int list_length);
247 boolean is_value() const;
248 void valueofv(Base_Type* value) const;
249 void set_value(template_sel other_value);
251 Base_Template* get_at(int index_value);
252 Base_Template* get_at(const INTEGER& index_value);
253 const Base_Template* get_at(int index_value) const;
254 const Base_Template* get_at(const INTEGER& index_value) const;
256 int size_of(boolean is_size) const;
257 Set_Of_Template* get_list_item(int list_index);
258 Base_Template* get_set_item(int set_index);
260 void substr_(int index, int returncount, Record_Of_Type* rec_of) const;
261 void replace_(int index, int len, const Set_Of_Template* repl, Record_Of_Type* rec_of) const;
262 void replace_(int index, int len, const Record_Of_Type* repl, Record_Of_Type* rec_of) const;
267 boolean matchv(const Base_Type* other_value) const;
268 void log_matchv(const Base_Type* match_value) const;
269 /** create an instance of this */
270 virtual Set_Of_Template* create() const = 0;
271 /** create an instance of the element class */
272 virtual Base_Template* create_elem() const = 0;
274 // used for both set of and record of types
275 static boolean match_function_specific(
276 const Base_Type *value_ptr, int value_index,
277 const Restricted_Length_Template *template_ptr, int template_index);
278 // 2 static functions only for set of types
279 static boolean match_function_set(
280 const Base_Type *value_ptr, int value_index,
281 const Restricted_Length_Template *template_ptr, int template_index);
282 static void log_function(const Base_Type *value_ptr,
283 const Restricted_Length_Template *template_ptr,
284 int index_value, int index_template);
286 void encode_text(Text_Buf& text_buf) const;
287 void decode_text(Text_Buf& text_buf);
288 boolean is_present() const;
289 boolean match_omit() const;
291 void set_param(Module_Param& param);
293 void check_restriction(template_res t_res, const char* t_name=NULL) const;
294 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
297 class Record_Of_Template : public Restricted_Length_Template {
302 Base_Template **value_elements; // instances of a class derived from Base_Template
306 Record_Of_Template** list_value; // instances of a class derived from Record_Of_Template
309 Erroneous_descriptor_t* err_descr;
311 struct Pair_of_elements;
312 Pair_of_elements *permutation_intervals;
313 unsigned int number_of_permutations;
315 Record_Of_Template();
316 Record_Of_Template(template_sel new_selection);
317 /** Copy constructor not implemented */
318 Record_Of_Template(const Record_Of_Template& other_value);
319 /** Assignment disabled */
320 Record_Of_Template& operator=(const Record_Of_Template& other_value);
321 ~Record_Of_Template();
323 void clean_up_intervals();
325 void set_selection(template_sel new_selection);
326 void set_selection(const Record_Of_Template& other_value);
328 void encode_text_permutation(Text_Buf& text_buf) const;
329 void decode_text_permutation(Text_Buf& text_buf);
331 void copy_template(const Record_Of_Template& other_value);
332 void copy_optional(const Base_Type* other_value);
335 Base_Template* clone() const;
336 void copy_value(const Base_Type* other_value);
339 void add_permutation(unsigned int start_index, unsigned int end_index);
341 /** Removes all permutations set on this template, used when template variables
342 * are given new values. */
343 void remove_all_permutations() { clean_up_intervals(); }
345 unsigned int get_number_of_permutations() const;
346 unsigned int get_permutation_start(unsigned int index_value) const;
347 unsigned int get_permutation_end(unsigned int index_value) const;
348 unsigned int get_permutation_size(unsigned int index_value) const;
349 boolean permutation_starts_at(unsigned int index_value) const;
350 boolean permutation_ends_at(unsigned int index_value) const;
352 void set_size(int new_size);
353 void set_type(template_sel template_type, int list_length);
354 boolean is_value() const;
355 void valueofv(Base_Type* value) const;
356 void set_value(template_sel other_value);
358 Base_Template* get_at(int index_value);
359 Base_Template* get_at(const INTEGER& index_value);
360 const Base_Template* get_at(int index_value) const;
361 const Base_Template* get_at(const INTEGER& index_value) const;
363 int size_of(boolean is_size) const;
364 Record_Of_Template* get_list_item(int list_index);
366 void substr_(int index, int returncount, Record_Of_Type* rec_of) const;
367 void replace_(int index, int len, const Record_Of_Template* repl, Record_Of_Type* rec_of) const;
368 void replace_(int index, int len, const Record_Of_Type* repl, Record_Of_Type* rec_of) const;
371 int size_of() const { return size_of(TRUE); }
372 int lengthof() const { return size_of(FALSE); }
376 boolean matchv(const Base_Type* other_value) const;
377 void log_matchv(const Base_Type* match_value) const;
378 /** create an instance of this */
379 virtual Record_Of_Template* create() const = 0;
380 /** create an instance of the element class */
381 virtual Base_Template* create_elem() const = 0;
383 // used for both set of and record of types
384 static boolean match_function_specific(
385 const Base_Type *value_ptr, int value_index,
386 const Restricted_Length_Template *template_ptr, int template_index);
388 void encode_text(Text_Buf& text_buf) const;
389 void decode_text(Text_Buf& text_buf);
390 boolean is_present() const;
391 boolean match_omit() const;
393 void set_param(Module_Param& param);
395 void check_restriction(template_res t_res, const char* t_name=NULL) const;
396 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
399 class Record_Template : public Base_Template
405 Base_Template** value_elements;
409 Record_Template** list_value;
412 Erroneous_descriptor_t* err_descr;
414 /** create value elements by calling their constructor */
415 virtual void set_specific() = 0;
417 void copy_optional(const Base_Type* other_value);
418 void copy_template(const Record_Template& other_value);
421 Record_Template(template_sel other_value);
422 /** Copy constructor not implemented */
423 Record_Template(const Record_Template& other_value);
424 /** Assignment disabled */
425 Record_Template& operator=(const Record_Template& other_value);
429 void copy_value(const Base_Type* other_value);
432 void set_type(template_sel template_type, int list_length);
433 Record_Template* get_list_item(int list_index) const;
437 boolean is_value() const;
438 void valueofv(Base_Type* value) const;
439 void set_value(template_sel other_value);
442 Base_Template* get_at(int index_value);
443 const Base_Template* get_at(int index_value) const;
445 /** create an instance by calling the default constructor */
446 virtual Record_Template* create() const = 0;
448 virtual const char* fld_name(int /*field_index*/) const { return ""; }
451 Base_Template* clone() const;
455 boolean matchv(const Base_Type* other_value) const;
456 void log_matchv(const Base_Type* match_value) const;
458 void encode_text(Text_Buf& text_buf) const;
459 void decode_text(Text_Buf& text_buf);
460 boolean is_present() const;
461 boolean match_omit() const;
463 void set_param(Module_Param& param);
465 void check_restriction(template_res t_res, const char* t_name=NULL) const;
466 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
469 class Empty_Record_Template : public Base_Template
474 Empty_Record_Template** list_value;
477 void copy_optional(const Base_Type* other_value);
478 void copy_template(const Empty_Record_Template& other_value);
480 Empty_Record_Template();
481 Empty_Record_Template(template_sel other_value);
482 /** Copy constructor not implemented */
483 Empty_Record_Template(const Empty_Record_Template& other_value);
484 /** Assignment disabled */
485 Empty_Record_Template& operator=(const Empty_Record_Template& other_value);
486 ~Empty_Record_Template();
489 void copy_value(const Base_Type* other_value);
492 void set_type(template_sel template_type, int list_length);
493 Empty_Record_Template* get_list_item(int list_index) const;
497 boolean is_value() const;
498 void valueofv(Base_Type* value) const;
499 void set_value(template_sel other_value);
502 /** create an instance by calling the default constructor */
503 virtual Empty_Record_Template* create() const = 0;
506 Base_Template* clone() const;
510 boolean matchv(const Base_Type* other_value) const;
511 void log_matchv(const Base_Type* match_value) const;
513 void encode_text(Text_Buf& text_buf) const;
514 void decode_text(Text_Buf& text_buf);
515 boolean is_present() const;
516 boolean match_omit() const;
518 void set_param(Module_Param& param);
521 #undef VIRTUAL_IF_RUNTIME_2