OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLCellIterator.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLCELLITERATOR_HPP
2#define OPENXLSX_XLCELLITERATOR_HPP
3
4#ifdef _MSC_VER
5# pragma warning(push)
6# pragma warning(disable : 4251)
7# pragma warning(disable : 4275)
8#endif
9
10#include <algorithm>
11
12#include "OpenXLSX-Exports.hpp"
13#include "XLCell.hpp"
14#include "XLCellReference.hpp"
15#include "XLIterator.hpp"
16#include "XLXmlParser.hpp"
17
18namespace OpenXLSX
19{
24 XMLNode findRowNode(XMLNode sheetDataNode, uint32_t rowNumber);
25
30 XMLNode findCellNode(XMLNode rowNode, uint16_t columnNumber);
31
36 class OPENXLSX_EXPORT XLCellIterator
37 {
38 public:
39 using iterator_category = std::forward_iterator_tag;
41 using difference_type = int64_t;
42 using pointer = XLCell*;
43 using reference = XLCell&;
44
45 enum class CellStatus : uint8_t { NotLoaded = 0, NoSuchCell = 1, Loaded = 2 };
46
50 explicit XLCellIterator(const XLCellRange& cellRange, XLIteratorLocation loc, std::vector<XLStyleIndex> const* colStyles);
51
52 ~XLCellIterator() = default;
53 XLCellIterator(const XLCellIterator& other) = default;
54 XLCellIterator(XLCellIterator&& other) noexcept = default;
55 XLCellIterator& operator=(const XLCellIterator& other) = default;
56 XLCellIterator& operator=(XLCellIterator&& other) noexcept = default;
57
58 private:
59 static constexpr bool XLCreateIfMissing = true;
60 static constexpr bool XLDoNotCreateIfMissing = false;
61
66 void updateCurrentCell(bool createIfMissing) const;
67
68 public:
69 XLCellIterator& operator++();
70 XLCellIterator operator++(int);
71
72 [[nodiscard]] reference operator*();
73 [[nodiscard]] pointer operator->();
74
75 [[nodiscard]] bool operator==(const XLCellIterator& rhs) const noexcept;
76 [[nodiscard]] bool operator!=(const XLCellIterator& rhs) const noexcept;
77
81 [[nodiscard]] bool cellExists() const;
82
86 [[nodiscard]] bool endReached() const noexcept { return m_endReached; }
87
91 [[nodiscard]] uint64_t distance(const XLCellIterator& last) const;
92
96 [[nodiscard]] std::string address() const;
97
98 private:
99 mutable XMLNode m_dataNode;
100 XLCellReference m_topLeft;
101 XLCellReference m_bottomRight;
102 XLSharedStringsRef m_sharedStrings;
103 bool m_endReached;
104 mutable XMLNode m_hintNode;
105 mutable uint32_t m_hintRow;
106 mutable XLCell m_currentCell;
107 mutable CellStatus m_currentCellStatus;
108 uint32_t m_currentRow;
109 uint16_t m_currentColumn;
110 std::vector<XLStyleIndex> const* m_colStyles;
111 };
112
113 inline std::ostream& operator<<(std::ostream& os, const XLCellIterator& it)
114 {
115 os << it.address();
116 return os;
117 }
118} // namespace OpenXLSX
119
120namespace std
121{
123 template<>
124 inline std::iterator_traits<XLCellIterator>::difference_type distance<XLCellIterator>(XLCellIterator first, XLCellIterator last)
125 { return static_cast<std::iterator_traits<XLCellIterator>::difference_type>(first.distance(last)); }
126} // namespace std
127
128#ifdef _MSC_VER
129# pragma warning(pop)
130#endif
131
132#endif // OPENXLSX_XLCELLITERATOR_HPP
Definition XLXmlParser.hpp:84
A forward iterator for iterating over a range of cells.
Definition XLCellIterator.hpp:37
uint64_t distance(const XLCellIterator &last) const
Definition XLCellIterator.cpp:274
XLCellIterator & operator=(XLCellIterator &&other) noexcept=default
bool endReached() const noexcept
Definition XLCellIterator.hpp:86
std::forward_iterator_tag iterator_category
Definition XLCellIterator.hpp:39
XLCellIterator(const XLCellIterator &other)=default
CellStatus
Definition XLCellIterator.hpp:45
XLCellIterator(XLCellIterator &&other) noexcept=default
int64_t difference_type
Definition XLCellIterator.hpp:41
XLCellIterator & operator=(const XLCellIterator &other)=default
std::string address() const
Definition XLCellIterator.cpp:291
Represents a rectangular area of cells within a worksheet.
Definition XLCellRange.hpp:30
Definition XLCellReference.hpp:34
An implementation class encapsulating the properties and behaviours of a spreadsheet cell.
Definition XLCell.hpp:41
Definition IZipArchive.hpp:18
XMLNode findRowNode(XMLNode sheetDataNode, uint32_t rowNumber)
locate the XML row node within sheetDataNode for the row at rowNumber
Definition XLCellIterator.cpp:18
XLIteratorLocation
Definition XLIterator.hpp:7
bool operator==(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:304
bool operator!=(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:311
XMLNode findCellNode(XMLNode rowNode, uint16_t columnNumber)
locate the XML cell node within rownode for the cell at columnNumber
Definition XLCellIterator.cpp:50
constexpr const bool XLCreateIfMissing
Definition XLStyles.hpp:41
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:63
std::ostream & operator<<(std::ostream &os, const XLCell &c)
ostream output of XLCell content
Definition XLCell.hpp:319
std::reference_wrapper< const XLSharedStrings > XLSharedStringsRef
Definition XLSharedStrings.hpp:56
Definition XLCellIterator.hpp:121
std::iterator_traits< XLCellIterator >::difference_type distance< XLCellIterator >(XLCellIterator first, XLCellIterator last)
Definition XLCellIterator.hpp:124