Sync with 5.4.3
[deliverable/titan.core.git] / core / Float.hh
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 ///////////////////////////////////////////////////////////////////////////////
8 #ifndef FLOAT_HH
9 #define FLOAT_HH
10
11 #include "Basetype.hh"
12 #include "Template.hh"
13 #include "Optional.hh"
14 #include "Error.hh"
15 #include "ttcn3float.hh"
16
17 class Module_Param;
18
19 // float value class
20
21 class FLOAT : public Base_Type {
22
23 friend class FLOAT_template;
24 friend class TIMER;
25
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);
30
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);
34
35 boolean bound_flag;
36 ttcn3float float_value;
37
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);
41
42 public:
43
44 FLOAT();
45 FLOAT(double other_value);
46 FLOAT(const FLOAT& other_value);
47 void clean_up();
48
49 FLOAT& operator=(double other_value);
50 FLOAT& operator=(const FLOAT& other_value);
51
52 double operator+() const;
53 double operator-() const;
54
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;
63
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); }
70
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); }
83
84 operator double() const;
85
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); }
90
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);
94
95 void log() const;
96
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_; }
102 #else
103 inline boolean is_present() const { return is_bound(); }
104 #endif
105
106 void set_param(Module_Param& param);
107 Module_Param* get_param(Module_Param_Name& param_name) const;
108
109 void encode_text(Text_Buf& text_buf) const;
110 void decode_text(Text_Buf& text_buf);
111
112 void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
113 TTCN_EncDec::coding_t p_coding, ...) const;
114
115 void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
116 TTCN_EncDec::coding_t p_coding, ...);
117
118 ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td,
119 unsigned p_coding) const;
120
121 boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td,
122 const ASN_BER_TLV_t& p_tlv, unsigned L_form);
123
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;
128
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);
135
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*);
140
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;
144
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);
148 };
149
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);
154
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);
158
159 inline boolean operator!=(double double_value, const FLOAT& other_value)
160 {
161 return !(double_value == other_value);
162 }
163
164 inline boolean operator<=(double double_value, const FLOAT& other_value)
165 {
166 return !(double_value > other_value);
167 }
168
169 inline boolean operator>=(double double_value, const FLOAT& other_value)
170 {
171 return !(double_value < other_value);
172 }
173
174 // float template class
175
176 class FLOAT_template : public Base_Template {
177 private:
178 union {
179 double single_value;
180 struct {
181 unsigned int n_values;
182 FLOAT_template *list_value;
183 } value_list;
184 struct {
185 double min_value, max_value;
186 boolean min_is_present, max_is_present;
187 } value_range;
188 };
189
190 void copy_template(const FLOAT_template& other_value);
191
192 public:
193 FLOAT_template();
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);
199
200 ~FLOAT_template();
201 void clean_up();
202
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);
208
209 boolean match(double other_value, boolean legacy = FALSE) const;
210 boolean match(const FLOAT& other_value, boolean legacy = FALSE) const;
211
212 void set_type(template_sel template_type, unsigned int list_length = 0);
213 FLOAT_template& list_item(unsigned int list_index);
214
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);
219
220 double valueof() const;
221
222 void log() const;
223 void log_match(const FLOAT& match_value, boolean legacy = FALSE) const;
224
225 void set_param(Module_Param& param);
226 Module_Param* get_param(Module_Param_Name& param_name) const;
227
228 void encode_text(Text_Buf& text_buf) const;
229 void decode_text(Text_Buf& text_buf);
230
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); }
241 #else
242 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
243 #endif
244 };
245
246 extern const FLOAT PLUS_INFINITY, MINUS_INFINITY, NOT_A_NUMBER;
247
248 #endif
This page took 0.037488 seconds and 5 git commands to generate.