aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-02-16 03:35:41 +0000
committerMike Buland <eichlan@xagasoft.com>2012-02-16 03:35:41 +0000
commit255bd27d4e26d2e5cef9ad4d57bb9c18bc986c67 (patch)
tree0d207452a5e819d5ee5710e37ed3943c38fff9bf /src
parent7d7bd049ed6815d3d2bac03331ff56102d224580 (diff)
downloadlibbu++-255bd27d4e26d2e5cef9ad4d57bb9c18bc986c67.tar.gz
libbu++-255bd27d4e26d2e5cef9ad4d57bb9c18bc986c67.tar.bz2
libbu++-255bd27d4e26d2e5cef9ad4d57bb9c18bc986c67.tar.xz
libbu++-255bd27d4e26d2e5cef9ad4d57bb9c18bc986c67.zip
Added MemBuf docs and a new readAll function to the base stream class.
More helpers never really hurt.
Diffstat (limited to 'src')
-rw-r--r--src/membuf.h7
-rw-r--r--src/stream.cpp16
-rw-r--r--src/stream.h10
3 files changed, 32 insertions, 1 deletions
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 @@
17namespace Bu 17namespace Bu
18{ 18{
19 /** 19 /**
20 * A memory buffer stream. 20 * A memory buffer stream. This provides a read/write stream in memory that
21 * works exactly like a file stream...only in memory. You can seed the
22 * memory buffer with a Bu::String of your own, or start with an empty one.
23 * Due to Bu::String using Bu::SharedCore starting with a string will not
24 * necesarilly cause the MemBuf to make a copy of your memory, but if you're
25 * sure you're not going to need to change the stream then use StaticMemBuf.
21 *@ingroup Streams 26 *@ingroup Streams
22 */ 27 */
23 class MemBuf : public Stream 28 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()
30 } 30 }
31} 31}
32 32
33Bu::String Bu::Stream::readAll()
34{
35 Bu::String sRet;
36 char buf[4096];
37
38 while( !isEos() )
39 {
40 int iRead = read( buf, 4096 );
41 if( iRead == 0 )
42 return sRet;
43 sRet.append( buf, iRead );
44 }
45
46 return sRet;
47}
48
33Bu::size Bu::Stream::write( const Bu::String &sBuf ) 49Bu::size Bu::Stream::write( const Bu::String &sBuf )
34{ 50{
35 return write( sBuf.getStr(), sBuf.getSize() ); 51 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
@@ -56,6 +56,16 @@ namespace Bu
56 virtual Bu::String readLine(); 56 virtual Bu::String readLine();
57 57
58 /** 58 /**
59 * Reads all data from the current position onward until isEos returns
60 * true and returns it as a Bu::String. This will also return if no
61 * data is available and the stream is in non-blocking mode. This
62 * function is intended for very particular circumstances and is often
63 * not the most efficient way to access the data that you would like.
64 *@returns The entire stream contents.
65 */
66 virtual Bu::String readAll();
67
68 /**
59 * Write data to the stream. 69 * Write data to the stream.
60 *@param pBuf (const void *) The data to be written. 70 *@param pBuf (const void *) The data to be written.
61 *@param nBytes (size_t) Amount of data to write from pBuf. 71 *@param nBytes (size_t) Amount of data to write from pBuf.