2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file FSclAddress.cpp
18 * @brief This is the implementation for Address class.
20 * This file contains definitions of @e Address class.
23 #include <FBaseString.h>
24 #include <FSclAddress.h>
25 #include <FApp_AppInfo.h>
26 #include <FBaseSysLog.h>
27 #include "FScl_AddressImpl.h"
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
32 namespace Tizen { namespace Social
35 static const int _MAX_ADDR_COUNTRY_LENGTH_2_0 = 100;
37 Address::Address(void)
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));
43 Address::Address(const Address& rhs)
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));
50 Address::~Address(void)
52 delete __pAddressImpl;
56 Address::operator =(const Address& rhs)
63 *__pAddressImpl = *rhs.__pAddressImpl;
69 Address::operator ==(const Address& rhs) const
71 return *__pAddressImpl == *rhs.__pAddressImpl;
75 Address::operator !=(const Address& rhs) const
77 return !(*this == rhs);
81 Address::Equals(const Object& rhs) const
83 const Address* pAddress = dynamic_cast<const Address*>(&rhs);
90 return __pAddressImpl->Equals(*pAddress->__pAddressImpl);
94 Address::GetHashCode(void) const
96 return __pAddressImpl->GetHashCode();
100 Address::GetType(void) const
102 AddressType type = __pAddressImpl->GetType();
104 if (type == ADDRESS_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
106 type = ADDRESS_TYPE_OTHER;
113 Address::GetExtended(void) const
115 String extended = __pAddressImpl->GetExtended();
117 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
119 if (extended.GetLength() > MAX_ADDR_EXTENDED_LENGTH)
121 extended.SetLength(MAX_ADDR_EXTENDED_LENGTH);
129 Address::GetStreet(void) const
131 String street = __pAddressImpl->GetStreet();
133 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
135 if (street.GetLength() > MAX_ADDR_STREET_LENGTH)
137 street.SetLength(MAX_ADDR_STREET_LENGTH);
145 Address::GetCity(void) const
147 String city = __pAddressImpl->GetCity();
149 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
151 if (city.GetLength() > MAX_ADDR_CITY_LENGTH)
153 city.SetLength(MAX_ADDR_CITY_LENGTH);
161 Address::GetState(void) const
163 String state = __pAddressImpl->GetState();
165 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
167 if (state.GetLength() > MAX_ADDR_STATE_LENGTH)
169 state.SetLength(MAX_ADDR_STATE_LENGTH);
177 Address::GetPostalCode(void) const
179 String postalCode = __pAddressImpl->GetPostalCode();
181 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
183 if (postalCode.GetLength() > MAX_ADDR_POSTAL_CODE_LENGTH)
185 postalCode.SetLength(MAX_ADDR_POSTAL_CODE_LENGTH);
193 Address::GetCountry(void) const
195 String country = __pAddressImpl->GetCountry();
197 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
199 if (country.GetLength() > _MAX_ADDR_COUNTRY_LENGTH_2_0)
201 country.SetLength(_MAX_ADDR_COUNTRY_LENGTH_2_0);
209 Address::GetPostOfficeBoxNumber(void) const
211 String postOfficeBoxNumber = __pAddressImpl->GetPostOfficeBoxNumber();
213 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
215 if (postOfficeBoxNumber.GetLength() > MAX_ADDR_POBOXNUM_LENGTH)
217 postOfficeBoxNumber.SetLength(MAX_ADDR_POBOXNUM_LENGTH);
221 return postOfficeBoxNumber;
225 Address::SetType(AddressType type)
227 return __pAddressImpl->SetType(type);
231 Address::SetExtended(const String& extended)
233 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
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));
239 __pAddressImpl->SetExtended(extended);
245 Address::SetStreet(const String& street)
247 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
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));
253 __pAddressImpl->SetStreet(street);
259 Address::SetCity(const String& city)
261 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
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));
267 __pAddressImpl->SetCity(city);
273 Address::SetState(const String& state)
275 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
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));
281 __pAddressImpl->SetState(state);
287 Address::SetPostalCode(const String& postalCode)
289 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
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));
295 __pAddressImpl->SetPostalCode(postalCode);
301 Address::SetCountry(const String& country)
303 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
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));
309 __pAddressImpl->SetCountry(country);
315 Address::SetPostOfficeBoxNumber(const String& postOfficeBoxNumber)
317 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
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));
323 __pAddressImpl->SetPostOfficeBoxNumber(postOfficeBoxNumber);
329 Address::GetLabel(void) const
331 return __pAddressImpl->GetLabel();
335 Address::SetLabel(const String& label)
337 __pAddressImpl->SetLabel(label);