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 ContactEmail.cpp
19 * @author Lukasz Marek (l.marek@samsung.com)
25 #include "ContactAddress.h"
27 namespace WrtDeviceApis {
31 ContactAddress::ContactAddress() :
34 m_countryIsSet(false),
39 m_streetNumberIsSet(false),
40 m_premisesIsSet(false),
41 m_additionalInformationIsSet(false),
42 m_postalCodeIsSet(false)
47 ContactAddress::~ContactAddress()
52 bool ContactAddress::compareTo(const ContactAddressPtr &address,
54 bool includeTypes) const
56 //compare basic fields
57 if ((!includeId || m_id == address->getId()) &&
58 m_country == address->getCountry() &&
59 m_region == address->getRegion() &&
60 m_county == address->getCounty() &&
61 m_city == address->getCity() &&
62 m_street == address->getStreet() &&
63 m_streetNumber == address->getStreetNumber() &&
64 m_premises == address->getPremises() &&
65 m_additionalInformation == address->getAdditionalInformation() &&
66 m_postalCode == address->getPostalCode()) {
67 //if not include fields then addresses are equal
71 //if types have different sizes then addresses are different
72 if (m_types.size() != address->getTypes().size()) {
76 for (size_t i = 0; i < address->getTypes().size(); i++) {
77 if (!isTypeOf(address->getTypes()[i])) {
86 ContactAddressPtr ContactAddress::clone() const
88 //clone object by using copy constructors
89 return ContactAddressPtr(new ContactAddress(*this));
92 std::string ContactAddress::getAsSingleString() const
94 std::string fullAddress;
95 //add street and street number when not empty
96 if (!m_street.empty()) {
97 fullAddress = m_street;
98 if (!m_streetNumber.empty()) {
99 fullAddress += " " + m_streetNumber;
102 //add city and postal code when not empty
103 if (!m_city.empty()) {
104 if (!fullAddress.empty()) {
107 if (!m_postalCode.empty()) {
108 fullAddress += m_postalCode + " " + m_city;
110 fullAddress += m_city;
113 //add country when not empty
114 if (!m_country.empty()) {
115 if (!fullAddress.empty()) {
116 fullAddress += " " + m_country;
118 fullAddress = m_country;
121 if (!fullAddress.empty()) {
124 //when no data on detailed fields, then return free form field
128 std::string ContactAddress::getAddress() const
130 //return free form field for address
134 void ContactAddress::setAddress(const std::string &value)
136 //set free form field for address
140 int ContactAddress::getId() const
142 //return id of address record
146 void ContactAddress::setId(int value)
148 //set id of address record
152 std::string ContactAddress::getCountry() const
158 void ContactAddress::setCountry(const std::string &value)
162 //mark country as set
163 m_countryIsSet = true;
166 std::string ContactAddress::getRegion() const
172 void ContactAddress::setRegion(const std::string &value)
177 m_regionIsSet = true;
180 std::string ContactAddress::getCounty() const
186 void ContactAddress::setCounty(const std::string &value)
191 m_countyIsSet = true;
194 std::string ContactAddress::getCity() const
200 void ContactAddress::setCity(const std::string &value)
208 std::string ContactAddress::getStreet() const
214 void ContactAddress::setStreet(const std::string &value)
219 m_streetIsSet = true;
222 std::string ContactAddress::getStreetNumber() const
224 //return street number
225 return m_streetNumber;
228 void ContactAddress::setStreetNumber(const std::string &value)
231 m_streetNumber = value;
232 //mark streen number as set
233 m_streetNumberIsSet = true;
236 std::string ContactAddress::getPremises() const
242 void ContactAddress::setPremises(const std::string &value)
246 //mark premises as set
247 m_premisesIsSet = true;
250 std::string ContactAddress::getAdditionalInformation() const
252 //return additional information
253 return m_additionalInformation;
256 void ContactAddress::setAdditionalInformation(const std::string &value)
258 //set additional information
259 m_additionalInformation = value;
260 //mark additional information as set
261 m_additionalInformationIsSet = true;
264 std::string ContactAddress::getPostalCode() const
266 //returns postal code
270 void ContactAddress::setPostalCode(const std::string &value)
272 //set new postal code
273 m_postalCode = value;
274 //mark postal code as set
275 m_postalCodeIsSet = true;
278 std::vector<ContactAddress::ContactAddressType> ContactAddress::getTypes()
281 //return address types
285 void ContactAddress::addType(const ContactAddressType value)
287 //add new type to set
288 m_types.push_back(value);
291 void ContactAddress::setTypes(const std::vector<ContactAddressType> &value)
297 bool ContactAddress::isTypeOf(const ContactAddressType value) const
299 //return true when address is type of type passed as argument
300 return std::find(m_types.begin(), m_types.end(), value) != m_types.end();
303 void ContactAddress::setTypeFilter(const ContactAddressType value)
305 //clear existing types and add new one
307 m_types.push_back(value);
310 ContactAddress::ContactAddressType ContactAddress::getTypeFilter() const
312 //return first type or undefined when non set
313 return m_types.size() == 0 ? CONTACT_ADDRESS_TYPE_PREF : m_types[0];
316 bool ContactAddress::getCountryIsSet() const
318 //returns true when contry is set
319 return m_countryIsSet;
322 bool ContactAddress::getRegionIsSet() const
324 //returns true when region is set
325 return m_regionIsSet;
328 bool ContactAddress::getCountyIsSet() const
330 //returns true when county is set
331 return m_countyIsSet;
334 bool ContactAddress::getCityIsSet() const
336 //returns true when city is set
340 bool ContactAddress::getStreetIsSet() const
342 //returns true when street is set
343 return m_streetIsSet;
346 bool ContactAddress::getStreetNumberIsSet() const
348 //returns true when street number is set
349 return m_streetNumberIsSet;
352 bool ContactAddress::getPremisesIsSet() const
354 //returns true when premises is set
355 return m_premisesIsSet;
358 bool ContactAddress::getAdditionalInformationIsSet() const
360 //returns true when additional information is set
361 return m_additionalInformationIsSet;
364 bool ContactAddress::getPostalCodeIsSet() const
366 //returns true when postal code is set
367 return m_postalCodeIsSet;