From a8af099733b573d69436add61ba633cded420c00 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Sat, 24 Jan 2015 14:39:52 +0100 Subject: added some functions on the state of a Range (isPrimitive, isCOmpact, isOpenLow, isOpenHigh) --- src/core/RangeSet.hpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/RangeSet.hpp b/src/core/RangeSet.hpp index b196dec..fc0070f 100644 --- a/src/core/RangeSet.hpp +++ b/src/core/RangeSet.hpp @@ -128,7 +128,7 @@ struct Range { /** * Calculates the union of the two ranges -- note that this operation is - * only valid if the ranges overlapp. Use the RangeSet class if you cannot + * only valid if the ranges overlap. Use the RangeSet class if you cannot * guarantee that. */ Range merge(const Range &r) const @@ -136,6 +136,44 @@ struct Range { return Range(std::min(start, r.start), std::max(end, r.end)); } + /** + * Returns true if and only if this Range only accepts a single element. + * + * @return true if and only if this Range only accepts a single element. + */ + bool isPrimitive() const { return start == end; } + /** + * Returns true if and only if this Range [a,b] meets the criteria: + * * a > lower limit of the type range (a > negative infinity) + * * a < b + * * b < upper limit of the type range (b < infinity) + * + * @return true if and only if this Range is compact as defined above. + */ + bool isCompact() const + { + return start > std::numeric_limits::min() && start < end && + end < std::numeric_limits::max(); + } + + /** + * Returns true if and only if the lower limit of this Range is equal to the + * type minimum (negative infinity). + * + * @return true if and only if this Range is open at the lower end in the + * sense defined above. + */ + bool isOpenLow() const { return start == std::numeric_limits::min(); } + + /** + * Returns true if and only if the upper limit of this Range is equal to the + * type maximum (positive infinity). + * + * @return true if and only if this Range is open at the upper end in the + * sense defined above. + */ + bool isOpenHigh() const { return end == std::numeric_limits::max(); } + /** * Returns a range that represents the spans the complete set defined by the * given type T. -- cgit v1.2.3