|
// released into the public domain
// by Christopher Diggins 2004
// http://www.cdiggins.com
#ifndef PARSER_INPUT_STREAM_HPP_INCLUDED
#define PARSER_INPUT_STREAM_HPP_INCLUDED
#include <assert.h>
namespace yard
{
template<typename Elem_T, typename Iter_T = Elem_T const*>
struct ParserInputStream
{
typedef Elem_T element_type;
typedef Iter_T iter_type;
ParserInputStream(Iter_T begin, Iter_T end) : mCurPos(begin), mEndPos(end)
{ }
Elem_T GetElem() {
assert(!AtEnd());
return *mCurPos;
}
void GotoNext() {
assert(!AtEnd());
++mCurPos;
}
Iter_T GetPos() {
return mCurPos;
}
void SetPos(Iter_T pos) {
mCurPos = pos;
}
bool AdvancePast(Elem_T elem) {
if (AtEnd()) {
return false;
}
if (GetElem() == elem) {
GotoNext();
return true;
}
return false;
}
bool AtEnd() {
return mCurPos == mEndPos;
}
private:
Iter_T mCurPos;
Iter_T mEndPos;
};
}
#endif // #ifndef PARSER_INPUT_STREAM_HPP_INCLUDED
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here