belcard_identification.cpp 8.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
	belcard_identification.cpp
	Copyright (C) 2015  Belledonne Communications SARL

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

19
#include "belcard/belcard.hpp"
20

21 22 23 24 25

using namespace::std;
using namespace::belr;
using namespace::belcard;

Sylvain Berfini's avatar
Sylvain Berfini committed
26
shared_ptr<BelCardFullName> BelCardFullName::parse(const string& input) {
Sylvain Berfini's avatar
Sylvain Berfini committed
27
	return BelCardProperty::parseProperty<BelCardFullName>("FN", input);
28 29
}

Sylvain Berfini's avatar
Sylvain Berfini committed
30
void BelCardFullName::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
Sylvain Berfini's avatar
Sylvain Berfini committed
31
	parser->setHandler("FN", make_fn(BelCardGeneric::create<BelCardFullName>))
32 33 34 35 36 37 38 39 40
			->setCollector("group", make_sfn(&BelCardProperty::setGroup))
			->setCollector("any-param", make_sfn(&BelCardProperty::addParam))
			->setCollector("VALUE-param", make_sfn(&BelCardProperty::setValueParam))
			->setCollector("TYPE-param", make_sfn(&BelCardProperty::setTypeParam))
			->setCollector("LANGUAGE-param", make_sfn(&BelCardProperty::setLanguageParam))
			->setCollector("ALTID-param", make_sfn(&BelCardProperty::setAlternativeIdParam))
			->setCollector("PID-param", make_sfn(&BelCardProperty::setParamIdParam))
			->setCollector("PREF-param", make_sfn(&BelCardProperty::setPrefParam))
			->setCollector("FN-value", make_sfn(&BelCardProperty::setValue));
41 42
}

Sylvain Berfini's avatar
Sylvain Berfini committed
43
BelCardFullName::BelCardFullName() : BelCardProperty() {
44 45 46
	setName("FN");
}

Sylvain Berfini's avatar
Sylvain Berfini committed
47
shared_ptr<BelCardName> BelCardName::parse(const string& input) {
Sylvain Berfini's avatar
Sylvain Berfini committed
48
	return BelCardProperty::parseProperty<BelCardName>("N", input);
49 50
}

Sylvain Berfini's avatar
Sylvain Berfini committed
51
void BelCardName::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
Sylvain Berfini's avatar
Sylvain Berfini committed
52
	parser->setHandler("N", make_fn(BelCardGeneric::create<BelCardName>))
53 54 55 56 57 58
			->setCollector("group", make_sfn(&BelCardProperty::setGroup))
			->setCollector("any-param", make_sfn(&BelCardProperty::addParam))
			->setCollector("VALUE-param", make_sfn(&BelCardProperty::setValueParam))
			->setCollector("SORT-AS-param", make_sfn(&BelCardProperty::setSortAsParam))
			->setCollector("LANGUAGE-param", make_sfn(&BelCardProperty::setLanguageParam))
			->setCollector("ALTID-param", make_sfn(&BelCardProperty::setAlternativeIdParam))
Sylvain Berfini's avatar
Sylvain Berfini committed
59 60 61 62 63
			->setCollector("N-fn", make_sfn(&BelCardName::setFamilyName))
			->setCollector("N-gn", make_sfn(&BelCardName::setGivenName))
			->setCollector("N-an", make_sfn(&BelCardName::setAdditionalName))
			->setCollector("N-prefixes", make_sfn(&BelCardName::setPrefixes))
			->setCollector("N-suffixes", make_sfn(&BelCardName::setSuffixes));
64 65
}

Sylvain Berfini's avatar
Sylvain Berfini committed
66
BelCardName::BelCardName() : BelCardProperty() {
67 68 69
	setName("N");
}

Sylvain Berfini's avatar
Sylvain Berfini committed
70
void BelCardName::setFamilyName(const string &value) {
71 72
	_family_name = value;
}
Sylvain Berfini's avatar
Sylvain Berfini committed
73
const string &BelCardName::getFamilyName() const {
74 75 76
	return _family_name;
}

