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
15 * Szabo, Janos Zoltan – initial implementation
18 ******************************************************************************/
23 #include "Basetype.hh"
24 #include "Template.hh"
25 #include "Optional.hh"
31 friend class TTCN_Default;
33 friend class DEFAULT_template;
35 unsigned int default_id;
36 const char *altstep_name;
37 Default_Base *default_prev, *default_next;
38 // Even though Default_base doesn't own these pointers,
39 // it's best to disallow copying.
40 Default_Base(const Default_Base&);
41 Default_Base& operator=(const Default_Base&);
43 Default_Base(const char *par_altstep_name);
44 virtual ~Default_Base();
46 virtual alt_status call_altstep() = 0;
51 class DEFAULT : public Base_Type {
52 friend class TTCN_Default;
53 friend class DEFAULT_template;
54 friend boolean operator==(component default_value,
55 const DEFAULT& other_value);
56 friend boolean operator==(Default_Base *default_value,
57 const DEFAULT& other_value);
59 Default_Base *default_ptr;
62 DEFAULT(component other_value);
63 DEFAULT(Default_Base *other_value);
64 DEFAULT(const DEFAULT& other_value);
66 DEFAULT& operator=(component other_value);
67 DEFAULT& operator=(Default_Base *other_value);
68 DEFAULT& operator=(const DEFAULT& other_value);
70 boolean operator==(component other_value) const;
71 boolean operator==(Default_Base *other_value) const;
72 boolean operator==(const DEFAULT& other_value) const;
74 boolean operator!=(component other_value) const
75 { return !(*this == other_value); }
76 boolean operator!=(Default_Base *other_value) const
77 { return !(*this == other_value); }
78 boolean operator!=(const DEFAULT& other_value) const
79 { return !(*this == other_value); }
81 operator Default_Base*() const;
83 boolean is_bound() const;
84 boolean is_value() const;
88 #ifdef TITAN_RUNTIME_2
89 boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const DEFAULT*>(other_value)); }
90 void set_value(const Base_Type* other_value) { *this = *(static_cast<const DEFAULT*>(other_value)); }
91 Base_Type* clone() const { return new DEFAULT(*this); }
92 const TTCN_Typedescriptor_t* get_descriptor() const { return &DEFAULT_descr_; }
94 inline boolean is_present() const { return is_bound(); }
97 void set_param(Module_Param& param);
98 Module_Param* get_param(Module_Param_Name& param_name) const;
100 void encode_text(Text_Buf& text_buf) const;
101 void decode_text(Text_Buf& text_buf);
104 extern boolean operator==(component default_value, const DEFAULT& other_value);
105 extern boolean operator==(Default_Base *default_value,
106 const DEFAULT& other_value);
108 inline boolean operator!=(component default_value, const DEFAULT& other_value)
109 { return !(default_value == other_value); }
110 inline boolean operator!=(Default_Base *default_value,
111 const DEFAULT& other_value)
112 { return !(default_value == other_value); }
115 class DEFAULT_template : public Base_Template {
117 Default_Base *single_value;
119 unsigned int n_values;
120 DEFAULT_template *list_value;
124 void copy_template(const DEFAULT_template& other_value);
128 DEFAULT_template(template_sel other_value);
129 DEFAULT_template(component other_value);
130 DEFAULT_template(Default_Base *other_value);
131 DEFAULT_template(const DEFAULT& other_value);
132 DEFAULT_template(const OPTIONAL<DEFAULT>& other_value);
133 DEFAULT_template(const DEFAULT_template& other_value);
138 DEFAULT_template& operator=(template_sel other_value);
139 DEFAULT_template& operator=(component other_value);
140 DEFAULT_template& operator=(Default_Base *other_value);
141 DEFAULT_template& operator=(const DEFAULT& other_value);
142 DEFAULT_template& operator=(const OPTIONAL<DEFAULT>& other_value);
143 DEFAULT_template& operator=(const DEFAULT_template& other_value);
145 boolean match(component other_value, boolean legacy = FALSE) const;
146 boolean match(Default_Base *other_value, boolean legacy = FALSE) const;
147 boolean match(const DEFAULT& other_value, boolean legacy = FALSE) const;
148 Default_Base *valueof() const;
150 void set_type(template_sel template_type, unsigned int list_length);
151 DEFAULT_template& list_item(unsigned int list_index);
154 void log_match(const DEFAULT& match_value, boolean legacy = FALSE) const;
156 void set_param(Module_Param& param);
157 Module_Param* get_param(Module_Param_Name& param_name) const;
159 void encode_text(Text_Buf& text_buf) const;
160 void decode_text(Text_Buf& text_buf);
162 boolean is_present(boolean legacy = FALSE) const;
163 boolean match_omit(boolean legacy = FALSE) const;
164 #ifdef TITAN_RUNTIME_2
165 void valueofv(Base_Type* value) const { *(static_cast<DEFAULT*>(value)) = valueof(); }
166 void set_value(template_sel other_value) { *this = other_value; }
167 void copy_value(const Base_Type* other_value) { *this = *(static_cast<const DEFAULT*>(other_value)); }
168 Base_Template* clone() const { return new DEFAULT_template(*this); }
169 const TTCN_Typedescriptor_t* get_descriptor() const { return &DEFAULT_descr_; }
170 boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const DEFAULT*>(other_value)), legacy); }
171 void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const DEFAULT*>(match_value)), legacy); }
173 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
178 static unsigned int default_count, backup_count;
179 static Default_Base *list_head, *list_tail, *backup_head, *backup_tail;
180 static boolean control_defaults_saved;
182 static unsigned int activate(Default_Base *new_default);
183 static void deactivate(Default_Base *removable_default);
184 static void deactivate(const DEFAULT& removable_default);
185 static void deactivate_all();
187 static alt_status try_altsteps();
189 static void log(Default_Base *default_ptr);
191 static void save_control_defaults();
192 static void restore_control_defaults();
193 static void reset_counter();