belcard_general.cpp 3.03 KB
Newer Older
1 2 3 4 5 6 7
#include "belcard/belcard_general.hpp"

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

shared_ptr<BelCardKind> BelCardKind::create() {
8
	return BelCardGeneric::create<BelCardKind>();
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
}

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

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

BelCardKind::BelCardKind() : BelCardProperty() {
	setName("KIND");
}

shared_ptr<BelCardSource> BelCardSource::create() {
33
	return BelCardGeneric::create<BelCardSource>();
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<BelCardSource> BelCardSource::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("SOURCE", input, NULL);
	return dynamic_pointer_cast<BelCardSource>(ret);
}

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

BelCardSource::BelCardSource() : BelCardProperty() {
	setName("SOURCE");
}

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

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

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

BelCardXML::BelCardXML() : BelCardProperty() {
	setName("XML");
}