Sylvain Berfini's avatar
Sylvain Berfini committed
77
void BelCardName::setGivenName(const string &value) {
78 79
	_given_name = value;
}
Sylvain Berfini's avatar
Sylvain Berfini committed
80
const string &BelCardName::getGivenName() const {
81 82 83
	return _given_name;
}

Sylvain Berfini's avatar
Sylvain Berfini committed
84
void BelCardName::setAdditionalName(const string &value) {
85 86
	_additional_name = value;
}
Sylvain Berfini's avatar
Sylvain Berfini committed
87
const string &BelCardName::getAdditionalName() const {
88 89 90
	return _additional_name;
}

Sylvain Berfini's avatar
Sylvain Berfini committed
91
void BelCardName::setPrefixes(const string &value) {
92 93
	_prefixes = value;
}
Sylvain Berfini's avatar
Sylvain Berfini committed
94
const string &BelCardName::getPrefixes() const {
95 96 97
	return _prefixes;
}

Sylvain Berfini's avatar
Sylvain Berfini committed
98
void BelCardName::setSuffixes(const string &value) {
99 100
	_suffixes = value;
}
Sylvain Berfini's avatar
Sylvain Berfini committed
101
const string &BelCardName::getSuffixes() const {
102 103 104
	return _suffixes;
}

105 106 107 108 109 110 111 112 113 114 115 116
void BelCardName::serialize(ostream& output) const {
	if (getGroup().length() > 0) {
		output << getGroup() << ".";
	}
	
	output << getName();
	for (auto it = getParams().begin(); it != getParams().end(); ++it) {
		output << ";" << (**it); 
	}
	output << ":" << getFamilyName() + ";" + getGivenName() + ";" + getAdditionalName() + ";" + getPrefixes() + ";" + getSuffixes() << "\r\n";
}

117
shared_ptr<BelCardNickname> BelCardNickname::parse(const string& input) {
Sylvain Berfini's avatar
Sylvain Berfini committed
118
	return BelCardProperty::parseProperty<BelCardNickname>("NICKNAME", input);
119 120 121
}

void BelCardNickname::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
Sylvain Berfini's avatar
Sylvain Berfini committed
122
	parser->setHandler("NICKNAME", make_fn(BelCardGeneric::create<BelCardNickname>))
123 124 125 126 127 128 129 130 131
			->setCollector("group", make_sfn(&BelCardProperty::setGroup))
			->setCollector("any-param", make_sfn(&BelCardProperty::addParam))
			->setCollector("VALUE-param", make_sfn(&BelCardProperty::setValueParam))
			->setCollector("TYPE-param", make_sfn(&BelCardProperty::setTypeParam))
			->setCollector("LANGUAGE-param", make_sfn(&BelCardProperty::setLanguageParam))
			->setCollector("ALTID-param", make_sfn(&BelCardProperty::setAlternativeIdParam))
			->setCollector("PID-param", make_sfn(&BelCardProperty::setParamIdParam))
			->setCollector("PREF-param", make_sfn(&BelCardProperty::setPrefParam))
			->setCollector("NICKNAME-value", make_sfn(&BelCardProperty::setValue));
132 133 134 135 136 137 138
}

BelCardNickname::BelCardNickname() : BelCardProperty() {
	setName("NICKNAME");
}

shared_ptr<BelCardBirthday> BelCardBirthday::parse(const string& input) {
Sylvain Berfini's avatar
Sylvain Berfini committed
139
	return BelCardProperty::parseProperty<BelCardBirthday>("BDAY", input);
140 141 142
}

void BelCardBirthday::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
Sylvain Berfini's avatar
Sylvain Berfini committed
143
	parser->setHandler("BDAY", make_fn(BelCardGeneric::create<BelCardBirthday>))
144 145 146 147 148 149 150
			->setCollector("group", make_sfn(&BelCardProperty::setGroup))
			->setCollector("any-param", make_sfn(&BelCardProperty::addParam))
			->setCollector("VALUE-param", make_sfn(&BelCardProperty::setValueParam))
			->setCollector("LANGUAGE-param", make_sfn(&BelCardProperty::setLanguageParam))
			->setCollector("ALTID-param", make_sfn(&BelCardProperty::setAlternativeIdParam))
			->setCollector("CALSCALE-param", make_sfn(&BelCardProperty::setCALSCALEParam))
			->setCollector("BDAY-value", make_sfn(&BelCardProperty::setValue));
