From: Rafał Długołęcki Date: Tue, 21 Apr 2015 23:18:35 +0000 (+0200) Subject: Added Argument template class X-Git-Tag: v0.2~46 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=638b210134daa5d4ecd207e003241a4edb7234dc;p=command.git Added Argument template class --- 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 */