1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
|
//
// Tizen Web Device API
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
/**
* @file ContactAddress.cpp
* @version 0.1
* @brief
*/
#include <algorithm>
#include "ContactAddress.h"
namespace DeviceAPI {
namespace Contact {
ContactAddress::ContactAddress() :
m_countryIsSet(false),
m_regionIsSet(false),
m_cityIsSet(false),
m_streetAddressIsSet(false),
m_additionalInformationIsSet(false),
m_postalCodeIsSet(false),
m_isDefault(false)
{
m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
is_typesSetJSArray = false;
m_context = NULL;
m_typesJsValue = NULL;
m_typesObj = NULL;
}
ContactAddress::~ContactAddress()
{
if(IsTypesSetJSArray()){
JSContextRef contextRef = getContext();
JSObjectRef tempJSObject = getTypesJSObj();
JSValueUnprotect(contextRef, tempJSObject);
}
}
std::string ContactAddress::getCountry() const
{
return m_country;
}
void ContactAddress::setCountry(const std::string &value)
{
m_country = value;
m_countryIsSet = true;
}
void ContactAddress::unsetCountry()
{
m_country = "";
m_countryIsSet = false;
}
bool ContactAddress::getCountryIsSet() const
{
return m_countryIsSet;
}
std::string ContactAddress::getRegion() const
{
return m_region;
}
void ContactAddress::setRegion(const std::string &value)
{
m_region = value;
m_regionIsSet = true;
}
void ContactAddress::unsetRegion()
{
m_region = "";
m_regionIsSet = false;
}
bool ContactAddress::getRegionIsSet() const
{
return m_regionIsSet;
}
std::string ContactAddress::getCity() const
{
return m_city;
}
void ContactAddress::setCity(const std::string &value)
{
m_city = value;
m_cityIsSet = true;
}
void ContactAddress::unsetCity()
{
m_city = "";
m_cityIsSet = false;
}
bool ContactAddress::getCityIsSet() const
{
return m_cityIsSet;
}
std::string ContactAddress::getStreetAddress() const
{
return m_streetAddress;
}
void ContactAddress::setStreetAddress(const std::string &value)
{
m_streetAddress = value;
m_streetAddressIsSet = true;
}
void ContactAddress::unsetStreetAddress()
{
m_streetAddress = "";
m_streetAddressIsSet = false;
}
bool ContactAddress::getStreetAddressIsSet() const
{
return m_streetAddressIsSet;
}
std::string ContactAddress::getAdditionalInformation() const
{
return m_additionalInformation;
}
void ContactAddress::setAdditionalInformation(const std::string &value)
{
m_additionalInformation = value;
m_additionalInformationIsSet = true;
}
void ContactAddress::unsetAdditionalInformation()
{
m_additionalInformation = "";
m_additionalInformationIsSet = false;
}
bool ContactAddress::getAdditionalInformationIsSet() const
{
return m_additionalInformationIsSet;
}
std::string ContactAddress::getPostalCode() const
{
return m_postalCode;
}
void ContactAddress::setPostalCode(const std::string &value)
{
m_postalCode = value;
m_postalCodeIsSet = true;
}
void ContactAddress::unsetPostalCode()
{
m_postalCode = "";
m_postalCodeIsSet = false;
}
bool ContactAddress::getPostalCodeIsSet() const
{
return m_postalCodeIsSet;
}
bool ContactAddress::getIsDefault() const
{
return m_isDefault;
}
void ContactAddress::setIsDefault(const bool &value)
{
m_isDefault = value;
}
ContactAddressTypeArrayPtr ContactAddress::getTypes() const
{
return m_types;
}
void ContactAddress::setTypes(const ContactAddressTypeArrayPtr &value)
{
m_types = value;
}
void ContactAddress::addType(const ContactAddressType &value)
{
m_types->push_back(value);
}
bool ContactAddress::isTypeOf(const ContactAddressType &value) const
{
return std::find(m_types->begin(), m_types->end(), value) != m_types->end();
}
int ContactAddress::getTypesNum() const
{
return m_types->size();
}
bool ContactAddress::compareTo(const ContactAddressPtr &address,
bool includeId,
bool includeTypes) const
{
//compare basic fields
if ((!includeId) &&
m_country == address->getCountry() &&
m_region == address->getRegion() &&
m_city == address->getCity() &&
m_streetAddress == address->getStreetAddress() &&
m_additionalInformation == address->getAdditionalInformation() &&
m_postalCode == address->getPostalCode()) {
//if not include fields then addresses are equal
if (!includeTypes) {
return true;
}
//if types have different sizes then addresses are different
if (m_types->size() != address->getTypes()->size()) {
return false;
}
//compare each type
for (size_t i = 0; i < address->getTypes()->size(); i++) {
if (!isTypeOf(address->getTypes()->at(i))) {
return false;
}
}
return true;
}
return false;
}
std::string ContactAddress::getAsSingleString() const
{
std::string fullAddress;
//add street and street number when not empty
if (!m_streetAddress.empty()) {
fullAddress = m_streetAddress;
}
//add city and postal code when not empty
if (!m_city.empty()) {
if (!fullAddress.empty()) {
fullAddress += " ";
}
if (!m_postalCode.empty()) {
fullAddress += m_postalCode + " " + m_city;
} else {
fullAddress += m_city;
}
}
//add country when not empty
if (!m_country.empty()) {
if (!fullAddress.empty()) {
fullAddress += " " + m_country;
} else {
fullAddress = m_country;
}
}
if (!fullAddress.empty()) {
return fullAddress;
}
//when no data on detailed fields, then return free form field
return "";
}
void ContactAddress::clear()
{
m_country = "";
m_countryIsSet = false;
m_region = "";
m_regionIsSet = false;
m_city = "";
m_cityIsSet = false;
m_streetAddress = "";
m_streetAddressIsSet = false;
m_additionalInformation = "";
m_additionalInformationIsSet = false;
m_postalCode = "";
m_postalCodeIsSet = false;
m_label = "";
m_labelIsSet = false;
m_isDefault = false;
m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
}
ContactAddressPtr ContactAddress::clone() const
{
ContactAddressPtr result(new ContactAddress());
result->m_country = m_country;
result->m_countryIsSet = m_countryIsSet;
result->m_region = m_region;
result->m_regionIsSet = m_regionIsSet;
result->m_city = m_city;
result->m_cityIsSet = m_cityIsSet;
result->m_streetAddress = m_streetAddress;
result->m_streetAddressIsSet = m_streetAddressIsSet;
result->m_additionalInformation = m_additionalInformation;
result->m_additionalInformationIsSet = m_additionalInformationIsSet;
result->m_postalCode = m_postalCode;
result->m_postalCodeIsSet = m_postalCodeIsSet;
result->m_isDefault = m_isDefault;
result->m_label = m_label;
result->m_labelIsSet = m_labelIsSet;
result->m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
ContactAddressTypeArray::iterator typeIter;
for(typeIter = m_types->begin(); typeIter != m_types->end(); typeIter++)
{
ContactAddressType addressType = *typeIter;
result->m_types->push_back(addressType);
}
return result;
}
std::string ContactAddress::getLabel() const
{
return m_label;
}
void ContactAddress::setLabel(const std::string &value)
{
m_label = value;
m_labelIsSet = true;
}
bool ContactAddress::getLabelIsSet() const
{
return m_labelIsSet;
}
void ContactAddress::setTypesJSArray(bool value, JSObjectRef initValue)
{
is_typesSetJSArray = value;
m_typesObj = initValue;
}
JSValueRef ContactAddress::getTypesJSArray()
{
return m_typesJsValue;
}
JSObjectRef ContactAddress::getTypesJSObj()
{
return m_typesObj;
}
bool ContactAddress::IsTypesSetJSArray() const
{
return is_typesSetJSArray;
}
void ContactAddress::resetTypesJSObj()
{
if(IsTypesSetJSArray()){
JSContextRef contextRef = getContext();
JSObjectRef tempJSObject = getTypesJSObj();
JSValueUnprotect(contextRef, tempJSObject);
}
is_typesSetJSArray = false;
m_typesObj = NULL;
m_typesJsValue = NULL;
}
void ContactAddress::setContext(JSContextRef contextRef)
{
if(m_context == NULL)
m_context = contextRef;
}
JSContextRef ContactAddress::getContext()
{
return m_context;
}
} // Contact
} // DeviceAPI
|