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
25 //-----------------------------------------------------------------------------
27 #include "AliMpStringObjMap.h"
31 #include <TObjString.h>
32 #include <Riostream.h>
35 ClassImp(AliMpStringObjMap)
38 const TString AliMpStringObjMap::fgkUndefinedKey = "Undefined";
40 //______________________________________________________________________________
41 AliMpStringObjMap::AliMpStringObjMap(Bool_t isOwner)
48 /// Standard constructor
50 fFirstArray.SetOwner(true);
51 fSecondArray.SetOwner(isOwner);
54 //______________________________________________________________________________
55 AliMpStringObjMap::~AliMpStringObjMap()
66 //______________________________________________________________________________
67 Bool_t AliMpStringObjMap::Add(const TString& first, TObject* second)
69 /// Add map element if first not yet present
71 TObject* second2 = Get(first);
73 AliError(Form("%s is already present in the map", first.Data()));
77 fFirstArray.Add(new TObjString(first));
78 fSecondArray.Add(second);
84 //______________________________________________________________________________
85 TObject* AliMpStringObjMap::Get(const TString& first) const
87 /// Find the element with specified key (first)
89 for (Int_t i=0; i<fNofItems; i++) {
90 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
91 return fSecondArray.At(i);
97 //______________________________________________________________________________
98 Int_t AliMpStringObjMap::GetNofItems() const
100 /// Return the number of elements
105 //______________________________________________________________________________
106 void AliMpStringObjMap::Clear(Option_t* /*option*/)
108 /// Delete the elements
111 fFirstArray.Delete();
112 fSecondArray.Delete();
115 //______________________________________________________________________________
116 void AliMpStringObjMap::Print(const char* /*option*/) const
118 /// Print the map elements
120 for (Int_t i=0; i<fNofItems; i++) {
123 << ((TObjString*)fFirstArray.At(i))->GetString()
126 << fSecondArray.At(i)
131 //______________________________________________________________________________
132 void AliMpStringObjMap::Print(const TString& key, ofstream& out) const
136 for (Int_t i=0; i<fNofItems; i++) {
138 << ((TObjString*)fFirstArray.At(i))->GetString()
141 << fSecondArray.At(i)
146 //______________________________________________________________________________
147 void AliMpStringObjMap::First()
149 /// Set iterator to the first item and return its object
155 //______________________________________________________________________________
156 void AliMpStringObjMap::Next()
158 /// Set iterator to the next item and return its object
159 /// Return 0 if there are no more items
165 //______________________________________________________________________________
166 TObject* AliMpStringObjMap::CurrentItem()
168 /// Set iterator to the first item and return its object
170 if ( fCurrentIndex >= fNofItems ) return 0;
172 return fSecondArray.At(fCurrentIndex);
176 //______________________________________________________________________________
177 TString AliMpStringObjMap::CurrentKey()
179 /// Set iterator to the first item and return its object
181 if ( fCurrentIndex >= fNofItems ) return fgkUndefinedKey;
183 return ((TObjString*)fFirstArray.At(fCurrentIndex))->GetString();
187 //______________________________________________________________________________
188 Bool_t AliMpStringObjMap::IsDone() const
190 /// Return true if the iterator reached the end of map
192 return fCurrentIndex >= fNofItems;