Cmp< Projection > Class Template Reference

#include <Cmp.hh>

List of all members.


Detailed Description

template<>
class Rivet::Rivet::Cmp< Projection >

Specialization of Cmp for checking the ordering of two {Projection}s.

Specialization of the Cmp helper class to be used when checking the ordering of two Projection 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. This specialization uses directly the virtual compare() function in the Projection class.

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 110 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< Projection > & 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 Projection &p1, const Projection &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< Projection > & 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 Projection
*, const Projection * > 
_objects
 The objects to be compared.

Constructor & Destructor Documentation

~Cmp (  )  [inline]

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

Definition at line 127 of file Cmp.hh.

00127 { };


Member Function Documentation

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

The default constructor.

Definition at line 116 of file Cmp.hh.

00117       : _value(UNDEFINED), _objects(&p1, &p2)
00118     { }

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

The copy constructor.

Definition at line 122 of file Cmp.hh.

00123       : _value(x), _objects(0, 0)
00124     { }

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

The assignment operator.

Definition at line 131 of file Cmp.hh.

References Cmp::_value.

00131                                                       {
00132       _value = x;
00133       return *this;
00134     }

operator CmpState (  )  const [inline]

Automatically convert to an enum.

Definition at line 140 of file Cmp.hh.

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

00140                               {
00141       _compare();
00142       return _value;
00143     }

operator int (  )  const [inline]

Automatically convert to an integer.

Definition at line 147 of file Cmp.hh.

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

00147                          {
00148       _compare();
00149       return _value;
00150     }

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

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

Definition at line 154 of file Cmp.hh.

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

00154                                                              {
00155       _compare();
00156       if (_value == EQUIVALENT) _value = c;
00157       return *this;
00158     }

void _compare (  )  const [inline, private]

Perform the actual comparison if necessary.

Definition at line 163 of file Cmp.hh.

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

00163                           {
00164       if (_value == UNDEFINED) {
00165         const std::type_info& id1 = typeid(*_objects.first);
00166         const std::type_info& id2 = typeid(*_objects.second);
00167         if (id1.before(id2)) _value = ORDERED;
00168         else if (id2.before(id1)) _value = UNORDERED;
00169         else {
00170           int c = _objects.first->compare(*_objects.second);
00171           if (c < 0) _value = ORDERED;
00172           else if (c > 0) _value = UNORDERED;
00173           else _value = EQUIVALENT;
00174         }
00175       }
00176     }


Member Data Documentation

CmpState _value [mutable, private]

The state of this object.

Definition at line 181 of file Cmp.hh.

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

The objects to be compared.

Definition at line 184 of file Cmp.hh.


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