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
17 * Szabo, Janos Zoltan – initial implementation
21 ******************************************************************************/
26 #include "Basetype.hh"
27 #include "Template.hh"
28 #include "Optional.hh"
33 class BOOLEAN : public Base_Type {
34 friend class BOOLEAN_template;
36 friend boolean operator&&(boolean bool_value, const BOOLEAN& other_value);
37 friend boolean operator^(boolean bool_value, const BOOLEAN& other_value);
38 friend boolean operator||(boolean bool_value, const BOOLEAN& other_value);
39 friend boolean operator==(boolean bool_value, const BOOLEAN& other_value);
42 boolean boolean_value;
46 BOOLEAN(boolean other_value);
47 BOOLEAN(const BOOLEAN& other_value);
49 BOOLEAN& operator=(boolean other_value);
50 BOOLEAN& operator=(const BOOLEAN& other_value);
52 boolean operator!() const;
53 boolean operator&&(boolean other_value) const;
54 boolean operator&&(const BOOLEAN& other_value) const;
55 boolean operator^(boolean other_value) const;
56 boolean operator^(const BOOLEAN& other_value) const;
57 boolean operator||(const BOOLEAN& other_value) const;
58 boolean operator||(boolean other_value) const;
60 boolean operator==(boolean other_value) const;
61 boolean operator==(const BOOLEAN& other_value) const;
63 inline boolean operator!=(boolean other_value) const
64 { return !(*this == other_value); }
65 inline boolean operator!=(const BOOLEAN& other_value) const
66 { return !(*this == other_value); }
68 operator boolean() const;
70 inline boolean is_bound() const { return bound_flag; }
71 inline boolean is_value() const { return bound_flag; }
73 inline void must_bound(const char *err_msg) const
74 { if (!bound_flag) TTCN_error("%s", err_msg); }
76 #ifdef TITAN_RUNTIME_2
77 boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const BOOLEAN*>(other_value)); }
78 void set_value(const Base_Type* other_value) { *this = *(static_cast<const BOOLEAN*>(other_value)); }
79 Base_Type* clone() const { return new BOOLEAN(*this); }
80 const TTCN_Typedescriptor_t* get_descriptor() const { return &BOOLEAN_descr_; }
82 inline boolean is_present() const { return is_bound(); }
87 void set_param(Module_Param& param);
88 Module_Param* get_param(Module_Param_Name& param_name) const;
90 void encode_text(Text_Buf& text_buf) const;
91 void decode_text(Text_Buf& text_buf);
93 void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
94 TTCN_EncDec::coding_t p_coding, ...) const;
96 void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
97 TTCN_EncDec::coding_t p_coding, ...);
99 ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td,
100 unsigned p_coding) const;
102 boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td,
103 const ASN_BER_TLV_t& p_tlv, unsigned L_form);
105 /** Encodes the value of the variable according to the
106 * TTCN_Typedescriptor_t. It must be public because called by
107 * another types during encoding. Returns the length of encoded data*/
108 int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const;
110 /** Decodes the value of the variable according to the
111 * TTCN_Typedescriptor_t. It must be public because called by
112 * another types during encoding. Returns the number of decoded bits*/
113 int RAW_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, int, raw_order_t,
114 boolean no_err=FALSE, int sel_field=-1, boolean first_call=TRUE);
115 int TEXT_encode(const TTCN_Typedescriptor_t&,
117 int TEXT_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, Limit_Token_List&,
118 boolean no_err=FALSE, boolean first_call=TRUE);
119 int XER_encode(const XERdescriptor_t& p_td,
120 TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t*) const;
121 int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
122 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*);
124 /** Encodes accordingly to the JSON encoding rules.
125 * Returns the length of the encoded data. */
126 int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const;
128 /** Decodes accordingly to the JSON encoding rules.
129 * Returns the length of the decoded data. */
130 int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean);
133 extern boolean operator&&(boolean bool_value, const BOOLEAN& other_value);
134 extern boolean operator^(boolean bool_value, const BOOLEAN& other_value);
135 extern boolean operator||(boolean bool_value, const BOOLEAN& other_value);
137 extern boolean operator==(boolean bool_value, const BOOLEAN& other_value);
138 inline boolean operator!=(boolean bool_value, const BOOLEAN& other_value)
139 { return !(bool_value == other_value); }
142 // boolean template class
145 class BOOLEAN_template : public Base_Template {
147 boolean single_value;
149 unsigned int n_values;
150 BOOLEAN_template *list_value;
154 void copy_template(const BOOLEAN_template& other_value);
159 BOOLEAN_template(template_sel other_value);
160 BOOLEAN_template(boolean other_value);
161 BOOLEAN_template(const BOOLEAN& other_value);
162 BOOLEAN_template(const OPTIONAL<BOOLEAN>& other_value);
163 BOOLEAN_template(const BOOLEAN_template& other_value);
168 BOOLEAN_template& operator=(template_sel other_value);
169 BOOLEAN_template& operator=(boolean other_value);
170 BOOLEAN_template& operator=(const BOOLEAN& other_value);
171 BOOLEAN_template& operator=(const OPTIONAL<BOOLEAN>& other_value);
172 BOOLEAN_template& operator=(const BOOLEAN_template& other_value);
174 boolean match(boolean other_value, boolean legacy = FALSE) const;
175 boolean match(const BOOLEAN& other_value, boolean legacy = FALSE) const;
176 boolean valueof() const;
178 void set_type(template_sel template_type, unsigned int list_length);
179 BOOLEAN_template& list_item(unsigned int list_index);
182 void log_match(const BOOLEAN& match_value, boolean legacy = FALSE) const;
184 void set_param(Module_Param& param);
185 Module_Param* get_param(Module_Param_Name& param_name) const;
187 void encode_text(Text_Buf& text_buf) const;
188 void decode_text(Text_Buf& text_buf);
190 boolean is_present(boolean legacy = FALSE) const;
191 boolean match_omit(boolean legacy = FALSE) const;
192 #ifdef TITAN_RUNTIME_2
193 void valueofv(Base_Type* value) const { *(static_cast<BOOLEAN*>(value)) = valueof(); }
194 void set_value(template_sel other_value) { *this = other_value; }
195 void copy_value(const Base_Type* other_value) { *this = *(static_cast<const BOOLEAN*>(other_value)); }
196 Base_Template* clone() const { return new BOOLEAN_template(*this); }
197 const TTCN_Typedescriptor_t* get_descriptor() const { return &BOOLEAN_descr_; }
198 boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const BOOLEAN*>(other_value)), legacy); }
199 void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const BOOLEAN*>(match_value)), legacy); }
201 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;