2020-07-27 08:18:54 +05:30
|
|
|
#ifndef BASE_DATA_RANGE_H
|
|
|
|
#define BASE_DATA_RANGE_H
|
2013-04-29 19:40:01 +05:30
|
|
|
|
|
|
|
#include <boost/optional.hpp>
|
2013-05-01 21:00:59 +05:30
|
|
|
#include <ostream>
|
2013-04-29 19:40:01 +05:30
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2013-05-08 21:08:04 +05:30
|
|
|
namespace base {
|
2013-04-29 19:40:01 +05:30
|
|
|
template <typename T>
|
2013-05-28 16:50:05 +05:30
|
|
|
class run {
|
2013-04-29 19:40:01 +05:30
|
|
|
public:
|
|
|
|
typedef boost::optional<T> maybe;
|
|
|
|
|
2013-05-28 17:29:17 +05:30
|
|
|
run() {
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit run(T const &b)
|
|
|
|
: begin_(b) {
|
|
|
|
}
|
|
|
|
|
|
|
|
run(T const &b, T const &e)
|
|
|
|
: begin_(b),
|
|
|
|
end_(e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit run(maybe begin, maybe end)
|
2013-04-29 19:40:01 +05:30
|
|
|
: begin_(begin),
|
|
|
|
end_(end) {
|
|
|
|
}
|
|
|
|
|
2013-05-28 16:50:05 +05:30
|
|
|
bool operator ==(run<T> const &r) const {
|
2013-04-29 20:42:34 +05:30
|
|
|
return (begin_ == r.begin_ && end_ == r.end_);
|
|
|
|
}
|
|
|
|
|
2013-05-17 15:44:12 +05:30
|
|
|
bool contains(T const &v) const {
|
|
|
|
if (begin_ && v < *begin_)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (end_ && v >= *end_)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-29 19:40:01 +05:30
|
|
|
maybe begin_;
|
|
|
|
maybe end_;
|
|
|
|
};
|
2013-05-01 21:00:59 +05:30
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::ostream &
|
2013-05-28 16:50:05 +05:30
|
|
|
operator <<(std::ostream &out, run<T> const &r) {
|
2013-05-01 21:00:59 +05:30
|
|
|
if (r.begin_)
|
|
|
|
out << "[" << *r.begin_;
|
|
|
|
else
|
|
|
|
out << "[-";
|
|
|
|
|
|
|
|
out << ", ";
|
|
|
|
|
|
|
|
if (r.end_)
|
|
|
|
out << *r.end_ << "]";
|
|
|
|
else
|
|
|
|
out << "-]";
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
2013-04-29 19:40:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|