153 * @param allocator the allocator this buffer shall use for automatic |
153 * @param allocator the allocator this buffer shall use for automatic |
154 * memory management. If \c NULL, the default heap allocator will be used. |
154 * memory management. If \c NULL, the default heap allocator will be used. |
155 * @param flags buffer features (see cx_buffer_s.flags) |
155 * @param flags buffer features (see cx_buffer_s.flags) |
156 * @return zero on success, non-zero if a required allocation failed |
156 * @return zero on success, non-zero if a required allocation failed |
157 */ |
157 */ |
158 __attribute__((__nonnull__(1))) |
158 cx_attr_nonnull_arg(1) |
159 int cxBufferInit( |
159 int cxBufferInit( |
160 CxBuffer *buffer, |
160 CxBuffer *buffer, |
161 void *space, |
161 void *space, |
162 size_t capacity, |
162 size_t capacity, |
163 const CxAllocator *allocator, |
163 const CxAllocator *allocator, |
164 int flags |
164 int flags |
165 ); |
165 ); |
|
166 |
|
167 /** |
|
168 * Destroys the buffer contents. |
|
169 * |
|
170 * Has no effect if the #CX_BUFFER_FREE_CONTENTS feature is not enabled. |
|
171 * If you want to free the memory of the entire buffer, use cxBufferFree(). |
|
172 * |
|
173 * @param buffer the buffer which contents shall be destroyed |
|
174 * @see cxBufferInit() |
|
175 */ |
|
176 cx_attr_nonnull |
|
177 void cxBufferDestroy(CxBuffer *buffer); |
|
178 |
|
179 /** |
|
180 * Deallocates the buffer. |
|
181 * |
|
182 * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, this function also destroys |
|
183 * the contents. If you \em only want to destroy the contents, use cxBufferDestroy(). |
|
184 * |
|
185 * \remark As with all free() functions, this accepts \c NULL arguments in which |
|
186 * case it does nothing. |
|
187 * |
|
188 * @param buffer the buffer to deallocate |
|
189 * @see cxBufferCreate() |
|
190 */ |
|
191 void cxBufferFree(CxBuffer *buffer); |
166 |
192 |
167 /** |
193 /** |
168 * Allocates and initializes a fresh buffer. |
194 * Allocates and initializes a fresh buffer. |
169 * |
195 * |
170 * \note You may provide \c NULL as argument for \p space. |
196 * \note You may provide \c NULL as argument for \p space. |
177 * @param allocator the allocator to use for allocating the structure and the automatic |
203 * @param allocator the allocator to use for allocating the structure and the automatic |
178 * memory management within the buffer. If \c NULL, the default heap allocator will be used. |
204 * memory management within the buffer. If \c NULL, the default heap allocator will be used. |
179 * @param flags buffer features (see cx_buffer_s.flags) |
205 * @param flags buffer features (see cx_buffer_s.flags) |
180 * @return a pointer to the buffer on success, \c NULL if a required allocation failed |
206 * @return a pointer to the buffer on success, \c NULL if a required allocation failed |
181 */ |
207 */ |
|
208 cx_attr_malloc |
|
209 cx_attr_dealloc(cxBufferFree, 1) |
|
210 cx_attr_nodiscard |
182 CxBuffer *cxBufferCreate( |
211 CxBuffer *cxBufferCreate( |
183 void *space, |
212 void *space, |
184 size_t capacity, |
213 size_t capacity, |
185 const CxAllocator *allocator, |
214 const CxAllocator *allocator, |
186 int flags |
215 int flags |
187 ); |
216 ); |
188 |
|
189 /** |
|
190 * Destroys the buffer contents. |
|
191 * |
|
192 * Has no effect if the #CX_BUFFER_FREE_CONTENTS feature is not enabled. |
|
193 * If you want to free the memory of the entire buffer, use cxBufferFree(). |
|
194 * |
|
195 * @param buffer the buffer which contents shall be destroyed |
|
196 * @see cxBufferInit() |
|
197 */ |
|
198 __attribute__((__nonnull__)) |
|
199 void cxBufferDestroy(CxBuffer *buffer); |
|
200 |
|
201 /** |
|
202 * Deallocates the buffer. |
|
203 * |
|
204 * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, this function also destroys |
|
205 * the contents. If you \em only want to destroy the contents, use cxBufferDestroy(). |
|
206 * |
|
207 * @param buffer the buffer to deallocate |
|
208 * @see cxBufferCreate() |
|
209 */ |
|
210 __attribute__((__nonnull__)) |
|
211 void cxBufferFree(CxBuffer *buffer); |
|
212 |
217 |
213 /** |
218 /** |
214 * Shifts the contents of the buffer by the given offset. |
219 * Shifts the contents of the buffer by the given offset. |
215 * |
220 * |
216 * If the offset is positive, the contents are shifted to the right. |
221 * If the offset is positive, the contents are shifted to the right. |
256 * @param buffer the buffer |
261 * @param buffer the buffer |
257 * @param shift the shift offset |
262 * @param shift the shift offset |
258 * @return 0 on success, non-zero if a required auto-extension fails |
263 * @return 0 on success, non-zero if a required auto-extension fails |
259 * @see cxBufferShift() |
264 * @see cxBufferShift() |
260 */ |
265 */ |
261 __attribute__((__nonnull__)) |
266 cx_attr_nonnull |
262 int cxBufferShiftRight( |
267 int cxBufferShiftRight( |
263 CxBuffer *buffer, |
268 CxBuffer *buffer, |
264 size_t shift |
269 size_t shift |
265 ); |
270 ); |
266 |
271 |
274 * @param buffer the buffer |
279 * @param buffer the buffer |
275 * @param shift the positive shift offset |
280 * @param shift the positive shift offset |
276 * @return always zero |
281 * @return always zero |
277 * @see cxBufferShift() |
282 * @see cxBufferShift() |
278 */ |
283 */ |
279 __attribute__((__nonnull__)) |
284 cx_attr_nonnull |
280 int cxBufferShiftLeft( |
285 int cxBufferShiftLeft( |
281 CxBuffer *buffer, |
286 CxBuffer *buffer, |
282 size_t shift |
287 size_t shift |
283 ); |
288 ); |
284 |
289 |
316 * If you do not need that, you can use the faster cxBufferReset(). |
321 * If you do not need that, you can use the faster cxBufferReset(). |
317 * |
322 * |
318 * @param buffer the buffer to be cleared |
323 * @param buffer the buffer to be cleared |
319 * @see cxBufferReset() |
324 * @see cxBufferReset() |
320 */ |
325 */ |
321 __attribute__((__nonnull__)) |
326 cx_attr_nonnull |
322 void cxBufferClear(CxBuffer *buffer); |
327 void cxBufferClear(CxBuffer *buffer); |
323 |
328 |
324 /** |
329 /** |
325 * Resets the buffer by resetting the position and size to zero. |
330 * Resets the buffer by resetting the position and size to zero. |
326 * |
331 * |
328 * reset of the buffer, use cxBufferClear(). |
333 * reset of the buffer, use cxBufferClear(). |
329 * |
334 * |
330 * @param buffer the buffer to be cleared |
335 * @param buffer the buffer to be cleared |
331 * @see cxBufferClear() |
336 * @see cxBufferClear() |
332 */ |
337 */ |
333 __attribute__((__nonnull__)) |
338 cx_attr_nonnull |
334 void cxBufferReset(CxBuffer *buffer); |
339 void cxBufferReset(CxBuffer *buffer); |
335 |
340 |
336 /** |
341 /** |
337 * Tests, if the buffer position has exceeded the buffer size. |
342 * Tests, if the buffer position has exceeded the buffer size. |
338 * |
343 * |
339 * @param buffer the buffer to test |
344 * @param buffer the buffer to test |
340 * @return non-zero, if the current buffer position has exceeded the last |
345 * @return non-zero, if the current buffer position has exceeded the last |
341 * byte of the buffer's contents. |
346 * byte of the buffer's contents. |
342 */ |
347 */ |
343 __attribute__((__nonnull__)) |
348 cx_attr_nonnull |
|
349 cx_attr_nodiscard |
344 int cxBufferEof(const CxBuffer *buffer); |
350 int cxBufferEof(const CxBuffer *buffer); |
345 |
351 |
346 |
352 |
347 /** |
353 /** |
348 * Ensures that the buffer has a minimum capacity. |
354 * Ensures that the buffer has a minimum capacity. |
383 * @param size the length of one element |
389 * @param size the length of one element |
384 * @param nitems the element count |
390 * @param nitems the element count |
385 * @param buffer the CxBuffer to write to |
391 * @param buffer the CxBuffer to write to |
386 * @return the total count of elements written |
392 * @return the total count of elements written |
387 */ |
393 */ |
388 __attribute__((__nonnull__)) |
394 cx_attr_nonnull |
389 size_t cxBufferWrite( |
395 size_t cxBufferWrite( |
390 const void *ptr, |
396 const void *ptr, |
391 size_t size, |
397 size_t size, |
392 size_t nitems, |
398 size_t nitems, |
393 CxBuffer *buffer |
399 CxBuffer *buffer |
427 * @param buffer the buffer to write to |
433 * @param buffer the buffer to write to |
428 * @param c the character to write |
434 * @param c the character to write |
429 * @return the byte that has bean written or \c EOF when the end of the stream is |
435 * @return the byte that has bean written or \c EOF when the end of the stream is |
430 * reached and automatic extension is not enabled or not possible |
436 * reached and automatic extension is not enabled or not possible |
431 */ |
437 */ |
432 __attribute__((__nonnull__)) |
438 cx_attr_nonnull |
433 int cxBufferPut( |
439 int cxBufferPut( |
434 CxBuffer *buffer, |
440 CxBuffer *buffer, |
435 int c |
441 int c |
436 ); |
442 ); |
437 |
443 |
454 * The current position of the buffer is increased after a successful read. |
461 * The current position of the buffer is increased after a successful read. |
455 * |
462 * |
456 * @param buffer the buffer to read from |
463 * @param buffer the buffer to read from |
457 * @return the character or \c EOF, if the end of the buffer is reached |
464 * @return the character or \c EOF, if the end of the buffer is reached |
458 */ |
465 */ |
459 __attribute__((__nonnull__)) |
466 cx_attr_nonnull |
460 int cxBufferGet(CxBuffer *buffer); |
467 int cxBufferGet(CxBuffer *buffer); |
461 |
468 |
462 #ifdef __cplusplus |
469 #ifdef __cplusplus |
463 } |
470 } |
464 #endif |
471 #endif |