Adapt MemoryIOSystem to delegate unhandled calls to shadowed IO system
parent
40a1c1ed07
commit
8191080986
|
@ -483,7 +483,7 @@ const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
|
||||||
IOSystem* io = pimpl->mIOHandler;
|
IOSystem* io = pimpl->mIOHandler;
|
||||||
pimpl->mIOHandler = NULL;
|
pimpl->mIOHandler = NULL;
|
||||||
|
|
||||||
SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength));
|
SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength,io));
|
||||||
|
|
||||||
// read the file and recover the previous IOSystem
|
// read the file and recover the previous IOSystem
|
||||||
static const size_t BufSize(Importer::MaxLenHint + 28);
|
static const size_t BufSize(Importer::MaxLenHint + 28);
|
||||||
|
|
|
@ -151,9 +151,8 @@ class MemoryIOSystem : public IOSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** Constructor. */
|
/** Constructor. */
|
||||||
MemoryIOSystem (const uint8_t* buff, size_t len)
|
MemoryIOSystem(const uint8_t* buff, size_t len, IOSystem* io)
|
||||||
: buffer (buff), length(len) {
|
: buffer(buff), length(len), existing_io(io), created_stream(NULL) {}
|
||||||
}
|
|
||||||
|
|
||||||
/** Destructor. */
|
/** Destructor. */
|
||||||
~MemoryIOSystem() {
|
~MemoryIOSystem() {
|
||||||
|
@ -161,40 +160,52 @@ public:
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Tests for the existence of a file at the given path. */
|
/** Tests for the existence of a file at the given path. */
|
||||||
bool Exists( const char* pFile) const {
|
bool Exists(const char* pFile) const {
|
||||||
return !strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH);
|
if (!strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return existing_io ? existing_io->Exists(pFile) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns the directory separator. */
|
/** Returns the directory separator. */
|
||||||
char getOsSeparator() const {
|
char getOsSeparator() const {
|
||||||
return '/'; // why not? it doesn't care
|
return existing_io ? existing_io->getOsSeparator()
|
||||||
|
: '/'; // why not? it doesn't care
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Open a new file with a given path. */
|
/** Open a new file with a given path. */
|
||||||
IOStream* Open( const char* pFile, const char* /*pMode*/ = "rb") {
|
IOStream* Open(const char* pFile, const char* pMode = "rb") {
|
||||||
if (strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
|
if (!strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
|
||||||
return NULL;
|
created_stream = new MemoryIOStream(buffer, length);
|
||||||
|
return created_stream;
|
||||||
}
|
}
|
||||||
return new MemoryIOStream(buffer,length);
|
return existing_io ? existing_io->Open(pFile, pMode) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Closes the given file and releases all resources associated with it. */
|
/** Closes the given file and releases all resources associated with it. */
|
||||||
void Close( IOStream* pFile) {
|
void Close( IOStream* pFile) {
|
||||||
|
if (pFile == created_stream) {
|
||||||
delete pFile;
|
delete pFile;
|
||||||
|
created_stream = NULL;
|
||||||
|
} else if (existing_io) {
|
||||||
|
existing_io->Close(pFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Compare two paths */
|
/** Compare two paths */
|
||||||
bool ComparePaths (const char* /*one*/, const char* /*second*/) const {
|
bool ComparePaths(const char* one, const char* second) const {
|
||||||
return false;
|
return existing_io ? existing_io->ComparePaths(one, second) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint8_t* buffer;
|
const uint8_t* buffer;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
IOSystem* existing_io;
|
||||||
|
IOStream* created_stream;
|
||||||
};
|
};
|
||||||
} // end namespace Assimp
|
} // end namespace Assimp
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue