|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 // vim:cindent:ts=8:et:sw=4: |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 /* a set of ranges on a number-line */ |
|
8 |
|
9 #ifndef nsIntervalSet_h___ |
|
10 #define nsIntervalSet_h___ |
|
11 |
|
12 #include "nsCoord.h" |
|
13 |
|
14 typedef void * |
|
15 (* IntervalSetAlloc)(size_t aBytes, void *aClosure); |
|
16 |
|
17 typedef void |
|
18 (* IntervalSetFree) (size_t aBytes, void *aPtr, void *aClosure); |
|
19 |
|
20 /* |
|
21 * A list-based class (hopefully tree-based when I get around to it) |
|
22 * for representing a set of ranges on a number-line. |
|
23 */ |
|
24 class nsIntervalSet { |
|
25 |
|
26 public: |
|
27 |
|
28 typedef nscoord coord_type; |
|
29 |
|
30 nsIntervalSet(IntervalSetAlloc aAlloc, IntervalSetFree aFree, |
|
31 void* aAllocatorClosure); |
|
32 ~nsIntervalSet(); |
|
33 |
|
34 /* |
|
35 * Include the interval [aBegin, aEnd] in the set. |
|
36 * |
|
37 * Removal of intervals added is not supported because that would |
|
38 * require keeping track of the individual intervals that were |
|
39 * added (nsIntervalMap should do that). It would be simple to |
|
40 * implement ExcludeInterval if anyone wants it, though. |
|
41 */ |
|
42 void IncludeInterval(coord_type aBegin, coord_type aEnd); |
|
43 |
|
44 /* |
|
45 * Are _some_ points in [aBegin, aEnd] contained within the set |
|
46 * of intervals? |
|
47 */ |
|
48 bool Intersects(coord_type aBegin, coord_type aEnd) const; |
|
49 |
|
50 /* |
|
51 * Are _all_ points in [aBegin, aEnd] contained within the set |
|
52 * of intervals? |
|
53 */ |
|
54 bool Contains(coord_type aBegin, coord_type aEnd) const; |
|
55 |
|
56 bool IsEmpty() const |
|
57 { |
|
58 return !mList; |
|
59 } |
|
60 |
|
61 private: |
|
62 |
|
63 class Interval { |
|
64 |
|
65 public: |
|
66 Interval(coord_type aBegin, coord_type aEnd) |
|
67 : mBegin(aBegin), |
|
68 mEnd(aEnd), |
|
69 mPrev(nullptr), |
|
70 mNext(nullptr) |
|
71 { |
|
72 } |
|
73 |
|
74 coord_type mBegin; |
|
75 coord_type mEnd; |
|
76 Interval *mPrev; |
|
77 Interval *mNext; |
|
78 }; |
|
79 |
|
80 void FreeInterval(Interval *aInterval); |
|
81 |
|
82 Interval *mList; |
|
83 IntervalSetAlloc mAlloc; |
|
84 IntervalSetFree mFree; |
|
85 void *mAllocatorClosure; |
|
86 |
|
87 }; |
|
88 |
|
89 #endif // !defined(nsIntervalSet_h___) |