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/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
8.32k
        m_capacity(0),
31
8.32k
        m_len(0),
32
8.32k
        m_buffer(nullptr) {
33
8.32k
    set(buffer, numChars);
34
8.32k
}
35
36
8.32k
Text::~Text() {
37
8.32k
    clear();
38
8.32k
}
39
40
16.6k
void Text::clear() {
41
16.6k
    delete[] m_buffer;
42
16.6k
    m_buffer = nullptr;
43
16.6k
    m_capacity = 0;
44
16.6k
    m_len = 0;
45
16.6k
}
46
47
8.32k
void Text::set(const char *buffer, size_t numChars) {
48
8.32k
    clear();
49
8.32k
    if (numChars > 0) {
50
2.21k
        m_len = numChars;
51
2.21k
        m_capacity = m_len + 1;
52
2.21k
        m_buffer = new char[m_capacity];
53
2.21k
        strncpy(m_buffer, buffer, numChars);
54
2.21k
        m_buffer[numChars] = '\0';
55
2.21k
    }
56
8.32k
}
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
28
        m_type(type), m_id(id) {
79
    // empty
80
28
}
81
82
28
Name::~Name() {
83
28
    delete m_id;
84
28
    m_id = nullptr;
85
28
}
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
10
        m_numRefs(numrefs), m_referencedName(nullptr) {
99
10
    if (numrefs > 0) {
100
10
        m_referencedName = new Name *[numrefs];
101
20
        for (size_t i = 0; i < numrefs; i++) {
102
10
            m_referencedName[i] = names[i];
103
10
        }
104
10
    }
105
10
}
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
10
Reference::~Reference() {
117
20
    for (size_t i = 0; i < m_numRefs; i++) {
118
10
        delete m_referencedName[i];
119
10
    }
120
10
    m_numRefs = 0;
121
10
    delete[] m_referencedName;
122
10
    m_referencedName = nullptr;
123
10
}
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
39
        m_key(id), m_value(nullptr), m_ref(nullptr), m_next(nullptr) {
143
    // empty
144
39
}
145
146
39
Property::~Property() {
147
39
    delete m_key;
148
39
    if (m_value != nullptr)
149
39
        delete m_value;
150
39
    if (m_ref != nullptr)
151
0
        delete (m_ref);
152
39
    if (m_next != nullptr)
153
0
        delete m_next;
154
39
}
155
156
DataArrayList::DataArrayList() :
157
13.4k
        m_numItems(0), m_dataList(nullptr), m_next(nullptr), m_refs(nullptr), m_numRefs(0) {
158
    // empty
159
13.4k
}
160
161
13.4k
DataArrayList::~DataArrayList() {
162
13.4k
    delete m_dataList;
163
13.4k
    if (m_next != nullptr)
164
13.4k
        delete m_next;
165
13.4k
    if (m_refs != nullptr)
166
0
        delete m_refs;
167
13.4k
}
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
11
        m_root(nullptr) {
188
    // empty
189
11
}
190
191
11
Context::~Context() {
192
11
    clear();
193
11
}
194
195
11
void Context::clear() {
196
11
    delete m_root;
197
11
    m_root = nullptr;
198
11
}
199
200
END_ODDLPARSER_NS