AmpGen 2.1
Loading...
Searching...
No Matches
OptionsParser.h
Go to the documentation of this file.
1#ifndef AMPGEN_OPTIONSPARSER_H
2#define AMPGEN_OPTIONSPARSER_H
3
4#include <iostream>
5#include <vector>
6#include <map>
7#include <string>
8#include <utility>
9#include <functional>
10#include "AmpGen/MsgService.h"
11#include "AmpGen/MetaUtils.h"
12
13namespace AmpGen {
14
15 class ConfigurableBase;
16
17 class OptionsParser {
18 public:
19 typedef std::map<std::string, std::vector<std::string>>::const_iterator const_iterator;
20 typedef std::map<std::string, std::vector<std::string>>::iterator iterator;
21
22 static OptionsParser *getMe();
23 static bool printHelp();
24 static void setArgs(int argc, char **argv, const std::string &description = "");
25 static void setArg(const std::string &arg);
26 void setQuiet();
27 void addArg(const std::string &arg);
28 void setCommandLineArgs(int argc, char **argv, const std::string &description = "");
29 void import(const std::string &fName);
30 iterator find(const std::string &name);
35 std::vector<std::vector<std::string>> getInputOrdered() const;
36
37 const std::vector<const ConfigurableBase *> &configurables() const { return m_configurables; }
38 template <typename T> T *registerClass(T *object) {
39 DEBUG("Registering -> " << type_string<T>());
40 addToConfigurables(object);
41 return object;
42 }
43 void print() const;
45
46 private:
47 std::vector<std::string> m_orderedKeys;
48 std::map<std::string, std::vector<std::string>> m_parsedLines;
49 std::map<std::string, std::function<void(std::vector<std::string>)>> m_keywords;
50 std::vector<const ConfigurableBase *> m_configurables;
51
52 bool m_printHelp = {false};
53 bool m_quiet = {false};
54 static OptionsParser *gOptionsParser;
55
56 OptionsParser();
57 bool ignoreThisLine(const std::string &line);
58 void readStream(std::istream &is);
59 std::vector<std::string> makeParsedStrings(const std::string &line, int &braceDepth) const;
60 void addArg(const std::vector<std::string> &tokens);
61 };
62} // namespace AmpGen
63
64#define REGISTER_CONFIGURABLE(CLASS_NAME) template <> CLASS_NAME *Configurable<CLASS_NAME>::gImpl = OptionsParser::getMe()->registerClass(new CLASS_NAME())
65
66#endif
static OptionsParser * getMe()
std::map< std::string, std::vector< std::string > >::iterator iterator
iterator find(const std::string &name)
std::vector< std::vector< std::string > > getInputOrdered() const
std::map< std::string, std::vector< std::string > >::const_iterator const_iterator
static bool printHelp()
const_iterator end() const
const_iterator begin() const
T * registerClass(T *object)
static void setArg(const std::string &arg)
const std::vector< const ConfigurableBase * > & configurables() const
static void setArgs(int argc, char **argv, const std::string &description="")
void addArg(const std::string &arg)
void addToConfigurables(const ConfigurableBase *)
void setCommandLineArgs(int argc, char **argv, const std::string &description="")
#define DEBUG(X)
Used for printing verbose debugging messages, only if DEBUGLEVEL is defined.
Definition MsgService.h:69
bool is(const Expression &expression)
Definition Expression.h:485
std::string type_string()
Utility classes for compile-time metaprogramming, such as identifying the types of arguments for gene...
Definition MetaUtils.h:17