diff options
Diffstat (limited to 'src/stable/membuf.h')
-rw-r--r-- | src/stable/membuf.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/stable/membuf.h b/src/stable/membuf.h new file mode 100644 index 0000000..544dc83 --- /dev/null +++ b/src/stable/membuf.h | |||
@@ -0,0 +1,68 @@ | |||
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_MEM_BUF_H | ||
9 | #define BU_MEM_BUF_H | ||
10 | |||
11 | #include <stdint.h> | ||
12 | |||
13 | #include "bu/config.h" | ||
14 | #include "bu/stream.h" | ||
15 | #include "bu/string.h" | ||
16 | |||
17 | namespace Bu | ||
18 | { | ||
19 | /** | ||
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. | ||
26 | *@ingroup Streams | ||
27 | */ | ||
28 | class MemBuf : public Stream | ||
29 | { | ||
30 | public: | ||
31 | MemBuf(); | ||
32 | MemBuf( const Bu::String &str ); | ||
33 | virtual ~MemBuf(); | ||
34 | |||
35 | virtual void close(); | ||
36 | virtual size read( void *pBuf, size iBytes ); | ||
37 | |||
38 | virtual size write( const void *pBuf, size iBytes ); | ||
39 | using Stream::write; | ||
40 | virtual size tell(); | ||
41 | virtual void seek( size offset ); | ||
42 | virtual void setPos( size pos ); | ||
43 | virtual void setPosEnd( size pos ); | ||
44 | virtual bool isEos(); | ||
45 | virtual bool isOpen(); | ||
46 | virtual void flush(); | ||
47 | virtual bool canRead(); | ||
48 | virtual bool canWrite(); | ||
49 | virtual bool isReadable(); | ||
50 | virtual bool isWritable(); | ||
51 | virtual bool isSeekable(); | ||
52 | virtual bool isBlocking(); | ||
53 | virtual void setBlocking( bool bBlocking=true ); | ||
54 | virtual void setSize( size iSize ); | ||
55 | virtual size getSize() const; | ||
56 | virtual size getBlockSize() const; | ||
57 | virtual Bu::String getLocation() const; | ||
58 | |||
59 | Bu::String &getString(); | ||
60 | void setString( const Bu::String &sNewData ); | ||
61 | |||
62 | private: | ||
63 | Bu::String sBuf; | ||
64 | size nPos; | ||
65 | }; | ||
66 | } | ||
67 | |||
68 | #endif | ||