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 #ifdef TITAN_RUNTIME_2
165 // Dummy functions, only used in record of/set of value in RT2
166 void add_refd_index(int) {}
167 void remove_refd_index(int) {}
171 #ifndef TITAN_RUNTIME_2
173 class Record_Of_Template : public Restricted_Length_Template {
175 struct Pair_of_elements;
176 Pair_of_elements *permutation_intervals;
177 unsigned int number_of_permutations;
179 Record_Of_Template();
180 Record_Of_Template(template_sel new_selection);
181 Record_Of_Template(const Record_Of_Template& other_value);
182 ~Record_Of_Template();
184 void clean_up_intervals();
186 void set_selection(template_sel new_selection);
187 void set_selection(const Record_Of_Template& other_value);
189 void encode_text_permutation(Text_Buf& text_buf) const;
190 void decode_text_permutation(Text_Buf& text_buf);
192 Record_Of_Template& operator=(const Record_Of_Template& other_value);
195 void add_permutation(unsigned int start_index, unsigned int end_index);
197 /** Removes all permutations set on this template, used when template variables
198 * are given new values. */
199 void remove_all_permutations() { clean_up_intervals(); }
201 unsigned int get_number_of_permutations() const;
202 unsigned int get_permutation_start(unsigned int index_value) const;
203 unsigned int get_permutation_end(unsigned int index_value) const;
204 unsigned int get_permutation_size(unsigned int index_value) const;
205 boolean permutation_starts_at(unsigned int index_value) const;
206 boolean permutation_ends_at(unsigned int index_value) const;
213 class Set_Of_Template : public Restricted_Length_Template {
218 Base_Template** value_elements; // instances of a class derived from Base_Template
222 Set_Of_Template** list_value; // instances of a class derived from Set_Of_Template
225 Erroneous_descriptor_t* err_descr;
228 Set_Of_Template(template_sel new_selection);
229 /** Copy constructor not implemented */
230 Set_Of_Template(const Set_Of_Template& other_value);
231 /** Assignment disabled */
232 Set_Of_Template& operator=(const Set_Of_Template& other_value);
235 void copy_template(const Set_Of_Template& other_value);
236 void copy_optional(const Base_Type* other_value);
239 Base_Template* clone() const;
240 void copy_value(const Base_Type* other_value);
243 int size_of() const { return size_of(TRUE); }
244 int lengthof() const { return size_of(FALSE); }
246 void set_size(int new_size);
247 void set_type(template_sel template_type, int list_length);
248 boolean is_value() const;
249 void valueofv(Base_Type* value) const;
250 void set_value(template_sel other_value);
252 Base_Template* get_at(int index_value);
253 Base_Template* get_at(const INTEGER& index_value);
254 const Base_Template* get_at(int index_value) const;
255 const Base_Template* get_at(const INTEGER& index_value) const;
257 int size_of(boolean is_size) const;
258 Set_Of_Template* get_list_item(int list_index);
259 Base_Template* get_set_item(int set_index);
261 void substr_(int index, int returncount, Record_Of_Type* rec_of) const;
262 void replace_(int index, int len, const Set_Of_Template* repl, Record_Of_Type* rec_of) const;
263 void replace_(int index, int len, const Record_Of_Type* repl, Record_Of_Type* rec_of) const;
268 boolean matchv(const Base_Type* other_value) const;
269 void log_matchv(const Base_Type* match_value) const;
270 /** create an instance of this */
271 virtual Set_Of_Template* create() const = 0;
272 /** create an instance of the element class */
273 virtual Base_Template* create_elem() const = 0;
275 // used for both set of and record of types
276 static boolean match_function_specific(
277 const Base_Type *value_ptr, int value_index,
278 const Restricted_Length_Template *template_ptr, int template_index);
279 // 2 static functions only for set of types
280 static boolean match_function_set(
281 const Base_Type *value_ptr, int value_index,
282 const Restricted_Length_Template *template_ptr, int template_index);
283 static void log_function(const Base_Type *value_ptr,
284 const Restricted_Length_Template *template_ptr,
285 int index_value, int index_template);
287 void encode_text(Text_Buf& text_buf) const;
288 void decode_text(Text_Buf& text_buf);
289 boolean is_present() const;
290 boolean match_omit() const;
292 void set_param(Module_Param& param);
294 void check_restriction(template_res t_res, const char* t_name=NULL) const;
295 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
298 class Record_Of_Template : public Restricted_Length_Template {
303 Base_Template **value_elements; // instances of a class derived from Base_Template
307 Record_Of_Template** list_value; // instances of a class derived from Record_Of_Template
310 Erroneous_descriptor_t* err_descr;
312 struct Pair_of_elements;
313 Pair_of_elements *permutation_intervals;
314 unsigned int number_of_permutations;
316 Record_Of_Template();
317 Record_Of_Template(template_sel new_selection);
318 /** Copy constructor not implemented */
319 Record_Of_Template(const Record_Of_Template& other_value);
320 /** Assignment disabled */
321 Record_Of_Template& operator=(const Record_Of_Template& other_value);
322 ~Record_Of_Template();
324 void clean_up_intervals();
326 void set_selection(template_sel new_selection);
327 void set_selection(const Record_Of_Template& other_value);
329 void encode_text_permutation(Text_Buf& text_buf) const;
330 void decode_text_permutation(Text_Buf& text_buf);
332 void copy_template(const Record_Of_Template& other_value);
333 void copy_optional(const Base_Type* other_value);
336 Base_Template* clone() const;
337 void copy_value(const Base_Type* other_value);
340 void add_permutation(unsigned int start_index, unsigned int end_index);
342 /** Removes all permutations set on this template, used when template variables
343 * are given new values. */
344 void remove_all_permutations() { clean_up_intervals(); }
346 unsigned int get_number_of_permutations() const;
347 unsigned int get_permutation_start(unsigned int index_value) const;
348 unsigned int get_permutation_end(unsigned int index_value) const;
349 unsigned int get_permutation_size(unsigned int index_value) const;
350 boolean permutation_starts_at(unsigned int index_value) const;
351 boolean permutation_ends_at(unsigned int index_value) const;
353 void set_size(int new_size);
354 void set_type(template_sel template_type, int list_length);
355 boolean is_value() const;
356 void valueofv(Base_Type* value) const;
357 void set_value(template_sel other_value);
359 Base_Template* get_at(int index_value);
360 Base_Template* get_at(const INTEGER& index_value);
361 const Base_Template* get_at(int index_value) const;
362 const Base_Template* get_at(const INTEGER& index_value) const;
364 int size_of(boolean is_size) const;
365 Record_Of_Template* get_list_item(int list_index);
367 void substr_(int index, int returncount, Record_Of_Type* rec_of) const;
368 void replace_(int index, int len, const Record_Of_Template* repl, Record_Of_Type* rec_of) const;
369 void replace_(int index, int len, const Record_Of_Type* repl, Record_Of_Type* rec_of) const;
372 int size_of() const { return size_of(TRUE); }
373 int lengthof() const { return size_of(FALSE); }
377 boolean matchv(const Base_Type* other_value) const;
378 void log_matchv(const Base_Type* match_value) const;
379 /** create an instance of this */
380 virtual Record_Of_Template* create() const = 0;
381 /** create an instance of the element class */
382 virtual Base_Template* create_elem() const = 0;
384 // used for both set of and record of types
385 static boolean match_function_specific(
386 const Base_Type *value_ptr, int value_index,
387 const Restricted_Length_Template *template_ptr, int template_index);
389 void encode_text(Text_Buf& text_buf) const;
390 void decode_text(Text_Buf& text_buf);
391 boolean is_present() const;
392 boolean match_omit() const;
394 void set_param(Module_Param& param);
396 void check_restriction(template_res t_res, const char* t_name=NULL) const;
397 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
400 class Record_Template : public Base_Template
406 Base_Template** value_elements;
410 Record_Template** list_value;
413 Erroneous_descriptor_t* err_descr;
415 /** create value elements by calling their constructor */
416 virtual void set_specific() = 0;
418 void copy_optional(const Base_Type* other_value);
419 void copy_template(const Record_Template& other_value);
422 Record_Template(template_sel other_value);
423 /** Copy constructor not implemented */
424 Record_Template(const Record_Template& other_value);
425 /** Assignment disabled */
426 Record_Template& operator=(const Record_Template& other_value);
430 void copy_value(const Base_Type* other_value);
433 void set_type(template_sel template_type, int list_length);
434 Record_Template* get_list_item(int list_index) const;
438 boolean is_value() const;
439 void valueofv(Base_Type* value) const;
440 void set_value(template_sel other_value);
443 Base_Template* get_at(int index_value);
444 const Base_Template* get_at(int index_value) const;
446 /** create an instance by calling the default constructor */
447 virtual Record_Template* create() const = 0;
449 virtual const char* fld_name(int /*field_index*/) const { return ""; }
452 Base_Template* clone() const;
456 boolean matchv(const Base_Type* other_value) const;
457 void log_matchv(const Base_Type* match_value) const;
459 void encode_text(Text_Buf& text_buf) const;
460 void decode_text(Text_Buf& text_buf);
461 boolean is_present() const;
462 boolean match_omit() const;
464 void set_param(Module_Param& param);
466 void check_restriction(template_res t_res, const char* t_name=NULL) const;
467 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
470 class Empty_Record_Template : public Base_Template
475 Empty_Record_Template** list_value;
478 void copy_optional(const Base_Type* other_value);
479 void copy_template(const Empty_Record_Template& other_value);
481 Empty_Record_Template();
482 Empty_Record_Template(template_sel other_value);
483 /** Copy constructor not implemented */
484 Empty_Record_Template(const Empty_Record_Template& other_value);
485 /** Assignment disabled */
486 Empty_Record_Template& operator=(const Empty_Record_Template& other_value);
487 ~Empty_Record_Template();
490 void copy_value(const Base_Type* other_value);
493 void set_type(template_sel template_type, int list_length);
494 Empty_Record_Template* get_list_item(int list_index) const;
498 boolean is_value() const;
499 void valueofv(Base_Type* value) const;
500 void set_value(template_sel other_value);
503 /** create an instance by calling the default constructor */
504 virtual Empty_Record_Template* create() const = 0;
507 Base_Template* clone() const;
511 boolean matchv(const Base_Type* other_value) const;
512 void log_matchv(const Base_Type* match_value) const;
514 void encode_text(Text_Buf& text_buf) const;
515 void decode_text(Text_Buf& text_buf);
516 boolean is_present() const;
517 boolean match_omit() const;
519 void set_param(Module_Param& param);
522 #undef VIRTUAL_IF_RUNTIME_2