Commit | Line | Data |
---|---|---|
970ed795 EL |
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 BOOLEAN_HH | |
9 | #define BOOLEAN_HH | |
10 | ||
11 | #include "Types.h" | |
12 | #include "Basetype.hh" | |
13 | #include "Template.hh" | |
14 | #include "Optional.hh" | |
15 | #include "Error.hh" | |
16 | ||
17 | class Module_Param; | |
18 | ||
19 | class BOOLEAN : public Base_Type { | |
20 | friend class BOOLEAN_template; | |
21 | ||
22 | friend boolean operator&&(boolean bool_value, const BOOLEAN& other_value); | |
23 | friend boolean operator^(boolean bool_value, const BOOLEAN& other_value); | |
24 | friend boolean operator||(boolean bool_value, const BOOLEAN& other_value); | |
25 | friend boolean operator==(boolean bool_value, const BOOLEAN& other_value); | |
26 | ||
27 | boolean bound_flag; | |
28 | boolean boolean_value; | |
29 | ||
30 | public: | |
31 | BOOLEAN(); | |
32 | BOOLEAN(boolean other_value); | |
33 | BOOLEAN(const BOOLEAN& other_value); | |
34 | ||
35 | BOOLEAN& operator=(boolean other_value); | |
36 | BOOLEAN& operator=(const BOOLEAN& other_value); | |
37 | ||
38 | boolean operator!() const; | |
39 | boolean operator&&(boolean other_value) const; | |
40 | boolean operator&&(const BOOLEAN& other_value) const; | |
41 | boolean operator^(boolean other_value) const; | |
42 | boolean operator^(const BOOLEAN& other_value) const; | |
43 | boolean operator||(const BOOLEAN& other_value) const; | |
44 | boolean operator||(boolean other_value) const; | |
45 | ||
46 | boolean operator==(boolean other_value) const; | |
47 | boolean operator==(const BOOLEAN& other_value) const; | |
48 | ||
49 | inline boolean operator!=(boolean other_value) const | |
50 | { return !(*this == other_value); } | |
51 | inline boolean operator!=(const BOOLEAN& other_value) const | |
52 | { return !(*this == other_value); } | |
53 | ||
54 | operator boolean() const; | |
55 | ||
56 | inline boolean is_bound() const { return bound_flag; } | |
57 | inline boolean is_value() const { return bound_flag; } | |
58 | void clean_up(); | |
59 | inline void must_bound(const char *err_msg) const | |
60 | { if (!bound_flag) TTCN_error("%s", err_msg); } | |
61 | ||
62 | #ifdef TITAN_RUNTIME_2 | |
63 | boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const BOOLEAN*>(other_value)); } | |
64 | void set_value(const Base_Type* other_value) { *this = *(static_cast<const BOOLEAN*>(other_value)); } | |
65 | Base_Type* clone() const { return new BOOLEAN(*this); } | |
66 | const TTCN_Typedescriptor_t* get_descriptor() const { return &BOOLEAN_descr_; } | |
67 | #else | |
68 | inline boolean is_present() const { return is_bound(); } | |
69 | #endif | |
70 | ||
71 | void log() const; | |
72 | ||
73 | void set_param(Module_Param& param); | |
74 | ||
75 | void encode_text(Text_Buf& text_buf) const; | |
76 | void decode_text(Text_Buf& text_buf); | |
77 | ||
78 | void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, | |
79 | TTCN_EncDec::coding_t p_coding, ...) const; | |
80 | ||
81 | void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, | |
82 | TTCN_EncDec::coding_t p_coding, ...); | |
83 | ||
84 | ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td, | |
85 | unsigned p_coding) const; | |
86 | ||
87 | boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td, | |
88 | const ASN_BER_TLV_t& p_tlv, unsigned L_form); | |
89 | ||
90 | /** Encodes the value of the variable according to the | |
91 | * TTCN_Typedescriptor_t. It must be public because called by | |
92 | * another types during encoding. Returns the length of encoded data*/ | |
93 | int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const; | |
94 | ||
95 | /** Decodes the value of the variable according to the | |
96 | * TTCN_Typedescriptor_t. It must be public because called by | |
97 | * another types during encoding. Returns the number of decoded bits*/ | |
98 | int RAW_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, int, raw_order_t, | |
99 | boolean no_err=FALSE, int sel_field=-1, boolean first_call=TRUE); | |
100 | int TEXT_encode(const TTCN_Typedescriptor_t&, | |
101 | TTCN_Buffer&) const; | |
102 | int TEXT_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, Limit_Token_List&, | |
103 | boolean no_err=FALSE, boolean first_call=TRUE); | |
104 | int XER_encode(const XERdescriptor_t& p_td, | |
af710487 | 105 | TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t*) const; |
970ed795 | 106 | int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader, |
af710487 | 107 | unsigned int flavor, embed_values_dec_struct_t*); |
970ed795 EL |
108 | |
109 | /** Encodes accordingly to the JSON encoding rules. | |
110 | * Returns the length of the encoded data. */ | |
111 | int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const; | |
112 | ||
113 | /** Decodes accordingly to the JSON encoding rules. | |
114 | * Returns the length of the decoded data. */ | |
115 | int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean); | |
116 | }; | |
117 | ||
118 | extern boolean operator&&(boolean bool_value, const BOOLEAN& other_value); | |
119 | extern boolean operator^(boolean bool_value, const BOOLEAN& other_value); | |
120 | extern boolean operator||(boolean bool_value, const BOOLEAN& other_value); | |
121 | ||
122 | extern boolean operator==(boolean bool_value, const BOOLEAN& other_value); | |
123 | inline boolean operator!=(boolean bool_value, const BOOLEAN& other_value) | |
124 | { return !(bool_value == other_value); } | |
125 | ||
126 | ||
127 | // boolean template class | |
128 | ||
129 | ||
130 | class BOOLEAN_template : public Base_Template { | |
131 | union { | |
132 | boolean single_value; | |
133 | struct { | |
134 | unsigned int n_values; | |
135 | BOOLEAN_template *list_value; | |
136 | } value_list; | |
137 | }; | |
138 | ||
139 | void copy_template(const BOOLEAN_template& other_value); | |
140 | ||
141 | public: | |
142 | ||
143 | BOOLEAN_template(); | |
144 | BOOLEAN_template(template_sel other_value); | |
145 | BOOLEAN_template(boolean other_value); | |
146 | BOOLEAN_template(const BOOLEAN& other_value); | |
147 | BOOLEAN_template(const OPTIONAL<BOOLEAN>& other_value); | |
148 | BOOLEAN_template(const BOOLEAN_template& other_value); | |
149 | ||
150 | ~BOOLEAN_template(); | |
151 | void clean_up(); | |
152 | ||
153 | BOOLEAN_template& operator=(template_sel other_value); | |
154 | BOOLEAN_template& operator=(boolean other_value); | |
155 | BOOLEAN_template& operator=(const BOOLEAN& other_value); | |
156 | BOOLEAN_template& operator=(const OPTIONAL<BOOLEAN>& other_value); | |
157 | BOOLEAN_template& operator=(const BOOLEAN_template& other_value); | |
158 | ||
159 | boolean match(boolean other_value) const; | |
160 | boolean match(const BOOLEAN& other_value) const; | |
161 | boolean valueof() const; | |
162 | ||
163 | void set_type(template_sel template_type, unsigned int list_length); | |
164 | BOOLEAN_template& list_item(unsigned int list_index); | |
165 | ||
166 | void log() const; | |
167 | void log_match(const BOOLEAN& match_value) const; | |
168 | ||
169 | void set_param(Module_Param& param); | |
170 | ||
171 | void encode_text(Text_Buf& text_buf) const; | |
172 | void decode_text(Text_Buf& text_buf); | |
173 | ||
174 | boolean is_present() const; | |
175 | boolean match_omit() const; | |
176 | #ifdef TITAN_RUNTIME_2 | |
177 | void valueofv(Base_Type* value) const { *(static_cast<BOOLEAN*>(value)) = valueof(); } | |
178 | void set_value(template_sel other_value) { *this = other_value; } | |
179 | void copy_value(const Base_Type* other_value) { *this = *(static_cast<const BOOLEAN*>(other_value)); } | |
180 | Base_Template* clone() const { return new BOOLEAN_template(*this); } | |
181 | const TTCN_Typedescriptor_t* get_descriptor() const { return &BOOLEAN_descr_; } | |
182 | boolean matchv(const Base_Type* other_value) const { return match(*(static_cast<const BOOLEAN*>(other_value))); } | |
183 | void log_matchv(const Base_Type* match_value) const { log_match(*(static_cast<const BOOLEAN*>(match_value))); } | |
184 | #else | |
185 | void check_restriction(template_res t_res, const char* t_name=NULL) const; | |
186 | #endif | |
187 | }; | |
188 | ||
189 | #endif |