From d84efdc312a9c5d0b6757c826810809a8e78f1e2 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Wed, 10 Dec 2014 02:41:16 +0100 Subject: copied old BufferedCharReader tests to CharReaderTest, fixed some bugs and optimized CharReader code --- src/core/utils/CharReader.hpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/core/utils/CharReader.hpp') diff --git a/src/core/utils/CharReader.hpp b/src/core/utils/CharReader.hpp index a48f5ad..3d4c894 100644 --- a/src/core/utils/CharReader.hpp +++ b/src/core/utils/CharReader.hpp @@ -377,7 +377,7 @@ protected: * * @param cursor is the underlying cursor in the Buffer instance. */ - Cursor(Buffer::CursorId cursor, size_t line = 1, size_t column = 1) + Cursor(Buffer::CursorId cursor, size_t line, size_t column) : cursor(cursor), line(line), column(column), @@ -432,6 +432,12 @@ protected: */ Cursor peekCursor; + /** + * Set to true as long the underlying Buffer cursor is at the same position + * for the read and the peek cursor. + */ + bool coherent; + /** * Protected constructor of the CharReader base class. Creates new read * and peek cursors for the given buffer. @@ -439,7 +445,7 @@ protected: * @param buffer is a reference to the underlying Buffer class responsible * for allowing to read from a single input stream from multiple locations. */ - CharReader(std::shared_ptr buffer); + CharReader(std::shared_ptr buffer, size_t line, size_t column); public: /** @@ -538,14 +544,14 @@ public: * * @return the current line number. */ - int getLine() const { return readCursor.line; } + size_t getLine() const { return readCursor.line; } /** * Returns the current column (starting with one). * * @return the current column number. */ - int getColumn() const { return readCursor.column; } + size_t getColumn() const { return readCursor.column; } }; /** @@ -570,10 +576,16 @@ private: /** * Constructor of the CharReaderFork class. + * + * @param buffer is a reference at the parent Buffer instance. + * @param parentPeekCursor is a reference at the parent read cursor. + * @param parentPeekCursor is a reference at the parent peek cursor. + * @param coherent specifies whether the char reader cursors are initialized + * coherently. */ CharReaderFork(std::shared_ptr buffer, CharReader::Cursor &parentReadCursor, - CharReader::Cursor &parentPeekCursor); + CharReader::Cursor &parentPeekCursor, bool coherent); public: /** -- cgit v1.2.3