OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLRow.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLROW_HPP
2#define OPENXLSX_XLROW_HPP
3
4#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
5# pragma warning(push)
6# pragma warning(disable : 4251)
7# pragma warning(disable : 4275)
8#endif // _MSC_VER
9
10// ===== OpenXLSX Includes ===== //
11#include "OpenXLSX-Exports.hpp"
12#include "XLRowData.hpp"
13
14namespace OpenXLSX
15{
16 class XLRowRange;
17
22 class OPENXLSX_EXPORT XLRow
23 {
24 friend class XLRowIterator;
25 friend class XLRowDataProxy;
26 friend bool operator==(const XLRow& lhs, const XLRow& rhs);
27 friend bool operator!=(const XLRow& lhs, const XLRow& rhs);
28 friend bool operator<(const XLRow& lhs, const XLRow& rhs);
29 friend bool operator>(const XLRow& lhs, const XLRow& rhs);
30 friend bool operator<=(const XLRow& lhs, const XLRow& rhs);
31 friend bool operator>=(const XLRow& lhs, const XLRow& rhs);
32
33 //---------- PUBLIC MEMBER FUNCTIONS ----------//
34 public:
38 XLRow();
39
45 XLRow(const XMLNode& rowNode, const XLSharedStrings& sharedStrings, XLWorksheet* wks = nullptr);
46
51 XLRow(const XLRow& other);
52
57 XLRow(XLRow&& other) noexcept;
58
64
69 XLRow& operator=(const XLRow& other);
70
75 XLRow& operator=(XLRow&& other) noexcept;
76
81 bool empty() const;
82
87 explicit operator bool() const;
88
93 double height() const;
94
99 void setHeight(float height);
100
106 float descent() const;
107
113 void setDescent(float descent);
114
119 bool isHidden() const;
120
125 void setHidden(bool state);
126
131 uint8_t outlineLevel() const;
132
137 void setOutlineLevel(uint8_t level);
138
143 bool isCollapsed() const;
144
149 void setCollapsed(bool state);
150
155 uint32_t rowNumber() const;
156
161 uint16_t cellCount() const;
162
167 XLRowDataProxy& values();
168
173 const XLRowDataProxy& values() const;
174
180 template<typename T>
181 T values() const
182 { return static_cast<T>(values()); }
183
188 XLRowDataRange cells() const;
189
195 XLRowDataRange cells(uint16_t cellCount) const;
196
203 XLRowDataRange cells(uint16_t firstCell, uint16_t lastCell) const;
204
210 XLCell findCell(uint16_t columNumber);
211
217 XLStyleIndex format() const;
218
224 bool setFormat(XLStyleIndex cellFormatIndex);
225
226 private:
233 static bool isEqual(const XLRow& lhs, const XLRow& rhs);
234
241 static bool isLessThan(const XLRow& lhs, const XLRow& rhs);
242
243 //---------- PRIVATE MEMBER VARIABLES ----------//
244 std::unique_ptr<XMLNode> m_rowNode;
245 XLSharedStringsRef m_sharedStrings;
246 XLRowDataProxy m_rowDataProxy;
247 XLWorksheet* m_wks{nullptr};
248 };
249
253 class OPENXLSX_EXPORT XLRowIterator
254 {
255 public:
256 using iterator_category = std::forward_iterator_tag;
258 using difference_type = int64_t;
259 using pointer = XLRow*;
260 using reference = XLRow&;
261
267 explicit XLRowIterator(const XLRowRange& rowRange, XLIteratorLocation loc);
268
273
278 XLRowIterator(const XLRowIterator& other);
279
284 XLRowIterator(XLRowIterator&& other) noexcept;
285
291 XLRowIterator& operator=(const XLRowIterator& other);
292
299
300 private
301 : // ===== Switch to private method that is used by the XLRowIterator increment operator++ and the dereference operators * and ->
302 static constexpr const bool XLCreateIfMissing = true; // code readability for updateCurrentRow parameter createIfMissing
303 static constexpr const bool XLDoNotCreateIfMissing = false; // "
308 void updateCurrentRow(bool createIfMissing);
309
310 public: // ===== Switch back to public methods
315 XLRowIterator& operator++();
316
321 XLRowIterator operator++(int); // NOLINT
322
327 reference operator*();
328
333 pointer operator->();
334
340 bool operator==(const XLRowIterator& rhs) const;
341
347 bool operator!=(const XLRowIterator& rhs) const;
348
353 explicit operator bool() const;
354
359 bool rowExists();
360
365 bool endReached() const { return m_endReached; }
366
371 uint32_t rowNumber() const { return m_endReached ? m_lastRow + 1 : m_currentRowNumber; }
372
373 private:
374 std::unique_ptr<XMLNode> m_dataNode;
375 uint32_t m_firstRow{1};
376 uint32_t m_lastRow{1};
377 XLRow m_currentRow;
378 XLSharedStringsRef m_sharedStrings;
380 // helper variables for non-creating iterator functionality
381 bool m_endReached;
382 XMLNode m_hintRow;
383 uint32_t m_hintRowNumber;
384 static constexpr const int XLNotLoaded = 0; // code readability for m_currentRowStatus
385 static constexpr const int XLNoSuchRow = 1; // "
386 static constexpr const int XLLoaded = 2; // "
387 int m_currentRowStatus;
388 uint32_t m_currentRowNumber;
389 };
390
394 class OPENXLSX_EXPORT XLRowRange
395 {
396 friend class XLRowIterator;
397
398 //----------------------------------------------------------------------------------------------------------------------
399 // Public Member Functions
400 //----------------------------------------------------------------------------------------------------------------------
401
402 public:
410 explicit XLRowRange(const XMLNode& dataNode, uint32_t first, uint32_t last, const XLSharedStrings& sharedStrings);
411
416 XLRowRange(const XLRowRange& other);
417
422 XLRowRange(XLRowRange&& other) noexcept;
423
428
434 XLRowRange& operator=(const XLRowRange& other);
435
441 XLRowRange& operator=(XLRowRange&& other) noexcept;
442
447 uint32_t rowCount() const;
448
453 XLRowIterator begin();
454
459 XLRowIterator end();
460
461 //----------------------------------------------------------------------------------------------------------------------
462 // Private Member Variables
463 //----------------------------------------------------------------------------------------------------------------------
464
465 private:
466 std::unique_ptr<XMLNode> m_dataNode;
467 uint32_t m_firstRow;
468 uint32_t m_lastRow;
469 XLSharedStringsRef m_sharedStrings;
470 };
471
472} // namespace OpenXLSX
473
474namespace OpenXLSX
475{
482 inline bool operator==(const XLRow& lhs, const XLRow& rhs) { return XLRow::isEqual(lhs, rhs); }
483
490 inline bool operator!=(const XLRow& lhs, const XLRow& rhs) { return !(lhs.m_rowNode == rhs.m_rowNode); }
491
498 inline bool operator<(const XLRow& lhs, const XLRow& rhs) { return XLRow::isLessThan(lhs, rhs); }
499
506 inline bool operator>(const XLRow& lhs, const XLRow& rhs) { return (rhs < lhs); }
507
514 inline bool operator<=(const XLRow& lhs, const XLRow& rhs) { return !(lhs > rhs); }
515
522 inline bool operator>=(const XLRow& lhs, const XLRow& rhs) { return !(lhs < rhs); }
523
524} // namespace OpenXLSX
525
526#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
527# pragma warning(pop)
528#endif // _MSC_VER
529
530#endif // OPENXLSX_XLROW_HPP
Definition XLXmlParser.hpp:84
An implementation class encapsulating the properties and behaviours of a spreadsheet cell.
Definition XLCell.hpp:41
The XLRowDataProxy is used as a proxy object when getting or setting row data. The class facilitates ...
Definition XLRowData.hpp:231
This class encapsulates the concept of a contiguous range of cells in a row.
Definition XLRowData.hpp:131
Definition XLRow.hpp:254
std::forward_iterator_tag iterator_category
Definition XLRow.hpp:256
XLRowIterator & operator=(XLRowIterator &&other) noexcept
uint32_t rowNumber() const
get the row number corresponding to the current iterator position
Definition XLRow.hpp:371
XLRowIterator(XLRowIterator &&other) noexcept
bool endReached() const
determine whether iterator is at 1 beyond the last row in range
Definition XLRow.hpp:365
int64_t difference_type
Definition XLRow.hpp:258
Definition XLRow.hpp:395
XLRowRange & operator=(XLRowRange &&other) noexcept
XLRowRange(XLRowRange &&other) noexcept
The XLRow class represent a row in an Excel spreadsheet. Using XLRow objects, various row formatting ...
Definition XLRow.hpp:23
~XLRow()
Destructor.
T values() const
Definition XLRow.hpp:181
This class encapsulate the Excel concept of Shared Strings. In Excel, instead of havig individual str...
Definition XLSharedStrings.hpp:67
A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook ob...
Definition XLWorksheet.hpp:118
Definition IZipArchive.hpp: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
constexpr const bool XLCreateIfMissing
Definition XLStyles.hpp:41
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:63
bool operator<=(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Asserts whether a cell sequentially precedes or occupies the exact same coordinate as another.
Definition XLCellReference.hpp:244
size_t XLStyleIndex
Definition XLStyles.hpp:31
bool operator<(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Evaluates precedence primarily by row, then by column, allowing cell ranges to be sorted efficiently ...
Definition XLCellReference.hpp:233
bool operator>=(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Asserts whether a cell sequentially follows or occupies the exact same coordinate as another.
Definition XLCellReference.hpp:249
bool operator>(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Inverts the less-than operator logic to verify strict left-to-right, top-to-bottom traversal dominanc...
Definition XLCellReference.hpp:239
std::reference_wrapper< const XLSharedStrings > XLSharedStringsRef
Definition XLSharedStrings.hpp:56