47 #ifndef AI_BLOBIOSYSTEM_H_INCLUDED
48 #define AI_BLOBIOSYSTEM_H_INCLUDED
83 blob->
size = file_size;
92 virtual size_t Read(
void *,
99 virtual size_t Write(
const void *pvBuffer,
103 if (cursor + pSize > cur_size) {
104 Grow(cursor + pSize);
107 memcpy(buffer + cursor, pvBuffer, pSize);
110 file_size = std::max(file_size, cursor);
123 cursor = file_size - pOffset;
134 if (cursor > file_size) {
138 file_size = std::max(cursor, file_size);
159 void Grow(
size_t need = 0) {
166 size_t new_size = std::max(initial, std::max(need, cur_size + (cur_size >> 1)));
168 const uint8_t *
const old = buffer;
169 buffer =
new uint8_t[new_size];
172 memcpy(buffer, old, cur_size);
181 size_t cur_size, file_size, cursor, initial;
183 const std::string file;
184 BlobIOSystem *
const creator;
187 #define AI_BLOBIO_MAGIC "$blobfile"
195 typedef std::pair<std::string, aiExportDataBlob *> BlobEntry;
202 for (BlobEntry &blobby : blobs) {
203 delete blobby.second;
209 const char *GetMagicFileName()
const {
210 return AI_BLOBIO_MAGIC;
217 for (
const BlobEntry &blobby : blobs) {
218 if (blobby.first == AI_BLOBIO_MAGIC) {
219 master = blobby.second;
224 ASSIMP_LOG_ERROR(
"BlobIOSystem: no data written or master file was not closed properly.");
228 master->
name.Set(
"");
231 for (
const BlobEntry &blobby : blobs) {
232 if (blobby.second == master) {
236 cur->
next = blobby.second;
240 const std::string::size_type s = blobby.first.find_first_of(
'.');
241 cur->
name.Set(s == std::string::npos ? blobby.first : blobby.first.substr(s + 1));
251 virtual bool Exists(
const char *pFile)
const {
252 return created.find(std::string(pFile)) != created.end();
263 if (pMode[0] !=
'w') {
267 created.insert(std::string(pFile));
278 void OnDestruct(
const std::string &filename,
BlobIOStream *child) {
282 blobs.push_back(BlobEntry(filename, child->GetBlob()));
286 std::set<std::string> created;
287 std::vector<BlobEntry> blobs;
291 BlobIOStream ::~BlobIOStream() {
292 creator->OnDestruct(file,
this);
Definition: cexport.h:200
aiOrigin
Definition: types.h:426
virtual void Flush()
Flush the contents of the file buffer (for writers) See fflush() for more details.
Definition: BlobIOSystem.h:153
virtual size_t Tell() const
Get the current position of the read/write cursor.
Definition: BlobIOSystem.h:143
@ aiOrigin_SET
Definition: types.h:428
C_STRUCT aiString name
Definition: cexport.h:219
virtual size_t Read(void *, size_t, size_t)
Read from the file.
Definition: BlobIOSystem.h:92
File system wrapper for C++. Inherit this class to supply custom file handling logic to the Import li...
@ aiOrigin_END
Definition: types.h:434
virtual char getOsSeparator() const
Returns the system specific directory separator.
Definition: BlobIOSystem.h:256
virtual IOStream * Open(const char *pFile, const char *pMode)
Open a new file with a given path.
Definition: BlobIOSystem.h:261
aiReturn
Definition: types.h:397
void * data
The data.
Definition: cexport.h:205
virtual void Close(IOStream *pFile)
Closes the given file and releases all resources associated with it.
Definition: BlobIOSystem.h:272
virtual size_t Write(const void *pvBuffer, size_t pSize, size_t pCount)
Write to the file.
Definition: BlobIOSystem.h:99
virtual aiReturn Seek(size_t pOffset, aiOrigin pOrigin)
Set the read/write cursor of the file.
Definition: BlobIOSystem.h:115
Definition: BlobIOSystem.h:64
Defines the C-API for the Assimp export interface.
C_STRUCT aiExportDataBlob * next
Definition: cexport.h:222
Definition: BlobIOSystem.h:192
CPP-API: Interface to the file system.
Definition: IOSystem.hpp:93
File I/O wrappers for C++.
Definition: ai_assert.h:50
size_t size
Size of the data in bytes.
Definition: cexport.h:202
virtual bool Exists(const char *pFile) const
Tests for the existence of a file at the given path.
Definition: BlobIOSystem.h:251
virtual size_t FileSize() const
Returns filesize Returns the filesize.
Definition: BlobIOSystem.h:148
CPP-API: Class to handle file I/O for C++.
Definition: IOStream.hpp:75
@ aiOrigin_CUR
Definition: types.h:431