1/*
2 * Copyright 2013, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef RANGE_LIST_H
6#define RANGE_LIST_H
7
8
9#include <ObjectList.h>
10#include <SupportDefs.h>
11
12
13struct Range {
14	int32 lowerBound;
15	int32 upperBound;
16
17	Range()
18		:
19		lowerBound(-1),
20		upperBound(-1)
21	{
22	}
23
24	Range(int32 lowValue, int32 highValue)
25		:
26		lowerBound(lowValue),
27		upperBound(highValue)
28	{
29	}
30};
31
32
33class RangeList : private BObjectList<Range>
34{
35public:
36							RangeList();
37	virtual					~RangeList();
38
39
40			status_t		AddRange(int32 lowValue, int32 highValue);
41			status_t		AddRange(const Range& range);
42
43			void			RemoveRangeAt(int32 index);
44
45			int32			CountRanges() const;
46			const Range*	RangeAt(int32 index) const;
47
48			bool			Contains(int32 value) const;
49
50private:
51			void			_CollapseOverlappingRanges(int32 startIndex,
52								int32 highValue);
53};
54
55#endif // RANGE_LIST_H
56