From 638b210134daa5d4ecd207e003241a4edb7234dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Wed, 22 Apr 2015 01:18:35 +0200 Subject: [PATCH] Added Argument template class --- include/argument.h | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 include/argument.h diff --git a/include/argument.h b/include/argument.h new file mode 100644 index 0000000..6a292b4 --- /dev/null +++ b/include/argument.h @@ -0,0 +1,49 @@ +#ifndef __COMMAND_ARGUMENT_H +#define __COMMAND_ARGUMENT_H + +#include + +#include + +namespace command { + /** + * Class responsible for handling commandline arguments. + * Arguments are required non-named parameters for program. + * + * Example: + * ./myprog ARGUMENT + */ + template + class Argument : public Descriptive { + public: + typedef void (*)(ArgumentType) FunctionType; + + protected: + /** + * Function handling user Arguments + */ + FunctionType function; + + public: + /** + * Default constructor. + * + * @param description Description of current Argument + * @param function Function used to handle current Argument. + */ + Argument(std::string description, FunctionType function) + : Descriptive(description), function(function) { + } + + /** + * Executes command binded with argument + * + * @param value Value passed to program argument + */ + void run(ArgumentType value) { + this->function(value); + } + }; +} + +#endif /* __COMMAND_ARGUMENT_H */ -- 2.30.2