sync with tizen_2.0
[platform/framework/native/appfw.git] / src / locales / FLclCurrency.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file            FLclCurrency.cpp
20  * @brief           This is the implementation file for Currency class.
21  */
22
23 // Includes
24 #include <FBaseSysLog.h>
25 #include <FLclCurrency.h>
26 #include <FLclLocale.h>
27 #include <FApp_AppInfo.h>
28 #include "FLcl_LocaleData.h"
29 #include "FLcl_CurrencyImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33
34 namespace Tizen { namespace Locales
35 {
36
37
38 /////////////////////////////////////////////////////////////////////////////////////////////////////
39 // Currency class Lifecycle
40
41 Currency::Currency(void)
42         : __currencyCodeSymbol()
43         , __pCurrencyImpl(null)
44 {
45 }
46
47
48 Currency::~Currency(void)
49 {
50 }
51
52
53 result
54 Currency::Construct(const Locale& locale)
55 {
56         result r =  _CurrencyImpl::GetCurrencyCodeSymbol(locale, __currencyCodeSymbol);
57         if (IsFailed(r))
58         {
59                 r = (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
60         }
61         return r;
62 }
63
64
65 result
66 Currency::Construct(const String& currencyCode)
67 {
68         result r = (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
69         SysTryReturnResult(NID_LCL, !currencyCode.IsEmpty(), r, "Currency code is empty");
70
71         r = _CurrencyImpl::GetCurrencyCodeSymbol(currencyCode, __currencyCodeSymbol);
72         if (IsFailed(r))
73         {
74                 r = (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
75         }
76         return r;
77 }
78
79
80 /////////////////////////////////////////////////////////////////////////////////////////////////////
81 // Currency class operations
82
83 String
84 Currency::GetCurrencyCode(void) const
85 {
86         int index = 0;
87         String retStr;
88
89         // if __currencyCodeSymbol is valid, will be in <Currency Code>_<Currency Symbol> format
90         if (!__currencyCodeSymbol.IsEmpty())
91         {
92                 result r = __currencyCodeSymbol.IndexOf(L'_', 0, index);          // get index till '_'
93                 if (r != E_OBJ_NOT_FOUND)
94                 {
95                         __currencyCodeSymbol.SubString(0, index, retStr);         // get string till index, it will be Currency Code
96                 }
97         }
98
99         return retStr;
100 }
101
102
103 String
104 Currency::GetSymbol(void) const
105 {
106         int index = 0;
107         String retStr;
108
109         // if __currencyCodeSymbol is valid, will be in <Currency Code>_<Currency Symbol> format
110         if (!__currencyCodeSymbol.IsEmpty())
111         {
112                 result r = __currencyCodeSymbol.IndexOf(L'_', 0, index);          // get index till '_'
113                 if (r != E_OBJ_NOT_FOUND)
114                 {
115                         __currencyCodeSymbol.SubString(index + 1, retStr);       // get string after index, it will be Currency symbol
116                 }
117         }
118
119         return retStr;
120 }
121
122 bool
123 Currency::Equals(const Object& obj) const
124 {
125         const Currency* pOtherCurrency = dynamic_cast< const Currency* >(&obj);
126         if (pOtherCurrency)
127         {
128                 return __currencyCodeSymbol.Equals(pOtherCurrency->__currencyCodeSymbol, true);
129         }
130         return false;
131 }
132
133 int
134 Currency::GetHashCode(void) const
135 {
136         return __currencyCodeSymbol.GetHashCode();
137 }
138
139 IList*
140 Currency::GetAvailableCurrenciesN(void)
141 {
142         return _CurrencyImpl::GetAvailableCurrenciesN();
143 }
144
145
146 };
147 };      // Tizen::Locales
148