blob: 528a41d6443876704f3af28b0507c2dc727d8ab7 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.commit09911bf2008-07-26 23:55:294
[email protected]8ff1d422009-07-07 21:31:395#ifndef PRINTING_PAGE_NUMBER_H_
6#define PRINTING_PAGE_NUMBER_H_
initial.commit09911bf2008-07-26 23:55:297
initial.commit09911bf2008-07-26 23:55:298#include <ostream>
initial.commit09911bf2008-07-26 23:55:299
[email protected]8ff1d422009-07-07 21:31:3910#include "printing/page_range.h"
initial.commit09911bf2008-07-26 23:55:2911
12namespace printing {
13
14class PrintSettings;
15
16// Represents a page series following the array of page ranges defined in a
17// PrintSettings.
18class 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.
65template<class E, class T>
[email protected]23afa0f2008-09-19 15:58:5566inline typename std::basic_ostream<E,T>& operator<<(
67 typename std::basic_ostream<E,T>& ss, const PageNumber& page) {
initial.commit09911bf2008-07-26 23:55:2968 return ss << page.ToInt();
69}
70
71} // namespace printing
72
[email protected]8ff1d422009-07-07 21:31:3973#endif // PRINTING_PAGE_NUMBER_H_