72 #define OGDF_STD_COMPARER(type) \ 73 template<> class StdComparer<type> \ 76 static bool less (const type &x, const type &y) { return x < y; } \ 77 static bool leq (const type &x, const type &y) { return x <= y; } \ 78 static bool greater(const type &x, const type &y) { return x > y; } \ 79 static bool geq (const type &x, const type &y) { return x >= y; } \ 80 static bool equal (const type &x, const type &y) { return x == y; } \ 88 template<>
class StdComparer<bool> {
91 static bool less (
const bool &x,
const bool &y) {
return !x && y; }
92 static bool leq (
const bool &x,
const bool &y) {
return !x || y; }
93 static bool greater(
const bool &x,
const bool &y) {
return x && !y; }
94 static bool geq (
const bool &x,
const bool &y) {
return x || !y; }
95 static bool equal (
const bool &x,
const bool &y) {
return x == y; }
105 template<
class CONTENTTYPE,
class STATICCONTENTCOMPARER = StdComparer<CONTENTTYPE> >
157 #define OGDF_AUGMENT_COMPARER(type) \ 159 bool less(const type &x, const type &y) const { return compare(x,y) < 0; } \ 160 bool leq(const type &x, const type &y) const { return compare(x,y) <= 0; } \ 161 bool greater(const type &x, const type &y) const { return compare(x,y) > 0; } \ 162 bool geq(const type &x, const type &y) const { return compare(x,y) >= 0; } \ 163 bool equal(const type &x, const type &y) const { return compare(x,y) == 0; } 203 #define OGDF_AUGMENT_STATICCOMPARER(type) \ 205 static bool less(const type &x, const type &y) { return compare(x,y) < 0; } \ 206 static bool leq(const type &x, const type &y) { return compare(x,y) <= 0; } \ 207 static bool greater(const type &x, const type &y) { return compare(x,y) > 0; } \ 208 static bool geq(const type &x, const type &y) { return compare(x,y) >= 0; } \ 209 static bool equal(const type &x, const type &y) { return compare(x,y) == 0; } 245 virtual int compare(
const E &x,
const E &y)
const = 0;
248 virtual bool less(
const E &x,
const E &y)
const {
249 return compare(x,y) < 0;
253 virtual bool leq(
const E &x,
const E &y)
const {
254 return compare(x,y) <= 0;
258 virtual bool greater(
const E &x,
const E &y)
const {
259 return compare(x,y) > 0;
263 virtual bool geq(
const E &x,
const E &y)
const {
264 return compare(x,y) >= 0;
268 virtual bool equal(
const E &x,
const E &y)
const {
269 return compare(x,y) == 0;
278 template<
class X,
class Priority=
double>
309 bool operator<(const Prioritized<X,Priority>& P)
const {
return p<P.
p; }
312 bool operator<=(const Prioritized<X,Priority>& P)
const {
return p<=P.
p; }
343 template<
typename TYPE,
class COMPARER = StdComparer<TYPE>>
347 return COMPARER::less(x, y);
358 template<
typename TYPE,
class COMPARER = StdComparer<TYPE>>
362 return COMPARER::greater(x, y);
376 template<
typename ELEM,
typename NUM,
bool ascending = true>
384 int compare(
const ELEM& x,
const ELEM& y)
const {
385 NUM a = m_mapToValue(x);
386 NUM b = m_mapToValue(y);
388 return a == b ? 0 : ((a < b) == ascending ? -1 : 1);
413 #define OGDF_DECLARE_COMPARER(NAME, TYPE, NUMBER, GET_X_ATTR) \ 414 struct NAME : public GenericComparer<TYPE, NUMBER> { \ 415 NAME() : GenericComparer([&](const TYPE& x) { return GET_X_ATTR; }) {} \ CONTENTTYPE * CONTENTPOINTER
void setItem(X item)
Sets value x.
A static comparer which compares the target of pointers ("content"), instead of the pointer's adresse...
static bool leq(const E &x, const E &y)
bool operator()(const TYPE &x, const TYPE &y) const
void setPriority(Priority pp)
Sets priority.
static bool greater(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)
static bool less(const E &x, const E &y)
int compare(const ELEM &x, const ELEM &y) const
See OGDF_AUGMENT_COMPARER.
#define OGDF_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
const OrderFunction m_mapToValue
#define OGDF_THROW(CLASS)
Replacement for throw.
Priority priority() const
Returns the key of the element.
bool operator()(const TYPE &x, const TYPE &y) const
std::function< NUM(const ELEM &)> OrderFunction
#define OGDF_STD_COMPARER(type)
Generates a specialization of the standard static comparer for type based on compare operators...
bool operator!=(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
virtual bool less(const E &x, const E &y) const
Returns true iff x < y.
static bool greater(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
Augments any data elements of type X with keys of type Priority. This class is also its own Comparer...
static bool geq(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)
bool operator>=(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
Template for converting any StdComparer into a STL compatible compare functor.
Standard comparer (valid as a static comparer).
static bool equal(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
bool operator==(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
static bool geq(const E &x, const E &y)
virtual bool leq(const E &x, const E &y) const
Returns true iff x <= y.
Abstract base class for comparer classes.
static bool less(const bool &x, const bool &y)
static bool greater(const E &x, const E &y)
X item() const
Returns the data of the element.
Definition of exception classes.
virtual bool equal(const E &x, const E &y) const
Returns true iff x = y.
static bool equal(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)
Template for converting any StdComparer into a STL compatible compare functor.
static bool leq(const bool &x, const bool &y)
GenericComparer(const OrderFunction &mapToValue)
Construct a comparer with mapping mapToValue.
static bool equal(const bool &x, const bool &y)
static bool less(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)
virtual bool greater(const E &x, const E &y) const
Returns true iff x > y.
static bool leq(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
static bool greater(const bool &x, const bool &y)
Exception thrown when a required standard comparer has not been specialized.
static bool equal(const E &x, const E &y)
static bool geq(const bool &x, const bool &y)
VComparer()
Initializes a comparer.
Prioritized()
Constructor of empty element. Be careful!
virtual bool geq(const E &x, const E &y) const
Returns true iff x >= y.
The namespace for all OGDF objects.
Compare elements based on a single comparable attribute.
static bool less(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
Prioritized(X xt, Priority pt)
Constructor using a key/value pair.
static bool geq(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
bool operator>(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
static bool leq(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)