1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 ///////////////////////////////////////////////////////////////////////////////
12 #include "Basetype.hh"
13 #include "Template.hh"
14 #include "Optional.hh"
20 friend class TTCN_Default;
22 friend class DEFAULT_template;
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&);
32 Default_Base(const char *par_altstep_name);
33 virtual ~Default_Base();
35 virtual alt_status call_altstep() = 0;
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);
48 Default_Base *default_ptr;
51 DEFAULT(component other_value);
52 DEFAULT(Default_Base *other_value);
53 DEFAULT(const DEFAULT& other_value);
55 DEFAULT& operator=(component other_value);
56 DEFAULT& operator=(Default_Base *other_value);
57 DEFAULT& operator=(const DEFAULT& other_value);
59 boolean operator==(component other_value) const;
60 boolean operator==(Default_Base *other_value) const;
61 boolean operator==(const DEFAULT& other_value) const;
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); }
70 operator Default_Base*() const;
72 boolean is_bound() const;
73 boolean is_value() const;
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_; }
83 inline boolean is_present() const { return is_bound(); }
86 void set_param(Module_Param& param);
87 Module_Param* get_param(Module_Param_Name& param_name) const;
89 void encode_text(Text_Buf& text_buf) const;
90 void decode_text(Text_Buf& text_buf);
93 extern boolean operator==(component default_value, const DEFAULT& other_value);
94 extern boolean operator==(Default_Base *default_value,
95 const DEFAULT& other_value);
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); }
104 class DEFAULT_template : public Base_Template {
106 Default_Base *single_value;
108 unsigned int n_values;
109 DEFAULT_template *list_value;
113 void copy_template(const DEFAULT_template& other_value);
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);
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);
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;
137 Default_Base *valueof() const;
139 void set_type(template_sel template_type, unsigned int list_length);
140 DEFAULT_template& list_item(unsigned int list_index);
143 void log_match(const DEFAULT& match_value, boolean legacy = FALSE) const;
145 void set_param(Module_Param& param);
146 Module_Param* get_param(Module_Param_Name& param_name) const;
148 void encode_text(Text_Buf& text_buf) const;
149 void decode_text(Text_Buf& text_buf);
151 boolean is_present(boolean legacy = FALSE) const;
152 boolean match_omit(boolean legacy = FALSE) const;
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_; }
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); }
162 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
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;
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();
176 static alt_status try_altsteps();
178 static void log(Default_Base *default_ptr);
180 static void save_control_defaults();
181 static void restore_control_defaults();
182 static void reset_counter();