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 ///////////////////////////////////////////////////////////////////////////////
12 #include "Basetype.hh"
13 #include "Template.hh"
14 #include "Optional.hh"
18 // value class for all component types
20 class COMPONENT : public Base_Type {
21 friend class COMPONENT_template;
22 friend boolean operator==(component component_value,
23 const COMPONENT& other_value);
25 static unsigned int n_component_names;
26 struct component_name_struct;
27 static component_name_struct *component_names;
29 component component_value;
33 COMPONENT(component other_value);
34 COMPONENT(const COMPONENT& other_value);
36 COMPONENT& operator=(component other_value);
37 COMPONENT& operator=(const COMPONENT& other_value);
39 boolean operator==(component other_value) const;
40 boolean operator==(const COMPONENT& other_value) const;
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); }
47 operator component() const;
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;
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_; }
64 inline boolean is_present() const { return is_bound(); }
67 alt_status done() const;
68 alt_status killed() const;
70 boolean running() const;
71 boolean alive() const;
76 void set_param(Module_Param& param);
78 void encode_text(Text_Buf& text_buf) const;
79 void decode_text(Text_Buf& text_buf);
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
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"
92 * @param component_reference
93 * @return a string which must be Free()'d
95 static char *get_component_string(component component_reference);
97 inline boolean is_component() { return TRUE; }
100 extern boolean operator==(component component_value,
101 const COMPONENT& other_value);
103 inline boolean operator!=(component component_value,
104 const COMPONENT& other_value)
106 return !(component_value == other_value);
109 extern COMPONENT self;
112 // template for all component types
114 class COMPONENT_template : public Base_Template {
117 component single_value;
119 unsigned int n_values;
120 COMPONENT_template *list_value;
124 void copy_template(const COMPONENT_template& other_value);
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);
134 ~COMPONENT_template();
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);
143 boolean match(component other_value) const;
144 boolean match(const COMPONENT& other_value) const;
145 component valueof() const;
147 void set_type(template_sel template_type, unsigned int list_length);
148 COMPONENT_template& list_item(unsigned int list_index);
151 void log_match(const COMPONENT& match_value) const;
153 void set_param(Module_Param& param);
155 void encode_text(Text_Buf& text_buf) const;
156 void decode_text(Text_Buf& text_buf);
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))); }
169 void check_restriction(template_res t_res, const char* t_name=NULL) const;
172 inline boolean is_component() { return TRUE; }
175 extern const COMPONENT_template& any_compref;