Skip to content

Commit

Permalink
added StdCharBufStream which reads from a buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Mar 29, 2024
1 parent ad9b49d commit 1696577
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,42 @@ class StdIStream : public simplecpp::TokenList::Stream {
std::istream &istr;
};

class StdCharBufStream : public simplecpp::TokenList::Stream {
public:
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
StdCharBufStream(const unsigned char* str, std::size_t size)
: str(str)
, size(size)
, pos(0)
, lastStatus(0)
{
init();
}

virtual int get() OVERRIDE {
if (pos >= size)
return lastStatus = EOF;
return str[pos++];
}
virtual int peek() OVERRIDE {
if (pos >= size)
return lastStatus = EOF;
return str[pos];
}
virtual void unget() OVERRIDE {
--pos;
}
virtual bool good() OVERRIDE {
return lastStatus != EOF;
}

private:
const unsigned char *str;
const std::size_t size;
std::size_t pos;
int lastStatus;
};

class FileStream : public simplecpp::TokenList::Stream {
public:
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
Expand Down

0 comments on commit 1696577

Please sign in to comment.