Commit 705a7a1d authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Moved code from header to cpp file + prepared all missing properties (need to...

Moved code from header to cpp file + prepared all missing properties (need to complete grammar and tester)
parent 8deddfdd
......@@ -6,6 +6,11 @@ belcard_include_HEADERS = belcard.hpp \
belcard_identification.hpp \
belcard_addressing.hpp \
belcard_communication.hpp \
belcard_geographical.hpp \
belcard_organizational.hpp \
belcard_explanatory.hpp \
belcard_security.hpp \
belcard_calendar.hpp \
belcard_parser.hpp \
vcard_grammar.hpp
......
......@@ -6,6 +6,11 @@
#include "belcard_identification.hpp"
#include "belcard_addressing.hpp"
#include "belcard_communication.hpp"
#include "belcard_geographical.hpp"
#include "belcard_organizational.hpp"
#include "belcard_explanatory.hpp"
#include "belcard_security.hpp"
#include "belcard_calendar.hpp"
#include <string>
#include <list>
......@@ -34,168 +39,65 @@ namespace belcard {
list<shared_ptr<BelCardProperty>> _properties;
public:
static shared_ptr<BelCard> create() {
return make_shared<BelCard>();
}
static shared_ptr<BelCard> create();
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
parser->setHandler("vcard", make_fn(&BelCard::create))
->setCollector("KIND", make_sfn(&BelCard::setKind))
->setCollector("FN", make_sfn(&BelCard::setFN))
->setCollector("N", make_sfn(&BelCard::setN))
->setCollector("BDAY", make_sfn(&BelCard::setBirthday))
->setCollector("ANNIVERSARY", make_sfn(&BelCard::setAnniversary))
->setCollector("GENDER", make_sfn(&BelCard::setGender))
->setCollector("NICKNAME", make_sfn(&BelCard::addNickname))
->setCollector("PHOTO", make_sfn(&BelCard::addPhoto))
->setCollector("ADR", make_sfn(&BelCard::addAddress))
->setCollector("TEL", make_sfn(&BelCard::addTel))
->setCollector("EMAIL", make_sfn(&BelCard::addEmail))
->setCollector("IMPP", make_sfn(&BelCard::addImpp))
->setCollector("LANG", make_sfn(&BelCard::addLang))
->setCollector("SOURCE", make_sfn(&BelCard::addSource))
->setCollector("XML", make_sfn(&BelCard::addXML));
BelCard();
friend ostream &operator<<(ostream &output, const BelCard &card) {
output << card.serialize();
return output;
}
BelCard() {
}
void setKind(const shared_ptr<BelCardKind> &kind);
const shared_ptr<BelCardKind> &getKind() const;
void setKind(const shared_ptr<BelCardKind> &kind) {
_kind = kind;
addProperty(_kind);
}
const shared_ptr<BelCardKind> &getKind() const {
return _kind;
}
void setFN(const shared_ptr<BelCardFN> &fn);
const shared_ptr<BelCardFN> &getFN() const;
void setFN(const shared_ptr<BelCardFN> &fn) {
_fn = fn;
addProperty(_fn);
}
const shared_ptr<BelCardFN> &getFN() const {
return _fn;
}
void setN(const shared_ptr<BelCardN> &n);
const shared_ptr<BelCardN> &getN() const;
void setN(const shared_ptr<BelCardN> &n) {
_n = n;
addProperty(_n);
}
const shared_ptr<BelCardN> &getN() const {
return _n;
}
void setBirthday(const shared_ptr<BelCardBirthday> &bday);
const shared_ptr<BelCardBirthday> &getBirthday() const;
void setBirthday(const shared_ptr<BelCardBirthday> &bday) {
_bday = bday;
addProperty(_bday);
}
const shared_ptr<BelCardBirthday> &getBirthday() const {
return _bday;
}
void setAnniversary(const shared_ptr<BelCardAnniversary> &anniversary);
const shared_ptr<BelCardAnniversary> &getAnniversary() const;
void setAnniversary(const shared_ptr<BelCardAnniversary> &anniversary) {
_anniversary = anniversary;
addProperty(_anniversary);
}
const shared_ptr<BelCardAnniversary> &getAnniversary() const {
return _anniversary;
}
void setGender(const shared_ptr<BelCardGender> &gender);
const shared_ptr<BelCardGender> &getGender() const;
void setGender(const shared_ptr<BelCardGender> &gender) {
_gender = gender;
addProperty(_gender);
}
const shared_ptr<BelCardGender> &getGender() const {
return _gender;
}
void addNickname(const shared_ptr<BelCardNickname> &nickname);
const list<shared_ptr<BelCardNickname>> &getNicknames() const;
void addNickname(const shared_ptr<BelCardNickname> &nickname) {
_nicknames.push_back(nickname);
addProperty(nickname);
}
const list<shared_ptr<BelCardNickname>> &getNicknames() const {
return _nicknames;
}
void addPhoto(const shared_ptr<BelCardPhoto> &photo);
const list<shared_ptr<BelCardPhoto>> &getPhotos() const;
void addPhoto(const shared_ptr<BelCardPhoto> &photo) {
_photos.push_back(photo);
addProperty(photo);
}
const list<shared_ptr<BelCardPhoto>> &getPhotos() const {
return _photos;
}
void addAddress(const shared_ptr<BelCardAddress> &addr);
const list<shared_ptr<BelCardAddress>> &getAddresses() const;
void addAddress(const shared_ptr<BelCardAddress> &addr) {
_addr.push_back(addr);
addProperty(addr);
}
const list<shared_ptr<BelCardAddress>> &getAddresses() const {
return _addr;
}
void addTel(const shared_ptr<BelCardTel> &tel) {
_tel.push_back(tel);
addProperty(tel);
}
const list<shared_ptr<BelCardTel>> &getTel() const {
return _tel;
}
void addTel(const shared_ptr<BelCardTel> &tel);
const list<shared_ptr<BelCardTel>> &getTel() const;
void addEmail(const shared_ptr<BelCardEmail> &email) {
_emails.push_back(email);
addProperty(email);
}
const list<shared_ptr<BelCardEmail>> &getEmails() const {
return _emails;
}
void addEmail(const shared_ptr<BelCardEmail> &email);
const list<shared_ptr<BelCardEmail>> &getEmails() const;
void addImpp(const shared_ptr<BelCardImpp> &impp) {
_impp.push_back(impp);
addProperty(impp);
}
const list<shared_ptr<BelCardImpp>> &getImpp() const {
return _impp;
}
void addImpp(const shared_ptr<BelCardImpp> &impp);
const list<shared_ptr<BelCardImpp>> &getImpp() const;
void addLang(const shared_ptr<BelCardLang> &lang) {
_langs.push_back(lang);
addProperty(lang);
}
const list<shared_ptr<BelCardLang>> &getLangs() const {
return _langs;
}
void addLang(const shared_ptr<BelCardLang> &lang);
const list<shared_ptr<BelCardLang>> &getLangs() const;
void addSource(const shared_ptr<BelCardSource> &source) {
_sources.push_back(source);
addProperty(source);
}
const list<shared_ptr<BelCardSource>> &getSource() const {
return _sources;
}
void addSource(const shared_ptr<BelCardSource> &source);
const list<shared_ptr<BelCardSource>> &getSource() const;
void addXML(const shared_ptr<BelCardXML> &xml) {
_xml.push_back(xml);
addProperty(xml);
}
const list<shared_ptr<BelCardXML>> &getXML() const {
return _xml;
}
void addXML(const shared_ptr<BelCardXML> &xml);
const list<shared_ptr<BelCardXML>> &getXML() const;
void addProperty(const shared_ptr<BelCardProperty> &property) {
_properties.push_back(property);
}
const list<shared_ptr<BelCardProperty>> &getProperties() const {
return _properties;
}
void addProperty(const shared_ptr<BelCardProperty> &property);
const list<shared_ptr<BelCardProperty>> &getProperties() const;
friend ostream &operator<<(ostream &output, const BelCard &card) {
output << "BEGIN:VCARD\r\nVERSION:4.0\r\n";
for (auto it = card.getProperties().begin(); it != card.getProperties().end(); ++it) {
output << (**it);
}
output << "END:VCARD\r\n";
return output;
}
string serialize() const;
};
}
......
......@@ -23,107 +23,38 @@ namespace belcard {
string _country;
public:
static shared_ptr<BelCardAddress> create() {
return make_shared<BelCardAddress>();
}
static shared_ptr<BelCardAddress> create();
static shared_ptr<BelCardAddress> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
static shared_ptr<BelCardAddress> 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("ADR", input, NULL);
return dynamic_pointer_cast<BelCardAddress>(ret);
}
BelCardAddress();
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
parser->setHandler("ADR", make_fn(&BelCardAddress::create))
->setCollector("group", make_sfn(&BelCardAddress::setGroup))
->setCollector("any-param", make_sfn(&BelCardAddress::addParam))
->setCollector("ADR-pobox", make_sfn(&BelCardAddress::setPostOfficeBox))
->setCollector("ADR-ext", make_sfn(&BelCardAddress::setExtendedAddress))
->setCollector("ADR-street", make_sfn(&BelCardAddress::setStreet))
->setCollector("ADR-locality", make_sfn(&BelCardAddress::setLocality))
->setCollector("ADR-region", make_sfn(&BelCardAddress::setRegion))
->setCollector("ADR-code", make_sfn(&BelCardAddress::setPostalCode))
->setCollector("ADR-country", make_sfn(&BelCardAddress::setCountry));
}
void setPostOfficeBox(const string &value);
const string &getPostOfficeBox() const;
BelCardAddress() : BelCardProperty() {
setName("ADR");
}
void setExtendedAddress(const string &value);
const string &getExtendedAddress() const;
void setPostOfficeBox(const string &value) {
_po_box = value;
}
const string &getPostOfficeBox() const {
return _po_box;
}
void setStreet(const string &value);
const string &getStreet() const;
void setExtendedAddress(const string &value) {
_extended_address = value;
}
const string &getExtendedAddress() const {
return _extended_address;
}
void setLocality(const string &value);
const string &getLocality() const;
void setStreet(const string &value) {
_street = value;
}
const string &getStreet() const {
return _street;
}
void setRegion(const string &value);
const string &getRegion() const;
void setLocality(const string &value) {
_locality = value;
}
const string &getLocality() const {
return _locality;
}
void setPostalCode(const string &value);
const string &getPostalCode() const;
void setRegion(const string &value) {
_region = value;
}
const string &getRegion() const {
return _region;
}
void setPostalCode(const string &value) {
_postal_code = value;
}
const string &getPostalCode() const {
return _postal_code;
}
void setCountry(const string &value);
const string &getCountry() const;
void setCountry(const string &value) {
_country = value;
}
const string &getCountry() const {
return _country;
}
string serialize() const;
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
string serialize() const {
stringstream output;
if (getGroup().length() > 0) {
output << getGroup() << ".";
}
output << getName();
for (auto it = getParams().begin(); it != getParams().end(); ++it) {
output << ";" << (**it);
}
output << ":" << getPostOfficeBox() << ";" << getExtendedAddress()
<< ";" << getStreet() << ";" << getLocality() << ";" << getRegion()
<< ";" << getPostalCode() << ";" << getCountry() << "\r\n";
return output.str();
}
};
}
......
#ifndef belcard_calendar_hpp
#define belcard_calendar_hpp
#include "belcard_generic.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
#include <string>
using namespace::std;
using namespace::belr;
namespace belcard {
class BelCardFBURL : public BelCardProperty {
public:
static shared_ptr<BelCardFBURL> create();
static shared_ptr<BelCardFBURL> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardFBURL();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
class BelCardCALADRURI : public BelCardProperty {
public:
static shared_ptr<BelCardCALADRURI> create();
static shared_ptr<BelCardCALADRURI> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardCALADRURI();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
class BelCardCALURI : public BelCardProperty {
public:
static shared_ptr<BelCardCALURI> create();
static shared_ptr<BelCardCALURI> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardCALURI();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
}
#endif
\ No newline at end of file
......@@ -14,30 +14,11 @@ using namespace::belr;
namespace belcard {
class BelCardTel : public BelCardProperty {
public:
static shared_ptr<BelCardTel> create() {
return make_shared<BelCardTel>();
}
static shared_ptr<BelCardTel> 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("TEL", input, NULL);
return dynamic_pointer_cast<BelCardTel>(ret);
}
static shared_ptr<BelCardTel> create();
static shared_ptr<BelCardTel> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
parser->setHandler("TEL", make_fn(&BelCardTel::create))
->setCollector("group", make_sfn(&BelCardTel::setGroup))
->setCollector("any-param", make_sfn(&BelCardTel::addParam))
->setCollector("TEL-value", make_sfn(&BelCardTel::setValue));
}
BelCardTel() : BelCardProperty() {
setName("TEL");
}
BelCardTel();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
......@@ -46,30 +27,11 @@ namespace belcard {
class BelCardEmail : public BelCardProperty {
public:
static shared_ptr<BelCardEmail> create() {
return make_shared<BelCardEmail>();
}
static shared_ptr<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);
}
static shared_ptr<BelCardEmail> create();
static shared_ptr<BelCardEmail> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
static void 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() : BelCardProperty() {
setName("EMAIL");
}
BelCardEmail();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
......@@ -78,30 +40,11 @@ namespace belcard {
class BelCardImpp : public BelCardProperty {
public:
static shared_ptr<BelCardImpp> create() {
return make_shared<BelCardImpp>();
}
static shared_ptr<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);
}
static shared_ptr<BelCardImpp> create();
static shared_ptr<BelCardImpp> parse(const string& input) ;
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
static void 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() : BelCardProperty() {
setName("IMPP");
}
BelCardImpp();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
......@@ -110,30 +53,11 @@ namespace belcard {
class BelCardLang : public BelCardProperty {
public:
static shared_ptr<BelCardLang> create() {
return make_shared<BelCardLang>();
}
static shared_ptr<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);
}
static shared_ptr<BelCardLang> create();
static shared_ptr<BelCardLang> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
static void 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() : BelCardProperty() {
setName("LANG");
}
BelCardLang();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
......
#ifndef belcard_explanatory_hpp
#define belcard_explanatory_hpp
#include "belcard_generic.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
#include <string>
using namespace::std;
using namespace::belr;
namespace belcard {
class BelCardCategories : public BelCardProperty {
public:
static shared_ptr<BelCardCategories> create();
static shared_ptr<BelCardCategories> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardCategories();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
class BelCardNote : public BelCardProperty {
public:
static shared_ptr<BelCardNote> create();
static shared_ptr<BelCardNote> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardNote();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
class BelCardProductId : public BelCardProperty {
public:
static shared_ptr<BelCardProductId> create();
static shared_ptr<BelCardProductId> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardProductId();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
class BelCardRevision : public BelCardProperty {
public:
static shared_ptr<BelCardRevision> create();
static shared_ptr<BelCardRevision> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardRevision();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
class BelCardSound : public BelCardProperty {
public:
static shared_ptr<BelCardSound> create();
static shared_ptr<BelCardSound> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardSound();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
class BelCardUniqueId : public BelCardProperty {
public:
static shared_ptr<BelCardUniqueId> create();
static shared_ptr<BelCardUniqueId> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardUniqueId();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
class BelCardClientProductIdMap : public BelCardProperty {
public:
static shared_ptr<BelCardClientProductIdMap> create();
static shared_ptr<BelCardClientProductIdMap> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardClientProductIdMap();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
class BelCardURL : public BelCardProperty {
public:
static shared_ptr<BelCardURL> create();
static shared_ptr<BelCardURL> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardURL();
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
}
#endif
\ No newline at end of file
......@@ -13,30 +13,11 @@ using namespace::belr;
namespace belcard {
class BelCardKind : public BelCardProperty {
public:
static shared_ptr<BelCardKind> create() {
return make_shared<BelCardKind>();
}
static shared_ptr<BelCardKind> create();
static shared_ptr<BelCardKind> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
static shared_ptr<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);
}
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {