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