diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
commit | 469bbcf0701e1eb8a6670c23145b0da87357e178 (patch) | |
tree | b5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/stable/nullstream.h | |
parent | ee1b79396076edc4e30aefb285fada03bb45e80d (diff) | |
download | libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2 libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip |
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/stable/nullstream.h')
-rw-r--r-- | src/stable/nullstream.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/stable/nullstream.h b/src/stable/nullstream.h new file mode 100644 index 0000000..9b75332 --- /dev/null +++ b/src/stable/nullstream.h | |||
@@ -0,0 +1,67 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #ifndef BU_NULL_STREAM_H | ||
9 | #define BU_NULL_STREAM_H | ||
10 | |||
11 | #include "bu/stream.h" | ||
12 | |||
13 | namespace Bu | ||
14 | { | ||
15 | /** | ||
16 | * Works a lot like /dev/null on *nix style systems. This class allows | ||
17 | * infinite reading and writing. All operatorns "succeed" even if they | ||
18 | * don't seem to do anything. This is great for testing writing code or | ||
19 | * doing dry runs. When reading, it will produce NULL bytes, so any | ||
20 | * application that would like the ability to produce null streams as a | ||
21 | * snap-in replacement for any other Bu::Stream, this is the right option. | ||
22 | * | ||
23 | * As an added feature, the NullStream will track how many bytes it was | ||
24 | * asked to read and write, allowing you to use it to determine how many | ||
25 | * bytes a write opretion would use without actually writing anything. | ||
26 | */ | ||
27 | class NullStream : public Bu::Stream | ||
28 | { | ||
29 | public: | ||
30 | NullStream(); | ||
31 | virtual ~NullStream(); | ||
32 | |||
33 | virtual void close(); | ||
34 | virtual Bu::size read( void *pBuf, Bu::size nBytes ); | ||
35 | virtual Bu::String readLine(); | ||
36 | virtual Bu::size write( const void *pBuf, Bu::size nBytes ); | ||
37 | using Bu::Stream::write; | ||
38 | virtual Bu::size tell(); | ||
39 | virtual void seek( Bu::size offset ); | ||
40 | virtual void setPos( Bu::size pos ); | ||
41 | virtual void setPosEnd( Bu::size pos ); | ||
42 | virtual bool isEos(); | ||
43 | virtual bool isOpen(); | ||
44 | virtual void flush(); | ||
45 | virtual bool canRead(); | ||
46 | virtual bool canWrite(); | ||
47 | virtual bool isReadable(); | ||
48 | virtual bool isWritable(); | ||
49 | virtual bool isSeekable(); | ||
50 | virtual bool isBlocking(); | ||
51 | virtual void setBlocking( bool bBlocking=true ); | ||
52 | virtual void setSize( Bu::size iSize ); | ||
53 | |||
54 | virtual size getSize() const; | ||
55 | virtual size getBlockSize() const; | ||
56 | virtual Bu::String getLocation() const; | ||
57 | |||
58 | Bu::size getBytesRead() { return sRead; } | ||
59 | Bu::size getByetsWritten() { return sWrote; } | ||
60 | |||
61 | private: | ||
62 | Bu::size sRead; | ||
63 | Bu::size sWrote; | ||
64 | }; | ||
65 | }; | ||
66 | |||
67 | #endif | ||