page_range.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2011 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. #ifndef PRINTING_PAGE_RANGE_H_
  5. #define PRINTING_PAGE_RANGE_H_
  6. #include <stdint.h>
  7. #include <limits>
  8. #include <vector>
  9. #include "base/component_export.h"
  10. namespace printing {
  11. struct PageRange;
  12. using PageRanges = std::vector<PageRange>;
  13. // Print range is inclusive. To select one page, set from == to.
  14. struct COMPONENT_EXPORT(PRINTING) PageRange {
  15. // Any value above maximum practical page count (enforced by PageNumber)
  16. // would work, but we chose something that works even where the page
  17. // numbers are 1-based (i.e. can be increased by one without overflow).
  18. static constexpr uint32_t kMaxPage = std::numeric_limits<uint32_t>::max() - 1;
  19. uint32_t from;
  20. uint32_t to;
  21. bool operator<(const PageRange& rhs) const {
  22. return from < rhs.from || (from == rhs.from && to < rhs.to);
  23. }
  24. bool operator==(const PageRange& rhs) const {
  25. return from == rhs.from && to == rhs.to;
  26. }
  27. // Ensures entries come in monotonically increasing order and do not
  28. // overlap.
  29. static void Normalize(PageRanges& ranges);
  30. };
  31. } // namespace printing
  32. #endif // PRINTING_PAGE_RANGE_H_