Merge pull request #83 from eadrkir/master
[deliverable/titan.core.git] / core / Template.hh
CommitLineData
d44e3c4f 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
7 *
8 * Contributors:
9 *
10 * Balasko, Jeno
11 * Baranyi, Botond
12 * Delic, Adam
13 * Forstner, Matyas
14 * Kovacs, Ferenc
15 * Raduly, Csaba
16 * Szabados, Kristof
17 * Szabo, Janos Zoltan – initial implementation
18 * Tatarka, Gabor
19 * Zalanyi, Balazs Andor
20 *
21 ******************************************************************************/
970ed795
EL
22#ifndef TEMPLATE_HH
23#define TEMPLATE_HH
24
25#include "Types.h"
26
27#ifdef TITAN_RUNTIME_2
28#include "Struct_of.hh"
a38c6d4c 29#include "RefdIndex.hh"
970ed795
EL
30struct TTCN_Typedescriptor_t;
31struct Erroneous_descriptor_t;
32#endif
33
34class Text_Buf;
35class Module_Param;
3abe9331 36class Module_Param_Name;
37class Module_Param_Length_Restriction;
970ed795
EL
38
39enum template_sel {
40 UNINITIALIZED_TEMPLATE = -1,
41 SPECIFIC_VALUE = 0,
42 OMIT_VALUE = 1,
43 ANY_VALUE = 2,
44 ANY_OR_OMIT = 3,
45 VALUE_LIST = 4,
46 COMPLEMENTED_LIST = 5,
47 VALUE_RANGE = 6,
48 STRING_PATTERN = 7,
49 SUPERSET_MATCH = 8,
28352dbd
BB
50 SUBSET_MATCH = 9,
51 DECODE_MATCH = 10
970ed795
EL
52};
53
54enum template_res {
55 TR_VALUE,
56 TR_OMIT,
57 TR_PRESENT
58};
59
60#ifdef TITAN_RUNTIME_2
61#define VIRTUAL_IF_RUNTIME_2 virtual
62#else
63#define VIRTUAL_IF_RUNTIME_2
64#endif
65
66class Base_Template {
67protected:
68 template_sel template_selection;
69 boolean is_ifpresent;
70
71 Base_Template();
72 Base_Template(template_sel other_value);
73 // Compiler-generated copy constructor and assignment are acceptable
74
75 static void check_single_selection(template_sel other_value);
76 void set_selection(template_sel other_value);
77 void set_selection(const Base_Template& other_value);
78
79 void log_generic() const;
80 void log_ifpresent() const;
81
82 void encode_text_base(Text_Buf& text_buf) const;
83 void decode_text_base(Text_Buf& text_buf);
84
85public:
86 inline template_sel get_selection() const { return template_selection; }
87
88 void set_ifpresent();
89
90 VIRTUAL_IF_RUNTIME_2 boolean is_omit() const;
91 VIRTUAL_IF_RUNTIME_2 boolean is_any_or_omit() const;
92 /** Returns FALSE if \a template_selection is \a UNINITIALIZED_TEMPLATE,
93 * TRUE otherwise. */
94 VIRTUAL_IF_RUNTIME_2 boolean is_bound() const
95 { return UNINITIALIZED_TEMPLATE != template_selection; }
96 VIRTUAL_IF_RUNTIME_2 boolean is_value() const
97 { return !is_ifpresent && template_selection==SPECIFIC_VALUE; }
98 VIRTUAL_IF_RUNTIME_2 void clean_up()
99 { template_selection = UNINITIALIZED_TEMPLATE; }
100 /** return the name of template restriction \a tr */
101 static const char* get_res_name(template_res tr);
102
3abe9331 103 /** Initialize this object (or one of its fields/elements) with a
104 * module parameter value. The module parameter may contain references to
105 * other module parameters or module parameter expressions, which are processed
106 * by this method to calculated the final result.
107 * @note Sets the 'ifpresent' flag if either the reference (if any) or the
108 * (referenced) module parameter value have their 'ifpresent' flag
109 * @note If both the reference (if any) and the (referenced) module parameter
110 * have a length restriction, then the reference's length restriction is used.
111 * @note A temporary object is used when setting VALUE_LIST or COMPLEMENT_LIST
112 * templates, as the list of templates might contain a reference to this object.
113 * @param param module parameter value (its ID specifies which object is to be set) */
970ed795 114 VIRTUAL_IF_RUNTIME_2 void set_param(Module_Param& param);
3abe9331 115 /** Create a module parameter value equivalent to this object (or one of its
116 * fields/elements)
117 * @param param_name module parameter ID, specifies which object to convert */
118 VIRTUAL_IF_RUNTIME_2 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
119
120 /** not a component by default (component templates will return true) */
121 inline boolean is_component() { return FALSE; }
122
123#ifdef TITAN_RUNTIME_2
124 /** set the value of the object pointed to by \a value */
125 virtual void valueofv(Base_Type* value) const = 0;
126 virtual void set_value(template_sel other_value) = 0;
127 virtual void copy_value(const Base_Type* other_value) = 0;
128
129 virtual Base_Template* clone() const = 0;
130 virtual const TTCN_Typedescriptor_t* get_descriptor() const = 0;
131
132 virtual void log() const = 0;
133
134 // virtual functions for match and log_match
3abe9331 135 virtual boolean matchv(const Base_Type* other_value, boolean legacy) const = 0;
136 virtual void log_matchv(const Base_Type* match_value, boolean legacy) const = 0;
970ed795
EL
137
138 virtual void encode_text(Text_Buf& text_buf) const = 0;
139 virtual void decode_text(Text_Buf& text_buf) = 0;
3abe9331 140 virtual boolean is_present(boolean legacy = FALSE) const = 0;
141 virtual boolean match_omit(boolean legacy = FALSE) const = 0;
970ed795 142
3abe9331 143 virtual void check_restriction(template_res t_res, const char* t_name=NULL,
144 boolean legacy = FALSE) const;
970ed795
EL
145
146 virtual ~Base_Template() { }
147#endif
148};
149
a38c6d4c 150class Restricted_Length_Template : public Base_Template
151#ifdef TITAN_RUNTIME_2
152 , public RefdIndexInterface
153#endif
154{
970ed795
EL
155protected:
156 enum length_restriction_type_t {
157 NO_LENGTH_RESTRICTION = 0,
158 SINGLE_LENGTH_RESTRICTION = 1,
159 RANGE_LENGTH_RESTRICTION =2
160 } length_restriction_type;
161 union {
162 int single_length;
163 struct {
164 int min_length, max_length;
165 boolean max_length_set;
166 } range_length;
167 } length_restriction;
168
169 Restricted_Length_Template();
170 Restricted_Length_Template(template_sel other_value);
171 // Compiler-generated copy constructor and assignment are acceptable
172
173 void set_selection(template_sel new_selection);
174 void set_selection(const Restricted_Length_Template& other_value);
175
176public:
177 boolean match_length(int value_length) const;
178
179protected:
180 int check_section_is_single(int min_size, boolean has_any_or_none,
181 const char* operation_name,
182 const char* type_name_prefix,
183 const char* type_name) const;
184
185 void log_restricted() const;
186 void log_match_length(int value_length) const;
187
188 void encode_text_restricted(Text_Buf& text_buf) const;
189 void decode_text_restricted(Text_Buf& text_buf);
190
191 void set_length_range(const Module_Param& param);
3abe9331 192 Module_Param_Length_Restriction* get_length_range() const;
970ed795
EL
193
194public:
195
196 void set_single_length(int single_length);
197 void set_min_length(int min_length);
198 void set_max_length(int max_length);
199
200 boolean is_omit() const;
201 boolean is_any_or_omit() const;
970ed795
EL
202};
203
204#ifndef TITAN_RUNTIME_2
205
206class Record_Of_Template : public Restricted_Length_Template {
207protected:
208 struct Pair_of_elements;
209 Pair_of_elements *permutation_intervals;
210 unsigned int number_of_permutations;
211
212 Record_Of_Template();
213 Record_Of_Template(template_sel new_selection);
214 Record_Of_Template(const Record_Of_Template& other_value);
215 ~Record_Of_Template();
216
217 void clean_up_intervals();
218
219 void set_selection(template_sel new_selection);
220 void set_selection(const Record_Of_Template& other_value);
221
222 void encode_text_permutation(Text_Buf& text_buf) const;
223 void decode_text_permutation(Text_Buf& text_buf);
224private:
225 Record_Of_Template& operator=(const Record_Of_Template& other_value);
226
227public:
228 void add_permutation(unsigned int start_index, unsigned int end_index);
229
230 /** Removes all permutations set on this template, used when template variables
231 * are given new values. */
232 void remove_all_permutations() { clean_up_intervals(); }
233
234 unsigned int get_number_of_permutations() const;
235 unsigned int get_permutation_start(unsigned int index_value) const;
236 unsigned int get_permutation_end(unsigned int index_value) const;
237 unsigned int get_permutation_size(unsigned int index_value) const;
238 boolean permutation_starts_at(unsigned int index_value) const;
239 boolean permutation_ends_at(unsigned int index_value) const;
240};
241
242#else
243
244class INTEGER;
245
246class Set_Of_Template : public Restricted_Length_Template {
247protected:
248 union {
249 struct {
250 int n_elements;
251 Base_Template** value_elements; // instances of a class derived from Base_Template
252 } single_value;
253 struct {
254 int n_values;
255 Set_Of_Template** list_value; // instances of a class derived from Set_Of_Template
256 } value_list;
257 };
258 Erroneous_descriptor_t* err_descr;
259
260 Set_Of_Template();
261 Set_Of_Template(template_sel new_selection);
262 /** Copy constructor not implemented */
263 Set_Of_Template(const Set_Of_Template& other_value);
264 /** Assignment disabled */
265 Set_Of_Template& operator=(const Set_Of_Template& other_value);
266 ~Set_Of_Template();
267
268 void copy_template(const Set_Of_Template& other_value);
269 void copy_optional(const Base_Type* other_value);
270
271public:
272 Base_Template* clone() const;
273 void copy_value(const Base_Type* other_value);
274 void clean_up();
275
276 int size_of() const { return size_of(TRUE); }
277 int lengthof() const { return size_of(FALSE); }
278 int n_elem() const;
279 void set_size(int new_size);
280 void set_type(template_sel template_type, int list_length);
281 boolean is_value() const;
282 void valueofv(Base_Type* value) const;
283 void set_value(template_sel other_value);
284protected:
285 Base_Template* get_at(int index_value);
286 Base_Template* get_at(const INTEGER& index_value);
287 const Base_Template* get_at(int index_value) const;
288 const Base_Template* get_at(const INTEGER& index_value) const;
289
290 int size_of(boolean is_size) const;
291 Set_Of_Template* get_list_item(int list_index);
292 Base_Template* get_set_item(int set_index);
293
294 void substr_(int index, int returncount, Record_Of_Type* rec_of) const;
295 void replace_(int index, int len, const Set_Of_Template* repl, Record_Of_Type* rec_of) const;
296 void replace_(int index, int len, const Record_Of_Type* repl, Record_Of_Type* rec_of) const;
297
298public:
299 void log() const;
300
3abe9331 301 boolean matchv(const Base_Type* other_value, boolean legacy) const;
302 void log_matchv(const Base_Type* match_value, boolean legacy) const;
970ed795
EL
303 /** create an instance of this */
304 virtual Set_Of_Template* create() const = 0;
305 /** create an instance of the element class */
306 virtual Base_Template* create_elem() const = 0;
307
308 // used for both set of and record of types
309 static boolean match_function_specific(
310 const Base_Type *value_ptr, int value_index,
3abe9331 311 const Restricted_Length_Template *template_ptr, int template_index,
312 boolean legacy);
970ed795
EL
313 // 2 static functions only for set of types
314 static boolean match_function_set(
315 const Base_Type *value_ptr, int value_index,
3abe9331 316 const Restricted_Length_Template *template_ptr, int template_index,
317 boolean legacy);
970ed795
EL
318 static void log_function(const Base_Type *value_ptr,
319 const Restricted_Length_Template *template_ptr,
3abe9331 320 int index_value, int index_template, boolean legacy);
970ed795
EL
321
322 void encode_text(Text_Buf& text_buf) const;
323 void decode_text(Text_Buf& text_buf);
3abe9331 324 boolean is_present(boolean legacy = FALSE) const;
325 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
326
327 void set_param(Module_Param& param);
3abe9331 328 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795 329
3abe9331 330 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
331 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
332};
333
334class Record_Of_Template : public Restricted_Length_Template {
335protected:
336 union {
337 struct {
338 int n_elements;
339 Base_Template **value_elements; // instances of a class derived from Base_Template
340 } single_value;
341 struct {
342 int n_values;
343 Record_Of_Template** list_value; // instances of a class derived from Record_Of_Template
344 } value_list;
345 };
346 Erroneous_descriptor_t* err_descr;
347
348 struct Pair_of_elements;
349 Pair_of_elements *permutation_intervals;
350 unsigned int number_of_permutations;
351
352 Record_Of_Template();
353 Record_Of_Template(template_sel new_selection);
354 /** Copy constructor not implemented */
355 Record_Of_Template(const Record_Of_Template& other_value);
356 /** Assignment disabled */
357 Record_Of_Template& operator=(const Record_Of_Template& other_value);
358 ~Record_Of_Template();
359
360 void clean_up_intervals();
361
362 void set_selection(template_sel new_selection);
363 void set_selection(const Record_Of_Template& other_value);
364
365 void encode_text_permutation(Text_Buf& text_buf) const;
366 void decode_text_permutation(Text_Buf& text_buf);
367
368 void copy_template(const Record_Of_Template& other_value);
369 void copy_optional(const Base_Type* other_value);
370
371public:
372 Base_Template* clone() const;
373 void copy_value(const Base_Type* other_value);
374 void clean_up();
375
376 void add_permutation(unsigned int start_index, unsigned int end_index);
377
378 /** Removes all permutations set on this template, used when template variables
379 * are given new values. */
380 void remove_all_permutations() { clean_up_intervals(); }
381
382 unsigned int get_number_of_permutations() const;
383 unsigned int get_permutation_start(unsigned int index_value) const;
384 unsigned int get_permutation_end(unsigned int index_value) const;
385 unsigned int get_permutation_size(unsigned int index_value) const;
386 boolean permutation_starts_at(unsigned int index_value) const;
387 boolean permutation_ends_at(unsigned int index_value) const;
388
389 void set_size(int new_size);
390 void set_type(template_sel template_type, int list_length);
391 boolean is_value() const;
392 void valueofv(Base_Type* value) const;
393 void set_value(template_sel other_value);
394protected:
395 Base_Template* get_at(int index_value);
396 Base_Template* get_at(const INTEGER& index_value);
397 const Base_Template* get_at(int index_value) const;
398 const Base_Template* get_at(const INTEGER& index_value) const;
399
400 int size_of(boolean is_size) const;
401 Record_Of_Template* get_list_item(int list_index);
402
403 void substr_(int index, int returncount, Record_Of_Type* rec_of) const;
404 void replace_(int index, int len, const Record_Of_Template* repl, Record_Of_Type* rec_of) const;
405 void replace_(int index, int len, const Record_Of_Type* repl, Record_Of_Type* rec_of) const;
406
407public:
408 int size_of() const { return size_of(TRUE); }
409 int lengthof() const { return size_of(FALSE); }
410 int n_elem() const;
411 void log() const;
412
3abe9331 413 boolean matchv(const Base_Type* other_value, boolean legacy) const;
414 void log_matchv(const Base_Type* match_value, boolean legacy) const;
970ed795
EL
415 /** create an instance of this */
416 virtual Record_Of_Template* create() const = 0;
417 /** create an instance of the element class */
418 virtual Base_Template* create_elem() const = 0;
419
420 // used for both set of and record of types
421 static boolean match_function_specific(
422 const Base_Type *value_ptr, int value_index,
3abe9331 423 const Restricted_Length_Template *template_ptr, int template_index, boolean legacy);
970ed795
EL
424
425 void encode_text(Text_Buf& text_buf) const;
426 void decode_text(Text_Buf& text_buf);
3abe9331 427 boolean is_present(boolean legacy = FALSE) const;
428 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
429
430 void set_param(Module_Param& param);
3abe9331 431 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795 432
3abe9331 433 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
434 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
435};
436
437class Record_Template : public Base_Template
438{
439protected:
440 union {
441 struct {
442 int n_elements;
443 Base_Template** value_elements;
444 } single_value;
445 struct {
446 int n_values;
447 Record_Template** list_value;
448 } value_list;
449 };
450 Erroneous_descriptor_t* err_descr;
451
452 /** create value elements by calling their constructor */
453 virtual void set_specific() = 0;
454
455 void copy_optional(const Base_Type* other_value);
456 void copy_template(const Record_Template& other_value);
457
458 Record_Template();
459 Record_Template(template_sel other_value);
460 /** Copy constructor not implemented */
461 Record_Template(const Record_Template& other_value);
462 /** Assignment disabled */
463 Record_Template& operator=(const Record_Template& other_value);
464 ~Record_Template();
465
466public:
467 void copy_value(const Base_Type* other_value);
468 void clean_up();
469
470 void set_type(template_sel template_type, int list_length);
471 Record_Template* get_list_item(int list_index) const;
472
473 int size_of() const;
474
475 boolean is_value() const;
476 void valueofv(Base_Type* value) const;
477 void set_value(template_sel other_value);
478
479protected:
480 Base_Template* get_at(int index_value);
481 const Base_Template* get_at(int index_value) const;
482
483 /** create an instance by calling the default constructor */
484 virtual Record_Template* create() const = 0;
485
486 virtual const char* fld_name(int /*field_index*/) const { return ""; }
487
488public:
489 Base_Template* clone() const;
490
491 void log() const;
492
3abe9331 493 boolean matchv(const Base_Type* other_value, boolean legacy) const;
494 void log_matchv(const Base_Type* match_value, boolean legacy) const;
970ed795
EL
495
496 void encode_text(Text_Buf& text_buf) const;
497 void decode_text(Text_Buf& text_buf);
3abe9331 498 boolean is_present(boolean legacy = FALSE) const;
499 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
500
501 void set_param(Module_Param& param);
3abe9331 502 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795 503
3abe9331 504 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
505 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
506};
507
508class Empty_Record_Template : public Base_Template
509{
510protected:
511 struct {
512 int n_values;
513 Empty_Record_Template** list_value;
514 } value_list;
515
516 void copy_optional(const Base_Type* other_value);
517 void copy_template(const Empty_Record_Template& other_value);
518
519 Empty_Record_Template();
520 Empty_Record_Template(template_sel other_value);
521 /** Copy constructor not implemented */
522 Empty_Record_Template(const Empty_Record_Template& other_value);
523 /** Assignment disabled */
524 Empty_Record_Template& operator=(const Empty_Record_Template& other_value);
525 ~Empty_Record_Template();
526
527public:
528 void copy_value(const Base_Type* other_value);
529 void clean_up();
530
531 void set_type(template_sel template_type, int list_length);
532 Empty_Record_Template* get_list_item(int list_index) const;
533
534 int size_of() const;
535
536 boolean is_value() const;
537 void valueofv(Base_Type* value) const;
538 void set_value(template_sel other_value);
539
540protected:
541 /** create an instance by calling the default constructor */
542 virtual Empty_Record_Template* create() const = 0;
543
544public:
545 Base_Template* clone() const;
546
547 void log() const;
548
3abe9331 549 boolean matchv(const Base_Type* other_value, boolean legacy) const;
550 void log_matchv(const Base_Type* match_value, boolean legacy) const;
970ed795
EL
551
552 void encode_text(Text_Buf& text_buf) const;
553 void decode_text(Text_Buf& text_buf);
3abe9331 554 boolean is_present(boolean legacy = FALSE) const;
555 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
556
557 void set_param(Module_Param& param);
3abe9331 558 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
559};
560
561#undef VIRTUAL_IF_RUNTIME_2
562#endif
563
564#endif
This page took 0.04744 seconds and 5 git commands to generate.