41template<
typename ELEM,
typename NUM,
bool ascending = true>
42struct GenericComparer;
80#define OGDF_STD_COMPARER(type) \
82 class StdComparer<type> { \
84 static bool less(const type& x, const type& y) { return x < y; } \
85 static bool leq(const type& x, const type& y) { return x <= y; } \
86 static bool greater(const type& x, const type& y) { return x > y; } \
87 static bool geq(const type& x, const type& y) { return x >= y; } \
88 static bool equal(const type& x, const type& y) { return x == y; } \
100 static bool less(
const bool& x,
const bool& y) {
return !x && y; }
102 static bool leq(
const bool& x,
const bool& y) {
return !x || y; }
104 static bool greater(
const bool& x,
const bool& y) {
return x && !y; }
106 static bool geq(
const bool& x,
const bool& y) {
return x || !y; }
108 static bool equal(
const bool& x,
const bool& y) {
return x == y; }
117template<
class CONTENTTYPE,
class STATICCONTENTCOMPARER = StdComparer<CONTENTTYPE>>
123 return STATICCONTENTCOMPARER::less(*x, *y);
127 return STATICCONTENTCOMPARER::leq(*x, *y);
131 return STATICCONTENTCOMPARER::greater(*x, *y);
135 return STATICCONTENTCOMPARER::geq(*x, *y);
139 return STATICCONTENTCOMPARER::equal(*x, *y);
183#define OGDF_AUGMENT_COMPARER(type) \
185 bool less(const type& x, const type& y) const { return compare(x, y) < 0; } \
186 bool leq(const type& x, const type& y) const { return compare(x, y) <= 0; } \
187 bool greater(const type& x, const type& y) const { return compare(x, y) > 0; } \
188 bool geq(const type& x, const type& y) const { return compare(x, y) >= 0; } \
189 bool equal(const type& x, const type& y) const { return compare(x, y) == 0; }
229#define OGDF_AUGMENT_STATICCOMPARER(type) \
231 static bool less(const type& x, const type& y) { return compare(x, y) < 0; } \
232 static bool leq(const type& x, const type& y) { return compare(x, y) <= 0; } \
233 static bool greater(const type& x, const type& y) { return compare(x, y) > 0; } \
234 static bool geq(const type& x, const type& y) { return compare(x, y) >= 0; } \
235 static bool equal(const type& x, const type& y) { return compare(x, y) == 0; }
271 virtual int compare(
const E& x,
const E& y)
const = 0;
274 virtual bool less(
const E& x,
const E& y)
const {
return compare(x, y) < 0; }
277 virtual bool leq(
const E& x,
const E& y)
const {
return compare(x, y) <= 0; }
283 virtual bool geq(
const E& x,
const E& y)
const {
return compare(x, y) >= 0; }
286 virtual bool equal(
const E& x,
const E& y)
const {
return compare(x, y) == 0; }
294template<
class X,
class Priority =
double>
343template<
class X,
class Priority>
373template<
typename TYPE,
class COMPARER = StdComparer<TYPE>>
376 bool operator()(
const TYPE& x,
const TYPE& y)
const {
return COMPARER::less(x, y); }
385template<
typename TYPE,
class COMPARER = StdComparer<TYPE>>
388 bool operator()(
const TYPE& x,
const TYPE& y)
const {
return COMPARER::greater(x, y); }
401template<
typename ELEM,
typename NUM,
bool ascending>
409 int compare(
const ELEM& x,
const ELEM& y)
const {
413 return a == b ? 0 : ((a < b) == ascending ? -1 : 1);
438#define OGDF_DECLARE_COMPARER(NAME, TYPE, NUMBER, GET_X_ATTR) \
439 struct NAME : public GenericComparer<TYPE, NUMBER> { \
440 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.
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