From: Rafał Długołęcki Date: Sat, 2 May 2015 16:22:18 +0000 (+0200) Subject: Parameter inheritance fixes. X-Git-Tag: v0.2~36 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=1fb7bf70d04d24cbb0c1789a3c5125aadeb8b158;p=command.git Parameter inheritance fixes. --- diff --git a/include/argument.h b/include/argument.h index 70d83c7..eee218f 100644 --- a/include/argument.h +++ b/include/argument.h @@ -31,9 +31,12 @@ namespace command { virtual ~Argument() { } virtual void handle() { - std::cout << "Argument::handle()" << std::endl; this->call(std::string("A")); } + + virtual bool understand(const std::string &) { + return false; + } }; } diff --git a/include/descriptive.h b/include/descriptive.h index d93c931..08be41e 100644 --- a/include/descriptive.h +++ b/include/descriptive.h @@ -15,7 +15,7 @@ namespace command { * * @param description Description */ - Descriptive(std::string description) + Descriptive(const std::string& description) : description(description) { } diff --git a/include/option.h b/include/option.h index fef4e31..3cba30f 100644 --- a/include/option.h +++ b/include/option.h @@ -3,7 +3,7 @@ #include -#include "argument.h" +#include "parameter.h" namespace command { /** @@ -15,9 +15,7 @@ namespace command { */ template class Option - : public Argument { - public: -// typedef typename Argument::FunctionType FunctionType; + : public Parameter, public Callable { protected: /** * Option name @@ -33,14 +31,21 @@ namespace command { * @param function Function used to handle current Option. */ Option(std::string name, std::string description, void (*function)(OptionType)) - : name(name), Argument(description, function) { + : Parameter(description), Callable(function) { } virtual ~Option() { } virtual void handle() { - std::cout << "Option::handle()" << std::endl; this->call(std::string("O")); } + + virtual bool understand(std::string argVal) { + if (argVal.find(name) != std::string::npos) { + return true; + } + + return false; + } }; } diff --git a/include/parameter.h b/include/parameter.h index 5ca4931..3f5cfaa 100644 --- a/include/parameter.h +++ b/include/parameter.h @@ -8,15 +8,12 @@ namespace command { /** - * Class responsible for handling commandline arguments. - * Arguments are required,x non-named parameters of program. + * Base class for all the Arguments and Options. * * Example: * ./myprog ARGUMENT */ class Parameter : public Descriptive { - protected: - std::string userValue; public: typedef class Parameter Type; /** @@ -29,11 +26,16 @@ namespace command { } virtual ~Parameter() {} + /** + * Method used for handling method calls linked with Argument or Option + */ virtual void handle() = 0; - virtual void passUserValue(std::string argVal) { - userValue = argVal; - } + /** + * Method used for checking if the given user value understandable for + * parameter. + */ + virtual bool understand(std::string argVal) = 0; }; }