43 #include "../Text/TextTools.h" 44 #include "../Clonable.h" 80 Range(
const T& a = 0,
const T& b = 0):
104 bool operator<(const Range<T>& r)
const {
237 virtual std::string
toString()
const = 0;
242 virtual bool isEmpty()
const = 0;
247 virtual size_t size()
const = 0;
257 virtual void clear() = 0;
266 return ((*a) < (*b));
288 for (
typename std::set<
Range<T>* >::iterator it =
set.
ranges_.begin(); it !=
set.ranges_.end(); ++it) {
296 for (
typename std::set<
Range<T>* >::iterator it =
set.
ranges_.begin(); it !=
set.ranges_.end(); ++it) {
313 typename std::set< Range<T>* >::iterator it =
ranges_.begin();
316 if ((**it).isEmpty()) {
317 typename std::set< Range<T>* >::iterator it2 = it;
328 typename std::set< Range<T>* >::iterator it =
ranges_.begin();
333 typename std::set< Range<T>* >::iterator it2 = it;
342 std::string s =
"{ ";
344 s += (**it).toString() +
" ";
355 typename std::set< Range<T>* >::const_iterator it =
ranges_.begin();
356 for (
size_t c = 0; c < i; ++c)
393 for (
size_t i = 0; i < mr.
ranges_.size(); ++i)
400 for (
size_t i = 0; i < mr.
ranges_.size(); ++i)
413 std::vector<size_t> overlappingPositions;
414 for (
size_t i = 0; i <
ranges_.size(); ++i) {
416 overlappingPositions.push_back(i);
419 if (overlappingPositions.size() == 0) {
424 ranges_[overlappingPositions[0]]->expandWith(r);
426 for (
size_t i = overlappingPositions.size() - 1; i > 0; --i) {
428 ranges_[overlappingPositions[0]]->expandWith(*
ranges_[overlappingPositions[i]]);
430 delete ranges_[overlappingPositions[i]];
431 ranges_.erase(
ranges_.begin() +
static_cast<ptrdiff_t
>(overlappingPositions[i]));
438 for (
size_t i = 0; i <
ranges_.size(); ++i)
444 typename std::vector< Range<T>* >::iterator it =
ranges_.begin();
459 std::string s =
"{ ";
460 for (
size_t i = 0; i <
ranges_.size(); ++i)
470 std::vector<T> bounds;
471 for (
size_t i = 0; i <
ranges_.size(); ++i) {
472 bounds.push_back(
ranges_[i]->begin());
473 bounds.push_back(
ranges_[i]->end());
497 typename std::vector< Range<T>* >::iterator it =
ranges_.begin();
499 if ((**it).isEmpty()) {
509 for (
size_t i = 0; i <
ranges_.size(); ++i) {
void expandWith(const Range &r)
Expand the current interval with the given one.
RangeSet & operator=(const RangeSet< T > &set)
virtual bool isEmpty() const =0
Interface discribing a collection of Range objects.
Range(const T &a=0, const T &b=0)
Creates a new interval.
MultiRange(const MultiRange< T > &mr)
std::vector< T > getBounds() const
virtual Range & operator-=(const T &val)
The Range class, defining an interval.
This class allows to perform a correspondence analysis.
virtual void restrictTo(const Range< T > &r)=0
Get the intersection with a given range.
virtual void addRange(const Range< T > &r)=0
Add a new range to the collection.
std::set< Range< T > *, rangeComp_< T > > ranges_
Range< T > * clone() const
Create a copy of this object and send a pointer to it.
const Range< T > & getRange(size_t i) const
This class implements a data structure describing a set of non-overlapping intervales.
void filterWithin(const Range< T > &r)
Only keep the ranges that fall within the given range.
virtual std::string toString() const =0
static std::string toString(T t)
General template method to convert to a string.
virtual void clear()=0
Clear the collection.
void clear()
Clear the collection.
MultiRange & operator=(const MultiRange< T > &mr)
void filterWithin(const Range< T > &r)
Only keep the ranges that fall within the given range.
std::set< Range< T > *, rangeComp_< T > > & getSet()
Range(const Range< T > &range)
virtual Range operator+(const T &val)
const std::set< Range< T > *, rangeComp_< T > > & getSet() const
void sliceWith(const Range &r)
Restrict the current interval to the intersection with the given one.
std::vector< Range< T > * > ranges_
std::string toString() const
A special class used inside RangeCollection.
std::string toString() const
std::string toString() const
Range< T > & operator=(const Range< T > &range)
void clear()
Clear the collection.
bool operator==(const Range< T > &r) const
bool isContiguous(const Range &r) const
bool contains(const Range &r) const
The Clonable interface (allow an object to be cloned).
virtual size_t size() const =0
virtual ~RangeCollection()
bool operator()(const Range< T > *a, const Range< T > *b) const
void addRange(const Range< T > &r)
Add a new range to the collection.
This class implements a data structure describing a set of intervales.
virtual Range operator-(const T &val)
void restrictTo(const Range< T > &r)
Get the intersection with a given range.
const Range< T > & getRange(size_t i) const
bool operator!=(const Range< T > &r) const
RangeSet(const RangeSet< T > &set)
void restrictTo(const Range< T > &r)
Get the intersection with a given range.
virtual const Range< T > & getRange(size_t i) const =0
virtual Range & operator+=(const T &val)
void addRange(const Range< T > &r)
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.
bool overlap(const Range &r) const