Move system-server under server/system.
[platform/framework/native/appfw.git] / inc / FBaseInt8.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                FBaseInt8.h
19  * @brief               This is the header file for the %Int8 class.
20  *
21  * @see                 Tizen::Base::Number
22  *
23  * This header file contains the declarations of the %Int8 class.
24  */
25 #ifndef _FBASE_INT8_H_
26 #define _FBASE_INT8_H_
27
28 #include <FBaseNumber.h>
29
30 namespace Tizen { namespace Base
31 {
32 /**
33  * @class       Int8
34  * @brief       This class is the wrapper class for the @c signed @c char built-in type.
35  *
36  * @since 2.0
37  *
38  * The %Int8 class represents an integer value ranging from -128 to 127. The class is useful when passing an 8-bit
39  * signed integral value to a method that accepts only an instance of Object. Furthermore, this class provides
40  * methods for converting %Int8 (and @c char) to String, and %String to %Int8 (and @c char).
41  *
42  * The following example demonstrates how to use the %Int8 class.
43  * @code
44  *
45  *      #include <FBase.h>
46  *
47  *      using namespace Tizen::Base;
48  *
49  *      // This method checks whether the given string object contains a string
50  *      // representation of the pre-defined minimum 8-bit integral value.
51  *      result
52  *      MyClass::Verify(String& string, bool& out)
53  *      {
54  *              static const Int8 MINIMUM(123);
55  *
56  *              result r = E_SUCCESS;
57  *
58  *              char ch;
59  *              r = Int8::Parse(string, ch);
60  *              if (IsFailed(r))
61  *              {
62  *                      goto CATCH;
63  *              }
64  *
65  *              out = (MINIMUM.CompareTo(ch) == 0) ? true: false;
66  *
67  *              return r;
68  *      CATCH:
69  *              return r;
70  *      }
71  * @endcode
72  */
73 class _OSP_EXPORT_ Int8
74         : public Number
75 {
76 public:
77         /**
78          * Initializes this instance of %Int8 with the specified value.
79          *
80          * @since 2.0
81          *
82          * @param[in]   value   A @c char value
83          */
84         Int8(char value = 0);
85
86         /**
87          * Copying of objects using this copy constructor is allowed.
88          *
89          * @since 2.0
90          *
91          * @param[in]   value   An instance of %Int8
92          */
93         Int8(const Int8& value);
94
95         /**
96          * This destructor overrides Tizen::Base::Object::~Object().
97          *
98          * @since 2.0
99          */
100         virtual ~Int8(void);
101
102         /**
103          * Copying of objects using this copy assignment operator is allowed.
104          *
105          * @since 2.0
106          *
107          * @param[in]   rhs     An instance of %Int8
108          */
109         Int8& operator =(const Int8& rhs);
110
111         /**
112          * Compares two @c char values.
113          *
114          * @since 2.0
115          *
116          * @return              A 32-bit @c signed integer value
117          * @code
118          * <  0  if the value of ch1 is less than the value of ch2
119          * == 0  if the value of ch1 is equal to the value of ch2
120          * >  0  if the value of ch1 is greater than the value of ch2
121          * @endcode
122          * @param[in]   ch1     The first @c char value to compare
123          * @param[in]   ch2     The second @c char value to compare
124          */
125         static int Compare(char ch1, char ch2);
126
127         /**
128          * Compares the value of the current instance with the value of the specified instance of the %Int8 class.
129          *
130          * @since 2.0
131          *
132          * @return              A 32-bit @c signed integer value
133          * @code
134          * <  0  if the value of the current instance is less than the value of the specified instance
135          * == 0  if the value of the current instance is equal to the value of the specified instance
136          * >  0  if the value of the current instance is greater than the value of the specified instance
137          * @endcode
138          * @param[in]   value   An instance of the %Int8 class to compare
139          */
140         int CompareTo(const Int8& value) const;
141
142         /**
143          * Checks whether the value of the specified instance of %Int8 is equal to the value of the current instance.
144          *
145          * @since 2.0
146          *
147          * @return              @c true if the value of the specified instance is equal to the value of the current instance, @n
148          *                              else @c false
149          * @param[in]   obj An instance of Object to compare
150          * @see                 Tizen::Base::Object::Equals()
151          */
152         virtual bool Equals(const Object& obj) const;
153
154         /**
155          *      Gets the hash value of the current instance of %Int8.
156          *
157          *      @since 2.0
158          *
159          *      @return         An integer value indicating the hash value of the current instance of %Int8
160          *      @remarks        Two equal instances must return the same hash value. For better performance,
161          *                              the used hash function must generate a random distribution for all inputs. @n
162          *                              The default implementation of this method returns the value of the current instance.
163          */
164         virtual int GetHashCode(void) const;
165
166         /**
167         *   Gets the hash value of the specified @c char value.
168         *
169         *   @since 2.0
170         *
171         *   @return             An integer value indicating the hash value of the specified @c char value
172         *   @param[in]  val   A @c char value to get the hash value
173         */
174         static int GetHashCode(char val);
175
176         /**
177          * Decodes a string into a @c signed @c char.
178          *
179          * @since 2.0
180          *
181          * @return              An error code
182          * @param[in]   s       A string representing a numeric value
183          * @param[out]  ret     The result of the operation
184          * @exception   E_SUCCESS        The method is successful.
185          * @exception   E_NUM_FORMAT The specified string does not contain a number that can be parsed.
186          * @remarks             This method accepts decimal, hexadecimal, and octal numbers given by the
187          *                              following grammar:
188          * @code
189          *      - DecodableString:
190          *              Sign[opt] DecimalNumeral
191          *              Sign[opt] 0x HexDigits
192          *              Sign[opt] 0X HexDigits
193          *              Sign[opt] # HexDigits
194          *              Sign[opt] 0 OctalDigits
195          *      - Sign:
196          *              '-'
197          * @endcode
198          * @remarks             This method has portability issue. @n
199          *                              When the specified string is nagative number in the ARM architecture, type casting is needed like following code.
200          * @code
201          *      char ret;
202          *      Int8::Decode(L"-0X20", ret);
203          *      SomeOutputFunction(static_cast< signed char >(ret));
204          * @endcode
205          */
206         static result Decode(const String& s, char& ret);
207
208         /**
209          * Parses the @c signed @c char equivalent of the specified string representing a numeric value.
210          *
211          * @since 2.0
212          *
213          * @return              An error code
214          * @param[in]   s       A string representing a numeric value
215          * @param[out]  ret     The result of the operation
216          * @exception   E_SUCCESS        The method is successful.
217          * @exception   E_NUM_FORMAT The specified string does not contain a byte that can be parsed.
218          * @remarks
219          *                              - This method assumes that the string representing the numeric value uses a radix 10.
220          *                              - This method guarantees that the original value of out-parameter is not changed when the method returns error.
221          */
222         static result Parse(const String& s, char& ret);
223
224         /**
225          * Parses the specified string representing a numeric value and
226          * returns the value as @c signed @c char (as out parameter).
227          *
228          * @since 2.0
229          *
230          * @return              The @c signed @c char equivalent of the specified string representing the numeric value using the specified index
231          * @param[in]   s       A string representing a numeric value
232          * @param[in]   radix   The radix of the string representing a numeric value @n
233          *                                              It must either be 2, 8, 10, or 16.
234          * @param[out]  ret             The result of the operation
235          * @exception   E_SUCCESS        The method is successful.
236          * @exception   E_NUM_FORMAT The specified string does not contain a number that can be parsed.
237          * @exception   E_OUT_OF_RANGE The specified @c radix is invalid.
238          * @remarks             This method guarantees that the original value of out-parameter is not changed when the method returns error.
239          */
240         static result Parse(const String& s, int radix, char& ret);
241
242         /**
243          * Gets the @c signed @c char equivalent of the current instance of %Int8.
244          *
245          * @since 2.0
246          *
247          * @return      The @c signed @c char equivalent of the current instance
248          */
249         virtual char ToChar(void) const;
250
251         /**
252          * Gets the @c signed @c short equivalent of the current instance of %Int8.
253          *
254          * @since 2.0
255          *
256          * @return      The @c signed @c short equivalent of the current instance
257          */
258         virtual short ToShort(void) const;
259
260         /**
261          * Gets the @c signed @c int equivalent of the current instance of %Int8.
262          *
263          * @since 2.0
264          *
265          * @return      The @c signed @c int equivalent of the current instance
266          */
267         virtual int ToInt(void) const;
268
269         /**
270          * Gets the @c signed @c long equivalent of the current instance of %Int8.
271          *
272          * @since 2.0
273          *
274          * @return      The @c signed @c long equivalent of the current instance
275          */
276         virtual long ToLong(void) const;
277
278         /**
279         * Gets the @c signed @c long @c long equivalent of the current instance of %Int8.
280         *
281         * @since 2.0
282         *
283         * @return       The @c signed @c long @c long equivalent of the current instance
284         */
285         virtual long long ToLongLong(void) const;
286
287         /**
288          * Gets the @c signed @c float equivalent of the current instance of %Int8.
289          *
290          * @since 2.0
291          *
292          * @return      The @c signed @c float equivalent of the current instance
293          */
294         virtual float ToFloat(void) const;
295
296         /**
297          * Gets the @c signed @c double equivalent of the current instance of %Int8.
298          *
299          * @since 2.0
300          *
301          * @return      The @c signed @c double equivalent of the current instance
302          */
303         virtual double ToDouble(void) const;
304
305         /**
306          * Gets the string representing the value of the current instance of %Int8.
307          *
308          * @since 2.0
309          *
310          * @return              A string representing the value of the current instance
311          */
312         virtual String ToString(void) const;
313
314         /**
315          * Gets the string representing the specified @c signed @c char value using radix @c 10.
316          *
317          * @since 2.0
318          *
319          * @return              A string containing a Unicode representation of the specified @c char value using radix 10
320          * @param[in]   value   A @c char value
321          */
322         static String ToString(char value);
323
324         /**
325          * A constant holding the maximum value of type @c char. @n
326          * A @c short character can hold a value of upto 2^7-1.
327          *
328          * @since 2.0
329          */
330         static const char VALUE_MAX = (signed char) 0x7F;
331
332         /**
333          * A constant holding the minimum value of type @c char. @n
334          * A @c short character can hold a value of upto -2^7.
335          *
336          * @since 2.0
337          */
338         static const char VALUE_MIN = (signed char) 0x80;
339
340         /**
341          * A @c signed @c char value of this instance.
342          *
343          * @since 2.0
344          */
345         signed char value;
346
347
348 private:
349         friend class _Int8Impl;
350         class _Int8Impl* __pInt8Impl;
351
352 }; // Int8
353
354 }} // Tizen::Base
355
356 #endif //_FBASE_INT8_H_