PetaVision  Alpha
ConfigParser.hpp
1 #ifndef CONFIGPARSER_HPP_
2 #define CONFIGPARSER_HPP_
3 
4 #include "io/Configuration.hpp"
5 #include <istream>
6 #include <string>
7 
8 namespace PV {
9 
21 class ConfigParser {
22  public:
31  ConfigParser(std::istream &configStream, bool allowUnrecognizedArguments);
32 
36  bool getAllowUnrecognizedArguments() const { return mAllowUnrecognizedArguments; }
37 
44  bool const &getBooleanArgument(std::string const &name) const {
45  return mConfig.getBooleanArgument(name);
46  }
47 
54  int const &getIntegerArgument(std::string const &name) const {
55  return mConfig.getIntegerArgument(name);
56  }
57 
64  unsigned int const &getUnsignedIntArgument(std::string const &name) const {
65  return mConfig.getUnsignedIntArgument(name);
66  }
67 
74  std::string getStringArgument(std::string const &name) const {
75  return mConfig.getStringArgument(name);
76  }
77 
84  Configuration::IntOptional getIntOptionalArgument(std::string const &name) const {
85  return mConfig.getIntOptionalArgument(name);
86  }
87 
93  std::string printConfig() const { return mConfig.printConfig(); }
94 
95  static std::string createString(
96  bool requireReturnFlag,
97  std::string const &outputPath,
98  std::string const &paramsFile,
99  std::string const &logFile,
100  std::string const &gpuDevices,
101  unsigned int randomSeed,
102  std::string const &workingDir,
103  bool restartFlag,
104  std::string const &checkpointReadDir,
105  bool useDefaultNumThreads,
106  int numThreads,
107  int numRows,
108  int numColumns,
109  int batchWidth,
110  bool dryRunFlag);
111 
115  Configuration const &getConfig() const { return mConfig; }
116 
117  private:
152  void initialize(std::istream &inputStream, bool allowUnrecognizedArguments);
153 
158  void handleUnrecognized(std::string const &argument, std::string const &value, int linenumber);
159 
165  std::string stripLeadingTrailingWhitespace(std::string const &inString);
166 
167  private:
168  bool mAllowUnrecognizedArguments = false;
169  Configuration mConfig;
170 };
171 
172 } // end namespace PV
173 
174 #endif // CONFIGPARSER_HPP_
ConfigParser(std::istream &configStream, bool allowUnrecognizedArguments)
unsigned int const & getUnsignedIntArgument(std::string const &name) const
void initialize(std::istream &inputStream, bool allowUnrecognizedArguments)
bool const & getBooleanArgument(std::string const &name) const
int const & getIntegerArgument(std::string const &name) const
std::string printConfig() const
bool getAllowUnrecognizedArguments() const
std::string getStringArgument(std::string const &name) const
Configuration const & getConfig() const
Configuration::IntOptional getIntOptionalArgument(std::string const &name) const
std::string stripLeadingTrailingWhitespace(std::string const &inString)
void handleUnrecognized(std::string const &argument, std::string const &value, int linenumber)