|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
41 template<
typename ELEM,
typename NUM,
bool ascending = true>
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; }
117 template<
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);
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; }
294 template<
class X,
class Priority =
double>
343 template<
class X,
class Priority>
373 template<
typename TYPE,
class COMPARER = StdComparer<TYPE>>
376 bool operator()(
const TYPE& x,
const TYPE& y)
const {
return COMPARER::less(x, y); }
385 template<
typename TYPE,
class COMPARER = StdComparer<TYPE>>
388 bool operator()(
const TYPE& x,
const TYPE& y)
const {
return COMPARER::greater(x, y); }
401 template<
typename ELEM,
typename NUM,
bool ascending>
402 struct GenericComparer {
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; }) { } \
The namespace for all OGDF objects.
virtual bool equal(const E &x, const E &y) const
Returns true iff x = y.
void setItem(X item)
Sets value x.
Exception thrown when a required standard comparer has not been specialized.
static bool greater(const bool &x, const bool &y)
Definition of exception classes.
Prioritized(X xt, Priority pt)
Constructor using a key/value pair.
Standard comparer (valid as a static comparer).
#define OGDF_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
static bool less(const E &x, const E &y)
CONTENTTYPE * CONTENTPOINTER
static bool geq(const E &x, const E &y)
#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)
Template for converting any StdComparer into a STL compatible compare functor.
VComparer()
Initializes a comparer.
static bool equal(const E &x, const E &y)
Priority priority() const
Returns the key of the element.
static bool leq(const bool &x, const bool &y)
virtual bool less(const E &x, const E &y) const
Returns true iff x < y.
bool operator()(const TYPE &x, const TYPE &y) const
Abstract base class for comparer classes.
static bool equal(const bool &x, const bool &y)
static bool less(const bool &x, const bool &y)
bool operator!=(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
static bool less(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
Template for converting any StdComparer into a STL compatible compare functor.
Prioritized()
Constructor of empty element. Be careful!
#define OGDF_THROW(CLASS)
Replacement for throw.
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)
bool operator<(const Prioritized< X, Priority > &P) const
Comparison oprator based on the compare-operator for the key type (Priority)
bool operator()(const TYPE &x, const TYPE &y) const
virtual bool geq(const E &x, const E &y) const
Returns true iff x >= y.
static bool greater(const E &x, const E &y)
static bool equal(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)
virtual bool leq(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.
const OrderFunction m_mapToValue
virtual int compare(const E &x, const E &y) const =0
Compares x and y and returns the result as an integer.
Prioritized & operator=(const Prioritized< X, Priority > &P)=default
Copy assignment operator.
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)
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)
int compare(const ELEM &x, const ELEM &y) const
See OGDF_AUGMENT_COMPARER.
static bool leq(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
static bool geq(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)
std::function< NUM(const ELEM &)> OrderFunction
void setPriority(Priority pp)
Sets priority.
GenericComparer(const OrderFunction &mapToValue)
Construct a comparer with mapping mapToValue.
static bool geq(const bool &x, const bool &y)
Augments any data elements of type X with keys of type Priority. This class is also its own Comparer.
static bool greater(const CONTENTPOINTER &x, const CONTENTPOINTER &y)
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)
Compare elements based on a single comparable attribute.
X item() const
Returns the data of the element.
static bool less(const Prioritized< X, Priority > &x, const Prioritized< X, Priority > &y)