parent
ad18cd9660
commit
b04ed67288
|
@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
#define AI_MEMORYIO_MAGIC_FILENAME "$$$___magic___$$$"
|
#define AI_MEMORYIO_MAGIC_FILENAME "$$$___magic___$$$"
|
||||||
#define AI_MEMORYIO_MAGIC_FILENAME_LENGTH 17
|
#define AI_MEMORYIO_MAGIC_FILENAME_LENGTH 17
|
||||||
|
|
||||||
|
@ -78,9 +79,11 @@ public:
|
||||||
size_t Read(void* pvBuffer, size_t pSize, size_t pCount) {
|
size_t Read(void* pvBuffer, size_t pSize, size_t pCount) {
|
||||||
ai_assert(nullptr != pvBuffer);
|
ai_assert(nullptr != pvBuffer);
|
||||||
ai_assert(0 != pSize);
|
ai_assert(0 != pSize);
|
||||||
const size_t cnt = std::min(pCount,(length-pos)/pSize), ofs = pSize*cnt;
|
|
||||||
|
const size_t cnt = std::min( pCount, (length-pos) / pSize);
|
||||||
|
const size_t ofs = pSize * cnt;
|
||||||
|
|
||||||
memcpy(pvBuffer,buffer+pos,ofs);
|
::memcpy(pvBuffer,buffer+pos,ofs);
|
||||||
pos += ofs;
|
pos += ofs;
|
||||||
|
|
||||||
return cnt;
|
return cnt;
|
||||||
|
@ -148,20 +151,18 @@ public:
|
||||||
: buffer(buff)
|
: buffer(buff)
|
||||||
, length(len)
|
, length(len)
|
||||||
, existing_io(io)
|
, existing_io(io)
|
||||||
, created_stream() {
|
, created_streams() {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Destructor. */
|
/** Destructor. */
|
||||||
~MemoryIOSystem() {
|
~MemoryIOSystem() {
|
||||||
delete created_stream;
|
|
||||||
created_stream = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** 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 override {
|
bool Exists(const char* pFile) const override {
|
||||||
if (!strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
|
if (0 == strncmp( pFile, AI_MEMORYIO_MAGIC_FILENAME, AI_MEMORYIO_MAGIC_FILENAME_LENGTH ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return existing_io ? existing_io->Exists(pFile) : false;
|
return existing_io ? existing_io->Exists(pFile) : false;
|
||||||
|
@ -177,9 +178,9 @@ public:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** 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") override {
|
IOStream* Open(const char* pFile, const char* pMode = "rb") override {
|
||||||
if (!strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
|
if ( 0 == strncmp( pFile, AI_MEMORYIO_MAGIC_FILENAME, AI_MEMORYIO_MAGIC_FILENAME_LENGTH ) ) {
|
||||||
created_stream = new MemoryIOStream(buffer, length);
|
created_streams.emplace_back(new MemoryIOStream(buffer, length));
|
||||||
return created_stream;
|
return created_streams.back();
|
||||||
}
|
}
|
||||||
return existing_io ? existing_io->Open(pFile, pMode) : NULL;
|
return existing_io ? existing_io->Open(pFile, pMode) : NULL;
|
||||||
}
|
}
|
||||||
|
@ -187,9 +188,10 @@ public:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** 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) override {
|
void Close( IOStream* pFile) override {
|
||||||
if (pFile == created_stream) {
|
auto it = std::find(created_streams.begin(), created_streams.end(), pFile);
|
||||||
delete created_stream;
|
if (it != created_streams.end()) {
|
||||||
created_stream = nullptr;
|
delete pFile;
|
||||||
|
created_streams.erase(it);
|
||||||
} else if (existing_io) {
|
} else if (existing_io) {
|
||||||
existing_io->Close(pFile);
|
existing_io->Close(pFile);
|
||||||
}
|
}
|
||||||
|
@ -234,7 +236,7 @@ private:
|
||||||
const uint8_t* buffer;
|
const uint8_t* buffer;
|
||||||
size_t length;
|
size_t length;
|
||||||
IOSystem* existing_io;
|
IOSystem* existing_io;
|
||||||
IOStream *created_stream;
|
std::vector<IOStream*> created_streams;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace Assimp
|
} // end namespace Assimp
|
||||||
|
|
Loading…
Reference in New Issue