OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLCellReference.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_XLCELLREFERENCE_HPP
12#define OPENXLSX_XLCELLREFERENCE_HPP
13
14#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
15# pragma warning(push)
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
18#endif // _MSC_VER
19
20// ===== External Includes ===== //
21#include <cstdint> // Pull request #276
22#include <string>
23#include <string_view>
24#include <utility>
25
26// ===== OpenXLSX Includes ===== //
27#include "OpenXLSX-Exports.hpp"
28
29namespace OpenXLSX
30{
35 {
36 uint32_t row;
37 uint16_t column;
38 };
39
43 class OPENXLSX_EXPORT XLCellReference final
44 {
45 friend bool operator==(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
46 friend bool operator!=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
47 friend bool operator<(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
48 friend bool operator>(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
49 friend bool operator<=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
50 friend bool operator>=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept;
51
52 //----------------------------------------------------------------------------------------------------------------------
53 // Public Member Functions
54 //----------------------------------------------------------------------------------------------------------------------
55
56 public:
63 XLCellReference(std::string_view cellAddress = ""); // NOLINT
64
70 XLCellReference(uint32_t row, uint16_t column);
71
77 XLCellReference(uint32_t row, std::string_view column);
78
84
90
95
102
109
115
120 XLCellReference operator++(int); // NOLINT
121
127
132 XLCellReference operator--(int); // NOLINT
133
138 uint32_t row() const noexcept;
139
144 void setRow(uint32_t row);
145
150 uint16_t column() const noexcept;
151
156 void setColumn(uint16_t column);
157
163 void setRowAndColumn(uint32_t row, uint16_t column);
164
169 std::string address() const;
170
176 void setAddress(std::string_view address);
177
178 //----------------------------------------------------------------------------------------------------------------------
179 // Private Member Functions
180 //----------------------------------------------------------------------------------------------------------------------
181
182 // private:
183
189 static std::string rowAsString(uint32_t row);
190
196 static uint32_t rowAsNumber(std::string_view row);
197
203 static std::string columnAsString(uint16_t column);
204
210 static uint16_t columnAsNumber(std::string_view column);
211
217 static XLCoordinates coordinatesFromAddress(std::string_view address);
218
219 //----------------------------------------------------------------------------------------------------------------------
220 // Private Member Variables
221 //----------------------------------------------------------------------------------------------------------------------
222 private:
223 uint32_t m_row{1};
224 uint16_t m_column{1};
225 std::string m_cellAddress{"A1"};
226 };
227
231 inline bool operator==(const XLCellReference& lhs, const XLCellReference& rhs) noexcept
232 { return lhs.row() == rhs.row() and lhs.column() == rhs.column(); }
233
237 inline bool operator!=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept { return !(lhs == rhs); }
238
243 inline bool operator<(const XLCellReference& lhs, const XLCellReference& rhs) noexcept
244 { return lhs.row() < rhs.row() or (lhs.row() <= rhs.row() and lhs.column() < rhs.column()); }
245
249 inline bool operator>(const XLCellReference& lhs, const XLCellReference& rhs) noexcept { return (rhs < lhs); }
250
254 inline bool operator<=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept { return !(lhs > rhs); }
255
259 inline bool operator>=(const XLCellReference& lhs, const XLCellReference& rhs) noexcept { return !(lhs < rhs); }
260} // namespace OpenXLSX
261
262#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
263# pragma warning(pop)
264#endif // _MSC_VER
265
266#endif // OPENXLSX_XLCELLREFERENCE_HPP
void setRow(uint32_t row)
Set the row number for the XLCellReference.
Definition XLCellReference.cpp:163
~XLCellReference()
Destructor. Default implementation used.
friend 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:243
XLCellReference(std::string_view cellAddress="")
Constructor taking a cell address as argument.
Definition XLCellReference.cpp:43
friend 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:249
static std::string rowAsString(uint32_t row)
Definition XLCellReference.cpp:225
static uint32_t rowAsNumber(std::string_view row)
Definition XLCellReference.cpp:235
friend 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:259
XLCellReference & operator=(XLCellReference &&other) noexcept
static std::string columnAsString(uint16_t column)
Static helper function to convert column number to column letter (e.g. column 1 becomes 'A').
Definition XLCellReference.cpp:246
void setColumn(uint16_t column)
Set the column number of the XLCellReference.
Definition XLCellReference.cpp:180
friend 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:254
XLCellReference & operator++()
Definition XLCellReference.cpp:100
static uint16_t columnAsNumber(std::string_view column)
Static helper function to convert column letter to column number (e.g. column 'A' becomes 1).
Definition XLCellReference.cpp:257
friend bool operator==(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Determines exact coordinate identity, allowing comparisons without resolving their DOM node equivalen...
Definition XLCellReference.hpp:231
XLCellReference(XLCellReference &&other) noexcept
XLCellReference(const XLCellReference &other)
Copy constructor.
XLCellReference & operator--()
Definition XLCellReference.cpp:129
uint32_t row() const noexcept
Get the row number of the XLCellReference.
Definition XLCellReference.cpp:157
friend bool operator!=(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Detects coordinate divergence, effectively identical to !(lhs == rhs).
Definition XLCellReference.hpp:237
std::string address() const
Get the address of the XLCellReference.
Definition XLCellReference.cpp:207
void setRowAndColumn(uint32_t row, uint16_t column)
Set both row and column number of the XLCellReference.
Definition XLCellReference.cpp:193
uint16_t column() const noexcept
Get the column number of the XLCellReference.
Definition XLCellReference.cpp:175
XLCellReference & operator=(const XLCellReference &other)
Assignment operator.
static XLCoordinates coordinatesFromAddress(std::string_view address)
Static helper function to convert cell address to coordinates.
Definition XLCellReference.cpp:279
void setAddress(std::string_view address)
Set the address of the XLCellReference.
Definition XLCellReference.cpp:213
Definition IXLCellProvider.hpp:24
bool operator==(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:314
bool operator!=(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:321
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:254
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:243
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:259
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:249
Definition XLCellIterator.hpp:131
Definition XLCellReference.hpp:35
uint16_t column
Definition XLCellReference.hpp:37
uint32_t row
Definition XLCellReference.hpp:36