Modify the spec file for secure log
[framework/osp/social.git] / src / FSclAddress.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  * @file                FSclAddress.cpp
18  * @brief               This is the implementation for Address class.
19  *
20  * This file contains definitions of @e Address class.
21  */
22
23 #include <FBaseString.h>
24 #include <FSclAddress.h>
25 #include <FApp_AppInfo.h>
26 #include <FBaseSysLog.h>
27 #include "FScl_AddressImpl.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31
32 namespace Tizen { namespace Social
33 {
34
35 static const int _MAX_ADDR_COUNTRY_LENGTH_2_0 = 100;
36
37 Address::Address(void)
38 {
39         __pAddressImpl = new (std::nothrow) _AddressImpl();
40         SysTryReturnVoidResult(NID_SCL, __pAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
41 }
42
43 Address::Address(const Address& rhs)
44 {
45         __pAddressImpl = new (std::nothrow) _AddressImpl(*rhs.__pAddressImpl);
46         SysTryReturnVoidResult(NID_SCL, __pAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
47
48 }
49
50 Address::~Address(void)
51 {
52         delete __pAddressImpl;
53 }
54
55 Address&
56 Address::operator =(const Address& rhs)
57 {
58         if (this == &rhs)
59         {
60                 return *this;
61         }
62
63         *__pAddressImpl = *rhs.__pAddressImpl;
64
65         return *this;
66 }
67
68 bool
69 Address::operator ==(const Address& rhs) const
70 {
71         return *__pAddressImpl == *rhs.__pAddressImpl;
72 }
73
74 bool
75 Address::operator !=(const Address& rhs) const
76 {
77         return !(*this == rhs);
78 }
79
80 bool
81 Address::Equals(const Object& rhs) const
82 {
83         const Address* pAddress = dynamic_cast<const Address*>(&rhs);
84
85         if (pAddress == null)
86         {
87                 return false;
88         }
89
90         return __pAddressImpl->Equals(*pAddress->__pAddressImpl);
91 }
92
93 int
94 Address::GetHashCode(void) const
95 {
96         return __pAddressImpl->GetHashCode();
97 }
98
99 AddressType
100 Address::GetType(void) const
101 {
102         AddressType type =  __pAddressImpl->GetType();
103
104         if (type == ADDRESS_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
105         {
106                 type =  ADDRESS_TYPE_OTHER;
107         }
108
109         return type;
110 }
111
112 String
113 Address::GetExtended(void) const
114 {
115         String extended =  __pAddressImpl->GetExtended();
116
117         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
118         {
119                 if (extended.GetLength() > MAX_ADDR_EXTENDED_LENGTH)
120                 {
121                         extended.SetLength(MAX_ADDR_EXTENDED_LENGTH);
122                 }
123         }
124
125         return extended;
126 }
127
128 String
129 Address::GetStreet(void) const
130 {
131         String street =  __pAddressImpl->GetStreet();
132
133         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
134         {
135                 if (street.GetLength() > MAX_ADDR_STREET_LENGTH)
136                 {
137                         street.SetLength(MAX_ADDR_STREET_LENGTH);
138                 }
139         }
140
141         return street;
142 }
143
144 String
145 Address::GetCity(void) const
146 {
147         String city =  __pAddressImpl->GetCity();
148
149         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
150         {
151                 if (city.GetLength() > MAX_ADDR_CITY_LENGTH)
152                 {
153                         city.SetLength(MAX_ADDR_CITY_LENGTH);
154                 }
155         }
156
157         return city;
158 }
159
160 String
161 Address::GetState(void) const
162 {
163         String state =  __pAddressImpl->GetState();
164
165         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
166         {
167                 if (state.GetLength() > MAX_ADDR_STATE_LENGTH)
168                 {
169                         state.SetLength(MAX_ADDR_STATE_LENGTH);
170                 }
171         }
172
173         return state;
174 }
175
176 String
177 Address::GetPostalCode(void) const
178 {
179         String postalCode =  __pAddressImpl->GetPostalCode();
180
181         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
182         {
183                 if (postalCode.GetLength() > MAX_ADDR_POSTAL_CODE_LENGTH)
184                 {
185                         postalCode.SetLength(MAX_ADDR_POSTAL_CODE_LENGTH);
186                 }
187         }
188
189         return postalCode;
190 }
191
192 String
193 Address::GetCountry(void) const
194 {
195         String country =  __pAddressImpl->GetCountry();
196
197         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
198         {
199                 if (country.GetLength() > _MAX_ADDR_COUNTRY_LENGTH_2_0)
200                 {
201                         country.SetLength(_MAX_ADDR_COUNTRY_LENGTH_2_0);
202                 }
203         }
204
205         return country;
206 }
207
208 String
209 Address::GetPostOfficeBoxNumber(void) const
210 {
211         String postOfficeBoxNumber = __pAddressImpl->GetPostOfficeBoxNumber();
212
213         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
214         {
215                 if (postOfficeBoxNumber.GetLength() > MAX_ADDR_POBOXNUM_LENGTH)
216                 {
217                         postOfficeBoxNumber.SetLength(MAX_ADDR_POBOXNUM_LENGTH);
218                 }
219         }
220
221         return postOfficeBoxNumber;
222 }
223
224 void
225 Address::SetType(AddressType type)
226 {
227         return __pAddressImpl->SetType(type);
228 }
229
230 result
231 Address::SetExtended(const String& extended)
232 {
233         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
234         {
235                 SysTryReturn(NID_SCL, extended.GetLength() <= MAX_ADDR_EXTENDED_LENGTH,
236                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_EXTENDED_LENGTH.", GetErrorMessage(E_INVALID_ARG));
237         }
238
239         __pAddressImpl->SetExtended(extended);
240
241         return E_SUCCESS;
242 }
243
244 result
245 Address::SetStreet(const String& street)
246 {
247         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
248         {
249                 SysTryReturn(NID_SCL, street.GetLength() <= MAX_ADDR_STREET_LENGTH,
250                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_STREET_LENGTH.", GetErrorMessage(E_INVALID_ARG));
251         }
252
253         __pAddressImpl->SetStreet(street);
254
255         return E_SUCCESS;
256 }
257
258 result
259 Address::SetCity(const String& city)
260 {
261         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
262         {
263                 SysTryReturn(NID_SCL, city.GetLength() <= MAX_ADDR_CITY_LENGTH,
264                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_CITY_LENGTH.", GetErrorMessage(E_INVALID_ARG));
265         }
266
267         __pAddressImpl->SetCity(city);
268
269         return E_SUCCESS;
270 }
271
272 result
273 Address::SetState(const String& state)
274 {
275         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
276         {
277                 SysTryReturn(NID_SCL, state.GetLength() <= MAX_ADDR_STATE_LENGTH,
278                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_STATE_LENGTH.", GetErrorMessage(E_INVALID_ARG));
279         }
280
281         __pAddressImpl->SetState(state);
282
283         return E_SUCCESS;
284 }
285
286 result
287 Address::SetPostalCode(const String& postalCode)
288 {
289         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
290         {
291                 SysTryReturn(NID_SCL, postalCode.GetLength() <= MAX_ADDR_POSTAL_CODE_LENGTH,
292                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_POSTAL_CODE_LENGTH.", GetErrorMessage(E_INVALID_ARG));
293         }
294
295         __pAddressImpl->SetPostalCode(postalCode);
296
297         return E_SUCCESS;
298 }
299
300 result
301 Address::SetCountry(const String& country)
302 {
303         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
304         {
305                 SysTryReturn(NID_SCL, country.GetLength() <= _MAX_ADDR_COUNTRY_LENGTH_2_0,
306                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of country exceeds the maximum length.", GetErrorMessage(E_INVALID_ARG));
307         }
308
309         __pAddressImpl->SetCountry(country);
310
311         return E_SUCCESS;
312 }
313
314 result
315 Address::SetPostOfficeBoxNumber(const String& postOfficeBoxNumber)
316 {
317         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
318         {
319                 SysTryReturn(NID_SCL, postOfficeBoxNumber.GetLength() <= MAX_ADDR_POBOXNUM_LENGTH,
320                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_POBOXNUM_LENGTH.", GetErrorMessage(E_INVALID_ARG));
321         }
322
323         __pAddressImpl->SetPostOfficeBoxNumber(postOfficeBoxNumber);
324
325         return E_SUCCESS;
326 }
327
328 String
329 Address::GetLabel(void) const
330 {
331         return __pAddressImpl->GetLabel();
332 }
333
334 void
335 Address::SetLabel(const String& label)
336 {
337         __pAddressImpl->SetLabel(label);
338 }
339
340
341 }} //Tizen::Social