Coverage Report

Created: 2026-10-28 07:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/contrib/openddlparser/code/OpenDDLCommon.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/OpenDDLCommon.h>
25
#include <openddlparser/Value.h>
26
27
BEGIN_ODDLPARSER_NS
28
29
Text::Text(const char *buffer, size_t numChars) :
30
49.4k
        m_capacity(0),
31
49.4k
        m_len(0),
32
49.4k
        m_buffer(nullptr) {
33
49.4k
    set(buffer, numChars);
34
49.4k
}
35
36
49.4k
Text::~Text() {
37
49.4k
    clear();
38
49.4k
}
39
40
98.9k
void Text::clear() {
41
98.9k
    delete[] m_buffer;
42
98.9k
    m_buffer = nullptr;
43
98.9k
    m_capacity = 0;
44
98.9k
    m_len = 0;
45
98.9k
}
46
47
49.4k
void Text::set(const char *buffer, size_t numChars) {
48
49.4k
    clear();
49
49.4k
    if (numChars > 0) {
50
43.0k
        m_len = numChars;
51
43.0k
        m_capacity = m_len + 1;
52
43.0k
        m_buffer = new char[m_capacity];
53
43.0k
        strncpy(m_buffer, buffer, numChars);
54
43.0k
        m_buffer[numChars] = '\0';
55
43.0k
    }
56
49.4k
}
57
58
0
bool Text::operator==(const std::string &name) const {
59
0
    if (m_len != name.size()) {
60
0
        return false;
61
0
    }
62
0
    const int res(strncmp(m_buffer, name.c_str(), name.size()));
63
64
0
    return (0 == res);
65
0
}
66
67
0
bool Text::operator==(const Text &rhs) const {
68
0
    if (m_len != rhs.m_len) {
69
0
        return false;
70
0
    }
71
72
0
    const int res(strncmp(m_buffer, rhs.m_buffer, m_len));
73
74
0
    return (0 == res);
75
0
}
76
77
Name::Name(NameType type, Text *id) :
78
207
        m_type(type), m_id(id) {
79
    // empty
80
207
}
81
82
207
Name::~Name() {
83
207
    delete m_id;
84
207
    m_id = nullptr;
85
207
}
86
87
0
Name::Name(const Name &name) {
88
0
    m_type = name.m_type;
89
0
    m_id = new Text(name.m_id->m_buffer, name.m_id->m_len);
90
0
}
91
92
Reference::Reference() :
93
0
        m_numRefs(0), m_referencedName(nullptr) {
94
    // empty
95
0
}
96
97
Reference::Reference(size_t numrefs, Name **names) :
98
60
        m_numRefs(numrefs), m_referencedName(nullptr) {
99
60
    if (numrefs > 0) {
100
60
        m_referencedName = new Name *[numrefs];
101
124
        for (size_t i = 0; i < numrefs; i++) {
102
64
            m_referencedName[i] = names[i];
103
64
        }
104
60
    }
105
60
}
106
0
Reference::Reference(const Reference &ref) {
107
0
    m_numRefs = ref.m_numRefs;
108
0
    if (m_numRefs != 0) {
109
0
        m_referencedName = new Name *[m_numRefs];
110
0
        for (size_t i = 0; i < m_numRefs; i++) {
111
0
            m_referencedName[i] = new Name(*ref.m_referencedName[i]);
112
0
        }
113
0
    }
114
0
}
115
116
60
Reference::~Reference() {
117
124
    for (size_t i = 0; i < m_numRefs; i++) {
118
64
        delete m_referencedName[i];
119
64
    }
120
60
    m_numRefs = 0;
121
60
    delete[] m_referencedName;
122
60
    m_referencedName = nullptr;
123
60
}
124
125
0
size_t Reference::sizeInBytes() {
126
0
    if (0 == m_numRefs) {
127
0
        return 0;
128
0
    }
129
130
0
    size_t size(0);
131
0
    for (size_t i = 0; i < m_numRefs; i++) {
132
0
        Name *name(m_referencedName[i]);
133
0
        if (nullptr != name) {
134
0
            size += name->m_id->m_len;
135
0
        }
136
0
    }
137
138
0
    return size;
139
0
}
140
141
Property::Property(Text *id) :
142
2.94k
        m_key(id), m_value(nullptr), m_ref(nullptr), m_next(nullptr) {
143
    // empty
144
2.94k
}
145
146
2.93k
Property::~Property() {
147
2.93k
    delete m_key;
148
2.93k
    if (m_value != nullptr)
149
2.92k
        delete m_value;
150
2.93k
    if (m_ref != nullptr)
151
18
        delete (m_ref);
152
2.93k
    if (m_next != nullptr)
153
0
        delete m_next;
154
2.93k
}
155
156
DataArrayList::DataArrayList() :
157
46.3k
        m_numItems(0), m_dataList(nullptr), m_next(nullptr), m_refs(nullptr), m_numRefs(0) {
158
    // empty
159
46.3k
}
160
161
46.3k
DataArrayList::~DataArrayList() {
162
46.3k
    delete m_dataList;
163
46.3k
    if (m_next != nullptr)
164
46.1k
        delete m_next;
165
46.3k
    if (m_refs != nullptr)
166
0
        delete m_refs;
167
46.3k
}
168
169
0
size_t DataArrayList::size() {
170
0
    size_t result(0);
171
0
    if (nullptr == m_next) {
172
0
        if (m_dataList != nullptr) {
173
0
            result = 1;
174
0
        }
175
0
        return result;
176
0
    }
177
178
0
    DataArrayList *n(m_next);
179
0
    while (nullptr != n) {
180
0
        result++;
181
0
        n = n->m_next;
182
0
    }
183
0
    return result;
184
0
}
185
186
Context::Context() :
187
68
        m_root(nullptr) {
188
    // empty
189
68
}
190
191
68
Context::~Context() {
192
68
    clear();
193
68
}
194
195
68
void Context::clear() {
196
68
    delete m_root;
197
68
    m_root = nullptr;
198
68
}
199
200
END_ODDLPARSER_NS