Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
|
Go to the documentation of this file.
43 static const void* s_vpMagicNumber = (
void*)
"vector";
45 #if defined APG_VEC_STATS
66 static void vStatsPush(
vector* spCtx,
aint uiPushed);
67 static void vStatsPop(
vector* spCtx,
aint uiPopped);
68 static void vStatsGrow(
vector* spCtx,
aint uiAddedElements);
77 #define STATS_PUSH(s, p) vStatsPush((s), (p))
81 #define STATS_POP(s, p) vStatsPop((s), (p))
85 #define STATS_GROW(s, n) vStatsGrow((s), (n))
89 const void* vpValidate;
97 #define STATS_PUSH(s, p)
98 #define STATS_POP(s, p)
99 #define STATS_GROW(s, n)
102 static void vGrow(
vector* spCtx,
aint uiElements);
127 if (uiElementSize == 0) {
128 XTHROW(spEx,
"element size cannot be zero");
131 if (uiInitialAlloc == 0) {
132 XTHROW(spEx,
"initial allocation cannot be zero");
136 memset((
void*) spCtx, 0,
sizeof(*spCtx));
137 spCtx->cpData = (
char*)
vpMemAlloc(vpMem, (uiElementSize * uiInitialAlloc));
138 spCtx->uiElementSize = uiElementSize;
139 spCtx->uiReserved = uiInitialAlloc;
143 spCtx->vpMem = vpMem;
144 spCtx->spException = spEx;
146 return (
void*) spCtx;
165 void* vpMem = spCtx->
vpMem;
167 memset(vpCtx, 0,
sizeof(
vector));
181 if (vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)) {
195 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
196 void* vpReturn = NULL;
223 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
225 void* vpReturn = NULL;
227 vGrow(spCtx, uiCount);
252 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
273 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
274 if ((uiCount > 0) && (spCtx->
uiUsed > 0)) {
275 if (spCtx->
uiUsed > uiCount) {
308 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
309 if(uiIndex >= spCtx->
uiUsed){
328 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
330 return ((
void*) spCtx->
cpData);
345 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
364 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
369 return ((
void*) spCtx->
cpData);
371 if(uiIndex < spCtx->uiUsed){
387 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
404 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
405 return (
void*)spCtx->
cpData;
439 static void vGrow(
vector* spCtx,
aint uiElements) {
441 uiNewReserved = 2 * (spCtx->
uiReserved + uiElements);
450 #if defined APG_VEC_STATS
487 void vStatsGrow(
vector* spCtx,
aint uiAddedElements){
499 memset((
void*) spStats, 0,
sizeof(
vec_stats));
This header "#include"s all publid lib headers and other standard headers needed by most objects.
aint uiReserved
The current number of elements reserved.
void * vpVecBuffer(void *vpCtx)
Get a pointer to the vector buffer.
aint uiGrownCount
The number times the vector was automatically extended.
void vVecStats(void *vpCtx, vec_stats *spStats)
void vVecDtor(void *vpCtx)
The vector component destructor.
aint uiGrownBytes
The number of bytes automatically added to the vector.
aint uiOriginalBytes
The initial number of bytes allocated to the vector.
void vExContext()
Handles bad context pointers.
aint uiGrownCount
number times the vector automatically grew in size
aint uiUsed
The current number elements used.
void * vpVecAt(void *vpCtx, aint uiIndex)
Get a the indexed vector element. The vector is not altered.
void * vpMemRealloc(void *vpCtx, const void *vpData, aint uiBytes)
Re-allocates memory previously allocated with vpMemAlloc().
#define XTHROW(ctx, msg)
Exception throw macro.
void * vpMem
context to the underlying memory component
aint uiPushed
The total number of elements pushed onto (added to) the vector.
void * vpVecPop(void *vpCtx)
Pops one element from the end of the array.
aint uiMaxUsed
maximum number of elements used;
uint_fast32_t aint
The APG parser's unsigned integer type.
void * vpVecLast(void *vpCtx)
Get the last element one the vector. The vector is not altered.
aint uiOriginalElements
The initial number of elements allocated to the vector.
void * vpVecPopn(void *vpCtx, aint uiCount)
Pops one or more elements from the end of the array.
aint uiUsedBytes
The current number of bytes in use.
exception * spMemException(void *vpCtx)
Get a pointer to this memory objects's exception handler.
Private for internal use only. Defines the vector's state. Opaque to applications.
void * vpMemAlloc(void *vpCtx, aint uiBytes)
Allocates memory.
aint uiElementSize
number of bytes in one element
aint uiVecLen(void *vpCtx)
Get the vector length. That is, the number of elements on the vector.
void * vpVecCtor(void *vpMem, aint uiElementSize, aint uiInitialAlloc)
The vector object constructor.
aint uiReservedBytes
The current number of bytes reserved.
aint uiPopped
number of elements popped
A structure to describe the type and location of a caught exception.
void vMemFree(void *vpCtx, const void *vpData)
Free memory previously allocated with vpMemAlloc().
abool bVecValidate(void *vpCtx)
Validates a vector component context.
char * cpData
pointer to the vector's data buffer
aint uiReserved
number of elements that have been reserved on the buffer
const void * vpValidate
Used by the memory object to validate the exception structure.
void * vpVecFirst(void *vpCtx)
Get the first element one the vector. The vector is not altered.
void * vpVecPushn(void *vpCtx, void *vpElement, aint uiCount)
Adds one or more elements to the end of the array.
aint uiPopped
The total number of elements popped from (removed from) the vector.
#define STATS_PUSH(s, p)
Called by the vector object to count the number of pushed (added) elements.
aint uiUsed
number of the reserved elements that have been used
#define STATS_GROW(s, n)
Called by the vector object to count the number of times the size of the vector was automatically ext...
aint uiGrownElements
The number new elements automatically added to the vector.
abool bMemValidate(void *vpCtx)
Validates a memory context.
#define STATS_POP(s, p)
Called by the vector object to count the number of popped (removed) elements.
uint8_t abool
abool is the APG bool type.
void * vpVecPopi(void *vpCtx, aint uiIndex)
Pops the element at the given zero-based index and all higher indexes.
const void * vpValidate
must be equal to s_vpMagicNumber
aint uiGrownElements
number elements vector has grown by
void * vpVecPush(void *vpCtx, void *vpElement)
Adds one element to the end of the array.
aint uiMaxUsedBytes
The maximum number of bytes used over the lifetime of the vector.
void vVecClear(void *vpCtx)
Clears all used elements in a vector component.
aint uiElementSize
The number of bytes in one element.
aint uiPushed
number of elements pushed
aint uiMaxUsed
The maximum number of elements used during the vector's lifetime.
APG Version 7.0 is licensed under the
2-Clause BSD License,
an Open Source Initiative Approved License.