|
//____________________________________________________________________ // // Command line option classes. Currently, these options can only // take one value, and one alone. The types of arguments implmented // are // Float_t, Int_t, Bool_t, and String // //____________________________________________________________________ // // // $Id: BrAppOption.cxx,v 1.3 2002/04/23 15:18:30 hagel Exp $ // $Date: 2002/04/23 15:18:30 $ // $Copyright: BRAHMS Collaboration 2000 #ifndef __CSTDLIB__ #include <cstdlib> #endif #ifndef __CSTRING__ #include <cstring> #endif #ifndef __IOSTREAM__ #include <iostream> #endif #ifndef __IOMANIP__ #include <iomanip> #endif #ifndef ROOT_TString #include "TString.h" #endif #ifndef ROOT_TObject #include "TObject.h" #endif #ifndef ROOT_TObjArray #include "TObjArray.h" #endif #ifndef ROOT_TSystem #include "TSystem.h" #endif #ifndef BRAT_BrAppOption #include "BrAppOption.h" #endif #ifndef BRAT_BrAppOptionManager #include "BrAppOptionManager.h" #endif #ifdef BR_USE_EXCEPTIONS #undef BR_USE_EXCEPTIONS #endif #ifdef BR_USE_EXCEPTIONS #include <BrException.h> #endif //____________________________________________________________________ ClassImp(BrAppOption); // Options class ------------------------------ //____________________________________________________________________ BrAppOption::BrAppOption(const Char_t shortName, const Char_t* longName, const Char_t* helpString) : fShortName(shortName), fLongName(longName), fHelpString(helpString) { fNValues = 0; BrAppOptionManager::Instance()->AddOption(this, kTRUE); } //____________________________________________________________________ Int_t BrAppOption::Compare(const TObject* o) const { return fLongName.CompareTo(o->GetName()); } Int_t BrAppOption::Compare(TObject* o) { return fLongName.CompareTo(o->GetName()); } //____________________________________________________________________ ULong_t BrAppOption::Hash(void) { return fLongName.Hash(); } //____________________________________________________________________ ULong_t BrAppOption::Hash(void) const { return fLongName.Hash(); } //____________________________________________________________________ void BrAppOption::Print(Option_t* option) const { // Print information on this option ios::fmtflags oldflags = cout.setf(ios::left); cout << " -" << fShortName << " " << " --" << setw(16) << fLongName << " " << fHelpString << ", default is " << flush; cout.setf(oldflags); } //____________________________________________________________________ ClassImp(BrAppIntOption); // Options class --------------------------- //____________________________________________________________________ BrAppIntOption::BrAppIntOption(Char_t sName, const Char_t* lName, const Char_t* helpString, const Int_t defualtValue) : BrAppOption(sName,lName,helpString) { fValue = new Int_t[1]; fValue[0] = defualtValue; } //____________________________________________________________________ Int_t BrAppIntOption::GetValue(Int_t i) const { if (fNValues == 0) return fValue[0]; if (i < 0 || i >= fNValues) { Warning("GetValue", "index %d out of bounds [0,%d)", i, fNValues); return 0; } return fValue[i]; } //____________________________________________________________________ Bool_t BrAppIntOption::SetValue(const Char_t* strValue, Int_t i) { if (!strValue) { #ifdef BR_USE_EXCEPTIONS throw new BrError("BrAppIntOption::SetValue", "Option -%c/--%s need an argument", fShortName,fLongName.Data()); #else Error("SetValue", "Option -%c/--%s need an argument", fShortName,fLongName.Data()); return kFALSE; #endif } Int_t val = strtol(strValue,NULL,0); if (fNValues == 0 && i <= 0) i = 0; else if (i < 0 || i >= fNValues) { if (i < 0) i = fNValues; // Expand the array as needed Int_t* values = new Int_t[i + 1]; Int_t j = 0; for (j = 0; j < fNValues; j++) values[j] = fValue[j]; for (; j < i + 1; j++) values[j] = 0; delete [] fValue; fValue = values; } fValue[i] = val; fNValues++; return kTRUE; } //____________________________________________________________________ void BrAppIntOption::Print(Option_t* option) const { // Print information on this option BrAppOption::Print(); if (fNValues == 0) cout << fValue[0] << flush; else for (Int_t i = 0; i < fNValues; i++) cout << fValue[i] << " " << flush; cout << endl; } //____________________________________________________________________ ClassImp(BrAppFloatOption); // Options class ------------------------- //____________________________________________________________________ BrAppFloatOption::BrAppFloatOption(Char_t sName, const Char_t* lName, const Char_t* helpString, const Float_t defualtValue) : BrAppOption(sName,lName,helpString) { fValue = new Float_t[1]; fValue[0] = defualtValue; } //____________________________________________________________________ Float_t BrAppFloatOption::GetValue(Int_t i) const { if (fNValues == 0) return fValue[0]; if (i < 0 || i >= fNValues) { Warning("GetValue", "index %d out of bounds [0,%d)", i, fNValues); return 0; } return fValue[i]; } //____________________________________________________________________ Bool_t BrAppFloatOption::SetValue(const Char_t* strValue, Int_t i) { if (!strValue) { #ifdef BR_USE_EXCEPTIONS throw new BrError("BrAppFloatOption::SetValue", "Option -%c/--%s need an argument", fShortName,fLongName.Data()); #else Error("SetValue", "Option -%c/--%s need an argument", fShortName,fLongName.Data()); return kFALSE; #endif } Float_t val = strtod(strValue,NULL); if (fNValues == 0 && i <= 0) i = 0; else if (i < 0 || i >= fNValues) { if (i < 0) i = fNValues; // Expand the array as needed Float_t* values = new Float_t[i + 1]; Int_t j = 0; for (j = 0; j < fNValues; j++) values[j] = fValue[j]; for (; j < i + 1; j++) values[j] = 0; delete [] fValue; fValue = values; } fValue[i] = val; fNValues++; return kTRUE; } //____________________________________________________________________ void BrAppFloatOption::Print(Option_t* option) const { // Print information on this option BrAppOption::Print(); if (fNValues == 0) cout << fValue[0] << flush; else for (Int_t i = 0; i < fNValues; i++) cout << fValue[i] << " " << flush; cout << endl; } //____________________________________________________________________ ClassImp(BrAppBoolOption); // Options class -------------------------- //____________________________________________________________________ Bool_t BrAppBoolOption::SetValue(const Char_t* strValue, Int_t i) { fValue = !fValue; return kTRUE; } //____________________________________________________________________ void BrAppBoolOption::Print(Option_t* option) const { // Print information on this option BrAppOption::Print(); cout << (fValue ? "true" : "false" ) << endl; } //____________________________________________________________________ ClassImp(BrAppStringOption); // Options class ------------------------ //____________________________________________________________________ BrAppStringOption::BrAppStringOption(Char_t sName, const Char_t* lName, const Char_t* helpString, const Char_t* defualtValue) : BrAppOption(sName,lName,helpString) { fValue = new TString[1]; fValue[0] = defualtValue; } //____________________________________________________________________ const Char_t* BrAppStringOption::GetValue(Int_t i) const { if (fNValues == 0) return fValue[0].Data(); if (i < 0 || i >= fNValues) { Warning("GetValue", "index %d out of bounds [0,%d)", i, fNValues); return 0; } return fValue[i].Data(); } //____________________________________________________________________ Bool_t BrAppStringOption::SetValue(const Char_t* strValue, Int_t i) { if (!strValue) { #ifdef BR_USE_EXCEPTIONS throw new BrError("BrAppStringOption::SetValue", "Option -%c/--%s need an argument", fShortName,fLongName.Data()); #else Error("SetValue", "Option -%c/--%s need an argument", fShortName,fLongName.Data()); return kFALSE; #endif } if (fNValues == 0 && i <= 0) i = 0; if (i < 0 || i >= fNValues) { if (i < 0) i = fNValues; // Expand the array as needed TString* values = new TString[i + 1]; Int_t j = 0; for (j = 0; j < fNValues; j++) values[j] = fValue[j]; delete [] fValue; fValue = values; } fValue[i] = strValue; fNValues++; //Return statement added KH 23-Apr-2002 How did this work without it?! //It appears to have been lost sometime between 2.0.31 (still there) and //2.2.10 (not there) Probably during the transition to ability to //specify multiple values return kTRUE; } //____________________________________________________________________ void BrAppStringOption::Print(Option_t* option) const { // Print information on this option BrAppOption::Print(); if (fNValues == 0) cout << fValue[0] << flush; else for (Int_t i = 0; i < fNValues; i++) cout << fValue[i] << " " << flush; cout << endl; } /////////////////////////////////////////////////////////////////////// // // $Log: BrAppOption.cxx,v $ // Revision 1.3 2002/04/23 15:18:30 hagel // Add return to BrAppStringOption::SetValue // // Revision 1.2 2001/12/14 15:28:12 cholm // BrAppOption sublcasses now adds them selves to BrAppOptionManager // automatically. Also, the int, float, and string option class can now // hold multiple values. It's all fairly well documented in 'The Guide'. // // Revision 1.1.1.1 2001/06/21 14:55:15 hagel // Initial revision of brat2 // // Revision 1.6 2001/03/07 12:15:39 cholm // * Defined standard BrModule methods in BrIOModule. // * Add the (simple) class BrHistIOModule. // * BrAppOptionManager and BrAppOption classes changed to not use // BrExceptions. // * Added the method Int_t BrMainModule::Main() to do EVERYTHING. // * Made the method BrModule::Info() const obsolete in favour of // BrModule::Print(Option_t* option="B") const. Impact on other classes. // // Revision 1.5 2001/01/22 19:58:24 cholm // Corrected const-ness of BrAppOption::Compare for old ROOT versions. // Fixed BrModule::Streamer to work with new ROOT. Changed the avaliable // module status values to kStop, kFailure, kAbort, and updated // BrModuleContainer and BrModule accordingly. Also renamed BrIOModule::fStatus // to BrIOModule::fIOStatus. BrEventIO uses Stop, Failure, and Abort now. // Also fix of BrEventIO::Streamer for ROOT 3.00/00+ // // Revision 1.4 2001/01/19 16:36:06 cholm // Updated BrAppOption for const'ness of compare. // Added state and status information to BrModule. A container may inspect // these react accordingly, for example by aborting the processing of the // current event, sequnce, run, job, etc. // // Revision 1.3 2000/09/04 13:38:33 videbaek // Use BrIostream.h to facilitate different iostream conventions. // // Revision 1.2 2000/07/20 16:14:12 videbaek // Fixed problme in IsEventSync and IsEvent. // Added Finish method in Module container. // Moved comments CVSlog // // Revision 1.1 2000/04/06 20:17:41 cholm // Added the classes BrAppOption, BrAppOptionManager, and // BrDetectorList. The first two are for command line processing, // the third for easy detector list, can be used for many purposes. // // |
||||||
This page automatically generated by script docBrat by Christian Holm |
Copyright ; 2002 BRAHMS Collaboration
<brahmlib@rcf.rhic.bnl.gov>
|