belcard_identification.cpp 8.66 KB
Newer Older
1 2 3 4 5 6
#include "belcard/belcard_identification.hpp"

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

Sylvain Berfini's avatar
Sylvain Berfini committed
7 8
shared_ptr<BelCardFullName> BelCardFullName::create() {
	return BelCardGeneric::create<BelCardFullName>();
9 10
}

Sylvain Berfini's avatar
Sylvain Berfini committed
11
shared_ptr<BelCardFullName> BelCardFullName::parse(const string& input) {
12 13 14 15 16 17
	ABNFGrammarBuilder grammar_builder;
	shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>());
	Parser<shared_ptr<BelCardGeneric>> parser(grammar);
	setHandlerAndCollectors(&parser);
	BelCardParam::setHandlerAndCollectors(&parser);
	shared_ptr<BelCardGeneric> ret = parser.parseInput("FN", input, NULL);
Sylvain Berfini's avatar
Sylvain Berfini committed
18
	return dynamic_pointer_cast<BelCardFullName>(ret);
19 20
}

Sylvain Berfini's avatar
Sylvain Berfini committed
21 22 23 24 25
void BelCardFullName::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
	parser->setHandler("FN", make_fn(&BelCardFullName::create))
			->setCollector("group", make_sfn(&BelCardFullName::setGroup))
			->setCollector("any-param", make_sfn(&BelCardFullName::addParam))
			->setCollector("FN-value", make_sfn(&BelCardFullName::setValue));
26 27
}

Sylvain Berfini's avatar
Sylvain Berfini committed
28
BelCardFullName::BelCardFullName() : BelCardProperty() {
29 30 31
	setName("FN");
}

Sylvain Berfini's avatar
Sylvain Berfini committed
32 33
shared_ptr<BelCardName> BelCardName::create() {
	return BelCardGeneric::create<BelCardName>();
34 35
}

Sylvain Berfini's avatar
Sylvain Berfini committed
36
shared_ptr<BelCardName> BelCardName::parse(const string& input) {
37 38 39 40 41 42
	ABNFGrammarBuilder grammar_builder;
	shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>());
	Parser<shared_ptr<BelCardGeneric>> parser(grammar);
	setHandlerAndCollectors(&parser);
	BelCardParam::setHandlerAndCollectors(&parser);
	shared_ptr<BelCardGeneric> ret = parser.parseInput("N", input, NULL);
Sylvain Berfini's avatar
Sylvain Berfini committed
43
	return dynamic_pointer_cast<BelCardName>(ret);
44 45
}

Sylvain Berfini's avatar
Sylvain Berfini committed
46 47 48 49 50 51 52 53 54
void BelCardName::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
	parser->setHandler("N", make_fn(&BelCardName::create))
			->setCollector("group", make_sfn(&BelCardName::setGroup))
			->setCollector("any-param", make_sfn(&BelCardName::addParam))
			->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));
55 56
}

Sylvain Berfini's avatar
Sylvain Berfini committed
57
BelCardName::BelCardName() : BelCardProperty() {
58 59 60
	setName("N");
}

Sylvain Berfini's avatar
Sylvain Berfini committed
61
void BelCardName::setFamilyName(const string &value) {
62 63
	_family_name = value;
}
Sylvain Berfini's avatar
Sylvain Berfini committed
64
const string &BelCardName::getFamilyName() const {
65 66 67
	return _family_name;
}

Sylvain Berfini's avatar
Sylvain Berfini committed
68
void BelCardName::setGivenName(const string &value) {
69 70
	_given_name = value;
}
Sylvain Berfini's avatar
Sylvain Berfini committed
71
const string &BelCardName::getGivenName() const {
72 73 74
	return _given_name;
}

Sylvain Berfini's avatar
Sylvain Berfini committed
75
void BelCardName::setAdditionalName(const string &value) {
76 77
	_additional_name = value;
}
Sylvain Berfini's avatar
Sylvain Berfini committed
78
const string &BelCardName::getAdditionalName() const {
79 80 81
	return _additional_name;
}

Sylvain Berfini's avatar
Sylvain Berfini committed
82
void BelCardName::setPrefixes(const string &value) {
83 84
	_prefixes = value;
}
Sylvain Berfini's avatar
Sylvain Berfini committed
85
const string &BelCardName::getPrefixes() const {
86 87 88
	return _prefixes;
}

Sylvain Berfini's avatar
Sylvain Berfini committed
89
void BelCardName::setSuffixes(const string &value) {
90 91
	_suffixes = value;
}
Sylvain Berfini's avatar
Sylvain Berfini committed
92
const string &BelCardName::getSuffixes() const {
93 94 95
	return _suffixes;
}

Sylvain Berfini's avatar
Sylvain Berfini committed
96
string BelCardName::serialize() const {
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
	stringstream output;
	
	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";
	
	return output.str();            
}

shared_ptr<BelCardNickname> BelCardNickname::create() {
113
	return BelCardGeneric::create<BelCardNickname>();
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
}

