michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: // vim:cindent:ts=8:et:sw=4: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* a set of ranges on a number-line */ michael@0: michael@0: #ifndef nsIntervalSet_h___ michael@0: #define nsIntervalSet_h___ michael@0: michael@0: #include "nsCoord.h" michael@0: michael@0: typedef void * michael@0: (* IntervalSetAlloc)(size_t aBytes, void *aClosure); michael@0: michael@0: typedef void michael@0: (* IntervalSetFree) (size_t aBytes, void *aPtr, void *aClosure); michael@0: michael@0: /* michael@0: * A list-based class (hopefully tree-based when I get around to it) michael@0: * for representing a set of ranges on a number-line. michael@0: */ michael@0: class nsIntervalSet { michael@0: michael@0: public: michael@0: michael@0: typedef nscoord coord_type; michael@0: michael@0: nsIntervalSet(IntervalSetAlloc aAlloc, IntervalSetFree aFree, michael@0: void* aAllocatorClosure); michael@0: ~nsIntervalSet(); michael@0: michael@0: /* michael@0: * Include the interval [aBegin, aEnd] in the set. michael@0: * michael@0: * Removal of intervals added is not supported because that would michael@0: * require keeping track of the individual intervals that were michael@0: * added (nsIntervalMap should do that). It would be simple to michael@0: * implement ExcludeInterval if anyone wants it, though. michael@0: */ michael@0: void IncludeInterval(coord_type aBegin, coord_type aEnd); michael@0: michael@0: /* michael@0: * Are _some_ points in [aBegin, aEnd] contained within the set michael@0: * of intervals? michael@0: */ michael@0: bool Intersects(coord_type aBegin, coord_type aEnd) const; michael@0: michael@0: /* michael@0: * Are _all_ points in [aBegin, aEnd] contained within the set michael@0: * of intervals? michael@0: */ michael@0: bool Contains(coord_type aBegin, coord_type aEnd) const; michael@0: michael@0: bool IsEmpty() const michael@0: { michael@0: return !mList; michael@0: } michael@0: michael@0: private: michael@0: michael@0: class Interval { michael@0: michael@0: public: michael@0: Interval(coord_type aBegin, coord_type aEnd) michael@0: : mBegin(aBegin), michael@0: mEnd(aEnd), michael@0: mPrev(nullptr), michael@0: mNext(nullptr) michael@0: { michael@0: } michael@0: michael@0: coord_type mBegin; michael@0: coord_type mEnd; michael@0: Interval *mPrev; michael@0: Interval *mNext; michael@0: }; michael@0: michael@0: void FreeInterval(Interval *aInterval); michael@0: michael@0: Interval *mList; michael@0: IntervalSetAlloc mAlloc; michael@0: IntervalSetFree mFree; michael@0: void *mAllocatorClosure; michael@0: michael@0: }; michael@0: michael@0: #endif // !defined(nsIntervalSet_h___)