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< int > |
| class | ogdf::StdComparer< float > |
| class | ogdf::StdComparer< double > |
| 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. | |
Defines | |
| #define | OGDF_COMPARER_H |
| #define | OGDF_STD_COMPARER(type) |
| Generates a specialization of the standard static comparer for type based on compare operators. | |
| #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. | |
Declarations for Comparer objects.
Copyright (C). All rights reserved. See README.txt in the root directory of the OGDF installation for details.
Definition in file comparer.h.
| #define OGDF_AUGMENT_COMPARER | ( | type | ) |
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 } OGDF_AUGMENT_COMPARER(MyStuff) }
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 170 of file comparer.h.
| #define OGDF_AUGMENT_STATICCOMPARER | ( | type | ) |
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 } OGDF_AUGMENT_STATICCOMPARER(MyStuff) }
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 214 of file comparer.h.
| #define OGDF_COMPARER_H |
Definition at line 48 of file comparer.h.
| #define OGDF_STD_COMPARER | ( | type | ) |
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 90 of file comparer.h.