OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLXmlData.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_XLXMLDATA_HPP
12#define OPENXLSX_XLXMLDATA_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>
22#include <cstdlib>
23#include <memory>
24#include <string>
25
26// ===== OpenXLSX Includes ===== //
27#include "OpenXLSX-Exports.hpp"
28#include "XLContentTypes.hpp"
29#include "XLXmlParser.hpp"
31
32namespace OpenXLSX
33{
38 void* data = nullptr;
39 size_t size = 0;
40
41 ~XLAllocatedMemory() { if (data) std::free(data); }
42 XLAllocatedMemory() = default;
43
44 // Disable copy
47
48 // Enable move
49 XLAllocatedMemory(XLAllocatedMemory&& other) noexcept : data(other.data), size(other.size) {
50 other.data = nullptr;
51 other.size = 0;
52 }
54 if (this != &other) {
55 if (data) std::free(data);
56 data = other.data;
57 size = other.size;
58 other.data = nullptr;
59 other.size = 0;
60 }
61 return *this;
62 }
63
64 // Release ownership
65 void* release() {
66 void* ret = data;
67 data = nullptr;
68 return ret;
69 }
70 };
71
78 class OPENXLSX_EXPORT XLXmlData final
79 {
80 public:
81 // ===== PUBLIC MEMBER FUNCTIONS ===== //
82
88 XLXmlData() = default;
89
99 XLXmlData(XLDocument* parentDoc,
100 const std::string& xmlPath,
101 const std::string& xmlId = "",
103
109
115 bool valid() const { return m_xmlDoc != nullptr; }
116
122 XLXmlData(const XLXmlData& other) = delete;
123
129 XLXmlData(XLXmlData&& other) noexcept = default;
130
135 XLXmlData& operator=(const XLXmlData& other) = delete;
136
143 XLXmlData& operator=(XLXmlData&& other) noexcept = default;
144
151 void setRawData(const std::string& data);
152
160 std::string getRawData(XLXmlSavingDeclaration savingDeclaration = XLXmlSavingDeclaration{}) const;
161
168 XLAllocatedMemory getRawAllocatedData(XLXmlSavingDeclaration savingDeclaration = XLXmlSavingDeclaration{}) const;
169
174 XLDocument* getParentDoc();
175
180 const XLDocument* getParentDoc() const;
181
186 std::string getXmlPath() const;
187
192 std::string getXmlID() const;
193
198 XLContentType getXmlType() const;
199
204 XMLDocument* getXmlDocument();
205
210 const XMLDocument* getXmlDocument() const;
211
215 [[nodiscard]] bool isDirty() const noexcept { return m_isDirty; }
216
220 void markDirty() noexcept { m_isDirty = true; }
221
225 void markClean() noexcept { m_isDirty = false; }
226
230 [[nodiscard]] bool isLoaded() const noexcept { return m_isLoaded; }
231
236 bool empty() const;
237
238 private:
239 // ===== PRIVATE MEMBER VARIABLES ===== //
240
241 XLDocument* m_parentDoc{};
242 std::string m_xmlPath{};
243 std::string m_xmlID{};
244 XLContentType m_xmlType{};
245 mutable std::unique_ptr<XMLDocument> m_xmlDoc;
246 mutable bool m_isDirty{false};
247 mutable bool m_isLoaded{false};
248 public:
249 bool m_isStreamed{false};
250 std::string m_streamFilePath;
252 std::string m_streamMemory;
256 uint32_t m_streamLastRow{0};
257 uint16_t m_streamMaxCol{0};
258 };
259} // namespace OpenXLSX
260
261#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
262# pragma warning(pop)
263#endif // _MSC_VER
264
265#endif // OPENXLSX_XLXMLDATA_HPP
This class encapsulates the concept of an excel file. It is different from the XLWorkbook,...
Definition XLDocument.hpp:97
bool valid() const
check whether class is linked to a valid XML document
Definition XLXmlData.hpp:115
uint16_t m_streamMaxCol
Definition XLXmlData.hpp:257
XLXmlData(XLXmlData &&other) noexcept=default
Move constructor. All data members are trivially movable. Hence an explicitly defaulted move construc...
std::string m_streamFilePath
Definition XLXmlData.hpp:250
uint32_t m_streamLastRow
Definition XLXmlData.hpp:256
bool m_streamWriterOpen
Definition XLXmlData.hpp:254
bool m_isStreamed
Definition XLXmlData.hpp:249
std::string m_streamMemory
Definition XLXmlData.hpp:252
void setRawData(const std::string &data)
Set the raw data for the underlying XML document. Being able to set the XML data directly is useful w...
Definition XLXmlData.cpp:90
std::string getRawData(XLXmlSavingDeclaration savingDeclaration=XLXmlSavingDeclaration{}) const
Get the raw data for the underlying XML document. This function will retrieve the raw XML text data f...
Definition XLXmlData.cpp:104
XLXmlData & operator=(XLXmlData &&other) noexcept=default
Move assignment operator. All data members are trivially movable. Hence an explicitly defaulted move ...
XLXmlData(const XLXmlData &other)=delete
Copy constructor. The m_xmlDoc data member is a XMLDocument object, which is non-copyable....
XLXmlData & operator=(const XLXmlData &other)=delete
Copy assignment operator. The m_xmlDoc data member is a XMLDocument object, which is non-copyable....
void markDirty() noexcept
Mark this XML part as modified.
Definition XLXmlData.hpp:220
bool empty() const
Test whether there is an XML file linked to this object.
XLXmlData()=default
Default constructor. All member variables are default constructed. Except for the raw XML data,...
~XLXmlData()
Default destructor. The XLXmlData does not manage any dynamically allocated resources,...
void markClean() noexcept
Reset the dirty state of this XML part.
Definition XLXmlData.hpp:225
bool isLoaded() const noexcept
Check whether the underlying XML document DOM has been loaded into memory.
Definition XLXmlData.hpp:230
bool isDirty() const noexcept
Check whether this XML part has been modified since loaded or last saved.
Definition XLXmlData.hpp:215
The XLXmlSavingDeclaration class encapsulates the properties of an XML saving declaration,...
Definition XLXmlSavingDeclaration.hpp:29
Definition IXLCellProvider.hpp:24
XLContentType
Definition XLContentTypes.hpp:38
@ Unknown
Definition XLContentTypes.hpp:62
Auto-managed malloc memory for Zero-Copy serialization.
Definition XLXmlData.hpp:37
XLAllocatedMemory(const XLAllocatedMemory &)=delete
XLAllocatedMemory(XLAllocatedMemory &&other) noexcept
Definition XLXmlData.hpp:49
void * data
Definition XLXmlData.hpp:38
~XLAllocatedMemory()
Definition XLXmlData.hpp:41
XLAllocatedMemory & operator=(XLAllocatedMemory &&other) noexcept
Definition XLXmlData.hpp:53
XLAllocatedMemory & operator=(const XLAllocatedMemory &)=delete
size_t size
Definition XLXmlData.hpp:39
void * release()
Definition XLXmlData.hpp:65