layout/generic/nsIntervalSet.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial