2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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.
18 * @file ContactAddress.cpp
19 * @author Kisub Song (kisubs.song@samsung.com)
25 #include "ContactAddress.h"
31 ContactAddress::ContactAddress() :
32 m_countryIsSet(false),
35 m_streetAddressIsSet(false),
36 m_additionalInformationIsSet(false),
37 m_postalCodeIsSet(false)
39 m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
42 ContactAddress::~ContactAddress()
46 std::string ContactAddress::getCountry() const
51 void ContactAddress::setCountry(const std::string &value)
54 m_countryIsSet = true;
57 bool ContactAddress::getCountryIsSet() const
59 return m_countryIsSet;
62 std::string ContactAddress::getRegion() const
67 void ContactAddress::setRegion(const std::string &value)
73 bool ContactAddress::getRegionIsSet() const
78 std::string ContactAddress::getCity() const
83 void ContactAddress::setCity(const std::string &value)
89 bool ContactAddress::getCityIsSet() const
94 std::string ContactAddress::getStreetAddress() const
96 return m_streetAddress;
99 void ContactAddress::setStreetAddress(const std::string &value)
101 m_streetAddress = value;
102 m_streetAddressIsSet = true;
105 bool ContactAddress::getStreetAddressIsSet() const
107 return m_streetAddressIsSet;
110 std::string ContactAddress::getAdditionalInformation() const
112 return m_additionalInformation;
115 void ContactAddress::setAdditionalInformation(const std::string &value)
117 m_additionalInformation = value;
118 m_additionalInformationIsSet = true;
121 bool ContactAddress::getAdditionalInformationIsSet() const
123 return m_additionalInformationIsSet;
126 std::string ContactAddress::getPostalCode() const
131 void ContactAddress::setPostalCode(const std::string &value)
133 m_postalCode = value;
134 m_postalCodeIsSet = true;
137 bool ContactAddress::getPostalCodeIsSet() const
139 return m_postalCodeIsSet;
142 ContactAddressTypeArrayPtr ContactAddress::getTypes() const
147 void ContactAddress::setTypes(const ContactAddressTypeArrayPtr &value)
152 void ContactAddress::addType(const ContactAddressType &value)
154 m_types->push_back(value);
157 bool ContactAddress::isTypeOf(const ContactAddressType &value) const
159 return std::find(m_types->begin(), m_types->end(), value) != m_types->end();
162 int ContactAddress::getTypesNum() const
164 return m_types->size();
168 bool ContactAddress::compareTo(const ContactAddressPtr &address,
170 bool includeTypes) const
172 //compare basic fields
174 m_country == address->getCountry() &&
175 m_region == address->getRegion() &&
176 m_city == address->getCity() &&
177 m_streetAddress == address->getStreetAddress() &&
178 m_additionalInformation == address->getAdditionalInformation() &&
179 m_postalCode == address->getPostalCode()) {
180 //if not include fields then addresses are equal
184 //if types have different sizes then addresses are different
185 if (m_types->size() != address->getTypes()->size()) {
189 for (size_t i = 0; i < address->getTypes()->size(); i++) {
190 if (!isTypeOf(address->getTypes()->at(i))) {
199 std::string ContactAddress::getAsSingleString() const
201 std::string fullAddress;
202 //add street and street number when not empty
203 if (!m_streetAddress.empty()) {
204 fullAddress = m_streetAddress;
206 //add city and postal code when not empty
207 if (!m_city.empty()) {
208 if (!fullAddress.empty()) {
211 if (!m_postalCode.empty()) {
212 fullAddress += m_postalCode + " " + m_city;
214 fullAddress += m_city;
217 //add country when not empty
218 if (!m_country.empty()) {
219 if (!fullAddress.empty()) {
220 fullAddress += " " + m_country;
222 fullAddress = m_country;
225 if (!fullAddress.empty()) {
228 //when no data on detailed fields, then return free form field
232 void ContactAddress::clear()
237 m_streetAddress = "";
238 m_additionalInformation = "";
240 m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
242 m_countryIsSet = false;
243 m_regionIsSet = false;
245 m_streetAddressIsSet = false;
246 m_additionalInformationIsSet = false;
247 m_postalCodeIsSet = false;
250 ContactAddressPtr ContactAddress::clone() const
252 ContactAddressPtr result(new ContactAddress());
254 result->m_country = m_country;
255 result->m_region = m_region;
256 result->m_city = m_city;
257 result->m_streetAddress = m_streetAddress;
258 result->m_additionalInformation = m_additionalInformation;
259 result->m_postalCode = m_postalCode;
260 result->m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
261 ContactAddressTypeArray::iterator typeIter;
262 for(typeIter = m_types->begin(); typeIter != m_types->end(); typeIter++)
264 ContactAddressType addressType = *typeIter;
265 result->m_types->push_back(addressType);
268 result->m_countryIsSet = m_countryIsSet;
269 result->m_regionIsSet = m_regionIsSet;
270 result->m_cityIsSet = m_cityIsSet;
271 result->m_streetAddressIsSet = m_streetAddressIsSet;
272 result->m_additionalInformationIsSet = m_additionalInformationIsSet;
273 result->m_postalCodeIsSet = m_postalCodeIsSet;