]>
Commit | Line | Data |
---|---|---|
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$ | |
13985652 | 17 | // $MpId: AliMpStringObjMap.cxx,v 1.4 2006/05/24 13:58:29 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 | ||
13985652 | 33 | /// \cond CLASSIMP |
c623aa64 | 34 | ClassImp(AliMpStringObjMap) |
13985652 | 35 | /// \endcond |
c623aa64 | 36 | |
37 | //______________________________________________________________________________ | |
973e9d18 | 38 | AliMpStringObjMap::AliMpStringObjMap(Bool_t isOwner) |
c623aa64 | 39 | : TObject(), |
40 | fNofItems(0), | |
41 | fFirstArray(), | |
42 | fSecondArray() | |
43 | { | |
44 | /// Standard constructor | |
45 | ||
46 | fFirstArray.SetOwner(true); | |
973e9d18 | 47 | fSecondArray.SetOwner(isOwner); |
c623aa64 | 48 | } |
49 | ||
c623aa64 | 50 | //______________________________________________________________________________ |
51 | AliMpStringObjMap::~AliMpStringObjMap() | |
52 | { | |
53 | /// Destructor | |
54 | ||
55 | fFirstArray.Delete(); | |
56 | } | |
57 | ||
c623aa64 | 58 | // |
59 | // public methods | |
60 | // | |
61 | ||
62 | //______________________________________________________________________________ | |
63 | Bool_t AliMpStringObjMap::Add(const TString& first, TObject* second) | |
64 | { | |
65 | /// Add map element if first not yet present | |
66 | ||
67 | TObject* second2 = Get(first); | |
68 | if ( second2 ) { | |
69 | AliError(Form("%s is already present in the map", first.Data())); | |
70 | return false; | |
71 | } | |
72 | ||
73 | fFirstArray.Add(new TObjString(first)); | |
74 | fSecondArray.Add(second); | |
75 | fNofItems++; | |
76 | ||
77 | return true; | |
78 | } | |
79 | ||
80 | //______________________________________________________________________________ | |
81 | TObject* AliMpStringObjMap::Get(const TString& first) const | |
82 | { | |
83 | /// Find the element with specified key (first) | |
84 | ||
85 | for (Int_t i=0; i<fNofItems; i++) { | |
86 | if ( ((TObjString*)fFirstArray.At(i))->GetString() == first ) | |
87 | return fSecondArray.At(i); | |
88 | } | |
89 | ||
90 | return 0; | |
91 | } | |
92 | ||
93 | //______________________________________________________________________________ | |
94 | Int_t AliMpStringObjMap::GetNofItems() const | |
95 | { | |
96 | /// Return the number of elements | |
97 | ||
98 | return fNofItems; | |
99 | } | |
100 | ||
101 | //______________________________________________________________________________ | |
102 | void AliMpStringObjMap::Clear(Option_t* /*option*/) | |
103 | { | |
104 | /// Delete the elements | |
105 | ||
106 | fNofItems = 0; | |
107 | fFirstArray.Delete(); | |
108 | fSecondArray.Delete(); | |
109 | } | |
110 | ||
111 | //______________________________________________________________________________ | |
112 | void AliMpStringObjMap::Print(const char* /*option*/) const | |
113 | { | |
114 | /// Print the map elements | |
115 | ||
116 | for (Int_t i=0; i<fNofItems; i++) { | |
117 | cout << setw(4) | |
118 | << i << " " | |
119 | << ((TObjString*)fFirstArray.At(i))->GetString() | |
120 | << " " | |
121 | << setw(5) | |
122 | << fSecondArray.At(i) | |
123 | << endl; | |
124 | } | |
125 | } | |
126 | ||
127 | //______________________________________________________________________________ | |
128 | void AliMpStringObjMap::Print(const TString& key, ofstream& out) const | |
129 | { | |
f5671fc3 | 130 | /// Special printing |
c623aa64 | 131 | |
132 | for (Int_t i=0; i<fNofItems; i++) { | |
133 | out << key << " " | |
134 | << ((TObjString*)fFirstArray.At(i))->GetString() | |
135 | << " " | |
136 | << setw(5) | |
137 | << fSecondArray.At(i) | |
138 | << endl; | |
139 | } | |
140 | } |