X-Git-Url: https://git.dlugolecki.net.pl/?p=command.git;a=blobdiff_plain;f=include%2Fargument.h;h=2cd3c300f970a8d2e205de7685a6f10fd9ad241d;hp=dfaea65cea9b4ba6d5d54dd39c000ee79b8ad19e;hb=ae6743a2a2c69b7a927f64ff1d3abf38a5e7d4bc;hpb=68461ce43951a67646427c05ba94a960dcfa0a55 diff --git a/include/argument.h b/include/argument.h index dfaea65..2cd3c30 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 { @@ -35,16 +36,21 @@ namespace command { : Parameter(description), Callable(function) { } + Argument(const std::string & description, std::function function) + : Parameter(description), Callable(function) { + } + /** * */ virtual ~Argument() { } /** - * + * \inheritdoc */ virtual void handle() { this->call(value); + this->used = true; } /** @@ -64,20 +70,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; + } }; }