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.
10 // Included in AliRoot: 2003/05/02
11 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
13 #include <Riostream.h>
15 #include "AliMpIntPair.h"
17 ClassImp(AliMpIntPair)
20 ///////////////////////////////////////////////////
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)
27 ///////////////////////////////////////////////////
30 //_____________________________________________________________________________
31 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy)
39 //_____________________________________________________________________________
40 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity)
48 //_____________________________________________________________________________
49 AliMpIntPair::AliMpIntPair()
58 //_____________________________________________________________________________
59 AliMpIntPair::AliMpIntPair(const AliMpIntPair& src):
63 fValidity(src.fValidity)
68 //_____________________________________________________________________________
69 AliMpIntPair::~AliMpIntPair() {
73 //_____________________________________________________________________________
74 Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
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;
83 //_____________________________________________________________________________
84 Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const
86 // are this and pos2 equals?
88 // one valid, one invalid
89 if (fValidity != pos2.fValidity) return false;
92 if (!fValidity) return true;
95 return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond);
98 //_____________________________________________________________________________
99 Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const
101 // are this and pos2 equals?
102 return !(*this == pos2);
105 //_____________________________________________________________________________
106 AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src)
108 // check assignement to self
109 if (this == &src) return *this;
111 // base class assignement
112 TObject::operator=(src);
114 // assignement operator
116 fSecond = src.fSecond;
117 fValidity = src.fValidity;
122 //_____________________________________________________________________________
123 void AliMpIntPair::operator += (const AliMpIntPair& op)
125 // incrementation operator
127 fSecond += op.fSecond;
129 // operation only on valid pairs
130 fValidity = fValidity && op.fValidity;
132 //_____________________________________________________________________________
133 void AliMpIntPair::operator -= (const AliMpIntPair& op)
135 // decrementation operator
137 fSecond -= op.fSecond;
139 // operation only on valid pairs
140 fValidity = fValidity && op.fValidity;
143 //_____________________________________________________________________________
144 AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2)
146 return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
147 op1.GetSecond()-op2.GetSecond(),
148 op1.IsValid() && op2.IsValid());
150 //_____________________________________________________________________________
151 AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2)
153 return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
154 op1.GetSecond()+op2.GetSecond(),
155 op1.IsValid() && op2.IsValid());
157 //_____________________________________________________________________________
158 AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2)
160 return AliMpIntPair(op1.GetFirst()*op2.GetFirst(),
161 op1.GetSecond()*op2.GetSecond(),
162 op1.IsValid() && op2.IsValid());
164 //_____________________________________________________________________________
165 ostream& operator<< (ostream &stream,const AliMpIntPair& op)
169 stream << op.GetFirst()<<','<<op.GetSecond()<<')';
173 stream << "AliMpIntPair::Invalid";