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