From 255bd27d4e26d2e5cef9ad4d57bb9c18bc986c67 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 16 Feb 2012 03:35:41 +0000 Subject: Added MemBuf docs and a new readAll function to the base stream class. More helpers never really hurt. --- src/membuf.h | 7 ++++++- src/stream.cpp | 16 ++++++++++++++++ src/stream.h | 10 ++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/membuf.h b/src/membuf.h index d98a29c..544dc83 100644 --- a/src/membuf.h +++ b/src/membuf.h @@ -17,7 +17,12 @@ namespace Bu { /** - * A memory buffer stream. + * A memory buffer stream. This provides a read/write stream in memory that + * works exactly like a file stream...only in memory. You can seed the + * memory buffer with a Bu::String of your own, or start with an empty one. + * Due to Bu::String using Bu::SharedCore starting with a string will not + * necesarilly cause the MemBuf to make a copy of your memory, but if you're + * sure you're not going to need to change the stream then use StaticMemBuf. *@ingroup Streams */ class MemBuf : public Stream diff --git a/src/stream.cpp b/src/stream.cpp index 028166e..58641cc 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -30,6 +30,22 @@ Bu::String Bu::Stream::readLine() } } +Bu::String Bu::Stream::readAll() +{ + Bu::String sRet; + char buf[4096]; + + while( !isEos() ) + { + int iRead = read( buf, 4096 ); + if( iRead == 0 ) + return sRet; + sRet.append( buf, iRead ); + } + + return sRet; +} + Bu::size Bu::Stream::write( const Bu::String &sBuf ) { return write( sBuf.getStr(), sBuf.getSize() ); diff --git a/src/stream.h b/src/stream.h index fb70f21..b35f6ee 100644 --- a/src/stream.h +++ b/src/stream.h @@ -55,6 +55,16 @@ namespace Bu */ virtual Bu::String readLine(); + /** + * Reads all data from the current position onward until isEos returns + * true and returns it as a Bu::String. This will also return if no + * data is available and the stream is in non-blocking mode. This + * function is intended for very particular circumstances and is often + * not the most efficient way to access the data that you would like. + *@returns The entire stream contents. + */ + virtual Bu::String readAll(); + /** * Write data to the stream. *@param pBuf (const void *) The data to be written. -- cgit v1.2.3