Refactor code to use Peek instead of Ungetc because due to how unget works in streambuf (no virtual function is called) this causes issues when implementing own streambufs.
MODIFY
src/ldb_eventcommand.cpp
src/ldb_eventcommand.cpp
@@ -141,10 +141,9 @@ void RawStruct<std::vector<RPG::EventCommand> >::ReadLcf(
unsigned long endpos = startpos + length;
for (;;) {
- uint8_t ch;
- stream.Read(ch);
+ uint8_t ch = (uint8_t)stream.Peek();
if (ch == 0) {
- stream.Seek(3, LcfReader::FromCurrent);
+ stream.Seek(4, LcfReader::FromCurrent);
break;
}
@@ -170,7 +169,6 @@ void RawStruct<std::vector<RPG::EventCommand> >::ReadLcf(
break;
}
- stream.Ungetch(ch);
RPG::EventCommand command;
RawStruct<RPG::EventCommand>::ReadLcf(command, stream, 0);
event_commands.push_back(command);

MODIFY
src/reader_lcf.cpp
src/reader_lcf.cpp
@@ -179,13 +179,13 @@ bool LcfReader::Eof() const {
void LcfReader::Seek(size_t pos, SeekMode mode) {
switch (mode) {
case LcfReader::FromStart:
- stream.seekg(pos, std::ios::ios_base::beg);
+ stream.seekg(pos, std::ios_base::beg);
break;
case LcfReader::FromCurrent:
- stream.seekg(pos, std::ios::ios_base::cur);
+ stream.seekg(pos, std::ios_base::cur);
break;
case LcfReader::FromEnd:
- stream.seekg(pos, std::ios::ios_base::end);
+ stream.seekg(pos, std::ios_base::end);
break;
default:
assert(false && "Invalid SeekMode");
@@ -196,8 +196,8 @@ uint32_t LcfReader::Tell() {
return (uint32_t)stream.tellg();
}
-bool LcfReader::Ungetch(uint8_t ch) {
- return stream.putback(ch).good();
+int LcfReader::Peek() {
+ return stream.peek();
}
#ifdef _DEBUG

MODIFY
src/reader_lcf.h
src/reader_lcf.h
@@ -167,13 +167,11 @@ public:
uint32_t Tell();
/**
- * Puts a character (ch) back into the stream.
- * This should usually be the last read one.
+ * Returns the next char in the stream and doesn't advance the position.
*
- * @param ch char that will be readded to the stream.
- * @return true if the operation was successful.
+ * @return next char in the buffer or EOF
*/
- bool Ungetch(uint8_t ch);
+ int Peek();
#ifdef _DEBUG
/**

Refactor code to use Peek instead of Ungetc because due to how unget works in streambuf (no virtual function is called) this causes issues when implementing own streambufs.