diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-01-19 23:02:44 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-01-19 23:02:44 +0000 |
commit | 10c557562e1d67c55314c212371ea9cb7f802863 (patch) | |
tree | 5834f4060874de33df5d0f9ebe115059d2541189 /src/stream.h | |
parent | dfb29c814b9c3327df3ab90e333b43504768e6d6 (diff) | |
download | libbu++-10c557562e1d67c55314c212371ea9cb7f802863.tar.gz libbu++-10c557562e1d67c55314c212371ea9cb7f802863.tar.bz2 libbu++-10c557562e1d67c55314c212371ea9cb7f802863.tar.xz libbu++-10c557562e1d67c55314c212371ea9cb7f802863.zip |
Started work adding more functions to stream, and changing to a new size type.
Diffstat (limited to 'src/stream.h')
-rw-r--r-- | src/stream.h | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/src/stream.h b/src/stream.h index 0ea5560..e7db7af 100644 --- a/src/stream.h +++ b/src/stream.h | |||
@@ -8,6 +8,8 @@ | |||
8 | #ifndef BU_STREAM_H | 8 | #ifndef BU_STREAM_H |
9 | #define BU_STREAM_H | 9 | #define BU_STREAM_H |
10 | 10 | ||
11 | #include "bu/config.h" | ||
12 | |||
11 | #include <stdint.h> | 13 | #include <stdint.h> |
12 | #include <stdio.h> | 14 | #include <stdio.h> |
13 | 15 | ||
@@ -43,7 +45,7 @@ namespace Bu | |||
43 | *@param nBytes (size_t) Max data to read. | 45 | *@param nBytes (size_t) Max data to read. |
44 | *@returns (size_t) Amount of data read. | 46 | *@returns (size_t) Amount of data read. |
45 | */ | 47 | */ |
46 | virtual size_t read( void *pBuf, size_t nBytes ) = 0; | 48 | virtual size read( void *pBuf, size iBytes ) = 0; |
47 | 49 | ||
48 | /** | 50 | /** |
49 | * Attempts to read a complete line from the stream. This will stop | 51 | * Attempts to read a complete line from the stream. This will stop |
@@ -59,33 +61,33 @@ namespace Bu | |||
59 | *@param nBytes (size_t) Amount of data to write from pBuf. | 61 | *@param nBytes (size_t) Amount of data to write from pBuf. |
60 | *@returns (size_t) Amount of data actually written. | 62 | *@returns (size_t) Amount of data actually written. |
61 | */ | 63 | */ |
62 | virtual size_t write( const void *pBuf, size_t nBytes ) = 0; | 64 | virtual size write( const void *pBuf, size iBytes ) = 0; |
63 | 65 | ||
64 | virtual size_t write( const Bu::FString &sBuf ); | 66 | virtual size write( const Bu::FString &sBuf ); |
65 | 67 | ||
66 | /** | 68 | /** |
67 | * Get the current position in the stream. | 69 | * Get the current position in the stream. |
68 | *@returns (long) The current position in the stream. | 70 | *@returns (long) The current position in the stream. |
69 | */ | 71 | */ |
70 | virtual long tell() = 0; | 72 | virtual size tell() = 0; |
71 | 73 | ||
72 | /** | 74 | /** |
73 | * Seek to a position in the stream relative to the current position. | 75 | * Seek to a position in the stream relative to the current position. |
74 | *@param offset (long) Offset from current position to seek to. | 76 | *@param offset (long) Offset from current position to seek to. |
75 | */ | 77 | */ |
76 | virtual void seek( long offset ) = 0; | 78 | virtual void seek( size offset ) = 0; |
77 | 79 | ||
78 | /** | 80 | /** |
79 | * Set position in the stream relative to the start of the stream. | 81 | * Set position in the stream relative to the start of the stream. |
80 | *@param pos (long) The position. | 82 | *@param pos (long) The position. |
81 | */ | 83 | */ |
82 | virtual void setPos( long pos ) = 0; | 84 | virtual void setPos( size pos ) = 0; |
83 | 85 | ||
84 | /** | 86 | /** |
85 | * Set position in the stream relative to the end of the stream. | 87 | * Set position in the stream relative to the end of the stream. |
86 | *@param pos (long) The position. | 88 | *@param pos (long) The position. |
87 | */ | 89 | */ |
88 | virtual void setPosEnd( long pos ) = 0; | 90 | virtual void setPosEnd( size pos ) = 0; |
89 | 91 | ||
90 | /** | 92 | /** |
91 | * Are we at the end of the stream? | 93 | * Are we at the end of the stream? |
@@ -158,10 +160,32 @@ namespace Bu | |||
158 | * removed from the end of the stream, but the content of the added | 160 | * removed from the end of the stream, but the content of the added |
159 | * data is undefined. | 161 | * data is undefined. |
160 | */ | 162 | */ |
161 | virtual void setSize( long iSize ) = 0; | 163 | virtual void setSize( size iSize ) = 0; |
164 | |||
165 | /** | ||
166 | * Returns the size of the stream if the stream can have a size. For | ||
167 | * streams that do not (sockets, pipes, etc.) this should throw an | ||
168 | * unsupported exception. | ||
169 | */ | ||
170 | virtual size getSize() const = 0; | ||
162 | 171 | ||
163 | public: // Filters | 172 | /** |
173 | * Returns the block-size of the stream, if it has one. This should | ||
174 | * throw an unsupported exception. In some cases the block size | ||
175 | * returned will not represent quite the same thing, for example, | ||
176 | * sockets will return their MTU, while files will return the | ||
177 | * filesystem's block size, and memory buffers will throw an exception. | ||
178 | */ | ||
179 | virtual size getBlockSize() const = 0; | ||
164 | 180 | ||
181 | /** | ||
182 | * If possible, this returns a string that can be used to describe how | ||
183 | * to access the open stream. Not all streams support this, such as | ||
184 | * MemBuf, but for files it may give you a path to a file, for a socket | ||
185 | * it may give you an ip address, etc. If it isn't supported, an empty | ||
186 | * string may be returned. | ||
187 | */ | ||
188 | virtual Bu::FString getLocation() const = 0; | ||
165 | 189 | ||
166 | private: | 190 | private: |
167 | 191 | ||