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