From: Rafał Długołęcki Date: Sun, 26 Apr 2015 11:59:03 +0000 (+0200) Subject: Small documentation improvements. Added possibility to pass user values for Parameters. X-Git-Tag: v0.2~41 X-Git-Url: https://git.dlugolecki.net.pl/?p=command.git;a=commitdiff_plain;h=56957154bf5f7dfc6005d689347df96276e4b51d Small documentation improvements. Added possibility to pass user values for Parameters. --- 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; + } }; }