Fill in rest of interface; switch created_stream to a unique_ptr

pull/2306/head
Adrian Perez 2019-01-21 14:37:33 -08:00
parent 8191080986
commit 87112eefae
1 changed files with 41 additions and 13 deletions

View File

@ -152,7 +152,7 @@ class MemoryIOSystem : public IOSystem
public: public:
/** Constructor. */ /** Constructor. */
MemoryIOSystem(const uint8_t* buff, size_t len, IOSystem* io) MemoryIOSystem(const uint8_t* buff, size_t len, IOSystem* io)
: buffer(buff), length(len), existing_io(io), created_stream(NULL) {} : buffer(buff), length(len), existing_io(io), created_stream() {}
/** Destructor. */ /** Destructor. */
~MemoryIOSystem() { ~MemoryIOSystem() {
@ -160,7 +160,7 @@ 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 override {
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 true; return true;
} }
@ -169,27 +169,26 @@ public:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Returns the directory separator. */ /** Returns the directory separator. */
char getOsSeparator() const { char getOsSeparator() const override {
return existing_io ? existing_io->getOsSeparator() return existing_io ? existing_io->getOsSeparator()
: '/'; // why not? it doesn't care : '/'; // 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") override {
if (!strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) { if (!strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
created_stream = new MemoryIOStream(buffer, length); created_stream.reset(new MemoryIOStream(buffer, length));
return created_stream; return created_stream.get();
} }
return existing_io ? existing_io->Open(pFile, pMode) : NULL; 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) override {
if (pFile == created_stream) { if (pFile == created_stream.get()) {
delete pFile; created_stream.reset();
created_stream = NULL;
} else if (existing_io) { } else if (existing_io) {
existing_io->Close(pFile); existing_io->Close(pFile);
} }
@ -197,15 +196,44 @@ public:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Compare two paths */ /** Compare two paths */
bool ComparePaths(const char* one, const char* second) const { bool ComparePaths(const char* one, const char* second) const override {
return existing_io ? existing_io->ComparePaths(one, second) : false; return existing_io ? existing_io->ComparePaths(one, second) : false;
} }
bool PushDirectory( const std::string &path ) override {
return existing_io ? existing_io->PushDirectory(path) : false;
}
const std::string &CurrentDirectory() const override {
static std::string empty;
return existing_io ? existing_io->CurrentDirectory() : empty;
}
size_t StackSize() const override {
return existing_io ? existing_io->StackSize() : 0;
}
bool PopDirectory() override {
return existing_io ? existing_io->PopDirectory() : false;
}
bool CreateDirectory( const std::string &path ) override {
return existing_io ? existing_io->CreateDirectory(path) : false;
}
bool ChangeDirectory( const std::string &path ) override {
return existing_io ? existing_io->ChangeDirectory(path) : false;
}
bool DeleteFile( const std::string &file ) override {
return existing_io ? existing_io->DeleteFile(file) : false;
}
private: 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::unique_ptr<IOStream> created_stream;
}; };
} // end namespace Assimp } // end namespace Assimp