Merge pull request #77 from balaskoa/master
[deliverable/titan.core.git] / core / Component.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 COMPONENT_HH
20#define COMPONENT_HH
21
22#include "Types.h"
23#include "Basetype.hh"
24#include "Template.hh"
25#include "Optional.hh"
26
27class Module_Param;
28
29// value class for all component types
30
31class COMPONENT : public Base_Type {
32 friend class COMPONENT_template;
33 friend boolean operator==(component component_value,
34 const COMPONENT& other_value);
35
36 static unsigned int n_component_names;
37 struct component_name_struct;
38 static component_name_struct *component_names;
39
40 component component_value;
41
42public:
43 COMPONENT();
44 COMPONENT(component other_value);
45 COMPONENT(const COMPONENT& other_value);
46
47 COMPONENT& operator=(component other_value);
48 COMPONENT& operator=(const COMPONENT& other_value);
49
50 boolean operator==(component other_value) const;
51 boolean operator==(const COMPONENT& other_value) const;
52
53 inline boolean operator!=(component other_value) const
54 { return !(*this == other_value); }
55 inline boolean operator!=(const COMPONENT& other_value) const
56 { return !(*this == other_value); }
57
58 operator component() const;
59
60 inline boolean is_bound() const
61 { return component_value != UNBOUND_COMPREF; }
62 inline boolean is_value() const
63 { return component_value != UNBOUND_COMPREF; }
64 inline void clean_up() { component_value = UNBOUND_COMPREF; }
65 void must_bound(const char*) const;
66
67 void log() const;
68
69#ifdef TITAN_RUNTIME_2
70 boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const COMPONENT*>(other_value)); }
71 void set_value(const Base_Type* other_value) { *this = *(static_cast<const COMPONENT*>(other_value)); }
72 Base_Type* clone() const { return new COMPONENT(*this); }
73 const TTCN_Typedescriptor_t* get_descriptor() const { return &COMPONENT_descr_; }
74#else
75 inline boolean is_present() const { return is_bound(); }
76#endif
77
78 alt_status done() const;
79 alt_status killed() const;
80
81 boolean running() const;
82 boolean alive() const;
83
84 void stop() const;
85 void kill() const;
86
87 void set_param(Module_Param& param);
3abe9331 88 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
89
90 void encode_text(Text_Buf& text_buf) const;
91 void decode_text(Text_Buf& text_buf);
92
93 static void register_component_name(component component_reference,
94 const char *component_name);
95 static const char *get_component_name(component component_reference);
96 static void clear_component_names();
97 static void log_component_reference(component component_reference);
98 /** Returns the symbolic value of \p component_reference
99 *
100 * If it's a special value, it returns its name ("null","mtc" or "system").
101 * If it has a name, it returns "name(number)"
102 * Else returns "number"
103 *
104 * @param component_reference
105 * @return a string which must be Free()'d
106 */
107 static char *get_component_string(component component_reference);
108
109 inline boolean is_component() { return TRUE; }
110};
111
112extern boolean operator==(component component_value,
113 const COMPONENT& other_value);
114
115inline boolean operator!=(component component_value,
116 const COMPONENT& other_value)
117{
118 return !(component_value == other_value);
119}
120
121extern COMPONENT self;
122
123
124// template for all component types
125
126class COMPONENT_template : public Base_Template {
127private:
128 union {
129 component single_value;
130 struct {
131 unsigned int n_values;
132 COMPONENT_template *list_value;
133 } value_list;
134 };
135
136 void copy_template(const COMPONENT_template& other_value);
137
138public:
139 COMPONENT_template();
140 COMPONENT_template(template_sel other_value);
141 COMPONENT_template(component other_value);
142 COMPONENT_template(const COMPONENT& other_value);
143 COMPONENT_template(const OPTIONAL<COMPONENT>& other_value);
144 COMPONENT_template(const COMPONENT_template& other_value);
145
146 ~COMPONENT_template();
147 void clean_up();
148
149 COMPONENT_template& operator=(template_sel other_value);
150 COMPONENT_template& operator=(component other_value);
151 COMPONENT_template& operator=(const COMPONENT& other_value);
152 COMPONENT_template& operator=(const OPTIONAL<COMPONENT>& other_value);
153 COMPONENT_template& operator=(const COMPONENT_template& other_value);
154
3abe9331 155 boolean match(component other_value, boolean legacy = FALSE) const;
156 boolean match(const COMPONENT& other_value, boolean legacy = FALSE) const;
970ed795
EL
157 component valueof() const;
158
159 void set_type(template_sel template_type, unsigned int list_length);
160 COMPONENT_template& list_item(unsigned int list_index);
161
162 void log() const;
3abe9331 163 void log_match(const COMPONENT& match_value, boolean legacy = FALSE) const;
970ed795
EL
164
165 void set_param(Module_Param& param);
3abe9331 166 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
167
168 void encode_text(Text_Buf& text_buf) const;
169 void decode_text(Text_Buf& text_buf);
170
3abe9331 171 boolean is_present(boolean legacy = FALSE) const;
172 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
173#ifdef TITAN_RUNTIME_2
174 void valueofv(Base_Type* value) const { *(static_cast<COMPONENT*>(value)) = valueof(); }
175 void set_value(template_sel other_value) { *this = other_value; }
176 void copy_value(const Base_Type* other_value) { *this = *(static_cast<const COMPONENT*>(other_value)); }
177 Base_Template* clone() const { return new COMPONENT_template(*this); }
178 const TTCN_Typedescriptor_t* get_descriptor() const { return &COMPONENT_descr_; }
3abe9331 179 boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const COMPONENT*>(other_value)), legacy); }
180 void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const COMPONENT*>(match_value)), legacy); }
970ed795 181#else
3abe9331 182 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
183#endif
184
185 inline boolean is_component() { return TRUE; }
186};
187
188extern const COMPONENT_template& any_compref;
189
190#endif
This page took 0.031056 seconds and 5 git commands to generate.