]>
Commit | Line | Data |
---|---|---|
5f91c9e8 | 1 | // $Id$ |
2 | // Category: basic | |
3 | // | |
4 | // Class AliMpIntPair | |
5 | // -------------- | |
6 | // Class that defines the pair of integers. | |
7 | // The pair created by the default constructor is in invalide state, | |
8 | // setting one of values changes the state to valid. | |
9 | // | |
dbe945cc | 10 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 11 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay |
12 | ||
13 | #include <Riostream.h> | |
14 | ||
15 | #include "AliMpIntPair.h" | |
16 | ||
17 | ClassImp(AliMpIntPair) | |
18 | ||
19 | ||
20 | /////////////////////////////////////////////////// | |
21 | // | |
22 | // This class is a replacement for the standard STL | |
23 | // pair<int,int> class, which can not be handed | |
24 | // by the normal ROOT automatic streamer | |
25 | // (at least in the ROOT version 3.03/03) | |
26 | // | |
27 | /////////////////////////////////////////////////// | |
28 | ||
29 | ||
30 | //_____________________________________________________________________________ | |
31 | AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy) | |
32 | : TObject(), | |
33 | fFirst(ix), | |
34 | fSecond(iy), | |
35 | fValidity(true) { | |
36 | // | |
37 | } | |
38 | ||
39 | //_____________________________________________________________________________ | |
40 | AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity) | |
41 | : TObject(), | |
42 | fFirst(ix), | |
43 | fSecond(iy), | |
44 | fValidity(validity) { | |
45 | // | |
46 | } | |
47 | ||
48 | //_____________________________________________________________________________ | |
49 | AliMpIntPair::AliMpIntPair() | |
50 | : TObject(), | |
51 | //fFirst(9999), | |
52 | //fSecond(9999), | |
53 | fFirst(0), | |
54 | fSecond(0), | |
55 | fValidity(false) { | |
56 | // | |
57 | } | |
58 | //_____________________________________________________________________________ | |
59 | AliMpIntPair::AliMpIntPair(const AliMpIntPair& src): | |
60 | TObject(src), | |
61 | fFirst(src.fFirst), | |
62 | fSecond(src.fSecond), | |
63 | fValidity(src.fValidity) | |
64 | { | |
65 | ||
66 | } | |
67 | ||
68 | //_____________________________________________________________________________ | |
69 | AliMpIntPair::~AliMpIntPair() { | |
70 | // | |
71 | } | |
72 | ||
73 | //_____________________________________________________________________________ | |
74 | Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const | |
75 | { | |
76 | // fFirst prior to fSecond | |
77 | if (fFirst<pos2.fFirst) return kTRUE; | |
78 | if (fFirst>pos2.fFirst) return kFALSE; | |
79 | if (fSecond<pos2.fSecond) return kTRUE; | |
80 | return kFALSE; | |
81 | } | |
82 | ||
83 | //_____________________________________________________________________________ | |
84 | Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const | |
85 | { | |
86 | // are this and pos2 equals? | |
87 | ||
88 | // one valid, one invalid | |
89 | if (fValidity != pos2.fValidity) return false; | |
90 | ||
91 | // both invalid | |
92 | if (!fValidity) return true; | |
93 | ||
94 | // both valid | |
95 | return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond); | |
96 | } | |
97 | ||
98 | //_____________________________________________________________________________ | |
99 | Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const | |
100 | { | |
101 | // are this and pos2 equals? | |
102 | return !(*this == pos2); | |
103 | } | |
104 | ||
105 | //_____________________________________________________________________________ | |
106 | AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src) | |
107 | { | |
108 | // check assignement to self | |
109 | if (this == &src) return *this; | |
110 | ||
111 | // base class assignement | |
112 | TObject::operator=(src); | |
113 | ||
114 | // assignement operator | |
115 | fFirst = src.fFirst; | |
116 | fSecond = src.fSecond; | |
117 | fValidity = src.fValidity; | |
118 | ||
119 | return *this; | |
120 | } | |
121 | ||
122 | //_____________________________________________________________________________ | |
123 | void AliMpIntPair::operator += (const AliMpIntPair& op) | |
124 | { | |
125 | // incrementation operator | |
126 | fFirst += op.fFirst; | |
127 | fSecond += op.fSecond; | |
128 | ||
129 | // operation only on valid pairs | |
130 | fValidity = fValidity && op.fValidity; | |
131 | } | |
132 | //_____________________________________________________________________________ | |
133 | void AliMpIntPair::operator -= (const AliMpIntPair& op) | |
134 | { | |
135 | // decrementation operator | |
136 | fFirst -= op.fFirst; | |
137 | fSecond -= op.fSecond; | |
138 | ||
139 | // operation only on valid pairs | |
140 | fValidity = fValidity && op.fValidity; | |
141 | } | |
142 | ||
143 | //_____________________________________________________________________________ | |
144 | AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2) | |
145 | { | |
146 | return AliMpIntPair(op1.GetFirst()-op2.GetFirst(), | |
147 | op1.GetSecond()-op2.GetSecond(), | |
148 | op1.IsValid() && op2.IsValid()); | |
149 | } | |
150 | //_____________________________________________________________________________ | |
151 | AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2) | |
152 | { | |
153 | return AliMpIntPair(op1.GetFirst()+op2.GetFirst(), | |
154 | op1.GetSecond()+op2.GetSecond(), | |
155 | op1.IsValid() && op2.IsValid()); | |
156 | } | |
157 | //_____________________________________________________________________________ | |
158 | AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2) | |
159 | { | |
160 | return AliMpIntPair(op1.GetFirst()*op2.GetFirst(), | |
161 | op1.GetSecond()*op2.GetSecond(), | |
162 | op1.IsValid() && op2.IsValid()); | |
163 | } | |
164 | //_____________________________________________________________________________ | |
165 | ostream& operator<< (ostream &stream,const AliMpIntPair& op) | |
166 | { | |
167 | if (op.IsValid()) { | |
168 | stream << '('; | |
169 | stream << op.GetFirst()<<','<<op.GetSecond()<<')'; | |
170 | return stream; | |
171 | } | |
172 | else { | |
173 | stream << "AliMpIntPair::Invalid"; | |
174 | return stream; | |
175 | } | |
176 | } | |
177 |