76#define OGDF_STD_COMPARER(type) \
78 class StdComparer<type> { \
80 static bool less(const type& x, const type& y) { return x < y; } \
81 static bool leq(const type& x, const type& y) { return x <= y; } \
82 static bool greater(const type& x, const type& y) { return x > y; } \
83 static bool geq(const type& x, const type& y) { return x >= y; } \
84 static bool equal(const type& x, const type& y) { return x == y; } \
96 static bool less(
const bool& x,
const bool& y) {
return !x && y; }
98 static bool leq(
const bool& x,
const bool& y) {
return !x || y; }
100 static bool greater(
const bool& x,
const bool& y) {
return x && !y; }
102 static bool geq(
const bool& x,
const bool& y) {
return x || !y; }
104 static bool equal(
const bool& x,
const bool& y) {
return x == y; }
113template<
class CONTENTTYPE,
class STATICCONTENTCOMPARER = StdComparer<CONTENTTYPE>>
119 return STATICCONTENTCOMPARER::less(*x, *y);
123 return STATICCONTENTCOMPARER::leq(*x, *y);
127 return STATICCONTENTCOMPARER::greater(*x, *y);
131 return STATICCONTENTCOMPARER::geq(*x, *y);
135 return STATICCONTENTCOMPARER::equal(*x, *y);
179#define OGDF_AUGMENT_COMPARER(type) \
181 bool less(const type& x, const type& y) const { return compare(x, y) < 0; } \
182 bool leq(const type& x, const type& y) const { return compare(x, y) <= 0; } \
183 bool greater(const type& x, const type& y) const { return compare(x, y) > 0; } \
184 bool geq(const type& x, const type& y) const { return compare(x, y) >= 0; } \
185 bool equal(const type& x, const type& y) const { return compare(x, y) == 0; }
225#define OGDF_AUGMENT_STATICCOMPARER(type) \
227 static bool less(const type& x, const type& y) { return compare(x, y) < 0; } \
228 static bool leq(const type& x, const type& y) { return compare(x, y) <= 0; } \
229 static bool greater(const type& x, const type& y) { return compare(x, y) > 0; } \
230 static bool geq(const type& x, const type& y) { return compare(x, y) >= 0; } \
231 static bool equal(const type& x, const type& y) { return compare(x, y) == 0; }
267 virtual int compare(
const E& x,
const E& y)
const = 0;
270 virtual bool less(
const E& x,
const E& y)
const {
return compare(x, y) < 0; }
273 virtual bool leq(
const E& x,
const E& y)
const {
return compare(x, y) <= 0; }
279 virtual bool geq(
const E& x,
const E& y)
const {
return compare(x, y) >= 0; }
282 virtual bool equal(
const E& x,
const E& y)
const {
return compare(x, y) == 0; }
290template<
class X,
class Priority =
double>
339template<
class X,
class Priority>
369template<
typename TYPE,
class COMPARER = StdComparer<TYPE>>
372 bool operator()(
const TYPE& x,
const TYPE& y)
const {
return COMPARER::less(x, y); }
381template<
typename TYPE,
class COMPARER = StdComparer<TYPE>>
384 bool operator()(
const TYPE& x,
const TYPE& y)
const {
return COMPARER::greater(x, y); }
397template<
typename ELEM,
typename NUM,
bool ascending = true>
409 return a == b ? 0 : ((a < b) ==
ascending ? -1 : 1);
434#define OGDF_DECLARE_COMPARER(NAME, TYPE, NUMBER, GET_X_ATTR) \
435 struct NAME : public GenericComparer<TYPE, NUMBER> { \
436 NAME() : GenericComparer([&](const TYPE& x) { return GET_X_ATTR; }) { } \
Exception thrown when a required standard comparer has not been specialized.
Augments any data elements of type X with keys of type Priority. This class is also its own Comparer.
bool operator<=(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
Prioritized(const Prioritized &P)=default
Copy-constructor.
X item() const
Returns the data of the element.
bool operator==(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
Priority priority() const
Returns the key of the element.
void setItem(X item)
Sets value x.
bool operator!=(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
bool operator>(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
void setPriority(Priority pp)
Sets priority.
Prioritized(X xt, Priority pt)
Constructor using a key/value pair.
Prioritized & operator=(const Prioritized< X, Priority > &P)=default
Copy assignment operator.
Prioritized()
Constructor of empty element. Be careful!
bool operator<(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
bool operator>=(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
static bool greater(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)
static bool leq(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)
static bool geq(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)
static bool equal(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)
static bool less(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)
static bool equal(const bool &x, const bool &y)
static bool less(const bool &x, const bool &y)
static bool leq(const bool &x, const bool &y)
static bool geq(const bool &x, const bool &y)
static bool greater(const bool &x, const bool &y)
Standard comparer (valid as a static comparer).
static bool less(const E &x, const E &y)
static bool equal(const E &x, const E &y)
static bool leq(const E &x, const E &y)
static bool geq(const E &x, const E &y)
static bool greater(const E &x, const E &y)
Template for converting any StdComparer into a STL compatible compare functor.
bool operator()(const TYPE &x, const TYPE &y) const
Template for converting any StdComparer into a STL compatible compare functor.
bool operator()(const TYPE &x, const TYPE &y) const
A static comparer which compares the target of pointers ("content"), instead of the pointer's adresse...
static bool less(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
static bool equal(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
static bool geq(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
CONTENTTYPE * CONTENTPOINTER
static bool leq(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
static bool greater(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
Abstract base class for comparer classes.
virtual int compare(const E &x, const E &y) const =0
Compares x and y and returns the result as an integer.
VComparer()
Initializes a comparer.
virtual bool geq(const E &x, const E &y) const
Returns true iff x >= y.
virtual bool equal(const E &x, const E &y) const
Returns true iff x = y.
virtual bool leq(const E &x, const E &y) const
Returns true iff x <= y.
virtual bool less(const E &x, const E &y) const
Returns true iff x < y.
virtual bool greater(const E &x, const E &y) const
Returns true iff x > y.
Definition of exception classes.
#define OGDF_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
#define OGDF_STD_COMPARER(type)
Generates a specialization of the standard static comparer for type based on compare operators.
#define OGDF_THROW(CLASS)
Replacement for throw.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Compare elements based on a single comparable attribute.
int compare(const ELEM &x, const ELEM &y) const
See OGDF_AUGMENT_COMPARER.
GenericComparer(const OrderFunction &mapToValue)
Construct a comparer with mapping mapToValue.
const OrderFunction m_mapToValue
std::function< NUM(const ELEM &)> OrderFunction