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 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
12 #include <Riostream.h>
14 #include "AliMpIntPair.h"
16 ClassImp(AliMpIntPair)
19 ///////////////////////////////////////////////////
21 // This class is a replacement for the standard STL
22 // pair<int,int> class, which can not be handed
23 // by the normal ROOT automatic streamer
24 // (at least in the ROOT version 3.03/03)
26 ///////////////////////////////////////////////////
29 //_____________________________________________________________________________
30 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy)
38 //_____________________________________________________________________________
39 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity)
47 //_____________________________________________________________________________
48 AliMpIntPair::AliMpIntPair()
57 //_____________________________________________________________________________
58 AliMpIntPair::AliMpIntPair(const AliMpIntPair& src):
62 fValidity(src.fValidity)
67 //_____________________________________________________________________________
68 AliMpIntPair::~AliMpIntPair() {
72 //_____________________________________________________________________________
73 Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
75 // fFirst prior to fSecond
76 if (fFirst<pos2.fFirst) return kTRUE;
77 if (fFirst>pos2.fFirst) return kFALSE;
78 if (fSecond<pos2.fSecond) return kTRUE;
82 //_____________________________________________________________________________
83 Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const
85 // are this and pos2 equals?
87 // one valid, one invalid
88 if (fValidity != pos2.fValidity) return false;
91 if (!fValidity) return true;
94 return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond);
97 //_____________________________________________________________________________
98 Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const
100 // are this and pos2 equals?
101 return !(*this == pos2);
104 //_____________________________________________________________________________
105 AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src)
107 // check assignement to self
108 if (this == &src) return *this;
110 // base class assignement
111 TObject::operator=(src);
113 // assignement operator
115 fSecond = src.fSecond;
116 fValidity = src.fValidity;
121 //_____________________________________________________________________________
122 void AliMpIntPair::operator += (const AliMpIntPair& op)
124 // incrementation operator
126 fSecond += op.fSecond;
128 // operation only on valid pairs
129 fValidity = fValidity && op.fValidity;
131 //_____________________________________________________________________________
132 void AliMpIntPair::operator -= (const AliMpIntPair& op)
134 // decrementation operator
136 fSecond -= op.fSecond;
138 // operation only on valid pairs
139 fValidity = fValidity && op.fValidity;
142 //_____________________________________________________________________________
143 AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2)
145 return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
146 op1.GetSecond()-op2.GetSecond(),
147 op1.IsValid() && op2.IsValid());
149 //_____________________________________________________________________________
150 AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2)
152 return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
153 op1.GetSecond()+op2.GetSecond(),
154 op1.IsValid() && op2.IsValid());
156 //_____________________________________________________________________________
157 AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2)
159 return AliMpIntPair(op1.GetFirst()*op2.GetFirst(),
160 op1.GetSecond()*op2.GetSecond(),
161 op1.IsValid() && op2.IsValid());
163 //_____________________________________________________________________________
164 ostream& operator<< (ostream &stream,const AliMpIntPair& op)
168 stream << op.GetFirst()<<','<<op.GetSecond()<<')';
172 stream << "AliMpIntPair::Invalid";