Dillo
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
lout::object::Comparator Class Referenceabstract

Used for other orders as the one defined by Comparable. More...

#include <object.hh>

Public Member Functions

virtual int compare (Object *o1, Object *o2)=0
 Compare two objects o1 and o2. More...
 
- Public Member Functions inherited from lout::object::Object
virtual ~Object ()
 The destructor is defined as virtual (but not abstract), so that destruction of Object's works properly. More...
 
virtual bool equals (Object *other)
 Returns, whether two objects are equal. More...
 
virtual int hashValue ()
 Return a hash value for the object. More...
 
virtual Objectclone ()
 Return an exact copy of the object. More...
 
virtual void intoStringBuffer (misc::StringBuffer *sb)
 Store a textual representation of the object in a misc::StringBuffer. More...
 
const char * toString ()
 Use object::Object::intoStringBuffer to return a textual representation of the object. More...
 
virtual size_t sizeOf ()
 Return the number of bytes, this object totally uses. More...
 

Static Public Member Functions

static int compareFun (const void *p1, const void *p2)
 This static method may be used as compare function for qsort(3) and bsearch(3), for an array of Object* (Object*[] or Object**). More...
 

Static Public Attributes

static ComparatorcompareFunComparator = NULL
 

Detailed Description

Used for other orders as the one defined by Comparable.

Compared objects must not neccessary be instances of Comparable.

Member Function Documentation

virtual int lout::object::Comparator::compare ( Object o1,
Object o2 
)
pure virtual

Compare two objects o1 and o2.

Return a value < 0, when o1 is less than o2, a value > 0, when o1 is greater than o2, or 0, when o1 and o2 are equal.

If o1.equals(o2) (as defined in Object), compare(o1, o2) must be 0, but, unlike you may expect, the reversed is not necessarily true. This method returns 0, if, according to the rules for sorting, there is no difference, but there may still be differences (not relevant for sorting), which "equals" will care about.

Implemented in lout::object::StandardComparator.

Referenced by lout::container::untyped::Vector::bsearch(), and compareFun().

int lout::object::Comparator::compareFun ( const void *  p1,
const void *  p2 
)
static

This static method may be used as compare function for qsort(3) and bsearch(3), for an array of Object* (Object*[] or Object**).

"compareFunComparator" should be set before.

Todo:
Not reentrant. Consider switching to reentrant variants (qsort_r), and compare function with an additional argument.

References compare(), and compareFunComparator.

Referenced by lout::container::untyped::Vector::sort().

Member Data Documentation

Comparator * lout::object::Comparator::compareFunComparator = NULL
static

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