OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLCellReference.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLCELLREFERENCE_HPP
2#define OPENXLSX_XLCELLREFERENCE_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// ===== External Includes ===== //
11#include <cstdint> // Pull request #276
12#include <string>
13#include <string_view>
14#include <utility>
15
16// ===== OpenXLSX Includes ===== //
17#include "OpenXLSX-Exports.hpp"
18
19namespace OpenXLSX
20{
25 {
26 uint32_t row;
27 uint16_t column;
28 };
29
33 class OPENXLSX_EXPORT XLCellReference final
34 {
35 friend bool operator==(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
36 friend bool operator!=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
37 friend bool operator<(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
38 friend bool operator>(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
39 friend bool operator<=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
40 friend bool operator>=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
41
42 //----------------------------------------------------------------------------------------------------------------------
43 // Public Member Functions
44 //----------------------------------------------------------------------------------------------------------------------
45
46 public:
53 XLCellReference(std::string_view cellAddress = ""); // NOLINT
54
60 XLCellReference(uint32_t row, uint16_t column);
61
67 XLCellReference(uint32_t row, std::string_view column);
68
74
80
85
92
99
104 XLCellReference& operator++();
105
110 XLCellReference operator++(int); // NOLINT
111
116 XLCellReference& operator--();
117
122 XLCellReference operator--(int); // NOLINT
123
128 uint32_t row() const noexcept;
129
134 void setRow(uint32_t row);
135
140 uint16_t column() const noexcept;
141
146 void setColumn(uint16_t column);
147
153 void setRowAndColumn(uint32_t row, uint16_t column);
154
159 std::string address() const;
160
166 void setAddress(std::string_view address);
167
168 //----------------------------------------------------------------------------------------------------------------------
169 // Private Member Functions
170 //----------------------------------------------------------------------------------------------------------------------
171
172 // private:
173
179 static std::string rowAsString(uint32_t row);
180
186 static uint32_t rowAsNumber(std::string_view row);
187
193 static std::string columnAsString(uint16_t column);
194
200 static uint16_t columnAsNumber(std::string_view column);
201
207 static XLCoordinates coordinatesFromAddress(std::string_view address);
208
209 //----------------------------------------------------------------------------------------------------------------------
210 // Private Member Variables
211 //----------------------------------------------------------------------------------------------------------------------
212 private:
213 uint32_t m_row{1};
214 uint16_t m_column{1};
215 std::string m_cellAddress{"A1"};
216 };
217
221 inline bool operator==(const XLCellReference& lhs, const XLCellReference& rhs) noexcept
222 { return lhs.row() == rhs.row() and lhs.column() == rhs.column(); }
223
227 inline bool operator!=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept { return !(lhs == rhs); }
228
233 inline bool operator<(const XLCellReference& lhs, const XLCellReference& rhs) noexcept
234 { return lhs.row() < rhs.row() or (lhs.row() <= rhs.row() and lhs.column() < rhs.column()); }
235
239 inline bool operator>(const XLCellReference& lhs, const XLCellReference& rhs) noexcept { return (rhs < lhs); }
240
244 inline bool operator<=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept { return !(lhs > rhs); }
245
249 inline bool operator>=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept { return !(lhs < rhs); }
250} // namespace OpenXLSX
251
252#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
253# pragma warning(pop)
254#endif // _MSC_VER
255
256#endif // OPENXLSX_XLCELLREFERENCE_HPP
Definition XLCellReference.hpp:34
~XLCellReference()
Destructor. Default implementation used.
XLCellReference & operator=(XLCellReference &&other) noexcept
XLCellReference(XLCellReference &&other) noexcept
XLCellReference(const XLCellReference &other)
Copy constructor.
XLCellReference & operator=(const XLCellReference &other)
Assignment operator.
Definition IZipArchive.hpp:18
bool operator==(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:304
bool operator!=(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:311
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
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
Definition XLCellIterator.hpp:121
Definition XLCellReference.hpp:25
uint16_t column
Definition XLCellReference.hpp:27
uint32_t row
Definition XLCellReference.hpp:26