blob: 5ca31ed21138f1be779ab7f06293238d4b6da14b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/* Copyright © 2006-2013 Roger Leigh <rleigh@debian.org>
*
* schroot is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* schroot is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
*********************************************************************/
#ifndef BIN_COMMON_OPTION_ACTION_H
#define BIN_COMMON_OPTION_ACTION_H
#include <set>
#include <string>
namespace bin_common
{
/**
* Actions specified as command-line options. This class contains
* all allowed options. This replaced the use of enums to allow
* extension of the options by inheritance.
*
* @todo Construct from iterator pair.
*/
class option_action
{
public:
/// Program action.
typedef std::string action_type;
/// The constructor.
option_action ();
/// The destructor.
virtual ~option_action ();
/**
* Add an action. The specified action is added to the list of
* permitted actions.
* @param action the action to add.
*/
void
add (const action_type& action);
/**
* Get the default action.
* @returns the default action, or an empty string if no default
* action has been set.
*/
action_type const&
get_default ();
/**
* Set the default action.
* @param action the action to set.
*/
void
set_default (const action_type& action);
/**
* Get the action to perform.
* @returns the action, or the default action if no action has
* been set, or an empty string if no default action has been set.
*/
action_type const&
get ();
/**
* Set the action to perform. This detects if an action has
* already been set (only one action may be specified at once).
* @param action the action to set.
* @todo Throw a custom error, and add a more informative error in
* main::run.
*/
void
set (const action_type& action);
/**
* Check if an action is valid.
* @param action the action to check.
* @returns if action is a valid action, otherwise false.
*/
bool
valid (const action_type& action);
/**
* Set an action.
*
* @param action the action to set.
* @returns the option_action object.
*/
option_action& operator = (const action_type& action)
{
set(action);
return *this;
}
/**
* Does the option_action contain the same action as the specified action?
*
* @param action the action to check.
* @returns true if the same, otherwise false.
*/
bool operator == (const action_type& action)
{
if (get() == action)
return true;
else
return false;
}
/**
* Does the option_action not contain the same action as the
* specified action?
*
* @param action the action to check.
* @returns true if different, otherwise false.
*/
bool operator != (const action_type& action)
{
return !(*this == action);
}
private:
/// The container of the actions.
typedef std::set<std::string> action_set;
/// Default action.
std::string default_action;
/// Current action.
std::string current_action;
/// Allowed actions.
action_set actions;
};
}
#endif /* BIN_COMMON_OPTION_ACTION_H */
/*
* Local Variables:
* mode:C++
* End:
*/
|