1 /*
2 	belcard.cpp
3 	Copyright (C) 2015  Belledonne Communications SARL
4 
5 	This program is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 3 of the License, or
8 	(at your option) any later version.
9 
10 	This program is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "belcard/belcard.hpp"
20 #include "belcard/belcard_utils.hpp"
21 #include <belr/parser-impl.cc>
22 
23 using namespace::std;
24 using namespace::belr;
25 using namespace::belcard;
26 
setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> * parser)27 void BelCard::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
28 	parser->setHandler("vcard", make_fn(BelCardGeneric::create<BelCard>))
29 			->setCollector("X-PROPERTY", make_sfn(&BelCard::_addExtendedProperty))
30 			->setCollector("SOURCE", make_sfn(&BelCard::_addSource))
31 			->setCollector("KIND", make_sfn(&BelCard::_setKind))
32 			->setCollector("XML", make_sfn(&BelCard::_addXML))
33 			->setCollector("FN", make_sfn(&BelCard::_setFullName))
34 			->setCollector("N", make_sfn(&BelCard::_setName))
35 			->setCollector("BDAY", make_sfn(&BelCard::_setBirthday))
36 			->setCollector("ANNIVERSARY", make_sfn(&BelCard::_setAnniversary))
37 			->setCollector("GENDER", make_sfn(&BelCard::_setGender))
38 			->setCollector("NICKNAME", make_sfn(&BelCard::_addNickname))
39 			->setCollector("PHOTO", make_sfn(&BelCard::_addPhoto))
40 			->setCollector("ADR", make_sfn(&BelCard::_addAddress))
41 			->setCollector("TEL", make_sfn(&BelCard::_addPhoneNumber))
42 			->setCollector("EMAIL", make_sfn(&BelCard::_addEmail))
43 			->setCollector("IMPP", make_sfn(&BelCard::_addImpp))
44 			->setCollector("LANG", make_sfn(&BelCard::_addLang))
45 			->setCollector("TZ", make_sfn(&BelCard::_addTimezone))
46 			->setCollector("GEO", make_sfn(&BelCard::_addGeo))
47 			->setCollector("TITLE", make_sfn(&BelCard::_addTitle))
48 			->setCollector("ROLE", make_sfn(&BelCard::_addRole))
49 			->setCollector("LOGO", make_sfn(&BelCard::_addLogo))
50 			->setCollector("ORG", make_sfn(&BelCard::_addOrganization))
51 			->setCollector("MEMBER", make_sfn(&BelCard::_addMember))
52 			->setCollector("RELATED", make_sfn(&BelCard::_addRelated))
53 			->setCollector("CATEGORIES", make_sfn(&BelCard::_addCategories))
54 			->setCollector("NOTE", make_sfn(&BelCard::_addNote))
55 			->setCollector("PRODID", make_sfn(&BelCard::_setProductId))
56 			->setCollector("REV", make_sfn(&BelCard::_setRevision))
57 			->setCollector("SOUND", make_sfn(&BelCard::_addSound))
58 			->setCollector("UID", make_sfn(&BelCard::_setUniqueId))
59 			->setCollector("CLIENTPIDMAP", make_sfn(&BelCard::_addClientProductIdMap))
60 			->setCollector("URL", make_sfn(&BelCard::_addURL))
61 			->setCollector("KEY", make_sfn(&BelCard::_addKey))
62 			->setCollector("FBURL", make_sfn(&BelCard::_addFBURL))
63 			->setCollector("CALADRURI", make_sfn(&BelCard::_addCALADRURI))
64 			->setCollector("CALURI", make_sfn(&BelCard::_addCALURI))
65 			->setCollector("BIRTHPLACE", make_sfn(&BelCard::_setBirthPlace))
66 			->setCollector("DEATHDATE", make_sfn(&BelCard::_setDeathDate))
67 			->setCollector("DEATHPLACE", make_sfn(&BelCard::_setDeathPlace));
68 }
69 
BelCard()70 BelCard::BelCard() : BelCardGeneric() {
71 
72 }
73 
setSkipFieldValidation(bool skip)74 void BelCard::setSkipFieldValidation(bool skip) {
75 	_skipFieldValidation = skip;
76 }
77 
getSkipFieldValidation()78 bool BelCard::getSkipFieldValidation() {
79 	return _skipFieldValidation;
80 }
81 
comparePropertiesUsingPrefParam(const shared_ptr<BelCardProperty> & prop1,const shared_ptr<BelCardProperty> & prop2)82 bool comparePropertiesUsingPrefParam(const shared_ptr<BelCardProperty>& prop1, const shared_ptr<BelCardProperty>& prop2) {
83 	shared_ptr<BelCardPrefParam> pref1 = prop1->getPrefParam();
84 	shared_ptr<BelCardPrefParam> pref2 = prop2->getPrefParam();
85 	if ((pref1 == nullptr) && (pref2 == nullptr)) return false;
86 	if (pref2 == nullptr) {
87 		return true;
88 	} else if (pref1 == nullptr) {
89 		return false;
90 	} else {
91 		return pref1->getValue() < pref2->getValue();
92 	}
93 }
94 
95 template <typename T>
set(shared_ptr<T> & p,const shared_ptr<T> & property)96 void BelCard::set(shared_ptr<T> &p, const shared_ptr<T> &property) {
97 	if (p) {
98 		removeProperty(p);
99 	}
100 	p = property;
101 	addProperty(property);
102 }
103 
104 template <typename T>
add(list<shared_ptr<T>> & property_list,const shared_ptr<T> & property)105 void BelCard::add(list<shared_ptr<T>> &property_list, const shared_ptr<T> &property) {
106 	property_list.push_back(property);
107 	property_list.sort(comparePropertiesUsingPrefParam);
108 	addProperty(property);
109 }
110 
111 template <typename T>
remove(list<shared_ptr<T>> & property_list,const shared_ptr<T> & property)112 void BelCard::remove(list<shared_ptr<T>> &property_list, const shared_ptr<T> &property) {
113 	property_list.remove(property);
114 	removeProperty(property);
115 }
116 
_setKind(const shared_ptr<BelCardKind> & kind)117 void BelCard::_setKind(const shared_ptr<BelCardKind> &kind) {
118 	set(_kind, kind);
119 }
setKind(const shared_ptr<BelCardKind> & kind)120 bool BelCard::setKind(const shared_ptr<BelCardKind> &kind) {
121 	if (_skipFieldValidation || BelCardGeneric::isValid(kind)) {
122 		_setKind(kind);
123 		return true;
124 	}
125 	return false;
126 }
getKind() const127 const shared_ptr<BelCardKind> &BelCard::getKind() const {
128 	return _kind;
129 }
130 
_setFullName(const shared_ptr<BelCardFullName> & fn)131 void BelCard::_setFullName(const shared_ptr<BelCardFullName> &fn) {
132 	set(_fn, fn);
133 }
setFullName(const shared_ptr<BelCardFullName> & fn)134 bool BelCard::setFullName(const shared_ptr<BelCardFullName> &fn) {
135 	if (_skipFieldValidation || BelCardGeneric::isValid(fn)) {
136 		_setFullName(fn);
137 		return true;
138 	}
139 	return false;
140 }
getFullName() const141 const shared_ptr<BelCardFullName> &BelCard::getFullName() const {
142 	return _fn;
143 }
144 
_setName(const shared_ptr<BelCardName> & n)145 void BelCard::_setName(const shared_ptr<BelCardName> &n) {
146 	set(_n, n);
147 }
setName(const shared_ptr<BelCardName> & n)148 bool BelCard::setName(const shared_ptr<BelCardName> &n) {
149 	if (_skipFieldValidation || BelCardGeneric::isValid(n)) {
150 		_setName(n);
151 		return true;
152 	}
153 	return false;
154 }
getName() const155 const shared_ptr<BelCardName> &BelCard::getName() const {
156 	return _n;
157 }
158 
_setBirthday(const shared_ptr<BelCardBirthday> & bday)159 void BelCard::_setBirthday(const shared_ptr<BelCardBirthday> &bday) {
160 	set(_bday, bday);
161 }
setBirthday(const shared_ptr<BelCardBirthday> & bday)162 bool BelCard::setBirthday(const shared_ptr<BelCardBirthday> &bday) {
163 	if (_skipFieldValidation || BelCardGeneric::isValid(bday)) {
164 		_setBirthday(bday);
165 		return true;
166 	}
167 	return false;
168 }
getBirthday() const169 const shared_ptr<BelCardBirthday> &BelCard::getBirthday() const {
170 	return _bday;
171 }
172 
_setAnniversary(const shared_ptr<BelCardAnniversary> & anniversary)173 void BelCard::_setAnniversary(const shared_ptr<BelCardAnniversary> &anniversary) {
174 	set(_anniversary, anniversary);
175 }
setAnniversary(const shared_ptr<BelCardAnniversary> & anniversary)176 bool BelCard::setAnniversary(const shared_ptr<BelCardAnniversary> &anniversary) {
177 	if (_skipFieldValidation || BelCardGeneric::isValid(anniversary)) {
178 		_setAnniversary(anniversary);
179 		return true;
180 	}
181 	return false;
182 }
getAnniversary() const183 const shared_ptr<BelCardAnniversary> &BelCard::getAnniversary() const {
184 	return _anniversary;
185 }
186 
_setGender(const shared_ptr<BelCardGender> & gender)187 void BelCard::_setGender(const shared_ptr<BelCardGender> &gender) {
188 	set(_gender, gender);
189 }
setGender(const shared_ptr<BelCardGender> & gender)190 bool BelCard::setGender(const shared_ptr<BelCardGender> &gender) {
191 	if (_skipFieldValidation || BelCardGeneric::isValid(gender)) {
192 		_setGender(gender);
193 		return true;
194 	}
195 	return false;
196 }
getGender() const197 const shared_ptr<BelCardGender> &BelCard::getGender() const {
198 	return _gender;
199 }
200 
_setProductId(const shared_ptr<BelCardProductId> & pid)201 void BelCard::_setProductId(const shared_ptr<BelCardProductId> &pid) {
202 	set(_pid, pid);
203 }
setProductId(const shared_ptr<BelCardProductId> & pid)204 bool BelCard::setProductId(const shared_ptr<BelCardProductId> &pid) {
205 	if (_skipFieldValidation || BelCardGeneric::isValid(pid)) {
206 		_setProductId(pid);
207 		return true;
208 	}
209 	return false;
210 }
getProductId() const211 const shared_ptr<BelCardProductId> &BelCard::getProductId() const {
212 	return _pid;
213 }
214 
_setRevision(const shared_ptr<BelCardRevision> & rev)215 void BelCard::_setRevision(const shared_ptr<BelCardRevision> &rev) {
216 	set(_rev, rev);
217 }
setRevision(const shared_ptr<BelCardRevision> & rev)218 bool BelCard::setRevision(const shared_ptr<BelCardRevision> &rev) {
219 	if (_skipFieldValidation || BelCardGeneric::isValid(rev)) {
220 		_setRevision(rev);
221 		return true;
222 	}
223 	return false;
224 }
getRevision() const225 const shared_ptr<BelCardRevision> &BelCard::getRevision() const {
226 	return _rev;
227 }
228 
_setUniqueId(const shared_ptr<BelCardUniqueId> & uid)229 void BelCard::_setUniqueId(const shared_ptr<BelCardUniqueId> &uid) {
230 	set(_uid, uid);
231 }
setUniqueId(const shared_ptr<BelCardUniqueId> & uid)232 bool BelCard::setUniqueId(const shared_ptr<BelCardUniqueId> &uid) {
233 	if (_skipFieldValidation || BelCardGeneric::isValid(uid)) {
234 		_setUniqueId(uid);
235 		return true;
236 	}
237 	return false;
238 }
getUniqueId() const239 const shared_ptr<BelCardUniqueId> &BelCard::getUniqueId() const {
240 	return _uid;
241 }
242 
_setBirthPlace(const shared_ptr<BelCardBirthPlace> & place)243 void BelCard::_setBirthPlace(const shared_ptr<BelCardBirthPlace> &place) {
244 	set(_bplace, place);
245 }
setBirthPlace(const shared_ptr<BelCardBirthPlace> & place)246 bool BelCard::setBirthPlace(const shared_ptr<BelCardBirthPlace> &place) {
247 	if (_skipFieldValidation || BelCardGeneric::isValid(place)) {
248 		_setBirthPlace(place);
249 		return true;
250 	}
251 	return false;
252 }
getBirthPlace() const253 const shared_ptr<BelCardBirthPlace> &BelCard::getBirthPlace() const {
254 	return _bplace;
255 }
256 
_setDeathPlace(const shared_ptr<BelCardDeathPlace> & place)257 void BelCard::_setDeathPlace(const shared_ptr<BelCardDeathPlace> &place) {
258 	set(_dplace, place);
259 }
setDeathPlace(const shared_ptr<BelCardDeathPlace> & place)260 bool BelCard::setDeathPlace(const shared_ptr<BelCardDeathPlace> &place) {
261 	if (_skipFieldValidation || BelCardGeneric::isValid(place)) {
262 		_setDeathPlace(place);
263 		return true;
264 	}
265 	return false;
266 }
getDeathPlace() const267 const shared_ptr<BelCardDeathPlace> &BelCard::getDeathPlace() const {
268 	return _dplace;
269 }
270 
_setDeathDate(const shared_ptr<BelCardDeathDate> & date)271 void BelCard::_setDeathDate(const shared_ptr<BelCardDeathDate> &date) {
272 	set(_ddate, date);
273 }
setDeathDate(const shared_ptr<BelCardDeathDate> & date)274 bool BelCard::setDeathDate(const shared_ptr<BelCardDeathDate> &date) {
275 	if (_skipFieldValidation || BelCardGeneric::isValid(date)) {
276 		_setDeathDate(date);
277 		return true;
278 	}
279 	return false;
280 }
getDeathDate() const281 const shared_ptr<BelCardDeathDate> &BelCard::getDeathDate() const {
282 	return _ddate;
283 }
284 
_addNickname(const shared_ptr<BelCardNickname> & nickname)285 void BelCard::_addNickname(const shared_ptr<BelCardNickname> &nickname) {
286 	add(_nicknames, nickname);
287 }
addNickname(const shared_ptr<BelCardNickname> & nickname)288 bool BelCard::addNickname(const shared_ptr<BelCardNickname> &nickname) {
289 	if (_skipFieldValidation || BelCardGeneric::isValid(nickname)) {
290 		_addNickname(nickname);
291 		return true;
292 	}
293 	return false;
294 }
removeNickname(const shared_ptr<BelCardNickname> & nickname)295 void BelCard::removeNickname(const shared_ptr<BelCardNickname> &nickname) {
296 	remove(_nicknames, nickname);
297 }
getNicknames() const298 const list<shared_ptr<BelCardNickname>> &BelCard::getNicknames() const {
299 	return _nicknames;
300 }
301 
_addPhoto(const shared_ptr<BelCardPhoto> & photo)302 void BelCard::_addPhoto(const shared_ptr<BelCardPhoto> &photo) {
303 	add(_photos, photo);
304 }
addPhoto(const shared_ptr<BelCardPhoto> & photo)305 bool BelCard::addPhoto(const shared_ptr<BelCardPhoto> &photo) {
306 	if (_skipFieldValidation || BelCardGeneric::isValid(photo)) {
307 		_addPhoto(photo);
308 		return true;
309 	}
310 	return false;
311 }
removePhoto(const shared_ptr<BelCardPhoto> & photo)312 void BelCard::removePhoto(const shared_ptr<BelCardPhoto> &photo) {
313 	remove(_photos, photo);
314 }
getPhotos() const315 const list<shared_ptr<BelCardPhoto>> &BelCard::getPhotos() const {
316 	return _photos;
317 }
318 
_addAddress(const shared_ptr<BelCardAddress> & addr)319 void BelCard::_addAddress(const shared_ptr<BelCardAddress> &addr) {
320 	add(_addr, addr);
321 }
addAddress(const shared_ptr<BelCardAddress> & addr)322 bool BelCard::addAddress(const shared_ptr<BelCardAddress> &addr) {
323 	if (_skipFieldValidation || BelCardGeneric::isValid(addr)) {
324 		_addAddress(addr);
325 		return true;
326 	}
327 	return false;
328 }
removeAddress(const shared_ptr<BelCardAddress> & addr)329 void BelCard::removeAddress(const shared_ptr<BelCardAddress> &addr) {
330 	remove(_addr, addr);
331 }
getAddresses() const332 const list<shared_ptr<BelCardAddress>> &BelCard::getAddresses() const {
333 	return _addr;
334 }
335 
_addPhoneNumber(const shared_ptr<BelCardPhoneNumber> & tel)336 void BelCard::_addPhoneNumber(const shared_ptr<BelCardPhoneNumber> &tel) {
337 	add(_tel, tel);
338 }
addPhoneNumber(const shared_ptr<BelCardPhoneNumber> & tel)339 bool BelCard::addPhoneNumber(const shared_ptr<BelCardPhoneNumber> &tel) {
340 	if (_skipFieldValidation || BelCardGeneric::isValid(tel)) {
341 		_addPhoneNumber(tel);
342 		return true;
343 	}
344 	return false;
345 }
removePhoneNumber(const shared_ptr<BelCardPhoneNumber> & tel)346 void BelCard::removePhoneNumber(const shared_ptr<BelCardPhoneNumber> &tel) {
347 	remove(_tel, tel);
348 }
getPhoneNumbers() const349 const list<shared_ptr<BelCardPhoneNumber>> &BelCard::getPhoneNumbers() const {
350 	return _tel;
351 }
352 
_addEmail(const shared_ptr<BelCardEmail> & email)353 void BelCard::_addEmail(const shared_ptr<BelCardEmail> &email) {
354 	add(_emails, email);
355 }
addEmail(const shared_ptr<BelCardEmail> & email)356 bool BelCard::addEmail(const shared_ptr<BelCardEmail> &email) {
357 	if (_skipFieldValidation || BelCardGeneric::isValid(email)) {
358 		_addEmail(email);
359 		return true;
360 	}
361 	return false;
362 }
removeEmail(const shared_ptr<BelCardEmail> & email)363 void BelCard::removeEmail(const shared_ptr<BelCardEmail> &email) {
364 	remove(_emails, email);
365 }
getEmails() const366 const list<shared_ptr<BelCardEmail>> &BelCard::getEmails() const {
367 	return _emails;
368 }
369 
_addImpp(const shared_ptr<BelCardImpp> & impp)370 void BelCard::_addImpp(const shared_ptr<BelCardImpp> &impp) {
371 	add(_impp, impp);
372 }
addImpp(const shared_ptr<BelCardImpp> & impp)373 bool BelCard::addImpp(const shared_ptr<BelCardImpp> &impp) {
374 	if (_skipFieldValidation || BelCardGeneric::isValid(impp)) {
375 		_addImpp(impp);
376 		return true;
377 	}
378 	return false;
379 }
removeImpp(const shared_ptr<BelCardImpp> & impp)380 void BelCard::removeImpp(const shared_ptr<BelCardImpp> &impp) {
381 	remove(_impp, impp);
382 }
getImpp() const383 const list<shared_ptr<BelCardImpp>> &BelCard::getImpp() const {
384 	return _impp;
385 }
386 
_addLang(const shared_ptr<BelCardLang> & lang)387 void BelCard::_addLang(const shared_ptr<BelCardLang> &lang) {
388 	add(_langs, lang);
389 }
addLang(const shared_ptr<BelCardLang> & lang)390 bool BelCard::addLang(const shared_ptr<BelCardLang> &lang) {
391 	if (_skipFieldValidation || BelCardGeneric::isValid(lang)) {
392 		_addLang(lang);
393 		return true;
394 	}
395 	return false;
396 }
removeLang(const shared_ptr<BelCardLang> & lang)397 void BelCard::removeLang(const shared_ptr<BelCardLang> &lang) {
398 	remove(_langs, lang);
399 }
getLangs() const400 const list<shared_ptr<BelCardLang>> &BelCard::getLangs() const {
401 	return _langs;
402 }
403 
_addSource(const shared_ptr<BelCardSource> & source)404 void BelCard::_addSource(const shared_ptr<BelCardSource> &source) {
405 	add(_sources, source);
406 }
addSource(const shared_ptr<BelCardSource> & source)407 bool BelCard::addSource(const shared_ptr<BelCardSource> &source) {
408 	if (_skipFieldValidation || BelCardGeneric::isValid(source)) {
409 		_addSource(source);
410 		return true;
411 	}
412 	return false;
413 }
removeSource(const shared_ptr<BelCardSource> & source)414 void BelCard::removeSource(const shared_ptr<BelCardSource> &source) {
415 	remove(_sources, source);
416 }
getSource() const417 const list<shared_ptr<BelCardSource>> &BelCard::getSource() const {
418 	return _sources;
419 }
420 
_addXML(const shared_ptr<BelCardXML> & xml)421 void BelCard::_addXML(const shared_ptr<BelCardXML> &xml) {
422 	add(_xml, xml);
423 }
addXML(const shared_ptr<BelCardXML> & xml)424 bool BelCard::addXML(const shared_ptr<BelCardXML> &xml) {
425 	if (_skipFieldValidation || BelCardGeneric::isValid(xml)) {
426 		_addXML(xml);
427 		return true;
428 	}
429 	return false;
430 }
removeXML(const shared_ptr<BelCardXML> & xml)431 void BelCard::removeXML(const shared_ptr<BelCardXML> &xml) {
432 	remove(_xml, xml);
433 }
getXML() const434 const list<shared_ptr<BelCardXML>> &BelCard::getXML() const {
435 	return _xml;
436 }
437 
_addTimezone(const shared_ptr<BelCardTimezone> & tz)438 void BelCard::_addTimezone(const shared_ptr<BelCardTimezone> &tz) {
439 	add(_timezones, tz);
440 }
addTimezone(const shared_ptr<BelCardTimezone> & tz)441 bool BelCard::addTimezone(const shared_ptr<BelCardTimezone> &tz) {
442 	if (_skipFieldValidation || BelCardGeneric::isValid(tz)) {
443 		_addTimezone(tz);
444 		return true;
445 	}
446 	return false;
447 }
removeTimezone(const shared_ptr<BelCardTimezone> & tz)448 void BelCard::removeTimezone(const shared_ptr<BelCardTimezone> &tz) {
449 	remove(_timezones, tz);
450 }
getTimezones() const451 const list<shared_ptr<BelCardTimezone>> &BelCard::getTimezones() const {
452 	return _timezones;
453 }
454 
_addGeo(const shared_ptr<BelCardGeo> & geo)455 void BelCard::_addGeo(const shared_ptr<BelCardGeo> &geo) {
456 	add(_geos, geo);
457 }
addGeo(const shared_ptr<BelCardGeo> & geo)458 bool BelCard::addGeo(const shared_ptr<BelCardGeo> &geo) {
459 	if (_skipFieldValidation || BelCardGeneric::isValid(geo)) {
460 		_addGeo(geo);
461 		return true;
462 	}
463 	return false;
464 }
removeGeo(const shared_ptr<BelCardGeo> & geo)465 void BelCard::removeGeo(const shared_ptr<BelCardGeo> &geo) {
466 	remove(_geos, geo);
467 }
getGeos() const468 const list<shared_ptr<BelCardGeo>> &BelCard::getGeos() const {
469 	return _geos;
470 }
471 
_addTitle(const shared_ptr<BelCardTitle> & title)472 void BelCard::_addTitle(const shared_ptr<BelCardTitle> &title) {
473 	add(_titles, title);
474 }
addTitle(const shared_ptr<BelCardTitle> & title)475 bool BelCard::addTitle(const shared_ptr<BelCardTitle> &title) {
476 	if (_skipFieldValidation || BelCardGeneric::isValid(title)) {
477 		_addTitle(title);
478 		return true;
479 	}
480 	return false;
481 }
removeTitle(const shared_ptr<BelCardTitle> & title)482 void BelCard::removeTitle(const shared_ptr<BelCardTitle> &title) {
483 	remove(_titles, title);
484 }
getTitles() const485 const list<shared_ptr<BelCardTitle>> &BelCard::getTitles() const {
486 	return _titles;
487 }
488 
_addRole(const shared_ptr<BelCardRole> & role)489 void BelCard::_addRole(const shared_ptr<BelCardRole> &role) {
490 	add(_roles, role);
491 }
addRole(const shared_ptr<BelCardRole> & role)492 bool BelCard::addRole(const shared_ptr<BelCardRole> &role) {
493 	if (_skipFieldValidation || BelCardGeneric::isValid(role)) {
494 		_addRole(role);
495 		return true;
496 	}
497 	return false;
498 }
removeRole(const shared_ptr<BelCardRole> & role)499 void BelCard::removeRole(const shared_ptr<BelCardRole> &role) {
500 	remove(_roles, role);
501 }
getRoles() const502 const list<shared_ptr<BelCardRole>> &BelCard::getRoles() const {
503 	return _roles;
504 }
505 
_addLogo(const shared_ptr<BelCardLogo> & logo)506 void BelCard::_addLogo(const shared_ptr<BelCardLogo> &logo) {
507 	add(_logos, logo);
508 }
addLogo(const shared_ptr<BelCardLogo> & logo)509 bool BelCard::addLogo(const shared_ptr<BelCardLogo> &logo) {
510 	if (_skipFieldValidation || BelCardGeneric::isValid(logo)) {
511 		_addLogo(logo);
512 		return true;
513 	}
514 	return false;
515 }
removeLogo(const shared_ptr<BelCardLogo> & logo)516 void BelCard::removeLogo(const shared_ptr<BelCardLogo> &logo) {
517 	remove(_logos, logo);
518 }
getLogos() const519 const list<shared_ptr<BelCardLogo>> &BelCard::getLogos() const {
520 	return _logos;
521 }
522 
_addOrganization(const shared_ptr<BelCardOrganization> & org)523 void BelCard::_addOrganization(const shared_ptr<BelCardOrganization> &org) {
524 	add(_organizations, org);
525 }
addOrganization(const shared_ptr<BelCardOrganization> & org)526 bool BelCard::addOrganization(const shared_ptr<BelCardOrganization> &org) {
527 	if (_skipFieldValidation || BelCardGeneric::isValid(org)) {
528 		_addOrganization(org);
529 		return true;
530 	}
531 	return false;
532 }
removeOrganization(const shared_ptr<BelCardOrganization> & org)533 void BelCard::removeOrganization(const shared_ptr<BelCardOrganization> &org) {
534 	remove(_organizations, org);
535 }
getOrganizations() const536 const list<shared_ptr<BelCardOrganization>> &BelCard::getOrganizations() const {
537 	return _organizations;
538 }
539 
_addMember(const shared_ptr<BelCardMember> & member)540 void BelCard::_addMember(const shared_ptr<BelCardMember> &member) {
541 	add(_members, member);
542 }
addMember(const shared_ptr<BelCardMember> & member)543 bool BelCard::addMember(const shared_ptr<BelCardMember> &member) {
544 	if (_skipFieldValidation || BelCardGeneric::isValid(member)) {
545 		_addMember(member);
546 		return true;
547 	}
548 	return false;
549 }
removeMember(const shared_ptr<BelCardMember> & member)550 void BelCard::removeMember(const shared_ptr<BelCardMember> &member) {
551 	remove(_members, member);
552 }
getMembers() const553 const list<shared_ptr<BelCardMember>> &BelCard::getMembers() const {
554 	return _members;
555 }
556 
_addRelated(const shared_ptr<BelCardRelated> & related)557 void BelCard::_addRelated(const shared_ptr<BelCardRelated> &related) {
558 	add(_related, related);
559 }
addRelated(const shared_ptr<BelCardRelated> & related)560 bool BelCard::addRelated(const shared_ptr<BelCardRelated> &related) {
561 	if (_skipFieldValidation || BelCardGeneric::isValid(related)) {
562 		_addRelated(related);
563 		return true;
564 	}
565 	return false;
566 }
removeRelated(const shared_ptr<BelCardRelated> & related)567 void BelCard::removeRelated(const shared_ptr<BelCardRelated> &related) {
568 	remove(_related, related);
569 }
getRelated() const570 const list<shared_ptr<BelCardRelated>> &BelCard::getRelated() const {
571 	return _related;
572 }
573 
_addCategories(const shared_ptr<BelCardCategories> & categories)574 void BelCard::_addCategories(const shared_ptr<BelCardCategories> &categories) {
575 	add(_categories, categories);
576 }
addCategories(const shared_ptr<BelCardCategories> & categories)577 bool BelCard::addCategories(const shared_ptr<BelCardCategories> &categories) {
578 	if (_skipFieldValidation || BelCardGeneric::isValid(categories)) {
579 		_addCategories(categories);
580 		return true;
581 	}
582 	return false;
583 }
removeCategories(const shared_ptr<BelCardCategories> & categories)584 void BelCard::removeCategories(const shared_ptr<BelCardCategories> &categories) {
585 	remove(_categories, categories);
586 }
getCategories() const587 const list<shared_ptr<BelCardCategories>> &BelCard::getCategories() const {
588 	return _categories;
589 }
590 
_addNote(const shared_ptr<BelCardNote> & note)591 void BelCard::_addNote(const shared_ptr<BelCardNote> &note) {
592 	add(_notes, note);
593 }
addNote(const shared_ptr<BelCardNote> & note)594 bool BelCard::addNote(const shared_ptr<BelCardNote> &note) {
595 	if (_skipFieldValidation || BelCardGeneric::isValid(note)) {
596 		_addNote(note);
597 		return true;
598 	}
599 	return false;
600 }
removeNote(const shared_ptr<BelCardNote> & note)601 void BelCard::removeNote(const shared_ptr<BelCardNote> &note) {
602 	remove(_notes, note);
603 }
getNotes() const604 const list<shared_ptr<BelCardNote>> &BelCard::getNotes() const {
605 	return _notes;
606 }
607 
_addSound(const shared_ptr<BelCardSound> & sound)608 void BelCard::_addSound(const shared_ptr<BelCardSound> &sound) {
609 	add(_sounds, sound);
610 }
addSound(const shared_ptr<BelCardSound> & sound)611 bool BelCard::addSound(const shared_ptr<BelCardSound> &sound) {
612 	if (_skipFieldValidation || BelCardGeneric::isValid(sound)) {
613 		_addSound(sound);
614 		return true;
615 	}
616 	return false;
617 }
removeSound(const shared_ptr<BelCardSound> & sound)618 void BelCard::removeSound(const shared_ptr<BelCardSound> &sound) {
619 	remove(_sounds, sound);
620 }
getSounds() const621 const list<shared_ptr<BelCardSound>> &BelCard::getSounds() const {
622 	return _sounds;
623 }
624 
_addClientProductIdMap(const shared_ptr<BelCardClientProductIdMap> & clientpidmap)625 void BelCard::_addClientProductIdMap(const shared_ptr<BelCardClientProductIdMap> &clientpidmap) {
626 	add(_clientpidmaps, clientpidmap);
627 }
addClientProductIdMap(const shared_ptr<BelCardClientProductIdMap> & clientpidmap)628 bool BelCard::addClientProductIdMap(const shared_ptr<BelCardClientProductIdMap> &clientpidmap) {
629 	if (_skipFieldValidation || BelCardGeneric::isValid(clientpidmap)) {
630 		_addClientProductIdMap(clientpidmap);
631 		return true;
632 	}
633 	return false;
634 }
removeClientProductIdMap(const shared_ptr<BelCardClientProductIdMap> & clientpidmap)635 void BelCard::removeClientProductIdMap(const shared_ptr<BelCardClientProductIdMap> &clientpidmap) {
636 	remove(_clientpidmaps, clientpidmap);
637 }
getClientProductIdMaps() const638 const list<shared_ptr<BelCardClientProductIdMap>> &BelCard::getClientProductIdMaps() const {
639 	return _clientpidmaps;
640 }
641 
_addURL(const shared_ptr<BelCardURL> & url)642 void BelCard::_addURL(const shared_ptr<BelCardURL> &url) {
643 	add(_urls, url);
644 }
addURL(const shared_ptr<BelCardURL> & url)645 bool BelCard::addURL(const shared_ptr<BelCardURL> &url) {
646 	if (_skipFieldValidation || BelCardGeneric::isValid(url)) {
647 		_addURL(url);
648 		return true;
649 	}
650 	return false;
651 }
removeURL(const shared_ptr<BelCardURL> & url)652 void BelCard::removeURL(const shared_ptr<BelCardURL> &url) {
653 	remove(_urls, url);
654 }
getURLs() const655 const list<shared_ptr<BelCardURL>> &BelCard::getURLs() const {
656 	return _urls;
657 }
658 
_addKey(const shared_ptr<BelCardKey> & key)659 void BelCard::_addKey(const shared_ptr<BelCardKey> &key) {
660 	add(_keys, key);
661 }
addKey(const shared_ptr<BelCardKey> & key)662 bool BelCard::addKey(const shared_ptr<BelCardKey> &key) {
663 	if (_skipFieldValidation || BelCardGeneric::isValid(key)) {
664 		_addKey(key);
665 		return true;
666 	}
667 	return false;
668 }
removeKey(const shared_ptr<BelCardKey> & key)669 void BelCard::removeKey(const shared_ptr<BelCardKey> &key) {
670 	remove(_keys, key);
671 }
getKeys() const672 const list<shared_ptr<BelCardKey>> &BelCard::getKeys() const {
673 	return _keys;
674 }
675 
_addFBURL(const shared_ptr<BelCardFBURL> & fburl)676 void BelCard::_addFBURL(const shared_ptr<BelCardFBURL> &fburl) {
677 	add(_fburls, fburl);
678 }
addFBURL(const shared_ptr<BelCardFBURL> & fburl)679 bool BelCard::addFBURL(const shared_ptr<BelCardFBURL> &fburl) {
680 	if (_skipFieldValidation || BelCardGeneric::isValid(fburl)) {
681 		_addFBURL(fburl);
682 		return true;
683 	}
684 	return false;
685 }
removeFBURL(const shared_ptr<BelCardFBURL> & fburl)686 void BelCard::removeFBURL(const shared_ptr<BelCardFBURL> &fburl) {
687 	remove(_fburls, fburl);
688 }
getFBURLs() const689 const list<shared_ptr<BelCardFBURL>> &BelCard::getFBURLs() const {
690 	return _fburls;
691 }
692 
_addCALADRURI(const shared_ptr<BelCardCALADRURI> & caladruri)693 void BelCard::_addCALADRURI(const shared_ptr<BelCardCALADRURI> &caladruri) {
694 	add(_caladruris, caladruri);
695 }
addCALADRURI(const shared_ptr<BelCardCALADRURI> & caladruri)696 bool BelCard::addCALADRURI(const shared_ptr<BelCardCALADRURI> &caladruri) {
697 	if (_skipFieldValidation || BelCardGeneric::isValid(caladruri)) {
698 		_addCALADRURI(caladruri);
699 		return true;
700 	}
701 	return false;
702 }
removeCALADRURI(const shared_ptr<BelCardCALADRURI> & caladruri)703 void BelCard::removeCALADRURI(const shared_ptr<BelCardCALADRURI> &caladruri) {
704 	remove(_caladruris, caladruri);
705 }
getCALADRURIs() const706 const list<shared_ptr<BelCardCALADRURI>> &BelCard::getCALADRURIs() const {
707 	return _caladruris;
708 }
709 
_addCALURI(const shared_ptr<BelCardCALURI> & caluri)710 void BelCard::_addCALURI(const shared_ptr<BelCardCALURI> &caluri) {
711 	add(_caluris, caluri);
712 }
addCALURI(const shared_ptr<BelCardCALURI> & caluri)713 bool BelCard::addCALURI(const shared_ptr<BelCardCALURI> &caluri) {
714 	if (_skipFieldValidation || BelCardGeneric::isValid(caluri)) {
715 		_addCALURI(caluri);
716 		return true;
717 	}
718 	return false;
719 }
removeCALURI(const shared_ptr<BelCardCALURI> & caluri)720 void BelCard::removeCALURI(const shared_ptr<BelCardCALURI> &caluri) {
721 	remove(_caluris, caluri);
722 }
getCALURIs() const723 const list<shared_ptr<BelCardCALURI>> &BelCard::getCALURIs() const {
724 	return _caluris;
725 }
726 
_addExtendedProperty(const shared_ptr<BelCardProperty> & property)727 void BelCard::_addExtendedProperty(const shared_ptr<BelCardProperty> &property) {
728 	add(_extended_properties, property);
729 }
addExtendedProperty(const shared_ptr<BelCardProperty> & property)730 bool BelCard::addExtendedProperty(const shared_ptr<BelCardProperty> &property) {
731 	if (_skipFieldValidation || BelCardGeneric::isValid(property)) {
732 		_addExtendedProperty(property);
733 		return true;
734 	}
735 	return false;
736 }
removeExtendedProperty(const shared_ptr<BelCardProperty> & property)737 void BelCard::removeExtendedProperty(const shared_ptr<BelCardProperty> &property) {
738 	remove(_extended_properties, property);
739 }
getExtendedProperties() const740 const list<shared_ptr<BelCardProperty>> &BelCard::getExtendedProperties() const {
741 	return _extended_properties;
742 }
743 
addProperty(const shared_ptr<BelCardProperty> & property)744 void BelCard::addProperty(const shared_ptr<BelCardProperty> &property) {
745 	_properties.push_back(property);
746 }
removeProperty(const shared_ptr<BelCardProperty> & property)747 void BelCard::removeProperty(const shared_ptr<BelCardProperty> &property) {
748 	_properties.remove(property);
749 }
getProperties() const750 const list<shared_ptr<BelCardProperty>> &BelCard::getProperties() const {
751 	return _properties;
752 }
753 
serialize(ostream & output) const754 void BelCard::serialize(ostream& output) const {
755 	output << "BEGIN:VCARD\r\nVERSION:4.0\r\n";
756 	for (auto it = getProperties().begin(); it != getProperties().end(); ++it) {
757 		output << (**it);
758 	}
759 	output << "END:VCARD\r\n";
760 }
761 
toFoldedString()762 string& BelCard::toFoldedString() {
763 	string temp = toString();
764 	_folded_string = belcard_fold(temp);
765 	return _folded_string;
766 }
767 
assertRFCCompliance() const768 bool BelCard::assertRFCCompliance() const {
769 	if (!_fn) {
770 		return false;
771 	}
772 
773 	return true;
774 }
775 
setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> * parser)776 void BelCardList::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
777 	parser->setHandler("vcard-list", make_fn(BelCardGeneric::create<BelCardList>))
778 			->setCollector("vcard", make_sfn(&BelCardList::addCard));
779 }
780 
BelCardList()781 BelCardList::BelCardList() : BelCardGeneric() {
782 
783 }
784 
addCard(const shared_ptr<BelCard> & vcard)785 void BelCardList::addCard(const shared_ptr<BelCard> &vcard) {
786 	_vCards.push_back(vcard);
787 }
788 
getCards() const789 const list<shared_ptr<BelCard>> &BelCardList::getCards() const {
790 	return _vCards;
791 }
792 
serialize(ostream & output) const793 void BelCardList::serialize(ostream &output) const {
794 	for (auto it = getCards().begin(); it != getCards().end(); ++it) {
795 		output << (*it)->toFoldedString();
796 	}
797 }
798