miniassimp

view src/CInterfaceIOWrapper.cpp @ 0:879c81d94345

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Jan 2019 18:19:26 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2018, assimp team
10 All rights reserved.
12 Redistribution and use of this software in source and binary forms,
13 with or without modification, are permitted provided that the following
14 conditions are met:
16 * Redistributions of source code must retain the above
17 copyright notice, this list of conditions and the
18 following disclaimer.
20 * Redistributions in binary form must reproduce the above
21 copyright notice, this list of conditions and the
22 following disclaimer in the documentation and/or other
23 materials provided with the distribution.
25 * Neither the name of the assimp team, nor the names of its
26 contributors may be used to endorse or promote products
27 derived from this software without specific prior
28 written permission of the assimp team.
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ---------------------------------------------------------------------------
42 */
44 /** @file aiFileIO -> IOSystem wrapper*/
46 #include "CInterfaceIOWrapper.h"
48 namespace Assimp {
50 CIOStreamWrapper::~CIOStreamWrapper(void)
51 {
52 /* Various places depend on this destructor to close the file */
53 if (mFile) {
54 mIO->mFileSystem->CloseProc(mIO->mFileSystem, mFile);
55 mFile = 0;
56 }
57 }
59 // ...................................................................
60 size_t CIOStreamWrapper::Read(void* pvBuffer,
61 size_t pSize,
62 size_t pCount
63 ){
64 // need to typecast here as C has no void*
65 return mFile->ReadProc(mFile,(char*)pvBuffer,pSize,pCount);
66 }
68 // ...................................................................
69 size_t CIOStreamWrapper::Write(const void* pvBuffer,
70 size_t pSize,
71 size_t pCount
72 ){
73 // need to typecast here as C has no void*
74 return mFile->WriteProc(mFile,(const char*)pvBuffer,pSize,pCount);
75 }
77 // ...................................................................
78 aiReturn CIOStreamWrapper::Seek(size_t pOffset,
79 aiOrigin pOrigin
80 ){
81 return mFile->SeekProc(mFile,pOffset,pOrigin);
82 }
84 // ...................................................................
85 size_t CIOStreamWrapper::Tell(void) const {
86 return mFile->TellProc(mFile);
87 }
89 // ...................................................................
90 size_t CIOStreamWrapper::FileSize() const {
91 return mFile->FileSizeProc(mFile);
92 }
94 // ...................................................................
95 void CIOStreamWrapper::Flush () {
96 return mFile->FlushProc(mFile);
97 }
99 // ------------------------------------------------------------------------------------------------
100 // Custom IOStream implementation for the C-API
101 bool CIOSystemWrapper::Exists( const char* pFile) const {
102 aiFile* p = mFileSystem->OpenProc(mFileSystem,pFile,"rb");
103 if (p){
104 mFileSystem->CloseProc(mFileSystem,p);
105 return true;
106 }
107 return false;
108 }
110 // ...................................................................
111 char CIOSystemWrapper::getOsSeparator() const {
112 #ifndef _WIN32
113 return '/';
114 #else
115 return '\\';
116 #endif
117 }
119 // ...................................................................
120 IOStream* CIOSystemWrapper::Open(const char* pFile,const char* pMode) {
121 aiFile* p = mFileSystem->OpenProc(mFileSystem,pFile,pMode);
122 if (!p) {
123 return NULL;
124 }
125 return new CIOStreamWrapper(p, this);
126 }
128 // ...................................................................
129 void CIOSystemWrapper::Close( IOStream* pFile) {
130 if (!pFile) {
131 return;
132 }
133 delete pFile;
134 }
136 }