OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLStreamReader.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLSTREAMREADER_HPP
2#define OPENXLSX_XLSTREAMREADER_HPP
3
4#include "OpenXLSX-Exports.hpp"
5#include "XLCellValue.hpp"
6#include <cstdint>
7#include <string>
8#include <vector>
9
10namespace OpenXLSX
11{
12
13 class XLWorksheet;
14
15 class OPENXLSX_EXPORT XLStreamReader
16 {
17 public:
18 XLStreamReader() = default;
21
22 XLStreamReader(XLStreamReader&& other) noexcept;
23 XLStreamReader& operator=(XLStreamReader&& other) noexcept;
24
26
31 bool hasNext();
32
39 std::vector<XLCellValue> nextRow();
40
45 uint32_t currentRow() const;
46
50 void close();
51
52 private:
53 friend class XLWorksheet;
54
55 explicit XLStreamReader(const XLWorksheet* worksheet);
56
57 void fetchMoreData();
58
62 enum class SaxState : uint8_t {
63 Scanning, // Scanning for an opening '<'
64 InTagName, // Reading the tag name
65 InAttrName, // Reading an attribute name
66 AfterAttrName, // After attr name, waiting for '='
67 InAttrValue, // Reading an attribute value (inside quotes)
68 InTextContent, // Inside a tag's text content (e.g., <v>42</v>)
69 InClosingTag, // Reading a closing tag (after '</')
70 };
71
72 void cleanup();
73
74 const XLWorksheet* m_worksheet{nullptr};
75 void* m_zipStream{nullptr};
76
77 std::string m_buffer;
78 bool m_eof{false};
79 uint32_t m_currentRow{0};
80
81 // Reusable scratch buffers to avoid per-row heap allocation
82 std::string m_tagNameBuf;
83 std::string m_attrNameBuf;
84 std::string m_attrValueBuf;
85 std::string m_textContentBuf;
86 };
87
88} // namespace OpenXLSX
89#endif // OPENXLSX_XLSTREAMREADER_HPP
Definition XLStreamReader.hpp:16
XLStreamReader(const XLStreamReader &)=delete
XLStreamReader & operator=(const XLStreamReader &)=delete
A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook ob...
Definition XLWorksheet.hpp:118
Definition IZipArchive.hpp:18