]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpStringObjMap.cxx
- Adding comment lines to class description needed for Root documentation
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpStringObjMap.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 // $Id$
17 // $MpId: AliMpStringObjMap.cxx,v 1.4 2006/05/24 13:58:29 ivana Exp $
18
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
26 #include "AliMpStringObjMap.h"
27
28 #include "AliLog.h"
29
30 #include <TObjString.h>
31 #include <Riostream.h>
32
33 /// \cond CLASSIMP
34 ClassImp(AliMpStringObjMap)
35 /// \endcond
36
37 const TString AliMpStringObjMap::fgkUndefinedKey = "Undefined";
38
39 //______________________________________________________________________________
40 AliMpStringObjMap::AliMpStringObjMap(Bool_t isOwner)
41  : TObject(),
42    fNofItems(0),
43    fFirstArray(),
44    fSecondArray(),
45    fCurrentIndex(0)
46 {
47 /// Standard constructor
48
49   fFirstArray.SetOwner(true);
50   fSecondArray.SetOwner(isOwner);
51 }
52
53 //______________________________________________________________________________
54 AliMpStringObjMap::~AliMpStringObjMap()
55 {
56 /// Destructor
57
58   fFirstArray.Delete();
59 }
60
61 //
62 // public methods
63 //
64
65 //______________________________________________________________________________
66 Bool_t  AliMpStringObjMap::Add(const TString& first, TObject* second)
67 {
68 /// Add map element if first not yet present
69
70   TObject* second2 = Get(first);
71   if ( second2 ) {
72     AliError(Form("%s is already present in the map", first.Data()));
73     return false;
74   }
75   
76   fFirstArray.Add(new TObjString(first)); 
77   fSecondArray.Add(second);
78   fNofItems++;
79    
80   return true;
81 }  
82
83 //______________________________________________________________________________
84 TObject*  AliMpStringObjMap::Get(const TString& first) const
85 {
86 /// Find the element with specified key (first)
87   
88   for (Int_t i=0; i<fNofItems; i++) {
89     if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
90       return fSecondArray.At(i);
91   }
92   
93   return 0;
94 }      
95
96 //______________________________________________________________________________
97 Int_t  AliMpStringObjMap::GetNofItems() const
98 {
99 /// Return the number of elements
100
101   return fNofItems;
102 }  
103
104 //______________________________________________________________________________
105 void  AliMpStringObjMap::Clear(Option_t* /*option*/)
106 {
107 /// Delete the elements
108
109   fNofItems = 0;
110   fFirstArray.Delete();
111   fSecondArray.Delete();
112 }  
113     
114 //______________________________________________________________________________
115 void AliMpStringObjMap::Print(const char* /*option*/) const
116 {
117 /// Print the map elements
118
119   for (Int_t i=0; i<fNofItems; i++) {
120     cout << setw(4)
121          << i << "  "
122          << ((TObjString*)fFirstArray.At(i))->GetString()
123          << "  "
124          << setw(5)
125          << fSecondArray.At(i)
126          << endl;
127   }
128 }        
129
130 //______________________________________________________________________________
131 void AliMpStringObjMap::Print(const TString& key, ofstream& out) const
132 {
133 /// Special printing 
134
135   for (Int_t i=0; i<fNofItems; i++) {
136     out  << key << "  "
137          << ((TObjString*)fFirstArray.At(i))->GetString()
138          << "  "
139          << setw(5)
140          << fSecondArray.At(i)
141          << endl;
142   }
143 }        
144
145 //______________________________________________________________________________
146 void  AliMpStringObjMap::First()
147 {
148 /// Set iterator to the first item and return its object
149
150   fCurrentIndex = 0; 
151 }  
152   
153
154 //______________________________________________________________________________
155 void  AliMpStringObjMap::Next()
156 {
157 /// Set iterator to the next item and return its object
158 /// Return 0 if there are no more items
159
160   ++fCurrentIndex;
161 }  
162     
163
164 //______________________________________________________________________________
165 TObject* AliMpStringObjMap::CurrentItem()
166 {
167 /// Set iterator to the first item and return its object
168
169   if ( fCurrentIndex >= fNofItems ) return 0;
170
171   return fSecondArray.At(fCurrentIndex);
172 }  
173   
174
175 //______________________________________________________________________________
176 TString AliMpStringObjMap::CurrentKey()
177 {
178 /// Set iterator to the first item and return its object
179
180   if ( fCurrentIndex >= fNofItems ) return fgkUndefinedKey;
181   
182   return ((TObjString*)fFirstArray.At(fCurrentIndex))->GetString();
183 }  
184   
185
186 //______________________________________________________________________________
187 Bool_t  AliMpStringObjMap::IsDone() const
188 {
189 /// Return true if the iterator reached the end of map
190
191   return fCurrentIndex >= fNofItems;
192 }   
193