|
@@ -151,9 +151,8 @@ class MemoryIOSystem : public IOSystem
|
|
{
|
|
{
|
|
public:
|
|
public:
|
|
/** Constructor. */
|
|
/** Constructor. */
|
|
- MemoryIOSystem (const uint8_t* buff, size_t len)
|
|
|
|
- : buffer (buff), length(len) {
|
|
|
|
- }
|
|
|
|
|
|
+ MemoryIOSystem(const uint8_t* buff, size_t len, IOSystem* io)
|
|
|
|
+ : 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 {
|
|
|
|
- return !strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH);
|
|
|
|
|
|
+ bool Exists(const char* pFile) const {
|
|
|
|
+ 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") {
|
|
|
|
- if (strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
|
|
|
|
- return NULL;
|
|
|
|
|
|
+ IOStream* Open(const char* pFile, const char* pMode = "rb") {
|
|
|
|
+ if (!strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
|
|
|
|
+ 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) {
|
|
- delete pFile;
|
|
|
|
|
|
+ if (pFile == created_stream) {
|
|
|
|
+ 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 {
|
|
|
|
- return false;
|
|
|
|
|
|
+ bool ComparePaths(const char* one, const char* second) const {
|
|
|
|
+ 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
|
|
|
|
|