src/cx/buffer.h

changeset 500
eb9e7bd40a8e
parent 489
af6be1e123aa
child 501
9a08f5e515cc
equal deleted inserted replaced
499:3dc9075df822 500:eb9e7bd40a8e
98 } cx_buffer_s; 98 } cx_buffer_s;
99 99
100 /** 100 /**
101 * UCX buffer. 101 * UCX buffer.
102 */ 102 */
103 typedef cx_buffer_s *CxBuffer; 103 typedef cx_buffer_s CxBuffer;
104 104
105 /** 105 /**
106 * Creates a new buffer. 106 * Creates a new buffer.
107 * 107 *
108 * \note You may provide \c NULL as argument for \p space. 108 * \note You may provide \c NULL as argument for \p space.
113 * new memory 113 * new memory
114 * @param capacity the capacity of the buffer 114 * @param capacity the capacity of the buffer
115 * @param flags buffer features (see cx_buffer_s.flags) 115 * @param flags buffer features (see cx_buffer_s.flags)
116 * @return the new buffer 116 * @return the new buffer
117 */ 117 */
118 CxBuffer cxBufferCreate( 118 CxBuffer *cxBufferCreate(
119 void *space, 119 void *space,
120 size_t capacity, 120 size_t capacity,
121 int flags 121 int flags
122 ); 122 );
123 123
127 * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, the contents of the buffer 127 * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, the contents of the buffer
128 * are also freed. 128 * are also freed.
129 * 129 *
130 * @param buffer the buffer to destroy 130 * @param buffer the buffer to destroy
131 */ 131 */
132 void cxBufferDestroy(CxBuffer buffer); 132 void cxBufferDestroy(CxBuffer *buffer);
133 133
134 /** 134 /**
135 * Creates a new buffer and fills it with content copied from another buffer. 135 * Creates a new buffer and fills it with content copied from another buffer.
136 * 136 *
137 * \note The #CX_BUFFER_FREE_CONTENTS feature is enforced for the new buffer. 137 * \note The #CX_BUFFER_FREE_CONTENTS feature is enforced for the new buffer.
140 * @param start the start position of extraction 140 * @param start the start position of extraction
141 * @param length the count of bytes to extract (must not be zero) 141 * @param length the count of bytes to extract (must not be zero)
142 * @param flags features for the new buffer (#CX_BUFFER_FREE_CONTENTS will always be enabled) 142 * @param flags features for the new buffer (#CX_BUFFER_FREE_CONTENTS will always be enabled)
143 * @return a new buffer containing the extraction 143 * @return a new buffer containing the extraction
144 */ 144 */
145 CxBuffer cxBufferExtract( 145 CxBuffer *cxBufferExtract(
146 CxBuffer src, 146 CxBuffer *src,
147 size_t start, 147 size_t start,
148 size_t length, 148 size_t length,
149 int flags 149 int flags
150 ); 150 );
151 151
191 * @param buffer the buffer 191 * @param buffer the buffer
192 * @param shift the shift offset (negative means left shift) 192 * @param shift the shift offset (negative means left shift)
193 * @return 0 on success, non-zero if a required auto-extension fails 193 * @return 0 on success, non-zero if a required auto-extension fails
194 */ 194 */
195 int cxBufferShift( 195 int cxBufferShift(
196 CxBuffer buffer, 196 CxBuffer *buffer,
197 off_t shift 197 off_t shift
198 ); 198 );
199 199
200 /** 200 /**
201 * Shifts the buffer to the right. 201 * Shifts the buffer to the right.
205 * @param shift the shift offset 205 * @param shift the shift offset
206 * @return 0 on success, non-zero if a required auto-extension fails 206 * @return 0 on success, non-zero if a required auto-extension fails
207 * @see cxBufferShift() 207 * @see cxBufferShift()
208 */ 208 */
209 int cxBufferShiftRight( 209 int cxBufferShiftRight(
210 CxBuffer buffer, 210 CxBuffer *buffer,
211 size_t shift 211 size_t shift
212 ); 212 );
213 213
214 /** 214 /**
215 * Shifts the buffer to the left. 215 * Shifts the buffer to the left.
222 * @param shift the positive shift offset 222 * @param shift the positive shift offset
223 * @return always zero 223 * @return always zero
224 * @see cxBufferShift() 224 * @see cxBufferShift()
225 */ 225 */
226 int cxBufferShiftLeft( 226 int cxBufferShiftLeft(
227 CxBuffer buffer, 227 CxBuffer *buffer,
228 size_t shift 228 size_t shift
229 ); 229 );
230 230
231 231
232 /** 232 /**
247 * @param whence one of \c SEEK_SET, \c SEEK_CUR or \c SEEK_END 247 * @param whence one of \c SEEK_SET, \c SEEK_CUR or \c SEEK_END
248 * @return 0 on success, non-zero if the position is invalid 248 * @return 0 on success, non-zero if the position is invalid
249 * 249 *
250 */ 250 */
251 int cxBufferSeek( 251 int cxBufferSeek(
252 CxBuffer buffer, 252 CxBuffer *buffer,
253 off_t offset, 253 off_t offset,
254 int whence 254 int whence
255 ); 255 );
256 256
257 /** 257 /**
269 * 269 *
270 * @param buffer the buffer to test 270 * @param buffer the buffer to test
271 * @return non-zero, if the current buffer position has exceeded the last 271 * @return non-zero, if the current buffer position has exceeded the last
272 * available byte of the buffer. 272 * available byte of the buffer.
273 */ 273 */
274 int cxBufferEof(CxBuffer buffer); 274 int cxBufferEof(CxBuffer *buffer);
275 275
276 276
277 /** 277 /**
278 * Ensures that the buffer has a minimum capacity. 278 * Ensures that the buffer has a minimum capacity.
279 * 279 *
282 * @param buffer the buffer 282 * @param buffer the buffer
283 * @param capacity the minimum required capacity for this buffer 283 * @param capacity the minimum required capacity for this buffer
284 * @return 0 on success or a non-zero value on failure 284 * @return 0 on success or a non-zero value on failure
285 */ 285 */
286 int cxBufferMinimumCapacity( 286 int cxBufferMinimumCapacity(
287 CxBuffer buffer, 287 CxBuffer *buffer,
288 size_t capacity 288 size_t capacity
289 ); 289 );
290 290
291 /** 291 /**
292 * Writes data to a CxBuffer. 292 * Writes data to a CxBuffer.
303 */ 303 */
304 size_t cxBufferWrite( 304 size_t cxBufferWrite(
305 void const *ptr, 305 void const *ptr,
306 size_t size, 306 size_t size,
307 size_t nitems, 307 size_t nitems,
308 CxBuffer buffer 308 CxBuffer *buffer
309 ); 309 );
310 310
311 /** 311 /**
312 * Reads data from a CxBuffer. 312 * Reads data from a CxBuffer.
313 * 313 *
323 */ 323 */
324 size_t cxBufferRead( 324 size_t cxBufferRead(
325 void *ptr, 325 void *ptr,
326 size_t size, 326 size_t size,
327 size_t nitems, 327 size_t nitems,
328 CxBuffer buffer 328 CxBuffer *buffer
329 ); 329 );
330 330
331 /** 331 /**
332 * Writes a character to a buffer. 332 * Writes a character to a buffer.
333 * 333 *
342 * @param c the character to write 342 * @param c the character to write
343 * @return the byte that has bean written or \c EOF when the end of the stream is 343 * @return the byte that has bean written or \c EOF when the end of the stream is
344 * reached and automatic extension is not enabled or not possible 344 * reached and automatic extension is not enabled or not possible
345 */ 345 */
346 int cxBufferPut( 346 int cxBufferPut(
347 CxBuffer buffer, 347 CxBuffer *buffer,
348 int c 348 int c
349 ); 349 );
350 350
351 /** 351 /**
352 * Gets a character from a buffer. 352 * Gets a character from a buffer.
354 * The current position of the buffer is increased after a successful read. 354 * The current position of the buffer is increased after a successful read.
355 * 355 *
356 * @param buffer the buffer to read from 356 * @param buffer the buffer to read from
357 * @return the character or \c EOF, if the end of the buffer is reached 357 * @return the character or \c EOF, if the end of the buffer is reached
358 */ 358 */
359 int cxBufferGet(CxBuffer buffer); 359 int cxBufferGet(CxBuffer *buffer);
360 360
361 /** 361 /**
362 * Writes a string to a buffer. 362 * Writes a string to a buffer.
363 * 363 *
364 * @param buffer the buffer 364 * @param buffer the buffer
365 * @param str the zero-terminated string 365 * @param str the zero-terminated string
366 * @return the number of bytes written 366 * @return the number of bytes written
367 */ 367 */
368 size_t cxBufferPutString( 368 size_t cxBufferPutString(
369 CxBuffer buffer, 369 CxBuffer *buffer,
370 const char *str 370 const char *str
371 ); 371 );
372 372
373 #ifdef __cplusplus 373 #ifdef __cplusplus
374 } 374 }

mercurial