aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-08-04 15:17:11 +0000
committerMike Buland <eichlan@xagasoft.com>2010-08-04 15:17:11 +0000
commita83e9babede7ab5bc8e1ac6c7ee3784b91bd8452 (patch)
treee54db7f9a50e7f9924c5a749a586fbf172cb48ce /src
parent819cfbbc5f8caa65575caefb3e602d2d9f7425b3 (diff)
downloadlibbu++-a83e9babede7ab5bc8e1ac6c7ee3784b91bd8452.tar.gz
libbu++-a83e9babede7ab5bc8e1ac6c7ee3784b91bd8452.tar.bz2
libbu++-a83e9babede7ab5bc8e1ac6c7ee3784b91bd8452.tar.xz
libbu++-a83e9babede7ab5bc8e1ac6c7ee3784b91bd8452.zip
Alright, NullStream compiles and works.
Diffstat (limited to 'src')
-rw-r--r--src/nullstream.cpp114
-rw-r--r--src/nullstream.h19
2 files changed, 113 insertions, 20 deletions
diff --git a/src/nullstream.cpp b/src/nullstream.cpp
index 364b58a..40c636c 100644
--- a/src/nullstream.cpp
+++ b/src/nullstream.cpp
@@ -1,6 +1,8 @@
1#include "bu/nullstream.h" 1#include "bu/nullstream.h"
2 2
3Bu::NullStream::NullStream() 3Bu::NullStream::NullStream() :
4 sRead( 0 ),
5 sWrote( 0 )
4{ 6{
5} 7}
6 8
@@ -8,24 +10,96 @@ Bu::NullStream::~NullStream()
8{ 10{
9} 11}
10 12
11void Bu::NullStream::close(); 13void Bu::NullStream::close()
12size_t Bu::NullStream::read( void *pBuf, size_t nBytes ); 14{
13Bu::FString Bu::NullStream::readLine(); 15 sRead = sWrote = 0;
14size_t Bu::NullStream::write( const void *pBuf, size_t nBytes ); 16}
15long Bu::NullStream::tell(); 17
16void Bu::NullStream::seek( long offset ); 18size_t Bu::NullStream::read( void *pBuf, size_t nBytes )
17void Bu::NullStream::setPos( long pos ); 19{
18void Bu::NullStream::setPosEnd( long pos ); 20 memset( pBuf, 0, nBytes );
19bool Bu::NullStream::isEos(); 21 sRead += nBytes;
20bool Bu::NullStream::isOpen(); 22 return nBytes;
21void Bu::NullStream::flush(); 23}
22bool Bu::NullStream::canRead(); 24
23bool Bu::NullStream::canWrite(); 25Bu::FString Bu::NullStream::readLine()
24bool Bu::NullStream::isReadable(); 26{
25bool Bu::NullStream::isWritable(); 27 sRead++;
26bool Bu::NullStream::isSeekable(); 28 return Bu::FString("\0", 1 );
27bool Bu::NullStream::isBlocking(); 29}
28void Bu::NullStream::setBlocking( bool bBlocking=true ); 30
29void Bu::NullStream::setSize( long iSize ); 31size_t Bu::NullStream::write( const void *, size_t nBytes )
32{
33 sWrote += nBytes;
34 return nBytes;
35}
36
37long Bu::NullStream::tell()
38{
39 return sRead + sWrote;
40}
30 41
42void Bu::NullStream::seek( long )
43{
44}
45
46void Bu::NullStream::setPos( long )
47{
48}
49
50void Bu::NullStream::setPosEnd( long )
51{
52}
53
54bool Bu::NullStream::isEos()
55{
56 return false;
57}
58
59bool Bu::NullStream::isOpen()
60{
61 return true;
62}
63
64void Bu::NullStream::flush()
65{
66}
67
68bool Bu::NullStream::canRead()
69{
70 return true;
71}
72
73bool Bu::NullStream::canWrite()
74{
75 return true;
76}
77
78bool Bu::NullStream::isReadable()
79{
80 return true;
81}
82
83bool Bu::NullStream::isWritable()
84{
85 return true;
86}
87
88bool Bu::NullStream::isSeekable()
89{
90 return false;
91}
92
93bool Bu::NullStream::isBlocking()
94{
95 return true;
96}
97
98void Bu::NullStream::setBlocking( bool )
99{
100}
101
102void Bu::NullStream::setSize( long )
103{
104}
31 105
diff --git a/src/nullstream.h b/src/nullstream.h
index 5440af6..1537ffb 100644
--- a/src/nullstream.h
+++ b/src/nullstream.h
@@ -5,6 +5,18 @@
5 5
6namespace Bu 6namespace Bu
7{ 7{
8 /**
9 * Works a lot like /dev/null on *nix style systems. This class allows
10 * infinite reading and writing. All operatorns "succeed" even if they
11 * don't seem to do anything. This is great for testing writing code or
12 * doing dry runs. When reading, it will produce NULL bytes, so any
13 * application that would like the ability to produce null streams as a
14 * snap-in replacement for any other Bu::Stream, this is the right option.
15 *
16 * As an added feature, the NullStream will track how many bytes it was
17 * asked to read and write, allowing you to use it to determine how many
18 * bytes a write opretion would use without actually writing anything.
19 */
8 class NullStream : public Bu::Stream 20 class NullStream : public Bu::Stream
9 { 21 {
10 public: 22 public:
@@ -31,6 +43,13 @@ namespace Bu
31 virtual bool isBlocking(); 43 virtual bool isBlocking();
32 virtual void setBlocking( bool bBlocking=true ); 44 virtual void setBlocking( bool bBlocking=true );
33 virtual void setSize( long iSize ); 45 virtual void setSize( long iSize );
46
47 size_t getBytesRead() { return sRead; }
48 size_t getByetsWritten() { return sWrote; }
49
50 private:
51 size_t sRead;
52 size_t sWrote;
34 }; 53 };
35}; 54};
36 55