Coverage Report

Created: 2025-06-22 07:30

/src/assimp/code/CApi/CInterfaceIOWrapper.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
---------------------------------------------------------------------------
3
Open Asset Import Library (assimp)
4
---------------------------------------------------------------------------
5
6
Copyright (c) 2006-2025, assimp team
7
8
All rights reserved.
9
10
Redistribution and use of this software in source and binary forms,
11
with or without modification, are permitted provided that the following
12
conditions are met:
13
14
* Redistributions of source code must retain the above
15
  copyright notice, this list of conditions and the
16
  following disclaimer.
17
18
* Redistributions in binary form must reproduce the above
19
  copyright notice, this list of conditions and the
20
  following disclaimer in the documentation and/or other
21
  materials provided with the distribution.
22
23
* Neither the name of the assimp team, nor the names of its
24
  contributors may be used to endorse or promote products
25
  derived from this software without specific prior
26
  written permission of the assimp team.
27
28
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
---------------------------------------------------------------------------
40
*/
41
42
/** @file aiFileIO -> IOSystem wrapper*/
43
44
#ifndef AI_CIOSYSTEM_H_INCLUDED
45
#define AI_CIOSYSTEM_H_INCLUDED
46
47
#include <assimp/cfileio.h>
48
#include <assimp/IOStream.hpp>
49
#include <assimp/IOSystem.hpp>
50
#include <assimp/ai_assert.h>
51
52
namespace Assimp {
53
54
class CIOSystemWrapper;
55
56
// ------------------------------------------------------------------------------------------------
57
/// @brief Custom IOStream implementation for the C-API-
58
// ------------------------------------------------------------------------------------------------
59
class CIOStreamWrapper final : public IOStream {
60
public:
61
    explicit CIOStreamWrapper(aiFile *pFile, CIOSystemWrapper *io);
62
    ~CIOStreamWrapper() override;
63
    size_t Read(void *pvBuffer, size_t pSize, size_t pCount) override;
64
    size_t Write(const void *pvBuffer, size_t pSize, size_t pCount) override;
65
    aiReturn Seek(size_t pOffset, aiOrigin pOrigin) override;
66
    size_t Tell(void) const override;
67
    size_t FileSize() const override;
68
    void Flush() override;
69
70
private:
71
    aiFile *mFile;
72
    CIOSystemWrapper *mIO;
73
};
74
75
inline CIOStreamWrapper::CIOStreamWrapper(aiFile *pFile, CIOSystemWrapper *io) :
76
0
        mFile(pFile),
77
0
        mIO(io) {
78
0
    ai_assert(io != nullptr);
79
0
}
80
81
// ------------------------------------------------------------------------------------------------
82
/// @brief Custom IO-System wrapper implementation for the C-API.
83
// ------------------------------------------------------------------------------------------------
84
class CIOSystemWrapper final : public IOSystem {
85
    friend class CIOStreamWrapper;
86
87
public:
88
    explicit CIOSystemWrapper(aiFileIO *pFile);
89
    ~CIOSystemWrapper() override = default;
90
    bool Exists(const char *pFile) const override;
91
    char getOsSeparator() const override;
92
    IOStream *Open(const char *pFile, const char *pMode = "rb") override;
93
    void Close(IOStream *pFile) override;
94
95
private:
96
    aiFileIO *mFileSystem;
97
};
98
99
0
inline CIOSystemWrapper::CIOSystemWrapper(aiFileIO *pFile) : mFileSystem(pFile) {
100
0
    ai_assert(pFile != nullptr);
101
0
}
102
103
} // namespace Assimp
104
105
#endif // AI_CIOSYSTEM_H_INCLUDED