vrshoot
view libs/assimp/CInterfaceIOWrapper.h @ 2:334d17aed7de
visual studio project files
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 02 Feb 2014 18:36:38 +0200 |
parents | |
children |
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2012, assimp team
8 All rights reserved.
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:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
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.
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.
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 */
42 /** @file aiFileIO -> IOSystem wrapper*/
44 #ifndef AI_CIOSYSTEM_H_INCLUDED
45 #define AI_CIOSYSTEM_H_INCLUDED
47 #include "assimp/cfileio.h"
49 namespace Assimp {
51 // ------------------------------------------------------------------------------------------------
52 // Custom IOStream implementation for the C-API
53 class CIOStreamWrapper : public IOStream
54 {
55 friend class CIOSystemWrapper;
56 public:
58 CIOStreamWrapper(aiFile* pFile)
59 : mFile(pFile)
60 {}
62 // ...................................................................
63 size_t Read(void* pvBuffer,
64 size_t pSize,
65 size_t pCount
66 ){
67 // need to typecast here as C has no void*
68 return mFile->ReadProc(mFile,(char*)pvBuffer,pSize,pCount);
69 }
71 // ...................................................................
72 size_t Write(const void* pvBuffer,
73 size_t pSize,
74 size_t pCount
75 ){
76 // need to typecast here as C has no void*
77 return mFile->WriteProc(mFile,(const char*)pvBuffer,pSize,pCount);
78 }
80 // ...................................................................
81 aiReturn Seek(size_t pOffset,
82 aiOrigin pOrigin
83 ){
84 return mFile->SeekProc(mFile,pOffset,pOrigin);
85 }
87 // ...................................................................
88 size_t Tell(void) const {
89 return mFile->TellProc(mFile);
90 }
92 // ...................................................................
93 size_t FileSize() const {
94 return mFile->FileSizeProc(mFile);
95 }
97 // ...................................................................
98 void Flush () {
99 return mFile->FlushProc(mFile);
100 }
102 private:
103 aiFile* mFile;
104 };
106 // ------------------------------------------------------------------------------------------------
107 // Custom IOStream implementation for the C-API
108 class CIOSystemWrapper : public IOSystem
109 {
110 public:
111 CIOSystemWrapper(aiFileIO* pFile)
112 : mFileSystem(pFile)
113 {}
115 // ...................................................................
116 bool Exists( const char* pFile) const {
117 aiFile* p = mFileSystem->OpenProc(mFileSystem,pFile,"rb");
118 if (p){
119 mFileSystem->CloseProc(mFileSystem,p);
120 return true;
121 }
122 return false;
123 }
125 // ...................................................................
126 char getOsSeparator() const {
127 #ifndef _WIN32
128 return '/';
129 #else
130 return '\\';
131 #endif
132 }
134 // ...................................................................
135 IOStream* Open(const char* pFile,const char* pMode = "rb") {
136 aiFile* p = mFileSystem->OpenProc(mFileSystem,pFile,pMode);
137 if (!p) {
138 return NULL;
139 }
140 return new CIOStreamWrapper(p);
141 }
143 // ...................................................................
144 void Close( IOStream* pFile) {
145 if (!pFile) {
146 return;
147 }
148 mFileSystem->CloseProc(mFileSystem,((CIOStreamWrapper*) pFile)->mFile);
149 delete pFile;
150 }
151 private:
152 aiFileIO* mFileSystem;
153 };
155 }
157 #endif