range_set.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2016 The Chromium 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. // Defines a set of geometric ranges, and standard operations on it.
  5. #ifndef PDF_LOADER_RANGE_SET_H_
  6. #define PDF_LOADER_RANGE_SET_H_
  7. #include <ostream>
  8. #include <set>
  9. #include <string>
  10. #include "ui/gfx/range/range.h"
  11. namespace chrome_pdf {
  12. class RangeSet {
  13. public:
  14. RangeSet();
  15. explicit RangeSet(const gfx::Range& range);
  16. ~RangeSet();
  17. RangeSet(const RangeSet& range_set);
  18. RangeSet(RangeSet&& range_set);
  19. RangeSet& operator=(const RangeSet& other);
  20. bool operator==(const RangeSet& other) const;
  21. bool operator!=(const RangeSet& other) const;
  22. bool Contains(uint32_t point) const;
  23. bool Contains(const gfx::Range& range) const;
  24. bool Contains(const RangeSet& range_set) const;
  25. bool Intersects(const gfx::Range& range) const;
  26. bool Intersects(const RangeSet& range_set) const;
  27. void Union(const gfx::Range& range);
  28. void Union(const RangeSet& range_set);
  29. void Intersect(const gfx::Range& range);
  30. void Intersect(const RangeSet& range_set);
  31. void Subtract(const gfx::Range& range);
  32. void Subtract(const RangeSet& range_set);
  33. void Xor(const gfx::Range& range);
  34. void Xor(const RangeSet& range_set);
  35. bool IsEmpty() const;
  36. void Clear();
  37. gfx::Range First() const;
  38. gfx::Range Last() const;
  39. std::string ToString() const;
  40. struct range_compare {
  41. bool operator()(const gfx::Range& lval, const gfx::Range& rval) const {
  42. return lval.start() < rval.start();
  43. }
  44. };
  45. using RangesContainer = std::set<gfx::Range, range_compare>;
  46. const RangesContainer& ranges() const { return ranges_; }
  47. size_t Size() const { return ranges_.size(); }
  48. private:
  49. RangesContainer ranges_;
  50. };
  51. } // namespace chrome_pdf
  52. std::ostream& operator<<(std::ostream& os,
  53. const chrome_pdf::RangeSet& range_set);
  54. #endif // PDF_LOADER_RANGE_SET_H_