File: Range.cpp

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (64 lines) | stat: -rw-r--r-- 1,269 bytes parent folder | download | duplicates (3)
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);
		}

	}
}