1 #ifndef _library__range__hpp__included__
2 #define _library__range__hpp__included__
9 * These ranges wrap around. All range can't be represented.
15 * Make range [low, high)
17 static range
make_b(uint32_t low
, uint32_t high
);
19 * Make range [low, low + size)
21 static range
make_s(uint32_t low
, uint32_t size
) { return make_b(low
, low
+ size
); }
23 * Make range [0, size)
25 static range
make_w(uint32_t size
) { return make_b(0, size
); }
29 * Parameter o: Offset to add to both ends of range.
31 range
operator+(uint32_t o
) const throw() { range x
= *this; x
+= o
; return x
; }
32 range
& operator+=(uint32_t o
) throw();
33 range
operator-(uint32_t o
) const throw() { return *this + (-o
); }
34 range
& operator-=(uint32_t o
) throw() { return *this += (-o
); }
38 * If there are multiple overlaps, the one starting nearer to start of first operand is chose.
40 * Parameter b: Another range to intersect.
42 range
operator&(const range
& b
) const throw() { range x
= *this; x
&= b
; return x
; }
43 range
& operator&=(const range
& b
) throw();
45 * Return lower limit of range
47 uint32_t low() const throw() { return _low
; }
49 * Return upper limit of range
51 uint32_t high() const throw() { return _high
; }
53 * Return size of range
55 uint32_t size() const throw() { return _high
- _low
; }
59 bool in(uint32_t x
) const throw();
61 range(uint32_t l
, uint32_t h
);
62 uint32_t _low
; //Inclusive.
63 uint32_t _high
; //Exclusive.