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" | |
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 | ||
af710487 | 164 | #ifdef TITAN_RUNTIME_2 |
165 | // Dummy functions, only used in record of/set of value in RT2 | |
970ed795 EL |
166 | void add_refd_index(int) {} |
167 | void remove_refd_index(int) {} | |
af710487 | 168 | #endif |
970ed795 EL |
169 | }; |
170 | ||
171 | #ifndef TITAN_RUNTIME_2 | |
172 | ||
173 | class Record_Of_Template : public Restricted_Length_Template { | |
174 | protected: | |
175 | struct Pair_of_elements; | |
176 | Pair_of_elements *permutation_intervals; | |
177 | unsigned int number_of_permutations; | |
178 | ||
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(); | |
183 | ||
184 | void clean_up_intervals(); | |
185 | ||
186 | void set_selection(template_sel new_selection); | |
187 | void set_selection(const Record_Of_Template& other_value); | |
188 | ||
189 | void encode_text_permutation(Text_Buf& text_buf) const; | |
190 | void decode_text_permutation(Text_Buf& text_buf); | |
191 | private: | |
192 | Record_Of_Template& operator=(const Record_Of_Template& other_value); | |
193 | ||
194 | public: | |
195 | void add_permutation(unsigned int start_index, unsigned int end_index); | |
196 | ||
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(); } | |
200 | ||
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; | |
207 | }; | |
208 | ||
209 | #else | |
210 | ||
211 | class INTEGER; | |
212 | ||
213 | class Set_Of_Template : public Restricted_Length_Template { | |
214 | protected: | |
215 | union { | |
216 | struct { | |
217 | int n_elements; | |
218 | Base_Template** value_elements; // instances of a class derived from Base_Template | |
219 | } single_value; | |
220 | struct { | |
221 | int n_values; | |
222 | Set_Of_Template** list_value; // instances of a class derived from Set_Of_Template | |
223 | } value_list; | |
224 | }; | |
225 | Erroneous_descriptor_t* err_descr; | |
226 | ||
227 | Set_Of_Template(); | |
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); | |
233 | ~Set_Of_Template(); | |
234 | ||
235 | void copy_template(const Set_Of_Template& other_value); | |
236 | void copy_optional(const Base_Type* other_value); | |
237 | ||
238 | public: | |
239 | Base_Template* clone() const; | |
240 | void copy_value(const Base_Type* other_value); | |
241 | void clean_up(); | |
242 | ||
243 | int size_of() const { return size_of(TRUE); } | |
244 | int lengthof() const { return size_of(FALSE); } | |
245 | int n_elem() const; | |
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); | |
251 | protected: | |
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; | |
256 | ||
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); | |
260 | ||
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; | |
264 | ||
265 | public: | |
266 | void log() const; | |
267 | ||
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; | |
274 | ||
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); | |
286 | ||
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; | |
291 | ||
292 | void set_param(Module_Param& param); | |
293 | ||
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; } | |
296 | }; | |
297 | ||
298 | class Record_Of_Template : public Restricted_Length_Template { | |
299 | protected: | |
300 | union { | |
301 | struct { | |
302 | int n_elements; | |
303 | Base_Template **value_elements; // instances of a class derived from Base_Template | |
304 | } single_value; | |
305 | struct { | |
306 | int n_values; | |
307 | Record_Of_Template** list_value; // instances of a class derived from Record_Of_Template | |
308 | } value_list; | |
309 | }; | |
310 | Erroneous_descriptor_t* err_descr; | |
311 | ||
312 | struct Pair_of_elements; | |
313 | Pair_of_elements *permutation_intervals; | |
314 | unsigned int number_of_permutations; | |
315 | ||
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(); | |
323 | ||
324 | void clean_up_intervals(); | |
325 | ||
326 | void set_selection(template_sel new_selection); | |
327 | void set_selection(const Record_Of_Template& other_value); | |
328 | ||
329 | void encode_text_permutation(Text_Buf& text_buf) const; | |
330 | void decode_text_permutation(Text_Buf& text_buf); | |
331 | ||
332 | void copy_template(const Record_Of_Template& other_value); | |
333 | void copy_optional(const Base_Type* other_value); | |
334 | ||
335 | public: | |
336 | Base_Template* clone() const; | |
337 | void copy_value(const Base_Type* other_value); | |
338 | void clean_up(); | |
339 | ||
340 | void add_permutation(unsigned int start_index, unsigned int end_index); | |
341 | ||
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(); } | |
345 | ||
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; | |
352 | ||
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); | |
358 | protected: | |
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; | |
363 | ||
364 | int size_of(boolean is_size) const; | |
365 | Record_Of_Template* get_list_item(int list_index); | |
366 | ||
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; | |
370 | ||
371 | public: | |
372 | int size_of() const { return size_of(TRUE); } | |
373 | int lengthof() const { return size_of(FALSE); } | |
374 | int n_elem() const; | |
375 | void log() const; | |
376 | ||
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; | |
383 | ||
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); | |
388 | ||
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; | |
393 | ||
394 | void set_param(Module_Param& param); | |
395 | ||
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; } | |
398 | }; | |
399 | ||
400 | class Record_Template : public Base_Template | |
401 | { | |
402 | protected: | |
403 | union { | |
404 | struct { | |
405 | int n_elements; | |
406 | Base_Template** value_elements; | |
407 | } single_value; | |
408 | struct { | |
409 | int n_values; | |
410 | Record_Template** list_value; | |
411 | } value_list; | |
412 | }; | |
413 | Erroneous_descriptor_t* err_descr; | |
414 | ||
415 | /** create value elements by calling their constructor */ | |
416 | virtual void set_specific() = 0; | |
417 | ||
418 | void copy_optional(const Base_Type* other_value); | |
419 | void copy_template(const Record_Template& other_value); | |
420 | ||
421 | Record_Template(); | |
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); | |
427 | ~Record_Template(); | |
428 | ||
429 | public: | |
430 | void copy_value(const Base_Type* other_value); | |
431 | void clean_up(); | |
432 | ||
433 | void set_type(template_sel template_type, int list_length); | |
434 | Record_Template* get_list_item(int list_index) const; | |
435 | ||
436 | int size_of() const; | |
437 | ||
438 | boolean is_value() const; | |
439 | void valueofv(Base_Type* value) const; | |
440 | void set_value(template_sel other_value); | |
441 | ||
442 | protected: | |
443 | Base_Template* get_at(int index_value); | |
444 | const Base_Template* get_at(int index_value) const; | |
445 | ||
446 | /** create an instance by calling the default constructor */ | |
447 | virtual Record_Template* create() const = 0; | |
448 | ||
449 | virtual const char* fld_name(int /*field_index*/) const { return ""; } | |
450 | ||
451 | public: | |
452 | Base_Template* clone() const; | |
453 | ||
454 | void log() const; | |
455 | ||
456 | boolean matchv(const Base_Type* other_value) const; | |
457 | void log_matchv(const Base_Type* match_value) const; | |
458 | ||
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; | |
463 | ||
464 | void set_param(Module_Param& param); | |
465 | ||
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; } | |
468 | }; | |
469 | ||
470 | class Empty_Record_Template : public Base_Template | |
471 | { | |
472 | protected: | |
473 | struct { | |
474 | int n_values; | |
475 | Empty_Record_Template** list_value; | |
476 | } value_list; | |
477 | ||
478 | void copy_optional(const Base_Type* other_value); | |
479 | void copy_template(const Empty_Record_Template& other_value); | |
480 | ||
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(); | |
488 | ||
489 | public: | |
490 | void copy_value(const Base_Type* other_value); | |
491 | void clean_up(); | |
492 | ||
493 | void set_type(template_sel template_type, int list_length); | |
494 | Empty_Record_Template* get_list_item(int list_index) const; | |
495 | ||
496 | int size_of() const; | |
497 | ||
498 | boolean is_value() const; | |
499 | void valueofv(Base_Type* value) const; | |
500 | void set_value(template_sel other_value); | |
501 | ||
502 | protected: | |
503 | /** create an instance by calling the default constructor */ | |
504 | virtual Empty_Record_Template* create() const = 0; | |
505 | ||
506 | public: | |
507 | Base_Template* clone() const; | |
508 | ||
509 | void log() const; | |
510 | ||
511 | boolean matchv(const Base_Type* other_value) const; | |
512 | void log_matchv(const Base_Type* match_value) const; | |
513 | ||
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; | |
518 | ||
519 | void set_param(Module_Param& param); | |
520 | }; | |
521 | ||
522 | #undef VIRTUAL_IF_RUNTIME_2 | |
523 | #endif | |
524 | ||
525 | #endif |