mlpack  3.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cli.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_CORE_UTIL_CLI_HPP
15 #define MLPACK_CORE_UTIL_CLI_HPP
16 
17 #include <list>
18 #include <iostream>
19 #include <map>
20 #include <string>
21 
22 #include <boost/any.hpp>
23 
24 #include <mlpack/prereqs.hpp>
25 
26 #include "timers.hpp"
27 #include "program_doc.hpp"
28 #include "version.hpp"
29 
30 #include "param_data.hpp"
31 
32 namespace mlpack {
33 namespace util {
34 
35 // Externally defined in option.hpp, this class holds information about the
36 // program being run.
37 class ProgramDoc;
38 
39 } // namespace util
40 
166 class CLI
167 {
168  public:
175  static void Add(util::ParamData&& d);
176 
182  static bool HasParam(const std::string& identifier);
183 
190  template<typename T>
191  static T& GetParam(const std::string& identifier);
192 
201  template<typename T>
202  static std::string GetPrintableParam(const std::string& identifier);
203 
213  template<typename T>
214  static T& GetRawParam(const std::string& identifier);
215 
225  static void MakeInPlaceCopy(const std::string& outputParamName,
226  const std::string& inputParamName);
227 
239  static CLI& GetSingleton();
240 
249 
251  static std::map<std::string, util::ParamData>& Parameters();
253  static std::map<char, std::string>& Aliases();
254 
256  static std::string ProgramName();
257 
263  static void SetPassed(const std::string& name);
264 
273  static void StoreSettings(const std::string& name);
274 
284  static void RestoreSettings(const std::string& name, const bool fatal = true);
285 
289  static void ClearSettings();
290 
291  private:
293  std::map<char, std::string> aliases;
295  std::map<std::string, util::ParamData> parameters;
296 
297  public:
300  typedef std::map<std::string, std::map<std::string,
301  void (*)(const util::ParamData&, const void*, void*)>> FunctionMapType;
303 
304  private:
306  std::map<std::string, std::tuple<std::map<std::string, util::ParamData>,
307  std::map<char, std::string>, FunctionMapType>> storageMap;
308 
309  public:
311  bool didParse;
312 
316 
319 
321  friend class Timer;
322 
325 
326  private:
330  CLI();
331 
333  CLI(const CLI& other);
335  CLI& operator=(const CLI& other);
336 };
337 
338 } // namespace mlpack
339 
340 // Include the actual definitions of templated methods
341 #include "cli_impl.hpp"
342 
343 #endif
static void SetPassed(const std::string &name)
Mark a particular parameter as passed.
bool didParse
True, if CLI was used to parse command line options.
Definition: cli.hpp:311
static CLI & GetSingleton()
Retrieve the singleton.
static void RegisterProgramDoc(util::ProgramDoc *doc)
Registers a ProgramDoc object, which contains documentation about the program.
static void StoreSettings(const std::string &name)
Take all parameters and function mappings and store them, under the given name.
The core includes that mlpack expects; standard C++ includes and Armadillo.
static T & GetRawParam(const std::string &identifier)
Get the raw value of the parameter before any processing that GetParam() might normally do...
static std::string GetPrintableParam(const std::string &identifier)
Cast the given parameter of the given type to a short, printable std::string, for use in status messa...
Timers timer
Holds the timer objects.
Definition: cli.hpp:318
std::string programName
Holds the name of the program for –version.
Definition: cli.hpp:315
static std::string ProgramName()
Get the program name as set by the PROGRAM_INFO() macro.
static std::map< std::string, util::ParamData > & Parameters()
Return a modifiable list of parameters that CLI knows about.
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
The timer class provides a way for mlpack methods to be timed.
Definition: timers.hpp:45
util::ProgramDoc * doc
Pointer to the ProgramDoc object.
Definition: cli.hpp:324
static void ClearSettings()
Clear all of the settings, removing all parameters and function mappings.
static void MakeInPlaceCopy(const std::string &outputParamName, const std::string &inputParamName)
Given two (matrix) parameters, ensure that the first is an in-place copy of the second.
static T & GetParam(const std::string &identifier)
Get the value of type T found while parsing.
std::map< std::string, std::map< std::string, void(*)(const util::ParamData &, const void *, void *)> > FunctionMapType
Map for functions and types.
Definition: cli.hpp:301
static void Add(util::ParamData &&d)
Adds a parameter to the hierarchy; use the PARAM_*() macros instead of this (i.e. ...
static std::map< char, std::string > & Aliases()
Return a modifiable list of aliases that CLI knows about.
A static object whose constructor registers program documentation with the CLI class.
Definition: program_doc.hpp:26
Parses the command line for parameters and holds user-specified parameters.
Definition: cli.hpp:166
string(REGEX REPLACE".*#define MLPACK_VERSION_MINOR ([0-9]+).*""\\1"MLPACK_VERSION_MINOR"${VERSION_HPP_CONTENTS}") string(REGEX REPLACE".* "\\1" MLPACK_VERSION_PATCH "$
Definition: CMakeLists.txt:56
static void RestoreSettings(const std::string &name, const bool fatal=true)
Restore all of the parameters and function mappings of the given name, if they exist.
static bool HasParam(const std::string &identifier)
See if the specified flag was found while parsing.
FunctionMapType functionMap
Definition: cli.hpp:302