#include <DbmCmdOptions.h>
Public Member Functions | |
| DbmCmdOptions (const std::string &validOpts="", JobCommand *jcmd=0, const std::list< std::string > *defaultOpts=0) | |
| virtual | ~DbmCmdOptions () |
| void | GetOptIntList (const std::string &opt, std::list< int > &nos) const |
| Int_t | GetOptInt (const std::string &opt) const |
| std::string | GetOptString (const std::string &opt) const |
| std::string | GetOpts () const |
| Bool_t | IsValid () const |
| Bool_t | IsValid (const std::string &opt) const |
| UInt_t | NumOpts () const |
| Bool_t | TestOpt (const std::string &opt) const |
| Bool_t | AddOpt (const std::string &opt, JobCommand &jcmd) |
| Bool_t | AddOpt (const std::string &opt, const std::string &val) |
| Bool_t | ProcessCmd (JobCommand &jcmd, const std::list< std::string > *defaultOpts=0) |
Public Attributes | |
| Bool_t | fIsValid |
| std::string | fValidOpts |
| std::map< std::string, std::string > | fOptsMap |
|
||||||||||||||||
|
Definition at line 41 of file DbmCmdOptions.cxx. 00043 : 00044 fIsValid(kTRUE), 00045 fValidOpts(":") 00046 { 00047 // 00048 // 00049 // Purpose: Default constructor 00050 // 00051 // Arguments: 00052 // validOpts in Option list of colon separated valid options 00053 // e.g."--Since:--File". Default = "". 00054 // jcmd in JobCommand to process. Optional, default = 0. 00055 // defaultOpts in Ordered list of default options. 00056 // If none supplied, use --Table --File (see 00057 // ProcessCmd). 00058 // 00059 // Return: n/a 00060 // 00061 // Contact: N. West 00062 // 00063 // Specification:- 00064 // ============= 00065 // 00066 // o Create a DbmCmdOptions. 00067 00068 00069 // Program Notes:- 00070 // ============= 00071 00072 // None. 00073 00074 LEA_CTOR //Leak Checker 00075 00076 MSG("Dbm", Msg::kVerbose) << "Creating DbmCmdOptions" << endl; 00077 00078 // Add leading and trailing colons to simplify searching. 00079 fValidOpts += validOpts; 00080 fValidOpts += ':'; 00081 if ( jcmd ) ProcessCmd( *jcmd, defaultOpts ); 00082 00083 }
|
|
|
Definition at line 87 of file DbmCmdOptions.cxx. 00087 {
00088 //
00089 //
00090 // Purpose: Destructor
00091 //
00092 // Arguments:
00093 // None.
00094 //
00095 // Return: n/a
00096 //
00097 // Contact: N. West
00098 //
00099 // Specification:-
00100 // =============
00101 //
00102 // o Destroy DbmCmdOptions.
00103
00104
00105 // Program Notes:-
00106 // =============
00107
00108 // None.
00109
00110 LEA_DTOR //Leak Checker
00111
00112 MSG("Dbm", Msg::kVerbose) << "Destroying DbmCmdOptions" << endl;
00113
00114 }
|
|
||||||||||||
|
Definition at line 176 of file DbmCmdOptions.cxx. References fIsValid, fOptsMap, IsValid(), MSG, and TestOpt(). 00176 {
00177 //
00178 //
00179 // Purpose: Add option, plus associated value, if valid.
00180 //
00181 // Arguments:
00182 // opt in Option to be stored.
00183 // jcmd in JobCommand holding option value, if any.
00184 // out Option removed, if any.
00185 //
00186 // Return: kTRUE if option permitted
00187 //
00188 // Contact: N. West
00189 //
00190 // Specification:-
00191 // =============
00192 //
00193 // o Add option plus associated value if valid.
00194
00195 // Program Notes:-
00196 // =============
00197
00198 // None.
00199
00200 // Store if valid.
00201 if ( ! IsValid( opt ) ) {
00202 MSG("Dbm",Msg::kError) << "Option " << opt
00203 << " not allowed for this command" << endl;
00204 fIsValid = kFALSE;
00205 return kFALSE;
00206 }
00207 if ( TestOpt(opt)
00208 ) MSG("Dbm",Msg::kWarning) << "Option " << opt
00209 << " has been duplicated" << endl;
00210 fOptsMap[opt] = val;
00211 return fIsValid;
00212
00213 }
|
|
||||||||||||
|
Definition at line 118 of file DbmCmdOptions.cxx. References fIsValid, MSG, and JobCommand::PopOpt(). Referenced by ProcessCmd(). 00118 {
00119 //
00120 //
00121 // Purpose: Add option, plus associated value, if valid.
00122 //
00123 // Arguments:
00124 // opt in Option to be stored.
00125 // jcmd in JobCommand holding option value, if any.
00126 // out Option removed, if any.
00127 //
00128 // Return: kTRUE if option permitted
00129 //
00130 // Contact: N. West
00131 //
00132 // Specification:-
00133 // =============
00134 //
00135 // o Add option plus associated value if valid. If no associated
00136 // value, stored "yes".
00137
00138 // Program Notes:-
00139 // =============
00140
00141 // None.
00142
00143
00144 // Collect option if any.
00145 string val("yes");
00146 Bool_t hasOpt = kFALSE;
00147
00148 if ( opt == "--Date" ) hasOpt = kTRUE;
00149 if ( opt == "--DatabaseNumber" ) hasOpt = kTRUE;
00150 if ( opt == "--Detector" ) hasOpt = kTRUE;
00151 if ( opt == "--File" ) hasOpt = kTRUE;
00152 if ( opt == "--LogFile" ) hasOpt = kTRUE;
00153 if ( opt == "--NumSeqNo" ) hasOpt = kTRUE;
00154 if ( opt == "--Reason" ) hasOpt = kTRUE;
00155 if ( opt == "--SimFlag" ) hasOpt = kTRUE;
00156 if ( opt == "--SeqNo" ) hasOpt = kTRUE;
00157 if ( opt == "--SeqNoMin" ) hasOpt = kTRUE;
00158 if ( opt == "--SeqNoMax" ) hasOpt = kTRUE;
00159 if ( opt == "--Since" ) hasOpt = kTRUE;
00160 if ( opt == "--Table" ) hasOpt = kTRUE;
00161 if ( opt == "--Task" ) hasOpt = kTRUE;
00162 if ( opt == "--UpdateTime" ) hasOpt = kTRUE;
00163
00164 if ( hasOpt ) {
00165 const char* valPtr = jcmd.PopOpt();
00166 if ( ! valPtr) {
00167 MSG("Dbm",Msg::kError) << "Option " << opt
00168 << " must be followed by a value" << endl;
00169 fIsValid = kFALSE;
00170 return kFALSE;
00171 }
00172 else val = valPtr;
00173 }
00174 return AddOpt(opt,val);
00175 }
|
|
|
Definition at line 260 of file DbmCmdOptions.cxx. References GetOptString(). Referenced by DbmModule::Import(), DbmModule::LogEntry(), and DbmModule::Query(). 00260 {
00261 //
00262 //
00263 // Purpose: Return associated option value as an integer
00264 //
00265 // Arguments:
00266 // opt in Option whose value is to be returned.
00267 //
00268 // Return: 0 if option not currently stored
00269 // otherwise the option value or 1 if none.
00270 //
00271 // Contact: N. West
00272 //
00273 // Specification:-
00274 // =============
00275 //
00276 // o Return associated option value as an integer.
00277
00278 string value = this->GetOptString(opt);
00279 if ( opt == "no" ) return 0;
00280 if ( opt == "yes" ) return 1;
00281 return atoi(value.c_str());
00282
00283
00284 }
|
|
||||||||||||
|
Definition at line 216 of file DbmCmdOptions.cxx. References GetOptString(), UtilString::IsInt(), and UtilString::StringTok(). Referenced by DbmModule::ExportTables(). 00216 {
00217 //
00218 //
00219 // Purpose: Parse and return a comma separated list.
00220 //
00221 // Arguments:
00222 // opt in The option whose value is the comma separated list.
00223 // nos in The initial list
00224 // out Updated to include the list of numbers.
00225 // If any error, the list will be cleared to zero
00226 // (including anything that pre-existed the call to this function).
00228 // Contact: N. West
00229 //
00230 // Specification:-
00231 // =============
00232 //
00233 // o Treat option value associated with supplied option as a comma separated
00234 // list of integers and stored them in the supplied list.
00235
00236 string optValue = this->GetOptString(opt);
00237 bool fail = (opt == "no");
00238
00239 if ( ! fail ) {
00240 std::vector<std::string> ls;
00241 UtilString::StringTok(ls,optValue,",");
00242 if ( ls.size() == 0 ) fail = true;
00243 else {
00244 std::vector<std::string>::iterator itr = ls.begin();
00245 std::vector<std::string>::iterator itrEnd = ls.end();
00246 while ( itr != itrEnd ) {
00247 if ( UtilString::IsInt(itr->c_str()) ) nos.push_back(atoi(itr->c_str()));
00248 else fail = true;
00249 ++itr;
00250 }
00251 }
00252 }
00253
00254 if ( fail ) nos.clear();
00255
00256 }
|
|
|
Definition at line 318 of file DbmCmdOptions.cxx. References fOptsMap. Referenced by DbmLogFile::LogCmd(). 00318 {
00319 //
00320 //
00321 // Purpose: Return string containing all options.
00322 //
00323 // Arguments: None.
00324 //
00325 // Return: String containing all options.
00326 //
00327 // Contact: N. West
00328 //
00329 // Specification:-
00330 // =============
00331 //
00332 // o Return string containing all options.
00333
00334 // Program Notes:-
00335 // =============
00336
00337 // None.
00338
00339 string opts;
00340 for ( map<string,string>::const_iterator itr = fOptsMap.begin();
00341 itr != fOptsMap.end();
00342 ++itr ) {
00343 opts += (*itr).first + " " + (*itr).second + " ";
00344 }
00345 return opts;
00346
00347 }
|
|
|
Definition at line 288 of file DbmCmdOptions.cxx. References fOptsMap, and TestOpt(). Referenced by DbmModule::ExportTables(), GetOptInt(), GetOptIntList(), DbmModule::GlobaliseSeqNo(), DbmModule::Import(), DbmModule::LogEntry(), and DbmModule::Query(). 00288 {
00289 //
00290 //
00291 // Purpose: Return associated option value as a string.
00292 //
00293 // Arguments:
00294 // opt in Option whose value is to be returned.
00295 //
00296 // Return: "no" if option not currently stored
00297 // otherwise the option value or "yes" if none.
00298 //
00299 // Contact: N. West
00300 //
00301 // Specification:-
00302 // =============
00303 //
00304 // o Return associated option value as a string.
00305
00306 // Program Notes:-
00307 // =============
00308
00309 // As we are careful to check that key exists before using
00310 // the non-const operator[], its O.K. to cast away const.
00311
00312 DbmCmdOptions* me = const_cast<DbmCmdOptions*>(this);
00313 return TestOpt(opt) ? me->fOptsMap[opt] : "no";
00314
00315 }
|
|
|
Definition at line 348 of file DbmCmdOptions.cxx. References fValidOpts. 00348 {
00349 //
00350 //
00351 // Purpose: Test to see if option is valid.
00352 //
00353 // Arguments:
00354 // opt in Option to be tested.
00355 //
00356 // Return: kTRUE if option permitted
00357 //
00358 // Contact: N. West
00359 //
00360 // Specification:-
00361 // =============
00362 //
00363 // o Test to see if option is valid.
00364
00365 // Program Notes:-
00366 // =============
00367
00368 // None.
00369
00370 // Look up option is valid list.
00371 string optStr(":");
00372 optStr += opt;
00373 optStr += ':';
00374 return fValidOpts.find(optStr) != string::npos;
00375
00376 }
|
|
|
Definition at line 45 of file DbmCmdOptions.h. Referenced by AddOpt(), DbmModule::CheckMemory(), DbmModule::ExportTables(), DbmModule::GlobaliseSeqNo(), DbmModule::Import(), DbmModule::LogEntry(), ProcessCmd(), and DbmModule::Query(). 00045 { return fIsValid; }
|
|
|
Definition at line 47 of file DbmCmdOptions.h. 00047 { return fOptsMap.size(); }
|
|
||||||||||||
|
Definition at line 380 of file DbmCmdOptions.cxx. References AddOpt(), fIsValid, IsValid(), MSG, option, JobCommand::PopOpt(), and TestOpt(). 00381 {
00382 //
00383 //
00384 // Purpose: Process JobCommand storing all options.
00385 //
00386 // Arguments:
00387 // jcmd in JobCommand to be processed.
00388 // out Exhausted JobCommand.
00389 // defaultOpts in Ordered list of default options.
00390 // If none supplied, use --Table --File
00391 //
00392 // Return:
00393 //
00394 // Contact: N. West
00395 //
00396 // Specification:-
00397 // =============
00398 //
00399 // o Process JobCommand storing all options.
00400 //
00401 // o Supply default options to the first parameters
00402 // i.e. options that do not start "-" and are permitted.
00403
00404
00405 // Program Notes:-
00406 // =============
00407
00408 // None.
00409
00410 // Provide a default for the default!
00411 std::list<std::string> defDefOPts;
00412 defDefOPts.push_back("--Table");
00413 defDefOPts.push_back("--File");
00414
00415 if ( defaultOpts == 0 ) defaultOpts = &defDefOPts;
00416
00417 std::list<std::string>::const_iterator
00418 defOptsItr = defaultOpts->begin();
00419 std::list<std::string>::const_iterator
00420 defOptsItrEnd = defaultOpts->end();
00421
00422 const char* opt = jcmd.PopOpt();
00423 while (opt) {
00424
00425 // Deal with option.
00426 if ( opt[0] == '-' ) {
00427
00428 string option = opt;
00429 AddOpt(opt, jcmd);
00430 }
00431
00432 // Deal with parameter.
00433 else {
00434
00435 // Pick up next default option, if any.
00436 std::string defaultOpt = "";
00437 if ( defOptsItr != defOptsItrEnd ) {
00438 defaultOpt = *defOptsItr;
00439 ++defOptsItr;
00440 }
00441
00442 // Permit default if defined, not yet used and is valid.
00443 if ( defaultOpt != "" && ! TestOpt(defaultOpt) && IsValid(defaultOpt)
00444 ) AddOpt(defaultOpt, opt);
00445
00446 else {
00447 MSG("Dbm",Msg::kWarning) << "Unknown parameter " << opt << endl;
00448 fIsValid = kFALSE;
00449 }
00450 }
00451
00452 opt = jcmd.PopOpt();
00453 } // loop over options
00454
00455 return fIsValid;
00456
00457 }
|
|
|
Definition at line 461 of file DbmCmdOptions.cxx. References fOptsMap. Referenced by AddOpt(), DbmModule::ExportTables(), GetOptString(), DbmModule::GlobaliseSeqNo(), DbmModule::Import(), DbmModule::LogEntry(), ProcessCmd(), and DbmModule::Query(). 00461 {
00462 //
00463 //
00464 // Purpose: Test existence of option.
00465 //
00466 // Arguments:
00467 // opt in Option whose value is to be tested.
00468 //
00469 // Return: kTRUE if option exists, otherwise kFALSE.
00470 //
00471 // Contact: N. West
00472 //
00473 // Specification:-
00474 // =============
00475 //
00476 // o Test existence of option.
00477
00478 // Program Notes:-
00479 // =============
00480
00481 // None.
00482
00483 map<string,string>::const_iterator loc = fOptsMap.find(opt);
00484 return loc != fOptsMap.end();
00485
00486 }
|
|
|
Definition at line 59 of file DbmCmdOptions.h. Referenced by AddOpt(), and ProcessCmd(). |
|
|
Definition at line 61 of file DbmCmdOptions.h. Referenced by AddOpt(), GetOpts(), GetOptString(), and TestOpt(). |
|
|
Definition at line 60 of file DbmCmdOptions.h. Referenced by IsValid(). |
1.3.9.1