aboutsummaryrefslogtreecommitdiff
path: root/src/nullstream.h
blob: 8c1f744d5f1b02457223479a3d27adc20da7c27e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef BU_NULL_STREAM_H
#define BU_NULL_STREAM_H

#include "bu/stream.h"

namespace Bu
{
	/**
	 * Works a lot like /dev/null on *nix style systems.  This class allows
	 * infinite reading and writing.  All operatorns "succeed" even if they
	 * don't seem to do anything.  This is great for testing writing code or
	 * doing dry runs.  When reading, it will produce NULL bytes, so any
	 * application that would like the ability to produce null streams as a
	 * snap-in replacement for any other Bu::Stream, this is the right option.
	 *
	 * As an added feature, the NullStream will track how many bytes it was
	 * asked to read and write, allowing you to use it to determine how many
	 * bytes a write opretion would use without actually writing anything.
	 */
	class NullStream : public Bu::Stream
	{
	public:
		NullStream();
		virtual ~NullStream();

		virtual void close();
		virtual size_t read( void *pBuf, size_t nBytes );
		virtual Bu::String readLine();
		virtual size_t write( const void *pBuf, size_t nBytes );
		using Bu::Stream::write;
		virtual long tell();
		virtual void seek( long offset );
		virtual void setPos( long pos );
		virtual void setPosEnd( long pos );
		virtual bool isEos();
		virtual bool isOpen();
		virtual void flush();
		virtual bool canRead();
		virtual bool canWrite();
		virtual bool isReadable();
		virtual bool isWritable();
		virtual bool isSeekable();
		virtual bool isBlocking();
		virtual void setBlocking( bool bBlocking=true );
		virtual void setSize( long iSize );

		size_t getBytesRead() { return sRead; }
		size_t getByetsWritten() { return sWrote; }

	private:
		size_t sRead;
		size_t sWrote;
	};
};

#endif