Commit | Line | Data |
---|---|---|
970ed795 | 1 | /////////////////////////////////////////////////////////////////////////////// |
3abe9331 | 2 | // Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
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 DEFAULT_HH | |
9 | #define DEFAULT_HH | |
10 | ||
11 | #include "Types.h" | |
12 | #include "Basetype.hh" | |
13 | #include "Template.hh" | |
14 | #include "Optional.hh" | |
15 | ||
16 | class Text_Buf; | |
17 | class Module_Param; | |
18 | ||
19 | class Default_Base { | |
20 | friend class TTCN_Default; | |
21 | friend class DEFAULT; | |
22 | friend class DEFAULT_template; | |
23 | ||
24 | unsigned int default_id; | |
25 | const char *altstep_name; | |
26 | Default_Base *default_prev, *default_next; | |
27 | // Even though Default_base doesn't own these pointers, | |
28 | // it's best to disallow copying. | |
29 | Default_Base(const Default_Base&); | |
30 | Default_Base& operator=(const Default_Base&); | |
31 | public: | |
32 | Default_Base(const char *par_altstep_name); | |
33 | virtual ~Default_Base(); | |
34 | ||
35 | virtual alt_status call_altstep() = 0; | |
36 | ||
37 | void log() const; | |
38 | }; | |
39 | ||
40 | class DEFAULT : public Base_Type { | |
41 | friend class TTCN_Default; | |
42 | friend class DEFAULT_template; | |
43 | friend boolean operator==(component default_value, | |
44 | const DEFAULT& other_value); | |
45 | friend boolean operator==(Default_Base *default_value, | |
46 | const DEFAULT& other_value); | |
47 | ||
48 | Default_Base *default_ptr; | |
49 | public: | |
50 | DEFAULT(); | |
51 | DEFAULT(component other_value); | |
52 | DEFAULT(Default_Base *other_value); | |
53 | DEFAULT(const DEFAULT& other_value); | |
54 | ||
55 | DEFAULT& operator=(component other_value); | |
56 | DEFAULT& operator=(Default_Base *other_value); | |
57 | DEFAULT& operator=(const DEFAULT& other_value); | |
58 | ||
59 | boolean operator==(component other_value) const; | |
60 | boolean operator==(Default_Base *other_value) const; | |
61 | boolean operator==(const DEFAULT& other_value) const; | |
62 | ||
63 | boolean operator!=(component other_value) const | |
64 | { return !(*this == other_value); } | |
65 | boolean operator!=(Default_Base *other_value) const | |
66 | { return !(*this == other_value); } | |
67 | boolean operator!=(const DEFAULT& other_value) const | |
68 | { return !(*this == other_value); } | |
69 | ||
70 | operator Default_Base*() const; | |
71 | ||
72 | boolean is_bound() const; | |
73 | boolean is_value() const; | |
74 | void clean_up(); | |
75 | void log() const; | |
76 | ||
77 | #ifdef TITAN_RUNTIME_2 | |
78 | boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const DEFAULT*>(other_value)); } | |
79 | void set_value(const Base_Type* other_value) { *this = *(static_cast<const DEFAULT*>(other_value)); } | |
80 | Base_Type* clone() const { return new DEFAULT(*this); } | |
81 | const TTCN_Typedescriptor_t* get_descriptor() const { return &DEFAULT_descr_; } | |
82 | #else | |
83 | inline boolean is_present() const { return is_bound(); } | |
84 | #endif | |
85 | ||
86 | void set_param(Module_Param& param); | |
3abe9331 | 87 | Module_Param* get_param(Module_Param_Name& param_name) const; |
970ed795 EL |
88 | |
89 | void encode_text(Text_Buf& text_buf) const; | |
90 | void decode_text(Text_Buf& text_buf); | |
91 | }; | |
92 | ||
93 | extern boolean operator==(component default_value, const DEFAULT& other_value); | |
94 | extern boolean operator==(Default_Base *default_value, | |
95 | const DEFAULT& other_value); | |
96 | ||
97 | inline boolean operator!=(component default_value, const DEFAULT& other_value) | |
98 | { return !(default_value == other_value); } | |
99 | inline boolean operator!=(Default_Base *default_value, | |
100 | const DEFAULT& other_value) | |
101 | { return !(default_value == other_value); } | |
102 | ||
103 | ||
104 | class DEFAULT_template : public Base_Template { | |
105 | union { | |
106 | Default_Base *single_value; | |
107 | struct { | |
108 | unsigned int n_values; | |
109 | DEFAULT_template *list_value; | |
110 | } value_list; | |
111 | }; | |
112 | ||
113 | void copy_template(const DEFAULT_template& other_value); | |
114 | ||
115 | public: | |
116 | DEFAULT_template(); | |
117 | DEFAULT_template(template_sel other_value); | |
118 | DEFAULT_template(component other_value); | |
119 | DEFAULT_template(Default_Base *other_value); | |
120 | DEFAULT_template(const DEFAULT& other_value); | |
121 | DEFAULT_template(const OPTIONAL<DEFAULT>& other_value); | |
122 | DEFAULT_template(const DEFAULT_template& other_value); | |
123 | ||
124 | ~DEFAULT_template(); | |
125 | void clean_up(); | |
126 | ||
127 | DEFAULT_template& operator=(template_sel other_value); | |
128 | DEFAULT_template& operator=(component other_value); | |
129 | DEFAULT_template& operator=(Default_Base *other_value); | |
130 | DEFAULT_template& operator=(const DEFAULT& other_value); | |
131 | DEFAULT_template& operator=(const OPTIONAL<DEFAULT>& other_value); | |
132 | DEFAULT_template& operator=(const DEFAULT_template& other_value); | |
133 | ||
3abe9331 | 134 | boolean match(component other_value, boolean legacy = FALSE) const; |
135 | boolean match(Default_Base *other_value, boolean legacy = FALSE) const; | |
136 | boolean match(const DEFAULT& other_value, boolean legacy = FALSE) const; | |
970ed795 EL |
137 | Default_Base *valueof() const; |
138 | ||
139 | void set_type(template_sel template_type, unsigned int list_length); | |
140 | DEFAULT_template& list_item(unsigned int list_index); | |
141 | ||
142 | void log() const; | |
3abe9331 | 143 | void log_match(const DEFAULT& match_value, boolean legacy = FALSE) const; |
970ed795 EL |
144 | |
145 | void set_param(Module_Param& param); | |
3abe9331 | 146 | Module_Param* get_param(Module_Param_Name& param_name) const; |
970ed795 EL |
147 | |
148 | void encode_text(Text_Buf& text_buf) const; | |
149 | void decode_text(Text_Buf& text_buf); | |
150 | ||
3abe9331 | 151 | boolean is_present(boolean legacy = FALSE) const; |
152 | boolean match_omit(boolean legacy = FALSE) const; | |
970ed795 EL |
153 | #ifdef TITAN_RUNTIME_2 |
154 | void valueofv(Base_Type* value) const { *(static_cast<DEFAULT*>(value)) = valueof(); } | |
155 | void set_value(template_sel other_value) { *this = other_value; } | |
156 | void copy_value(const Base_Type* other_value) { *this = *(static_cast<const DEFAULT*>(other_value)); } | |
157 | Base_Template* clone() const { return new DEFAULT_template(*this); } | |
158 | const TTCN_Typedescriptor_t* get_descriptor() const { return &DEFAULT_descr_; } | |
3abe9331 | 159 | boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const DEFAULT*>(other_value)), legacy); } |
160 | void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const DEFAULT*>(match_value)), legacy); } | |
970ed795 | 161 | #else |
3abe9331 | 162 | void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const; |
970ed795 EL |
163 | #endif |
164 | }; | |
165 | ||
166 | class TTCN_Default { | |
167 | static unsigned int default_count, backup_count; | |
168 | static Default_Base *list_head, *list_tail, *backup_head, *backup_tail; | |
169 | static boolean control_defaults_saved; | |
170 | public: | |
171 | static unsigned int activate(Default_Base *new_default); | |
172 | static void deactivate(Default_Base *removable_default); | |
173 | static void deactivate(const DEFAULT& removable_default); | |
174 | static void deactivate_all(); | |
175 | ||
176 | static alt_status try_altsteps(); | |
177 | ||
178 | static void log(Default_Base *default_ptr); | |
179 | ||
180 | static void save_control_defaults(); | |
181 | static void restore_control_defaults(); | |
182 | static void reset_counter(); | |
183 | }; | |
184 | ||
185 | #endif |