src
range.h
Go to the documentation of this file.
1 #ifndef _RE2C_UTIL_RANGE_
2 #define _RE2C_UTIL_RANGE_
3 
4 #include "src/util/c99_stdint.h"
5 #include <assert.h>
6 #include <stddef.h> // NULL
7 
8 #include "src/test/range/test.h"
9 #include "src/util/forbid_copy.h"
10 #include "src/util/free_list.h"
11 
12 namespace re2c
13 {
14 
15 class Range
16 {
17 public:
19 
20 private:
21  Range * nx;
22  // [lb,ub)
23  uint32_t lb;
24  uint32_t ub;
25 
26 public:
27  static Range * sym (uint32_t c)
28  {
29  return new Range (NULL, c, c + 1);
30  }
31  static Range * ran (uint32_t l, uint32_t u)
32  {
33  return new Range (NULL, l, u);
34  }
35  ~Range ()
36  {
37  vFreeList.erase (this);
38  }
39  Range * next () const { return nx; }
40  uint32_t lower () const { return lb; }
41  uint32_t upper () const { return ub; }
42  static Range * add (const Range * r1, const Range * r2);
43  static Range * sub (const Range * r1, const Range * r2);
44 
45 private:
46  Range (Range * n, uint32_t l, uint32_t u)
47  : nx (n)
48  , lb (l)
49  , ub (u)
50  {
51  assert (lb < ub);
52  vFreeList.insert (this);
53  }
54  static void append_overlapping (Range * & head, Range * & tail, const Range * r);
55  static void append (Range ** & ptail, uint32_t l, uint32_t u);
56 
57  // test addition and subtraction
58  template <uint8_t> friend Range * re2c_test::range (uint32_t n);
59 
60  FORBID_COPY (Range);
61 };
62 
63 } // namespace re2c
64 
65 #endif // _RE2C_UTIL_RANGE_
static Range * sub(const Range *r1, const Range *r2)
Definition: range.cc:61
size_type erase(const key_type &key)
Definition: free_list.h:23
static Range * ran(uint32_t l, uint32_t u)
Definition: range.h:31
~Range()
Definition: range.h:35
uint32_t lower() const
Definition: range.h:40
static free_list< Range * > vFreeList
Definition: range.h:18
static Range * sym(uint32_t c)
Definition: range.h:27
re2c::Range * range(uint32_t n)
Definition: test-impl.h:16
uint32_t upper() const
Definition: range.h:41
Definition: bitmap.cc:10
Range * next() const
Definition: range.h:39
static Range * add(const Range *r1, const Range *r2)
Definition: range.cc:26