00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #pragma once
00016 #ifndef _SBIA_BASIS_MULTIARG_H
00017 #define _SBIA_BASIS_MULTIARG_H
00018
00019
00020 #include <sbia/tclap/MultiArg.h>
00021
00022
00023 namespace sbia
00024 {
00025
00026 namespace basis
00027 {
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 template <class T>
00047 class MultiArg : public TCLAP::MultiArg<T>
00048 {
00049
00050
00051 public:
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 MultiArg(const std::string& flag,
00072 const std::string& name,
00073 const std::string& desc,
00074 bool req,
00075 const std::string& typeDesc,
00076 unsigned int n = 1,
00077 bool once = false,
00078 TCLAP::Visitor* v = NULL);
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 MultiArg(const std::string& flag,
00100 const std::string& name,
00101 const std::string& desc,
00102 bool req,
00103 const std::string& typeDesc,
00104 TCLAP::CmdLineInterface& parser,
00105 unsigned int n = 1,
00106 bool once = false,
00107 TCLAP::Visitor* v = NULL);
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 MultiArg(const std::string& flag,
00126 const std::string& name,
00127 const std::string& desc,
00128 bool req,
00129 TCLAP::Constraint<T>* constraint,
00130 unsigned int n = 1,
00131 bool once = false,
00132 TCLAP::Visitor* v = NULL);
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 MultiArg(const std::string& flag,
00152 const std::string& name,
00153 const std::string& desc,
00154 bool req,
00155 TCLAP::Constraint<T>* constraint,
00156 TCLAP::CmdLineInterface& parser,
00157 unsigned int n = 1,
00158 bool once = false,
00159 TCLAP::Visitor* v = NULL);
00160
00161
00162
00163 public:
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 virtual bool processArg(int* i, std::vector<std::string>& args);
00176
00177
00178
00179
00180
00181
00182
00183 virtual bool isRequired() const;
00184
00185
00186
00187 private:
00188
00189 MultiArg<T>(const MultiArg<T>&);
00190 MultiArg<T>& operator=(const MultiArg<T>&);
00191
00192
00193
00194 protected:
00195
00196 unsigned int _numberOfArguments;
00197
00198 };
00199
00200
00201
00202
00203
00204
00205
00206 template <class T>
00207 MultiArg<T>::MultiArg(const std::string& flag,
00208 const std::string& name,
00209 const std::string& desc,
00210 bool req,
00211 const std::string& typeDesc,
00212 unsigned int n,
00213 bool once,
00214 TCLAP::Visitor* v)
00215 :
00216 TCLAP::MultiArg<T>(flag, name, desc, req, typeDesc, v),
00217 _numberOfArguments(n)
00218 {
00219 if (once) TCLAP::MultiArg<T>::_acceptsMultipleValues = false;
00220 }
00221
00222
00223 template <class T>
00224 MultiArg<T>::MultiArg(const std::string& flag,
00225 const std::string& name,
00226 const std::string& desc,
00227 bool req,
00228 const std::string& typeDesc,
00229 TCLAP::CmdLineInterface& parser,
00230 unsigned int n,
00231 bool once,
00232 TCLAP::Visitor* v)
00233 :
00234 TCLAP::MultiArg<T>(flag, name, desc, req, typeDesc, parser, v),
00235 _numberOfArguments(n)
00236 {
00237 if (once) TCLAP::MultiArg<T>::_acceptsMultipleValues = false;
00238 }
00239
00240
00241 template <class T>
00242 MultiArg<T>::MultiArg(const std::string& flag,
00243 const std::string& name,
00244 const std::string& desc,
00245 bool req,
00246 TCLAP::Constraint<T>* constraint,
00247 unsigned int n,
00248 bool once,
00249 TCLAP::Visitor* v)
00250 :
00251 TCLAP::MultiArg<T>(flag, name, desc, req, constraint, v),
00252 _numberOfArguments(n)
00253 {
00254 if (once) TCLAP::MultiArg<T>::_acceptsMultipleValues = false;
00255 }
00256
00257
00258 template <class T>
00259 MultiArg<T>::MultiArg(const std::string& flag,
00260 const std::string& name,
00261 const std::string& desc,
00262 bool req,
00263 TCLAP::Constraint<T>* constraint,
00264 TCLAP::CmdLineInterface& parser,
00265 unsigned int n,
00266 bool once,
00267 TCLAP::Visitor* v)
00268 :
00269 TCLAP::MultiArg<T>(flag, name, desc, req, constraint, parser, v),
00270 _numberOfArguments(n)
00271 {
00272 if (once) TCLAP::MultiArg<T>::_acceptsMultipleValues = false;
00273 }
00274
00275
00276 template <class T>
00277 bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)
00278 {
00279 if (TCLAP::MultiArg<T>::_ignoreable && TCLAP::Arg::ignoreRest()) {
00280 return false;
00281 }
00282 if (TCLAP::MultiArg<T>::_hasBlanks( args[*i] )) return false;
00283
00284 std::string flag = args[*i];
00285 std::string value = "";
00286 TCLAP::MultiArg<T>::trimFlag(flag, value);
00287 if (!TCLAP::MultiArg<T>::argMatches(flag)) return false;
00288
00289 if (TCLAP::Arg::delimiter() != ' ' && value == "") {
00290 throw TCLAP::ArgParseException(
00291 "Couldn't find delimiter for this argument!",
00292 TCLAP::MultiArg<T>::toString());
00293 }
00294
00295 if (value == "")
00296 {
00297 if (TCLAP::MultiArg<T>::_alreadySet &&
00298 !TCLAP::MultiArg<T>::_acceptsMultipleValues) {
00299 throw TCLAP::CmdLineParseException("Argument already set!",
00300 TCLAP::MultiArg<T>::toString());
00301 }
00302 (*i)++;
00303 if (static_cast<unsigned int>(*i) < args.size()) {
00304 TCLAP::MultiArg<T>::_extractValue(args[*i]);
00305 } else {
00306 throw TCLAP::ArgParseException(
00307 "Missing a value for this argument!",
00308 TCLAP::MultiArg<T>::toString());
00309 }
00310 } else {
00311 TCLAP::MultiArg<T>::_extractValue(value);
00312 }
00313
00314 for (unsigned int n = 1; n < _numberOfArguments; n++) {
00315 (*i)++;
00316 if (static_cast<unsigned int>(*i) < args.size()) {
00317 TCLAP::MultiArg<T>::_extractValue(args[*i]);
00318 } else {
00319 throw TCLAP::ArgParseException(
00320 "Too few values for this argument!",
00321 TCLAP::MultiArg<T>::toString());
00322 }
00323 }
00324 TCLAP::MultiArg<T>::_alreadySet = true;
00325 TCLAP::MultiArg<T>::_allowMore = false;
00326 TCLAP::MultiArg<T>::_checkWithVisitor();
00327 return true;
00328 }
00329
00330 template <class T>
00331 bool MultiArg<T>::isRequired() const
00332 {
00333 if (TCLAP::MultiArg<T>::_required) {
00334 if (TCLAP::MultiArg<T>::_acceptsMultipleValues
00335 && TCLAP::MultiArg<T>::_values.size() > 1) {
00336 return false;
00337 } else {
00338 return true;
00339 }
00340 } else {
00341 return false;
00342 }
00343 }
00344
00345
00346 }
00347
00348 }
00349
00350
00351 #endif // _SBIA_BASIS_MULTIARG_H