mlpack  master
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 #include <boost/program_options.hpp>
24 
25 #include <mlpack/prereqs.hpp>
26 
27 #include "timers.hpp"
28 #include "cli_deleter.hpp" // To make sure we can delete the singleton.
29 #include "version.hpp"
30 #include "param.hpp"
31 
32 
33 #include "param_data.hpp"
34 #include "print_param.hpp"
35 #include "output_param.hpp"
36 #include "default_param.hpp"
37 #include "string_type_param.hpp"
38 
39 namespace po = boost::program_options;
40 
41 namespace mlpack {
42 namespace util {
43 
44 // Externally defined in option.hpp, this class holds information about the
45 // program being run.
46 class ProgramDoc;
47 
48 } // namespace util
49 
175 class CLI
176 {
177  public:
190  template<class T>
191  static void Add(const T& defaultValue,
192  const std::string& identifier,
193  const std::string& description,
194  const char alias = '\0',
195  const bool required = false,
196  const bool input = true,
197  const bool noTranspose = false);
198 
204  static void Destroy();
205 
212  template<typename T>
213  static T& GetParam(const std::string& identifier);
214 
224  template<typename T>
225  static typename util::ParameterType<T>::type& GetUnmappedParam(
226  const std::string& identifier);
227 
237  template<typename T>
238  static T& GetRawParam(const std::string& identifier);
239 
252  static CLI& GetSingleton();
253 
259  static bool HasParam(const std::string& identifier);
260 
268  static std::string HyphenateString(const std::string& str, int padding);
269 
276  static void ParseCommandLine(int argc, char** argv);
277 
282  static void PrintHelp(const std::string& param = "");
283 
291  static void RegisterProgramDoc(util::ProgramDoc* doc);
292 
296  ~CLI();
297 
298  private:
300  po::options_description desc;
301 
303  po::variables_map vmap;
304 
306  std::list<std::string> outputOptions;
308  std::list<std::string> requiredOptions;
310  std::map<char, std::string> aliases;
311 
313  std::map<std::string, util::ParamData> parameters;
314 
316  static CLI* singleton;
317 
319  bool didParse;
320 
324 
327 
329  friend class Timer;
330 
331  public:
334 
335  private:
342  static void AddAlias(const std::string& alias, const std::string& original);
343 
351  static char AliasReverseLookup(const std::string& value);
352 
356  CLI();
357 
359  CLI(const CLI& other);
360 
369  template<typename T>
370  void AddOption(
371  const char* optId,
372  const char* descr,
374  /* junk */ = 0);
375 
384  template<typename T>
385  void AddOption(
386  const char* optId,
387  const char* descr,
389  /* junk */ = 0);
390 };
391 
392 } // namespace mlpack
393 
394 // Include the actual definitions of templated methods
395 #include "cli_impl.hpp"
396 
397 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
std::list< std::string > requiredOptions
Convenience list of required options.
Definition: cli.hpp:308
The core includes that mlpack expects; standard C++ includes and Armadillo.
po::variables_map vmap
Values of the options given by user.
Definition: cli.hpp:303
std::map< std::string, util::ParamData > parameters
Map of parameters.
Definition: cli.hpp:313
Timers timer
Holds the timer objects.
Definition: cli.hpp:326
util::ProgramDoc * doc
Pointer to the ProgramDoc object.
Definition: cli.hpp:333
po::options_description desc
The documentation and names of options.
Definition: cli.hpp:300
The timer class provides a way for mlpack methods to be timed.
Definition: timers.hpp:38
Metaprogramming structure for vector detection.
Definition: param_data.hpp:25
std::list< std::string > outputOptions
Convenience list of output options.
Definition: cli.hpp:306
std::string programName
Holds the name of the program for –version.
Definition: cli.hpp:323
ParameterTypeDeducer< data::HasSerialize< T >::value, T >::type type
Definition: param_data.hpp:54
std::map< char, std::string > aliases
Convenience map from alias values to names.
Definition: cli.hpp:310
static CLI * singleton
The singleton itself.
Definition: cli.hpp:316
bool didParse
True, if CLI was used to parse command line options.
Definition: cli.hpp:319
test cpp RESULT_VARIABLE MEX_RESULT_TRASH OUTPUT_VARIABLE MEX_OUTPUT ERROR_VARIABLE MEX_ERROR_TRASH string(REGEX MATCH"Warning: You are using"MEX_WARNING"${MEX_OUTPUT}") if(MEX_WARNING) string(REGEX REPLACE".*using [a-zA-Z]* version \"([0-9.]*)[^\"]*\".*""\\1"OTHER_COMPILER_VERSION"$
Definition: CMakeLists.txt:18
A static object whose constructor registers program documentation with the CLI class.
Definition: option.hpp:71
Parses the command line for parameters and holds user-specified parameters.
Definition: cli.hpp:175
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:59