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

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

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

Sylvain Berfini's avatar
Sylvain Berfini committed
11
shared_ptr<BelCardPhoneNumber> BelCardPhoneNumber::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("TEL", input, NULL);
Sylvain Berfini's avatar
Sylvain Berfini committed
18
	return dynamic_pointer_cast<BelCardPhoneNumber>(ret);
19 20
}

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

Sylvain Berfini's avatar
Sylvain Berfini committed
28
BelCardPhoneNumber::BelCardPhoneNumber() : BelCardProperty() {
29 30 31 32
	setName("TEL");
}

shared_ptr<BelCardEmail> BelCardEmail::create() {
33
	return BelCardGeneric::create<BelCardEmail>();
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
}

shared_ptr<BelCardEmail> BelCardEmail::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("EMAIL", input, NULL);
	return dynamic_pointer_cast<BelCardEmail>(ret);
}

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

BelCardEmail::BelCardEmail() : BelCardProperty() {
	setName("EMAIL");
}

shared_ptr<BelCardImpp> BelCardImpp::create() {
58
	return BelCardGeneric::create<BelCardImpp>();
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
}

shared_ptr<BelCardImpp> BelCardImpp::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("IMPP", input, NULL);
	return dynamic_pointer_cast<BelCardImpp>(ret);
}

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

BelCardImpp::BelCardImpp() : BelCardProperty() {
	setName("IMPP");
}

shared_ptr<BelCardLang> BelCardLang::create() {
83
	return BelCardGeneric::create<BelCardLang>();
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
}

shared_ptr<BelCardLang> BelCardLang::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("LANG", input, NULL);
	return dynamic_pointer_cast<BelCardLang>(ret);
}

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

BelCardLang::BelCardLang() : BelCardProperty() {
	setName("LANG");
}