Coverage Report

Created: 2026-01-07 06:50

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