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