Skip to content

Commit

Permalink
specvec.h: Add function headers for inline functions
Browse files Browse the repository at this point in the history
See RM #536

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
  • Loading branch information
cazfi committed Sep 22, 2024
1 parent 39983d3 commit 85721ec
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions utility/specvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,18 @@ SPECVEC_VECTOR {
size_t size, size_alloc;
};

/**********************************************************************//**
Initialize the vector
**************************************************************************/
static inline void SPECVEC_FOO(_vector_init) (SPECVEC_VECTOR *tthis)
{
tthis->p = nullptr;
tthis->size = tthis->size_alloc = 0;
}

/**********************************************************************//**
Allocate vector to at least to size 'size'
**************************************************************************/
static inline void SPECVEC_FOO(_vector_reserve) (SPECVEC_VECTOR *tthis,
size_t size)
{
Expand All @@ -91,11 +97,17 @@ static inline void SPECVEC_FOO(_vector_reserve) (SPECVEC_VECTOR *tthis,
tthis->size = size;
}

/**********************************************************************//**
Return size of the vector
**************************************************************************/
static inline size_t SPECVEC_FOO(_vector_size) (const SPECVEC_VECTOR *tthis)
{
return tthis->size;
}

/**********************************************************************//**
Get element at position svindex
**************************************************************************/
static inline SPECVEC_TYPE *SPECVEC_FOO(_vector_get) (const SPECVEC_VECTOR
*tthis,
int svindex)
Expand All @@ -109,7 +121,11 @@ static inline SPECVEC_TYPE *SPECVEC_FOO(_vector_get) (const SPECVEC_VECTOR
}
}

/* You must _init "*to" before using this function */
/**********************************************************************//**
Copy vector to vector.
"*to" must be initialized by the _init() before the call.
**************************************************************************/
static inline void SPECVEC_FOO(_vector_copy) (SPECVEC_VECTOR *to,
const SPECVEC_VECTOR *from)
{
Expand All @@ -119,6 +135,9 @@ static inline void SPECVEC_FOO(_vector_copy) (SPECVEC_VECTOR *to,
}
}

/**********************************************************************//**
Free the vector
**************************************************************************/
static inline void SPECVEC_FOO(_vector_free) (SPECVEC_VECTOR *tthis)
{
if (tthis->p) {
Expand All @@ -127,14 +146,17 @@ static inline void SPECVEC_FOO(_vector_free) (SPECVEC_VECTOR *tthis)
SPECVEC_FOO(_vector_init)(tthis);
}

/**********************************************************************//**
Add pfoo to the end of the vector
**************************************************************************/
static inline void SPECVEC_FOO(_vector_append) (SPECVEC_VECTOR *tthis,
SPECVEC_TYPE const pfoo)
{
SPECVEC_FOO(_vector_reserve) (tthis, tthis->size + 1);
tthis->p[tthis->size - 1] = pfoo;
}

/**************************************************************************
/**********************************************************************//**
Remove element number svindex from the vector.
**************************************************************************/
static inline void SPECVEC_FOO(_vector_remove) (SPECVEC_VECTOR *tthis,
Expand Down

0 comments on commit 85721ec

Please sign in to comment.