license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 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. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 5 | #ifndef PRINTING_PAGE_NUMBER_H_ |
| 6 | #define PRINTING_PAGE_NUMBER_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | #include <ostream> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 10 | #include "printing/page_range.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | |
| 12 | namespace printing { |
| 13 | |
| 14 | class PrintSettings; |
| 15 | |
| 16 | // Represents a page series following the array of page ranges defined in a |
| 17 | // PrintSettings. |
| 18 | class PageNumber { |
| 19 | public: |
| 20 | // Initializes the page to the first page in the settings's range or 0. |
| 21 | PageNumber(const PrintSettings& settings, int document_page_count); |
| 22 | |
| 23 | PageNumber(); |
| 24 | |
| 25 | void operator=(const PageNumber& other); |
| 26 | |
| 27 | // Initializes the page to the first page in the setting's range or 0. It |
| 28 | // initialize to npos if the range is empty and document_page_count is 0. |
| 29 | void Init(const PrintSettings& settings, int document_page_count); |
| 30 | |
| 31 | // Converts to a page numbers. |
| 32 | int ToInt() const { |
| 33 | return page_number_; |
| 34 | } |
| 35 | |
| 36 | // Calculates the next page in the serie. |
| 37 | int operator++(); |
| 38 | |
| 39 | // Returns an instance that represents the end of a serie. |
| 40 | static const PageNumber npos() { |
| 41 | return PageNumber(); |
| 42 | } |
| 43 | |
| 44 | // Equality operator. Only the current page number is verified so that |
| 45 | // "page != PageNumber::npos()" works. |
| 46 | bool operator==(const PageNumber& other) const; |
| 47 | bool operator!=(const PageNumber& other) const; |
| 48 | |
| 49 | private: |
| 50 | // The page range to follow. |
| 51 | const PageRanges* ranges_; |
| 52 | |
| 53 | // The next page to be printed. -1 when not printing. |
| 54 | int page_number_; |
| 55 | |
| 56 | // The next page to be printed. -1 when not used. Valid only if |
| 57 | // document()->settings().range.empty() is false. |
| 58 | int page_range_index_; |
| 59 | |
| 60 | // Number of expected pages in the document. Used when ranges_ is NULL. |
| 61 | int document_page_count_; |
| 62 | }; |
| 63 | |
| 64 | // Debug output support. |
| 65 | template<class E, class T> |
[email protected] | 23afa0f | 2008-09-19 15:58:55 | [diff] [blame] | 66 | inline typename std::basic_ostream<E,T>& operator<<( |
| 67 | typename std::basic_ostream<E,T>& ss, const PageNumber& page) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 68 | return ss << page.ToInt(); |
| 69 | } |
| 70 | |
| 71 | } // namespace printing |
| 72 | |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 73 | #endif // PRINTING_PAGE_NUMBER_H_ |