41 #ifndef BPP_NUMERIC_RANGE_H
42 #define BPP_NUMERIC_RANGE_H
45 #include "../Clonable.h"
46 #include "../Text/TextTools.h"
82 Range(
const T& a = 0,
const T& b = 0) :
261 virtual size_t size()
const = 0;
309 for (
const auto& it : set.
ranges_)
311 ranges_.push_back(it->clone());
318 for (
const auto& it : set.
ranges_)
320 ranges_.push_back(it->clone());
343 if ((**it).isEmpty())
374 std::string s =
"{ ";
377 s += it->toString() +
" ";
439 for (
size_t i = 0; i < mr.
ranges_.size(); ++i)
448 for (
size_t i = 0; i < mr.
ranges_.size(); ++i)
464 std::vector<size_t> overlappingPositions;
465 for (
size_t i = 0; i <
ranges_.size(); ++i)
468 overlappingPositions.push_back(i);
471 if (overlappingPositions.size() == 0)
479 ranges_[overlappingPositions[0]]->expandWith(r);
481 for (
size_t i = overlappingPositions.size() - 1; i > 0; --i)
484 ranges_[overlappingPositions[0]]->expandWith(*
ranges_[overlappingPositions[i]]);
486 delete ranges_[overlappingPositions[i]];
487 ranges_.erase(
ranges_.begin() +
static_cast<ptrdiff_t
>(overlappingPositions[i]));
524 std::string s =
"{ ";
527 s += it->toString() +
" ";
538 std::vector<T> bounds;
541 bounds.push_back(it->begin());
542 bounds.push_back(it->end());
581 if ((**it).isEmpty())
596 for (
size_t i = 0; i <
ranges_.size(); ++i)
The Clonable interface (allow an object to be cloned).
This class implements a data structure describing a set of non-overlapping intervals.
void restrictTo(const Range< T > &r)
Get the intersection with a given range.
MultiRange(const MultiRange< T > &mr)
MultiRange & operator=(const MultiRange< T > &mr)
void addRange(const Range< T > &r)
Add a new range to the collection.
void clear()
Clear the collection.
void filterWithin(const Range< T > &r)
Only keep the ranges that fall within the given range.
std::string toString() const
size_t totalLength() const
const Range< T > & getRange(size_t i) const
std::vector< Range< T > * > ranges_
std::vector< T > getBounds() const
Interface discribing a collection of Range objects.
virtual const Range< T > & getRange(size_t i) const =0
virtual ~RangeCollection()
virtual bool isEmpty() const =0
virtual void addRange(const Range< T > &r)=0
Add a new range to the collection.
virtual void filterWithin(const Range< T > &r)=0
Only keep the ranges that fall within the given range.
virtual std::string toString() const =0
virtual size_t size() const =0
virtual size_t totalLength() const =0
virtual void clear()=0
Clear the collection.
virtual void restrictTo(const Range< T > &r)=0
Get the intersection with a given range.
This class implements a data structure describing a set of intervals.
std::vector< Range< T > * > ranges_
const Range< T > & getRange(size_t i) const
void addRange(const Range< T > &r)
Add a new range to the collection.
RangeSet & operator=(const RangeSet< T > &set)
void filterWithin(const Range< T > &r)
Only keep the ranges that fall within the given range.
std::vector< Range< T > * > & getSet()
const std::vector< Range< T > * > & getSet() const
void clear()
Clear the collection.
size_t totalLength() const
RangeSet(const RangeSet< T > &set)
void restrictTo(const Range< T > &r)
Get the intersection with a given range.
std::string toString() const
The Range class, defining an interval.
virtual Range operator+(const T &val)
Range< T > * clone() const
Create a copy of this object and send a pointer to it.
bool isContiguous(const Range &r) const
virtual Range & operator-=(const T &val)
bool contains(const Range &r) const
void sliceWith(const Range &r)
Restrict the current interval to the intersection with the given one.
bool operator==(const Range< T > &r) const
virtual Range & operator+=(const T &val)
Range(const Range< T > &range)
bool operator!=(const Range< T > &r) const
Range< T > & operator=(const Range< T > &range)
Range(const T &a=0, const T &b=0)
Creates a new interval.
virtual Range operator-(const T &val)
bool overlap(const Range &r) const
std::string toString() const
bool operator<(const Range< T > &r) const
void expandWith(const Range &r)
Expand the current interval with the given one.
A special class used inside RangeCollection.
bool operator()(const Range< T > *a, const Range< T > *b) const
std::string toString(T t)
General template method to convert to a string.