vrshoot
diff libs/assimp/CInterfaceIOWrapper.h @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/CInterfaceIOWrapper.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,158 @@ 1.4 +/* 1.5 +--------------------------------------------------------------------------- 1.6 +Open Asset Import Library (assimp) 1.7 +--------------------------------------------------------------------------- 1.8 + 1.9 +Copyright (c) 2006-2012, assimp team 1.10 + 1.11 +All rights reserved. 1.12 + 1.13 +Redistribution and use of this software in source and binary forms, 1.14 +with or without modification, are permitted provided that the following 1.15 +conditions are met: 1.16 + 1.17 +* Redistributions of source code must retain the above 1.18 + copyright notice, this list of conditions and the 1.19 + following disclaimer. 1.20 + 1.21 +* Redistributions in binary form must reproduce the above 1.22 + copyright notice, this list of conditions and the 1.23 + following disclaimer in the documentation and/or other 1.24 + materials provided with the distribution. 1.25 + 1.26 +* Neither the name of the assimp team, nor the names of its 1.27 + contributors may be used to endorse or promote products 1.28 + derived from this software without specific prior 1.29 + written permission of the assimp team. 1.30 + 1.31 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.32 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.33 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.34 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.35 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.36 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.37 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.41 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.42 +--------------------------------------------------------------------------- 1.43 +*/ 1.44 + 1.45 +/** @file aiFileIO -> IOSystem wrapper*/ 1.46 + 1.47 +#ifndef AI_CIOSYSTEM_H_INCLUDED 1.48 +#define AI_CIOSYSTEM_H_INCLUDED 1.49 + 1.50 +#include "assimp/cfileio.h" 1.51 + 1.52 +namespace Assimp { 1.53 + 1.54 +// ------------------------------------------------------------------------------------------------ 1.55 +// Custom IOStream implementation for the C-API 1.56 +class CIOStreamWrapper : public IOStream 1.57 +{ 1.58 + friend class CIOSystemWrapper; 1.59 +public: 1.60 + 1.61 + CIOStreamWrapper(aiFile* pFile) 1.62 + : mFile(pFile) 1.63 + {} 1.64 + 1.65 + // ................................................................... 1.66 + size_t Read(void* pvBuffer, 1.67 + size_t pSize, 1.68 + size_t pCount 1.69 + ){ 1.70 + // need to typecast here as C has no void* 1.71 + return mFile->ReadProc(mFile,(char*)pvBuffer,pSize,pCount); 1.72 + } 1.73 + 1.74 + // ................................................................... 1.75 + size_t Write(const void* pvBuffer, 1.76 + size_t pSize, 1.77 + size_t pCount 1.78 + ){ 1.79 + // need to typecast here as C has no void* 1.80 + return mFile->WriteProc(mFile,(const char*)pvBuffer,pSize,pCount); 1.81 + } 1.82 + 1.83 + // ................................................................... 1.84 + aiReturn Seek(size_t pOffset, 1.85 + aiOrigin pOrigin 1.86 + ){ 1.87 + return mFile->SeekProc(mFile,pOffset,pOrigin); 1.88 + } 1.89 + 1.90 + // ................................................................... 1.91 + size_t Tell(void) const { 1.92 + return mFile->TellProc(mFile); 1.93 + } 1.94 + 1.95 + // ................................................................... 1.96 + size_t FileSize() const { 1.97 + return mFile->FileSizeProc(mFile); 1.98 + } 1.99 + 1.100 + // ................................................................... 1.101 + void Flush () { 1.102 + return mFile->FlushProc(mFile); 1.103 + } 1.104 + 1.105 +private: 1.106 + aiFile* mFile; 1.107 +}; 1.108 + 1.109 +// ------------------------------------------------------------------------------------------------ 1.110 +// Custom IOStream implementation for the C-API 1.111 +class CIOSystemWrapper : public IOSystem 1.112 +{ 1.113 +public: 1.114 + CIOSystemWrapper(aiFileIO* pFile) 1.115 + : mFileSystem(pFile) 1.116 + {} 1.117 + 1.118 + // ................................................................... 1.119 + bool Exists( const char* pFile) const { 1.120 + aiFile* p = mFileSystem->OpenProc(mFileSystem,pFile,"rb"); 1.121 + if (p){ 1.122 + mFileSystem->CloseProc(mFileSystem,p); 1.123 + return true; 1.124 + } 1.125 + return false; 1.126 + } 1.127 + 1.128 + // ................................................................... 1.129 + char getOsSeparator() const { 1.130 +#ifndef _WIN32 1.131 + return '/'; 1.132 +#else 1.133 + return '\\'; 1.134 +#endif 1.135 + } 1.136 + 1.137 + // ................................................................... 1.138 + IOStream* Open(const char* pFile,const char* pMode = "rb") { 1.139 + aiFile* p = mFileSystem->OpenProc(mFileSystem,pFile,pMode); 1.140 + if (!p) { 1.141 + return NULL; 1.142 + } 1.143 + return new CIOStreamWrapper(p); 1.144 + } 1.145 + 1.146 + // ................................................................... 1.147 + void Close( IOStream* pFile) { 1.148 + if (!pFile) { 1.149 + return; 1.150 + } 1.151 + mFileSystem->CloseProc(mFileSystem,((CIOStreamWrapper*) pFile)->mFile); 1.152 + delete pFile; 1.153 + } 1.154 +private: 1.155 + aiFileIO* mFileSystem; 1.156 +}; 1.157 + 1.158 +} 1.159 + 1.160 +#endif 1.161 +