Merge pull request #62 from BenceJanosSzabo/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,
50 SUBSET_MATCH = 9
51};
52
53enum template_res {
54 TR_VALUE,
55 TR_OMIT,
56 TR_PRESENT
57};
58
59#ifdef TITAN_RUNTIME_2
60#define VIRTUAL_IF_RUNTIME_2 virtual
61#else
62#define VIRTUAL_IF_RUNTIME_2
63#endif
64
65class Base_Template {
66protected:
67 template_sel template_selection;
68 boolean is_ifpresent;
69
70 Base_Template();
71 Base_Template(template_sel other_value);
72 // Compiler-generated copy constructor and assignment are acceptable
73
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);
77
78 void log_generic() const;
79 void log_ifpresent() const;
80
81 void encode_text_base(Text_Buf& text_buf) const;
82 void decode_text_base(Text_Buf& text_buf);
83
84public:
85 inline template_sel get_selection() const { return template_selection; }
86
87 void set_ifpresent();
88
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,
92 * TRUE otherwise. */
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);
101
3abe9331 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) */
970ed795 113 VIRTUAL_IF_RUNTIME_2 void set_param(Module_Param& param);
3abe9331 114 /** Create a module parameter value equivalent to this object (or one of its
115 * fields/elements)
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;
970ed795
EL
118
119 /** not a component by default (component templates will return true) */
120 inline boolean is_component() { return FALSE; }
121
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;
127
128 virtual Base_Template* clone() const = 0;
129 virtual const TTCN_Typedescriptor_t* get_descriptor() const = 0;
130
131 virtual void log() const = 0;
132
133 // virtual functions for match and log_match
3abe9331 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;
970ed795
EL
136
137 virtual void encode_text(Text_Buf& text_buf) const = 0;
138 virtual void decode_text(Text_Buf& text_buf) = 0;
3abe9331 139 virtual boolean is_present(boolean legacy = FALSE) const = 0;
140 virtual boolean match_omit(boolean legacy = FALSE) const = 0;
970ed795 141
3abe9331 142 virtual void check_restriction(template_res t_res, const char* t_name=NULL,
143 boolean legacy = FALSE) const;
970ed795
EL
144
145 virtual ~Base_Template() { }
146#endif
147};
148
a38c6d4c 149class Restricted_Length_Template : public Base_Template
150#ifdef TITAN_RUNTIME_2
151 , public RefdIndexInterface
152#endif
153{
970ed795
EL
154protected:
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;
160 union {
161 int single_length;
162 struct {
163 int min_length, max_length;
164 boolean max_length_set;
165 } range_length;
166 } length_restriction;
167
168 Restricted_Length_Template();
169 Restricted_Length_Template(template_sel other_value);
170 // Compiler-generated copy constructor and assignment are acceptable
171
172 void set_selection(template_sel new_selection);
173 void set_selection(const Restricted_Length_Template& other_value);
174
175public:
176 boolean match_length(int value_length) const;
177
178protected:
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;
183
184 void log_restricted() const;
185 void log_match_length(int value_length) const;
186
187 void encode_text_restricted(Text_Buf& text_buf) const;
188 void decode_text_restricted(Text_Buf& text_buf);
189
190 void set_length_range(const Module_Param& param);
3abe9331 191 Module_Param_Length_Restriction* get_length_range() const;
970ed795
EL
192
193public:
194
195 void set_single_length(int single_length);
196 void set_min_length(int min_length);
197 void set_max_length(int max_length);
198
199 boolean is_omit() const;
200 boolean is_any_or_omit() const;
970ed795
EL
201};
202
203#ifndef TITAN_RUNTIME_2
204
205class Record_Of_Template : public Restricted_Length_Template {
206protected:
207 struct Pair_of_elements;
208 Pair_of_elements *permutation_intervals;
209 unsigned int number_of_permutations;
210
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();
215
216 void clean_up_intervals();
217
218 void set_selection(template_sel new_selection);
219 void set_selection(const Record_Of_Template& other_value);
220
221 void encode_text_permutation(Text_Buf& text_buf) const;
222 void decode_text_permutation(Text_Buf& text_buf);
223private:
224 Record_Of_Template& operator=(const Record_Of_Template& other_value);
225
226public:
227 void add_permutation(unsigned int start_index, unsigned int end_index);
228
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(); }
232
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;
239};
240
241#else
242
243class INTEGER;
244
245class Set_Of_Template : public Restricted_Length_Template {
246protected:
247 union {
248 struct {
249 int n_elements;
250 Base_Template** value_elements; // instances of a class derived from Base_Template
251 } single_value;
252 struct {
253 int n_values;
254 Set_Of_Template** list_value; // instances of a class derived from Set_Of_Template
255 } value_list;
256 };
257 Erroneous_descriptor_t* err_descr;
258
259 Set_Of_Template();
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);
265 ~Set_Of_Template();
266
267 void copy_template(const Set_Of_Template& other_value);
268 void copy_optional(const Base_Type* other_value);
269
270public:
271 Base_Template* clone() const;
272 void copy_value(const Base_Type* other_value);
273 void clean_up();
274
275 int size_of() const { return size_of(TRUE); }
276 int lengthof() const { return size_of(FALSE); }
277 int n_elem() const;
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);
283protected:
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;
288
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);
292
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;
296
297public:
298 void log() const;
299
3abe9331 300 boolean matchv(const Base_Type* other_value, boolean legacy) const;
301 void log_matchv(const Base_Type* match_value, boolean legacy) const;
970ed795
EL
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;
306
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,
3abe9331 310 const Restricted_Length_Template *template_ptr, int template_index,
311 boolean legacy);
970ed795
EL
312 // 2 static functions only for set of types
313 static boolean match_function_set(
314 const Base_Type *value_ptr, int value_index,
3abe9331 315 const Restricted_Length_Template *template_ptr, int template_index,
316 boolean legacy);
970ed795
EL
317 static void log_function(const Base_Type *value_ptr,
318 const Restricted_Length_Template *template_ptr,
3abe9331 319 int index_value, int index_template, boolean legacy);
970ed795
EL
320
321 void encode_text(Text_Buf& text_buf) const;
322 void decode_text(Text_Buf& text_buf);
3abe9331 323 boolean is_present(boolean legacy = FALSE) const;
324 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
325
326 void set_param(Module_Param& param);
3abe9331 327 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795 328
3abe9331 329 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
330 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
331};
332
333class Record_Of_Template : public Restricted_Length_Template {
334protected:
335 union {
336 struct {
337 int n_elements;
338 Base_Template **value_elements; // instances of a class derived from Base_Template
339 } single_value;
340 struct {
341 int n_values;
342 Record_Of_Template** list_value; // instances of a class derived from Record_Of_Template
343 } value_list;
344 };
345 Erroneous_descriptor_t* err_descr;
346
347 struct Pair_of_elements;
348 Pair_of_elements *permutation_intervals;
349 unsigned int number_of_permutations;
350
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();
358
359 void clean_up_intervals();
360
361 void set_selection(template_sel new_selection);
362 void set_selection(const Record_Of_Template& other_value);
363
364 void encode_text_permutation(Text_Buf& text_buf) const;
365 void decode_text_permutation(Text_Buf& text_buf);
366
367 void copy_template(const Record_Of_Template& other_value);
368 void copy_optional(const Base_Type* other_value);
369
370public:
371 Base_Template* clone() const;
372 void copy_value(const Base_Type* other_value);
373 void clean_up();
374
375 void add_permutation(unsigned int start_index, unsigned int end_index);
376
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(); }
380
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;
387
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);
393protected:
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;
398
399 int size_of(boolean is_size) const;
400 Record_Of_Template* get_list_item(int list_index);
401
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;
405
406public:
407 int size_of() const { return size_of(TRUE); }
408 int lengthof() const { return size_of(FALSE); }
409 int n_elem() const;
410 void log() const;
411
3abe9331 412 boolean matchv(const Base_Type* other_value, boolean legacy) const;
413 void log_matchv(const Base_Type* match_value, boolean legacy) const;
970ed795
EL
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;
418
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,
3abe9331 422 const Restricted_Length_Template *template_ptr, int template_index, boolean legacy);
970ed795
EL
423
424 void encode_text(Text_Buf& text_buf) const;
425 void decode_text(Text_Buf& text_buf);
3abe9331 426 boolean is_present(boolean legacy = FALSE) const;
427 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
428
429 void set_param(Module_Param& param);
3abe9331 430 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795 431
3abe9331 432 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
433 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
434};
435
436class Record_Template : public Base_Template
437{
438protected:
439 union {
440 struct {
441 int n_elements;
442 Base_Template** value_elements;
443 } single_value;
444 struct {
445 int n_values;
446 Record_Template** list_value;
447 } value_list;
448 };
449 Erroneous_descriptor_t* err_descr;
450
451 /** create value elements by calling their constructor */
452 virtual void set_specific() = 0;
453
454 void copy_optional(const Base_Type* other_value);
455 void copy_template(const Record_Template& other_value);
456
457 Record_Template();
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);
463 ~Record_Template();
464
465public:
466 void copy_value(const Base_Type* other_value);
467 void clean_up();
468
469 void set_type(template_sel template_type, int list_length);
470 Record_Template* get_list_item(int list_index) const;
471
472 int size_of() const;
473
474 boolean is_value() const;
475 void valueofv(Base_Type* value) const;
476 void set_value(template_sel other_value);
477
478protected:
479 Base_Template* get_at(int index_value);
480 const Base_Template* get_at(int index_value) const;
481
482 /** create an instance by calling the default constructor */
483 virtual Record_Template* create() const = 0;
484
485 virtual const char* fld_name(int /*field_index*/) const { return ""; }
486
487public:
488 Base_Template* clone() const;
489
490 void log() const;
491
3abe9331 492 boolean matchv(const Base_Type* other_value, boolean legacy) const;
493 void log_matchv(const Base_Type* match_value, boolean legacy) const;
970ed795
EL
494
495 void encode_text(Text_Buf& text_buf) const;
496 void decode_text(Text_Buf& text_buf);
3abe9331 497 boolean is_present(boolean legacy = FALSE) const;
498 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
499
500 void set_param(Module_Param& param);
3abe9331 501 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795 502
3abe9331 503 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
504 void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }
505};
506
507class Empty_Record_Template : public Base_Template
508{
509protected:
510 struct {
511 int n_values;
512 Empty_Record_Template** list_value;
513 } value_list;
514
515 void copy_optional(const Base_Type* other_value);
516 void copy_template(const Empty_Record_Template& other_value);
517
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();
525
526public:
527 void copy_value(const Base_Type* other_value);
528 void clean_up();
529
530 void set_type(template_sel template_type, int list_length);
531 Empty_Record_Template* get_list_item(int list_index) const;
532
533 int size_of() const;
534
535 boolean is_value() const;
536 void valueofv(Base_Type* value) const;
537 void set_value(template_sel other_value);
538
539protected:
540 /** create an instance by calling the default constructor */
541 virtual Empty_Record_Template* create() const = 0;
542
543public:
544 Base_Template* clone() const;
545
546 void log() const;
547
3abe9331 548 boolean matchv(const Base_Type* other_value, boolean legacy) const;
549 void log_matchv(const Base_Type* match_value, boolean legacy) const;
970ed795
EL
550
551 void encode_text(Text_Buf& text_buf) const;
552 void decode_text(Text_Buf& text_buf);
3abe9331 553 boolean is_present(boolean legacy = FALSE) const;
554 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
555
556 void set_param(Module_Param& param);
3abe9331 557 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
558};
559
560#undef VIRTUAL_IF_RUNTIME_2
561#endif
562
563#endif
This page took 0.047598 seconds and 5 git commands to generate.