2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FSclAddress.cpp
19 * @brief This is the implementation for Address class.
21 * This file contains definitions of @e Address class.
24 #include <FBaseString.h>
25 #include <FSclAddress.h>
26 #include <FApp_AppInfo.h>
27 #include <FBaseSysLog.h>
28 #include "FScl_AddressImpl.h"
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
33 namespace Tizen { namespace Social
36 static const int _MAX_ADDR_COUNTRY_LENGTH_2_0 = 100;
38 Address::Address(void)
40 __pAddressImpl = new (std::nothrow) _AddressImpl();
41 SysTryReturnVoidResult(NID_SCL, __pAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
44 Address::Address(const Address& rhs)
46 __pAddressImpl = new (std::nothrow) _AddressImpl(*rhs.__pAddressImpl);
47 SysTryReturnVoidResult(NID_SCL, __pAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
51 Address::~Address(void)
53 delete __pAddressImpl;
57 Address::operator =(const Address& rhs)
64 *__pAddressImpl = *rhs.__pAddressImpl;
70 Address::operator ==(const Address& rhs) const
72 return *__pAddressImpl == *rhs.__pAddressImpl;
76 Address::operator !=(const Address& rhs) const
78 return !(*this == rhs);
82 Address::Equals(const Object& rhs) const
84 const Address* pAddress = dynamic_cast<const Address*>(&rhs);
91 return __pAddressImpl->Equals(*pAddress->__pAddressImpl);
95 Address::GetHashCode(void) const
97 return __pAddressImpl->GetHashCode();
101 Address::GetType(void) const
103 AddressType type = __pAddressImpl->GetType();
105 if (type == ADDRESS_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
107 type = ADDRESS_TYPE_OTHER;
114 Address::GetExtended(void) const
116 String extended = __pAddressImpl->GetExtended();
118 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
120 if (extended.GetLength() > MAX_ADDR_EXTENDED_LENGTH)
122 extended.SetLength(MAX_ADDR_EXTENDED_LENGTH);
130 Address::GetStreet(void) const
132 String street = __pAddressImpl->GetStreet();
134 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
136 if (street.GetLength() > MAX_ADDR_STREET_LENGTH)
138 street.SetLength(MAX_ADDR_STREET_LENGTH);
146 Address::GetCity(void) const
148 String city = __pAddressImpl->GetCity();
150 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
152 if (city.GetLength() > MAX_ADDR_CITY_LENGTH)
154 city.SetLength(MAX_ADDR_CITY_LENGTH);
162 Address::GetState(void) const
164 String state = __pAddressImpl->GetState();
166 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
168 if (state.GetLength() > MAX_ADDR_STATE_LENGTH)
170 state.SetLength(MAX_ADDR_STATE_LENGTH);
178 Address::GetPostalCode(void) const
180 String postalCode = __pAddressImpl->GetPostalCode();
182 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
184 if (postalCode.GetLength() > MAX_ADDR_POSTAL_CODE_LENGTH)
186 postalCode.SetLength(MAX_ADDR_POSTAL_CODE_LENGTH);
194 Address::GetCountry(void) const
196 String country = __pAddressImpl->GetCountry();
198 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
200 if (country.GetLength() > _MAX_ADDR_COUNTRY_LENGTH_2_0)
202 country.SetLength(_MAX_ADDR_COUNTRY_LENGTH_2_0);
210 Address::GetPostOfficeBoxNumber(void) const
212 String postOfficeBoxNumber = __pAddressImpl->GetPostOfficeBoxNumber();
214 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
216 if (postOfficeBoxNumber.GetLength() > MAX_ADDR_POBOXNUM_LENGTH)
218 postOfficeBoxNumber.SetLength(MAX_ADDR_POBOXNUM_LENGTH);
222 return postOfficeBoxNumber;
226 Address::SetType(AddressType type)
228 return __pAddressImpl->SetType(type);
232 Address::SetExtended(const String& extended)
234 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
236 SysTryReturn(NID_SCL, extended.GetLength() <= MAX_ADDR_EXTENDED_LENGTH,
237 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));
240 __pAddressImpl->SetExtended(extended);
246 Address::SetStreet(const String& street)
248 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
250 SysTryReturn(NID_SCL, street.GetLength() <= MAX_ADDR_STREET_LENGTH,
251 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));
254 __pAddressImpl->SetStreet(street);
260 Address::SetCity(const String& city)
262 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
264 SysTryReturn(NID_SCL, city.GetLength() <= MAX_ADDR_CITY_LENGTH,
265 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));
268 __pAddressImpl->SetCity(city);
274 Address::SetState(const String& state)
276 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
278 SysTryReturn(NID_SCL, state.GetLength() <= MAX_ADDR_STATE_LENGTH,
279 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));
282 __pAddressImpl->SetState(state);
288 Address::SetPostalCode(const String& postalCode)
290 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
292 SysTryReturn(NID_SCL, postalCode.GetLength() <= MAX_ADDR_POSTAL_CODE_LENGTH,
293 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));
296 __pAddressImpl->SetPostalCode(postalCode);
302 Address::SetCountry(const String& country)
304 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
306 SysTryReturn(NID_SCL, country.GetLength() <= _MAX_ADDR_COUNTRY_LENGTH_2_0,
307 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of country exceeds the maximum length.", GetErrorMessage(E_INVALID_ARG));
310 __pAddressImpl->SetCountry(country);
316 Address::SetPostOfficeBoxNumber(const String& postOfficeBoxNumber)
318 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
320 SysTryReturn(NID_SCL, postOfficeBoxNumber.GetLength() <= MAX_ADDR_POBOXNUM_LENGTH,
321 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));
324 __pAddressImpl->SetPostOfficeBoxNumber(postOfficeBoxNumber);
330 Address::GetLabel(void) const
332 return __pAddressImpl->GetLabel();
336 Address::SetLabel(const String& label)
338 __pAddressImpl->SetLabel(label);