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

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

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

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

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

BelCardKey::BelCardKey() : BelCardProperty() {
	setName("KEY");
}