1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include "stdafx.h"
#include "Range.h"
namespace storm {
namespace server {
using namespace storm::syntax;
Range::Range() : from(0), to(0) {}
Range::Range(Nat from, Nat to) {
this->from = min(from, to);
this->to = max(from, to);
}
Bool Range::intersects(Range other) const {
return to > other.from
&& from < other.to;
}
Bool Range::contains(Nat pt) const {
return from <= pt && to > pt;
}
static Nat delta(Nat a, Nat b) {
if (a > b)
return a - b;
else
return b - a;
}
Nat Range::distance(Nat pt) const {
if (contains(pt))
return 0;
return min(delta(from, pt), delta(to, pt));
}
void Range::deepCopy(CloneEnv *env) {}
void Range::toS(StrBuf *to) const {
*to << S("(") << this->from << S(" - ") << this->to << S(")");
}
wostream &operator <<(wostream &to, Range r) {
return to << L"(" << r.from << L" - " << r.to << L")";
}
Range merge(Range a, Range b) {
if (a.empty())
return b;
if (b.empty())
return a;
return Range(min(a.from, b.from),
max(a.to, b.to));
}
ColoredRange::ColoredRange(Range r, TokenColor c)
: range(r), color(c) {}
void ColoredRange::toS(StrBuf *to) const {
*to << range << S("#") << name(to->engine(), color);
}
}
}
|