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 
248  static void RegisterProgramDoc(util::ProgramDoc* doc);
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 
315  std::string programName;
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
bool didParse
True, if CLI was used to parse command line options.
Definition: cli.hpp:311
Linear algebra utility functions, generally performed on matrices or vectors.
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:318
std::string programName
Holds the name of the program for –version.
Definition: cli.hpp:315
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
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
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:302