Coverage Report

Created: 2026-02-05 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/contrib/openddlparser/code/DDLNode.cpp
Line
Count
Source
1
/*-----------------------------------------------------------------------------------------------
2
The MIT License (MIT)
3
4
Copyright (c) 2014-2020 Kim Kulling
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy of
7
this software and associated documentation files (the "Software"), to deal in
8
the Software without restriction, including without limitation the rights to
9
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
the Software, and to permit persons to whom the Software is furnished to do so,
11
subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in all
14
copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
-----------------------------------------------------------------------------------------------*/
23
#include <openddlparser/DDLNode.h>
24
#include <openddlparser/OpenDDLParser.h>
25
#include <openddlparser/OpenDDLStream.h>
26
27
#include <algorithm>
28
29
BEGIN_ODDLPARSER_NS
30
31
DDLNode::DllNodeList DDLNode::s_allocatedNodes;
32
33
template <class T>
34
inline static void releaseDataType(T *ptr) {
35
    if (nullptr == ptr) {
36
        return;
37
    }
38
39
    T *current(nullptr);
40
    while (ptr) {
41
        current = ptr;
42
        ptr = ptr->m_next;
43
        delete current;
44
    }
45
}
46
47
2.15k
static void releaseReferencedNames(Reference *ref) {
48
2.15k
    if (nullptr == ref) {
49
2.14k
        return;
50
2.14k
    }
51
52
10
    delete ref;
53
10
}
54
55
DDLNode::DDLNode(const std::string &type, const std::string &name, size_t idx, DDLNode *parent) :
56
2.15k
        m_type(type),
57
2.15k
        m_name(name),
58
2.15k
        m_parent(parent),
59
2.15k
        m_children(),
60
2.15k
        m_properties(nullptr),
61
2.15k
        m_value(nullptr),
62
2.15k
        m_dtArrayList(nullptr),
63
2.15k
        m_references(nullptr),
64
2.15k
        m_idx(idx) {
65
2.15k
    if (m_parent) {
66
2.14k
        m_parent->m_children.push_back(this);
67
2.14k
    }
68
2.15k
}
69
70
2.15k
DDLNode::~DDLNode() {
71
2.15k
    delete m_properties;
72
2.15k
    delete m_value;
73
2.15k
    releaseReferencedNames(m_references);
74
75
2.15k
    delete m_dtArrayList;
76
2.15k
    m_dtArrayList = nullptr;
77
2.15k
    if (s_allocatedNodes[m_idx] == this) {
78
2.15k
        s_allocatedNodes[m_idx] = nullptr;
79
2.15k
    }
80
4.30k
    for (size_t i = 0; i < m_children.size(); i++) {
81
2.14k
        delete m_children[i];
82
2.14k
    }
83
2.15k
}
84
85
0
void DDLNode::attachParent(DDLNode *parent) {
86
0
    if (m_parent == parent) {
87
0
        return;
88
0
    }
89
90
0
    m_parent = parent;
91
0
    if (nullptr != m_parent) {
92
0
        m_parent->m_children.push_back(this);
93
0
    }
94
0
}
95
96
0
void DDLNode::detachParent() {
97
0
    if (nullptr != m_parent) {
98
0
        DDLNodeIt it = std::find(m_parent->m_children.begin(), m_parent->m_children.end(), this);
99
0
        if (m_parent->m_children.end() != it) {
100
0
            m_parent->m_children.erase(it);
101
0
        }
102
0
        m_parent = nullptr;
103
0
    }
104
0
}
105
106
7
DDLNode *DDLNode::getParent() const {
107
7
    return m_parent;
108
7
}
109
110
13
const DDLNode::DllNodeList &DDLNode::getChildNodeList() const {
111
13
    return m_children;
112
13
}
113
114
0
void DDLNode::setType(const std::string &type) {
115
0
    m_type = type;
116
0
}
117
118
57
const std::string &DDLNode::getType() const {
119
57
    return m_type;
120
57
}
121
122
18
void DDLNode::setName(const std::string &name) {
123
18
    m_name = name;
124
18
}
125
126
2
const std::string &DDLNode::getName() const {
127
2
    return m_name;
128
2
}
129
130
39
void DDLNode::setProperties(Property *prop) {
131
39
    if (m_properties != nullptr)
132
0
        delete m_properties;
133
39
    m_properties = prop;
134
39
}
135
136
11
Property *DDLNode::getProperties() const {
137
11
    return m_properties;
138
11
}
139
140
0
bool DDLNode::hasProperty(const std::string &name) {
141
0
    const Property *prop(findPropertyByName(name));
142
0
    return (nullptr != prop);
143
0
}
144
145
0
bool DDLNode::hasProperties() const {
146
0
    return (nullptr != m_properties);
147
0
}
148
149
9
Property *DDLNode::findPropertyByName(const std::string &name) {
150
9
    if (name.empty()) {
151
0
        return nullptr;
152
0
    }
153
154
9
    if (nullptr == m_properties) {
155
0
        return nullptr;
156
0
    }
157
158
9
    Property *current(m_properties);
159
9
    while (nullptr != current) {
160
9
        int res = strncmp(current->m_key->m_buffer, name.c_str(), name.size());
161
9
        if (0 == res) {
162
9
            return current;
163
9
        }
164
0
        current = current->m_next;
165
0
    }
166
167
0
    return nullptr;
168
9
}
169
170
33
void DDLNode::setValue(Value *val) {
171
33
    m_value = val;
172
33
}
173
174
18
Value *DDLNode::getValue() const {
175
18
    return m_value;
176
18
}
177
178
21
void DDLNode::setDataArrayList(DataArrayList *dtArrayList) {
179
21
    m_dtArrayList = dtArrayList;
180
21
}
181
182
11
DataArrayList *DDLNode::getDataArrayList() const {
183
11
    return m_dtArrayList;
184
11
}
185
186
10
void DDLNode::setReferences(Reference *refs) {
187
10
    m_references = refs;
188
10
}
189
190
9
Reference *DDLNode::getReferences() const {
191
9
    return m_references;
192
9
}
193
194
0
void DDLNode::dump(IOStreamBase &stream) {
195
0
    if (!stream.isOpen()) {
196
0
        return;
197
0
    }
198
199
0
    const std::string &type = this->getType();
200
0
    stream.write("type = " + type);
201
0
    Value::Iterator it(getValue());
202
0
    while (it.hasNext()) {
203
0
        Value *v = it.getNext();
204
0
        v->dump(stream);
205
0
    }
206
0
}
207
208
2.15k
DDLNode *DDLNode::create(const std::string &type, const std::string &name, DDLNode *parent) {
209
2.15k
    const size_t idx(s_allocatedNodes.size());
210
2.15k
    DDLNode *node = new DDLNode(type, name, idx, parent);
211
2.15k
    s_allocatedNodes.push_back(node);
212
213
2.15k
    return node;
214
2.15k
}
215
216
0
void DDLNode::releaseNodes() {
217
0
    if (s_allocatedNodes.size() > 0) {
218
0
        for (DDLNodeIt it = s_allocatedNodes.begin(); it != s_allocatedNodes.end(); it++) {
219
0
            if (*it) {
220
0
                delete *it;
221
0
            }
222
0
        }
223
0
        s_allocatedNodes.clear();
224
0
    }
225
0
}
226
227
END_ODDLPARSER_NS