@@ -7,14 +7,21 @@ * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ +#import "OFObject.h" + /** - * The OFStream protocol provides functions to read from and write to streams. + * The OFStream class provides a base class for different types of streams. */ -@protocol OFStream +@interface OFStream: OFObject +{ + char *cache; + size_t cache_len; +} + /** * Reads from the stream into a buffer. * * \param buf The buffer into which the data is read * \param size The size of the data that should be read. @@ -22,10 +29,20 @@ * \return The number of bytes read */ - (size_t)readNBytes: (size_t)size intoBuffer: (char*)buf; +/** + * Read until a newline or \0 occurs. + * + * If you want to use readNBytes afterwards again, you have to clear the cache + * before and optionally get the cache before clearing it! + * + * \return The line that was read. Use freeMem: to free it! + */ +- (char*)readLine; + /** * Writes from a buffer into the stream. * * \param buf The buffer from which the data is written to the stream * \param size The size of the data that should be written @@ -40,10 +57,24 @@ * \param str The C string from which the data is written to the stream * \return The number of bytes written */ - (size_t)writeCString: (const char*)str; +/** + * Sets a specified pointer to the cache and returns the length of the cache. + * + * \param ptr A pointer to a pointer. It will be set to the cache. + * If it is NULL, only the number of bytes in the cache is returned. + * \return The number of bytes in the cache. + */ +- (size_t)getCache: (char**)ptr; + +/** + * Clears the cache. + */ +- clearCache; + /** * Closes the stream. */ - close; @end