Commit 45c1cb28 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Getting rid of BelcardParser getInstance()

parent 9a335d9b
......@@ -41,12 +41,10 @@ namespace belcard {
ABNFGrammarBuilder _grammar_builder;
shared_ptr<Grammar> _grammar;
BelCardParser();
shared_ptr<BelCardGeneric> _parse(const string &input, const string &rule);
public:
BELCARD_PUBLIC static BelCardParser& getInstance();
BelCardParser();
BELCARD_PUBLIC ~BelCardParser();
BELCARD_PUBLIC shared_ptr<BelCard> parseOne(const string &input);
......
......@@ -137,8 +137,3 @@ shared_ptr<BelCardList> BelCardParser::parseFile(const string &filename) {
shared_ptr<BelCardList> belCards = dynamic_pointer_cast<BelCardList>(ret);
return belCards;
}
BelCardParser& BelCardParser::getInstance() {
static BelCardParser *instance = new BelCardParser();
return *instance;
}
......@@ -59,25 +59,27 @@ static void unfolding(void) {
static void vcard_parsing(void) {
string vcard = openFile("vcards/vcard.vcf");
BelCardParser parser = BelCardParser::getInstance();
shared_ptr<BelCard> belCard = parser.parseOne(vcard);
BelCardParser *parser = new BelCardParser();
shared_ptr<BelCard> belCard = parser->parseOne(vcard);
if (!BC_ASSERT_TRUE(belCard!=NULL)) return;
BC_ASSERT_TRUE(belCard->assertRFCCompliance());
string vcard2 = belCard->toFoldedString();
BC_ASSERT_EQUAL(vcard2.compare(vcard), 0, int, "%d");
delete(parser);
}
static void vcards_parsing(void) {
string vcards = openFile("vcards/vcards.vcf");
BelCardParser parser = BelCardParser::getInstance();
shared_ptr<BelCardList> belCards = parser.parse(vcards);
BelCardParser *parser = new BelCardParser();
shared_ptr<BelCardList> belCards = parser->parse(vcards);
if (!BC_ASSERT_TRUE(belCards!=NULL)) return;
BC_ASSERT_EQUAL(belCards->getCards().size(), 2, unsigned, "%u");
string vcards2 = belCards->toString();
BC_ASSERT_EQUAL(vcards2.compare(vcards), 0, int, "%d");
delete(parser);
}
static void create_vcard_from_api(void) {
......@@ -91,12 +93,13 @@ static void create_vcard_from_api(void) {
BC_ASSERT_TRUE(belCard->assertRFCCompliance());
string vcard = belCard->toString();
BelCardParser parser = BelCardParser::getInstance();
shared_ptr<BelCard> belCard2 = parser.parseOne(vcard);
BelCardParser *parser = new BelCardParser();
shared_ptr<BelCard> belCard2 = parser->parseOne(vcard);
if (!BC_ASSERT_TRUE(belCard2!=NULL)) return;
BC_ASSERT_TRUE(belCard2->assertRFCCompliance());
string vcard2 = belCard2->toString();
BC_ASSERT_EQUAL(vcard.compare(vcard2), 0, unsigned, "%u");
delete(parser);
}
static void property_sort_using_pref_param(void) {
......
......@@ -38,11 +38,11 @@ int main(int argc, char *argv[]) {
file = argv[1];
auto t_start = std::chrono::high_resolution_clock::now();
BelCardParser parser = BelCardParser::getInstance();
BelCardParser *parser = new BelCardParser();
auto t_end = std::chrono::high_resolution_clock::now();
auto t_start_2 = std::chrono::high_resolution_clock::now();
shared_ptr<BelCardList> belCards = parser.parseFile(file);
shared_ptr<BelCardList> belCards = parser->parseFile(file);
auto t_end_2 = std::chrono::high_resolution_clock::now();
if (belCards) {
......@@ -53,5 +53,7 @@ int main(int argc, char *argv[]) {
cout << "Parser initialized in " << std::chrono::duration<double, std::milli>(t_end - t_start).count() << " milliseconds" << endl;
cout << "Parsing done in " << std::chrono::duration<double, std::milli>(t_end_2 - t_start_2).count() << " milliseconds" << endl;
delete(parser);
return 0;
}
\ No newline at end of file
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