From 0251dbd2ab9eb32b38a93d7baaddb5ef5549fb9c Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Sun, 19 Dec 2010 15:39:54 -0500 Subject: [PATCH] lib: added convenience Add() members to MultiRecordParser --- src/parser.cc | 16 ++++++++++++++++ src/parser.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/parser.cc b/src/parser.cc index ddfb0e98..dd3d9a20 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -122,6 +122,22 @@ bool MultiRecordParser::Add(const std::string &dbname, return true; } +bool MultiRecordParser::Add(const std::string &dbname, AllRecordStore &store) +{ +#undef HANDLE_PARSER +#define HANDLE_PARSER(tname) \ + if( dbname == tname::GetDBName() ) { \ + Add(dbname, new RecordParser(store)); \ + return true; \ + } + + // check for recognized database names + ALL_KNOWN_PARSER_TYPES + + // if we get here, record was not found + return false; +} + // Parser overrides void MultiRecordParser::ParseRecord(const DBData &data, const IConverter *ic) { diff --git a/src/parser.h b/src/parser.h index def703c3..496347e9 100644 --- a/src/parser.h +++ b/src/parser.h @@ -396,12 +396,45 @@ public: /// Adds given parser to list and takes ownership of it void Add(RecordParserBase *parser); + /// Creates a RecordParser<> object using the given record + /// type and AllRecordStore. Does NOT take ownership of the + /// store object, since it can be used multiple times for + /// multiple records. + template + void Add(AllRecordStore &store) + { + Add( RecordT::GetDBName(), + new RecordParser(store) ); + } + + /// Two helper template functions that create the RecordParser<> + /// automatically based on the function call. Both pointer and + /// reference versions. + template + void Add(StorageT *store) + { + Add( RecordT::GetDBName(), + new RecordParser(store) ); + } + + template + void Add(StorageT &store) + { + Add( RecordT::GetDBName(), + new RecordParser(store) ); + } + /// Creates a RecordParser<> object for the given database name, /// using DumpStore<> with the given stream for the output, /// and adds it to list. /// Returns false if there is no known Record class for dbname. bool Add(const std::string &dbname, std::ostream &os); + /// Creates a RecordParser<> object for the given database name, + /// using the given store object. + /// Returns false if there is no known Record class for dbname. + bool Add(const std::string &dbname, AllRecordStore &store); + // Parser overrides virtual void ParseRecord(const DBData &data, const IConverter *ic); }; -- 2.11.4.GIT