Added Argument template class
[command.git] / include / argument.h
1 #ifndef __COMMAND_ARGUMENT_H
2 #define __COMMAND_ARGUMENT_H
3
4 #include <string>
5
6 #include <command/descriptive.h>
7
8 namespace command {
9     /**
10      * Class responsible for handling commandline arguments.
11      * Arguments are required non-named parameters for program.
12      *
13      * Example:
14      *  ./myprog ARGUMENT
15      */
16     template<typename ArgumentType>
17     class Argument : public Descriptive {
18     public:
19         typedef void (*)(ArgumentType) FunctionType;
20
21     protected:
22         /**
23          * Function handling user Arguments
24          */
25         FunctionType function;
26
27     public:
28         /**
29          * Default constructor.
30          *
31          * @param description Description of current Argument
32          * @param function Function used to handle current Argument.
33          */
34         Argument(std::string description, FunctionType function)
35             : Descriptive(description), function(function) {
36         }
37
38         /**
39          * Executes command binded with argument
40          *
41          * @param value Value passed to program argument
42          */
43         void run(ArgumentType value) {
44             this->function(value);
45         }
46     };
47 }
48
49 #endif /* __COMMAND_ARGUMENT_H */