00001 #include "BField/TIntList.h" 00002 00003 ClassImp(TObjNum) 00004 ClassImp(TIntList) 00005 00006 TIntList::TIntList() 00007 { 00008 fNum = new TObjNum(1); 00009 fList = new TList(fNum); 00010 } 00011 00012 TIntList::~TIntList() 00013 { 00014 fList->Delete(); 00015 delete fList; 00016 delete fNum; 00017 } 00018 00019 void TIntList::Add(Int_t num) 00020 { 00021 fList->Add(new TObjNum(num)); 00022 } 00023 00024 void TIntList::AddFirst(Int_t num) 00025 { 00026 fList->AddFirst(new TObjNum(num)); 00027 } 00028 00029 void TIntList::AddLast(Int_t num) 00030 { 00031 fList->AddLast(new TObjNum(num)); 00032 } 00033 00034 void TIntList::Delete(Option_t* /* option */) 00035 { 00036 fList->Delete(); 00037 } 00038 00039 void TIntList::AddAt(Int_t num, Int_t idx) 00040 { 00041 fList->AddAt(new TObjNum(num),idx); 00042 } 00043 00044 Int_t TIntList::At(Int_t slot) 00045 { 00046 return ((TObjNum *)fList->At(slot))->GetNum(); 00047 } 00048 00049 Int_t TIntList::First(void) 00050 { 00051 return ((TObjNum *)fList->First())->GetNum(); 00052 } 00053 00054 Int_t TIntList::Last(void) 00055 { 00056 return ((TObjNum *)fList->Last())->GetNum(); 00057 } 00058 00059 Int_t TIntList::NumberOfElements(void) 00060 { 00061 Int_t NofElements = 0; 00062 TObjNum * IntObj; 00063 TIter next(fList); 00064 00065 while( (IntObj = (TObjNum *)next()) ) NofElements ++; 00066 00067 delete IntObj; 00068 00069 return NofElements; 00070 } 00071 00072 Bool_t TIntList::Exists(Int_t num) 00073 { 00074 Bool_t Exists = kFALSE; 00075 TObjNum * IntObj; 00076 TIter next(fList); 00077 00078 while( (IntObj = (TObjNum *)next()) ) { 00079 if(num == IntObj->GetNum()) Exists = kTRUE; 00080 } 00081 delete IntObj; 00082 00083 return Exists; 00084 } 00085 00086 void TIntList::Remove(Int_t element) 00087 { 00088 // Remove all occurences of 'element' from the list 00089 00090 TObjNum * IntObj; 00091 TObjNum * FndObj; 00092 TIter next(fList); 00093 00094 while( (IntObj = (TObjNum *)next()) ) { 00095 if(element == IntObj->GetNum()) { 00096 FndObj = (TObjNum*) fList->Remove(IntObj); 00097 delete FndObj; 00098 } 00099 } 00100 00101 } 00102 00103