Merge "Remove the memory leak on osp-security-service" into tizen_2.2
[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  * This header file contains the declarations of the %Double class.
22  *
23  * @see         Tizen::Base::Number
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   The @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 to copy
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 to copy
113          */
114         Double& operator =(const Double& rhs);
115
116         /**
117          * Compares two @c double values.
118          *
119          * @since 2.0
120          *
121          * @return              The 32-bit @c signed integer value
122          * @code
123          * <  0  if the value of d1 is less than the value of d2
124          * == 0  if the value of d1 is equal to the value of d2
125          * >  0  if the value of d1 is greater than the value of 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              The 32-bit @c signed integer value
138          * @code
139          * <  0  if the value of the current instance is less than the specified signed double
140          * == 0  if the value of the current instance is equal to the specified signed double
141          * >  0  if the value of the current instance is greater than the specified signed 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              The 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         The integer value that indicates the hash value of the current instance of %Double
180          *      @remarks
181          *                              - Two equal instances must return the same hash value. @n
182          *                              For better performance, the used hash function must generate a random distribution for all the inputs.
183          *                              - The default implementation of this method returns the value of the current instance.
184          */
185         virtual int GetHashCode(void) const;
186
187         /**
188          *   Gets the hash value of the specified @c double value.
189          *
190          *   @since 2.0
191          *
192          *   @return            The integer value that indicates the hash value of the specified @c double value
193          *   @param[in]         val   The @c double value to get the hash value
194          */
195         static int GetHashCode(double val);
196
197         /**
198          * Parses the specified string that represents a numeric value and returns the value as @c signed @c double (as out parameter).
199          *
200          * @since 2.0
201          *
202          * @return              An error code
203          * @param[in]   s                               The unicode representation of @c signed @c double value
204          * @param[out]  ret             The converted numeric value
205          * @exception   E_SUCCESS               The method is successful.
206          * @exception   E_NUM_FORMAT    The specified string does not contain a number that can be parsed.
207          * @remarks
208          *                              - This method guarantees that the original value of the out-parameter is not changed when the method returns an error.
209          *                              - The behavior of this method is dependent on the system default locale setting.
210          */
211         static result Parse(const String& s, double& ret);
212
213         /**
214          * Gets the @c signed @c char equivalent of the current instance of %Double.
215          *
216          * @since 2.0
217          *
218          * @return              The @c signed @c char equivalent of the current instance
219          */
220         virtual char ToChar(void) const;
221
222         /**
223          * Gets the @c signed @c short equivalent of the current instance of %Double.
224          *
225          * @since 2.0
226          *
227          * @return              The @c signed @c short equivalent of the current instance
228          */
229         virtual short ToShort(void) const;
230
231         /**
232          * Gets the @c signed @c int equivalent of the current instance of %Double.
233          *
234          * @since 2.0
235          *
236          * @return              The @c signed @c int equivalent of the current instance
237          */
238         virtual int ToInt(void) const;
239
240         /**
241          * Gets the @c signed @c long equivalent of the current instance of %Double.
242          *
243          * @since 2.0
244          *
245          * @return              The @c signed @c long equivalent of the current instance
246          */
247         virtual long ToLong(void) const;
248
249         /**
250          * Gets the @c signed @c long @c long equivalent of the current instance of %Double.
251          *
252          * @since 2.0
253          *
254          * @return              The @c signed @c long @c long equivalent of the current instance
255          */
256         virtual long long ToLongLong(void) const;
257
258         /**
259          * Gets the @c signed @c float equivalent of the current instance of %Double.
260          *
261          * @since 2.0
262          *
263          * @return              The @c signed @c float equivalent of the current instance
264          */
265         virtual float ToFloat(void) const;
266
267         /**
268          * Gets the @c signed @c double equivalent of the current instance of %Double.
269          *
270          * @since 2.0
271          *
272          * @return              The @c signed @c double equivalent of the current instance
273          */
274         virtual double ToDouble(void) const;
275
276         /**
277          * Gets the string that represents the value of the current instance of %Double.
278          *
279          * @since 2.0
280          *
281          * @return              The string that contains the Unicode representation of the value of the current instance
282          * @remarks
283          *                              - If the value of the current instance is Not-a-Number (NaN), the result is the string "NaN". Furthermore, infinity
284          *                              produces the result "Infinity". @n
285          *                              6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
286          *                              - The behavior of this method is dependent on the system default locale setting.
287          */
288         virtual String ToString(void) const;
289
290         /**
291          * Gets the string that represents the specified @c double value.
292          *
293          * @since 2.0
294          *
295          * @return              The string that contains the Unicode representation of the specified @c double value
296          * @param[in]   value   The @c double value to convert
297          * @remarks
298          *                              - If the input value is Not-a-Number (NaN), the result is the string "NaN". Furthermore, infinity
299          *                              produces the result "Infinity". @n
300          *                              6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
301          *                              - The behavior of this method is dependent on the system default locale setting.
302          */
303         static String ToString(double value);
304
305         /**
306          * Gets the IEEE 754 floating-point "double format" bit layout representation of the specified @c double value.
307          *
308          * @since 2.0
309          *
310          * @return              The bits that represent the floating-point number in the IEEE 754 floating-point "double format" bit layout
311          * @param[in]   value   The @c double value to convert
312          */
313         static long long ToBits(double value);
314
315         /**
316          * Gets the @c double value equivalent of the specified floating-point value represented in the IEEE 754 floating-point "double format" bit layout.
317          *
318          * @since 2.0
319          *
320          * @return              The @c double floating-point value with the same bit pattern
321          * @param[in]   value   The floating-point value to convert
322          */
323         static double ToDoubleFromBits(long long value);
324
325         /**
326          * Checks whether the current value of %Double is equal to the negative or positive infinity.
327          *
328          * @since 2.0
329          *
330          * @return              @c true if the current value equals the negative or positive infinity, @n
331          *                              else @c false
332          */
333         bool IsInfinity(void) const;
334
335         /**
336          * Checks whether the specified @c double value is equal to the negative or positive infinity.
337          *
338          * @since 2.0
339          *
340          * @return              @c true if the specified value equals the negative or positive infinity, @n
341          *                              else @c false
342          * @param[in]   value   The @c double value to check
343          */
344         static bool IsInfinity(double value);
345
346         /**
347          * Checks whether the current value is Not-a-Number.
348          *
349          * @since 2.0
350          *
351          * @return              @c true if the current value is Not-a-Number, @n
352          *                              else @c false
353          */
354         bool IsNaN(void) const;
355
356         /**
357          * Checks whether the specified value is Not-a-Number.
358          *
359          * @since 2.0
360          *
361          * @return              @c true if the specified value is Not-a-Number, @n
362          *                              else @c false
363          * @param[in]   value   The @c double value to check
364          */
365         static bool IsNaN(double value);
366
367         /**
368          * Gets the constant holding the largest positive finite value of type @c double. @n
369          * This is equal to the value defined in Limit.h of the C library.
370          *
371          * @since 2.0
372          *
373          * @return              The constant holding the largest positive finite value of type @c double
374          */
375         static double GetMaxValue(void);
376
377         /**
378          * Gets the constant holding the smallest positive non-zero value of type @c double. @n
379          * This is equal to the value defined in Limit.h of the C library.
380          *
381          * @since 2.0
382          *
383          * @return              The constant holding the smallest possible non-zero value of type @c double
384          */
385         static double GetMinValue(void);
386
387         /**
388          * The @c double value of this instance.
389          *
390          * @since 2.0
391          */
392         double value;
393
394 private:
395         /**
396          *      Checks if the specified @c double value is finite.
397          *
398          *      @since 2.0
399          *
400          *      @return         @c true if the specified value is finite, @n
401          *                              else @c false
402          *      @param[in]      value   A @c double value to check
403          */
404         static bool IsFinite(double d);
405
406         static const int __DBL_MAX_10_EXP = 308;
407
408         friend class _DoubleImpl;
409         class _DoubleImpl* __pDoubleImpl;
410
411 }; // Double
412 }} // Tizen::Base
413 #endif //_FBASE_DOUBLE_H_