OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLCellIterator.hpp
Go to the documentation of this file.
1/*
2 * OpenXLSX-NX - Modern High-Performance C++ Excel Library
3 *
4 * Original work Copyright (c) 2018-2025, Kenneth Troldal Balslev and OpenXLSX contributors
5 * Modified work Copyright (c) 2026, Curry Tang and OpenXLSX-NX contributors
6 *
7 * Distributed under the BSD 3-Clause License.
8 * See LICENSE.md in the project root or https://opensource.org/licenses/BSD-3-Clause
9 */
10
11#ifndef OPENXLSX_XLCELLITERATOR_HPP
12#define OPENXLSX_XLCELLITERATOR_HPP
13
14#ifdef _MSC_VER
15# pragma warning(push)
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
18#endif
19
20#include <algorithm>
21
22#include "OpenXLSX-Exports.hpp"
23#include "XLCell.hpp"
24#include "XLCellReference.hpp"
25#include "XLIterator.hpp"
26#include "XLXmlParser.hpp"
27
28namespace OpenXLSX
29{
34 XMLNode findRowNode(XMLNode sheetDataNode, uint32_t rowNumber);
35
40 XMLNode findCellNode(XMLNode rowNode, uint16_t columnNumber);
41
46 class OPENXLSX_EXPORT XLCellIterator
47 {
48 public:
49 using iterator_category = std::forward_iterator_tag;
51 using difference_type = int64_t;
52 using pointer = XLCell*;
53 using reference = XLCell&;
54
55 enum class CellStatus : uint8_t { NotLoaded = 0, NoSuchCell = 1, Loaded = 2 };
56
60 explicit XLCellIterator(const XLCellRange& cellRange, XLIteratorLocation loc, std::vector<XLStyleIndex> const* colStyles);
61
62 ~XLCellIterator() = default;
63 XLCellIterator(const XLCellIterator& other) = default;
64 XLCellIterator(XLCellIterator&& other) noexcept = default;
65 XLCellIterator& operator=(const XLCellIterator& other) = default;
66 XLCellIterator& operator=(XLCellIterator&& other) noexcept = default;
67
68 private:
69 static constexpr bool XLCreateIfMissing = true;
70 static constexpr bool XLDoNotCreateIfMissing = false;
71
76 void updateCurrentCell(bool createIfMissing) const;
77
78 public:
81
82 [[nodiscard]] reference operator*();
83 [[nodiscard]] pointer operator->();
84
85 [[nodiscard]] bool operator==(const XLCellIterator& rhs) const noexcept;
86 [[nodiscard]] bool operator!=(const XLCellIterator& rhs) const noexcept;
87
91 [[nodiscard]] bool cellExists() const;
92
96 [[nodiscard]] bool endReached() const noexcept { return m_endReached; }
97
101 [[nodiscard]] uint64_t distance(const XLCellIterator& last) const;
102
106 [[nodiscard]] std::string address() const;
107
108 private:
109 mutable XMLNode m_dataNode;
110 XLCellReference m_topLeft;
111 XLCellReference m_bottomRight;
112 XLSharedStringsRef m_sharedStrings;
113 bool m_endReached;
114 mutable XMLNode m_hintNode;
115 mutable uint32_t m_hintRow;
116 mutable XLCell m_currentCell;
117 mutable CellStatus m_currentCellStatus;
118 uint32_t m_currentRow;
119 uint16_t m_currentColumn;
120 std::vector<XLStyleIndex> const* m_colStyles;
121 };
122
123 inline std::ostream& operator<<(std::ostream& os, const XLCellIterator& it)
124 {
125 os << it.address();
126 return os;
127 }
128} // namespace OpenXLSX
129
130namespace std
131{
133 template<>
134 inline std::iterator_traits<XLCellIterator>::difference_type distance<XLCellIterator>(XLCellIterator first, XLCellIterator last)
135 { return static_cast<std::iterator_traits<XLCellIterator>::difference_type>(first.distance(last)); }
136} // namespace std
137
138#ifdef _MSC_VER
139# pragma warning(pop)
140#endif
141
142#endif // OPENXLSX_XLCELLITERATOR_HPP
A forward iterator for iterating over a range of cells.
Definition XLCellIterator.hpp:47
bool operator==(const XLCellIterator &rhs) const noexcept
Definition XLCellIterator.cpp:252
XLCellIterator & operator++()
Definition XLCellIterator.cpp:203
XLCell & reference
Definition XLCellIterator.hpp:53
uint64_t distance(const XLCellIterator &last) const
Definition XLCellIterator.cpp:284
XLCellIterator & operator=(XLCellIterator &&other) noexcept=default
bool endReached() const noexcept
Definition XLCellIterator.hpp:96
XLCell value_type
Definition XLCellIterator.hpp:50
std::forward_iterator_tag iterator_category
Definition XLCellIterator.hpp:49
XLCell * pointer
Definition XLCellIterator.hpp:52
XLCellIterator(const XLCellIterator &other)=default
CellStatus
Definition XLCellIterator.hpp:55
XLCellIterator(XLCellIterator &&other) noexcept=default
int64_t difference_type
Definition XLCellIterator.hpp:51
bool cellExists() const
Definition XLCellIterator.cpp:275
XLCellIterator & operator=(const XLCellIterator &other)=default
XLCellIterator(const XLCellRange &cellRange, XLIteratorLocation loc, std::vector< XLStyleIndex > const *colStyles)
Definition XLCellIterator.cpp:102
pointer operator->()
Definition XLCellIterator.cpp:243
std::string address() const
Definition XLCellIterator.cpp:301
reference operator*()
Definition XLCellIterator.cpp:234
bool operator!=(const XLCellIterator &rhs) const noexcept
Definition XLCellIterator.cpp:270
Represents a rectangular area of cells within a worksheet.
Definition XLCellRange.hpp:40
Definition XLCellReference.hpp:44
An implementation class encapsulating the properties and behaviours of a spreadsheet cell.
Definition XLCell.hpp:51
Definition IXLCellProvider.hpp:24
XMLNode findRowNode(XMLNode sheetDataNode, uint32_t rowNumber)
locate the XML row node within sheetDataNode for the row at rowNumber
Definition XLCellIterator.cpp:28
XLIteratorLocation
Definition XLIterator.hpp:17
XMLNode findCellNode(XMLNode rowNode, uint16_t columnNumber)
locate the XML cell node within rownode for the cell at columnNumber
Definition XLCellIterator.cpp:60
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:64
std::ostream & operator<<(std::ostream &os, const XLCell &c)
ostream output of XLCell content
Definition XLCell.hpp:329
std::reference_wrapper< const XLSharedStrings > XLSharedStringsRef
Definition XLSharedStrings.hpp:67
Definition XLCellIterator.hpp:131
std::iterator_traits< XLCellIterator >::difference_type distance< XLCellIterator >(XLCellIterator first, XLCellIterator last)
Definition XLCellIterator.hpp:134