Cmp Class Template Reference

#include <Cmp.hh>

List of all members.


Detailed Description

template<typename T>
class Rivet::Cmp< T >

Helper class when checking the ordering of two objects.

Cmp is a helper class to be used when checking the ordering of two objects. 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.

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 27 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< T > & operator|| (const Cmp< U > &c) const
 If this state is equivalent, set this state to the state of c.
Standard constructors etc.
 Cmp (const T &t1, const T &t2)
 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< T > & 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.
pair< const T *, const T * > _objects
 The objects to be compared.

Constructor & Destructor Documentation

Cmp ( const T &  t1,
const T &  t2 
) [inline]

The default constructor.

Definition at line 33 of file Cmp.hh.

00034       : _value(UNDEFINED), _objects(&t1, &t2) { }

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

The copy constructor.

Definition at line 38 of file Cmp.hh.

00039       : _value(x), _objects(0, 0) { }

~Cmp (  )  [inline]

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

Definition at line 42 of file Cmp.hh.

00042 { };


Member Function Documentation

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

The assignment operator.

Definition at line 46 of file Cmp.hh.

References Cmp::_value.

00046                                              {
00047       _value = x;
00048       return *this;
00049     }

operator CmpState (  )  const [inline]

Automatically convert to an enum.

Definition at line 55 of file Cmp.hh.

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

00055                               {
00056       _compare();
00057       return _value;
00058     }

operator int (  )  const [inline]

Automatically convert to an integer.

Definition at line 61 of file Cmp.hh.

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

00061                          {
00062       _compare();
00063       return _value;
00064     }

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

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

Definition at line 68 of file Cmp.hh.

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

00068                                                     {
00069       _compare();
00070       if (_value == EQUIVALENT) _value = c;
00071       return *this;
00072     }

void _compare (  )  const [inline, private]

Perform the actual comparison if necessary.

Definition at line 77 of file Cmp.hh.

References Cmp::_objects, Cmp::_value, Rivet::EQUIVALENT, Rivet::ORDERED, Rivet::UNDEFINED, and Rivet::UNORDERED.

Referenced by Cmp< double >::operator CmpState(), Cmp< Projection >::operator CmpState(), Cmp::operator CmpState(), Cmp< double >::operator int(), Cmp< Projection >::operator int(), Cmp::operator int(), Cmp< double >::operator||(), Cmp< Projection >::operator||(), and Cmp::operator||().

00077                           {
00078       if (_value == UNDEFINED) {
00079         less<T> l;
00080         if ( l(*_objects.first, *_objects.second) ) _value = ORDERED;
00081         else if ( l(*_objects.second, *_objects.first) ) _value = UNORDERED;
00082         else _value = EQUIVALENT;
00083       }
00084     }


Member Data Documentation

CmpState _value [mutable, private]

pair<const T*, const T*> _objects [private]

The objects to be compared.

Definition at line 90 of file Cmp.hh.

Referenced by Cmp< Projection >::_compare(), and Cmp::_compare().


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