Merge pull request #1799 from mesilliac/streamwriter_improvements

Some StreamWriter improvements / additions.
This commit is contained in:
Kim Kulling 2018-02-17 17:26:26 +01:00 committed by GitHub
commit 0c8f574229
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 59 additions and 1 deletions

View File

@ -58,7 +58,7 @@ namespace Assimp {
// --------------------------------------------------------------------------------------------
/** Wrapper class around IOStream to allow for consistent writing of binary data in both
* little and big endian format. Don't attempt to instance the template directly. Use
* StreamWriterLE to read from a little-endian stream and StreamWriterBE to read from a
* StreamWriterLE to write to a little-endian stream and StreamWriterBE to write to a
* BE stream. Alternatively, there is StreamWriterAny if the endianness of the output
* stream is to be determined at runtime.
*/
@ -108,6 +108,38 @@ public:
stream->Flush();
}
public:
// ---------------------------------------------------------------------
/** Flush the contents of the internal buffer, and the output IOStream */
void Flush()
{
stream->Write(&buffer[0], 1, buffer.size());
stream->Flush();
buffer.clear();
cursor = 0;
}
// ---------------------------------------------------------------------
/** Seek to the given offset / origin in the output IOStream.
*
* Flushes the internal buffer and the output IOStream prior to seeking. */
aiReturn Seek(size_t pOffset, aiOrigin pOrigin=aiOrigin_SET)
{
Flush();
return stream->Seek(pOffset, pOrigin);
}
// ---------------------------------------------------------------------
/** Tell the current position in the output IOStream.
*
* First flushes the internal buffer and the output IOStream. */
size_t Tell()
{
Flush();
return stream->Tell();
}
public:
// ---------------------------------------------------------------------
@ -171,6 +203,32 @@ public:
Put(n);
}
// ---------------------------------------------------------------------
/** Write an aiString to the stream */
void PutString(const aiString& s)
{
// as Put(T f) below
if (cursor + s.length >= buffer.size()) {
buffer.resize(cursor + s.length);
}
void* dest = &buffer[cursor];
::memcpy(dest, s.C_Str(), s.length);
cursor += s.length;
}
// ---------------------------------------------------------------------
/** Write a std::string to the stream */
void PutString(const std::string& s)
{
// as Put(T f) below
if (cursor + s.size() >= buffer.size()) {
buffer.resize(cursor + s.size());
}
void* dest = &buffer[cursor];
::memcpy(dest, s.c_str(), s.size());
cursor += s.size();
}
public:
// ---------------------------------------------------------------------