commit
e308474163
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2022, assimp team
|
Copyright (c) 2006-2022, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2022, assimp team
|
Copyright (c) 2006-2022, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -47,14 +45,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
CIOStreamWrapper::~CIOStreamWrapper() {
|
CIOStreamWrapper::~CIOStreamWrapper() {
|
||||||
/* Various places depend on this destructor to close the file */
|
// Various places depend on this destructor to close the file
|
||||||
if (mFile) {
|
if (mFile != nullptr) {
|
||||||
|
|
||||||
mIO->mFileSystem->CloseProc(mIO->mFileSystem, mFile);
|
mIO->mFileSystem->CloseProc(mIO->mFileSystem, mFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...................................................................
|
// ------------------------------------------------------------------------------------------------
|
||||||
size_t CIOStreamWrapper::Read(void *pvBuffer,
|
size_t CIOStreamWrapper::Read(void *pvBuffer,
|
||||||
size_t pSize,
|
size_t pSize,
|
||||||
size_t pCount) {
|
size_t pCount) {
|
||||||
|
@ -62,7 +62,7 @@ size_t CIOStreamWrapper::Read(void *pvBuffer,
|
||||||
return mFile->ReadProc(mFile, (char *)pvBuffer, pSize, pCount);
|
return mFile->ReadProc(mFile, (char *)pvBuffer, pSize, pCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...................................................................
|
// ------------------------------------------------------------------------------------------------
|
||||||
size_t CIOStreamWrapper::Write(const void *pvBuffer,
|
size_t CIOStreamWrapper::Write(const void *pvBuffer,
|
||||||
size_t pSize,
|
size_t pSize,
|
||||||
size_t pCount) {
|
size_t pCount) {
|
||||||
|
@ -70,23 +70,23 @@ size_t CIOStreamWrapper::Write(const void *pvBuffer,
|
||||||
return mFile->WriteProc(mFile, (const char *)pvBuffer, pSize, pCount);
|
return mFile->WriteProc(mFile, (const char *)pvBuffer, pSize, pCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...................................................................
|
// ------------------------------------------------------------------------------------------------
|
||||||
aiReturn CIOStreamWrapper::Seek(size_t pOffset,
|
aiReturn CIOStreamWrapper::Seek(size_t pOffset,
|
||||||
aiOrigin pOrigin) {
|
aiOrigin pOrigin) {
|
||||||
return mFile->SeekProc(mFile, pOffset, pOrigin);
|
return mFile->SeekProc(mFile, pOffset, pOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...................................................................
|
// ------------------------------------------------------------------------------------------------
|
||||||
size_t CIOStreamWrapper::Tell() const {
|
size_t CIOStreamWrapper::Tell() const {
|
||||||
return mFile->TellProc(mFile);
|
return mFile->TellProc(mFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...................................................................
|
// ------------------------------------------------------------------------------------------------
|
||||||
size_t CIOStreamWrapper::FileSize() const {
|
size_t CIOStreamWrapper::FileSize() const {
|
||||||
return mFile->FileSizeProc(mFile);
|
return mFile->FileSizeProc(mFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...................................................................
|
// ------------------------------------------------------------------------------------------------
|
||||||
void CIOStreamWrapper::Flush() {
|
void CIOStreamWrapper::Flush() {
|
||||||
return mFile->FlushProc(mFile);
|
return mFile->FlushProc(mFile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,48 +47,59 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <assimp/cfileio.h>
|
#include <assimp/cfileio.h>
|
||||||
#include <assimp/IOStream.hpp>
|
#include <assimp/IOStream.hpp>
|
||||||
#include <assimp/IOSystem.hpp>
|
#include <assimp/IOSystem.hpp>
|
||||||
|
#include <assimp/ai_assert.h>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
class CIOSystemWrapper;
|
class CIOSystemWrapper;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Custom IOStream implementation for the C-API
|
/// @brief Custom IOStream implementation for the C-API-
|
||||||
class CIOStreamWrapper : public IOStream {
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
class CIOStreamWrapper final : public IOStream {
|
||||||
public:
|
public:
|
||||||
explicit CIOStreamWrapper(aiFile *pFile, CIOSystemWrapper *io) :
|
explicit CIOStreamWrapper(aiFile *pFile, CIOSystemWrapper *io);
|
||||||
mFile(pFile),
|
~CIOStreamWrapper() override;
|
||||||
mIO(io) {}
|
size_t Read(void *pvBuffer, size_t pSize, size_t pCount) override;
|
||||||
~CIOStreamWrapper(void);
|
size_t Write(const void *pvBuffer, size_t pSize, size_t pCount) override;
|
||||||
|
aiReturn Seek(size_t pOffset, aiOrigin pOrigin) override;
|
||||||
size_t Read(void *pvBuffer, size_t pSize, size_t pCount);
|
size_t Tell(void) const override;
|
||||||
size_t Write(const void *pvBuffer, size_t pSize, size_t pCount);
|
size_t FileSize() const override;
|
||||||
aiReturn Seek(size_t pOffset, aiOrigin pOrigin);
|
void Flush() override;
|
||||||
size_t Tell(void) const;
|
|
||||||
size_t FileSize() const;
|
|
||||||
void Flush();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
aiFile *mFile;
|
aiFile *mFile;
|
||||||
CIOSystemWrapper *mIO;
|
CIOSystemWrapper *mIO;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CIOSystemWrapper : public IOSystem {
|
inline CIOStreamWrapper::CIOStreamWrapper(aiFile *pFile, CIOSystemWrapper *io) :
|
||||||
|
mFile(pFile),
|
||||||
|
mIO(io) {
|
||||||
|
ai_assert(io != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
/// @brief Custom IO-System wrapper implementation for the C-API.
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
class CIOSystemWrapper final : public IOSystem {
|
||||||
friend class CIOStreamWrapper;
|
friend class CIOStreamWrapper;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CIOSystemWrapper(aiFileIO *pFile) :
|
explicit CIOSystemWrapper(aiFileIO *pFile);
|
||||||
mFileSystem(pFile) {}
|
~CIOSystemWrapper() override = default;
|
||||||
|
bool Exists(const char *pFile) const override;
|
||||||
bool Exists(const char *pFile) const;
|
char getOsSeparator() const override;
|
||||||
char getOsSeparator() const;
|
IOStream *Open(const char *pFile, const char *pMode = "rb") override;
|
||||||
IOStream *Open(const char *pFile, const char *pMode = "rb");
|
void Close(IOStream *pFile) override;
|
||||||
void Close(IOStream *pFile);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
aiFileIO *mFileSystem;
|
aiFileIO *mFileSystem;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline CIOSystemWrapper::CIOSystemWrapper(aiFileIO *pFile) : mFileSystem(pFile) {
|
||||||
|
ai_assert(pFile != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Assimp
|
} // namespace Assimp
|
||||||
|
|
||||||
#endif
|
#endif // AI_CIOSYSTEM_H_INCLUDED
|
||||||
|
|
Loading…
Reference in New Issue