16 #ifndef __MLPACK_CORE_UTIL_CLI_HPP 17 #define __MLPACK_CORE_UTIL_CLI_HPP 24 #include <boost/any.hpp> 25 #include <boost/program_options.hpp> 46 #define PROGRAM_INFO(NAME, DESC) static mlpack::util::ProgramDoc \ 47 io_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, DESC); 66 #define PARAM_FLAG(ID, DESC, ALIAS) \ 67 PARAM_FLAG_INTERNAL(ID, DESC, ALIAS); 90 #define PARAM_INT(ID, DESC, ALIAS, DEF) \ 91 PARAM(int, ID, DESC, ALIAS, DEF, false) 114 #define PARAM_FLOAT(ID, DESC, ALIAS, DEF) \ 115 PARAM(float, ID, DESC, ALIAS, DEF, false) 138 #define PARAM_DOUBLE(ID, DESC, ALIAS, DEF) \ 139 PARAM(double, ID, DESC, ALIAS, DEF, false) 163 #define PARAM_STRING(ID, DESC, ALIAS, DEF) \ 164 PARAM(std::string, ID, DESC, ALIAS, DEF, false) 187 #define PARAM_VECTOR(T, ID, DESC, ALIAS) \ 188 PARAM(std::vector<T>, ID, DESC, ALIAS, std::vector<T>(), false) 212 #define PARAM_INT_REQ(ID, DESC, ALIAS) PARAM(int, ID, DESC, ALIAS, 0, true) 236 #define PARAM_FLOAT_REQ(ID, DESC, ALIAS) PARAM(float, ID, DESC, ALIAS, 0.0f, \ 259 #define PARAM_DOUBLE_REQ(ID, DESC, ALIAS) PARAM(double, ID, DESC, ALIAS, \ 282 #define PARAM_STRING_REQ(ID, DESC, ALIAS) PARAM(std::string, ID, DESC, \ 305 #define PARAM_VECTOR_REQ(T, ID, DESC, ALIAS) PARAM(std::vector<T>, ID, DESC, \ 306 ALIAS, std::vector<T>(), true); 315 #define JOIN(x, y) JOIN_AGAIN(x, y) 316 #define JOIN_AGAIN(x, y) x ## y 334 #define PARAM(T, ID, DESC, ALIAS, DEF, REQ) static mlpack::util::Option<T> \ 335 JOIN(io_option_dummy_object_, __COUNTER__) \ 336 (false, DEF, ID, DESC, ALIAS, REQ); 339 #define PARAM_FLAG_INTERNAL(ID, DESC, ALIAS) static \ 340 mlpack::util::Option<bool> JOIN(__io_option_flag_object_, __COUNTER__) \ 349 #define PARAM(T, ID, DESC, ALIAS, DEF, REQ) static mlpack::util::Option<T> \ 350 JOIN(JOIN(io_option_dummy_object_, __LINE__), opt) (false, DEF, ID, \ 354 #define PARAM_FLAG_INTERNAL(ID, DESC, ALIAS) static \ 355 mlpack::util::Option<bool> JOIN(__io_option_flag_object_, __LINE__) \ 364 #define TYPENAME(x) (std::string(typeid(x).name())) 366 namespace po = boost::program_options;
537 static void Add(
const std::string& path,
538 const std::string& description,
539 const std::string& alias =
"",
540 bool required =
false);
554 static void Add(
const std::string& identifier,
555 const std::string& description,
556 const std::string& alias =
"",
557 bool required =
false);
566 static void AddFlag(
const std::string& identifier,
567 const std::string& description,
568 const std::string& alias =
"");
574 static void DefaultMessages();
581 static void Destroy();
590 static T& GetParam(
const std::string& identifier);
598 static std::string GetDescription(
const std::string& identifier);
612 static CLI& GetSingleton();
619 static bool HasParam(
const std::string& identifier);
628 static std::string HyphenateString(
const std::string& str,
int padding);
636 static void ParseCommandLine(
int argc,
char** argv);
643 static void RemoveDuplicateFlags(po::basic_parsed_options<char>& bpo);
650 static void ParseStream(std::istream& stream);
660 static void PrintHelp(
const std::string& param =
"");
687 typedef std::map<std::string, ParamData>
gmap_t;
691 typedef std::map<std::string, std::string>
amap_t;
720 static void AddAlias(
const std::string& alias,
const std::string& original);
729 static std::string AliasReverseLookup(
const std::string& value);
737 void FileTimeToTimeVal(timeval* tv);
745 static void RequiredOptions();
754 static std::string SanitizeString(
const std::string& str);
759 static void UpdateGmap();
771 CLI(
const std::string& optionsName);
780 #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.