Skip to content

Commit

Permalink
COMMON: Add constructor to MemoryReadStream for strings
Browse files Browse the repository at this point in the history
Creating a MemoryReadStream around a static string.
  • Loading branch information
DrMcCoy committed Dec 24, 2016
1 parent d07f2cd commit 54c5ddf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/aurora/biffile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void BIFFile::readVarResTable(Common::SeekableReadStream &bif, uint32 offset) {
Common::SeekableReadStream *BIFFile::getResource(uint32 index) const {
const Resource &res = getRes(index);
if (res.size == 0)
return new Common::MemoryReadStream(0, 0);
return new Common::MemoryReadStream(static_cast<const byte *>(0), 0);

_bif->seek(res.offset);

Expand Down
2 changes: 1 addition & 1 deletion src/aurora/bzffile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void BZFFile::readVarResTable(Common::SeekableReadStream &bzf, uint32 offset) {
Common::SeekableReadStream *BZFFile::getResource(uint32 index) const {
const Resource &res = getRes(index);
if ((res.packedSize == 0) || (res.size == 0))
return new Common::MemoryReadStream(0, 0);
return new Common::MemoryReadStream(static_cast<const byte *>(0), 0);

_bzf->seek(res.offset);

Expand Down
8 changes: 8 additions & 0 deletions src/common/memreadstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ class MemoryReadStream : boost::noncopyable, public SeekableReadStream {

}

/** Create a MemoryReadStream around a static string buffer, optionally including the
* terminating \0. Never disposes its memory. */
MemoryReadStream(const char *str, bool useTerminator = false) :
_ptrOrig(reinterpret_cast<const byte *>(str), false), _ptr(reinterpret_cast<const byte *>(str)),
_size(strlen(str) + (useTerminator ? 1 : 0)), _pos(0), _eos(false) {

}

/** Template constructor to create a MemoryReadStream around a static array buffer.
* Never disposes its memory. */
template<size_t N>
Expand Down

0 comments on commit 54c5ddf

Please sign in to comment.