xlnt
worksheet_iterator.hpp
1 // Copyright (c) 2014-2022 Thomas Fussell
2 // Copyright (c) 2010-2015 openpyxl
3 // Copyright (c) 2024 xlnt-community
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE
22 //
23 // @license: http://www.opensource.org/licenses/mit-license.php
24 // @author: see AUTHORS file
25 #pragma once
26 
27 #include <cstddef>
28 #include <iterator>
29 
30 #include <xlnt/xlnt_config.hpp>
31 
32 namespace xlnt {
33 
34 class workbook;
35 class worksheet;
36 
37 // Note: There are const and non-const implementations of this iterator
38 // because one needs to point at a const workbook and the other needs
39 // to point at a non-const workbook stored as a member variable, respectively.
40 
44 class XLNT_API worksheet_iterator
45 {
46 public:
50  using iterator_category = std::bidirectional_iterator_tag;
51  using value_type = worksheet;
52  using difference_type = std::ptrdiff_t;
53  using pointer = worksheet *;
54  using reference = worksheet; // intentionally value
55 
59  worksheet_iterator() = default;
60 
64  worksheet_iterator(workbook &wb, std::size_t index);
65 
69  worksheet_iterator(const worksheet_iterator &) = default;
70 
74  worksheet_iterator &operator=(const worksheet_iterator &) = default;
75 
80 
84  worksheet_iterator &operator=(worksheet_iterator &&) = default;
85 
89  ~worksheet_iterator() = default;
90 
96  reference operator*();
97 
103  const reference operator*() const;
104 
108  bool operator==(const worksheet_iterator &comparand) const;
109 
113  bool operator!=(const worksheet_iterator &comparand) const;
114 
119  worksheet_iterator operator++(int);
120 
125  worksheet_iterator &operator++();
126 
131  worksheet_iterator operator--(int);
132 
137  worksheet_iterator &operator--();
138 
139 private:
143  workbook *wb_ = nullptr;
144 
148  std::size_t index_ = 0;
149 };
150 
155 {
156 public:
160  using iterator_category = std::bidirectional_iterator_tag;
161  using value_type = const worksheet;
162  using difference_type = std::ptrdiff_t;
163  using pointer = const worksheet *;
164  using reference = const worksheet; // intentionally value
165 
169  const_worksheet_iterator() = default;
170 
174  const_worksheet_iterator(const workbook &wb, std::size_t index);
175 
180 
184  const_worksheet_iterator &operator=(const const_worksheet_iterator &) = default;
185 
190 
194  const_worksheet_iterator &operator=(const_worksheet_iterator &&) = default;
195 
199  ~const_worksheet_iterator() = default;
200 
206  const reference operator*() const;
207 
211  bool operator==(const const_worksheet_iterator &comparand) const;
212 
216  bool operator!=(const const_worksheet_iterator &comparand) const;
217 
222  const_worksheet_iterator operator++(int);
223 
228  const_worksheet_iterator &operator++();
229 
234  const_worksheet_iterator operator--(int);
235 
240  const_worksheet_iterator &operator--();
241 
242 private:
246  const workbook *wb_ = nullptr;
247 
251  std::size_t index_ = 0;
252 };
253 
254 } // namespace xlnt
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:37
std::bidirectional_iterator_tag iterator_category
iterator tags required for use with standard algorithms and adapters
Definition: worksheet_iterator.hpp:160
A worksheet is a 2D array of cells starting with cell A1 in the top-left corner and extending indefin...
Definition: worksheet.hpp:77
bool operator==(std::nullptr_t, const cell &cell)
Returns true if this cell is uninitialized.
An iterator which is used to iterate over the worksheets in a workbook.
Definition: worksheet_iterator.hpp:44
An iterator which is used to iterate over the worksheets in a const workbook.
Definition: worksheet_iterator.hpp:154
std::bidirectional_iterator_tag iterator_category
iterator tags required for use with standard algorithms and adapters
Definition: worksheet_iterator.hpp:50
bool operator!=(const std::string &reference_string, const range_reference &ref)
Returns true if the string representation of the range is not equivalent to ref.
workbook is the container for all other parts of the document.
Definition: workbook.hpp:92