Cmp< double > Class Template Reference

#include <Cmp.hh>

List of all members.


Detailed Description

template<>
class Rivet::Rivet::Cmp< double >

Specialization of Cmp for checking the ordering of two floating point numbers.

When implicitly converted to an integer the value will be negative if the two objects used in the constructor are ordered and positive if they are not. Zero will be returned if they are equal. This specialization uses the Rivet fuzzyEquals function to indicate equivalence protected from numerical precision effects.

The main usage of the Cmp class is if several variables should be checked for ordering in which case several Cmp objects can be combined as follows: cmp(a1, a2) || cmp(b1, b2) || cmp(c1, c2) where cmp is a global function for easy creation of Cmp objects.

Definition at line 205 of file Cmp.hh.


Public Member Functions

 operator CmpState () const
 Automatically convert to an enum.
 operator int () const
 Automatically convert to an integer.
template<typename U>
const Cmp< double > & operator|| (const Cmp< U > &c) const
 If this state is equivalent, set this state to the state of c.
Standard constructors and destructors.
 Cmp (const double p1, const double p2)
 The default constructor.
template<typename U>
 Cmp (const Cmp< U > &x)
 The copy constructor.
 ~Cmp ()
 The destructor is not virtual since this is not intended to be a base class.
template<typename U>
const Cmp< double > & operator= (const Cmp< U > &x)
 The assignment operator.

Private Member Functions

void _compare () const
 Perform the actual comparison if necessary.

Private Attributes

CmpState _value
 The state of this object.
double _numA
 The objects to be compared.
double _numB

Constructor & Destructor Documentation

~Cmp (  )  [inline]

The destructor is not virtual since this is not intended to be a base class.

Definition at line 222 of file Cmp.hh.

00222 { }


Member Function Documentation

Cmp ( const double  p1,
const double  p2 
) [inline]

The default constructor.

Definition at line 211 of file Cmp.hh.

00212       : _value(UNDEFINED), _numA(p1), _numB(p2)
00213     { }

Cmp ( const Cmp< U > &  x  )  [inline]

The copy constructor.

Definition at line 217 of file Cmp.hh.

00218       : _value(x), _numA(0.0), _numB(0.0)
00219     { }

const Cmp<double>& operator= ( const Cmp< U > &  x  )  [inline]

The assignment operator.

Definition at line 226 of file Cmp.hh.

References Cmp::_value.

00226                                                   {
00227       _value = x;
00228       return *this;
00229     }

operator CmpState (  )  const [inline]

Automatically convert to an enum.

Definition at line 235 of file Cmp.hh.

References Cmp::_compare(), and Cmp::_value.

00235                               {
00236       _compare();
00237       return _value;
00238     }

operator int (  )  const [inline]

Automatically convert to an integer.

Definition at line 241 of file Cmp.hh.

References Cmp::_compare(), and Cmp::_value.

00241                          {
00242       _compare();
00243       return _value;
00244     }

const Cmp<double>& operator|| ( const Cmp< U > &  c  )  const [inline]

If this state is equivalent, set this state to the state of c.

Definition at line 248 of file Cmp.hh.

References Cmp::_compare(), Cmp::_value, and Rivet::EQUIVALENT.

00248                                                          {
00249       _compare();
00250       if (_value == EQUIVALENT) _value = c;
00251       return *this;
00252     }

void _compare (  )  const [inline, private]

Perform the actual comparison if necessary.

Definition at line 257 of file Cmp.hh.

References Cmp::_value, Rivet::EQUIVALENT, Rivet::fuzzyEquals(), Rivet::ORDERED, Rivet::UNDEFINED, and Rivet::UNORDERED.

00257                           {
00258       if (_value == UNDEFINED) {
00259         if (fuzzyEquals(_numA,_numB)) _value = EQUIVALENT;
00260         else if (_numA < _numB) _value = ORDERED;
00261         else _value = UNORDERED;
00262       }
00263     }


Member Data Documentation

CmpState _value [mutable, private]

The state of this object.

Definition at line 268 of file Cmp.hh.

double _numA [private]

The objects to be compared.

Definition at line 271 of file Cmp.hh.

double _numB [private]

Definition at line 271 of file Cmp.hh.


The documentation for this class was generated from the following file: