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 class nsIPresShell;
15 
16 /*
17  * A list-based class (hopefully tree-based when I get around to it)
18  * for representing a set of ranges on a number-line.
19  */
20 class nsIntervalSet {
21  public:
22   typedef nscoord coord_type;
23 
24   explicit nsIntervalSet(nsIPresShell *aPresShell);
25   ~nsIntervalSet();
26 
27   /*
28    * Include the interval [aBegin, aEnd] in the set.
29    *
30    * Removal of intervals added is not supported because that would
31    * require keeping track of the individual intervals that were
32    * added (nsIntervalMap should do that).  It would be simple to
33    * implement ExcludeInterval if anyone wants it, though.
34    */
35   void IncludeInterval(coord_type aBegin, coord_type aEnd);
36 
37   /*
38    * Are _some_ points in [aBegin, aEnd] contained within the set
39    * of intervals?
40    */
41   bool Intersects(coord_type aBegin, coord_type aEnd) const;
42 
43   /*
44    * Are _all_ points in [aBegin, aEnd] contained within the set
45    * of intervals?
46    */
47   bool Contains(coord_type aBegin, coord_type aEnd) const;
48 
IsEmpty()49   bool IsEmpty() const { return !mList; }
50 
51  private:
52   class Interval {
53    public:
Interval(coord_type aBegin,coord_type aEnd)54     Interval(coord_type aBegin, coord_type aEnd)
55         : mBegin(aBegin), mEnd(aEnd), mPrev(nullptr), mNext(nullptr) {}
56 
57     coord_type mBegin;
58     coord_type mEnd;
59     Interval *mPrev;
60     Interval *mNext;
61   };
62 
63   void *AllocateInterval();
64   void FreeInterval(Interval *aInterval);
65 
66   Interval *mList;
67   nsIPresShell *mPresShell;
68 };
69 
70 #endif  // !defined(nsIntervalSet_h___)
71