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