Coverage Report

Created: 2025-08-26 06:41

/src/assimp/code/Common/FileLogStream.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2025, assimp team
6
7
All rights reserved.
8
9
Redistribution and use of this software in source and binary forms,
10
with or without modification, are permitted provided that the
11
following conditions are met:
12
13
* Redistributions of source code must retain the above
14
copyright notice, this list of conditions and the
15
following disclaimer.
16
17
* Redistributions in binary form must reproduce the above
18
copyright notice, this list of conditions and the
19
following disclaimer in the documentation and/or other
20
materials provided with the distribution.
21
22
* Neither the name of the assimp team, nor the names of its
23
contributors may be used to endorse or promote products
24
derived from this software without specific prior
25
written permission of the assimp team.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39
----------------------------------------------------------------------
40
*/
41
/** @file FileLofStream.h
42
*/
43
#ifndef ASSIMP_FILELOGSTREAM_H_INC
44
#define ASSIMP_FILELOGSTREAM_H_INC
45
46
#include <assimp/DefaultIOSystem.h>
47
#include <assimp/IOStream.hpp>
48
#include <assimp/LogStream.hpp>
49
50
namespace Assimp {
51
52
// ----------------------------------------------------------------------------------
53
/** @class  FileLogStream
54
 *  @brief  Logstream to write into a file.
55
 */
56
class FileLogStream : public LogStream {
57
public:
58
    FileLogStream(const char *file, IOSystem *io = nullptr);
59
    ~FileLogStream();
60
    void write(const char *message);
61
62
private:
63
    IOStream *m_pStream;
64
};
65
66
// ----------------------------------------------------------------------------------
67
//  Constructor
68
inline FileLogStream::FileLogStream(const char *file, IOSystem *io) :
69
0
        m_pStream(nullptr) {
70
0
    if (!file || 0 == *file)
71
0
        return;
72
73
    // If no IOSystem is specified: take a default one
74
0
    if (!io) {
75
0
        DefaultIOSystem FileSystem;
76
0
        m_pStream = FileSystem.Open(file, "wt");
77
0
    } else
78
0
        m_pStream = io->Open(file, "wt");
79
0
}
80
81
// ----------------------------------------------------------------------------------
82
//  Destructor
83
0
inline FileLogStream::~FileLogStream() {
84
    // The virtual d'tor should destroy the underlying file
85
0
    delete m_pStream;
86
0
}
87
88
// ----------------------------------------------------------------------------------
89
//  Write method
90
0
inline void FileLogStream::write(const char *message) {
91
0
    if (m_pStream != nullptr) {
92
0
        m_pStream->Write(message, sizeof(char), ::strlen(message));
93
0
        m_pStream->Flush();
94
0
    }
95
0
}
96
97
// ----------------------------------------------------------------------------------
98
} // namespace Assimp
99
100
#endif // !! ASSIMP_FILELOGSTREAM_H_INC