minor code cleanup
[platform/framework/native/appfw.git] / src / locales / FLclCurrency.cpp
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            FLclCurrency.cpp
19  * @brief           This is the implementation file for Currency class.
20  */
21
22 // Includes
23 #include <FBaseSysLog.h>
24 #include <FLclCurrency.h>
25 #include <FLclLocale.h>
26 #include <FApp_AppInfo.h>
27 #include "FLcl_LocaleData.h"
28 #include "FLcl_CurrencyImpl.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32
33 namespace Tizen { namespace Locales
34 {
35
36
37 /////////////////////////////////////////////////////////////////////////////////////////////////////
38 // Currency class Lifecycle
39
40 Currency::Currency(void)
41         : __currencyCodeSymbol()
42         , __pCurrencyImpl(null)
43 {
44 }
45
46
47 Currency::~Currency(void)
48 {
49 }
50
51
52 result
53 Currency::Construct(const Locale& locale)
54 {
55         result r =  _CurrencyImpl::GetCurrencyCodeSymbol(locale, __currencyCodeSymbol);
56         if (IsFailed(r))
57         {
58                 r = (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
59         }
60         return r;
61 }
62
63
64 result
65 Currency::Construct(const String& currencyCode)
66 {
67         result r = (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
68         SysTryReturnResult(NID_LCL, !currencyCode.IsEmpty(), r, "Currency code is empty");
69
70         r = _CurrencyImpl::GetCurrencyCodeSymbol(currencyCode, __currencyCodeSymbol);
71         if (IsFailed(r))
72         {
73                 r = (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
74         }
75         return r;
76 }
77
78
79 /////////////////////////////////////////////////////////////////////////////////////////////////////
80 // Currency class operations
81
82 String
83 Currency::GetCurrencyCode(void) const
84 {
85         int index = 0;
86         String retStr;
87
88         // if __currencyCodeSymbol is valid, will be in <Currency Code>_<Currency Symbol> format
89         if (!__currencyCodeSymbol.IsEmpty())
90         {
91                 result r = __currencyCodeSymbol.IndexOf(L'_', 0, index);          // get index till '_'
92                 if (r != E_OBJ_NOT_FOUND)
93                 {
94                         __currencyCodeSymbol.SubString(0, index, retStr);         // get string till index, it will be Currency Code
95                 }
96         }
97
98         return retStr;
99 }
100
101
102 String
103 Currency::GetSymbol(void) const
104 {
105         int index = 0;
106         String retStr;
107
108         // if __currencyCodeSymbol is valid, will be in <Currency Code>_<Currency Symbol> format
109         if (!__currencyCodeSymbol.IsEmpty())
110         {
111                 result r = __currencyCodeSymbol.IndexOf(L'_', 0, index);          // get index till '_'
112                 if (r != E_OBJ_NOT_FOUND)
113                 {
114                         __currencyCodeSymbol.SubString(index + 1, retStr);       // get string after index, it will be Currency symbol
115                 }
116         }
117
118         return retStr;
119 }
120
121 bool
122 Currency::Equals(const Object& obj) const
123 {
124         const Currency* pOtherCurrency = dynamic_cast< const Currency* >(&obj);
125         if (pOtherCurrency)
126         {
127                 return __currencyCodeSymbol.Equals(pOtherCurrency->__currencyCodeSymbol, true);
128         }
129         return false;
130 }
131
132 int
133 Currency::GetHashCode(void) const
134 {
135         return __currencyCodeSymbol.GetHashCode();
136 }
137
138 IList*
139 Currency::GetAvailableCurrenciesN(void)
140 {
141         return _CurrencyImpl::GetAvailableCurrenciesN();
142 }
143
144
145 };
146 };      // Tizen::Locales
147