diff options
Diffstat (limited to '')
| -rw-r--r-- | src/stable/stream.h | 366 |
1 files changed, 183 insertions, 183 deletions
diff --git a/src/stable/stream.h b/src/stable/stream.h index 21e090e..a76e5fd 100644 --- a/src/stable/stream.h +++ b/src/stable/stream.h | |||
| @@ -17,189 +17,189 @@ | |||
| 17 | 17 | ||
| 18 | namespace Bu | 18 | namespace Bu |
| 19 | { | 19 | { |
| 20 | /** | 20 | /** |
| 21 | * The basis for a completely general data transport mechanism. Anything | 21 | * The basis for a completely general data transport mechanism. Anything |
| 22 | * that inherits from this should provide at least the basic read and/or | 22 | * that inherits from this should provide at least the basic read and/or |
| 23 | * write functions, and very probably the close function. Any functions | 23 | * write functions, and very probably the close function. Any functions |
| 24 | * that aren't supported should throw an exception if called. | 24 | * that aren't supported should throw an exception if called. |
| 25 | * | 25 | * |
| 26 | * The constructor of a child class should pretty much universally be used | 26 | * The constructor of a child class should pretty much universally be used |
| 27 | * to open the stream. I can't think of anything that should require an | 27 | * to open the stream. I can't think of anything that should require an |
| 28 | * exception. | 28 | * exception. |
| 29 | *@ingroup Streams | 29 | *@ingroup Streams |
| 30 | */ | 30 | */ |
| 31 | class Stream | 31 | class Stream |
| 32 | { | 32 | { |
| 33 | public: | 33 | public: |
| 34 | Stream(); | 34 | Stream(); |
| 35 | virtual ~Stream(); | 35 | virtual ~Stream(); |
| 36 | 36 | ||
| 37 | /** | 37 | /** |
| 38 | * Close the stream. | 38 | * Close the stream. |
| 39 | */ | 39 | */ |
| 40 | virtual void close() = 0; | 40 | virtual void close() = 0; |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| 43 | * Read data from the stream into a buffer. | 43 | * Read data from the stream into a buffer. |
| 44 | *@param pBuf (void *) Buffer which will be filled. | 44 | *@param pBuf (void *) Buffer which will be filled. |
| 45 | *@param nBytes (size_t) Max data to read. | 45 | *@param nBytes (size_t) Max data to read. |
| 46 | *@returns (size_t) Amount of data read. | 46 | *@returns (size_t) Amount of data read. |
| 47 | */ | 47 | */ |
| 48 | virtual size read( void *pBuf, size iBytes ) = 0; | 48 | virtual size read( void *pBuf, size iBytes ) = 0; |
| 49 | 49 | ||
| 50 | /** | 50 | /** |
| 51 | * 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 |
| 52 | * reading when it has reached the end of the stream, or runs out of | 52 | * reading when it has reached the end of the stream, or runs out of |
| 53 | * data in a non-blocking stream. | 53 | * data in a non-blocking stream. |
| 54 | *@returns The line read, not including newline character. | 54 | *@returns The line read, not including newline character. |
| 55 | */ | 55 | */ |
| 56 | virtual Bu::String readLine(); | 56 | virtual Bu::String readLine(); |
| 57 | 57 | ||
| 58 | /** | 58 | /** |
| 59 | * Reads all data from the current position onward until isEos returns | 59 | * Reads all data from the current position onward until isEos returns |
| 60 | * true and returns it as a Bu::String. This will also return if no | 60 | * true and returns it as a Bu::String. This will also return if no |
| 61 | * data is available and the stream is in non-blocking mode. This | 61 | * data is available and the stream is in non-blocking mode. This |
| 62 | * function is intended for very particular circumstances and is often | 62 | * function is intended for very particular circumstances and is often |
| 63 | * not the most efficient way to access the data that you would like. | 63 | * not the most efficient way to access the data that you would like. |
| 64 | *@returns The entire stream contents. | 64 | *@returns The entire stream contents. |
| 65 | */ | 65 | */ |
| 66 | virtual Bu::String readAll(); | 66 | virtual Bu::String readAll(); |
| 67 | 67 | ||
| 68 | /** | 68 | /** |
| 69 | * Write data to the stream. | 69 | * Write data to the stream. |
| 70 | *@param pBuf (const void *) The data to be written. | 70 | *@param pBuf (const void *) The data to be written. |
| 71 | *@param nBytes (size_t) Amount of data to write from pBuf. | 71 | *@param nBytes (size_t) Amount of data to write from pBuf. |
| 72 | *@returns (size_t) Amount of data actually written. | 72 | *@returns (size_t) Amount of data actually written. |
| 73 | */ | 73 | */ |
| 74 | virtual size write( const void *pBuf, size iBytes ) = 0; | 74 | virtual size write( const void *pBuf, size iBytes ) = 0; |
| 75 | 75 | ||
| 76 | virtual size write( const Bu::String &sBuf ); | 76 | virtual size write( const Bu::String &sBuf ); |
| 77 | 77 | ||
| 78 | /** | 78 | /** |
| 79 | * Get the current position in the stream. | 79 | * Get the current position in the stream. |
| 80 | *@returns (long) The current position in the stream. | 80 | *@returns (long) The current position in the stream. |
| 81 | */ | 81 | */ |
| 82 | virtual size tell() = 0; | 82 | virtual size tell() = 0; |
| 83 | 83 | ||
| 84 | /** | 84 | /** |
| 85 | * Seek to a position in the stream relative to the current position. | 85 | * Seek to a position in the stream relative to the current position. |
| 86 | *@param offset (long) Offset from current position to seek to. | 86 | *@param offset (long) Offset from current position to seek to. |
| 87 | */ | 87 | */ |
| 88 | virtual void seek( size offset ) = 0; | 88 | virtual void seek( size offset ) = 0; |
| 89 | 89 | ||
| 90 | /** | 90 | /** |
| 91 | * Set position in the stream relative to the start of the stream. | 91 | * Set position in the stream relative to the start of the stream. |
| 92 | *@param pos (long) The position. | 92 | *@param pos (long) The position. |
| 93 | */ | 93 | */ |
| 94 | virtual void setPos( size pos ) = 0; | 94 | virtual void setPos( size pos ) = 0; |
| 95 | 95 | ||
| 96 | /** | 96 | /** |
| 97 | * Set position in the stream relative to the end of the stream. | 97 | * Set position in the stream relative to the end of the stream. |
| 98 | *@param pos (long) The position. | 98 | *@param pos (long) The position. |
| 99 | */ | 99 | */ |
| 100 | virtual void setPosEnd( size pos ) = 0; | 100 | virtual void setPosEnd( size pos ) = 0; |
| 101 | 101 | ||
| 102 | /** | 102 | /** |
| 103 | * Are we at the end of the stream? | 103 | * Are we at the end of the stream? |
| 104 | *@returns (bool) Are we at the end of the stream? | 104 | *@returns (bool) Are we at the end of the stream? |
| 105 | */ | 105 | */ |
| 106 | virtual bool isEos() = 0; | 106 | virtual bool isEos() = 0; |
| 107 | 107 | ||
| 108 | /** | 108 | /** |
| 109 | * Is the stream open? | 109 | * Is the stream open? |
| 110 | *@returns (bool) Is the stream open? | 110 | *@returns (bool) Is the stream open? |
| 111 | */ | 111 | */ |
| 112 | virtual bool isOpen() = 0; | 112 | virtual bool isOpen() = 0; |
| 113 | 113 | ||
| 114 | /** | 114 | /** |
| 115 | * Flush any data still held in buffers. | 115 | * Flush any data still held in buffers. |
| 116 | */ | 116 | */ |
| 117 | virtual void flush() = 0; | 117 | virtual void flush() = 0; |
| 118 | 118 | ||
| 119 | /** | 119 | /** |
| 120 | * In non-blocking streams this indicates if a read operation will | 120 | * In non-blocking streams this indicates if a read operation will |
| 121 | * return data at the moment or not. In blocking streams this should | 121 | * return data at the moment or not. In blocking streams this should |
| 122 | * return the same value as isEos(). | 122 | * return the same value as isEos(). |
| 123 | */ | 123 | */ |
| 124 | virtual bool canRead() = 0; | 124 | virtual bool canRead() = 0; |
| 125 | 125 | ||
| 126 | /** | 126 | /** |
| 127 | * In non-blocking streams this indicates if a write operation will | 127 | * In non-blocking streams this indicates if a write operation will |
| 128 | * actually write one or more bytes. In some cases writing is not | 128 | * actually write one or more bytes. In some cases writing is not |
| 129 | * allowed (e.g. internal buffers are full) temporarilly. In blocking | 129 | * allowed (e.g. internal buffers are full) temporarilly. In blocking |
| 130 | * streams this should return the same value as isWritable. | 130 | * streams this should return the same value as isWritable. |
| 131 | */ | 131 | */ |
| 132 | virtual bool canWrite() = 0; | 132 | virtual bool canWrite() = 0; |
| 133 | 133 | ||
| 134 | /** | 134 | /** |
| 135 | * Indicates if the stream is capable of read operations. This does not | 135 | * Indicates if the stream is capable of read operations. This does not |
| 136 | * indicate if such operations will return useful data, see canRead for | 136 | * indicate if such operations will return useful data, see canRead for |
| 137 | * that. | 137 | * that. |
| 138 | */ | 138 | */ |
| 139 | virtual bool isReadable() = 0; | 139 | virtual bool isReadable() = 0; |
| 140 | 140 | ||
| 141 | /** | 141 | /** |
| 142 | * Indicates if the stream is capable of write operations. This does | 142 | * Indicates if the stream is capable of write operations. This does |
| 143 | * not indicate if such operations will succeed or fail, see canWrite | 143 | * not indicate if such operations will succeed or fail, see canWrite |
| 144 | * for that. | 144 | * for that. |
| 145 | */ | 145 | */ |
| 146 | virtual bool isWritable() = 0; | 146 | virtual bool isWritable() = 0; |
| 147 | 147 | ||
| 148 | /** | 148 | /** |
| 149 | * Indicates if the stream is capable of seek operations. This is | 149 | * Indicates if the stream is capable of seek operations. This is |
| 150 | * generally false for non-blocking streams. Some buffered streams may | 150 | * generally false for non-blocking streams. Some buffered streams may |
| 151 | * support limited in-buffer seeking. | 151 | * support limited in-buffer seeking. |
| 152 | */ | 152 | */ |
| 153 | virtual bool isSeekable() = 0; | 153 | virtual bool isSeekable() = 0; |
| 154 | 154 | ||
| 155 | /** | 155 | /** |
| 156 | * Are we currently set to block mode? | 156 | * Are we currently set to block mode? |
| 157 | *@returns (bool) | 157 | *@returns (bool) |
| 158 | */ | 158 | */ |
| 159 | virtual bool isBlocking() = 0; | 159 | virtual bool isBlocking() = 0; |
| 160 | 160 | ||
| 161 | /** | 161 | /** |
| 162 | * Set stream to blocking or non-blocking mode. | 162 | * Set stream to blocking or non-blocking mode. |
| 163 | *@param bBlocking (bool) Whether we should block or not. | 163 | *@param bBlocking (bool) Whether we should block or not. |
| 164 | */ | 164 | */ |
| 165 | virtual void setBlocking( bool bBlocking=true ) = 0; | 165 | virtual void setBlocking( bool bBlocking=true ) = 0; |
| 166 | 166 | ||
| 167 | /** | 167 | /** |
| 168 | * Set the size of the stream, this does not apply to many types of | 168 | * Set the size of the stream, this does not apply to many types of |
| 169 | * streams. For those that it does apply to, data will be added or | 169 | * streams. For those that it does apply to, data will be added or |
| 170 | * removed from the end of the stream, but the content of the added | 170 | * removed from the end of the stream, but the content of the added |
| 171 | * data is undefined. | 171 | * data is undefined. |
| 172 | */ | 172 | */ |
| 173 | virtual void setSize( size iSize ) = 0; | 173 | virtual void setSize( size iSize ) = 0; |
| 174 | 174 | ||
| 175 | /** | 175 | /** |
| 176 | * Returns the size of the stream if the stream can have a size. For | 176 | * Returns the size of the stream if the stream can have a size. For |
| 177 | * streams that do not (sockets, pipes, etc.) this should throw an | 177 | * streams that do not (sockets, pipes, etc.) this should throw an |
| 178 | * unsupported exception. | 178 | * unsupported exception. |
| 179 | */ | 179 | */ |
| 180 | virtual size getSize() const = 0; | 180 | virtual size getSize() const = 0; |
| 181 | 181 | ||
| 182 | /** | 182 | /** |
| 183 | * Returns the block-size of the stream, if it has one. This should | 183 | * Returns the block-size of the stream, if it has one. This should |
| 184 | * throw an unsupported exception. In some cases the block size | 184 | * throw an unsupported exception. In some cases the block size |
| 185 | * returned will not represent quite the same thing, for example, | 185 | * returned will not represent quite the same thing, for example, |
| 186 | * sockets will return their MTU, while files will return the | 186 | * sockets will return their MTU, while files will return the |
| 187 | * filesystem's block size, and memory buffers will throw an exception. | 187 | * filesystem's block size, and memory buffers will throw an exception. |
| 188 | */ | 188 | */ |
| 189 | virtual size getBlockSize() const = 0; | 189 | virtual size getBlockSize() const = 0; |
| 190 | 190 | ||
| 191 | /** | 191 | /** |
| 192 | * If possible, this returns a string that can be used to describe how | 192 | * If possible, this returns a string that can be used to describe how |
| 193 | * to access the open stream. Not all streams support this, such as | 193 | * to access the open stream. Not all streams support this, such as |
| 194 | * MemBuf, but for files it may give you a path to a file, for a socket | 194 | * MemBuf, but for files it may give you a path to a file, for a socket |
| 195 | * it may give you an ip address, etc. If it isn't supported, an empty | 195 | * it may give you an ip address, etc. If it isn't supported, an empty |
| 196 | * string may be returned. | 196 | * string may be returned. |
| 197 | */ | 197 | */ |
| 198 | virtual Bu::String getLocation() const = 0; | 198 | virtual Bu::String getLocation() const = 0; |
| 199 | 199 | ||
| 200 | private: | 200 | private: |
| 201 | 201 | ||
| 202 | }; | 202 | }; |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | #endif | 205 | #endif |