151 152 153 154 155 156 157
}

BelCardBirthday::BelCardBirthday() : BelCardProperty() {
	setName("BDAY");
}

shared_ptr<BelCardAnniversary> BelCardAnniversary::parse(const string& input) {
Sylvain Berfini's avatar
Sylvain Berfini committed
158
	return BelCardProperty::parseProperty<BelCardAnniversary>("ANNIVERSARY", input);
159 160 161
}

void BelCardAnniversary::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
Sylvain Berfini's avatar
Sylvain Berfini committed
162
	parser->setHandler("ANNIVERSARY", make_fn(BelCardGeneric::create<BelCardAnniversary>))
163 164 165 166 167 168
			->setCollector("group", make_sfn(&BelCardProperty::setGroup))
			->setCollector("any-param", make_sfn(&BelCardProperty::addParam))
			->setCollector("VALUE-param", make_sfn(&BelCardProperty::setValueParam))
			->setCollector("ALTID-param", make_sfn(&BelCardProperty::setAlternativeIdParam))
			->setCollector("CALSCALE-param", make_sfn(&BelCardProperty::setCALSCALEParam))
			->setCollector("ANNIVERSARY-value", make_sfn(&BelCardProperty::setValue));
169 170 171 172 173 174 175
}

BelCardAnniversary::BelCardAnniversary() : BelCardProperty() {
	setName("ANNIVERSARY");
}

shared_ptr<BelCardGender> BelCardGender::parse(const string& input) {
Sylvain Berfini's avatar
Sylvain Berfini committed
176
	return BelCardProperty::parseProperty<BelCardGender>("GENDER", input);
177 178 179
}

void BelCardGender::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
Sylvain Berfini's avatar
Sylvain Berfini committed
180
	parser->setHandler("GENDER", make_fn(BelCardGeneric::create<BelCardGender>))
181 182 183 184
			->setCollector("group", make_sfn(&BelCardProperty::setGroup))
			->setCollector("any-param", make_sfn(&BelCardProperty::addParam))
			->setCollector("VALUE-param", make_sfn(&BelCardProperty::setValueParam))
			->setCollector("GENDER-value", make_sfn(&BelCardProperty::setValue));
185 186 187 188 189 190 191
}

BelCardGender::BelCardGender() : BelCardProperty() {
	setName("GENDER");
}

shared_ptr<BelCardPhoto> BelCardPhoto::parse(const string& input) {
Sylvain Berfini's avatar
Sylvain Berfini committed
192
	return BelCardProperty::parseProperty<BelCardPhoto>("PHOTO", input);
193 194 195
}

void BelCardPhoto::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
Sylvain Berfini's avatar
Sylvain Berfini committed
196
	parser->setHandler("PHOTO", make_fn(BelCardGeneric::create<BelCardPhoto>))
197 198 199 200 201 202 203 204 205
			->setCollector("group", make_sfn(&BelCardProperty::setGroup))
			->setCollector("any-param", make_sfn(&BelCardProperty::addParam))
			->setCollector("VALUE-param", make_sfn(&BelCardProperty::setValueParam))
			->setCollector("ALTID-param", make_sfn(&BelCardProperty::setAlternativeIdParam))
			->setCollector("TYPE-param", make_sfn(&BelCardProperty::setTypeParam))
			->setCollector("MEDIATYPE-param", make_sfn(&BelCardProperty::setMediaTypeParam))
			->setCollector("PREF-param", make_sfn(&BelCardProperty::setPrefParam))
			->setCollector("PID-param", make_sfn(&BelCardProperty::setParamIdParam))
			->setCollector("PHOTO-value", make_sfn(&BelCardProperty::setValue));
206 207 208 209 210
}

BelCardPhoto::BelCardPhoto() : BelCardProperty() {
	setName("PHOTO");
}