1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/nsIntervalSet.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +// vim:cindent:ts=8:et:sw=4: 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/* a set of ranges on a number-line */ 1.11 + 1.12 +#ifndef nsIntervalSet_h___ 1.13 +#define nsIntervalSet_h___ 1.14 + 1.15 +#include "nsCoord.h" 1.16 + 1.17 +typedef void * 1.18 +(* IntervalSetAlloc)(size_t aBytes, void *aClosure); 1.19 + 1.20 +typedef void 1.21 +(* IntervalSetFree) (size_t aBytes, void *aPtr, void *aClosure); 1.22 + 1.23 +/* 1.24 + * A list-based class (hopefully tree-based when I get around to it) 1.25 + * for representing a set of ranges on a number-line. 1.26 + */ 1.27 +class nsIntervalSet { 1.28 + 1.29 +public: 1.30 + 1.31 + typedef nscoord coord_type; 1.32 + 1.33 + nsIntervalSet(IntervalSetAlloc aAlloc, IntervalSetFree aFree, 1.34 + void* aAllocatorClosure); 1.35 + ~nsIntervalSet(); 1.36 + 1.37 + /* 1.38 + * Include the interval [aBegin, aEnd] in the set. 1.39 + * 1.40 + * Removal of intervals added is not supported because that would 1.41 + * require keeping track of the individual intervals that were 1.42 + * added (nsIntervalMap should do that). It would be simple to 1.43 + * implement ExcludeInterval if anyone wants it, though. 1.44 + */ 1.45 + void IncludeInterval(coord_type aBegin, coord_type aEnd); 1.46 + 1.47 + /* 1.48 + * Are _some_ points in [aBegin, aEnd] contained within the set 1.49 + * of intervals? 1.50 + */ 1.51 + bool Intersects(coord_type aBegin, coord_type aEnd) const; 1.52 + 1.53 + /* 1.54 + * Are _all_ points in [aBegin, aEnd] contained within the set 1.55 + * of intervals? 1.56 + */ 1.57 + bool Contains(coord_type aBegin, coord_type aEnd) const; 1.58 + 1.59 + bool IsEmpty() const 1.60 + { 1.61 + return !mList; 1.62 + } 1.63 + 1.64 +private: 1.65 + 1.66 + class Interval { 1.67 + 1.68 + public: 1.69 + Interval(coord_type aBegin, coord_type aEnd) 1.70 + : mBegin(aBegin), 1.71 + mEnd(aEnd), 1.72 + mPrev(nullptr), 1.73 + mNext(nullptr) 1.74 + { 1.75 + } 1.76 + 1.77 + coord_type mBegin; 1.78 + coord_type mEnd; 1.79 + Interval *mPrev; 1.80 + Interval *mNext; 1.81 + }; 1.82 + 1.83 + void FreeInterval(Interval *aInterval); 1.84 + 1.85 + Interval *mList; 1.86 + IntervalSetAlloc mAlloc; 1.87 + IntervalSetFree mFree; 1.88 + void *mAllocatorClosure; 1.89 + 1.90 +}; 1.91 + 1.92 +#endif // !defined(nsIntervalSet_h___)