OpenXLSX 1.10.0
Loading...
Searching...
No Matches
XLXmlData.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLXMLDATA_HPP
2#define OPENXLSX_XLXMLDATA_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 <cstdlib>
12#include <memory>
13#include <string>
14
15// ===== OpenXLSX Includes ===== //
16#include "OpenXLSX-Exports.hpp"
17#include "XLContentTypes.hpp"
18#include "XLXmlParser.hpp"
20
21namespace OpenXLSX
22{
27 void* data = nullptr;
28 size_t size = 0;
29
30 ~XLAllocatedMemory() { if (data) std::free(data); }
31 XLAllocatedMemory() = default;
32
33 // Disable copy
36
37 // Enable move
38 XLAllocatedMemory(XLAllocatedMemory&& other) noexcept : data(other.data), size(other.size) {
39 other.data = nullptr;
40 other.size = 0;
41 }
43 if (this != &other) {
44 if (data) std::free(data);
45 data = other.data;
46 size = other.size;
47 other.data = nullptr;
48 other.size = 0;
49 }
50 return *this;
51 }
52
53 // Release ownership
54 void* release() {
55 void* ret = data;
56 data = nullptr;
57 return ret;
58 }
59 };
60
67 class OPENXLSX_EXPORT XLXmlData final
68 {
69 public:
70 // ===== PUBLIC MEMBER FUNCTIONS ===== //
71
77 XLXmlData() = default;
78
88 XLXmlData(XLDocument* parentDoc,
89 const std::string& xmlPath,
90 const std::string& xmlId = "",
91 XLContentType xmlType = XLContentType::Unknown);
92
98
104 bool valid() const { return m_xmlDoc != nullptr; }
105
111 XLXmlData(const XLXmlData& other) = delete;
112
118 XLXmlData(XLXmlData&& other) noexcept = default;
119
124 XLXmlData& operator=(const XLXmlData& other) = delete;
125
132 XLXmlData& operator=(XLXmlData&& other) noexcept = default;
133
140 void setRawData(const std::string& data);
141
149 std::string getRawData(XLXmlSavingDeclaration savingDeclaration = XLXmlSavingDeclaration{}) const;
150
157 XLAllocatedMemory getRawAllocatedData(XLXmlSavingDeclaration savingDeclaration = XLXmlSavingDeclaration{}) const;
158
163 XLDocument* getParentDoc();
164
169 const XLDocument* getParentDoc() const;
170
175 std::string getXmlPath() const;
176
181 std::string getXmlID() const;
182
187 XLContentType getXmlType() const;
188
193 XMLDocument* getXmlDocument();
194
199 const XMLDocument* getXmlDocument() const;
200
205 bool empty() const;
206
207 private:
208 // ===== PRIVATE MEMBER VARIABLES ===== //
209
210 XLDocument* m_parentDoc{};
211 std::string m_xmlPath{};
212 std::string m_xmlID{};
213 XLContentType m_xmlType{};
214 mutable std::unique_ptr<XMLDocument> m_xmlDoc;
215 public:
216 bool m_isStreamed{false};
217 std::string m_streamFilePath;
218 };
219} // namespace OpenXLSX
220
221#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
222# pragma warning(pop)
223#endif // _MSC_VER
224
225#endif // OPENXLSX_XLXMLDATA_HPP
This class encapsulates the concept of an excel file. It is different from the XLWorkbook,...
Definition XLDocument.hpp:82
The XLXmlData class encapsulates the properties and behaviour of the .xml files in an ....
Definition XLXmlData.hpp:68
bool valid() const
check whether class is linked to a valid XML document
Definition XLXmlData.hpp:104
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:217
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....
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,...
The XLXmlSavingDeclaration class encapsulates the properties of an XML saving declaration,...
Definition XLXmlSavingDeclaration.hpp:19
Definition IZipArchive.hpp:18
XLContentType
Definition XLContentTypes.hpp:28
Auto-managed malloc memory for Zero-Copy serialization.
Definition XLXmlData.hpp:26
XLAllocatedMemory(const XLAllocatedMemory &)=delete
XLAllocatedMemory(XLAllocatedMemory &&other) noexcept
Definition XLXmlData.hpp:38
void * data
Definition XLXmlData.hpp:27
~XLAllocatedMemory()
Definition XLXmlData.hpp:30
XLAllocatedMemory & operator=(XLAllocatedMemory &&other) noexcept
Definition XLXmlData.hpp:42
XLAllocatedMemory & operator=(const XLAllocatedMemory &)=delete
size_t size
Definition XLXmlData.hpp:28
void * release()
Definition XLXmlData.hpp:54