page_number.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_NUMBER_H_
  5. #define PRINTING_PAGE_NUMBER_H_
  6. #include <ostream>
  7. #include <vector>
  8. #include "base/memory/raw_ptr.h"
  9. #include "printing/page_range.h"
  10. namespace printing {
  11. // Represents a page series using the array of page ranges.
  12. class COMPONENT_EXPORT(PRINTING) PageNumber {
  13. public:
  14. // Initializes the page to the first page in the ranges or 0.
  15. PageNumber(const PageRanges& ranges, uint32_t document_page_count);
  16. PageNumber();
  17. PageNumber(const PageNumber& other);
  18. PageNumber& operator=(const PageNumber& other);
  19. // Initializes the page to the first page in the ranges or 0.
  20. // Initializes to npos if the ranges is empty and document_page_count is 0.
  21. void Init(const PageRanges& ranges, uint32_t document_page_count);
  22. // Converts to a page numbers.
  23. uint32_t ToUint() const { return page_number_; }
  24. // Calculates the next page in the series.
  25. uint32_t operator++();
  26. // Returns an instance that represents the end of a series.
  27. static const PageNumber npos() { return PageNumber(); }
  28. // Equality operator. Only the current page number is verified so that
  29. // "page != PageNumber::npos()" works.
  30. bool operator==(const PageNumber& other) const;
  31. bool operator!=(const PageNumber& other) const;
  32. static std::vector<uint32_t> GetPages(PageRanges ranges,
  33. uint32_t document_page_count);
  34. private:
  35. // The page range to follow.
  36. raw_ptr<const PageRanges> ranges_;
  37. // The next page to be printed. `kInvalidPageIndex` when not printing.
  38. uint32_t page_number_;
  39. // The next page to be printed. `kInvalidPageIndex` when not used. Valid only
  40. // if document()->settings().range.empty() is false.
  41. uint32_t page_range_index_;
  42. // Number of expected pages in the document. Used when ranges_ is NULL.
  43. uint32_t document_page_count_;
  44. };
  45. // Debug output support.
  46. template <class E, class T>
  47. inline typename std::basic_ostream<E, T>& operator<<(
  48. typename std::basic_ostream<E, T>& ss,
  49. const PageNumber& page) {
  50. return ss << page.ToUint();
  51. }
  52. } // namespace printing
  53. #endif // PRINTING_PAGE_NUMBER_H_