Lua: Fix type confusion between signed and unsigned
[lsnes.git] / include / library / range.hpp
blob4cb9ab0e1666fa5283c15f8d5b1f9724a91d53d2
1 #ifndef _library__range__hpp__included__
2 #define _library__range__hpp__included__
4 #include <cstdint>
6 /**
7 * A range.
9 * These ranges wrap around. All range can't be represented.
11 class range
13 public:
14 /**
15 * Make range [low, high)
17 static range make_b(uint32_t low, uint32_t high);
18 /**
19 * Make range [low, low + size)
21 static range make_s(uint32_t low, uint32_t size) { return make_b(low, low + size); }
22 /**
23 * Make range [0, size)
25 static range make_w(uint32_t size) { return make_b(0, size); }
26 /**
27 * Offset range.
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); }
35 /**
36 * Intersect range.
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();
44 /**
45 * Return lower limit of range
47 uint32_t low() const throw() { return _low; }
48 /**
49 * Return upper limit of range
51 uint32_t high() const throw() { return _high; }
52 /**
53 * Return size of range
55 uint32_t size() const throw() { return _high - _low; }
56 /**
57 * Number in range?
59 bool in(uint32_t x) const throw();
60 private:
61 range(uint32_t l, uint32_t h);
62 uint32_t _low; //Inclusive.
63 uint32_t _high; //Exclusive.
66 #endif