OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLEvaluationContext.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_XLEVALUATIONCONTEXT_HPP
12#define OPENXLSX_XLEVALUATIONCONTEXT_HPP
13
14#ifdef _MSC_VER
15# pragma warning(push)
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
18#endif
19
20#include "OpenXLSX-Exports.hpp"
21#include "XLCellValue.hpp"
22
23#include <string>
24#include <string_view>
25#include <unordered_map>
26
27namespace OpenXLSX
28{
29 class XLWorksheet;
30
41 class OPENXLSX_EXPORT XLEvaluationContext
42 {
43 public:
44 virtual ~XLEvaluationContext() = default;
45
50 [[nodiscard]] virtual XLCellValue cellValue(std::string_view ref) const = 0;
51 };
52
56 class OPENXLSX_EXPORT XLMapEvaluationContext final : public XLEvaluationContext
57 {
58 public:
60 explicit XLMapEvaluationContext(std::unordered_map<std::string, XLCellValue> cells);
61
62 void set(std::string_view ref, XLCellValue value);
63
64 [[nodiscard]] XLCellValue cellValue(std::string_view ref) const override;
65
66 private:
67 std::unordered_map<std::string, XLCellValue> m_cells;
68 };
69
74 class OPENXLSX_EXPORT XLWorksheetEvaluationContext final : public XLEvaluationContext
75 {
76 public:
77 explicit XLWorksheetEvaluationContext(const XLWorksheet& wks) noexcept;
78
79 [[nodiscard]] XLCellValue cellValue(std::string_view ref) const override;
80
81 private:
82 const XLWorksheet* m_wks{nullptr};
83 };
84
85} // namespace OpenXLSX
86
87#ifdef _MSC_VER
88# pragma warning(pop)
89#endif
90
91#endif // OPENXLSX_XLEVALUATIONCONTEXT_HPP
Class encapsulating a cell value.
Definition XLCellValue.hpp:89
Abstract sheet-read port for formula evaluation.
Definition XLEvaluationContext.hpp:42
virtual XLCellValue cellValue(std::string_view ref) const =0
Resolve a single-cell reference to its live (or mapped) value.
virtual ~XLEvaluationContext()=default
void set(std::string_view ref, XLCellValue value)
Definition XLEvaluationContext.cpp:43
XLCellValue cellValue(std::string_view ref) const override
Resolve a single-cell reference to its live (or mapped) value.
Definition XLEvaluationContext.cpp:45
XLCellValue cellValue(std::string_view ref) const override
Resolve a single-cell reference to its live (or mapped) value.
Definition XLEvaluationContext.cpp:58
XLWorksheetEvaluationContext(const XLWorksheet &wks) noexcept
Definition XLEvaluationContext.cpp:56
A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook ob...
Definition XLWorksheet.hpp:132
Definition IXLCellProvider.hpp:24