Add to retry to read DUID.
[platform/framework/native/appfw.git] / inc / FBaseDouble.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        FBaseDouble.h
19  * @brief       This is the header file for the %Double class.
20  *
21  * @see         Tizen::Base::Number
22  *
23  * This header file contains the declarations of the %Double class.
24  */
25 #ifndef _FBASE_DOUBLE_H_
26 #define _FBASE_DOUBLE_H_
27
28 #include <FBaseNumber.h>
29
30 namespace Tizen { namespace Base
31 {
32 /**
33  *      @class  Double
34  *      @brief  This class is the wrapper class for the @c signed @c double built-in type.
35  *
36  *      @since 2.0
37  *
38  *  The %Double class is the wrapper class for the @c signed @c double built-in type.
39  *
40  *      It represents a double-precision 64-bit number with values ranging from negative
41  *      1.79769313486232e308 to positive 1.79769313486232e308. This class is useful when passing a @c double
42  *      value to a method expecting an instance of Object, such as Tizen::Base::Collection::Queue or
43  *      Tizen::Base::Collection::Stack. Furthermore, this class provides methods for converting
44  *      %Double (and @c double) to String, and String to %Double (and @c double).
45  *
46  *  The following example demonstrates how to use the %Double class.
47  *
48  *      @code
49  *
50  *      #include <FBase.h>
51  *
52  *      using namespace Tizen::Base;
53  *
54  *      // This method checks whether the given string object contains a string
55  *      // representation of the pre-defined minimum double value.
56  *      result
57  *      MyClass::Verify(const String& string, bool& out)
58  *      {
59  *              static const Double MINIMUM(1.23L);
60  *
61  *              result r = E_SUCCESS;
62  *
63  *              double d;
64  *              r = Double::Parse(string, d);
65  *              if (IsFailed(r))
66  *              {
67  *                      goto CATCH;
68  *              }
69  *
70  *              out = (MINIMUM.CompareTo(d) == 0) ? true: false;
71  *
72  *              return r;
73  *      CATCH:
74  *              return r;
75  *      }
76  *      @endcode
77  */
78 class _OSP_EXPORT_ Double
79         : public Number
80 {
81 public:
82         /**
83          * Initializes this instance of %Double with the specified value.
84          *
85          * @since 2.0
86          *
87          * @param[in]   value   A @c double value
88          */
89         Double(double value = 0.0L);
90
91         /**
92          * Copying of objects using this copy constructor is allowed.
93          *
94          * @since 2.0
95          *
96          * @param[in]   value   An instance of %Double
97          */
98         Double(const Double& value);
99
100         /**
101          * This destructor overrides Tizen::Base::Object::~Object().
102          *
103          * @since 2.0
104          */
105         virtual ~Double(void);
106
107         /**
108          * Copying of objects using this copy assignment operator is allowed.
109          *
110          * @since 2.0
111          *
112          * @param[in]   rhs     An instance of %Double
113          */
114         Double& operator =(const Double& rhs);
115
116         /**
117          * Compares two @c double values.
118          *
119          * @since 2.0
120          *
121          * @return              A 32-bit @c signed integer value
122          * @code
123          * <  0  if the value of @c d1 is less than the value of @c d2
124          * == 0  if the value of @c d1 is equal to the value of @c d2
125          * >  0  if the value of @c d1 is greater than the value of @c d2
126          * @endcode
127          * @param[in]   d1      The first @c double value to compare
128          * @param[in]   d2      The second @c double value to compare
129          */
130         static int Compare(double d1, double d2);
131
132         /**
133          * Compares the value of the current instance of %Double with the value of the specified @c signed @c double.
134          *
135          * @since 2.0
136          *
137          * @return              A 32-bit @c signed integer value
138          * @code
139          * <  0  if the value of the current instance is less than the specified @c signed @c double
140          * == 0  if the value of the current instance is equal to the specified @c signed @c double
141          * >  0  if the value of the current instance is greater than the specified @c signed @c double
142          * @endcode
143          * @param[in]   value   A @c signed @c double value
144          */
145         int CompareTo(double value) const;
146
147         /**
148          * Compares the value of the current instance of %Double with the value of the specified instance of %Double.
149          *
150          * @since 2.0
151          *
152          * @return              A 32-bit @c signed integer value
153          * @code
154          * <  0  if the value of the current instance is less than the value of the specified instance
155          * == 0  if the value of the current instance is equal to the value of the specified instance
156          * >  0  if the value of the current instance is greater than the value of the specified instance
157          * @endcode
158          * @param[in]   value   An instance of %Double
159          */
160         int CompareTo(const Double& value) const;
161
162         /**
163          * Checks whether the value of the specified instance of Object is equal to the value of the current instance of %Double.
164          *
165          * @since 2.0
166          *
167          * @return              @c true if the value of the specified instance of %Object is equal to the value of the current instance of %Double, @n
168          *                              else @c false
169          * @param[in]   obj An instance of Object to compare
170          * @see                 Tizen::Base::Object::Equals
171          */
172         virtual bool Equals(const Object& obj) const;
173
174         /**
175          *      Gets the hash value of the current instance of %Double.
176          *
177          *      @since 2.0
178          *
179          *      @return         An integer value indicating the hash value of the current instance of %Double
180          *      @remarks    Two equal instances must return the same hash value. For better performance,
181          *                              the used hash function must generate a random distribution for all inputs. @n
182          *                              The default implementation of this method returns the value of the current instance.
183          */
184         virtual int GetHashCode(void) const;
185
186         /**
187         *        Gets the hash value of the specified @c double value.
188         *
189         *        @since 2.0
190         *
191         *        @return                An integer value indicating the hash value of the specified @c double value
192         *        @param[in]             val   A @c double value to get the hash value
193         */
194         static int GetHashCode(double val);
195
196         /**
197          * Parses the specified string representing a numeric value and returns the value as @c signed @c double (as out parameter).
198          *
199          * @since 2.0
200          *
201          * @return              An error code
202          * @param[in]   s                               A unicode representation of @c signed @c double value
203          * @param[out]  ret             The converted numeric value
204          * @exception   E_SUCCESS               The method is successful.
205          * @exception   E_NUM_FORMAT    The specified string does not contain a number that can be parsed.
206          * @remarks
207          *                              - This method guarantees that the original value of out-parameter is not changed when the method returns error.
208          *                              - The behavior of this method is dependent on the system default locale setting.
209          */
210         static result Parse(const String& s, double& ret);
211
212         /**
213          * Gets the @c signed @c char equivalent of the current instance of %Double.
214          *
215          * @since 2.0
216          *
217          * @return              A @c signed @c char equivalent of the current instance
218          */
219         virtual char ToChar(void) const;
220
221         /**
222          * Gets the @c signed @c short equivalent of the current instance of %Double.
223          *
224          * @since 2.0
225          *
226          * @return              A @c signed @c short equivalent of the current instance
227          */
228         virtual short ToShort(void) const;
229
230         /**
231          * Gets the @c signed @c int equivalent of the current instance of %Double.
232          *
233          * @since 2.0
234          *
235          * @return              A @c signed @c int equivalent of the current instance
236          */
237         virtual int ToInt(void) const;
238
239         /**
240          * Gets the @c signed @c long equivalent of the current instance of %Double.
241          *
242          * @since 2.0
243          *
244          * @return              A @c signed @c long equivalent of the current instance
245          */
246         virtual long ToLong(void) const;
247
248         /**
249          * Gets the @c signed @c long @c long equivalent of the current instance of %Double.
250          *
251          * @since 2.0
252          *
253          * @return              A @c signed @c long @c long equivalent of the current instance
254          */
255         virtual long long ToLongLong(void) const;
256
257         /**
258          * Gets the @c signed @c float equivalent of the current instance of %Double.
259          *
260          * @since 2.0
261          *
262          * @return              A @c signed @c float equivalent of the current instance
263          */
264         virtual float ToFloat(void) const;
265
266         /**
267          * Gets the @c signed @c double equivalent of the current instance of %Double.
268          *
269          * @since 2.0
270          *
271          * @return              A @c signed @c double equivalent of the current instance
272          */
273         virtual double ToDouble(void) const;
274
275         /**
276          * Gets the string representing the value of the current instance of %Double.
277          *
278          * @since 2.0
279          *
280          * @return              A string containing a Unicode representation of the value of the current instance
281          * @remarks
282          *                              - If the value of the current instance is Not-a-Number (NaN), the result is the string "NaN". Furthermore, infinity
283          *                              produces the result "Infinity". @n
284          *                              6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
285          *                              - The behavior of this method is dependent on the system default locale setting.
286          */
287         virtual String ToString(void) const;
288
289         /**
290          * Gets the string representing the specified @c double value.
291          *
292          * @since 2.0
293          *
294          * @return              A string containing a Unicode representation of the specified @c double value
295          * @param[in]   value A @c double value to convert
296          * @remarks
297          *                              - If the input value is Not-a-Number (NaN), the result is the string "NaN". Furthermore, infinity
298          *                              produces the result "Infinity". @n
299          *                              6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
300          *                              - The behavior of this method is dependent on the system default locale setting.
301          */
302         static String ToString(double value);
303
304         /**
305          * Gets the IEEE 754 floating-point "double format" bit layout representation of the specified @c double value.
306          *
307          * @since 2.0
308          *
309          * @return              The bits that represent the floating-point number in the IEEE 754 floating-point "double format" bit layout
310          * @param[in]   value   A @c double value to convert
311          */
312         static long long ToBits(double value);
313
314         /**
315          * Gets the @c double value equivalent of the specified floating-point value represented in the IEEE 754 floating-point "double format" bit layout.
316          *
317          * @since 2.0
318          *
319          * @return              The @c double floating-point value with the same bit pattern
320          * @param[in]   value   The floating-point value to convert
321          */
322         static double ToDoubleFromBits(long long value);
323
324         /**
325          * Checks whether the current value of %Double is equal to negative or positive infinity.
326          *
327          * @since 2.0
328          *
329          * @return              @c true if the current value equals negative or positive infinity, @n
330          *                              else @c false
331          */
332         bool IsInfinity(void) const;
333
334         /**
335          * Checks whether the specified @c double value is equal to negative or positive infinity.
336          *
337          * @since 2.0
338          *
339          * @return              @c true if the specified value equals negative or positive infinity, @n
340          *                              else @c false
341          * @param[in]   value   A @c double value to check
342          */
343         static bool IsInfinity(double value);
344
345         /**
346          * Checks whether the current value is Not-a-Number.
347          *
348          * @since 2.0
349          *
350          * @return              @c true if the current value is Not-a-Number, @n
351          *                              else @c false
352          */
353         bool IsNaN(void) const;
354
355         /**
356          * Checks whether the specified value is Not-a-Number.
357          *
358          * @since 2.0
359          *
360          * @return              @c true if the specified value is Not-a-Number, @n
361          *                              else @c false
362          * @param[in]   value   A @c double value to check
363          */
364         static bool IsNaN(double value);
365
366         /**
367          * Gets a constant holding the largest positive finite value of type @c double. @n
368          * This is equal to the value defined in Limit.h of the C library.
369          *
370          * @since 2.0
371          *
372          * @return              A constant holding the largest positive finite value of type @c double
373          */
374         static double GetMaxValue(void);
375
376         /**
377          * Gets a constant holding the smallest positive non-zero value of type @c double. @n
378          * This is equal to the value defined in Limit.h of the C library.
379          *
380          * @since 2.0
381          *
382          * @return              A constant holding the smallest possible non-zero value of type @c double
383          */
384         static double GetMinValue(void);
385
386         /**
387          * A @c double value of this instance.
388          *
389          * @since 2.0
390          */
391         double value;
392
393 private:
394         /**
395          *      Checks if the specified @c double value is finite.
396          *
397          *      @since 2.0
398          *
399          *      @return         @c true if the specified value is finite, @n
400          *                              else @c false
401          *      @param[in]      value   A @c double value to check
402          */
403         static bool IsFinite(double d);
404
405         static const int __DBL_MAX_10_EXP = 308;
406
407         friend class _DoubleImpl;
408         class _DoubleImpl* __pDoubleImpl;
409
410 }; // Double
411 }} // Tizen::Base
412 #endif //_FBASE_DOUBLE_H_