Merge "sync code for tizen_2.2" into devel_3.0_main
[platform/framework/native/appfw.git] / src / locales / FLclDateTimeSymbols.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        FLclDateTimeSymbols.cpp
19  * @brief       This is the implementation file for DateTimeSymbols class.
20  */
21
22 #include <unique_ptr.h>
23
24 #include <FBaseSysLog.h>
25 #include <FApp_AppInfo.h>
26 #include <FLclDateTimeSymbols.h>
27 #include "FLcl_DateTimeSymbolsImpl.h"
28
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Base::Utility;
33
34 namespace Tizen { namespace Locales
35 {
36
37
38 /////////////////////////////////////////////////////////////////////////////////////////////////////
39 // Public Methods
40
41 DateTimeSymbols::DateTimeSymbols(void)
42         : __pDateTimeSymbolsImpl(null)
43 {
44 }
45
46 DateTimeSymbols::~DateTimeSymbols(void)
47 {
48         delete __pDateTimeSymbolsImpl;
49         __pDateTimeSymbolsImpl = null;
50 }
51
52 result
53 DateTimeSymbols::AddTimeZoneName(const Tizen::Base::String& timeZoneId, const Tizen::Base::String& concatenatedTimeZoneName)
54 {
55         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
56
57         return __pDateTimeSymbolsImpl->AddTimeZoneName(timeZoneId, concatenatedTimeZoneName);
58 }
59
60
61 result
62 DateTimeSymbols::Construct(const Locale& locale, CalendarType calendarType)
63 {
64         SysAssertf(__pDateTimeSymbolsImpl == null,
65                 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
66
67         std::unique_ptr< _DateTimeSymbolsImpl > pDateTimeSymbolsImpl(new (std::nothrow) _DateTimeSymbolsImpl);
68         SysTryReturnResult(NID_LCL, pDateTimeSymbolsImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
69
70         result r = pDateTimeSymbolsImpl->Initialize(locale, calendarType);
71         if (IsFailed(r))
72         {
73                 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
74                 {
75                         return E_UNSUPPORTED_OPERATION;
76                 }
77                 return E_INVALID_ARG;
78         }
79
80         __pDateTimeSymbolsImpl = pDateTimeSymbolsImpl.release();
81         return E_SUCCESS;
82 }
83
84
85 result
86 DateTimeSymbols::Construct(CalendarType calendarType)
87 {
88         // Object is not allowed to construct twice
89         SysAssertf(__pDateTimeSymbolsImpl == null,
90                 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
91
92         std::unique_ptr< _DateTimeSymbolsImpl > pDateTimeSymbolsImpl(new (std::nothrow) _DateTimeSymbolsImpl);
93         SysTryReturnResult(NID_LCL, pDateTimeSymbolsImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
94
95         result r = pDateTimeSymbolsImpl->Initialize(calendarType);
96         if (IsFailed(r))
97         {
98                 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
99                 {
100                         return E_UNSUPPORTED_OPERATION;
101                 }
102                 return E_INVALID_ARG;
103         }
104
105         __pDateTimeSymbolsImpl = pDateTimeSymbolsImpl.release();
106         return E_SUCCESS;
107 }
108
109
110 result
111 DateTimeSymbols::Construct(const DateTimeSymbols& other)
112 {
113         SysAssertf(__pDateTimeSymbolsImpl == null,
114                 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
115
116         if (other.__pDateTimeSymbolsImpl)
117         {
118                 __pDateTimeSymbolsImpl = new (std::nothrow) _DateTimeSymbolsImpl;
119                 SysTryReturnResult(NID_LCL, __pDateTimeSymbolsImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
120
121                 __pDateTimeSymbolsImpl->Set(other.__pDateTimeSymbolsImpl);
122         }
123
124         return E_SUCCESS;
125 }
126
127 const IList*
128 DateTimeSymbols::GetAmPm(void) const
129 {
130         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
131         return __pDateTimeSymbolsImpl->GetAmPm();
132 }
133
134 result
135 DateTimeSymbols::SetAmPm(const String& amPm)
136 {
137         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
138         return __pDateTimeSymbolsImpl->SetAmPm(amPm);
139 }
140
141 const IList*
142 DateTimeSymbols::GetEras(void) const
143 {
144         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
145         return __pDateTimeSymbolsImpl->GetEras();
146 }
147
148 result
149 DateTimeSymbols::SetEras(const String& eras)
150 {
151         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
152         return __pDateTimeSymbolsImpl->SetEras(eras);
153 }
154
155 const IList*
156 DateTimeSymbols::GetMonths(void) const
157 {
158         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
159         return __pDateTimeSymbolsImpl->GetMonths();
160 }
161
162 result
163 DateTimeSymbols::SetMonths(const String& months)
164 {
165         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
166         return __pDateTimeSymbolsImpl->SetMonths(months);
167 }
168
169 const IList*
170 DateTimeSymbols::GetShortMonths(void) const
171 {
172         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");;
173         return __pDateTimeSymbolsImpl->GetShortMonths();
174 }
175
176 result
177 DateTimeSymbols::SetShortMonths(const String& shortMonths)
178 {
179         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
180         return __pDateTimeSymbolsImpl->SetShortMonths(shortMonths);
181 }
182
183 const IList*
184 DateTimeSymbols::GetWeekdays(void) const
185 {
186         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
187         return __pDateTimeSymbolsImpl->GetWeekdays();
188 }
189
190 result
191 DateTimeSymbols::SetWeekdays(const String& weekdays)
192 {
193         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
194         return __pDateTimeSymbolsImpl->SetWeekdays(weekdays);
195 }
196
197
198 const IList*
199 DateTimeSymbols::GetShortWeekdays(void) const
200 {
201         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
202         return __pDateTimeSymbolsImpl->GetShortWeekdays();
203 }
204
205 result
206 DateTimeSymbols::SetShortWeekdays(const String& shortWeekdays)
207 {
208         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
209         return __pDateTimeSymbolsImpl->SetShortWeekdays(shortWeekdays);
210 }
211
212
213 String
214 DateTimeSymbols::GetTimeZoneName(Tizen::Base::String& timeZoneId, int timeZoneStyle) const
215 {
216         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
217         return __pDateTimeSymbolsImpl->GetTimeZoneName(timeZoneId, timeZoneStyle);
218 }
219
220
221 result
222 DateTimeSymbols::SetTimeZoneName(const Tizen::Base::String& timeZoneId, const Tizen::Base::String& concatenatedTimeZoneName)
223 {
224         SysAssertf(__pDateTimeSymbolsImpl != null, "Not yet constructed! Construct() should be called before use.");
225
226         return __pDateTimeSymbolsImpl->SetTimeZoneName(timeZoneId, concatenatedTimeZoneName);
227 }
228
229 };
230 };      // Tizen::Locales
231