From 1fb7bf70d04d24cbb0c1789a3c5125aadeb8b158 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Sat, 2 May 2015 18:22:18 +0200 Subject: [PATCH] Parameter inheritance fixes. --- include/argument.h | 5 ++++- include/descriptive.h | 2 +- include/option.h | 17 +++++++++++------ include/parameter.h | 16 +++++++++------- 4 files changed, 25 insertions(+), 15 deletions(-) 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; }; } -- 2.30.2