1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 ///////////////////////////////////////////////////////////////////////////////
11 #include "Basetype.hh"
12 #include "Template.hh"
13 #include "Optional.hh"
15 #include "ttcn3float.hh"
21 class FLOAT : public Base_Type {
23 friend class FLOAT_template;
26 friend double operator+(double double_value, const FLOAT& other_value);
27 friend double operator-(double double_value, const FLOAT& other_value);
28 friend double operator*(double double_value, const FLOAT& other_value);
29 friend double operator/(double double_value, const FLOAT& other_value);
31 friend boolean operator==(double double_value, const FLOAT& other_value);
32 friend boolean operator< (double double_value, const FLOAT& other_value);
33 friend boolean operator> (double double_value, const FLOAT& other_value);
36 ttcn3float float_value;
38 /** Returns true if the string parameter contains the string representation
39 * of a real number, otherwise returns false. */
40 boolean is_float(const char* p_str);
45 FLOAT(double other_value);
46 FLOAT(const FLOAT& other_value);
49 FLOAT& operator=(double other_value);
50 FLOAT& operator=(const FLOAT& other_value);
52 double operator+() const;
53 double operator-() const;
55 double operator+(double other_value) const;
56 double operator+(const FLOAT& other_value) const;
57 double operator-(double other_value) const;
58 double operator-(const FLOAT& other_value) const;
59 double operator*(double other_value) const;
60 double operator*(const FLOAT& other_value) const;
61 double operator/(double other_value) const;
62 double operator/(const FLOAT& other_value) const;
64 boolean operator==(double other_value) const;
65 boolean operator==(const FLOAT& other_value) const;
66 inline boolean operator!=(double other_value) const
67 { return !(*this == other_value); }
68 inline boolean operator!=(const FLOAT& other_value) const
69 { return !(*this == other_value); }
71 boolean operator<(double other_value) const;
72 boolean operator<(const FLOAT& other_value) const;
73 boolean operator>(double other_value) const;
74 boolean operator>(const FLOAT& other_value) const;
75 inline boolean operator<=(double other_value) const
76 { return !(*this > other_value); }
77 inline boolean operator<=(const FLOAT& other_value) const
78 { return !(*this > other_value); }
79 inline boolean operator>=(double other_value) const
80 { return !(*this < other_value); }
81 inline boolean operator>=(const FLOAT& other_value) const
82 { return !(*this < other_value); }
84 operator double() const;
86 inline boolean is_bound() const { return bound_flag; }
87 inline boolean is_value() const { return bound_flag; }
88 inline void must_bound(const char *err_msg) const
89 { if (!bound_flag) TTCN_error("%s", err_msg); }
91 /** special TTCN-3 float values are not_a_number and +/- infinity */
92 static bool is_special(double flt_val);
93 static void check_numeric(double flt_val, const char *err_msg_begin);
97 #ifdef TITAN_RUNTIME_2
98 boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const FLOAT*>(other_value)); }
99 void set_value(const Base_Type* other_value) { *this = *(static_cast<const FLOAT*>(other_value)); }
100 Base_Type* clone() const { return new FLOAT(*this); }
101 const TTCN_Typedescriptor_t* get_descriptor() const { return &FLOAT_descr_; }
103 inline boolean is_present() const { return is_bound(); }
106 void set_param(Module_Param& param);
107 Module_Param* get_param(Module_Param_Name& param_name) const;
109 void encode_text(Text_Buf& text_buf) const;
110 void decode_text(Text_Buf& text_buf);
112 void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
113 TTCN_EncDec::coding_t p_coding, ...) const;
115 void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
116 TTCN_EncDec::coding_t p_coding, ...);
118 ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td,
119 unsigned p_coding) const;
121 boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td,
122 const ASN_BER_TLV_t& p_tlv, unsigned L_form);
124 /** Encodes the value of the variable according to the
125 * TTCN_Typedescriptor_t. It must be public because called by
126 * another types during encoding. Returns the length of encoded data*/
127 int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const;
129 /** Decodes the value of the variable according to the
130 * TTCN_Typedescriptor_t. It must be public because called by
131 * another types during encoding. Returns the number of decoded bits*/
132 int RAW_decode(const TTCN_Typedescriptor_t&,
133 TTCN_Buffer&, int, raw_order_t, boolean no_err=FALSE,
134 int sel_field=-1, boolean first_call=TRUE);
136 int XER_encode(const XERdescriptor_t& p_td,
137 TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t*) const;
138 int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
139 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*);
141 /** Encodes accordingly to the JSON encoding rules.
142 * Returns the length of the encoded data. */
143 int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const;
145 /** Decodes accordingly to the JSON encoding rules.
146 * Returns the length of the decoded data. */
147 int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean);
150 extern double operator+(double double_value, const FLOAT& other_value);
151 extern double operator-(double double_value, const FLOAT& other_value);
152 extern double operator*(double double_value, const FLOAT& other_value);
153 extern double operator/(double double_value, const FLOAT& other_value);
155 extern boolean operator==(double double_value, const FLOAT& other_value);
156 extern boolean operator<(double double_value, const FLOAT& other_value);
157 extern boolean operator>(double double_value, const FLOAT& other_value);
159 inline boolean operator!=(double double_value, const FLOAT& other_value)
161 return !(double_value == other_value);
164 inline boolean operator<=(double double_value, const FLOAT& other_value)
166 return !(double_value > other_value);
169 inline boolean operator>=(double double_value, const FLOAT& other_value)
171 return !(double_value < other_value);
174 // float template class
176 class FLOAT_template : public Base_Template {
181 unsigned int n_values;
182 FLOAT_template *list_value;
185 double min_value, max_value;
186 boolean min_is_present, max_is_present;
190 void copy_template(const FLOAT_template& other_value);
194 FLOAT_template(template_sel other_value);
195 FLOAT_template(double other_value);
196 FLOAT_template(const FLOAT& other_value);
197 FLOAT_template(const OPTIONAL<FLOAT>& other_value);
198 FLOAT_template(const FLOAT_template& other_value);
203 FLOAT_template& operator=(template_sel other_value);
204 FLOAT_template& operator=(double other_value);
205 FLOAT_template& operator=(const FLOAT& other_value);
206 FLOAT_template& operator=(const OPTIONAL<FLOAT>& other_value);
207 FLOAT_template& operator=(const FLOAT_template& other_value);
209 boolean match(double other_value, boolean legacy = FALSE) const;
210 boolean match(const FLOAT& other_value, boolean legacy = FALSE) const;
212 void set_type(template_sel template_type, unsigned int list_length = 0);
213 FLOAT_template& list_item(unsigned int list_index);
215 void set_min(double min_value);
216 void set_min(const FLOAT& min_value);
217 void set_max(double max_value);
218 void set_max(const FLOAT& max_value);
220 double valueof() const;
223 void log_match(const FLOAT& match_value, boolean legacy = FALSE) const;
225 void set_param(Module_Param& param);
226 Module_Param* get_param(Module_Param_Name& param_name) const;
228 void encode_text(Text_Buf& text_buf) const;
229 void decode_text(Text_Buf& text_buf);
231 boolean is_present(boolean legacy = FALSE) const;
232 boolean match_omit(boolean legacy = FALSE) const;
233 #ifdef TITAN_RUNTIME_2
234 void valueofv(Base_Type* value) const { *(static_cast<FLOAT*>(value)) = valueof(); }
235 void set_value(template_sel other_value) { *this = other_value; }
236 void copy_value(const Base_Type* other_value) { *this = *(static_cast<const FLOAT*>(other_value)); }
237 Base_Template* clone() const { return new FLOAT_template(*this); }
238 const TTCN_Typedescriptor_t* get_descriptor() const { return &FLOAT_descr_; }
239 boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const FLOAT*>(other_value)), legacy); }
240 void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const FLOAT*>(match_value)), legacy); }
242 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
246 extern const FLOAT PLUS_INFINITY, MINUS_INFINITY, NOT_A_NUMBER;