72 lines
1.1 KiB
C
Raw Normal View History

2013-05-08 16:38:04 +01:00
#ifndef PERSISTENT_DATA_RANGE_H
#define PERSISTENT_DATA_RANGE_H
2013-04-29 15:10:01 +01:00
#include <boost/optional.hpp>
#include <ostream>
2013-04-29 15:10:01 +01:00
//----------------------------------------------------------------
2013-05-08 16:38:04 +01:00
namespace base {
2013-04-29 15:10:01 +01:00
template <typename T>
2013-05-28 12:20:05 +01:00
class run {
2013-04-29 15:10:01 +01:00
public:
typedef boost::optional<T> maybe;
2013-05-28 12:59:17 +01:00
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 15:10:01 +01:00
: begin_(begin),
end_(end) {
}
2013-05-28 12:20:05 +01:00
bool operator ==(run<T> const &r) const {
2013-04-29 16:12:34 +01:00
return (begin_ == r.begin_ && end_ == r.end_);
}
2013-05-17 11:14:12 +01:00
bool contains(T const &v) const {
if (begin_ && v < *begin_)
return false;
if (end_ && v >= *end_)
return false;
return true;
}
2013-04-29 15:10:01 +01:00
maybe begin_;
maybe end_;
};
template <typename T>
std::ostream &
2013-05-28 12:20:05 +01:00
operator <<(std::ostream &out, run<T> const &r) {
if (r.begin_)
out << "[" << *r.begin_;
else
out << "[-";
out << ", ";
if (r.end_)
out << *r.end_ << "]";
else
out << "-]";
return out;
}
2013-04-29 15:10:01 +01:00
}
//----------------------------------------------------------------
#endif