1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 // $MpId: AliMpStringObjMap.cxx,v 1.4 2006/05/24 13:58:29 ivana Exp $
19 // ------------------------------------
20 // Class AliMpStringObjMap
21 // ------------------------------------
22 // Helper class that substitutes map <string, int>
23 // which ALICE does not allow to use
24 // Author: Ivana Hrivnacova, IPN Orsay
26 #include "AliMpStringObjMap.h"
30 #include <TObjString.h>
31 #include <Riostream.h>
34 ClassImp(AliMpStringObjMap)
37 const TString AliMpStringObjMap::fgkUndefinedKey = "Undefined";
39 //______________________________________________________________________________
40 AliMpStringObjMap::AliMpStringObjMap(Bool_t isOwner)
47 /// Standard constructor
49 fFirstArray.SetOwner(true);
50 fSecondArray.SetOwner(isOwner);
53 //______________________________________________________________________________
54 AliMpStringObjMap::~AliMpStringObjMap()
65 //______________________________________________________________________________
66 Bool_t AliMpStringObjMap::Add(const TString& first, TObject* second)
68 /// Add map element if first not yet present
70 TObject* second2 = Get(first);
72 AliError(Form("%s is already present in the map", first.Data()));
76 fFirstArray.Add(new TObjString(first));
77 fSecondArray.Add(second);
83 //______________________________________________________________________________
84 TObject* AliMpStringObjMap::Get(const TString& first) const
86 /// Find the element with specified key (first)
88 for (Int_t i=0; i<fNofItems; i++) {
89 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
90 return fSecondArray.At(i);
96 //______________________________________________________________________________
97 Int_t AliMpStringObjMap::GetNofItems() const
99 /// Return the number of elements
104 //______________________________________________________________________________
105 void AliMpStringObjMap::Clear(Option_t* /*option*/)
107 /// Delete the elements
110 fFirstArray.Delete();
111 fSecondArray.Delete();
114 //______________________________________________________________________________
115 void AliMpStringObjMap::Print(const char* /*option*/) const
117 /// Print the map elements
119 for (Int_t i=0; i<fNofItems; i++) {
122 << ((TObjString*)fFirstArray.At(i))->GetString()
125 << fSecondArray.At(i)
130 //______________________________________________________________________________
131 void AliMpStringObjMap::Print(const TString& key, ofstream& out) const
135 for (Int_t i=0; i<fNofItems; i++) {
137 << ((TObjString*)fFirstArray.At(i))->GetString()
140 << fSecondArray.At(i)
145 //______________________________________________________________________________
146 void AliMpStringObjMap::First()
148 /// Set iterator to the first item and return its object
154 //______________________________________________________________________________
155 void AliMpStringObjMap::Next()
157 /// Set iterator to the next item and return its object
158 /// Return 0 if there are no more items
164 //______________________________________________________________________________
165 TObject* AliMpStringObjMap::CurrentItem()
167 /// Set iterator to the first item and return its object
169 if ( fCurrentIndex >= fNofItems ) return 0;
171 return fSecondArray.At(fCurrentIndex);
175 //______________________________________________________________________________
176 TString AliMpStringObjMap::CurrentKey()
178 /// Set iterator to the first item and return its object
180 if ( fCurrentIndex >= fNofItems ) return fgkUndefinedKey;
182 return ((TObjString*)fFirstArray.At(fCurrentIndex))->GetString();
186 //______________________________________________________________________________
187 Bool_t AliMpStringObjMap::IsDone() const
189 /// Return true if the iterator reached the end of map
191 return fCurrentIndex >= fNofItems;