Fix review findings.
parent
b170370e5c
commit
b7d08fc8f2
|
@ -65,23 +65,21 @@ namespace Assimp {
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
class MemoryIOStream : public IOStream {
|
class MemoryIOStream : public IOStream {
|
||||||
public:
|
public:
|
||||||
MemoryIOStream (const uint8_t* buff, size_t len, bool own = false)
|
MemoryIOStream (const uint8_t* buff, size_t len, bool own = false) :
|
||||||
: buffer (buff)
|
buffer (buff),
|
||||||
, length(len)
|
length(len),
|
||||||
, pos((size_t)0)
|
pos(static_cast<size_t>(0)),
|
||||||
, own(own) {
|
own(own) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
~MemoryIOStream () {
|
~MemoryIOStream() override {
|
||||||
if(own) {
|
if(own) {
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
size_t Read(void* pvBuffer, size_t pSize, size_t pCount) override {
|
||||||
// Read from stream
|
|
||||||
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);
|
||||||
|
|
||||||
|
@ -94,16 +92,12 @@ public:
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
size_t Write(const void*, size_t, size_t ) override {
|
||||||
// Write to stream
|
|
||||||
size_t Write(const void* /*pvBuffer*/, size_t /*pSize*/,size_t /*pCount*/) {
|
|
||||||
ai_assert(false); // won't be needed
|
ai_assert(false); // won't be needed
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
aiReturn Seek(size_t pOffset, aiOrigin pOrigin) override {
|
||||||
// Seek specific position
|
|
||||||
aiReturn Seek(size_t pOffset, aiOrigin pOrigin) {
|
|
||||||
if (aiOrigin_SET == pOrigin) {
|
if (aiOrigin_SET == pOrigin) {
|
||||||
if (pOffset > length) {
|
if (pOffset > length) {
|
||||||
return AI_FAILURE;
|
return AI_FAILURE;
|
||||||
|
@ -123,20 +117,14 @@ public:
|
||||||
return AI_SUCCESS;
|
return AI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
size_t Tell() const override {
|
||||||
// Get current seek position
|
|
||||||
size_t Tell() const {
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
size_t FileSize() const override {
|
||||||
// Get size of file
|
|
||||||
size_t FileSize() const {
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
|
||||||
// Flush file contents
|
|
||||||
void Flush() {
|
void Flush() {
|
||||||
ai_assert(false); // won't be needed
|
ai_assert(false); // won't be needed
|
||||||
}
|
}
|
||||||
|
@ -148,19 +136,19 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
/** Dummy IO system to read from a memory buffer */
|
/// @brief Dummy IO system to read from a memory buffer.
|
||||||
class MemoryIOSystem : public IOSystem {
|
class MemoryIOSystem : public IOSystem {
|
||||||
public:
|
public:
|
||||||
/** Constructor. */
|
/// @brief Constructor.
|
||||||
MemoryIOSystem(const uint8_t* buff, size_t len, IOSystem* io) : buffer(buff), length(len), existing_io(io) {
|
MemoryIOSystem(const uint8_t* buff, size_t len, IOSystem* io) : buffer(buff), length(len), existing_io(io) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Destructor. */
|
/// @brief Destructor.
|
||||||
~MemoryIOSystem() = default;
|
~MemoryIOSystem() = default;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Tests for the existence of a file at the given path. */
|
/// @brief 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 {
|
||||||
printf("Exists\n");
|
printf("Exists\n");
|
||||||
if (0 == strncmp( pFile, AI_MEMORYIO_MAGIC_FILENAME, AI_MEMORYIO_MAGIC_FILENAME_LENGTH ) ) {
|
if (0 == strncmp( pFile, AI_MEMORYIO_MAGIC_FILENAME, AI_MEMORYIO_MAGIC_FILENAME_LENGTH ) ) {
|
||||||
|
@ -170,14 +158,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns the directory separator. */
|
/// @brief Returns the directory separator.
|
||||||
char getOsSeparator() const override {
|
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. */
|
/// @brief 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 ( 0 == 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_streams.emplace_back(new MemoryIOStream(buffer, length));
|
created_streams.emplace_back(new MemoryIOStream(buffer, length));
|
||||||
|
@ -187,7 +175,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Closes the given file and releases all resources associated with it. */
|
/// @brief Closes the given file and releases all resources associated with it.
|
||||||
void Close( IOStream* pFile) override {
|
void Close( IOStream* pFile) override {
|
||||||
auto it = std::find(created_streams.begin(), created_streams.end(), pFile);
|
auto it = std::find(created_streams.begin(), created_streams.end(), pFile);
|
||||||
if (it != created_streams.end()) {
|
if (it != created_streams.end()) {
|
||||||
|
@ -199,36 +187,43 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Compare two paths */
|
/// @brief Compare two paths
|
||||||
bool ComparePaths(const char* one, const char* second) const override {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Will push the directory.
|
||||||
bool PushDirectory( const std::string &path ) override {
|
bool PushDirectory( const std::string &path ) override {
|
||||||
return existing_io ? existing_io->PushDirectory(path) : false;
|
return existing_io ? existing_io->PushDirectory(path) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Will return the current directory from the stack top.
|
||||||
const std::string &CurrentDirectory() const override {
|
const std::string &CurrentDirectory() const override {
|
||||||
static std::string empty;
|
static std::string empty;
|
||||||
return existing_io ? existing_io->CurrentDirectory() : empty;
|
return existing_io ? existing_io->CurrentDirectory() : empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Returns the stack size.
|
||||||
size_t StackSize() const override {
|
size_t StackSize() const override {
|
||||||
return existing_io ? existing_io->StackSize() : 0;
|
return existing_io ? existing_io->StackSize() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Will pop the upper directory.
|
||||||
bool PopDirectory() override {
|
bool PopDirectory() override {
|
||||||
return existing_io ? existing_io->PopDirectory() : false;
|
return existing_io ? existing_io->PopDirectory() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Will create the directory.
|
||||||
bool CreateDirectory( const std::string &path ) override {
|
bool CreateDirectory( const std::string &path ) override {
|
||||||
return existing_io ? existing_io->CreateDirectory(path) : false;
|
return existing_io ? existing_io->CreateDirectory(path) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Will change the directory.
|
||||||
bool ChangeDirectory( const std::string &path ) override {
|
bool ChangeDirectory( const std::string &path ) override {
|
||||||
return existing_io ? existing_io->ChangeDirectory(path) : false;
|
return existing_io ? existing_io->ChangeDirectory(path) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Will delete the file.
|
||||||
bool DeleteFile( const std::string &file ) override {
|
bool DeleteFile( const std::string &file ) override {
|
||||||
return existing_io ? existing_io->DeleteFile(file) : false;
|
return existing_io ? existing_io->DeleteFile(file) : false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue