Commit 2325c451 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Rework of some headers

parent 686cf9df
......@@ -3,6 +3,7 @@ belcard_includedir=$(includedir)/belcard
belcard_include_HEADERS = belcard.hpp \
belcard_generic.hpp \
belcard_params.hpp \
belcard_property.hpp \
belcard_general.hpp \
belcard_identification.hpp \
belcard_addressing.hpp \
......
......@@ -2,6 +2,8 @@
#define belcard_hpp
#include "belcard_generic.hpp"
#include "belcard_params.hpp"
#include "belcard_property.hpp"
#include "belcard_general.hpp"
#include "belcard_identification.hpp"
#include "belcard_addressing.hpp"
......
#ifndef belcard_addressing_hpp
#define belcard_addressing_hpp
#include "belcard_generic.hpp"
#include "belcard_property.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
......
#ifndef belcard_calendar_hpp
#define belcard_calendar_hpp
#include "belcard_generic.hpp"
#include "belcard_property.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
......
#ifndef belcard_communication_hpp
#define belcard_communication_hpp
#include "belcard_generic.hpp"
#include "belcard_property.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
......
#ifndef belcard_explanatory_hpp
#define belcard_explanatory_hpp
#include "belcard_generic.hpp"
#include "belcard_property.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
......
#ifndef belcard_general_hpp
#define belcard_general_hpp
#include "belcard_generic.hpp"
#include "belcard_property.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
......
#ifndef belcard_generic_hpp
#define belcard_generic_hpp
#include <belr/parser-impl.cc>
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
#include "belcard/vcard_grammar.hpp"
#include <string>
#include <list>
#include <sstream>
#include <memory>
using namespace::std;
using namespace::belr;
namespace belcard {
class BelCardGeneric {
......@@ -25,65 +19,6 @@ namespace belcard {
virtual ~BelCardGeneric() { } //put a virtual destructor to enable polymorphism and dynamic casting.
};
class BelCardParam : public BelCardGeneric {
private:
string _name;
string _value;
public:
static shared_ptr<BelCardParam> create();
static shared_ptr<BelCardParam> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardParam();
friend ostream &operator<<(ostream &output, const BelCardParam &param) {
output << param.serialize();
return output;
}
virtual void setName(const string &name);
virtual const string &getName() const;
virtual void setValue(const string &value) ;
virtual const string &getValue() const;
virtual string serialize() const;
};
class BelCardProperty : public BelCardGeneric {
protected:
string _group;
string _name;
string _value;
list<shared_ptr<BelCardParam>> _params;
public:
static shared_ptr<BelCardProperty> create();
static shared_ptr<BelCardProperty> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardProperty();
friend ostream &operator<<(ostream &output, const BelCardProperty &prop) {
output << prop.serialize();
return output;
}
virtual void setGroup(const string &group);
virtual const string &getGroup() const;
virtual void setName(const string &name);
virtual const string &getName() const;
virtual void setValue(const string &value);
virtual const string &getValue() const;
virtual void addParam(const shared_ptr<BelCardParam> &param);
virtual const list<shared_ptr<BelCardParam>> &getParams() const;
virtual string serialize() const;
};
}
#endif
\ No newline at end of file
#ifndef belcard_geographical_hpp
#define belcard_geographical_hpp
#include "belcard_generic.hpp"
#include "belcard_property.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
......
#ifndef belcard_identification_hpp
#define belcard_identification_hpp
#include "belcard_generic.hpp"
#include "belcard_property.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
......
#ifndef belcard_organizational_hpp
#define belcard_organizational_hpp
#include "belcard_generic.hpp"
#include "belcard_property.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
......
#ifndef belcard_params_hpp
#define belcard_params_hpp
#include "belcard_generic.hpp"
#include <belr/parser-impl.cc>
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
#include "belcard_generic.hpp"
#include <string>
#include <sstream>
using namespace::std;
using namespace::belr;
namespace belcard {
class BelCardParam : public BelCardGeneric {
private:
string _name;
string _value;
public:
static shared_ptr<BelCardParam> create();
static shared_ptr<BelCardParam> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardParam();
friend ostream &operator<<(ostream &output, const BelCardParam &param) {
output << param.serialize();
return output;
}
virtual void setName(const string &name);
virtual const string &getName() const;
virtual void setValue(const string &value) ;
virtual const string &getValue() const;
virtual string serialize() const;
};
class BelCardLanguageParam : public BelCardParam {
public:
static shared_ptr<BelCardLanguageParam> create();
......
#ifndef belcard_property_hpp
#define belcard_property_hpp
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
#include "belcard/belcard_generic.hpp"
#include "belcard_params.hpp"
#include <string>
#include <list>
#include <sstream>
using namespace::std;
using namespace::belr;
namespace belcard {
class BelCardProperty : public BelCardGeneric {
protected:
string _group;
string _name;
string _value;
shared_ptr<BelCardValueParam> _value_param;
list<shared_ptr<BelCardParam>> _params;
public:
static shared_ptr<BelCardProperty> create();
static shared_ptr<BelCardProperty> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardProperty();
friend ostream &operator<<(ostream &output, const BelCardProperty &prop) {
output << prop.serialize();
return output;
}
virtual void setGroup(const string &group);
virtual const string &getGroup() const;
virtual void setName(const string &name);
virtual const string &getName() const;
virtual void setValue(const string &value);
virtual const string &getValue() const;
virtual void addValueParam(const shared_ptr<BelCardValueParam> &param);
virtual void addParam(const shared_ptr<BelCardParam> &param);
virtual const list<shared_ptr<BelCardParam>> &getParams() const;
virtual string serialize() const;
};
}
#endif
\ No newline at end of file
#ifndef belcard_security_hpp
#define belcard_security_hpp
#include "belcard_generic.hpp"
#include "belcard_property.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
......
......@@ -6,8 +6,8 @@ vcard_grammar.cpp: vcard.grammar
xxd -i vcard.grammar | sed s/}\;/,0x00}\;/ >> vcard_grammar.cpp
libbelcard_la_SOURCES=belcard_parser.cpp \
belcard_generic.cpp \
belcard_params.cpp \
belcard_property.cpp \
belcard.cpp \
belcard_general.cpp \
belcard_identification.cpp \
......
......@@ -4,6 +4,49 @@ using namespace::std;
using namespace::belr;
using namespace::belcard;
shared_ptr<BelCardParam> BelCardParam::create() {
return BelCardGeneric::create<BelCardParam>();
}
shared_ptr<BelCardParam> BelCardParam::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);
shared_ptr<BelCardGeneric> ret = parser.parseInput("any-param", input, NULL);
return dynamic_pointer_cast<BelCardParam>(ret);
}
void BelCardParam::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
parser->setHandler("any-param", make_fn(&BelCardParam::create))
->setCollector("param-name", make_sfn(&BelCardParam::setName))
->setCollector("param-value", make_sfn(&BelCardParam::setValue));
}
BelCardParam::BelCardParam() : BelCardGeneric() {
}
void BelCardParam::setName(const string &name) {
_name = name;
}
const string &BelCardParam::getName() const {
return _name;
}
void BelCardParam::setValue(const string &value) {
_value = value;
}
const string &BelCardParam::getValue() const {
return _value;
}
string BelCardParam::serialize() const {
stringstream output;
output << getName() << "=" << getValue();
return output.str();
}
shared_ptr<BelCardLanguageParam> BelCardLanguageParam::create() {
return BelCardGeneric::create<BelCardLanguageParam>();
}
......
#include "belcard/belcard_generic.hpp"
#include "belcard/belcard_property.hpp"
using namespace::std;
using namespace::belr;
using namespace::belcard;
shared_ptr<BelCardParam> BelCardParam::create() {
return BelCardGeneric::create<BelCardParam>();
}
shared_ptr<BelCardParam> BelCardParam::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);
shared_ptr<BelCardGeneric> ret = parser.parseInput("any-param", input, NULL);
return dynamic_pointer_cast<BelCardParam>(ret);
}
void BelCardParam::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
parser->setHandler("any-param", make_fn(&BelCardParam::create))
->setCollector("param-name", make_sfn(&BelCardParam::setName))
->setCollector("param-value", make_sfn(&BelCardParam::setValue));
}
BelCardParam::BelCardParam() : BelCardGeneric() {
}
void BelCardParam::setName(const string &name) {
_name = name;
}
const string &BelCardParam::getName() const {
return _name;
}
void BelCardParam::setValue(const string &value) {
_value = value;
}
const string &BelCardParam::getValue() const {
return _value;
}
string BelCardParam::serialize() const {
stringstream output;
output << getName() << "=" << getValue();
return output.str();
}
shared_ptr<BelCardProperty> BelCardProperty::create() {
return BelCardGeneric::create<BelCardProperty>();
}
......@@ -92,6 +49,11 @@ void BelCardProperty::setValue(const string &value) {
const string &BelCardProperty::getValue() const {
return _value;
}
void BelCardProperty::addValueParam(const shared_ptr<BelCardValueParam> &param) {
_value_param = param;
_params.push_back(_value_param);
}
void BelCardProperty::addParam(const shared_ptr<BelCardParam> &param) {
_params.push_back(param);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment