Coverage Report

Created: 2026-09-14 07:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/contrib/openddlparser/code/OpenDDLStream.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/OpenDDLStream.h>
24
25
BEGIN_ODDLPARSER_NS
26
27
0
StreamFormatterBase::StreamFormatterBase() {
28
    // empty
29
0
}
30
31
0
StreamFormatterBase::~StreamFormatterBase() {
32
    // empty
33
0
}
34
35
0
std::string StreamFormatterBase::format(const std::string &statement) {
36
0
    std::string tmp(statement);
37
0
    return tmp;
38
0
}
39
40
IOStreamBase::IOStreamBase(StreamFormatterBase *formatter) :
41
0
        m_formatter(formatter),
42
0
        m_file(nullptr) {
43
0
    if (nullptr == m_formatter) {
44
0
        m_formatter = new StreamFormatterBase;
45
0
    }
46
0
}
47
48
0
IOStreamBase::~IOStreamBase() {
49
0
    delete m_formatter;
50
0
    m_formatter = nullptr;
51
0
}
52
53
0
bool IOStreamBase::open(const std::string &name) {
54
0
    m_file = ::fopen(name.c_str(), "a");
55
0
    if (m_file == nullptr) {
56
0
        return false;
57
0
    }
58
59
0
    return true;
60
0
}
61
62
0
bool IOStreamBase::close() {
63
0
    if (nullptr == m_file) {
64
0
        return false;
65
0
    }
66
67
0
    ::fclose(m_file);
68
0
    m_file = nullptr;
69
70
0
    return true;
71
0
}
72
73
0
bool IOStreamBase::isOpen() const {
74
0
    return (nullptr != m_file);
75
0
}
76
77
0
size_t IOStreamBase::read(size_t sizeToRead, std::string &statement) {
78
0
    if (nullptr == m_file) {
79
0
        return 0;
80
0
    }
81
82
0
    statement.resize(sizeToRead);
83
0
    const size_t readBytes = ::fread(&statement[0], 1, sizeToRead, m_file);
84
85
0
    return readBytes;
86
0
}
87
88
0
size_t IOStreamBase::write(const std::string &statement) {
89
0
    if (nullptr == m_file) {
90
0
        return 0;
91
0
    }
92
0
    std::string formatStatement = m_formatter->format(statement);
93
0
    return ::fwrite(formatStatement.c_str(), sizeof(char), formatStatement.size(), m_file);
94
0
}
95
96
END_ODDLPARSER_NS