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