28 #ifndef __CMD_ARGUMENTS__
29 #define __CMD_ARGUMENTS__
38 #include "boost/utility/value_init.hpp"
61 boost::value_initialized<T> value;
62 return getArg<T>(
name, value, isFatal);
76 T getArg(
const std::string
name,
T default_value,
bool isFatal =
false) {
77 T value = default_value;
79 value = this->arg<T>(
name);
82 std::ostringstream exe;
83 exe <<
"Fatal: argument \"";
85 exe <<
"\" not found!";
89 std::ostringstream
warn;
90 warn <<
"\033[01;35m";
91 warn <<
"Warning: argument \"";
93 warn <<
"\" not found! Using default value (";
94 warn << default_value;
97 std::cout << warn.str() << std::flush;
108 std::ostringstream oss;
113 "Argument '" + name +
"' exists");
116 arguments_.insert(std::make_pair(name, oss.str()));
121 std::ostringstream oss;
125 arguments_.insert(std::make_pair(name, oss.str()));
167 void split(std::string &
name, std::string &value, std::string
arg);
192 inline std::string CmdArguments::arg<std::string>(
const std::string
name) {
194 if(it != arguments_.end()) {
195 return arguments_[
name];
T getArg(const std::string name, bool isFatal=false)
void addArgument(const std::string &name, const T &value)
unsigned int getNumArguments() const
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
std::map< std::string, std::string > arguments_
container for storing command line options
void replaceArgument(const std::string &name, const T &value)
Inform & endl(Inform &inf)
void split(std::string &name, std::string &value, std::string arg)
helper to split string
void addArguments(int argc, char **argv)
parse user arguments
std::string::iterator iterator
CmdArguments(int argc, char **argv)
std::shared_ptr< CmdArguments > CmdArguments_t
T getArg(const std::string name, T default_value, bool isFatal=false)
std::set< std::string > warned_
constexpr double e
The value of .
char ** getArguments() const
T arg(const std::string name)