Debian Codegraph @

podofo/3rdparty/tclap/UnlabeledMultiArg.h

raw symbols SCIP
1 // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
2
3 /******************************************************************************
4 *
5 * file: UnlabeledMultiArg.h
6 *
7 * Copyright (c) 2003, Michael E. Smoot.
8 * Copyright (c) 2017, Google LLC
9 * All rights reserved.
10 *
11 * See the file COPYING in the top directory of this distribution for
12 * more information.
13 *
14 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 *
22 *****************************************************************************/
23
24 #ifndef TCLAP_UNLABELED_MULTI_ARG_H
25 #define TCLAP_UNLABELED_MULTI_ARG_H
26
27 #include <tclap/MultiArg.h>
28 #include <tclap/OptionalUnlabeledTracker.h>
29
30 #include <list>
31 #include <string>
32 #include <vector>
33
34 namespace TCLAP {
35
36 /**
37 * Just like a MultiArg, except that the arguments are unlabeled. Basically,
38 * this Arg will slurp up everything that hasn't been matched to another
39 * Arg.
40 */
41 template <class T>
42 class UnlabeledMultiArg : public MultiArg<T> {
43 // If compiler has two stage name lookup (as gcc >= 3.4 does)
44 // this is required to prevent undef. symbols
45 using MultiArg<T>::_ignoreable;
46 using MultiArg<T>::_hasBlanks;
47 using MultiArg<T>::_extractValue;
48 using MultiArg<T>::_typeDesc;
49 using MultiArg<T>::_name;
50 using MultiArg<T>::_description;
51 using MultiArg<T>::_alreadySet;
52 using MultiArg<T>::_setBy;
53 using MultiArg<T>::toString;
54
55 public:
56 /**
57 * Constructor.
58 * \param name - The name of the Arg. Note that this is used for
59 * identification, not as a long flag.
60 * \param desc - A description of what the argument is for or
61 * does.
62 * \param req - Whether the argument is required on the command
63 * line.
64 * \param typeDesc - A short, human readable description of the
65 * type that this object expects. This is used in the generation
66 * of the USAGE statement. The goal is to be helpful to the end user
67 * of the program.
68 * \param ignoreable - Whether or not this argument can be ignored
69 * using the "--" flag.
70 * \param v - An optional visitor. You probably should not
71 * use this unless you have a very good reason.
72 */
73 UnlabeledMultiArg(const std::string &name, const std::string &desc,
74 bool req, const std::string &typeDesc,
75 bool ignoreable = false, Visitor *v = NULL);
76 /**
77 * Constructor.
78 * \param name - The name of the Arg. Note that this is used for
79 * identification, not as a long flag.
80 * \param desc - A description of what the argument is for or
81 * does.
82 * \param req - Whether the argument is required on the command
83 * line.
84 * \param typeDesc - A short, human readable description of the
85 * type that this object expects. This is used in the generation
86 * of the USAGE statement. The goal is to be helpful to the end user
87 * of the program.
88 * \param parser - A CmdLine parser object to add this Arg to
89 * \param ignoreable - Whether or not this argument can be ignored
90 * using the "--" flag.
91 * \param v - An optional visitor. You probably should not
92 * use this unless you have a very good reason.
93 */
94 UnlabeledMultiArg(const std::string &name, const std::string &desc,
95 bool req, const std::string &typeDesc,
96 ArgContainer &parser, bool ignoreable = false,
97 Visitor *v = NULL);
98
99 /**
100 * Constructor.
101 * \param name - The name of the Arg. Note that this is used for
102 * identification, not as a long flag.
103 * \param desc - A description of what the argument is for or
104 * does.
105 * \param req - Whether the argument is required on the command
106 * line.
107 * \param constraint - A pointer to a Constraint object used
108 * to constrain this Arg.
109 * \param ignoreable - Whether or not this argument can be ignored
110 * using the "--" flag.
111 * \param v - An optional visitor. You probably should not
112 * use this unless you have a very good reason.
113 */
114 UnlabeledMultiArg(const std::string &name, const std::string &desc,
115 bool req, Constraint<T> *constraint,
116 bool ignoreable = false, Visitor *v = NULL);
117
118 /**
119 * Constructor.
120 * \param name - The name of the Arg. Note that this is used for
121 * identification, not as a long flag.
122 * \param desc - A description of what the argument is for or
123 * does.
124 * \param req - Whether the argument is required on the command
125 * line.
126 * \param constraint - A pointer to a Constraint object used
127 * to constrain this Arg.
128 * \param parser - A CmdLine parser object to add this Arg to
129 * \param ignoreable - Whether or not this argument can be ignored
130 * using the "--" flag.
131 * \param v - An optional visitor. You probably should not
132 * use this unless you have a very good reason.
133 */
134 UnlabeledMultiArg(const std::string &name, const std::string &desc,
135 bool req, Constraint<T> *constraint, ArgContainer &parser,
136 bool ignoreable = false, Visitor *v = NULL);
137
138 /**
139 * Handles the processing of the argument.
140 * This re-implements the Arg version of this method to set the
141 * _value of the argument appropriately. It knows the difference
142 * between labeled and unlabeled.
143 * \param i - Pointer the the current argument in the list.
144 * \param args - Mutable list of strings. Passed from main().
145 */
146 virtual bool processArg(int *i, std::vector<std::string> &args);
147
148 /**
149 * Returns the a short id string. Used in the usage.
150 */
151 virtual std::string shortID(const std::string &) const {
152 return Arg::getName() + " ...";
153 }
154
155 /**
156 * Returns the a long id string. Used in the usage.
157 * \param val - value to be used.
158 */
159 virtual std::string longID(const std::string &) const {
160 return Arg::getName() + " (accepted multiple times) <" + _typeDesc +
161 ">";
162 }
163
164 /**
165 * Operator ==.
166 * \param a - The Arg to be compared to this.
167 */
168 virtual bool operator==(const Arg &a) const;
169
170 /**
171 * Pushes this to back of list rather than front.
172 * \param argList - The list this should be added to.
173 */
174 virtual void addToList(std::list<Arg *> &argList) const;
175
176 virtual bool hasLabel() const { return false; }
177 };
178
179 template <class T>
180 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string &name,
181 const std::string &desc, bool req,
182 const std::string &typeDesc,
183 bool ignoreable, Visitor *v)
184 : MultiArg<T>("", name, desc, req, typeDesc, v) {
185 _ignoreable = ignoreable;
186 OptionalUnlabeledTracker::check(true, toString());
187 }
188
189 template <class T>
190 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string &name,
191 const std::string &desc, bool req,
192 const std::string &typeDesc,
193 ArgContainer &parser, bool ignoreable,
194 Visitor *v)
195 : MultiArg<T>("", name, desc, req, typeDesc, v) {
196 _ignoreable = ignoreable;
197 OptionalUnlabeledTracker::check(true, toString());
198 parser.add(this);
199 }
200
201 template <class T>
202 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string &name,
203 const std::string &desc, bool req,
204 Constraint<T> *constraint,
205 bool ignoreable, Visitor *v)
206 : MultiArg<T>("", name, desc, req, constraint, v) {
207 _ignoreable = ignoreable;
208 OptionalUnlabeledTracker::check(true, toString());
209 }
210
211 template <class T>
212 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string &name,
213 const std::string &desc, bool req,
214 Constraint<T> *constraint,
215 ArgContainer &parser, bool ignoreable,
216 Visitor *v)
217 : MultiArg<T>("", name, desc, req, constraint, v) {
218 _ignoreable = ignoreable;
219 OptionalUnlabeledTracker::check(true, toString());
220 parser.add(this);
221 }
222
223 template <class T>
224 bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string> &args) {
225 if (_hasBlanks(args[*i])) return false;
226
227 // never ignore an unlabeled multi arg
228
229 // always take the first value, regardless of the start string
230 _extractValue(args[(*i)]);
231
232 /*
233 // continue taking args until we hit the end or a start string
234 while ( (unsigned int)(*i)+1 < args.size() &&
235 args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 &&
236 args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
237 _extractValue( args[++(*i)] );
238 */
239
240 _alreadySet = true;
241 _setBy = args[*i];
242 this->_checkWithVisitor();
243 return true;
244 }
245
246 template <class T>
247 bool UnlabeledMultiArg<T>::operator==(const Arg &a) const {
248 if (_name == a.getName() || _description == a.getDescription())
249 return true;
250 else
251 return false;
252 }
253
254 template <class T>
255 void UnlabeledMultiArg<T>::addToList(std::list<Arg *> &argList) const {
256 argList.push_back(const_cast<Arg *>(static_cast<const Arg *const>(this)));
257 }
258 } // namespace TCLAP
259
260 #endif // TCLAP_UNLABELED_MULTI_ARG_H