blob: 87cbee910b324347d4eb7e84e017d0c45b744a25 [file] [log] [blame]
Artem Strygin0e60b9e2017-09-28 18:46:03 +03001// Copyright 2017 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef TESTING_RANGE_SET_H_
6#define TESTING_RANGE_SET_H_
7
8#include <set>
9#include <utility>
10
11class RangeSet {
12 public:
13 using Range = std::pair<size_t, size_t>;
14
15 RangeSet();
16 ~RangeSet();
17
18 bool Contains(const Range& range) const;
19
20 void Union(const Range& range);
21
22 void Union(const RangeSet& range_set);
23
24 bool IsEmpty() const { return ranges().empty(); }
25
26 void Clear() { ranges_.clear(); }
27
28 struct range_compare {
29 bool operator()(const Range& lval, const Range& rval) const {
30 return lval.first < rval.first;
31 }
32 };
33
34 using RangesContainer = std::set<Range, range_compare>;
35 const RangesContainer& ranges() const { return ranges_; }
36
37 private:
38 Range FixDirection(const Range& range) const;
39
40 bool IsEmptyRange(const Range& range) const;
41
42 RangesContainer ranges_;
43};
44
45#endif // TESTING_RANGE_SET_H_