15 #include "eckit/config/LocalConfiguration.h"
16 #include "eckit/exception/Exceptions.h"
37 virtual std::shared_ptr<Parser>
make(
const eckit::Configuration &conf) = 0;
46 std::shared_ptr<Parser>
make(
const eckit::Configuration &conf)
override
48 return std::make_shared<T>(conf);
58 static std::shared_ptr<Parser>
create(
const eckit::Configuration &conf)
62 throw eckit::BadParameter(
"Parser configuration has no \"name\".");
66 std::ostringstream errStr;
67 errStr <<
"Trying to use unregistered parser named ";
69 throw eckit::BadParameter(errStr.str());
83 std::ostringstream errStr;
84 errStr <<
"Trying to add parser with a duplicate name ";
86 errStr <<
". Name must be unique.";
88 throw eckit::BadParameter(errStr.str());
91 getMakers().insert({
name, std::make_shared<ParserMaker<T>>()});
97 static std::map<std::string, std::shared_ptr<ParserMakerBase>>&
getMakers()
99 static std::map<std::string, std::shared_ptr<ParserMakerBase>> makers;
Factory that is used to create Parsers.
static void registerParser(const std::string &name)
Register a new Parser type we want to be able to create.
static std::shared_ptr< Parser > create(const eckit::Configuration &conf)
Create a Parser.
static std::map< std::string, std::shared_ptr< ParserMakerBase > > & getMakers()
Internal method that returns a map of Parser Makers that were registered with registerParser.
Base class for all ParserMakers. Makes it possible to store all types of parsers inside a std data st...
virtual std::shared_ptr< Parser > make(const eckit::Configuration &conf)=0
Instantiate a Parser instance.
ParserMaker class template definition.
std::shared_ptr< Parser > make(const eckit::Configuration &conf) override
Instantiate a Parser instance.