Commit | Line | Data |
---|---|---|
970ed795 EL |
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" | |
a38c6d4c | 15 | #include "RefdIndex.hh" |
970ed795 EL |
16 | struct TTCN_Typedescriptor_t; |
17 | struct Erroneous_descriptor_t; | |
18 | #endif | |
19 | ||
20 | class Text_Buf; | |
21 | class Module_Param; | |
22 | ||
23 | enum template_sel { | |
24 | UNINITIALIZED_TEMPLATE = -1, | |
25 | SPECIFIC_VALUE = 0, | |
26 | OMIT_VALUE = 1, | |
27 | ANY_VALUE = 2, | |
28 | ANY_OR_OMIT = 3, | |
29 | VALUE_LIST = 4, | |
30 | COMPLEMENTED_LIST = 5, | |
31 | VALUE_RANGE = 6, | |
32 | STRING_PATTERN = 7, | |
33 | SUPERSET_MATCH = 8, | |
34 | SUBSET_MATCH = 9 | |
35 | }; | |
36 | ||
37 | enum template_res { | |
38 | TR_VALUE, | |
39 | TR_OMIT, | |
40 | TR_PRESENT | |
41 | }; | |
42 | ||
43 | #ifdef TITAN_RUNTIME_2 | |
44 | #define VIRTUAL_IF_RUNTIME_2 virtual | |
45 | #else | |
46 | #define VIRTUAL_IF_RUNTIME_2 | |
47 | #endif | |
48 | ||
49 | class Base_Template { | |
50 | protected: | |
51 | template_sel template_selection; | |
52 | boolean is_ifpresent; | |
53 | ||
54 | Base_Template(); | |
55 | Base_Template(template_sel other_value); | |
56 | // Compiler-generated copy constructor and assignment are acceptable | |
57 | ||
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); | |
61 | ||
62 | void log_generic() const; | |
63 | void log_ifpresent() const; | |
64 | ||
65 | void encode_text_base(Text_Buf& text_buf) const; | |
66 | void decode_text_base(Text_Buf& text_buf); | |
67 | ||
68 | public: | |
69 | inline template_sel get_selection() const { return template_selection; } | |
70 | ||
71 | void set_ifpresent(); | |
72 | ||
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, | |
76 | * TRUE otherwise. */ | |
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); | |
85 | ||
86 | VIRTUAL_IF_RUNTIME_2 void set_param(Module_Param& param); | |
87 | ||
88 | /** not a component by default (component templates will return true) */ | |
89 | inline boolean is_component() { return FALSE; } | |
90 | ||
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; | |
96 | ||
97 | virtual Base_Template* clone() const = 0; | |
98 | virtual const TTCN_Typedescriptor_t* get_descriptor() const = 0; | |
99 | ||
100 | virtual void log() const = 0; | |
101 | ||
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; | |
105 | ||
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; | |
110 | ||
111 | virtual void check_restriction(template_res t_res, const char* t_name=NULL) const; | |
112 | ||
113 | virtual ~Base_Template() { } | |
114 | #endif | |
115 | }; | |
116 | ||
a38c6d4c | 117 | class Restricted_Length_Template : public Base_Template |
118 | #ifdef TITAN_RUNTIME_2 | |
119 | , public RefdIndexInterface | |
120 | #endif | |
121 | { | |
970ed795 EL |
122 | protected: |
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; | |
128 | union { | |
129 | int single_length; | |
130 | struct { | |
131 | int min_length, max_length; | |
132 | boolean max_length_set; | |
133 | } range_length; | |
134 | } length_restriction; | |
135 | ||
136 | Restricted_Length_Template(); | |
137 | Restricted_Length_Template(template_sel other_value); | |
138 | // Compiler-generated copy constructor and assignment are acceptable | |
139 | ||
140 | void set_selection(template_sel new_selection); | |
141 | void set_selection(const Restricted_Length_Template& other_value); | |
142 | ||
143 | public: | |
144 | boolean match_length(int value_length) const; | |
145 | ||
146 | protected: | |
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; | |
151 | ||
152 | void log_restricted() const; | |
153 | void log_match_length(int value_length) const; | |
154 | ||
155 | void encode_text_restricted(Text_Buf& text_buf) const; | |
156 | void decode_text_restricted(Text_Buf& text_buf); | |
157 | ||
158 | void set_length_range(const Module_Param& param); | |
159 | ||
160 | public: | |
161 | ||
162 | void set_single_length(int single_length); | |
163 | void set_min_length(int min_length); | |
164 | void set_max_length(int max_length); | |
165 | ||
166 | boolean is_omit() const; | |
167 | boolean is_any_or_omit() const; | |
970ed795 EL |
168 | }; |
169 | ||
170 | #ifndef TITAN_RUNTIME_2 | |
171 | ||
172 | class Record_Of_Template : public Restricted_Length_Template { | |
173 | protected: | |
174 | struct Pair_of_elements; | |
175 | Pair_of_elements *permutation_intervals; | |
176 | unsigned int number_of_permutations; | |
177 | ||
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(); | |
182 | ||
183 | void clean_up_intervals(); | |
184 | ||
185 | void set_selection(template_sel new_selection); | |
186 | void set_selection(const Record_Of_Template& other_value); | |
187 | ||
188 | void encode_text_permutation(Text_Buf& text_buf) const; | |
189 | void decode_text_permutation(Text_Buf& text_buf); | |
190 | private: | |
191 | Record_Of_Template& operator=(const Record_Of_Template& other_value); | |
192 | ||
193 | public: | |
194 | void add_permutation(unsigned int start_index, unsigned int end_index); | |
195 | ||
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(); } | |
199 | ||
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; | |
206 | }; | |
207 | ||
208 | #else | |
209 | ||
210 | class INTEGER; | |
211 | ||
212 | class Set_Of_Template : public Restricted_Length_Template { | |
213 | protected: | |
214 | union { | |
215 | struct { | |
216 | int n_elements; | |
217 | Base_Template** value_elements; // instances of a class derived from Base_Template | |
218 | } single_value; | |
219 | struct { | |
220 | int n_values; | |
221 | Set_Of_Template** list_value; // instances of a class derived from Set_Of_Template | |
222 | } value_list; | |
223 | }; | |
224 | Erroneous_descriptor_t* err_descr; | |
225 | ||
226 | Set_Of_Template(); | |
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); | |
232 | ~Set_Of_Template(); | |
233 | ||
234 | void copy_template(const Set_Of_Template& other_value); | |
235 | void copy_optional(const Base_Type* other_value); | |
236 | ||
237 | public: | |
238 | Base_Template* clone() const; | |
239 | void copy_value(const Base_Type* other_value); | |
240 | void clean_up(); | |
241 | ||
242 | int size_of() const { return size_of(TRUE); } | |
243 | int lengthof() const { return size_of(FALSE); } | |
244 | int n_elem() const; | |
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); | |
250 | protected: | |
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; | |
255 | ||
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); | |
259 | ||
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; | |
263 | ||
264 | public: | |
265 | void log() const; | |
266 | ||
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; | |
273 | ||
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); | |
285 | ||
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; | |
290 | ||
291 | void set_param(Module_Param& param); | |
292 | ||
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; } | |
295 | }; | |
296 | ||
297 | class Record_Of_Template : public Restricted_Length_Template { | |
298 | protected: | |
299 | union { | |
300 | struct { | |
301 | int n_elements; | |
302 | Base_Template **value_elements; // instances of a class derived from Base_Template | |
303 | } single_value; | |
304 | struct { | |
305 | int n_values; | |
306 | Record_Of_Template** list_value; // instances of a class derived from Record_Of_Template | |
307 | } value_list; | |
308 | }; | |
309 | Erroneous_descriptor_t* err_descr; | |
310 | ||
311 | struct Pair_of_elements; | |
312 | Pair_of_elements *permutation_intervals; | |
313 | unsigned int number_of_permutations; | |
314 | ||
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(); | |
322 | ||
323 | void clean_up_intervals(); | |
324 | ||
325 | void set_selection(template_sel new_selection); | |
326 | void set_selection(const Record_Of_Template& other_value); | |
327 | ||
328 | void encode_text_permutation(Text_Buf& text_buf) const; | |
329 | void decode_text_permutation(Text_Buf& text_buf); | |
330 | ||
331 | void copy_template(const Record_Of_Template& other_value); | |
332 | void copy_optional(const Base_Type* other_value); | |
333 | ||
334 | public: | |
335 | Base_Template* clone() const; | |
336 | void copy_value(const Base_Type* other_value); | |
337 | void clean_up(); | |
338 | ||
339 | void add_permutation(unsigned int start_index, unsigned int end_index); | |
340 | ||
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(); } | |
344 | ||
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; | |
351 | ||
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); | |
357 | protected: | |
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; | |
362 | ||
363 | int size_of(boolean is_size) const; | |
364 | Record_Of_Template* get_list_item(int list_index); | |
365 | ||
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; | |
369 | ||
370 | public: | |
371 | int size_of() const { return size_of(TRUE); } | |
372 | int lengthof() const { return size_of(FALSE); } | |
373 | int n_elem() const; | |
374 | void log() const; | |
375 | ||
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; | |
382 | ||
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); | |
387 | ||
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; | |
392 | ||
393 | void set_param(Module_Param& param); | |
394 | ||
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; } | |
397 | }; | |
398 | ||
399 | class Record_Template : public Base_Template | |
400 | { | |
401 | protected: | |
402 | union { | |
403 | struct { | |
404 | int n_elements; | |
405 | Base_Template** value_elements; | |
406 | } single_value; | |
407 | struct { | |
408 | int n_values; | |
409 | Record_Template** list_value; | |
410 | } value_list; | |
411 | }; | |
412 | Erroneous_descriptor_t* err_descr; | |
413 | ||
414 | /** create value elements by calling their constructor */ | |
415 | virtual void set_specific() = 0; | |
416 | ||
417 | void copy_optional(const Base_Type* other_value); | |
418 | void copy_template(const Record_Template& other_value); | |
419 | ||
420 | Record_Template(); | |
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); | |
426 | ~Record_Template(); | |
427 | ||
428 | public: | |
429 | void copy_value(const Base_Type* other_value); | |
430 | void clean_up(); | |
431 | ||
432 | void set_type(template_sel template_type, int list_length); | |
433 | Record_Template* get_list_item(int list_index) const; | |
434 | ||
435 | int size_of() const; | |
436 | ||
437 | boolean is_value() const; | |
438 | void valueofv(Base_Type* value) const; | |
439 | void set_value(template_sel other_value); | |
440 | ||
441 | protected: | |
442 | Base_Template* get_at(int index_value); | |
443 | const Base_Template* get_at(int index_value) const; | |
444 | ||
445 | /** create an instance by calling the default constructor */ | |
446 | virtual Record_Template* create() const = 0; | |
447 | ||
448 | virtual const char* fld_name(int /*field_index*/) const { return ""; } | |
449 | ||
450 | public: | |
451 | Base_Template* clone() const; | |
452 | ||
453 | void log() const; | |
454 | ||
455 | boolean matchv(const Base_Type* other_value) const; | |
456 | void log_matchv(const Base_Type* match_value) const; | |
457 | ||
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; | |
462 | ||
463 | void set_param(Module_Param& param); | |
464 | ||
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; } | |
467 | }; | |
468 | ||
469 | class Empty_Record_Template : public Base_Template | |
470 | { | |
471 | protected: | |
472 | struct { | |
473 | int n_values; | |
474 | Empty_Record_Template** list_value; | |
475 | } value_list; | |
476 | ||
477 | void copy_optional(const Base_Type* other_value); | |
478 | void copy_template(const Empty_Record_Template& other_value); | |
479 | ||
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(); | |
487 | ||
488 | public: | |
489 | void copy_value(const Base_Type* other_value); | |
490 | void clean_up(); | |
491 | ||
492 | void set_type(template_sel template_type, int list_length); | |
493 | Empty_Record_Template* get_list_item(int list_index) const; | |
494 | ||
495 | int size_of() const; | |
496 | ||
497 | boolean is_value() const; | |
498 | void valueofv(Base_Type* value) const; | |
499 | void set_value(template_sel other_value); | |
500 | ||
501 | protected: | |
502 | /** create an instance by calling the default constructor */ | |
503 | virtual Empty_Record_Template* create() const = 0; | |
504 | ||
505 | public: | |
506 | Base_Template* clone() const; | |
507 | ||
508 | void log() const; | |
509 | ||
510 | boolean matchv(const Base_Type* other_value) const; | |
511 | void log_matchv(const Base_Type* match_value) const; | |
512 | ||
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; | |
517 | ||
518 | void set_param(Module_Param& param); | |
519 | }; | |
520 | ||
521 | #undef VIRTUAL_IF_RUNTIME_2 | |
522 | #endif | |
523 | ||
524 | #endif |