24 #ifndef __MLPACK_CORE_UTIL_CLI_HPP 25 #define __MLPACK_CORE_UTIL_CLI_HPP 32 #include <boost/any.hpp> 33 #include <boost/program_options.hpp> 54 #define PROGRAM_INFO(NAME, DESC) static mlpack::util::ProgramDoc \ 55 io_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, DESC); 74 #define PARAM_FLAG(ID, DESC, ALIAS) \ 75 PARAM_FLAG_INTERNAL(ID, DESC, ALIAS); 98 #define PARAM_INT(ID, DESC, ALIAS, DEF) \ 99 PARAM(int, ID, DESC, ALIAS, DEF, false) 122 #define PARAM_FLOAT(ID, DESC, ALIAS, DEF) \ 123 PARAM(float, ID, DESC, ALIAS, DEF, false) 146 #define PARAM_DOUBLE(ID, DESC, ALIAS, DEF) \ 147 PARAM(double, ID, DESC, ALIAS, DEF, false) 171 #define PARAM_STRING(ID, DESC, ALIAS, DEF) \ 172 PARAM(std::string, ID, DESC, ALIAS, DEF, false) 195 #define PARAM_VECTOR(T, ID, DESC, ALIAS) \ 196 PARAM(std::vector<T>, ID, DESC, ALIAS, std::vector<T>(), false) 220 #define PARAM_INT_REQ(ID, DESC, ALIAS) PARAM(int, ID, DESC, ALIAS, 0, true) 244 #define PARAM_FLOAT_REQ(ID, DESC, ALIAS) PARAM(float, ID, DESC, ALIAS, 0.0f, \ 267 #define PARAM_DOUBLE_REQ(ID, DESC, ALIAS) PARAM(double, ID, DESC, ALIAS, \ 290 #define PARAM_STRING_REQ(ID, DESC, ALIAS) PARAM(std::string, ID, DESC, \ 313 #define PARAM_VECTOR_REQ(T, ID, DESC, ALIAS) PARAM(std::vector<T>, ID, DESC, \ 314 ALIAS, std::vector<T>(), true); 323 #define JOIN(x, y) JOIN_AGAIN(x, y) 324 #define JOIN_AGAIN(x, y) x ## y 342 #define PARAM(T, ID, DESC, ALIAS, DEF, REQ) static mlpack::util::Option<T> \ 343 JOIN(io_option_dummy_object_, __COUNTER__) \ 344 (false, DEF, ID, DESC, ALIAS, REQ); 347 #define PARAM_FLAG_INTERNAL(ID, DESC, ALIAS) static \ 348 mlpack::util::Option<bool> JOIN(__io_option_flag_object_, __COUNTER__) \ 357 #define PARAM(T, ID, DESC, ALIAS, DEF, REQ) static mlpack::util::Option<T> \ 358 JOIN(JOIN(io_option_dummy_object_, __LINE__), opt) (false, DEF, ID, \ 362 #define PARAM_FLAG_INTERNAL(ID, DESC, ALIAS) static \ 363 mlpack::util::Option<bool> JOIN(__io_option_flag_object_, __LINE__) \ 372 #define TYPENAME(x) (std::string(typeid(x).name())) 374 namespace po = boost::program_options;
545 static void Add(
const std::string& path,
546 const std::string& description,
547 const std::string& alias =
"",
548 bool required =
false);
562 static void Add(
const std::string& identifier,
563 const std::string& description,
564 const std::string& alias =
"",
565 bool required =
false);
574 static void AddFlag(
const std::string& identifier,
575 const std::string& description,
576 const std::string& alias =
"");
582 static void DefaultMessages();
589 static void Destroy();
598 static T& GetParam(
const std::string& identifier);
606 static std::string GetDescription(
const std::string& identifier);
620 static CLI& GetSingleton();
627 static bool HasParam(
const std::string& identifier);
636 static std::string HyphenateString(
const std::string& str,
int padding);
644 static void ParseCommandLine(
int argc,
char** argv);
651 static void RemoveDuplicateFlags(po::basic_parsed_options<char>& bpo);
658 static void ParseStream(std::istream& stream);
668 static void PrintHelp(
const std::string& param =
"");
695 typedef std::map<std::string, ParamData>
gmap_t;
699 typedef std::map<std::string, std::string>
amap_t;
728 static void AddAlias(
const std::string& alias,
const std::string& original);
737 static std::string AliasReverseLookup(
const std::string& value);
745 void FileTimeToTimeVal(timeval* tv);
753 static void RequiredOptions();
762 static std::string SanitizeString(
const std::string& str);
767 static void UpdateGmap();
779 CLI(
const std::string& optionsName);
788 #include "cli_impl.hpp" std::map< std::string, ParamData > gmap_t
Map of global values.
Linear algebra utility functions, generally performed on matrices or vectors.
boost::any value
The actual value of this parameter.
std::list< std::string > requiredOptions
Pathnames of required options.
po::variables_map vmap
Values of the options given by user.
std::string desc
Description of this parameter, if any.
Timers timer
Holds the timer objects.
bool isFlag
True if the wasPassed value should not be ignored.
util::ProgramDoc * doc
Pointer to the ProgramDoc object.
po::options_description desc
The documentation and names of options.
std::string name
Name of this parameter.
The timer class provides a way for MLPACK methods to be timed.
std::string programName
Hold the name of the program for –version.
Aids in the extensibility of CLI by focusing potential changes into one structure.
static CLI * singleton
The singleton itself.
bool didParse
True, if CLI was used to parse command line options.
std::map< std::string, std::string > amap_t
Map for aliases, from alias to actual name.
bool wasPassed
True if this parameter was passed in via command line or file.
std::string tname
Type information of this parameter.
A static object whose constructor registers program documentation with the CLI class.
Parses the command line for parameters and holds user-specified parameters.