984ea6f22a815afcda64b2c6f0cb58713e3e75de
[platform/framework/native/appfw.git] / src / locales / FLclNumberSymbols.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            FLclNumberSymbols.cpp
20  * @brief           This is the implementation file for NumberSymbols class.
21  */
22
23 // Includes
24 #include <new>
25 #include <FBaseResult.h>
26 #include <FBaseSysLog.h>
27 #include <FApp_AppInfo.h>
28 #include <FLclNumberSymbols.h>
29 #include "FLcl_NumberSymbolsImpl.h"
30 #include "FLcl_LocaleImpl.h"
31
32
33 using namespace Tizen::Base;
34
35 namespace Tizen { namespace Locales
36 {
37
38
39 /////////////////////////////////////////////////////////////////////////////////////////////////////
40 // Public Method
41
42 NumberSymbols::NumberSymbols(void)
43         : __pNumberSymbolsImpl(null)
44 {
45 }
46
47 NumberSymbols::~NumberSymbols(void)
48 {
49         delete __pNumberSymbolsImpl;
50         __pNumberSymbolsImpl = null;
51 }
52
53 result
54 NumberSymbols::Construct(const Locale& locale)
55 {
56         // Object is not allowed to construct twice
57         SysAssertf(__pNumberSymbolsImpl == null,
58                 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
59
60         result r = E_INVALID_ARG;
61
62         if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
63         {
64                 r = E_UNSUPPORTED_OPERATION;
65         }
66         // validating locale
67         SysTryReturnResult(NID_LCL, _LocaleImpl::IsSupported(locale), r, "Given locale is not supported");
68
69         __pNumberSymbolsImpl = new (std::nothrow) _NumberSymbolsImpl;
70         SysTryReturnResult(NID_LCL, __pNumberSymbolsImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
71
72         r = __pNumberSymbolsImpl->Construct(locale);
73         if (IsFailed(r))
74         {
75                 delete __pNumberSymbolsImpl;
76                 __pNumberSymbolsImpl = null;
77         }
78         return r;
79 }
80
81
82 String
83 NumberSymbols::GetNumberSymbol(NumberSymbol symbol) const
84 {
85         SysAssertf(__pNumberSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
86         return __pNumberSymbolsImpl->GetNumberSymbol(symbol);
87 }
88
89
90 result
91 NumberSymbols::SetNumberSymbol(const NumberSymbol symbol, const String& str)
92 {
93         SysAssertf(__pNumberSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
94         return __pNumberSymbolsImpl->SetNumberSymbol(symbol, str);
95 }
96
97
98 const Locale*
99 NumberSymbols::GetLocale(void) const
100 {
101         SysAssertf(__pNumberSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
102         return __pNumberSymbolsImpl->GetLocale();
103 }
104
105
106 };
107 };      // Tizen::Locales
108