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 
227  static CLI& GetSingleton();
228 
236  static void RegisterProgramDoc(util::ProgramDoc* doc);
237 
239  static std::map<std::string, util::ParamData>& Parameters();
241  static std::map<char, std::string>& Aliases();
242 
244  static std::string ProgramName();
245 
251  static void SetPassed(const std::string& name);
252 
261  static void StoreSettings(const std::string& name);
262 
272  static void RestoreSettings(const std::string& name, const bool fatal = true);
273 
277  static void ClearSettings();
278 
279  private:
281  std::map<char, std::string> aliases;
283  std::map<std::string, util::ParamData> parameters;
284 
285  public:
288  typedef std::map<std::string, std::map<std::string,
289  void (*)(const util::ParamData&, const void*, void*)>> FunctionMapType;
291 
292  private:
294  std::map<std::string, std::tuple<std::map<std::string, util::ParamData>,
295  std::map<char, std::string>, FunctionMapType>> storageMap;
296 
297  public:
299  bool didParse;
300 
303  std::string programName;
304 
307 
309  friend class Timer;
310 
313 
314  private:
318  CLI();
319 
321  CLI(const CLI& other);
323  CLI& operator=(const CLI& other);
324 };
325 
326 } // namespace mlpack
327 
328 // Include the actual definitions of templated methods
329 #include "cli_impl.hpp"
330 
331 #endif
bool didParse
True, if CLI was used to parse command line options.
Definition: cli.hpp:299
.hpp
Definition: add_to_po.hpp:21
The core includes that mlpack expects; standard C++ includes and Armadillo.
Timers timer
Holds the timer objects.
Definition: cli.hpp:306
std::string programName
Holds the name of the program for –version.
Definition: cli.hpp:303
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:312
std::map< std::string, std::map< std::string, void(*)(const util::ParamData &, const void *, void *)> > FunctionMapType
Map for functions and types.
Definition: cli.hpp:289
T & GetParam(util::ParamData &d, const typename boost::disable_if< arma::is_arma_type< T >>::type *=0, const typename boost::disable_if< data::HasSerialize< T >>::type *=0, const typename boost::disable_if< std::is_same< T, std::tuple< mlpack::data::DatasetInfo, arma::mat >>>::type *=0)
This overload is called when nothing special needs to happen to the name of the parameter.
Definition: get_param.hpp:29
std::string GetPrintableParam(const util::ParamData &data, const typename boost::disable_if< arma::is_arma_type< T >>::type *=0, const typename boost::disable_if< util::IsStdVector< T >>::type *=0, const typename boost::disable_if< data::HasSerialize< T >>::type *=0, const typename boost::disable_if< std::is_same< T, std::tuple< data::DatasetInfo, arma::mat >>>::type *=0)
Print an option.
T & GetRawParam(util::ParamData &d, const typename boost::disable_if< arma::is_arma_type< T >>::type *=0, const typename boost::disable_if< data::HasSerialize< T >>::type *=0, const typename boost::disable_if< std::is_same< T, std::tuple< mlpack::data::DatasetInfo, arma::mat >>>::type *=0)
This overload is called when nothing special needs to happen to the name of the parameter.
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
FunctionMapType functionMap
Definition: cli.hpp:290