From 56957154bf5f7dfc6005d689347df96276e4b51d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Sun, 26 Apr 2015 13:59:03 +0200 Subject: [PATCH] Small documentation improvements. Added possibility to pass user values for Parameters. --- include/command.h | 36 +++++++++++++++++++++++++++--------- include/parameter.h | 10 +++++++--- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/include/command.h b/include/command.h index 9cf0a9f..a48ab91 100644 --- a/include/command.h +++ b/include/command.h @@ -13,29 +13,47 @@ namespace command { */ class Command { protected: - unsigned int argc; - std::vector _argv; std::vector args; public: /** * Default constructor. * - * @param - * @param - * @param + * @param argc passed to the main function + * @param argv passed to the main function + * @param params initializer_list containing Parameter handlers + * responsible for correctly handle user data. */ Command(unsigned int argc, char *argv[], std::initializer_list params) : args(params) { - for(Parameter *param : params) { - param->handle(); - } + + matchArguments(argc, argv); + invoke(); } - + + /** + * Destructor. Releases allocated memory. + */ ~Command() { for (Parameter * parameter : args) { delete parameter; } } + protected: + /** + * Matches user passed arguments with available parameter handlers. + */ + void matchArguments(unsigned int argc, char *argv[]) { +// param->passUserValue(); + } + + /** + * Invokes passed parameter handlers + */ + void invoke() { + for(Parameter *param : params) { + param->handle(); + } + } }; } diff --git a/include/parameter.h b/include/parameter.h index 9e25086..e55a2d1 100644 --- a/include/parameter.h +++ b/include/parameter.h @@ -15,6 +15,8 @@ namespace command { * ./myprog ARGUMENT */ class Parameter : public Descriptive { + protected: + std:string userValue; public: typedef class Parameter Type; /** @@ -27,9 +29,11 @@ namespace command { } virtual ~Parameter() {} - virtual void handle() { - std::cout << "Parameter::handle()" << std::endl; - }; + virtual void handle() = 0; + + virtual void passUserValue(std::string argVal) { + userValue = argVal; + } }; } -- 2.30.2