Fix compilation, remove some warnings.
[command.git] / include / option.h
1 #ifndef __COMMAND_OPTION_H
2 #define __COMMAND_OPTION_H
3
4 #include <string>
5
6 #include "parameter.h"
7
8 namespace command {
9     /**
10      * Class responsible for handling commandline options.
11      * Options are non-required, named parameters of program.
12      *
13      * Example:
14      *  ./myprog OptionName OptionValue
15      */
16     template<typename OptionType>
17     class Option
18         : public Parameter, public Callable<OptionType>  {
19     protected:
20         /**
21          * Option name
22          */
23         std::string name;
24
25     public:
26         /**
27          * Default constructor.
28          *
29          * @param name Name of the current Option
30          * @param description Description of current Option
31          * @param function Function used to handle current Option.
32          */
33         Option(std::string name, std::string description, void (*function)(OptionType))
34             : Parameter(description), Callable<OptionType>(function), name(name) {
35         }
36         virtual ~Option() { }
37
38         virtual void handle() {
39             this->call(std::string("O"));
40         }
41
42         virtual bool understand(const std::string & argVal) {
43             if (argVal.find(name) != std::string::npos) {
44                 return true;
45             }
46
47             return false;
48         }
49     };
50 }
51
52 #endif /* __COMMAND_OPTION_H */