shared_ptr<BelCardNickname> BelCardNickname::parse(const string& input) {
	ABNFGrammarBuilder grammar_builder;
	shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>());
	Parser<shared_ptr<BelCardGeneric>> parser(grammar);
	setHandlerAndCollectors(&parser);
	BelCardParam::setHandlerAndCollectors(&parser);
	shared_ptr<BelCardGeneric> ret = parser.parseInput("NICKNAME", input, NULL);
	return dynamic_pointer_cast<BelCardNickname>(ret);
}

void BelCardNickname::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
	parser->setHandler("NICKNAME", make_fn(&BelCardNickname::create))
			->setCollector("group", make_sfn(&BelCardNickname::setGroup))
			->setCollector("any-param", make_sfn(&BelCardNickname::addParam))
			->setCollector("NICKNAME-value", make_sfn(&BelCardNickname::setValue));
}

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

shared_ptr<BelCardBirthday> BelCardBirthday::create() {
138
	return BelCardGeneric::create<BelCardBirthday>();
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
}

shared_ptr<BelCardBirthday> BelCardBirthday::parse(const string& input) {
	ABNFGrammarBuilder grammar_builder;
	shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>());
	Parser<shared_ptr<BelCardGeneric>> parser(grammar);
	setHandlerAndCollectors(&parser);
	BelCardParam::setHandlerAndCollectors(&parser);
	shared_ptr<BelCardGeneric> ret = parser.parseInput("BDAY", input, NULL);
	return dynamic_pointer_cast<BelCardBirthday>(ret);
}

void BelCardBirthday::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
	parser->setHandler("BDAY", make_fn(&BelCardBirthday::create))
			->setCollector("group", make_sfn(&BelCardBirthday::setGroup))
			->setCollector("any-param", make_sfn(&BelCardBirthday::addParam))
			->setCollector("BDAY-value", make_sfn(&BelCardBirthday::setValue));
}

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

shared_ptr<BelCardAnniversary> BelCardAnniversary::create() {
163
	return BelCardGeneric::create<BelCardAnniversary>();
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
}

shared_ptr<BelCardAnniversary> BelCardAnniversary::parse(const string& input) {
	ABNFGrammarBuilder grammar_builder;
	shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>());
	Parser<shared_ptr<BelCardGeneric>> parser(grammar);
	setHandlerAndCollectors(&parser);
	BelCardParam::setHandlerAndCollectors(&parser);
	shared_ptr<BelCardGeneric> ret = parser.parseInput("ANNIVERSARY", input, NULL);
	return dynamic_pointer_cast<BelCardAnniversary>(ret);
}

void BelCardAnniversary::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
	parser->setHandler("ANNIVERSARY", make_fn(&BelCardAnniversary::create))
			->setCollector("group", make_sfn(&BelCardAnniversary::setGroup))
			->setCollector("any-param", make_sfn(&BelCardAnniversary::addParam))
			->setCollector("ANNIVERSARY-value", make_sfn(&BelCardAnniversary::setValue));
}

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

shared_ptr<BelCardGender> BelCardGender::create() {
188
	return BelCardGeneric::create<BelCardGender>();
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
}

shared_ptr<BelCardGender> BelCardGender::parse(const string& input) {
	ABNFGrammarBuilder grammar_builder;
	shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>());
	Parser<shared_ptr<BelCardGeneric>> parser(grammar);
	setHandlerAndCollectors(&parser);
	BelCardParam::setHandlerAndCollectors(&parser);
	shared_ptr<BelCardGeneric> ret = parser.parseInput("GENDER", input, NULL);
	return dynamic_pointer_cast<BelCardGender>(ret);
}

void BelCardGender::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
	parser->setHandler("GENDER", make_fn(&BelCardGender::create))
			->setCollector("group", make_sfn(&BelCardGender::setGroup))
			->setCollector("any-param", make_sfn(&BelCardGender::addParam))
			->setCollector("GENDER-value", make_sfn(&BelCardGender::setValue));
}

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

shared_ptr<BelCardPhoto> BelCardPhoto::create() {
213
	return BelCardGeneric::create<BelCardPhoto>();
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
}

shared_ptr<BelCardPhoto> BelCardPhoto::parse(const string& input) {
	ABNFGrammarBuilder grammar_builder;
	shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>());
	Parser<shared_ptr<BelCardGeneric>> parser(grammar);
	setHandlerAndCollectors(&parser);
	BelCardParam::setHandlerAndCollectors(&parser);
	shared_ptr<BelCardGeneric> ret = parser.parseInput("PHOTO", input, NULL);
	return dynamic_pointer_cast<BelCardPhoto>(ret);
}

void BelCardPhoto::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
	parser->setHandler("PHOTO", make_fn(&BelCardPhoto::create))
			->setCollector("group", make_sfn(&BelCardPhoto::setGroup))
			->setCollector("any-param", make_sfn(&BelCardPhoto::addParam))
			->setCollector("PHOTO-value", make_sfn(&BelCardPhoto::setValue));
}

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