Added comments for inline functions
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpStringObjMap.cxx
CommitLineData
c623aa64 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$
2c605e66 17// $MpId: AliMpStringObjMap.cxx,v 1.3 2006/03/17 11:34:46 ivana Exp $
f7006443 18
19// ------------------------------------
c623aa64 20// Class AliMpStringObjMap
21// ------------------------------------
22// Helper class that substitutes map <string, int>
23// which ALICE does not allow to use
c623aa64 24// Author: Ivana Hrivnacova, IPN Orsay
25
c623aa64 26#include "AliMpStringObjMap.h"
2c605e66 27
c623aa64 28#include "AliLog.h"
29
2c605e66 30#include <TObjString.h>
31#include <Riostream.h>
32
c623aa64 33ClassImp(AliMpStringObjMap)
34
35//______________________________________________________________________________
36AliMpStringObjMap::AliMpStringObjMap()
37 : TObject(),
38 fNofItems(0),
39 fFirstArray(),
40 fSecondArray()
41{
42/// Standard constructor
43
44 fFirstArray.SetOwner(true);
45}
46
47//______________________________________________________________________________
48AliMpStringObjMap::AliMpStringObjMap(const AliMpStringObjMap& rhs)
49 : TObject(rhs)
50{
51/// Protected copy constructor
52
53 AliFatal("Copy constructor is not implemented.");
54}
55
56//______________________________________________________________________________
57AliMpStringObjMap::~AliMpStringObjMap()
58{
59/// Destructor
60
61 fFirstArray.Delete();
62}
63
64//______________________________________________________________________________
65AliMpStringObjMap&
66AliMpStringObjMap::operator = (const AliMpStringObjMap& rhs)
67{
68/// Protected assignement operator
69
70 // check assignement to self
71 if (this == &rhs) return *this;
72
73 AliFatal("Assignment operator is not implemented.");
74
75 return *this;
76}
77
78
79//
80// public methods
81//
82
83//______________________________________________________________________________
84Bool_t AliMpStringObjMap::Add(const TString& first, TObject* second)
85{
86/// Add map element if first not yet present
87
88 TObject* second2 = Get(first);
89 if ( second2 ) {
90 AliError(Form("%s is already present in the map", first.Data()));
91 return false;
92 }
93
94 fFirstArray.Add(new TObjString(first));
95 fSecondArray.Add(second);
96 fNofItems++;
97
98 return true;
99}
100
101//______________________________________________________________________________
102TObject* AliMpStringObjMap::Get(const TString& first) const
103{
104/// Find the element with specified key (first)
105
106 for (Int_t i=0; i<fNofItems; i++) {
107 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
108 return fSecondArray.At(i);
109 }
110
111 return 0;
112}
113
114//______________________________________________________________________________
115Int_t AliMpStringObjMap::GetNofItems() const
116{
117/// Return the number of elements
118
119 return fNofItems;
120}
121
122//______________________________________________________________________________
123void AliMpStringObjMap::Clear(Option_t* /*option*/)
124{
125/// Delete the elements
126
127 fNofItems = 0;
128 fFirstArray.Delete();
129 fSecondArray.Delete();
130}
131
132//______________________________________________________________________________
133void AliMpStringObjMap::Print(const char* /*option*/) const
134{
135/// Print the map elements
136
137 for (Int_t i=0; i<fNofItems; i++) {
138 cout << setw(4)
139 << i << " "
140 << ((TObjString*)fFirstArray.At(i))->GetString()
141 << " "
142 << setw(5)
143 << fSecondArray.At(i)
144 << endl;
145 }
146}
147
148//______________________________________________________________________________
149void AliMpStringObjMap::Print(const TString& key, ofstream& out) const
150{
151// Prints the map elements
152
153 for (Int_t i=0; i<fNofItems; i++) {
154 out << key << " "
155 << ((TObjString*)fFirstArray.At(i))->GetString()
156 << " "
157 << setw(5)
158 << fSecondArray.At(i)
159 << endl;
160 }
161}