Added Option tests.
[command.git] / include / callable.h
1 #ifndef __COMMAND_CALLABLE_H
2 #define __COMMAND_CALLABLE_H
3
4 #include <string>
5
6 namespace command {
7     /**
8      * Callable behaviour class.
9      */
10     template<typename ArgumentType>
11     class Callable {
12     protected:
13         /**
14          * Function handling user Arguments
15          */
16         void (*func)(ArgumentType);
17
18     public:
19         /**
20          * Default constructor.
21          *
22          * @param function Function that will be invoked
23          */
24         Callable(void (*function)(ArgumentType))
25             : func(function) {
26         }
27         virtual ~Callable() { }
28
29     protected:
30         /**
31          * Executes command binded with argument
32          *
33          * @param value Value passed to program argument
34          */
35         void call(ArgumentType value) {
36             this->func(value);
37         }
38     };
39
40     /**
41      * Template specialization of Callable behaviour class.
42      * Allows passing functions with void argument
43      */
44     template<>
45     class Callable<void> {
46     protected:
47         /**
48          * Function handling user Arguments
49          */
50         void (*func)(void);
51
52     public:
53         /**
54          * Default constructor.
55          *
56          * @param function Function that will be invoked
57          */
58         Callable(void (*function)(void))
59             : func(function) {
60         }
61         virtual ~Callable() { }
62
63     protected:
64         /**
65          * Executes command
66          */
67         void call() {
68             this->func();
69         }
70     };
71 }
72
73 #endif /* __COMMAND_DESCRIPTIVE_H */