Coverage Report

Created: 2026-10-28 07:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/AssetLib/X3D/X3DImporter_Metadata.cpp
Line
Count
Source
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2019, assimp team
6
7
All rights reserved.
8
9
Redistribution and use of this software in source and binary forms,
10
with or without modification, are permitted provided that the
11
following conditions are met:
12
13
* Redistributions of source code must retain the above
14
copyright notice, this list of conditions and the
15
following disclaimer.
16
17
* Redistributions in binary form must reproduce the above
18
copyright notice, this list of conditions and the
19
following disclaimer in the documentation and/or other
20
materials provided with the distribution.
21
22
* Neither the name of the assimp team, nor the names of its
23
contributors may be used to endorse or promote products
24
derived from this software without specific prior
25
written permission of the assimp team.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39
----------------------------------------------------------------------
40
*/
41
/// \file   X3DImporter_Metadata.cpp
42
/// \brief  Parsing data from nodes of "Metadata" set of X3D.
43
/// \date   2015-2016
44
/// \author smal.root@gmail.com
45
46
#ifndef ASSIMP_BUILD_NO_X3D_IMPORTER
47
48
#include "X3DImporter.hpp"
49
#include "X3DImporter_Macro.hpp"
50
#include "X3DXmlHelper.h"
51
52
namespace Assimp {
53
54
0
bool X3DImporter::checkForMetadataNode(XmlNode &node) {
55
0
    const std::string &name = node.name();
56
0
    if (name == "MetadataBoolean") {
57
0
        readMetadataBoolean(node);
58
0
    } else if (name == "MetadataDouble") {
59
0
        readMetadataDouble(node);
60
0
    } else if (name == "MetadataFloat") {
61
0
        readMetadataFloat(node);
62
0
    } else if (name == "MetadataInteger") {
63
0
        readMetadataInteger(node);
64
0
    } else if (name == "MetadataSet") {
65
0
        readMetadataSet(node);
66
0
    } else if (name == "MetadataString") {
67
0
        readMetadataString(node);
68
0
    } else
69
0
        return false;
70
0
    return true;
71
0
}
72
73
0
void X3DImporter::childrenReadMetadata(XmlNode &node, X3DNodeElementBase *pParentElement, const std::string &pNodeName) {
74
0
    ParseHelper_Node_Enter(pParentElement);
75
0
    for (auto childNode : node.children()) {
76
0
        if (!checkForMetadataNode(childNode)) skipUnsupportedNode(pNodeName, childNode);
77
0
    }
78
0
    ParseHelper_Node_Exit();
79
0
}
80
81
/// \def MACRO_METADATA_FINDCREATE(pDEF_Var, pUSE_Var, pReference, pValue, pNE, pMetaName)
82
/// Find element by "USE" or create new one.
83
/// \param [in] pNode - pugi xml node to read.
84
/// \param [in] pDEF_Var - variable name with "DEF" value.
85
/// \param [in] pUSE_Var - variable name with "USE" value.
86
/// \param [in] pReference - variable name with "reference" value.
87
/// \param [in] pValue - variable name with "value" value.
88
/// \param [in, out] pNE - pointer to node element.
89
/// \param [in] pMetaClass - Class of node.
90
/// \param [in] pMetaName - Name of node.
91
/// \param [in] pType - type of element to find.
92
#define MACRO_METADATA_FINDCREATE(pNode, pDEF_Var, pUSE_Var, pReference, pValue, pNE, pMetaClass, pMetaName, pType)                            \
93
    /* if "USE" defined then find already defined element. */                                                                                  \
94
0
    if (!pUSE_Var.empty()) {                                                                                                                   \
95
0
        ne = MACRO_USE_CHECKANDAPPLY(pNode, pDEF_Var, pUSE_Var, pType, pNE);                                                                        \
96
0
    } else {                                                                                                                                   \
97
0
        pNE = new pMetaClass(mNodeElementCur);                                                                                                 \
98
0
        if (!pDEF_Var.empty()) pNE->ID = pDEF_Var;                                                                                             \
99
0
                                                                                                                                               \
100
0
        ((pMetaClass *)pNE)->Reference = pReference;                                                                                           \
101
0
        ((pMetaClass *)pNE)->Value = pValue;                                                                                                   \
102
0
        /* also metadata node can contain childs */                                                                                            \
103
0
        if (!isNodeEmpty(pNode))                                                                                                               \
104
0
            childrenReadMetadata(pNode, pNE, pMetaName); /* in that case node element will be added to child elements list of current node. */ \
105
0
        else                                                                                                                                   \
106
0
            mNodeElementCur->Children.push_back(pNE); /* else - add element to child list manually */                                          \
107
0
                                                                                                                                               \
108
0
        NodeElement_List.push_back(pNE); /* add new element to elements list. */                                                               \
109
0
    } /* if(!pUSE_Var.empty()) else */                                                                                                         \
110
0
                                                                                                                                               \
111
0
    do {                                                                                                                                       \
112
0
    } while (false)
113
114
// <MetadataBoolean
115
// DEF=""       ID
116
// USE=""       IDREF
117
// name=""      SFString [inputOutput]
118
// reference="" SFString [inputOutput]
119
// value=""     MFBool   [inputOutput]
120
// />
121
0
void X3DImporter::readMetadataBoolean(XmlNode &node) {
122
0
    std::string def, use;
123
0
    std::string name, reference;
124
0
    std::vector<bool> value;
125
0
    X3DNodeElementBase *ne(nullptr);
126
127
0
    MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
128
0
    XmlParser::getStdStrAttribute(node, "name", name);
129
0
    XmlParser::getStdStrAttribute(node, "reference", reference);
130
0
    X3DXmlHelper::getBooleanArrayAttribute(node, "value", value);
131
132
0
    MACRO_METADATA_FINDCREATE(node, def, use, reference, value, ne, X3DNodeElementMetaBoolean, "MetadataBoolean", ENET_MetaBoolean);
133
0
}
134
135
// <MetadataDouble
136
// DEF=""       ID
137
// USE=""       IDREF
138
// name=""      SFString [inputOutput]
139
// reference="" SFString [inputOutput]
140
// value=""     MFDouble [inputOutput]
141
// />
142
0
void X3DImporter::readMetadataDouble(XmlNode &node) {
143
0
    std::string def, use;
144
0
    std::string name, reference;
145
0
    std::vector<double> value;
146
0
    X3DNodeElementBase *ne(nullptr);
147
148
0
    MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
149
0
    XmlParser::getStdStrAttribute(node, "name", name);
150
0
    XmlParser::getStdStrAttribute(node, "reference", reference);
151
0
    X3DXmlHelper::getDoubleArrayAttribute(node, "value", value);
152
153
0
    MACRO_METADATA_FINDCREATE(node, def, use, reference, value, ne, X3DNodeElementMetaDouble, "MetadataDouble", ENET_MetaDouble);
154
0
}
155
156
// <MetadataFloat
157
// DEF=""       ID
158
// USE=""       IDREF
159
// name=""      SFString [inputOutput]
160
// reference="" SFString [inputOutput]
161
// value=""     MFFloat  [inputOutput]
162
// />
163
0
void X3DImporter::readMetadataFloat(XmlNode &node) {
164
0
    std::string def, use;
165
0
    std::string name, reference;
166
0
    std::vector<float> value;
167
0
    X3DNodeElementBase *ne(nullptr);
168
169
0
    MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
170
0
    XmlParser::getStdStrAttribute(node, "name", name);
171
0
    XmlParser::getStdStrAttribute(node, "reference", reference);
172
0
    X3DXmlHelper::getFloatArrayAttribute(node, "value", value);
173
174
0
    MACRO_METADATA_FINDCREATE(node, def, use, reference, value, ne, X3DNodeElementMetaFloat, "MetadataFloat", ENET_MetaFloat);
175
0
}
176
177
// <MetadataInteger
178
// DEF=""       ID
179
// USE=""       IDREF
180
// name=""      SFString  [inputOutput]
181
// reference="" SFString  [inputOutput]
182
// value=""     MFInteger [inputOutput]
183
// />
184
0
void X3DImporter::readMetadataInteger(XmlNode &node) {
185
0
    std::string def, use;
186
0
    std::string name, reference;
187
0
    std::vector<int32_t> value;
188
0
    X3DNodeElementBase *ne(nullptr);
189
190
0
    MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
191
0
    XmlParser::getStdStrAttribute(node, "name", name);
192
0
    XmlParser::getStdStrAttribute(node, "reference", reference);
193
0
    X3DXmlHelper::getInt32ArrayAttribute(node, "value", value);
194
195
0
    MACRO_METADATA_FINDCREATE(node, def, use, reference, value, ne, X3DNodeElementMetaInt, "MetadataInteger", ENET_MetaInteger);
196
0
}
197
198
// <MetadataSet
199
// DEF=""       ID
200
// USE=""       IDREF
201
// name=""      SFString [inputOutput]
202
// reference="" SFString [inputOutput]
203
// />
204
0
void X3DImporter::readMetadataSet(XmlNode &node) {
205
0
    std::string def, use;
206
0
    std::string name, reference;
207
0
    X3DNodeElementBase *ne(nullptr);
208
209
0
    MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
210
0
    XmlParser::getStdStrAttribute(node, "name", name);
211
0
    XmlParser::getStdStrAttribute(node, "reference", reference);
212
213
    // if "USE" defined then find already defined element.
214
0
    if (!use.empty()) {
215
0
        ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_MetaSet, ne);
216
0
    } else {
217
0
        ne = new X3DNodeElementMetaSet(mNodeElementCur);
218
0
        if (!def.empty()) ne->ID = def;
219
220
0
        ((X3DNodeElementMetaSet *)ne)->Reference = reference;
221
        // also metadata node can contain children
222
0
        if (!isNodeEmpty(node))
223
0
            childrenReadMetadata(node, ne, "MetadataSet");
224
0
        else
225
0
            mNodeElementCur->Children.push_back(ne); // made object as child to current element
226
227
0
        NodeElement_List.push_back(ne); // add new element to elements list.
228
0
    } // if(!use.empty()) else
229
0
}
230
231
// <MetadataString
232
// DEF=""       ID
233
// USE=""       IDREF
234
// name=""      SFString [inputOutput]
235
// reference="" SFString [inputOutput]
236
// value=""     MFString [inputOutput]
237
// />
238
0
void X3DImporter::readMetadataString(XmlNode &node) {
239
0
    std::string def, use;
240
0
    std::string name, reference;
241
0
    std::vector<std::string> value;
242
0
    X3DNodeElementBase *ne(nullptr);
243
244
0
    MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
245
0
    XmlParser::getStdStrAttribute(node, "name", name);
246
0
    XmlParser::getStdStrAttribute(node, "reference", reference);
247
0
    X3DXmlHelper::getStringArrayAttribute(node, "value", value);
248
249
0
    MACRO_METADATA_FINDCREATE(node, def, use, reference, value, ne, X3DNodeElementMetaString, "MetadataString", ENET_MetaString);
250
0
}
251
252
}// namespace Assimp
253
254
#endif // !ASSIMP_BUILD_NO_X3D_IMPORTER