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