Open
Graph Drawing
Framework

 v.2012.07
 

comparer.h File Reference

Declarations for Comparer objects. More...

Go to the source code of this file.

Classes

class  ogdf::StdComparer< E >
 Standard comparer (valid as a static comparer). More...
class  ogdf::StdComparer< bool >
 Generates a specialization of the standard static comparer for booleans. More...
class  ogdf::TargetComparer< CONTENTTYPE, STATICCONTENTCOMPARER >
 A static comparer which compares the target of pointers ("content"), instead of the pointer's adresses. More...
class  ogdf::VComparer< E >
 Abstract base class for comparer classes. More...

Namespaces

namespace  ogdf
 The namespace for all OGDF objects.

Macros

#define OGDF_AUGMENT_COMPARER(type)
 Add this macro to your class to turn it into a full comparer.
#define OGDF_AUGMENT_STATICCOMPARER(type)
 Add this macro to your class to turn it into a full static comparer.
#define OGDF_COMPARER_H
#define OGDF_STD_COMPARER(type)
 Generates a specialization of the standard static comparer for type based on compare operators.

Detailed Description

Declarations for Comparer objects.

Author:
Markus Chimani, Carsten Gutwenger
License:
This file is part of the Open Graph Drawing Framework (OGDF).
Copyright (C)
See README.txt in the root directory of the OGDF installation for details.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License Version 2 or 3 as published by the Free Software Foundation; see the file LICENSE.txt included in the packaging of this file for details.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See also:
http://www.gnu.org/copyleft/gpl.html

Definition in file comparer.h.


Macro Definition Documentation

#define OGDF_AUGMENT_COMPARER (   type)
Value:
public: \
bool less(const type &x, const type &y) const { return compare(x,y) < 0; } \
bool leq(const type &x, const type &y) const { return compare(x,y) <= 0; } \
bool greater(const type &x, const type &y) const { return compare(x,y) > 0; } \
bool geq(const type &x, const type &y) const { return compare(x,y) >= 0; } \
bool equal(const type &x, const type &y) const { return compare(x,y) == 0; }

Add this macro to your class to turn it into a full comparer.

It is assumed that your class has a method "compare(const type &x, const type &y)", which returns 0 if the two elements are equal, a negative value if x is smaller, and a positive value if x is greater.

Note: If the compare function of your class requires no additional data other than the two elements to compare, your should usually use the more general OGDF_AUGMENT_STATICCOMPARER: A static comparer is also always valid as a normal comparer.

Usage in Definition:

class MyComparer {
private:
Oracle oracle;
public:
MyComparer(Oracle o) : oracle(o) {}
int compare(const MyStuff& x1, const MyStuff& x2) const {
return ... //compare x1 with x2, using oracle
}
}

Use the Comparer:

MyStuff a=...;
MyStuff b=...;
Oracle or;
MyComparer comp(or);
if( comp.less(a,b) )
... // do something
...
Array<MyStuff> ay(10);
... // fill array
ay.quicksort(comp); // sort the array using the MyComparer comp

Definition at line 171 of file comparer.h.

#define OGDF_AUGMENT_STATICCOMPARER (   type)
Value:
public: \
static bool less(const type &x, const type &y) { return compare(x,y) < 0; } \
static bool leq(const type &x, const type &y) { return compare(x,y) <= 0; } \
static bool greater(const type &x, const type &y) { return compare(x,y) > 0; } \
static bool geq(const type &x, const type &y) { return compare(x,y) >= 0; } \
static bool equal(const type &x, const type &y) { return compare(x,y) == 0; }

Add this macro to your class to turn it into a full static comparer.

It is assumed that your class has a static method "compare(const type &x, const type &y)", which returns 0 if the two elements are equal, a negative value if x is smaller, and a positive value if x is greater.

Note: You should use this macro instead of OGDF_AUGMENT_COMPARER whenever your compare function requires no additional data stored in the object, other than the two elements to compare. A static comparer is also always valid as a normal comparer.

Usage in Definition:

class MyComparer {
public:
static int comparer(const MyStuff& x1, const MyStuff& x2) {
return ... //compare x1 with x2
}
}

Use the Comparer:

MyStuff a=...;
MyStuff b=...;
MyComparer comp;
if( MyComparer.less(a,b) ) // use it statically on the class
... // do something
if( comp.less(a,b) ) // use it on the object
... // do something
...
Array<MyStuff> ay(10);
... // fill array
ay.quicksort(comp); // sort the array using the MyComparer comp

Definition at line 215 of file comparer.h.

#define OGDF_COMPARER_H

Definition at line 49 of file comparer.h.

#define OGDF_STD_COMPARER (   type)
Value:
template<> class StdComparer<type> \
{ \
public: \
static bool less (const type &x, const type &y) { return x < y; } \
static bool leq (const type &x, const type &y) { return x <= y; } \
static bool greater(const type &x, const type &y) { return x > y; } \
static bool geq (const type &x, const type &y) { return x >= y; } \
static bool equal (const type &x, const type &y) { return x == y; } \
};

Generates a specialization of the standard static comparer for type based on compare operators.

Definition at line 91 of file comparer.h.