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>
53 #define PROGRAM_INFO(NAME, DESC) static mlpack::util::ProgramDoc \
54 io_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, DESC);
73 #define PARAM_FLAG(ID, DESC, ALIAS) \
74 PARAM_FLAG_INTERNAL(ID, DESC, ALIAS);
97 #define PARAM_INT(ID, DESC, ALIAS, DEF) \
98 PARAM(int, ID, DESC, ALIAS, DEF, false)
121 #define PARAM_FLOAT(ID, DESC, ALIAS, DEF) \
122 PARAM(float, ID, DESC, ALIAS, DEF, false)
145 #define PARAM_DOUBLE(ID, DESC, ALIAS, DEF) \
146 PARAM(double, ID, DESC, ALIAS, DEF, false)
170 #define PARAM_STRING(ID, DESC, ALIAS, DEF) \
171 PARAM(std::string, ID, DESC, ALIAS, DEF, false)
194 #define PARAM_VECTOR(T, ID, DESC, ALIAS) \
195 PARAM(std::vector<T>, ID, DESC, ALIAS, std::vector<T>(), false)
219 #define PARAM_INT_REQ(ID, DESC, ALIAS) PARAM(int, ID, DESC, ALIAS, 0, true)
243 #define PARAM_FLOAT_REQ(ID, DESC, ALIAS) PARAM(float, ID, DESC, ALIAS, 0.0f, \
266 #define PARAM_DOUBLE_REQ(ID, DESC, ALIAS) PARAM(double, ID, DESC, ALIAS, \
289 #define PARAM_STRING_REQ(ID, DESC, ALIAS) PARAM(std::string, ID, DESC, \
312 #define PARAM_VECTOR_REQ(T, ID, DESC, ALIAS) PARAM(std::vector<T>, ID, DESC, \
313 ALIAS, std::vector<T>(), true);
322 #define JOIN(x, y) JOIN_AGAIN(x, y)
323 #define JOIN_AGAIN(x, y) x ## y
341 #define PARAM(T, ID, DESC, ALIAS, DEF, REQ) static mlpack::util::Option<T> \
342 JOIN(io_option_dummy_object_, __COUNTER__) \
343 (false, DEF, ID, DESC, ALIAS, REQ);
346 #define PARAM_FLAG_INTERNAL(ID, DESC, ALIAS) static \
347 mlpack::util::Option<bool> JOIN(__io_option_flag_object_, __COUNTER__) \
356 #define PARAM(T, ID, DESC, ALIAS, DEF, REQ) static mlpack::util::Option<T> \
357 JOIN(JOIN(io_option_dummy_object_, __LINE__), opt) (false, DEF, ID, \
361 #define PARAM_FLAG_INTERNAL(ID, DESC, ALIAS) static \
362 mlpack::util::Option<bool> JOIN(__io_option_flag_object_, __LINE__) \
371 #define TYPENAME(x) (std::string(typeid(x).name()))
373 namespace po = boost::program_options;
544 static void Add(
const std::string& path,
545 const std::string& description,
546 const std::string& alias =
"",
547 bool required =
false);
561 static void Add(
const std::string& identifier,
562 const std::string& description,
563 const std::string& alias =
"",
564 bool required =
false);
573 static void AddFlag(
const std::string& identifier,
574 const std::string& description,
575 const std::string& alias =
"");
597 static T&
GetParam(
const std::string& identifier);
626 static bool HasParam(
const std::string& identifier);
635 static std::string
HyphenateString(
const std::string& str,
int padding);
667 static void PrintHelp(
const std::string& param =
"");
694 typedef std::map<std::string, ParamData>
gmap_t;
698 typedef std::map<std::string, std::string>
amap_t;
724 static void AddAlias(
const std::string& alias,
const std::string& original);
741 void FileTimeToTimeVal(timeval* tv);
775 CLI(
const std::string& optionsName);
784 #include "cli_impl.hpp"
std::map< std::string, ParamData > gmap_t
Map of global values.
static T & GetParam(const std::string &identifier)
Grab the value of type T found while parsing.
CLI()
Make the constructor private, to preclude unauthorized instances.
static void ParseStream(std::istream &stream)
Parses a stream for arguments.
boost::any value
The actual value of this parameter.
static void AddFlag(const std::string &identifier, const std::string &description, const std::string &alias="")
Adds a flag parameter to the hierarchy; use PARAM_FLAG() instead of this.
std::list< std::string > requiredOptions
Pathnames of required options.
static void Print()
Print out the current hierarchy.
static void Destroy()
Destroy the CLI object.
static void PrintHelp(const std::string ¶m="")
Print out the help info of the hierarchy.
static CLI & GetSingleton()
Retrieve the singleton.
po::variables_map vmap
Values of the options given by user.
std::string desc
Description of this parameter, if any.
static std::string SanitizeString(const std::string &str)
Cleans up input pathnames, rendering strings such as /foo/bar and foo/bar/ equivalent inputs...
Timers timer
Holds the timer objects.
static void UpdateGmap()
Parses the values given on the command line, overriding any default values.
bool isFlag
True if the wasPassed value should not be ignored.
util::ProgramDoc * doc
Pointer to the ProgramDoc object.
static std::string AliasReverseLookup(const std::string &value)
Returns an alias, if given the name of the original.
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.
static void ParseCommandLine(int argc, char **argv)
Parses the commandline for arguments.
static void RegisterProgramDoc(util::ProgramDoc *doc)
Registers a ProgramDoc object, which contains documentation about the program.
static void RequiredOptions()
Checks that all required parameters have been specified on the command line.
static void RemoveDuplicateFlags(po::basic_parsed_options< char > &bpo)
Removes duplicate flags.
static void Add(const std::string &path, const std::string &description, const std::string &alias="", bool required=false)
Adds a parameter to the hierarchy; use the PARAM_*() macros instead of this (i.e. ...
static void AddAlias(const std::string &alias, const std::string &original)
Maps a given alias to a given parameter.
Aids in the extensibility of CLI by focusing potential changes into one structure.
static CLI * singleton
The singleton itself.
static void DefaultMessages()
Parses the parameters for 'help' and 'info'.
static bool HasParam(const std::string &identifier)
See if the specified flag was found while parsing.
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.
static std::string GetDescription(const std::string &identifier)
Get the description of the specified node.
std::string tname
Type information of this parameter.
static std::string HyphenateString(const std::string &str, int padding)
Hyphenate a string or split it onto multiple 80-character lines, with some amount of padding on each ...
A static object whose constructor registers program documentation with the CLI class.
Parses the command line for parameters and holds user-specified parameters.