Sat, 04 Jan 2025 15:41:02 +0100
refine docs for buffer.h - issue #548
also fixes the ultra fail in the struct declaration
src/cx/buffer.h | file | annotate | diff | comparison | revisions |
--- a/src/cx/buffer.h Sat Jan 04 14:19:11 2025 +0100 +++ b/src/cx/buffer.h Sat Jan 04 15:41:02 2025 +0100 @@ -27,9 +27,9 @@ */ /** - * \file buffer.h + * @file buffer.h * - * \brief Advanced buffer implementation. + * @brief Advanced buffer implementation. * * Instances of CxBuffer can be used to read from or to write to like one * would do with a stream. @@ -38,9 +38,9 @@ * can be enabled. See the documentation of the macro constants for more * information. * - * \author Mike Becker - * \author Olaf Wintermann - * \copyright 2-Clause BSD License + * @author Mike Becker + * @author Olaf Wintermann + * @copyright 2-Clause BSD License */ #ifndef UCX_BUFFER_H @@ -89,7 +89,7 @@ #define CX_BUFFER_COPY_ON_EXTEND 0x08 /** Structure for the UCX buffer data. */ -typedef struct { +struct cx_buffer_s { /** A pointer to the buffer contents. */ union { /** @@ -111,7 +111,7 @@ size_t size; /** * The buffer may not extend beyond this threshold before starting to flush. - * Default is \c SIZE_MAX (flushing disabled when auto extension is enabled). + * Default is @c SIZE_MAX (flushing disabled when auto extension is enabled). */ size_t flush_threshold; /** @@ -122,13 +122,13 @@ /** * The maximum number of blocks to flush in one cycle. * Zero disables flushing entirely (this is the default). - * Set this to \c SIZE_MAX to flush the entire buffer. + * Set this to @c SIZE_MAX to flush the entire buffer. * * @attention if the maximum number of blocks multiplied with the block size * is smaller than the expected contents written to this buffer within one write * operation, multiple flush cycles are performed after that write. * That means the total number of blocks flushed after one write to this buffer may - * be larger than \c flush_blkmax. + * be larger than @c flush_blkmax. */ size_t flush_blkmax; @@ -139,7 +139,7 @@ cx_write_func flush_func; /** - * The target for \c flush_func. + * The target for @c flush_func. */ void *flush_target; @@ -151,41 +151,41 @@ * @see #CX_BUFFER_COPY_ON_WRITE */ int flags; -} cx_buffer_s; +}; /** * UCX buffer. */ -typedef cx_buffer_s CxBuffer; +typedef struct cx_buffer_s CxBuffer; /** * Initializes a fresh buffer. * - * You may also provide a read-only \p space, in which case + * You may also provide a read-only @p space, in which case * you will need to cast the pointer, and you should set the * #CX_BUFFER_COPY_ON_WRITE flag. * * You need to set the size manually after initialization, if - * you provide \p space which already contains data. + * you provide @p space which already contains data. * - * When you specify stack memory as \p space and decide to use - * the auto-extension feature, you \em must use the + * When you specify stack memory as @p space and decide to use + * the auto-extension feature, you @em must use the * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the * #CX_BUFFER_AUTO_EXTEND flag. * - * \note You may provide \c NULL as argument for \p space. + * @note You may provide @c NULL as argument for @p space. * Then this function will allocate the space and enforce * the #CX_BUFFER_FREE_CONTENTS flag. In that case, specifying * copy-on-write should be avoided, because the allocated * space will be leaking after the copy-on-write operation. * * @param buffer the buffer to initialize - * @param space pointer to the memory area, or \c NULL to allocate + * @param space pointer to the memory area, or @c NULL to allocate * new memory * @param capacity the capacity of the buffer * @param allocator the allocator this buffer shall use for automatic * memory management - * (if \c NULL, a default stdlib allocator will be used) + * (if @c NULL, a default stdlib allocator will be used) * @param flags buffer features (see cx_buffer_s.flags) * @return zero on success, non-zero if a required allocation failed */ @@ -214,9 +214,9 @@ * Deallocates the buffer. * * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, this function also destroys - * the contents. If you \em only want to destroy the contents, use cxBufferDestroy(). + * the contents. If you @em only want to destroy the contents, use cxBufferDestroy(). * - * \remark As with all free() functions, this accepts \c NULL arguments in which + * @remark As with all free() functions, this accepts @c NULL arguments in which * case it does nothing. * * @param buffer the buffer to deallocate @@ -227,26 +227,26 @@ /** * Allocates and initializes a fresh buffer. * - * You may also provide a read-only \p space, in which case + * You may also provide a read-only @p space, in which case * you will need to cast the pointer, and you should set the * #CX_BUFFER_COPY_ON_WRITE flag. - * When you specify stack memory as \p space and decide to use - * the auto-extension feature, you \em must use the + * When you specify stack memory as @p space and decide to use + * the auto-extension feature, you @em must use the * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the * #CX_BUFFER_AUTO_EXTEND flag. * - * \note You may provide \c NULL as argument for \p space. + * @note You may provide @c NULL as argument for @p space. * Then this function will allocate the space and enforce * the #CX_BUFFER_FREE_CONTENTS flag. * - * @param space pointer to the memory area, or \c NULL to allocate + * @param space pointer to the memory area, or @c NULL to allocate * new memory * @param capacity the capacity of the buffer * @param allocator the allocator to use for allocating the structure and the automatic * memory management within the buffer - * (if \c NULL, a default stdlib allocator will be used) + * (if @c NULL, a default stdlib allocator will be used) * @param flags buffer features (see cx_buffer_s.flags) - * @return a pointer to the buffer on success, \c NULL if a required allocation failed + * @return a pointer to the buffer on success, @c NULL if a required allocation failed */ cx_attr_malloc cx_attr_dealloc(cxBufferFree, 1) @@ -269,7 +269,7 @@ * are discarded. * * If the offset is negative, the contents are shifted to the left where the - * first \p shift bytes are discarded. + * first @p shift bytes are discarded. * The new size of the buffer is the old size minus the absolute shift value. * If this value is larger than the buffer size, the buffer is emptied (but * not cleared, see the security note below). @@ -277,11 +277,11 @@ * The buffer position gets shifted alongside with the content but is kept * within the boundaries of the buffer. * - * \note For situations where \c off_t is not large enough, there are specialized cxBufferShiftLeft() and - * cxBufferShiftRight() functions using a \c size_t as parameter type. + * @note For situations where @c off_t is not large enough, there are specialized cxBufferShiftLeft() and + * cxBufferShiftRight() functions using a @c size_t as parameter type. * - * \attention - * Security Note: The shifting operation does \em not erase the previously occupied memory cells. + * @attention + * Security Note: The shifting operation does @em not erase the previously occupied memory cells. * But you can easily do that manually, e.g. by calling * <code>memset(buffer->bytes, 0, shift)</code> for a right shift or * <code>memset(buffer->bytes + buffer->size, 0, buffer->capacity - buffer->size)</code> @@ -289,7 +289,10 @@ * * @param buffer the buffer * @param shift the shift offset (negative means left shift) - * @return 0 on success, non-zero if a required auto-extension or copy-on-write fails + * @retval zero success + * @retval non-zero if a required auto-extension or copy-on-write fails + * @see cxBufferShiftLeft() + * @see cxBufferShiftRight() */ cx_attr_nonnull int cxBufferShift( @@ -303,7 +306,8 @@ * * @param buffer the buffer * @param shift the shift offset - * @return 0 on success, non-zero if a required auto-extension or copy-on-write fails + * @retval zero success + * @retval non-zero if a required auto-extension or copy-on-write fails * @see cxBufferShift() */ cx_attr_nonnull @@ -318,7 +322,8 @@ * * @param buffer the buffer * @param shift the positive shift offset - * @return usually zero, except the buffer uses copy-on-write and the allocation fails + * @retval zero success + * @retval non-zero if the buffer uses copy-on-write and the allocation fails * @see cxBufferShift() */ cx_attr_nonnull @@ -331,20 +336,21 @@ /** * Moves the position of the buffer. * - * The new position is relative to the \p whence argument. + * The new position is relative to the @p whence argument. * - * \li \c SEEK_SET marks the start of the buffer. - * \li \c SEEK_CUR marks the current position. - * \li \c SEEK_END marks the end of the buffer. + * @li @c SEEK_SET marks the start of the buffer. + * @li @c SEEK_CUR marks the current position. + * @li @c SEEK_END marks the end of the buffer. * * With an offset of zero, this function sets the buffer position to zero - * (\c SEEK_SET), the buffer size (\c SEEK_END) or leaves the buffer position - * unchanged (\c SEEK_CUR). + * (@c SEEK_SET), the buffer size (@c SEEK_END) or leaves the buffer position + * unchanged (@c SEEK_CUR). * * @param buffer the buffer - * @param offset position offset relative to \p whence - * @param whence one of \c SEEK_SET, \c SEEK_CUR or \c SEEK_END - * @return 0 on success, non-zero if the position is invalid + * @param offset position offset relative to @p whence + * @param whence one of @c SEEK_SET, @c SEEK_CUR or @c SEEK_END + * @retval zero success + * @retval non-zero if the position is invalid * */ cx_attr_nonnull @@ -360,7 +366,7 @@ * The data is deleted by zeroing it with a call to memset(). * If you do not need that, you can use the faster cxBufferReset(). * - * \note If the #CX_BUFFER_COPY_ON_WRITE flag is set, this function + * @note If the #CX_BUFFER_COPY_ON_WRITE flag is set, this function * will not erase the data and behave exactly as cxBufferReset(). * * @param buffer the buffer to be cleared @@ -385,8 +391,9 @@ * Tests, if the buffer position has exceeded the buffer size. * * @param buffer the buffer to test - * @return true, if the current buffer position has exceeded the last - * byte of the buffer's contents. + * @retval true if the current buffer position has exceeded the last + * byte of the buffer's contents + * @retval false otherwise */ cx_attr_nonnull cx_attr_nodiscard @@ -400,7 +407,8 @@ * * @param buffer the buffer * @param capacity the minimum required capacity for this buffer - * @return 0 on success or a non-zero value on failure + * @retval zero the capacity was already sufficient or successfully increased + * @retval non-zero on allocation failure */ cx_attr_nonnull int cxBufferMinimumCapacity( @@ -420,19 +428,24 @@ * buffer are both incapable of taking more data or all data has been written. * The number returned by this function is the total number of elements that * could be written during the process. It does not necessarily mean that those - * elements are still in this buffer, because some of them could have also be + * elements are still in this buffer, because some of them could have also been * flushed already. * - * If automatic flushing is not enabled, the position of the buffer is increased + * If automatic flushing is not enabled, the data is simply written into the + * buffer at the current position and the position of the buffer is increased * by the number of bytes written. + * Use cxBufferAppend() if you want to add data to this buffer regardless of + * the position. * - * \note The signature is compatible with the fwrite() family of functions. + * @note The signature is compatible with the fwrite() family of functions. * * @param ptr a pointer to the memory area containing the bytes to be written * @param size the length of one element * @param nitems the element count * @param buffer the CxBuffer to write to * @return the total count of elements written + * @see cxBufferAppend() + * @see cxBufferRead() */ cx_attr_nonnull size_t cxBufferWrite( @@ -451,7 +464,7 @@ * while additional data is added to the buffer occasionally. * Consequently, the position of the buffer is unchanged after this operation. * - * \note The signature is compatible with the fwrite() family of functions. + * @note The signature is compatible with the fwrite() family of functions. * * @param ptr a pointer to the memory area containing the bytes to be written * @param size the length of one element @@ -459,6 +472,7 @@ * @param buffer the CxBuffer to write to * @return the total count of elements written * @see cxBufferWrite() + * @see cxBufferRead() */ cx_attr_nonnull size_t cxBufferAppend( @@ -473,13 +487,15 @@ * * The position of the buffer is increased by the number of bytes read. * - * \note The signature is compatible with the fread() family of functions. + * @note The signature is compatible with the fread() family of functions. * * @param ptr a pointer to the memory area where to store the read data * @param size the length of one element * @param nitems the element count * @param buffer the CxBuffer to read from * @return the total number of elements read + * @see cxBufferWrite() + * @see cxBufferAppend() */ cx_attr_nonnull size_t cxBufferRead( @@ -495,14 +511,18 @@ * The least significant byte of the argument is written to the buffer. If the * end of the buffer is reached and #CX_BUFFER_AUTO_EXTEND feature is enabled, * the buffer capacity is extended by cxBufferMinimumCapacity(). If the feature - * is disabled or buffer extension fails, \c EOF is returned. + * is disabled or buffer extension fails, @c EOF is returned. * * On successful write, the position of the buffer is increased. * + * If you just want to write a null-terminator at the current position, you + * should use cxBufferTerminate() instead. + * * @param buffer the buffer to write to * @param c the character to write - * @return the byte that has been written or \c EOF when the end of the stream is + * @return the byte that has been written or @c EOF when the end of the stream is * reached and automatic extension is not enabled or not possible + * @see cxBufferTerminate() */ cx_attr_nonnull int cxBufferPut( @@ -511,9 +531,9 @@ ); /** - * Writes a terminating zero to a buffer. + * Writes a terminating zero to a buffer at the current position. * - * On successful write, \em neither the position \em nor the size of the buffer is + * On successful write, @em neither the position @em nor the size of the buffer is * increased. * * The purpose of this function is to have the written data ready to be used as @@ -528,6 +548,8 @@ /** * Writes a string to a buffer. * + * This is a convenience function for <code>cxBufferWrite(str, 1, strlen(str), buffer)</code>. + * * @param buffer the buffer * @param str the zero-terminated string * @return the number of bytes written @@ -545,7 +567,7 @@ * The current position of the buffer is increased after a successful read. * * @param buffer the buffer to read from - * @return the character or \c EOF, if the end of the buffer is reached + * @return the character or @c EOF, if the end of the buffer is reached */ cx_attr_nonnull int cxBufferGet(CxBuffer *buffer);