Merge pull request #62 from BenceJanosSzabo/master
[deliverable/titan.core.git] / core / Default.hh
CommitLineData
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 * Szabados, Kristof
15 * Szabo, Janos Zoltan – initial implementation
16 * Tatarka, Gabor
17 *
18 ******************************************************************************/
970ed795
EL
19#ifndef DEFAULT_HH
20#define DEFAULT_HH
21
22#include "Types.h"
23#include "Basetype.hh"
24#include "Template.hh"
25#include "Optional.hh"
26
27class Text_Buf;
28class Module_Param;
29
30class Default_Base {
31 friend class TTCN_Default;
32 friend class DEFAULT;
33 friend class DEFAULT_template;
34
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&);
42public:
43 Default_Base(const char *par_altstep_name);
44 virtual ~Default_Base();
45
46 virtual alt_status call_altstep() = 0;
47
48 void log() const;
49};
50
51class 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);
58
59 Default_Base *default_ptr;
60public:
61 DEFAULT();
62 DEFAULT(component other_value);
63 DEFAULT(Default_Base *other_value);
64 DEFAULT(const DEFAULT& other_value);
65
66 DEFAULT& operator=(component other_value);
67 DEFAULT& operator=(Default_Base *other_value);
68 DEFAULT& operator=(const DEFAULT& other_value);
69
70 boolean operator==(component other_value) const;
71 boolean operator==(Default_Base *other_value) const;
72 boolean operator==(const DEFAULT& other_value) const;
73
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); }
80
81 operator Default_Base*() const;
82
83 boolean is_bound() const;
84 boolean is_value() const;
85 void clean_up();
86 void log() const;
87
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_; }
93#else
94 inline boolean is_present() const { return is_bound(); }
95#endif
96
97 void set_param(Module_Param& param);
3abe9331 98 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
99
100 void encode_text(Text_Buf& text_buf) const;
101 void decode_text(Text_Buf& text_buf);
102};
103
104extern boolean operator==(component default_value, const DEFAULT& other_value);
105extern boolean operator==(Default_Base *default_value,
106 const DEFAULT& other_value);
107
108inline boolean operator!=(component default_value, const DEFAULT& other_value)
109 { return !(default_value == other_value); }
110inline boolean operator!=(Default_Base *default_value,
111 const DEFAULT& other_value)
112 { return !(default_value == other_value); }
113
114
115class DEFAULT_template : public Base_Template {
116 union {
117 Default_Base *single_value;
118 struct {
119 unsigned int n_values;
120 DEFAULT_template *list_value;
121 } value_list;
122 };
123
124 void copy_template(const DEFAULT_template& other_value);
125
126public:
127 DEFAULT_template();
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);
134
135 ~DEFAULT_template();
136 void clean_up();
137
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);
144
3abe9331 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;
970ed795
EL
148 Default_Base *valueof() const;
149
150 void set_type(template_sel template_type, unsigned int list_length);
151 DEFAULT_template& list_item(unsigned int list_index);
152
153 void log() const;
3abe9331 154 void log_match(const DEFAULT& match_value, boolean legacy = FALSE) const;
970ed795
EL
155
156 void set_param(Module_Param& param);
3abe9331 157 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
158
159 void encode_text(Text_Buf& text_buf) const;
160 void decode_text(Text_Buf& text_buf);
161
3abe9331 162 boolean is_present(boolean legacy = FALSE) const;
163 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
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_; }
3abe9331 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); }
970ed795 172#else
3abe9331 173 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
174#endif
175};
176
177class TTCN_Default {
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;
181public:
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();
186
187 static alt_status try_altsteps();
188
189 static void log(Default_Base *default_ptr);
190
191 static void save_control_defaults();
192 static void restore_control_defaults();
193 static void reset_counter();
194};
195
196#endif
This page took 0.032576 seconds and 5 git commands to generate.