X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=include%2Fargument.h;h=bf5fc3354f304c7b894252069969451275ec7fff;hb=e8acdc5555d6e3e726ba689eb0454b870deb5871;hp=dfaea65cea9b4ba6d5d54dd39c000ee79b8ad19e;hpb=68461ce43951a67646427c05ba94a960dcfa0a55;p=command.git diff --git a/include/argument.h b/include/argument.h index dfaea65..bf5fc33 100644 --- a/include/argument.h +++ b/include/argument.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "parameter.h" #include "callable.h" @@ -14,9 +15,9 @@ namespace command { * Arguments are non-named parameters of program. * * Example: - * ./myprog ARGUMENT - * ./myprog /path/to/file - * ./myprog "some argument" + * - ./myprog ARGUMENT + * - ./myprog /path/to/file + * - ./myprog "some argument" */ template class Argument : public Parameter, public Callable { @@ -31,7 +32,7 @@ namespace command { * @param description Description of current Argument * @param function Function used to handle current Argument. */ - Argument(const std::string & description, void (*function)(ParameterType)) + Argument(const std::string & description, std::function function) : Parameter(description), Callable(function) { } @@ -41,10 +42,11 @@ namespace command { virtual ~Argument() { } /** - * + * \inheritdoc */ virtual void handle() { this->call(value); + this->used = true; } /** @@ -64,20 +66,24 @@ namespace command { * against next value. */ virtual bool understand(const std::string & argv) { - if (!isUsed()) { - std::stringstream ss; + std::stringstream ss; - ss << argv; - ss >> value; + ss << std::fixed << argv; + ss >> value; - if (!ss.fail()) { - this->used = true; - return true; - } + if (!ss.fail()) { + return true; } return false; } + + /** + * \inheritdoc + */ + virtual unsigned int valuePosition(const std::string & ) { + return 0; + } }; }