Commit | Line | Data |
---|---|---|
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 | * Balasko, Jeno | |
10 | * Baranyi, Botond | |
11 | * Beres, Szabolcs | |
12 | * Delic, Adam | |
13 | * Raduly, Csaba | |
14 | * | |
15 | ******************************************************************************/ | |
970ed795 EL |
16 | #ifndef PARAM_TYPES_H |
17 | #define PARAM_TYPES_H | |
18 | ||
19 | #include <stddef.h> | |
20 | #include "RInt.hh" | |
21 | #include "Types.h" | |
22 | #include "memory.h" | |
23 | #include "Vector.hh" | |
24 | #include <cstdio> | |
25 | ||
26 | ||
27 | // the following structures are used in the lexer/parser (ugly historical stuff) | |
28 | struct param_objid_t { | |
29 | int n_components; | |
30 | int *components_ptr; | |
31 | }; | |
32 | struct param_bitstring_t { | |
33 | int n_bits; | |
34 | unsigned char *bits_ptr; | |
35 | }; | |
36 | struct param_hexstring_t { | |
37 | int n_nibbles; | |
38 | unsigned char *nibbles_ptr; | |
39 | }; | |
40 | struct param_octetstring_t { | |
41 | int n_octets; | |
42 | unsigned char *octets_ptr; | |
43 | }; | |
44 | struct param_charstring_t { | |
45 | int n_chars; | |
46 | char *chars_ptr; | |
47 | }; | |
48 | struct param_universal_charstring_t { | |
49 | int n_uchars; | |
50 | universal_char *uchars_ptr; | |
970ed795 EL |
51 | }; |
52 | ||
53 | /////////////////////////////////////////////////////////////////////////////// | |
54 | ||
55 | class Module_Param_Id { | |
56 | Module_Param_Id(const Module_Param_Id& p); // copy constructor disabled | |
57 | Module_Param_Id& operator=(const Module_Param_Id& p); // assignment disabled | |
58 | public: | |
59 | Module_Param_Id() {} | |
60 | virtual ~Module_Param_Id() {} | |
61 | virtual bool is_explicit() const = 0; | |
62 | virtual bool is_index() const { return false; } | |
3abe9331 | 63 | virtual bool is_custom() const { return false; } |
970ed795 EL |
64 | virtual size_t get_index() const; |
65 | virtual char* get_name() const; | |
66 | virtual char* get_current_name() const; | |
67 | virtual bool next_name(int offset = 1); | |
68 | virtual char* get_str() const = 0; // returns an expstring that must be deallocated | |
69 | }; | |
70 | ||
71 | class Module_Param_Name : public Module_Param_Id { | |
72 | /** The first elements are the module name (if any) and the module parameter name, | |
73 | * followed by record/set field names and array (or record of/set of) indexes. | |
74 | * Since the names of modules, module parameters and fields cannot start with | |
75 | * numbers, the indexes are easily distinguishable from these elements. */ | |
76 | Vector<char*> names; | |
77 | /** The position of the current element being checked (in vector 'names') */ | |
78 | size_t pos; | |
79 | public: | |
80 | Module_Param_Name(const Vector<char*>& p): names(p), pos(0) {} | |
81 | ~Module_Param_Name() { for (size_t i = 0; i < names.size(); ++i) Free(names[i]); } | |
82 | bool is_explicit() const { return true; } | |
83 | char* get_current_name() const { return names[pos]; } | |
84 | bool next_name(int offset = 1) { | |
85 | if (static_cast<int>(pos) + offset < 0 || pos + offset >= names.size()) return false; | |
86 | pos += offset; | |
87 | return true; | |
88 | } | |
3abe9331 | 89 | void reset() { pos = 0; } |
90 | boolean is_single_name() const { return names.size() == 1; } | |
970ed795 EL |
91 | char* get_str() const; |
92 | }; | |
93 | ||
94 | class Module_Param_FieldName : public Module_Param_Id { | |
95 | char* name; // owned expstring_t | |
96 | public: | |
97 | Module_Param_FieldName(char* p): name(p) {} | |
98 | ~Module_Param_FieldName() { Free(name); } | |
99 | char* get_name() const { return name; } | |
100 | bool is_explicit() const { return true; } | |
101 | char* get_str() const; | |
102 | }; | |
103 | ||
104 | class Module_Param_Index : public Module_Param_Id { | |
105 | size_t index; | |
106 | bool is_expl; | |
107 | public: | |
108 | Module_Param_Index(size_t p_index, bool p_is_expl): index(p_index), is_expl(p_is_expl) {} | |
109 | size_t get_index() const { return index; } | |
110 | bool is_index() const { return true; } | |
111 | bool is_explicit() const { return is_expl; } | |
112 | char* get_str() const; | |
113 | }; | |
114 | ||
3abe9331 | 115 | /** Custom module parameter name class, used in Module_Param instances that aren't |
116 | * actual module parameters (length boundaries, array indexes and character codes in | |
117 | * quadruples use temporary Module_Param instances to allow the use of expressions | |
118 | * and references to module parameters). | |
119 | * Errors reported in these cases will contain the custom text set in this class, | |
120 | * instead of the regular error message header. */ | |
121 | class Module_Param_CustomName : public Module_Param_Id { | |
122 | char* name; // owned expstring_t | |
123 | public: | |
124 | Module_Param_CustomName(char* p): name(p) {} | |
125 | ~Module_Param_CustomName() { Free(name); } | |
126 | char* get_name() const { return name; } | |
127 | bool is_explicit() const { return true; } | |
128 | char* get_str() const; | |
129 | bool is_custom() const { return true; } | |
130 | }; | |
131 | ||
970ed795 EL |
132 | /////////////////////////////////////////////////////////////////////////////// |
133 | ||
134 | class Module_Param_Length_Restriction { | |
135 | Module_Param_Length_Restriction(const Module_Param_Length_Restriction& p); // copy constructor disabled | |
136 | Module_Param_Length_Restriction& operator=(const Module_Param_Length_Restriction& p); // assignment disabled | |
137 | size_t min; | |
138 | bool has_max; | |
139 | size_t max; | |
140 | public: | |
141 | Module_Param_Length_Restriction(): min(0), has_max(false), max(0) {} | |
142 | void set_single(size_t p_single) { has_max=true; min = max = p_single; } | |
143 | void set_min(size_t p_min) { min=p_min; } | |
144 | void set_max(size_t p_max) { has_max=true; max=p_max; } | |
145 | size_t get_min() const { return min; } | |
146 | bool get_has_max() const { return has_max; } | |
147 | size_t get_max() const { return max; } | |
148 | bool is_single() const { return has_max && min==max; } | |
149 | void log() const; | |
150 | }; | |
151 | ||
152 | /////////////////////////////////////////////////////////////////////////////// | |
153 | ||
3abe9331 | 154 | // forward declaration |
155 | class Module_Param_Ptr; | |
156 | ||
970ed795 EL |
157 | class Module_Param { |
158 | Module_Param(const Module_Param& p); // copy constructor disabled | |
159 | Module_Param& operator=(const Module_Param& p); // assignment disabled | |
160 | ||
161 | public: | |
162 | enum type_t { // list of all derived classes that can be instantiated | |
163 | MP_NotUsed, | |
164 | MP_Omit, | |
165 | MP_Integer, | |
166 | MP_Float, | |
167 | MP_Boolean, | |
168 | MP_Verdict, | |
169 | MP_Objid, | |
170 | MP_Bitstring, | |
171 | MP_Hexstring, | |
172 | MP_Octetstring, | |
173 | MP_Charstring, | |
174 | MP_Universal_Charstring, | |
175 | MP_Enumerated, | |
176 | MP_Ttcn_Null, | |
177 | MP_Ttcn_mtc, | |
178 | MP_Ttcn_system, | |
179 | MP_Asn_Null, | |
180 | MP_Any, | |
181 | MP_AnyOrNone, | |
182 | MP_IntRange, | |
183 | MP_FloatRange, | |
184 | MP_StringRange, | |
185 | MP_Pattern, | |
186 | MP_Bitstring_Template, | |
187 | MP_Hexstring_Template, | |
188 | MP_Octetstring_Template, | |
189 | MP_Assignment_List, | |
190 | MP_Value_List, | |
191 | MP_Indexed_List, | |
192 | MP_List_Template, | |
193 | MP_ComplementList_Template, | |
194 | MP_Superset_Template, | |
195 | MP_Subset_Template, | |
3abe9331 | 196 | MP_Permutation_Template, |
197 | MP_Reference, | |
198 | MP_Unbound, | |
199 | MP_Expression | |
970ed795 EL |
200 | }; |
201 | enum operation_type_t { OT_ASSIGN, OT_CONCAT }; | |
202 | enum basic_check_bits_t { // used to parametrize basic_check() | |
203 | BC_VALUE = 0x00, // non-list values | |
204 | BC_LIST = 0x01, // list values and templates | |
205 | BC_TEMPLATE = 0x02 // templates | |
206 | }; | |
3abe9331 | 207 | enum expression_operand_t { // expression types for MP_Expression |
208 | EXPR_ERROR, // for reporting errors | |
209 | EXPR_ADD, | |
210 | EXPR_SUBTRACT, | |
211 | EXPR_MULTIPLY, | |
212 | EXPR_DIVIDE, | |
213 | EXPR_CONCATENATE, | |
214 | EXPR_NEGATE // only operand1 is used | |
215 | }; | |
970ed795 EL |
216 | |
217 | protected: | |
218 | operation_type_t operation_type; | |
219 | Module_Param_Id* id; // owned | |
220 | Module_Param* parent; // not owned, NULL if no parent | |
221 | boolean has_ifpresent; // true if 'ifpresent' was used | |
222 | Module_Param_Length_Restriction* length_restriction; // owned, NULL if no length restriction | |
223 | ||
224 | public: | |
225 | // set default values, these shall be changed using member functions or constructors of derived classes | |
226 | Module_Param(): operation_type(OT_ASSIGN), id(NULL), parent(NULL), has_ifpresent(FALSE), length_restriction(NULL) {} | |
227 | virtual ~Module_Param() { delete id; delete length_restriction; } | |
228 | ||
229 | virtual type_t get_type() const = 0; | |
230 | void set_parent(Module_Param* p_parent) { parent = p_parent; } | |
231 | void set_id(Module_Param_Id* p_id); | |
232 | Module_Param_Id* get_id() const; // returns the Id or error, never returns NULL (because every module parameter | |
233 | // should have either an explicit or an implicit id when this is called) | |
234 | void set_ifpresent() { has_ifpresent = TRUE; } | |
235 | boolean get_ifpresent() const { return has_ifpresent; } | |
236 | void set_length_restriction(Module_Param_Length_Restriction* p_length_restriction); | |
237 | Module_Param_Length_Restriction* get_length_restriction() const { return length_restriction; } | |
238 | operation_type_t get_operation_type() const { return operation_type; } | |
239 | void set_operation_type(operation_type_t p_optype) { operation_type = p_optype; } | |
240 | const char* get_operation_type_str() const; | |
241 | const char* get_operation_type_sign_str() const; | |
242 | virtual const char* get_type_str() const = 0; | |
243 | void log(bool log_id = true) const; | |
244 | virtual void log_value() const = 0; | |
245 | char* get_param_context() const; | |
246 | ||
247 | // error reporter functions | |
248 | void error(const char* err, ...) const | |
249 | __attribute__ ((__format__ (__printf__, 2, 3), __noreturn__)); | |
250 | ||
3abe9331 | 251 | void type_error(const char* expected, const char* type_name = NULL) const |
252 | __attribute__ ((__noreturn__)); | |
253 | ||
254 | inline void expr_type_error(const char* type_name) const | |
970ed795 | 255 | __attribute__ ((__noreturn__)) { |
3abe9331 | 256 | error("%s is not allowed in %s expression.", |
257 | get_expr_type_str(), type_name); | |
970ed795 EL |
258 | } |
259 | ||
260 | // check and error report function for operation type, ifpresent and length restriction | |
261 | void basic_check(int check_type, const char* what) const; | |
262 | ||
263 | // add element to compound type, error if not compound type | |
264 | virtual void add_elem(Module_Param* value); | |
265 | virtual void add_list_with_implicit_ids(Vector<Module_Param*>* mp_list); | |
266 | ||
267 | // try to access data of a given type, error if it's another type | |
268 | virtual boolean get_boolean() const; | |
269 | virtual size_t get_size() const; | |
270 | virtual Module_Param* get_elem(size_t index) const; | |
271 | virtual int get_string_size() const; | |
272 | virtual void* get_string_data() const; | |
273 | virtual int_val_t* get_lower_int() const; | |
274 | virtual int_val_t* get_upper_int() const; | |
275 | virtual double get_lower_float() const; | |
276 | virtual double get_upper_float() const; | |
277 | virtual bool has_lower_float() const; | |
278 | virtual bool has_upper_float() const; | |
279 | virtual universal_char get_lower_uchar() const; | |
280 | virtual universal_char get_upper_uchar() const; | |
281 | virtual int_val_t* get_integer() const; | |
282 | virtual double get_float() const; | |
283 | virtual char* get_pattern() const; | |
284 | virtual verdicttype get_verdict() const; | |
285 | virtual char* get_enumerated() const; | |
3abe9331 | 286 | virtual Module_Param_Ptr get_referenced_param() const; |
287 | virtual expression_operand_t get_expr_type() const; | |
288 | virtual const char* get_expr_type_str() const; | |
289 | virtual Module_Param* get_operand1() const; | |
290 | virtual Module_Param* get_operand2() const; | |
291 | }; | |
292 | ||
293 | /** Smart pointer class for Module_Param instances | |
294 | * Uses a reference counter so the Module_Param object is never copied. | |
295 | * Deletes the object (if it's temporary), when the reference counter reaches zero. */ | |
296 | class Module_Param_Ptr { | |
297 | struct module_param_ptr_struct { | |
298 | Module_Param* mp_ptr; | |
299 | boolean temporary; | |
300 | int ref_count; | |
301 | } *ptr; | |
302 | void clean_up(); | |
303 | public: | |
304 | Module_Param_Ptr(Module_Param* p); | |
305 | Module_Param_Ptr(const Module_Param_Ptr& r); | |
306 | ~Module_Param_Ptr() { clean_up(); } | |
307 | Module_Param_Ptr& operator=(const Module_Param_Ptr& r); | |
308 | void set_temporary() { ptr->temporary = TRUE; } | |
309 | Module_Param& operator*() { return *ptr->mp_ptr; } | |
310 | Module_Param* operator->() { return ptr->mp_ptr; } | |
311 | }; | |
312 | ||
313 | /** Module parameter reference (and enumerated value) | |
314 | * Stores a reference to another module parameter, that can be retrieved with the | |
315 | * method get_referenced_param(). | |
316 | * @note Enumerated values are stored as references (with only 1 name segment), | |
317 | * since the parser cannot distinguish them. */ | |
318 | class Module_Param_Reference : public Module_Param { | |
319 | Module_Param_Name* mp_ref; | |
320 | public: | |
321 | type_t get_type() const { return MP_Reference; } | |
322 | Module_Param_Reference(Module_Param_Name* p); | |
323 | ~Module_Param_Reference() { delete mp_ref; } | |
324 | Module_Param_Ptr get_referenced_param() const; | |
325 | char* get_enumerated() const; | |
326 | const char* get_type_str() const { return "module parameter reference"; } | |
327 | void log_value() const; | |
328 | }; | |
329 | ||
330 | /** Unbound module parameter | |
331 | * This cannot be created by the parser, only by get_referenced_param(), when | |
332 | * the referenced module parameter is unbound. */ | |
333 | class Module_Param_Unbound : public Module_Param { | |
334 | type_t get_type() const { return MP_Unbound; } | |
335 | const char* get_type_str() const { return "<unbound>"; } | |
336 | void log_value() const; | |
337 | }; | |
338 | ||
339 | /** Module parameter expression | |
340 | * Contains an unprocessed module parameter expression with one or two operands. | |
341 | * Expression types: | |
342 | * with 2 operands: +, -, *, /, & | |
343 | * with 1 operand: - (unary + is handled by the parser). */ | |
344 | class Module_Param_Expression : public Module_Param { | |
345 | private: | |
346 | expression_operand_t expr_type; | |
347 | Module_Param* operand1; | |
348 | Module_Param* operand2; | |
349 | public: | |
350 | Module_Param_Expression(expression_operand_t p_type, Module_Param* p_op1, | |
351 | Module_Param* p_op2); | |
352 | Module_Param_Expression(Module_Param* p_op); | |
353 | ~Module_Param_Expression(); | |
354 | expression_operand_t get_expr_type() const { return expr_type; } | |
355 | const char* get_expr_type_str() const; | |
356 | Module_Param* get_operand1() const { return operand1; } | |
357 | Module_Param* get_operand2() const { return operand2; } | |
358 | type_t get_type() const { return MP_Expression; } | |
359 | const char* get_type_str() const { return "expression"; } | |
360 | void log_value() const; | |
970ed795 EL |
361 | }; |
362 | ||
363 | class Module_Param_NotUsed : public Module_Param { | |
364 | public: | |
365 | type_t get_type() const { return MP_NotUsed; } | |
366 | const char* get_type_str() const { return "-"; } | |
367 | void log_value() const; | |
368 | }; | |
369 | ||
370 | class Module_Param_Omit : public Module_Param { | |
371 | public: | |
372 | type_t get_type() const { return MP_Omit; } | |
373 | const char* get_type_str() const { return "omit"; } | |
374 | void log_value() const; | |
375 | }; | |
376 | ||
377 | class Module_Param_Integer : public Module_Param { | |
378 | int_val_t* integer_value; | |
379 | public: | |
380 | type_t get_type() const { return MP_Integer; } | |
381 | Module_Param_Integer(int_val_t* p); | |
382 | ~Module_Param_Integer() { delete integer_value; } | |
383 | int_val_t* get_integer() const { return integer_value; } | |
384 | const char* get_type_str() const { return "integer"; } | |
385 | void log_value() const; | |
386 | }; | |
387 | ||
388 | class Module_Param_Float : public Module_Param { | |
389 | double float_value; | |
390 | public: | |
391 | type_t get_type() const { return MP_Float; } | |
392 | Module_Param_Float(double p): float_value(p) {} | |
393 | double get_float() const { return float_value; } | |
394 | const char* get_type_str() const { return "float"; } | |
395 | void log_value() const; | |
396 | }; | |
397 | ||
398 | class Module_Param_Boolean : public Module_Param { | |
399 | boolean boolean_value; | |
400 | public: | |
401 | type_t get_type() const { return MP_Boolean; } | |
402 | Module_Param_Boolean(boolean p): boolean_value(p) {} | |
403 | boolean get_boolean() const { return boolean_value; } | |
404 | const char* get_type_str() const { return "boolean"; } | |
405 | void log_value() const; | |
406 | }; | |
407 | ||
408 | class Module_Param_Verdict : public Module_Param { | |
409 | verdicttype verdict_value; | |
410 | public: | |
411 | type_t get_type() const { return MP_Verdict; } | |
412 | Module_Param_Verdict(verdicttype p): verdict_value(p) {} | |
413 | verdicttype get_verdict() const { return verdict_value; } | |
414 | const char* get_type_str() const { return "verdict"; } | |
415 | void log_value() const; | |
416 | }; | |
417 | ||
418 | template <typename CHARTYPE> | |
419 | class Module_Param_String : public Module_Param { | |
420 | protected: | |
421 | int n_chars; | |
422 | CHARTYPE* chars_ptr; | |
423 | public: | |
424 | Module_Param_String(int p_n, CHARTYPE* p_c): n_chars(p_n), chars_ptr(p_c) {} | |
425 | ~Module_Param_String() { Free(chars_ptr); } | |
426 | int get_string_size() const { return n_chars; } | |
427 | void* get_string_data() const { return (void*)chars_ptr; } | |
428 | }; | |
429 | ||
430 | class Module_Param_Objid : public Module_Param_String<int> { // special string of integers :) | |
431 | public: | |
432 | type_t get_type() const { return MP_Objid; } | |
433 | Module_Param_Objid(int p_n, int* p_c): Module_Param_String<int>(p_n, p_c) {} | |
434 | const char* get_type_str() const { return "object identifier"; } | |
435 | void log_value() const; | |
436 | }; | |
437 | ||
438 | class Module_Param_Bitstring : public Module_Param_String<unsigned char> { | |
439 | public: | |
440 | type_t get_type() const { return MP_Bitstring; } | |
441 | Module_Param_Bitstring(int p_n, unsigned char* p_c): Module_Param_String<unsigned char>(p_n, p_c) {} | |
442 | const char* get_type_str() const { return "bitstring"; } | |
443 | void log_value() const; | |
444 | }; | |
445 | ||
446 | class Module_Param_Hexstring : public Module_Param_String<unsigned char> { | |
447 | public: | |
448 | type_t get_type() const { return MP_Hexstring; } | |
449 | Module_Param_Hexstring(int p_n, unsigned char* p_c): Module_Param_String<unsigned char>(p_n, p_c) {} | |
450 | const char* get_type_str() const { return "hexstring"; } | |
451 | void log_value() const; | |
452 | }; | |
453 | ||
454 | class Module_Param_Octetstring : public Module_Param_String<unsigned char> { | |
455 | public: | |
456 | type_t get_type() const { return MP_Octetstring; } | |
457 | Module_Param_Octetstring(int p_n, unsigned char* p_c): Module_Param_String<unsigned char>(p_n, p_c) {} | |
458 | const char* get_type_str() const { return "octetstring"; } | |
459 | void log_value() const; | |
460 | }; | |
461 | ||
462 | class Module_Param_Charstring : public Module_Param_String<char> { | |
463 | public: | |
464 | type_t get_type() const { return MP_Charstring; } | |
465 | Module_Param_Charstring(int p_n, char* p_c): Module_Param_String<char>(p_n, p_c) {} | |
466 | const char* get_type_str() const { return "charstring"; } | |
467 | void log_value() const; | |
468 | }; | |
469 | ||
470 | class Module_Param_Universal_Charstring : public Module_Param_String<universal_char> { | |
970ed795 EL |
471 | public: |
472 | type_t get_type() const { return MP_Universal_Charstring; } | |
3abe9331 | 473 | Module_Param_Universal_Charstring(int p_n, universal_char* p_c) |
474 | : Module_Param_String<universal_char>(p_n, p_c) {} | |
970ed795 EL |
475 | const char* get_type_str() const { return "universal charstring"; } |
476 | void log_value() const; | |
970ed795 EL |
477 | }; |
478 | ||
479 | class Module_Param_Enumerated : public Module_Param { | |
480 | char* enum_value; | |
481 | public: | |
482 | type_t get_type() const { return MP_Enumerated; } | |
483 | Module_Param_Enumerated(char* p_e): enum_value(p_e) {} | |
484 | ~Module_Param_Enumerated() { Free(enum_value); } | |
485 | char* get_enumerated() const { return enum_value; } | |
486 | const char* get_type_str() const { return "enumerated"; } | |
487 | void log_value() const; | |
488 | }; | |
489 | ||
490 | class Module_Param_Ttcn_Null : public Module_Param { | |
491 | public: | |
492 | type_t get_type() const { return MP_Ttcn_Null; } | |
493 | const char* get_type_str() const { return "null"; } | |
494 | void log_value() const; | |
495 | }; | |
496 | ||
497 | class Module_Param_Ttcn_mtc : public Module_Param { | |
498 | public: | |
499 | type_t get_type() const { return MP_Ttcn_mtc; } | |
500 | const char* get_type_str() const { return "mtc"; } | |
501 | void log_value() const; | |
502 | }; | |
503 | ||
504 | class Module_Param_Ttcn_system : public Module_Param { | |
505 | public: | |
506 | type_t get_type() const { return MP_Ttcn_system; } | |
507 | const char* get_type_str() const { return "system"; } | |
508 | void log_value() const; | |
509 | }; | |
510 | ||
511 | class Module_Param_Asn_Null : public Module_Param { | |
512 | public: | |
513 | type_t get_type() const { return MP_Asn_Null; } | |
514 | const char* get_type_str() const { return "NULL"; } | |
515 | void log_value() const; | |
516 | }; | |
517 | ||
518 | class Module_Param_Any : public Module_Param { | |
519 | public: | |
520 | type_t get_type() const { return MP_Any; } | |
521 | const char* get_type_str() const { return "?"; } | |
522 | void log_value() const; | |
523 | }; | |
524 | ||
525 | class Module_Param_AnyOrNone : public Module_Param { | |
526 | public: | |
527 | type_t get_type() const { return MP_AnyOrNone; } | |
528 | const char* get_type_str() const { return "*"; } | |
529 | void log_value() const; | |
530 | }; | |
531 | ||
532 | class Module_Param_IntRange : public Module_Param { | |
533 | int_val_t* lower_bound; // NULL == -infinity | |
534 | int_val_t* upper_bound; // NULL == infinity | |
535 | public: | |
536 | type_t get_type() const { return MP_IntRange; } | |
537 | Module_Param_IntRange(int_val_t* p_l, int_val_t* p_u): lower_bound(p_l), upper_bound(p_u) {} | |
538 | ~Module_Param_IntRange() { Free(lower_bound); Free(upper_bound); } | |
539 | int_val_t* get_lower_int() const { return lower_bound; } | |
540 | int_val_t* get_upper_int() const { return upper_bound; } | |
541 | const char* get_type_str() const { return "integer range"; } | |
542 | void log_value() const; | |
543 | static void log_bound(int_val_t* bound, bool is_lower); | |
544 | }; | |
545 | ||
546 | class Module_Param_FloatRange : public Module_Param { | |
547 | double lower_bound; | |
548 | bool has_lower; | |
549 | double upper_bound; | |
550 | bool has_upper; | |
551 | public: | |
552 | type_t get_type() const { return MP_FloatRange; } | |
553 | Module_Param_FloatRange(double p_lb, bool p_hl, double p_ub, bool p_hu): lower_bound(p_lb), has_lower(p_hl), upper_bound(p_ub), has_upper(p_hu) {} | |
554 | double get_lower_float() const { return lower_bound; } | |
555 | double get_upper_float() const { return upper_bound; } | |
556 | bool has_lower_float() const { return has_lower; } | |
557 | bool has_upper_float() const { return has_upper; } | |
558 | const char* get_type_str() const { return "float range"; } | |
559 | void log_value() const; | |
560 | }; | |
561 | ||
562 | class Module_Param_StringRange : public Module_Param { | |
563 | universal_char lower_bound; | |
564 | universal_char upper_bound; | |
565 | public: | |
566 | type_t get_type() const { return MP_StringRange; } | |
567 | Module_Param_StringRange(const universal_char& p_lb, const universal_char& p_ub): lower_bound(p_lb), upper_bound(p_ub) {} | |
568 | universal_char get_lower_uchar() const { return lower_bound; } | |
569 | universal_char get_upper_uchar() const { return upper_bound; } | |
570 | const char* get_type_str() const { return "char range"; } | |
571 | void log_value() const; | |
572 | }; | |
573 | ||
574 | class Module_Param_Pattern : public Module_Param { | |
575 | char* pattern; | |
576 | public: | |
577 | type_t get_type() const { return MP_Pattern; } | |
578 | Module_Param_Pattern(char* p_p): pattern(p_p) {} | |
579 | ~Module_Param_Pattern() { Free(pattern); } | |
580 | char* get_pattern() const { return pattern; } | |
581 | const char* get_type_str() const { return "pattern"; } | |
582 | void log_value() const; | |
583 | }; | |
584 | ||
585 | class Module_Param_Bitstring_Template : public Module_Param_String<unsigned char> { // template parameter type is taken from String_struct.hh (B/H/O-string template structures) | |
586 | public: | |
587 | type_t get_type() const { return MP_Bitstring_Template; } | |
588 | Module_Param_Bitstring_Template(int p_n, unsigned char* p_c): Module_Param_String<unsigned char>(p_n, p_c) {} | |
589 | const char* get_type_str() const { return "bitstring template"; } | |
590 | void log_value() const; | |
591 | }; | |
592 | ||
593 | class Module_Param_Hexstring_Template : public Module_Param_String<unsigned char> { | |
594 | public: | |
595 | type_t get_type() const { return MP_Hexstring_Template; } | |
596 | Module_Param_Hexstring_Template(int p_n, unsigned char* p_c): Module_Param_String<unsigned char>(p_n, p_c) {} | |
597 | const char* get_type_str() const { return "hexstring template"; } | |
598 | void log_value() const; | |
599 | }; | |
600 | ||
601 | class Module_Param_Octetstring_Template : public Module_Param_String<unsigned short> { | |
602 | public: | |
603 | type_t get_type() const { return MP_Octetstring_Template; } | |
604 | Module_Param_Octetstring_Template(int p_n, unsigned short* p_c): Module_Param_String<unsigned short>(p_n, p_c) {} | |
605 | const char* get_type_str() const { return "octetstring template"; } | |
606 | void log_value() const; | |
607 | }; | |
608 | ||
609 | class Module_Param_Compound : public Module_Param { | |
610 | Vector<Module_Param*> values; // Module_Param instances are owned | |
611 | public: | |
612 | Module_Param_Compound() {} | |
613 | ~Module_Param_Compound(); | |
614 | void log_value_vec(const char* begin_str, const char* end_str) const; | |
615 | void add_elem(Module_Param* value); | |
616 | // add a list of params, adds to each one an implicit index based on | |
617 | // the position in the values vector | |
618 | void add_list_with_implicit_ids(Vector<Module_Param*>* mp_list); | |
619 | size_t get_size() const; | |
620 | Module_Param* get_elem(size_t index) const; | |
621 | }; | |
622 | ||
623 | class Module_Param_Assignment_List : public Module_Param_Compound { | |
624 | public: | |
625 | type_t get_type() const { return MP_Assignment_List; } | |
626 | const char* get_type_str() const { return "list with assignment notation"; } | |
627 | void log_value() const { log_value_vec("{","}"); } | |
628 | }; | |
629 | ||
630 | class Module_Param_Value_List : public Module_Param_Compound { | |
631 | public: | |
632 | type_t get_type() const { return MP_Value_List; } | |
633 | const char* get_type_str() const { return "value list"; } | |
634 | void log_value() const { log_value_vec("{","}"); } | |
635 | }; | |
636 | ||
637 | class Module_Param_Indexed_List : public Module_Param_Compound { | |
638 | public: | |
639 | type_t get_type() const { return MP_Indexed_List; } | |
640 | const char* get_type_str() const { return "indexed value list"; } | |
641 | void log_value() const { log_value_vec("{","}"); } | |
642 | }; | |
643 | ||
644 | class Module_Param_List_Template : public Module_Param_Compound { | |
645 | public: | |
646 | type_t get_type() const { return MP_List_Template; } | |
647 | const char* get_type_str() const { return "list template"; } | |
648 | void log_value() const { log_value_vec("(",")"); } | |
649 | }; | |
650 | ||
651 | class Module_Param_ComplementList_Template : public Module_Param_Compound { | |
652 | public: | |
653 | type_t get_type() const { return MP_ComplementList_Template; } | |
654 | const char* get_type_str() const { return "complemented list template"; } | |
655 | void log_value() const { log_value_vec("complement(",")"); } | |
656 | }; | |
657 | ||
658 | class Module_Param_Superset_Template : public Module_Param_Compound { | |
659 | public: | |
660 | type_t get_type() const { return MP_Superset_Template; } | |
661 | const char* get_type_str() const { return "superset template"; } | |
662 | void log_value() const { log_value_vec("superset(",")"); } | |
663 | }; | |
664 | ||
665 | class Module_Param_Subset_Template : public Module_Param_Compound { | |
666 | public: | |
667 | type_t get_type() const { return MP_Subset_Template; } | |
668 | const char* get_type_str() const { return "subset template"; } | |
669 | void log_value() const { log_value_vec("subset(",")"); } | |
670 | }; | |
671 | ||
672 | class Module_Param_Permutation_Template : public Module_Param_Compound { | |
673 | public: | |
674 | type_t get_type() const { return MP_Permutation_Template; } | |
675 | const char* get_type_str() const { return "permutation template"; } | |
676 | void log_value() const { log_value_vec("permutation(",")"); } | |
677 | }; | |
678 | ||
679 | class Ttcn_String_Parsing { | |
680 | private: // only instantiation can set it to true and destruction set it back to false | |
681 | static bool string_parsing; | |
682 | public: | |
683 | Ttcn_String_Parsing() { string_parsing = true; } | |
684 | ~Ttcn_String_Parsing() { string_parsing = false; } | |
685 | static bool happening() { return string_parsing; } | |
686 | }; | |
687 | ||
688 | /** Use the configuration file parser to convert a string into a TTCN-3 value. | |
689 | * @param mp_str the converted string (used as if it were a module parameter in a | |
690 | * config file) | |
691 | * @param is_component true, if the expected TTCN-3 value is a component | |
692 | * @return the TTCN-3 value in module parameter form (will be set using set_param) | |
693 | * @tricky Component names (given with the "start" command) can contain any characters. | |
694 | * This conflicts with several other rules, so certain rules in the parser will only | |
695 | * be applied to components. */ | |
696 | extern Module_Param* process_config_string2ttcn(const char* mp_str, bool is_component); | |
697 | ||
698 | #endif |