PetaVision  Alpha
Configuration.hpp
1 #ifndef CONFIGURATION_HPP_
2 #define CONFIGURATION_HPP_
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 
8 namespace PV {
9 
11  public:
12  struct IntOptional {
13  bool mUseDefault = false;
14  int mValue = -1;
15  };
16  enum ConfigurationType {
17  CONFIG_UNRECOGNIZED,
18  CONFIG_BOOL,
19  CONFIG_INT,
20  CONFIG_UNSIGNED,
21  CONFIG_STRING,
22  CONFIG_INT_OPTIONAL
23  };
24 
25  Configuration();
26  ~Configuration() {}
27 
32  ConfigurationType getType(std::string const &name) const;
33 
34  bool const &getBooleanArgument(std::string const &name) const;
35  int const &getIntegerArgument(std::string const &name) const;
36  unsigned int const &getUnsignedIntArgument(std::string const &name) const;
37  std::string const &getStringArgument(std::string const &name) const;
38  IntOptional const &getIntOptionalArgument(std::string const &name) const;
39 
40  static std::string printBooleanArgument(std::string const &name, bool const &value);
41 
42  static std::string printIntegerArgument(std::string const &name, int const &value);
43 
44  static std::string printUnsignedArgument(std::string const &name, unsigned int const &value);
45 
46  static std::string printStringArgument(std::string const &name, std::string const &value);
47 
48  static std::string printIntOptionalArgument(std::string const &name, IntOptional const &value);
49 
50  std::string printArgument(std::string const &name) const;
51 
52  std::string printConfig() const;
53 
54  bool setArgumentUsingString(std::string const &name, std::string const &value);
55  bool setBooleanArgument(std::string const &name, bool const &value);
56  bool setIntegerArgument(std::string const &name, int const &value);
57  bool setUnsignedIntArgument(std::string const &name, unsigned int const &value);
58  bool setStringArgument(std::string const &name, std::string const &value);
59  bool setIntOptionalArgument(std::string const &name, IntOptional const &value);
60 
61  private:
62  void registerArgument(std::string const &name, ConfigurationType type);
63  void registerBooleanArgument(std::string const &name);
64  void registerIntegerArgument(std::string const &name);
65  void registerUnsignedIntArgument(std::string const &name);
66  void registerStringArgument(std::string const &name);
67  void registerIntOptionalArgument(std::string const &name);
68 
69  bool parseBoolean(std::string const &valueString) const;
70  int parseInteger(std::string const &valueString) const;
71  unsigned int parseUnsignedInt(std::string const &valueString) const;
72  std::string parseString(std::string const &valueString) const;
73  IntOptional parseIntOptional(std::string const &valueString) const;
74 
75  // Data members
76  private:
77  std::vector<std::string> mConfigArguments;
78  std::map<std::string, ConfigurationType> mConfigTypeMap;
79  std::map<std::string, bool> mBooleanConfigMap;
80  std::map<std::string, int> mIntegerConfigMap;
81  std::map<std::string, unsigned int> mUnsignedIntConfigMap;
82  std::map<std::string, std::string> mStringConfigMap;
83  std::map<std::string, IntOptional> mIntOptionalConfigMap;
84 }; // end class Configuration
85 
86 } // end namespace PV
87 
88 #endif // CONFIGURATION_HPP_
ConfigurationType getType(std::string const &name) const