Index: pdf/range_set.h |
diff --git a/pdf/range_set.h b/pdf/range_set.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..06a2577499689e7d3fd8ecbad0963d81032197df |
--- /dev/null |
+++ b/pdf/range_set.h |
@@ -0,0 +1,73 @@ |
+// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef PDF_RANGE_SET_H_ |
+#define PDF_RANGE_SET_H_ |
+ |
+#include <set> |
+#include <string> |
+ |
+#include "ui/gfx/range/range.h" |
+ |
+namespace chrome_pdf { |
+ |
+class RangeSet { |
Lei Zhang
2016/10/05 07:18:08
In general, it would be nice to have a description
snake
2016/10/05 14:14:10
Done.
|
+ public: |
+ RangeSet(); |
+ explicit RangeSet(const gfx::Range& range); |
+ ~RangeSet(); |
+ |
+ void Union(const gfx::Range& range); |
+ void Union(const RangeSet& range_set); |
+ |
+ bool Contains(uint32_t point) const; |
+ bool Contains(const gfx::Range& range) const; |
+ bool Contains(const RangeSet& range_set) const; |
+ |
+ bool Intersects(const gfx::Range& range) const; |
+ bool Intersects(const RangeSet& range_set) const; |
+ |
+ void Intersect(const gfx::Range& range); |
+ void Intersect(const RangeSet& range_set); |
+ |
+ void Subtract(const gfx::Range& range); |
+ void Subtract(const RangeSet& range_set); |
+ |
+ void Diff(const gfx::Range& range); |
+ void Diff(const RangeSet& range_set); |
+ |
+ bool IsEmpty() const; |
+ void Clear(); |
+ |
+ gfx::Range First() const; |
+ gfx::Range Last() const; |
+ std::string ToString() const; |
+ |
+ struct range_compare { |
+ bool operator()(const gfx::Range& lval, const gfx::Range& rval) const { |
+ return lval.start() < rval.start(); |
+ } |
+ }; |
+ |
+ typedef std::set<gfx::Range, range_compare> RangesContainer; |
+ |
+ const RangesContainer& ranges() const { return ranges_; } |
+ int Size() const { return static_cast<int>(ranges_.size()); } |
Lei Zhang
2016/10/05 07:18:08
Can this just return size_t and not cast?
snake
2016/10/05 14:14:10
Done.
|
+ |
+ private: |
+ RangesContainer ranges_; |
+}; |
+ |
+} // namespace chrome_pdf |
+ |
+inline bool operator==(const chrome_pdf::RangeSet& lhs, |
+ const chrome_pdf::RangeSet& rhs) { |
+ return lhs.ranges() == rhs.ranges(); |
+} |
+ |
+inline bool operator!=(const chrome_pdf::RangeSet& lhs, |
+ const chrome_pdf::RangeSet& rhs) { |
+ return !(lhs == rhs); |
+} |
+#endif // PDF_RANGE_SET_H_ |