OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLRelationships.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLRELATIONSHIPS_HPP
2#define OPENXLSX_XLRELATIONSHIPS_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 <gsl/pointers>
12#include <random> // std::mt19937
13#include <string>
14#include <vector>
15
16// ===== OpenXLSX Includes ===== //
17#include "OpenXLSX-Exports.hpp"
18#include "XLXmlFile.hpp"
19#include "XLXmlParser.hpp"
20
21namespace OpenXLSX
22{
26 void UseRandomIDs();
27
31 void UseSequentialIDs();
32
37 extern thread_local std::mt19937 Rand32;
38
43 uint64_t Rand64();
44
49 void InitRandom(bool pseudoRandom = false);
50
51 class XLRelationships;
52
53 class XLRelationshipItem;
54
94} // namespace OpenXLSX
95
97{ // special namespace to avoid naming conflict with another GetStringFromType function
98 using namespace OpenXLSX;
103 std::string GetStringFromType(XLRelationshipType type);
104} // namespace OpenXLSX_XLRelationships
105
106namespace OpenXLSX
107{
108 class OPENXLSX_EXPORT XLRelationshipItem
109 {
110 public:
112
116 explicit XLRelationshipItem(const XMLNode& node);
117
119 XLRelationshipItem(const XLRelationshipItem& other) = default;
120 XLRelationshipItem(XLRelationshipItem&& other) noexcept = default;
122 XLRelationshipItem& operator=(XLRelationshipItem&& other) noexcept = default;
123
124 [[nodiscard]] XLRelationshipType type() const;
125
129 [[nodiscard]] std::string target() const;
130
131 [[nodiscard]] std::string id() const;
132
133 [[nodiscard]] bool empty() const;
134
135 private:
136 XMLNode m_relationshipNode;
137 };
138
139 class OPENXLSX_EXPORT XLRelationships : public XLXmlFile
140 {
141 public:
142 XLRelationships() = default;
143
148 explicit XLRelationships(gsl::not_null<XLXmlData*> xmlData, std::string pathTo);
149
151
152 XLRelationships(const XLRelationships& other) = default;
153 XLRelationships(XLRelationships&& other) noexcept = default;
154 XLRelationships& operator=(const XLRelationships& other) = default;
155 XLRelationships& operator=(XLRelationships&& other) noexcept = default;
156
157 [[nodiscard]] XLRelationshipItem relationshipById(std::string_view id) const;
158
163 [[nodiscard]] XLRelationshipItem relationshipByTarget(std::string_view target, bool throwIfNotFound = true) const;
164
165 [[nodiscard]] std::vector<XLRelationshipItem> relationships() const;
166
167 void deleteRelationship(std::string_view relID);
168 void deleteRelationship(const XLRelationshipItem& item);
169
174 XLRelationshipItem addRelationship(XLRelationshipType type, std::string_view target, bool isExternal = false);
175
176 [[nodiscard]] bool targetExists(std::string_view target) const;
177 [[nodiscard]] bool idExists(std::string_view id) const;
178
182 void print(std::basic_ostream<char>& ostr) const;
183
184 private:
185 std::string m_path;
186 };
187} // namespace OpenXLSX
188
189#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
190# pragma warning(pop)
191#endif // _MSC_VER
192
193#endif // OPENXLSX_XLRELATIONSHIPS_HPP
XLXmlData * xmlData
Definition XLDocument.cpp:1422
return XLRelationships(xmlData, relsFilename)
Definition XLXmlParser.hpp:84
Definition XLRelationships.hpp:109
XLRelationshipItem & operator=(const XLRelationshipItem &other)=default
XLRelationshipItem(const XLRelationshipItem &other)=default
XLRelationshipItem(XLRelationshipItem &&other) noexcept=default
XLRelationshipItem & operator=(XLRelationshipItem &&other) noexcept=default
Definition XLRelationships.hpp:140
XLRelationships(XLRelationships &&other) noexcept=default
XLRelationships & operator=(const XLRelationships &other)=default
XLRelationships(const XLRelationships &other)=default
XLRelationships & operator=(XLRelationships &&other) noexcept=default
The XLXmlFile class provides an interface for derived classes to use. It functions as an ancestor to ...
Definition XLXmlFile.hpp:42
Definition XLRelationships.hpp:97
std::string GetStringFromType(XLRelationshipType type)
helper function, used only within module and from XLProperties.cpp / XLAppProperties::createFromTempl...
Definition XLRelationships.cpp:136
Definition IZipArchive.hpp:18
void InitRandom(bool pseudoRandom=false)
Initialize XLRand32 data source.
Definition XLRelationships.cpp:56
XLRelationshipType
An enum of the possible relationship (or XML document) types used in relationship (....
Definition XLRelationships.hpp:58
uint64_t Rand64()
Return a 64 bit random value (by invoking Rand32 twice)
Definition XLRelationships.cpp:48
void UseRandomIDs()
Enable use of random (relationship) IDs.
Definition XLRelationships.cpp:33
thread_local std::mt19937 Rand32
Return a 32 bit random value.
void UseSequentialIDs()
Disable use of random (relationship) IDs (default behavior)
Definition XLRelationships.cpp:38