Add Grouped behaviour.
[command.git] / include / parameter.h
1 #ifndef __COMMAND_PARAMETER_H
2 #define __COMMAND_PARAMETER_H
3
4 #include <string>
5 #include <sstream>
6
7 #include "descriptive.h"
8 #include "callable.h"
9
10 namespace command {
11     /**
12      * Base class for all the Arguments and Options.
13      *
14      * Example:
15      *  ./myprog ARGUMENT
16      */
17     class Parameter : public Descriptive {
18     protected:
19         /** Variable indicating if current Parameter was already used or not */
20         bool used = false;
21
22     public:
23         typedef class Parameter Type;
24         /**
25          * Default constructor.
26          *
27          * @param description Description of current Argument
28          */
29         Parameter(const std::string & description)
30             : Descriptive(description) {
31         }
32
33         virtual ~Parameter() { }
34
35         /**
36          * Method used for handling method calls linked with this Parameter
37          */
38         virtual void handle() = 0;
39
40         /**
41          * Method used for checking if the given user value understandable for
42          * parameter.
43          *
44          * @return true if passed value is understandable by current Parameter.
45          *      False otherwise.
46          */
47         virtual bool understand(const std::string & ) = 0;
48
49         /**
50          * Indicates if current Parameter is required
51          *
52          * @return false, as all Parameters are non-required by default. If you
53          *      want to make Parameter as required, wrap it using Required class
54          */
55         virtual bool isRequired() {
56             return false;
57         };
58
59         /**
60          * Indicates if current Parameter has been already used
61          *
62          * @return true if current Parameter has been already used. False otherwise.
63          */
64         virtual bool isUsed() {
65             return used;
66         }
67
68         /**
69          */
70         virtual bool hungryForValue() {
71             return false;
72         }
73
74         /**
75          * @return position where value starts in passed string
76          */
77         virtual unsigned int valuePosition(const std::string & ) = 0;
78     };
79 }
80
81 #endif /* __COMMAND_PARAMETER_H */