Changed fill-column to 80, so more space for comments.
This commit is contained in:
63
lib/darr.h
63
lib/darr.h
@@ -42,10 +42,10 @@ typedef struct
|
||||
/**
|
||||
@brief Get the `IND`th item of type `TYPE` in `DARR_DATA`
|
||||
|
||||
@details Cast `DARR_DATA` to `TYPE`, taking the `IND`th item.
|
||||
NOTE: This is unsafe as bound checks are not done i.e. if
|
||||
`DARR_DATA` has at least space for `IND` * sizeof(`TYPE`) items.
|
||||
It is presumed the caller will check themselves.
|
||||
@details Cast `DARR_DATA` to `TYPE`, taking the `IND`th item. NOTE: This is
|
||||
unsafe as bound checks are not done i.e. if `DARR_DATA` has at least space
|
||||
for `IND` * sizeof(`TYPE`) items. It is presumed the caller will check
|
||||
themselves.
|
||||
|
||||
@param[TYPE] Type to cast internal byte array
|
||||
@param[DARR_DATA] Byte array of darr
|
||||
@@ -58,24 +58,23 @@ typedef struct
|
||||
/**
|
||||
@brief Initialise a dynamic array `darr` with n bytes of space.
|
||||
|
||||
@details All properties of `darr` are initialised. `darr`.used is
|
||||
set to 0, `darr`.available is set to `n` and `darr`.data is set to
|
||||
a pointer of `n` bytes. NOTE: If `n` = 0 then it is set to
|
||||
DARR_DEFAULT_SIZE
|
||||
@details All properties of `darr` are initialised. `darr`.used is set to 0,
|
||||
`darr`.available is set to `n` and `darr`.data is set to a pointer of `n`
|
||||
bytes. NOTE: If `n` = 0 then it is set to DARR_DEFAULT_SIZE
|
||||
|
||||
@param[darr] Pointer to darr_t object to initialise
|
||||
@param[n] Number of bytes to allocate. If equal to 0 then
|
||||
considered treated as DARR_DEFAULT_SIZE
|
||||
@param[n] Number of bytes to allocate. If equal to 0 then considered treated
|
||||
as DARR_DEFAULT_SIZE
|
||||
*/
|
||||
void darr_init(darr_t *darr, size_t n);
|
||||
|
||||
/**
|
||||
@brief Ensure a dynamic array has at least n bytes of space free.
|
||||
|
||||
@details If `darr` has n or more bytes free, nothing occurs.
|
||||
Otherwise, the byte array in `darr` is reallocated such that it has
|
||||
at least `n` bytes of free space. NOTE: `darr` has at least `n`
|
||||
bytes free if and only if `darr`.used + `n` <= `darr`.available
|
||||
@details If `darr` has n or more bytes free, nothing occurs. Otherwise, the
|
||||
byte array in `darr` is reallocated such that it has at least `n` bytes of
|
||||
free space. NOTE: `darr` has at least `n` bytes free if and only if
|
||||
`darr`.used + `n` <= `darr`.available
|
||||
|
||||
@param[darr] Dynamic array to check
|
||||
@param[n] Number of bytes
|
||||
@@ -85,10 +84,9 @@ void darr_ensure_capacity(darr_t *darr, size_t n);
|
||||
/**
|
||||
@brief Append a byte to a dynamic array.
|
||||
|
||||
@details Append a byte to the end of the byte buffer in a dyamic
|
||||
array. If the dynamic array doesn't have enough free space to fit
|
||||
the byte, it will reallocate to ensure it can fit it in via
|
||||
darr_ensure_capacity().
|
||||
@details Append a byte to the end of the byte buffer in a dyamic array. If
|
||||
the dynamic array doesn't have enough free space to fit the byte, it will
|
||||
reallocate to ensure it can fit it in via darr_ensure_capacity().
|
||||
|
||||
@param[darr] Dynamic arrary to append to
|
||||
@param[b] Byte to append
|
||||
@@ -98,10 +96,9 @@ void darr_append_byte(darr_t *darr, byte_t b);
|
||||
/**
|
||||
@brief Append an array of n bytes to a dynamic array.
|
||||
|
||||
@details Append an array of bytes to the end of a byte buffer. If
|
||||
the dynamic array doesn't have enough free space to fit all n bytes
|
||||
it will reallocate to ensure it can fit it in via
|
||||
darr_ensure_capacity().
|
||||
@details Append an array of bytes to the end of a byte buffer. If the
|
||||
dynamic array doesn't have enough free space to fit all n bytes it will
|
||||
reallocate to ensure it can fit it in via darr_ensure_capacity().
|
||||
|
||||
@param[darr] Dynamic array to append to
|
||||
@param[b] Array of bytes to append
|
||||
@@ -112,9 +109,9 @@ void darr_append_bytes(darr_t *darr, byte_t *b, size_t n);
|
||||
/**
|
||||
@brief Get the nth byte of a dynamic array
|
||||
|
||||
@details Get the nth byte of the dynamic array. 0 based. NOTE: If
|
||||
the dynamic array has less than n bytes used, it will return 0 as a
|
||||
default value, so this is a safe alternative to DARR_AT().
|
||||
@details Get the nth byte of the dynamic array. 0 based. NOTE: If the
|
||||
dynamic array has less than n bytes used, it will return 0 as a default
|
||||
value, so this is a safe alternative to DARR_AT().
|
||||
|
||||
@param[darr] Dynamic array to index
|
||||
@param[n] Index to get byte at
|
||||
@@ -126,9 +123,9 @@ byte_t *darr_at(darr_t *darr, size_t n);
|
||||
/**
|
||||
@brief Write the bytes of a dynamic array to a file pointer
|
||||
|
||||
@details Given a dynamic array and a file pointer, write the
|
||||
internal buffer of bytes to the file pointer. NOTE: The file
|
||||
pointer is assumed to be open and suitable for writing.
|
||||
@details Given a dynamic array and a file pointer, write the internal buffer
|
||||
of bytes to the file pointer. NOTE: The file pointer is assumed to be open
|
||||
and suitable for writing.
|
||||
|
||||
@param[darr] Dynamic array to write
|
||||
@param[fp] File pointer to write on
|
||||
@@ -138,14 +135,14 @@ void darr_write_file(darr_t *darr, FILE *fp);
|
||||
/**
|
||||
@brief Read a file pointer in its entirety into a dynamic array
|
||||
|
||||
@details Read a file pointer as a buffer of bytes then return that
|
||||
buffer wrapped in a darr_t structure. NOTE: the file pointer is
|
||||
assumed to be open and suitable for reading.
|
||||
@details Read a file pointer as a buffer of bytes then return that buffer
|
||||
wrapped in a darr_t structure. NOTE: the file pointer is assumed to be open
|
||||
and suitable for reading.
|
||||
|
||||
@param[fp]: File pointer to read
|
||||
|
||||
@return Dynamic array structure with available set to the size of
|
||||
the `buffer` read and `data` set to the buffer of bytes.
|
||||
@return Dynamic array structure with available set to the size of the
|
||||
`buffer` read and `data` set to the buffer of bytes.
|
||||
*/
|
||||
darr_t darr_read_file(FILE *fp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user