de50db9d15424242314aa365e653a0da8818a1fb
[deliverable/titan.core.git] / core / Template.hh
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 ///////////////////////////////////////////////////////////////////////////////
8 #ifndef TEMPLATE_HH
9 #define TEMPLATE_HH
10
11 #include "Types.h"
12
13 #ifdef TITAN_RUNTIME_2
14 #include "Struct_of.hh"
15 struct TTCN_Typedescriptor_t;
16 struct Erroneous_descriptor_t;
17 #endif
18
19 class Text_Buf;
20 class Module_Param;
21
22 enum template_sel {
23 UNINITIALIZED_TEMPLATE = -1,
24 SPECIFIC_VALUE = 0,
25 OMIT_VALUE = 1,
26 ANY_VALUE = 2,
27 ANY_OR_OMIT = 3,
28 VALUE_LIST = 4,
29 COMPLEMENTED_LIST = 5,
30 VALUE_RANGE = 6,
31 STRING_PATTERN = 7,
32 SUPERSET_MATCH = 8,
33 SUBSET_MATCH = 9
34 };
35
36 enum template_res {
37 TR_VALUE,
38 TR_OMIT,
39 TR_PRESENT
40 };
41
42 #ifdef TITAN_RUNTIME_2
43 #define VIRTUAL_IF_RUNTIME_2 virtual
44 #else
45 #define VIRTUAL_IF_RUNTIME_2
46 #endif
47
48 class Base_Template {
49 protected:
50 template_sel template_selection;
51 boolean is_ifpresent;
52
53 Base_Template();
54 Base_Template(template_sel other_value);
55 // Compiler-generated copy constructor and assignment are acceptable
56
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);
60
61 void log_generic() const;
62 void log_ifpresent() const;
63
64 void encode_text_base(Text_Buf& text_buf) const;
65 void decode_text_base(Text_Buf& text_buf);
66
67 public:
68 inline template_sel get_selection() const { return template_selection; }
69
70 void set_ifpresent();
71
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,
75 * TRUE otherwise. */
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);
84
85 VIRTUAL_IF_RUNTIME_2 void set_param(Module_Param& param);
86
87 /** not a component by default (component templates will return true) */
88 inline boolean is_component() { return FALSE; }
89
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;
95
96 virtual Base_Template* clone() const = 0;
97 virtual const TTCN_Typedescriptor_t* get_descriptor() const = 0;
98
99 virtual void log() const = 0;
100
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;
104
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;
109
110 virtual void check_restriction(template_res t_res, const char* t_name=NULL) const;
111
112 virtual ~Base_Template() { }
113 #endif
114 };
115
116 class Restricted_Length_Template : public Base_Template {
117 protected:
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;
123 union {
124 int single_length;
125 struct {
126 int min_length, max_length;
127 boolean max_length_set;
128 } range_length;
129 } length_restriction;
130
131 Restricted_Length_Template();
132 Restricted_Length_Template(template_sel other_value);
133 // Compiler-generated copy constructor and assignment are acceptable
134
135 void set_selection(template_sel new_selection);
136 void set_selection(const Restricted_Length_Template& other_value);
137
138 public:
139 boolean match_length(int value_length) const;
140
141 protected:
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;
146
147 void log_restricted() const;
148 void log_match_length(int value_length) const;
149
150 void encode_text_restricted(Text_Buf& text_buf) const;
151 void decode_text_restricted(Text_Buf& text_buf);
152
153 void set_length_range(const Module_Param& param);
154
155 public:
156
157 void set_single_length(int single_length);
158 void set_min_length(int min_length);
159 void set_max_length(int max_length);
160
161 boolean is_omit() const;
162 boolean is_any_or_omit() const;
163
164 // Dummy functions, only used in record of/set of value
165 void add_refd_index(int) {}
166 void remove_refd_index(int) {}
167 };
168
169 #ifndef TITAN_RUNTIME_2
170
171 class Record_Of_Template : public Restricted_Length_Template {
172 protected:
173 struct Pair_of_elements;
174 Pair_of_elements *permutation_intervals;
175 unsigned int number_of_permutations;
176
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();
181
182 void clean_up_intervals();
183
184 void set_selection(template_sel new_selection);
185 void set_selection(const Record_Of_Template& other_value);
186
187 void encode_text_permutation(Text_Buf& text_buf) const;
188 void decode_text_permutation(Text_Buf& text_buf);
189 private:
190 Record_Of_Template& operator=(const Record_Of_Template& other_value);
191
192 public:
193 void add_permutation(unsigned int start_index, unsigned int end_index);
194
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(); }
198
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;
205 };
206
207 #else
208
209 class INTEGER;
210
211 class Set_Of_Template : public Restricted_Length_Template {
212 protected:
213 union {
214 struct {
215 int n_elements;
216 Base_Template** value_elements; // instances of a class derived from Base_Template
217 } single_value;
218 struct {
219 int n_values;
220 Set_Of_Template** list_value; // instances of a class derived from Set_Of_Template
221 } value_list;
222 };
223 Erroneous_descriptor_t* err_descr;
224
225 Set_Of_Template();
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);
231 ~Set_Of_Template();
232
233 void copy_template(const Set_Of_Template& other_value);
234 void copy_optional(const Base_Type* other_value);
235
236 public:
237 Base_Template* clone() const;
238 void copy_value(const Base_Type* other_value);
239 void clean_up();
240
241 int size_of() const { return size_of(TRUE); }
242 int lengthof() const { return size_of(FALSE); }
243 int n_elem() const;
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);
249 protected:
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;
254
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);
258
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;
262
263 public:
264 void log() const;
265
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;
272
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);
284
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;
289
290 void set_param(Module_Param& param);
291
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; }
294 };
295
296 class Record_Of_Template : public Restricted_Length_Template {
297 protected:
298 union {
299 struct {
300 int n_elements;
301 Base_Template **value_elements; // instances of a class derived from Base_Template
302 } single_value;
303 struct {
304 int n_values;
305 Record_Of_Template** list_value; // instances of a class derived from Record_Of_Template
306 } value_list;
307 };
308 Erroneous_descriptor_t* err_descr;
309
310 struct Pair_of_elements;
311 Pair_of_elements *permutation_intervals;
312 unsigned int number_of_permutations;
313
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();
321
322 void clean_up_intervals();
323
324 void set_selection(template_sel new_selection);
325 void set_selection(const Record_Of_Template& other_value);
326
327 void encode_text_permutation(Text_Buf& text_buf) const;
328 void decode_text_permutation(Text_Buf& text_buf);
329
330 void copy_template(const Record_Of_Template& other_value);
331 void copy_optional(const Base_Type* other_value);
332
333 public:
334 Base_Template* clone() const;
335 void copy_value(const Base_Type* other_value);
336 void clean_up();
337
338 void add_permutation(unsigned int start_index, unsigned int end_index);
339
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(); }
343
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;
350
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);
356 protected:
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;
361
362 int size_of(boolean is_size) const;
363 Record_Of_Template* get_list_item(int list_index);
364
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;
368
369 public:
370 int size_of() const { return size_of(TRUE); }
371 int lengthof() const { return size_of(FALSE); }
372 int n_elem() const;
373 void log() const;
374
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;
381
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);
386
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;
391
392 void set_param(Module_Param& param);
393
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; }
396 };
397
398 class Record_Template : public Base_Template
399 {
400 protected:
401 union {
402 struct {
403 int n_elements;
404 Base_Template** value_elements;
405 } single_value;
406 struct {
407 int n_values;
408 Record_Template** list_value;
409 } value_list;
410 };
411 Erroneous_descriptor_t* err_descr;
412
413 /** create value elements by calling their constructor */
414 virtual void set_specific() = 0;
415
416 void copy_optional(const Base_Type* other_value);
417 void copy_template(const Record_Template& other_value);
418
419 Record_Template();
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);
425 ~Record_Template();
426
427 public:
428 void copy_value(const Base_Type* other_value);
429 void clean_up();
430
431 void set_type(template_sel template_type, int list_length);
432 Record_Template* get_list_item(int list_index) const;
433
434 int size_of() const;
435
436 boolean is_value() const;
437 void valueofv(Base_Type* value) const;
438 void set_value(template_sel other_value);
439
440 protected:
441 Base_Template* get_at(int index_value);
442 const Base_Template* get_at(int index_value) const;
443
444 /** create an instance by calling the default constructor */
445 virtual Record_Template* create() const = 0;
446
447 virtual const char* fld_name(int /*field_index*/) const { return ""; }
448
449 public:
450 Base_Template* clone() const;
451
452 void log() const;
453
454 boolean matchv(const Base_Type* other_value) const;
455 void log_matchv(const Base_Type* match_value) const;
456
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;
461
462 void set_param(Module_Param& param);
463
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; }
466 };
467
468 class Empty_Record_Template : public Base_Template
469 {
470 protected:
471 struct {
472 int n_values;
473 Empty_Record_Template** list_value;
474 } value_list;
475
476 void copy_optional(const Base_Type* other_value);
477 void copy_template(const Empty_Record_Template& other_value);
478
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();
486
487 public:
488 void copy_value(const Base_Type* other_value);
489 void clean_up();
490
491 void set_type(template_sel template_type, int list_length);
492 Empty_Record_Template* get_list_item(int list_index) const;
493
494 int size_of() const;
495
496 boolean is_value() const;
497 void valueofv(Base_Type* value) const;
498 void set_value(template_sel other_value);
499
500 protected:
501 /** create an instance by calling the default constructor */
502 virtual Empty_Record_Template* create() const = 0;
503
504 public:
505 Base_Template* clone() const;
506
507 void log() const;
508
509 boolean matchv(const Base_Type* other_value) const;
510 void log_matchv(const Base_Type* match_value) const;
511
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;
516
517 void set_param(Module_Param& param);
518 };
519
520 #undef VIRTUAL_IF_RUNTIME_2
521 #endif
522
523 #endif
This page took 0.067001 seconds and 4 git commands to generate.