From e90a7ced80c6a7dbcdc75bf60c65bcc23f727ca2 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Mon, 8 Dec 2014 17:07:34 +0100 Subject: implemented and tested moveCursor function --- src/core/utils/CharReader.hpp | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'src/core/utils/CharReader.hpp') diff --git a/src/core/utils/CharReader.hpp b/src/core/utils/CharReader.hpp index 23e88b7..8d97d39 100644 --- a/src/core/utils/CharReader.hpp +++ b/src/core/utils/CharReader.hpp @@ -195,6 +195,16 @@ private: */ void stream(); + /** + * Moves the given cursor forward. + */ + size_t moveForward(CursorId cursor, size_t relativeOffs); + + /** + * Moves the given cursor backward. + */ + size_t moveBackward(CursorId cursor, size_t relativeOffs); + public: /** * Intializes the Buffer with a reference to a ReadCallback that is used @@ -254,6 +264,19 @@ public: */ void deleteCursor(CursorId cursor); + /** + * Moves a cursor by offs bytes. Note that moving backwards is theoretically + * limited by the LOOKBACK_SIZE of the Buffer, practically it will most likely + * be limited by the REQUEST_SIZE, so you can got at most 64 KiB backwards. + * + * @param cursor is the cursor that should be moved. + * @param relativeOffs is a positive or negative integer number specifying + * the number of bytes the cursor should be moved forward (positive numbers) + * or backwards (negative numbers). + * @return the actual number of bytes the cursor was moved. + */ + ssize_t moveCursor(CursorId cursor, ssize_t relativeOffs); + /** * Returns the current byte offset of the given cursor relative to the * beginning of the stream. @@ -286,20 +309,6 @@ public: * been reached. */ bool read(CursorId cursor, char &c); - -// /** -// * Reads string from the ring buffer from the given cursor. -// * -// * @param cursor specifies the cursor from which the data should be read. -// * The cursor will be advanced by the specified number of bytes (or to the -// * end of the stream). -// * @param res is the vector into which the data should be read. Any already -// * present data will be overridden. -// * @param len is number of bytes that should be read from the buffer. -// * @return true if len bytes were read, false if less the len bytes have -// * been read because the end of the stream has been reached. -// */ -// bool read(CursorId cursor, std::vector &res, size_t len); }; } -- cgit v1.2.3