Go to the documentation of this file.
46 #ifndef AI_MEMORYIOSTREAM_H_INC
47 #define AI_MEMORYIOSTREAM_H_INC
50 # pragma GCC system_header
55 #include <assimp/ai_assert.h>
61 #define AI_MEMORYIO_MAGIC_FILENAME "$$$___magic___$$$"
62 #define AI_MEMORYIO_MAGIC_FILENAME_LENGTH 17
85 size_t Read(
void* pvBuffer,
size_t pSize,
size_t pCount) {
86 ai_assert(
nullptr != pvBuffer);
87 ai_assert(0 != pSize);
89 const size_t cnt = std::min( pCount, (length-pos) / pSize);
90 const size_t ofs = pSize * cnt;
92 ::memcpy(pvBuffer,buffer+pos,ofs);
100 size_t Write(
const void* ,
size_t ,
size_t ) {
109 if (pOffset > length) {
114 if (pOffset > length) {
117 pos = length-pOffset;
119 if (pOffset+pos > length) {
146 const uint8_t* buffer;
160 , created_streams() {
170 bool Exists(
const char* pFile)
const override {
171 if (0 == strncmp( pFile, AI_MEMORYIO_MAGIC_FILENAME, AI_MEMORYIO_MAGIC_FILENAME_LENGTH ) ) {
174 return existing_io ? existing_io->
Exists(pFile) :
false;
187 if ( 0 == strncmp( pFile, AI_MEMORYIO_MAGIC_FILENAME, AI_MEMORYIO_MAGIC_FILENAME_LENGTH ) ) {
189 return created_streams.back();
191 return existing_io ? existing_io->
Open(pFile, pMode) : NULL;
197 auto it = std::find(created_streams.begin(), created_streams.end(), pFile);
198 if (it != created_streams.end()) {
200 created_streams.erase(it);
201 }
else if (existing_io) {
202 existing_io->
Close(pFile);
208 bool ComparePaths(
const char* one,
const char* second)
const override {
209 return existing_io ? existing_io->
ComparePaths(one, second) :
false;
213 return existing_io ? existing_io->
PushDirectory(path) :
false;
217 static std::string empty;
222 return existing_io ? existing_io->
StackSize() : 0;
226 return existing_io ? existing_io->
PopDirectory() :
false;
237 bool DeleteFile(
const std::string &file )
override {
238 return existing_io ? existing_io->DeleteFile(file) :
false;
242 const uint8_t* buffer;
245 std::vector<IOStream*> created_streams;
size_t Read(void *pvBuffer, size_t pSize, size_t pCount)
Read from the file.
Definition: MemoryIOWrapper.h:85
bool ChangeDirectory(const std::string &path) override
Will change the current directory to the given path.
Definition: MemoryIOWrapper.h:233
aiOrigin
Definition: types.h:426
bool CreateDirectory(const std::string &path) override
CReates an new directory at the given path.
Definition: MemoryIOWrapper.h:229
virtual bool ChangeDirectory(const std::string &path)
Will change the current directory to the given path.
Definition: IOSystem.hpp:337
@ aiOrigin_SET
Definition: types.h:428
virtual bool CreateDirectory(const std::string &path)
CReates an new directory at the given path.
Definition: IOSystem.hpp:323
File system wrapper for C++. Inherit this class to supply custom file handling logic to the Import li...
IOSystem() AI_NO_EXCEPT
Default constructor.
Definition: IOSystem.hpp:237
~MemoryIOSystem()
Definition: MemoryIOWrapper.h:165
MemoryIOSystem(const uint8_t *buff, size_t len, IOSystem *io)
Definition: MemoryIOWrapper.h:156
virtual size_t StackSize() const
Returns the number of directories stored on the stack.
Definition: IOSystem.hpp:305
Definition: MemoryIOWrapper.h:153
@ aiOrigin_END
Definition: types.h:434
bool PushDirectory(const std::string &path) override
Pushes a new directory onto the directory stack.
Definition: MemoryIOWrapper.h:212
aiReturn
Definition: types.h:397
bool ComparePaths(const char *one, const char *second) const override
Definition: MemoryIOWrapper.h:208
virtual bool ComparePaths(const char *one, const char *second) const
Compares two paths and check whether the point to identical files.
size_t FileSize() const
Returns filesize Returns the filesize.
Definition: MemoryIOWrapper.h:135
IOStream * Open(const char *pFile, const char *pMode="rb") override
Definition: MemoryIOWrapper.h:186
size_t Tell() const
Get the current position of the read/write cursor.
Definition: MemoryIOWrapper.h:129
virtual bool PushDirectory(const std::string &path)
Pushes a new directory onto the directory stack.
Definition: IOSystem.hpp:283
const std::string & CurrentDirectory() const override
Returns the top directory from the stack.
Definition: MemoryIOWrapper.h:216
virtual char getOsSeparator() const =0
Returns the system specific directory separator.
virtual bool PopDirectory()
Pops the top directory from the stack.
Definition: IOSystem.hpp:311
bool Exists(const char *pFile) const override
Definition: MemoryIOWrapper.h:170
Definition: MemoryIOWrapper.h:67
CPP-API: Interface to the file system.
Definition: IOSystem.hpp:93
aiReturn Seek(size_t pOffset, aiOrigin pOrigin)
Set the read/write cursor of the file.
Definition: MemoryIOWrapper.h:107
bool PopDirectory() override
Pops the top directory from the stack.
Definition: MemoryIOWrapper.h:225
void Flush()
Flush the contents of the file buffer (for writers) See fflush() for more details.
Definition: MemoryIOWrapper.h:141
size_t StackSize() const override
Returns the number of directories stored on the stack.
Definition: MemoryIOWrapper.h:221
File I/O wrappers for C++.
void Close(IOStream *pFile) override
Definition: MemoryIOWrapper.h:196
virtual const std::string & CurrentDirectory() const
Returns the top directory from the stack.
Definition: IOSystem.hpp:295
Definition: ai_assert.h:50
size_t Write(const void *, size_t, size_t)
Write to the file.
Definition: MemoryIOWrapper.h:100
virtual void Close(IOStream *pFile)=0
Closes the given file and releases all resources associated with it.
virtual IOStream * Open(const char *pFile, const char *pMode="rb")=0
Open a new file with a given path.
char getOsSeparator() const override
Definition: MemoryIOWrapper.h:179
AI_FORCE_INLINE bool Exists(const std::string &pFile) const
For backward compatibility.
Definition: IOSystem.hpp:265
CPP-API: Class to handle file I/O for C++.
Definition: IOStream.hpp:75