Version 6.3
Copyright © 2005 - 2012 Lowell D. Thomas
APG
  … ABNF Parser Generator
All Data Structures Files Functions Variables Typedefs Macros Pages
Data Structures | Macros | Typedefs | Functions
Apg.h File Reference

Required header file for all APG-generated parsers. Contains important configuration macros and declarations of the API functions for the entire library. More...

#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  APG_MEM_STATS
 generated by the Memory component, available to the user for display of memory statistics More...
 
struct  APG_CBDATA
 The data structure passed to all syntax and AST callback functions, both rule and UDT. More...
 
struct  APG_PARSER_STATE
 the state of the parser after parsing an input string. More...
 
struct  APG_STAT
 the parsers total node hit statistics More...
 
struct  APG_NAME_STAT
 named rule or UDT node statistics More...
 
struct  APG_PARSER_STATS
 full set of statistics gathered during parsing, uiParserSyntaxAnalysis() More...
 

Macros

#define APG_TRUE   1
 
#define APG_FALSE   0
 
#define APG_UNDEFINED   -1
 
#define APG_INFINITE   -1
 
#define APG_VEC_ELEMENT   ((apg_uint)1)
 
#define APG_VEC_ALLOC   ((apg_uint)100)
 
#define APG_DISPLAY_MAX_LINE   128
 
#define min(a, b)   (((a) < (b)) ? (a) : (b))
 
#define max(a, b)   (((a) > (b)) ? (a) : (b))
 
#define PRE_PARSE   ((apg_uint)0)
 
#define NOMATCH   ((apg_uint)1)
 
#define EMPTY   ((apg_uint)2)
 
#define MATCH   ((apg_uint)3)
 
#define PRE_AST   ((apg_uint)4)
 
#define POST_AST   ((apg_uint)5)
 

Typedefs

typedef unsigned int apg_uint
 
typedef unsigned char apg_achar
 
typedef void(* PFN_ALERT) (unsigned int uiLine, const char *cpFile)
 
typedef void(* PFN_ALERT_MSG) (unsigned int uiLine, const char *cpFile, const char *cpMsg)
 
typedef void *(* PFN_ALLOCATOR) (size_t)
 
typedef void(* PFN_DEALLOCATOR) (void *)
 
typedef apg_uint(* APG_CALLBACK) (APG_CBDATA *spData)
 

Functions

void vDefaultAlertHandler (unsigned int uiLine, const char *cpFile)
 
int apg_stricmp (const char *cpLhs, const char *cpRhs)
 
void vCharToAChar (apg_achar *acpAChars, const char *cpChars, apg_uint uiLen)
 
apg_uint uiACharToStringSize (const apg_achar *acpAChars, apg_uint uiALen)
 
apg_uint uiACharToString (char *cpChars, apg_uint uiCLen, const apg_achar *acpAChars, apg_uint uiALen)
 
void * vpMemCtorA (PFN_ALLOCATOR pfnAllocator, PFN_DEALLOCATOR pfnDeAllocator)
 
void * vpMemCtor ()
 
void vMemDtor (void *vpCtx)
 
apg_uint uiMemValidate (void *vpCtx)
 
void * vpMemAlloc (void *vpCtx, apg_uint uiBytes)
 
void * vpMemRealloc (void *vpCtx, void *vpData, apg_uint uiBytes)
 
void vMemFree (void *vpCtx, void *vpData)
 
apg_uint uiMemCheckPoint (void *vpCtx)
 
void vMemFreeToCheckPoint (void *vpCtx, apg_uint uiChk)
 
void vMemClear (void *vpCtx)
 
void * vpVecCtor (void *vpMemCtx, apg_uint uiElementSize, apg_uint uiInitialAlloc)
 
void vVecDtor (void *vpCtx)
 
void * vpVecPush (void *vpVec, void *vpElement)
 
void * vpVecPushn (void *vpCtx, void *vpElement, apg_uint uiCount)
 
void * vpVecPop (void *vpCtx)
 
void * vpVecPopn (void *vpCtx, apg_uint uiCount)
 
void * vpVecPopTo (void *vpCtx, apg_uint uiIndex)
 
void * vpVecFront (void *vpCtx)
 
void * vpVecBack (void *vpCtx)
 
void * vpVecAt (void *vpCtx, apg_uint uiIndex)
 
apg_uint uiVecBytes (void *vpCtx)
 
apg_uint uiVecSize (void *vpCtx)
 
apg_uint uiVecElementSize (void *vpCtx)
 
apg_uint uiVecReallocations (void *vpCtx)
 
apg_uint uiVecValidate (void *vpCtx)
 
void vVecClear (void *vpCtx)
 
void vExecuteRule (APG_CBDATA *spData, apg_uint uiId, apg_uint uiOffset)
 
void vExecuteUdt (APG_CBDATA *spData, apg_uint uiId, apg_uint uiOffset)
 
void * vpParserCtor (void *vpParserInit, PFN_ALERT pfnAlertHandler)
 
void vParserDtor (void *vpCtx)
 
apg_uint uiParserSyntaxInitCallbacks (void *vpCtx, APG_CALLBACK *spRuleCallbacks, APG_CALLBACK *spUdtCallbacks)
 
apg_uint uiParserSyntaxAnalysis (void *vpCtx, apg_uint uiStartRule, const apg_achar *acpSrc, apg_uint uiSrcLen, void *vpData)
 
apg_uint uiParserState (void *vpCtx, APG_PARSER_STATE *spState)
 
void vParserAstInitNodes (void *vpCtx, apg_uint *uipRules, apg_uint *uipUdts)
 
void vParserAstInitCallbacks (void *vpCtx, APG_CALLBACK *spRuleCallbacks, APG_CALLBACK *spUdtCallbacks)
 
apg_uint uiParserAstTranslate (void *vpCtx, APG_CALLBACK *pfnRuleCallbacks, APG_CALLBACK *pfnUdtCallbacks, void *vpData)
 
apg_uint uiParserStatsEnable (void *vpCtx, apg_uint uiEnable)
 
apg_uint uiParserStatsGet (void *vpCtx, APG_PARSER_STATS *spStats, apg_uint *uipBufferSize)
 
apg_uint uiParserTraceEnable (void *vpCtx, apg_uint uiEnable)
 
void vParserTraceOp (void *vpCtx, apg_uint uiOpId, apg_uint uiEnable)
 
void vParserTraceRule (void *vpCtx, apg_uint uiIndex, apg_uint uiEnable)
 
void vParserTraceUdt (void *vpCtx, apg_uint uiIndex, apg_uint uiEnable)
 
void vParserTraceRange (void *vpCtx, apg_uint uiBegin, apg_uint uiCount)
 
apg_uint uiUdtLib_e_owsp (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_wsp (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_lineend (APG_CBDATA *spData)
 
apg_uint uiUdtLib_e_any (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_semi_comment (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_cpp_comment (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_c_comment (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_alphanum (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_alphanum_hyphen (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_alphanum_under (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_decnum (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_hexnum (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_quotedstring (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_singlequotedstring (APG_CBDATA *spData)
 
apg_uint uiUdtLib_u_doublequotedstring (APG_CBDATA *spData)
 

Detailed Description

Required header file for all APG-generated parsers. Contains important configuration macros and declarations of the API functions for the entire library.

APG Version 6.3 is the first version to allow for alphabet character codes larger than 8 bits wide. While variable, it is a "compile-time" variable and how it is controlled is dicussed here.

Alphabet character codes have the typedef apg_achar (the prefix apg_ or APG_ is often used here as a namespace.) Its definition is controlled with the #define macro _APG_CFG_ACHAR. The corresponding values of _APG_CFG_ACHAR and apg_achar are given here:

typedef unsigned char      apg_achar; // _APG_CFG_ACHAR = 1
typedef unsigned short int apg_achar; // _APG_CFG_ACHAR = 2
typedef unsigned int       apg_achar; // _APG_CFG_ACHAR = 4
typedef unsigned long int  apg_achar; // _APG_CFG_ACHAR = 8
typedef unsigned char      apg_achar; // (default) _APG_CFG_ACHAR undefined or defined as some value other than 1, 2, 4 or 8.

Similarly, the size of the unsigned integer, apg_uint, ubiquitously used by APG, can be controlled here as well. (Sizes less than 4 are risky and should be avoided. The full range is given here for completness.)

typedef unsigned char      apg_uint; // _APG_CFG_UINT = 1
typedef unsigned short int apg_uint; // _APG_CFG_UINT = 2
typedef unsigned int       apg_uint; // _APG_CFG_UINT = 4
typedef unsigned long int  apg_uint; // _APG_CFG_UINT = 8
typedef unsigned int       apg_uint; // (default) _APG_CFG_UINT undefined or defined as some value other than 1, 2, 4 or 8.

In this regard, also note that APG code rather fastidiously adheres to use of the following Hungarian notation for variable and function names:

prefix - type
c      - char
cp     - char*
ac     - apg_achar
acp    - apg_achar*
ui     - apg_uint
uip    - apg_uint*
v      - void
vp     - void*
s      - struct/union
sp     - pointer to struct/union

A second important set of configuration #define macros are _APG_CFG_DEBUG, _APG_CFG_TRACE and _APG_CFG_STATS.

_APG_CFG_DEBUG is really a legacy macro whose usefullness is minor. In Version 6.3 it serves only as a shorthand way to simultaneously define the other two, _APG_CFG_TRACE and _APG_CFG_STATS. (In previous versions it also defined a debug assertion macro. This has been removed because of some complications it caused in multi-threaded applications.)

_APG_CFG_TRACE must be defined in order to enable tracing. The reason for doing it this way is because tracing seriously impacts the parser's performance and forces the inclusion of the IO library functions into the libary. When this macro is not defined, the tracing code is not compiled or included in the library, resulting in not only better preformance but a significanly smaller footprint.

For simialar reasons, _APG_CFG_STATS must be defined to enable the collection of parsing statistics. Statistics collection can be vitally important when optimizing a parser, especially through the use of UDTs, but usually serves no purpose in a release or production version.

Definition in file Apg.h.

Macro Definition Documentation

◆ APG_DISPLAY_MAX_LINE

#define APG_DISPLAY_MAX_LINE   128

The max line length in trace and AST record output.

Definition at line 267 of file Apg.h.

◆ APG_FALSE

#define APG_FALSE   0

An APG-specific false value

Definition at line 190 of file Apg.h.

◆ APG_INFINITE

#define APG_INFINITE   -1

Often used to indicate an infinite value for an apg_uint integer.

While practically insignificant, note that in this regard the useful maximum value for apg_uint integers is reduced by one.

Definition at line 199 of file Apg.h.

◆ APG_TRUE

#define APG_TRUE   1

An APG-specific true value

Definition at line 187 of file Apg.h.

◆ APG_UNDEFINED

#define APG_UNDEFINED   -1

Often used to indicate an undefined value for an apg_uint integer.

While practically insignificant, note that in this regard the useful maximum value for apg_uint integers is reduced by one.

Definition at line 194 of file Apg.h.

◆ APG_VEC_ALLOC

#define APG_VEC_ALLOC   ((apg_uint)100)

The default initial number of vector elements allocated.

See also
vpVecCtor()

Definition at line 265 of file Apg.h.

◆ APG_VEC_ELEMENT

#define APG_VEC_ELEMENT   ((apg_uint)1)

The default vector element size (bytes.)

See also
vpVecCtor()

Definition at line 261 of file Apg.h.

◆ EMPTY

#define EMPTY   ((apg_uint)2)

The uiState value passed to callback functions by uiParserSyntaxAnalysis() to indicate the post-parse or upward traversal of a syntax tree node when an empty phrase has been matched.

See also
APG_CBDATA
APG_CALLBACK
uiParserSyntaxAnalysis()

Definition at line 538 of file Apg.h.

◆ MATCH

#define MATCH   ((apg_uint)3)

The uiState value passed to callback functions by uiParserSyntaxAnalysis() to indicate the post-parse or upward traversal of a syntax tree node when a non-empty phrase has been matched.

See also
APG_CBDATA
APG_CALLBACK
uiParserSyntaxAnalysis()

Definition at line 544 of file Apg.h.

◆ max

#define max (   a,
 
)    (((a) > (b)) ? (a) : (b))

maximum macro - defined here because it is non-ANSI.

Definition at line 298 of file Apg.h.

◆ min

#define min (   a,
 
)    (((a) < (b)) ? (a) : (b))

minimum macro - defined here because it is non-ANSI.

Definition at line 296 of file Apg.h.

◆ NOMATCH

#define NOMATCH   ((apg_uint)1)

The uiState value passed to callback functions by uiParserSyntaxAnalysis() to indicate the post-parse or upward traversal of a syntax tree node when no phrase has been matched.

See also
APG_CBDATA
APG_CALLBACK
uiParserSyntaxAnalysis()

Definition at line 532 of file Apg.h.

◆ POST_AST

#define POST_AST   ((apg_uint)5)

The uiState value passed to callback functions by uiParserAstTranslate() to indicate the upward traversal of an AST node.

See also
APG_CBDATA
APG_CALLBACK
uiParserAstTranslate()

Definition at line 556 of file Apg.h.

◆ PRE_AST

#define PRE_AST   ((apg_uint)4)

The uiState value passed to callback functions by uiParserAstTranslate() to indicate the downward traversal of an AST node.

See also
APG_CBDATA
APG_CALLBACK
uiParserAstTranslate()

Definition at line 550 of file Apg.h.

◆ PRE_PARSE

#define PRE_PARSE   ((apg_uint)0)

The uiState value passed to callback functions by uiParserSyntaxAnalysis() to indicate the pre-parse or downward traversal of a syntax tree node.

See also
APG_CBDATA
APG_CALLBACK
uiParserSyntaxAnalysis()

Definition at line 526 of file Apg.h.

Typedef Documentation

◆ apg_achar

typedef unsigned char apg_achar

apg_achar defines the APG alphabet character code. It may be 1, 2, 4 or 8 bytes long.

Definition at line 183 of file Apg.h.

◆ APG_CALLBACK

typedef apg_uint(* APG_CALLBACK) (APG_CBDATA *spData)

Prototype of all user-written callback functions. It is the same for rule and UDT callback functions and for syntax and semantic analysis.

The interpretation of some data structure variables are somewhat different in each of the different cases. While this has been done for program development convenience, it can be confusing to the user in practice. Therefore, each of the four cases is descibed separately. Also, see Callbacks.c in the Demo example for explict examples how to write the callback functions in each case and initialize the Parser so that it will call them.

Only the uiState, uiPhraseLength and return values differ. For all other data variables refer to APG_CBDATA.

  1. Rule Syntax Callback eg.
    apg_uint MySyntaxRuleCallback(APG_CBDATA spData);
    See also
    Callbacks.c in the Demo example for examples of usage.
    uiParserSyntaxInitCallbacks()
    uiParserSyntaxAnalysis()
    Parameters
    uiStateone of PRE_PARSE, EMPTY, MATCH, NOMATCH indicating the parser state prior to phrase matching or the state following phrase matching
    uiPhraseLengthinput: (from Parser) the length of the matched phrase, if any
    output: (if overriding the Parser, ie. returning true) >= 0 for matched phrase, APG_UNDEFINED for no matched phrase
    Returns
    true if this result is to override the Parser's result, false to continue with the normal parsing
  2. Rule Semantic Callback eg.
    apg_uint MySemanticRuleCallback(APG_CBDATA spData);
    See also
    Callbacks.c in the Demo example for examples of usage.
    vParserAstInitCallbacks()
    uiParserAstTranslate()
    Parameters
    uiStateone of PRE_AST, POST_AST indicating before the AST node traversal (downward direction node visit) or after AST node traversal (upward directionnode visit).
    uiPhraseLengththe length of the matched phrase. Note that a phrase has always been matched for this node or it wouldn't be in the AST.
    Returns
    ignored by Parser
  3. UDT Syntax Callback eg.
    apg_uint MySyntaxUdtCallback(APG_CBDATA spData);
    See also
    Callbacks.c in the Demo example for examples of usage.
    uiParserSyntaxInitCallbacks()
    uiParserSyntaxAnalysis()
    Parameters
    uiStatePRE_PARSE only. UDTs are terminals and are only traversed once from the downward direction.
    uiPhraseLengthuser must set this to 0 if an empty phrase is matched, > 0 if a non-empty phrase is matched or APG_UNDEFINED if no phrase is matched. Note that only UDTs whose names begin with "e_" may return 0. If a "u-" named UDT returns 0 the Parser will fail.
    Returns
    ignored by Parser
  4. UDT Semantic Callback eg.
    apg_uint MySemanticUdtCallback(APG_CBDATA spData);
    See also
    Callbacks.c in the Demo example for examples of usage.
    vParserAstInitCallbacks()
    uiParserAstTranslate()
    Parameters
    uiStateone of PRE_AST or POST_AST indicating a pre-branch (downward direction) traversal or a post-branch (upward direction) traversal of the node.
    uiPhraseLengththe length of the matched phrase. Note that a phrase has always been matched for this node or it wouldn't be in the AST.
    Returns
    ignored by Parser

Definition at line 515 of file Apg.h.

◆ apg_uint

typedef unsigned int apg_uint

apg_uint defines the APG integer. It may be 1, 2, 4 or 8 bytes long. (1 and 2 not recommended)

Definition at line 169 of file Apg.h.

◆ PFN_ALERT

typedef void(* PFN_ALERT) (unsigned int uiLine, const char *cpFile)

Defines the function type for handling alerts with line number and file name.

Parameters
uiLinethe line number where the alert was generated.
cpFilename of the file where the alert was generated.
See also
vTerminalAlert()

Definition at line 276 of file Apg.h.

◆ PFN_ALERT_MSG

typedef void(* PFN_ALERT_MSG) (unsigned int uiLine, const char *cpFile, const char *cpMsg)

Defines the function type for handling alerts with line number, file name and a dexcriptive message.

Parameters
uiLinethe line number where the alert was generated.
cpFilename of the file where the alert was generated.
cpMsga descriptive message for the alert that was generated.
See also
vTerminalAlertMsg()

Definition at line 282 of file Apg.h.

◆ PFN_ALLOCATOR

typedef void*(* PFN_ALLOCATOR) (size_t)

the type required of any user-supplied memory allocator. The default allocator is malloc().

Definition at line 371 of file Apg.h.

◆ PFN_DEALLOCATOR

typedef void(* PFN_DEALLOCATOR) (void *)

the type required of any user-supplied memory de-allocator. The default de-allocator is free().

Definition at line 373 of file Apg.h.

Function Documentation

◆ apg_stricmp()

int apg_stricmp ( const char *  cpLhs,
const char *  cpRhs 
)

Case-insensitive: compares two strings. The two strings are compared, character for character. NOTE: stricmp() is non-ANSI and therefore, not used

Parameters
cpLhspointer to the left of the two strings to compare
cpRhspointer to the right of the two strings to compare
Returns
0 if the two strings are case-insensitively equal
-1 if the left string is less than the right string
+1 if the left string is greater than the right string

Definition at line 46 of file Tools.c.

◆ uiACharToString()

apg_uint uiACharToString ( char *  cpChars,
apg_uint  uiCLen,
const apg_achar acpAChars,
apg_uint  uiALen 
)

Converts a string of apg_achar characters to a null-terminated printable ASCII string. Non-printing characters are of the form: <xFF>. Brackets are used to distinguish the hex format from adjacent printing characters of "x" and "F", for example. The worst case scenario is that all translated characters will be of the form <xFF>, where sizeof(apg_achar) is 1 for example. To be safe, the cpChars buffer size, uiCLen, should be at least: uiALen * ((sizeof(apg_achar) * 2) + 3) plus 1 for terminating null. To get the exact size in advance, see uiACharToStringSize().

Parameters
cpCharspointer to the buffer to receive the printable, 8-bit character string
uiCLenlength of the cpChars buffer
acpACharspointer the apg_achar character string
uiALenthe number of apg_achar characters
See also
uiACharToStringSize()
Returns
the number of apg_achar characters translates. If < uiAlen, the translation was truncated due to insufficient buffer length, uiCLen

Converts a string of alphabet characters to a null-terminated printable ASCII string. Non-printing characters are of the form: <xFF>. Brackets are used to distinguish the hex format from adjacent printing characters of "x" and "F", for example. The worst case scenario is that all translated characters will be of the form <xFF>, where sizeof(apg_achar) is 1 for example. To be safe, the cpChars buffer size, uiCLen, should be at least: uiALen * ((sizeof(apg_achar) * 2) + 3) plus 1 for terminating null. To get the exact size in advance, see uiACharToStringSize().

Parameters
cpCharspointer to the buffer to receive the printable, 8-bit character string
uiCLenlength of the cpChars buffer
acpACharspointer the apg_achar character string
uiALenthe number of apg_achar characters
See also
uiACharToStringSize()
Returns
the number of apg_achar characters translated. If < uiAlen, the translation was truncated due to insufficient buffer length, uiCLen

Definition at line 197 of file Tools.c.

◆ uiACharToStringSize()

apg_uint uiACharToStringSize ( const apg_achar acpAChars,
apg_uint  uiALen 
)

Calculate the size of the string translated by uiACharToString()

Parameters
acpACharspointer the apg_achar character string
uiALenthe number of apg_achar characters
See also
uiACharToString()
Returns
the calculated size

Definition at line 165 of file Tools.c.

◆ uiMemCheckPoint()

apg_uint uiMemCheckPoint ( void *  vpCtx)

Returns a check point to the current state of the memory component. Can be used later to restore the current state.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA().
See also
vpMemCtor()
vpMemCtorA()
vMemFreeToCheckPoint()
Returns
current state

Definition at line 230 of file Memory.c.

◆ uiMemValidate()

apg_uint uiMemValidate ( void *  vpCtx)

Validates a Memory context handle.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA().
See also
vpMemCtor()
vpMemCtorA()
Returns
true if the handle is valid, false otherwise.

Definition at line 115 of file Memory.c.

◆ uiParserAstTranslate()

apg_uint uiParserAstTranslate ( void *  vpCtx,
APG_CALLBACK pfnRuleCallbacks,
APG_CALLBACK pfnUdtCallbacks,
void *  vpData 
)

Translates an AST.

Translation is done via user-written callback functions assigned to the AST nodes. The callback functions may be defined with a previous call to vParserAstInitCallbacks() or may be assigned/overridden here. A "depth first" traversal of the AST is done. The callback function defined for each node is called twice. Once on the downward traversal (PRE_AST) of the node and again later on the upward traversal (POST_AST) of the node.

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
pfnRuleCallbackspointer to an array of rule name callback function pointers. May be NULL. Will override any functions previously assigned in a call to vParserAstInitCallbacks().
pfnUdtCallbackspointer to an array of UDT callback function pointers. May be NULL. Will override any functions previously assigned in a call to vParserAstInitCallbacks().
vpDatauser-defined data to be passed to the callback functions. May be NULL. Ignored by Parser.
See also
vpParserCtor()
vParserAstInitCallbacks()
PRE_AST
POST_AST
Returns
the number of callback functions defined for which no AST node records have been collected. If non-zero, this is a warning user may want to re-define some of the callback functions

Definition at line 361 of file Parser.c.

◆ uiParserState()

apg_uint uiParserState ( void *  vpCtx,
APG_PARSER_STATE spState 
)

Returns the parser state. Only meaningful after a call to uiParserSyntaxAnalysis().

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
spStatepointer to a user-supplied APG_PARSER_STATE struct.
See also
vpParserCtor()
uiParserSyntaxAnalysis()
Returns
true if the parser state uiSuccess is true. false otherwise.

Definition at line 379 of file Parser.c.

◆ uiParserStatsEnable()

apg_uint uiParserStatsEnable ( void *  vpCtx,
apg_uint  uiEnable 
)

Enables/disables collection of parser statistics.

Statistics gathering will negatively affect the parser's performance. Therefore, statistics gathering is disabled by default.

Note: a call to this function will have no affect unless _APG_CFG_STATS is defined.

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
uiEnabletrue if statistics gathering is to be enabled, false to disable (default.)
See also
vpParserCtor()
uiParserStatsGet()
_APG_CFG_STATS in the configuration of Apg.h.
Returns
true if _APG_CFG_STATS has been defined in Apg.h, false otherwise.

Definition at line 403 of file Parser.c.

◆ uiParserStatsGet()

apg_uint uiParserStatsGet ( void *  vpCtx,
APG_PARSER_STATS spStats,
apg_uint uipBufferSize 
)

Retrieve the statistics collected by uiParserSyntaxAnalysis().

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
spStatspointer to a user-supplied statistics data buffer. If NULL, only the required buffer size is returned.
uipBufferSizepointer to the variable to receive the required buffer size.
See also
vpParserCtor()
uiParserStatsEnable()
vDisplayOperatorStats()
vDisplayRuleStats()
Returns
true if _APG_CFG_STATS has been defined in Apg.h, false otherwise.

Definition at line 422 of file Parser.c.

◆ uiParserSyntaxAnalysis()

apg_uint uiParserSyntaxAnalysis ( void *  vpCtx,
apg_uint  uiStartRule,
const apg_achar acpSrc,
apg_uint  uiSrcLen,
void *  vpData 
)

Parses an input string of alphabet characters.

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
uiStartRuleindex of the grammar rule to be used as the start rule. 0 will always be the index of the first rule defined by the grammar. Good usage practice is to always use an index defined in the ProjectName.h header file generated by apg, the parser generator. This will be a #define of the form "RULE_PROJECTNAME_RULENAME".
acpSrcpointer to the array of alphabet character codes defining the string to be parsed.
uiSrcLenthe number of alphabet characters in the input string.
vpDataoptional pointer to user-defined data. This pointer, which may be NULL, will be passed on to the user-defined callback functions. It will be the vpUserData member of the APG_CBDATA structs passed to the callback functions. It is otherwise ignored by the parser.
See also
vpParserCtor()
uiParserState()
APG_CALLBACK
APG_CBDATA
Returns
true if the parser accepted all characters in the input string. false otherwise. It is the same as the uiSuccess variable in the APG_PARSER_STATE struct.

Definition at line 228 of file Parser.c.

◆ uiParserSyntaxInitCallbacks()

apg_uint uiParserSyntaxInitCallbacks ( void *  vpCtx,
APG_CALLBACK spRuleCallbacks,
APG_CALLBACK spUdtCallbacks 
)

Defined the syntax callback functions to the parser.

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
spRuleCallbacksan array of pointers to the rule callback functions. May be NULL.
spUdtCallbacksan array of pointers to the UDT callback functions, if any. May be NULL if the grammar defines no UDTs. Each UDT defined in the grammar must have a callback function defined here. Otherwise, this function will return false and the parser syntax analysis will fail.
See also
vpParserCtor()
uiParserSyntaxAnalysis()
Returns
true if all UDTs defined in the grammar have a callback function defined here. false otherwise.

Definition at line 187 of file Parser.c.

◆ uiParserTraceEnable()

apg_uint uiParserTraceEnable ( void *  vpCtx,
apg_uint  uiEnable 
)

Enables/disables tracing.

Tracing will negatively affect the parser's performance. Therefore, tracing is disabled by default.

If tracing is enabled, trace records will be printed to the standard output as the parser traverses the syntax tree. By default, records are printed only for rule and UDT nodes (RNM and UDT.) However, prior to parsing, tracing can be configured to trace or not trace any type of node. For tracing other than the default nodes:

See also
vParserTraceOp()
vParserTraceRule()
vParserTraceUdt()
vParserTraceRange()

Note: a call to this function will have no affect unless _APG_CFG_TRACE is defined.

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
uiEnableif true, enables tracing, if false, disables tracing
See also
vpParserCtor()
uiParserStatsEnable()
Returns
true if _APG_CFG_TRACE has been defined in Apg.h, false otherwise.

Definition at line 452 of file Parser.c.

◆ uiUdtLib_e_any()

apg_uint uiUdtLib_e_any ( APG_CBDATA spData)

Phrase recognizer for a string of any printing characters, including TAB.

Equivalent SABNF syntax:

ANY = *(%d9 / %d32-127)
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 337 of file UdtLib.c.

◆ uiUdtLib_e_owsp()

apg_uint uiUdtLib_e_owsp ( APG_CBDATA spData)

Phrase recognizer for optional white space

Equivalent SABNF syntax:

WSP   = *(TAB / SPACE)
TAB   = %d9
SPACE = %d32

NOTE: see UdtLib.c for the static function uiWsp() for more options. Line continuations and various types of comments may also be easily included as white space.

Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 280 of file UdtLib.c.

◆ uiUdtLib_u_alphanum()

apg_uint uiUdtLib_u_alphanum ( APG_CBDATA spData)

Phrase recognizer for an alphanumeric string.

Equivalent SABNF syntax:

ALPHANUM = ALPHA *(ALPHA / DIGIT)
ALPHA    = %d65-90 / %d97-122
DIGIT    = %d48-57
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 414 of file UdtLib.c.

◆ uiUdtLib_u_alphanum_hyphen()

apg_uint uiUdtLib_u_alphanum_hyphen ( APG_CBDATA spData)

Phrase recognizer for an alphanumeric string, including hyphen.

Equivalent SABNF syntax:

ALPHANUM = ALPHA *(ALPHA / DIGIT / HYPHEN)
ALPHA    = %d65-90 / %d97-122
DIGIT    = %d48-57
HYPHEN   = %d45
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 434 of file UdtLib.c.

◆ uiUdtLib_u_alphanum_under()

apg_uint uiUdtLib_u_alphanum_under ( APG_CBDATA spData)

Phrase recognizer for an alphanumeric string, including underscore.

Equivalent SABNF syntax:

ALPHANUM = ALPHA *(ALPHA / DIGIT / UNDER)
ALPHA    = %d65-90 / %d97-122
DIGIT    = %d48-57
UNDER    = %d95
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 454 of file UdtLib.c.

◆ uiUdtLib_u_c_comment()

apg_uint uiUdtLib_u_c_comment ( APG_CBDATA spData)

Phrase recognizer for a C-style comment. Comment runs from "/ *" to "* /".

Equivalent SABNF syntax:

CCOMMENT = BEGIN *(!END ANY) END
BEGIN    = %d47.42
END      = %d42.47
ANY      = TAB / CR / LF / %d32-127
TAB      = %d9
LF       = %d10
CF       = %d13
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 395 of file UdtLib.c.

◆ uiUdtLib_u_cpp_comment()

apg_uint uiUdtLib_u_cpp_comment ( APG_CBDATA spData)

Phrase recognizer for a C++-style comment. Comment runs from "//" to end of line.

Equivalent SABNF syntax:

CPPCOMMENT = "//" ANY
ANY        = *(%d9 / %d32-127)
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 372 of file UdtLib.c.

◆ uiUdtLib_u_decnum()

apg_uint uiUdtLib_u_decnum ( APG_CBDATA spData)

Phrase recognizer for a decimal number.

Equivalent SABNF syntax:

DECNUM = 1*DIGIT
DIGIT  = %d48-57
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 472 of file UdtLib.c.

◆ uiUdtLib_u_doublequotedstring()

apg_uint uiUdtLib_u_doublequotedstring ( APG_CBDATA spData)

Phrase recognizer for a double-quoted string, a string beginning and ending with a double quote (").

Equivalent SABNF syntax:

DOUBLEQUOTE = %d34 *(%d9 / %d32-33 / %d35-127) %d34
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 561 of file UdtLib.c.

◆ uiUdtLib_u_hexnum()

apg_uint uiUdtLib_u_hexnum ( APG_CBDATA spData)

Phrase recognizer for a hexidecimal number.

Equivalent SABNF syntax:

HEXNUM   = "0x" 1*HEXDIGIT
HEXDIGIT = %d48-57 / %d65-70 / %d97-102
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 495 of file UdtLib.c.

◆ uiUdtLib_u_lineend()

apg_uint uiUdtLib_u_lineend ( APG_CBDATA spData)

Phrase recognizer for line ending. This is a "forgiving" line end allowing for the most commonly used values.

Equivalent SABNF syntax:

LINEEND = CR LF / CR / LF
CR      = %d13
LF      = %d10
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 320 of file UdtLib.c.

◆ uiUdtLib_u_quotedstring()

apg_uint uiUdtLib_u_quotedstring ( APG_CBDATA spData)

Phrase recognizer for a quoted string, a string beginning and ending with a single (') or double (") quote.

Equivalent SABNF syntax:

QUOTEDSTRING = SINGLEQUOTE / DOUBLEQUOTE
SINGLEQUOTE  = %d39 *(%d9 / %d32-38 / %d40-127) %d39
DOUBLEQUOTE  = %d34 *(%d9 / %d32-33 / %d35-127) %d34
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 525 of file UdtLib.c.

◆ uiUdtLib_u_semi_comment()

apg_uint uiUdtLib_u_semi_comment ( APG_CBDATA spData)

Phrase recognizer for a semicolon initialized comment. Comment runs from semicolon to end of line.

Equivalent SABNF syntax:

SEMICOMMENT = ";" ANY
ANY         = *(%d9 / %d32-127)
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 354 of file UdtLib.c.

◆ uiUdtLib_u_singlequotedstring()

apg_uint uiUdtLib_u_singlequotedstring ( APG_CBDATA spData)

Phrase recognizer for a single-quoted string, a string beginning and ending with a single quote (').

Equivalent SABNF syntax:

SINGLEQUOTE = %d39 *(%d9 / %d32-38 / %d40-127) %d39
Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 544 of file UdtLib.c.

◆ uiUdtLib_u_wsp()

apg_uint uiUdtLib_u_wsp ( APG_CBDATA spData)

Phrase recognizer for required white space

Equivalent SABNF syntax:

WSP   = 1*(TAB / SPACE)
TAB   = %d9
SPACE = %d32

NOTE: see UdtLib.c for the static function uiWsp() for more options. Line continuations and various types of comments may also be easily included as white space.

Parameters
spDatadata struct passed to this function by the Parser
Returns
0 - return ignored by Parser

Definition at line 301 of file UdtLib.c.

◆ uiVecBytes()

apg_uint uiVecBytes ( void *  vpCtx)

Gets the number of bytes of data in use.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor(). NULL or invalid handles are silently ignored.
See also
vpVecCtor()
Returns
the size in bytes of the data in use. May be smaller than the size of the allocation.

Definition at line 152 of file Vector.c.

◆ uiVecElementSize()

apg_uint uiVecElementSize ( void *  vpCtx)

Gets the size of a single element.

Note that:
uiVecBytes() = uiVecElementSize() * uiVecSize().

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor(). NULL or invalid handles are silently ignored.
See also
vpVecCtor()
Returns
the number of bytes in a single element.

Definition at line 185 of file Vector.c.

◆ uiVecReallocations()

apg_uint uiVecReallocations ( void *  vpCtx)

Gets the number times the array memory has been reallocated.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor().
See also
vpVecCtor()
Returns
the number times the array memory has been reallocated.

Definition at line 200 of file Vector.c.

◆ uiVecSize()

apg_uint uiVecSize ( void *  vpCtx)

Gets the number of array elements in use.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor(). NULL or invalid handles are silently ignored.
See also
vpVecCtor()
Returns
the number of vector array elements in use. May be smaller than the number that have been allocated.

Definition at line 167 of file Vector.c.

◆ uiVecValidate()

apg_uint uiVecValidate ( void *  vpCtx)

Validates a Vector component handle.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor(). NULL or invalid handles are silently ignored.
See also
vpVecCtor()
Returns
true if the handle is valid, false otherwise.

Definition at line 142 of file Vector.c.

◆ vCharToAChar()

void vCharToAChar ( apg_achar acpAChars,
const char *  cpChars,
apg_uint  uiLen 
)

Convert an ASCII, 8-bit character string to an apg_achar character string.

Parameters
acpACharspointer the destination or apg_achar character string
cpCharspointer to the 8-bit character string to convert
uiLenthe number of characters to convert

Convert an ASCII, 8-bit character string to an apg_achar character string.

Parameters
acpACharspointer to the apg_achar character string
cpCharspointer to the 8-bit character string to convert
uiLenthe number of characters to convert

Definition at line 79 of file Tools.c.

◆ vDefaultAlertHandler()

void vDefaultAlertHandler ( unsigned int  uiLine,
const char *  cpFile 
)

The default alert handler. (Simply exits the program.)

Parameters
uiLinethe line number where the alert was generated.
cpFilename of the file where the alert was generated.

Definition at line 33 of file Tools.c.

◆ vExecuteRule()

void vExecuteRule ( APG_CBDATA spData,
apg_uint  uiId,
apg_uint  uiOffset 
)

To be called only from callback functions. Executes the specified rule as if it were the following node in the syntax tree.

Parameters
spDatathe data supplied to the callback function by the parser
uiIdindex of the rule to execute
uiOffsetoffset into the input string of the first character of the phrase to match
See also
APG_CALLBACK

Definition at line 537 of file Parser.c.

◆ vExecuteUdt()

void vExecuteUdt ( APG_CBDATA spData,
apg_uint  uiId,
apg_uint  uiOffset 
)

To be called only from callback functions. Executes the specified UDT as if it were the following node in the syntax tree.

Parameters
spDatathe data supplied to the callback function by the parser
uiIdindex of the UDT to execute
uiOffsetoffset into the input string of the first character of the phrase to match
See also
APG_CALLBACK

Definition at line 559 of file Parser.c.

◆ vMemClear()

void vMemClear ( void *  vpCtx)

Frees all memory allocations from this Memory component.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA(). NULL pointers are silently ignored.
See also
vpMemCtor()
vpMemCtorA()

Definition at line 277 of file Memory.c.

◆ vMemDtor()

void vMemDtor ( void *  vpCtx)

Destroys a Memory component.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA(). NULL pointers are silently ignored.
See also
vpMemCtor()
vpMemCtorA()

Definition at line 97 of file Memory.c.

◆ vMemFree()

void vMemFree ( void *  vpCtx,
void *  vpData 
)

De-allocates memory previously allocated with vpMemAlloc().

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA(). NULL pointers are silently ignored.
vpDatapointer to the memory allocation to free. If NULL, silently ignored.
See also
vpMemCtor()
vpMemCtorA()
vpMemAlloc()

Definition at line 157 of file Memory.c.

◆ vMemFreeToCheckPoint()

void vMemFreeToCheckPoint ( void *  vpCtx,
apg_uint  uiChk 
)

Restores a previous state of the Memory component.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA(). NULL pointers are silently ignored.
uiChkthe previous state to restore. Must be from a previous call to uiMemCheckPoint().
See also
vpMemCtor()
vpMemCtorA()
uiMemCheckPoint()

Definition at line 250 of file Memory.c.

◆ vParserAstInitCallbacks()

void vParserAstInitCallbacks ( void *  vpCtx,
APG_CALLBACK pfnRuleCallbacks,
APG_CALLBACK pfnUdtCallbacks 
)

Defines which rule/UDT nodes are to be assigned callback functions in the AST.

These functions need only be assigned if translation with the function uiParserAstTranslate() is to be used.

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
pfnRuleCallbackspointer to an array of rule name callback function pointers. May be NULL.
pfnUdtCallbackspointer to an array of UDT callback function pointers. May be NULL.
See also
vpParserCtor()
uiParserAstTranslate()

Definition at line 316 of file Parser.c.

◆ vParserAstInitNodes()

void vParserAstInitNodes ( void *  vpCtx,
apg_uint uipRules,
apg_uint uipUdts 
)

Defines which rule/UDT names are to be kept as nodes in the Abstract Syntax Tree (AST).

Note that defining the nodes to be kept is a separate issue from defining which nodes have callback functions. The AST nodes may or may not be used for translation.

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
uipRulespointer to an array of integers defining the rule indexes of the rule name nodes to be kept in the AST. May be NULL.
uipUdtspointer to an array of integers defining the UDT indexes of the UDT nodes to be kept in the AST. May be NULL.
See also
vpParserCtor()
uiParserAstTranslate()
uiAstToXml()

Definition at line 283 of file Parser.c.

◆ vParserDtor()

void vParserDtor ( void *  vpCtx)

Parser component destructor

Parameters
vpCtxpointer to parser component context (returned from vpParserCtor())
See also
vpParserCtor()

Definition at line 168 of file Parser.c.

◆ vParserTraceOp()

void vParserTraceOp ( void *  vpCtx,
apg_uint  uiOpId,
apg_uint  uiEnable 
)

Configures the types of operator nodes to trace.

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
uiOpIdshould be one of the following:
APG_TRACE_ALL - trace all operator nodes
APG_TRACE_TRG - trace the TRG nodes
APG_TRACE_TBS - trace the TBS nodes
APG_TRACE_TLS - trace the TLS nodes
APG_TRACE_AND - trace the AND nodes
APG_TRACE_NOT - trace the NOT nodes
APG_TRACE_ALT - trace the ALT nodes
APG_TRACE_CAT - trace the CAT nodes
APG_TRACE_REP - trace the REP nodes
APG_TRACE_RNM - trace the RNM nodes
APG_TRACE_UDT - trace the UDT nodes
APG_TRACE_COUNT - count the trace records only, none are printed
uiEnableif true, the specified operators are printed, if false, not
See also
vpParserCtor()
uiParserTraceEnable()

Definition at line 482 of file Parser.c.

◆ vParserTraceRange()

void vParserTraceRange ( void *  vpCtx,
apg_uint  uiBegin,
apg_uint  uiCount 
)

Configures the trace record range to print.

Trace records can be voluminous. This configuration can reduce the number printed to a managable set. In this context, it may be useful to first trace the parse with APG_TRACE_COUNT configured in vParserTraceOp().

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
uiBeginthe record number of the first trace record to print
uiCountthe number of trace records to print
See also
vpParserCtor()
uiParserTraceEnable()

Definition at line 524 of file Parser.c.

◆ vParserTraceRule()

void vParserTraceRule ( void *  vpCtx,
apg_uint  uiIndex,
apg_uint  uiEnable 
)

Configures which rule names to trace. By default all rule names are traced.

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
uiIndexrule index of the rule name to trace
uiEnableif true, the specified rule name records are printed, if false, not
See also
vpParserCtor()
uiParserTraceEnable()

Definition at line 495 of file Parser.c.

◆ vParserTraceUdt()

void vParserTraceUdt ( void *  vpCtx,
apg_uint  uiIndex,
apg_uint  uiEnable 
)

Configures which UDT names to trace. By default all UDT names are traced.

Parameters
vpCtxpointer to a parser context, returned by vpParserCtor().
uiIndexUDT index of the UDT name to trace
uiEnableif true, the specified UDT name records are printed, if false, not
See also
vpParserCtor()
uiParserTraceEnable()

Definition at line 508 of file Parser.c.

◆ vpMemAlloc()

void* vpMemAlloc ( void *  vpCtx,
apg_uint  uiBytes 
)

Allocates memory.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA().
uiBytesthe number of bytes of memory to allocate
See also
vpMemCtor()
vpMemCtorA()
vMemFree()
Returns
a pointer to the allocated memory, NULL on allocation failure.

Definition at line 130 of file Memory.c.

◆ vpMemCtor()

void* vpMemCtor ( )

Constructs a Memory component using malloc() as the memory allocator and free() as the de-allocator.

Returns
a Memory context handle (void pointer to an opaque data struct). NULL on failure.

Definition at line 77 of file Memory.c.

◆ vpMemCtorA()

void* vpMemCtorA ( PFN_ALLOCATOR  pfnAllocator,
PFN_DEALLOCATOR  pfnDeAllocator 
)

Constructs a Memory component using a user-defined memory allocator and de-allocator.

Parameters
pfnAllocatorpointer to a user-defined memory allocator
pfnDeAllocatorpointer to a user-defined memory de-allocator
Returns
a Memory context handle (void pointer to an opaque data struct). NULL on failure.

Definition at line 56 of file Memory.c.

◆ vpMemRealloc()

void* vpMemRealloc ( void *  vpCtx,
void *  vpData,
apg_uint  uiBytes 
)

Re-allocates memory previously allocated with vpMemAlloc(). Can be used to up-size or down-size a memory allocation. Any previous data in the memory allocation is copied to the re-allocation.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA().
vpDatapointer to the memory to be re-allocated.
uiBytesnumber of re-allocated bytes of memory.
See also
vpMemCtor()
vpMemCtorA()
vpMemAlloc()()
Returns
pointer to the re-allocated memory. NULL if re-allocation failed.

Definition at line 182 of file Memory.c.

◆ vpParserCtor()

void* vpParserCtor ( void *  vpParserInit,
PFN_ALERT  pfnAlertHandler 
)

Construct a new APG parser component.

Parameters
vpParserInitthe initialization data from APG
pfnAlertHandlerthe alert handler, called on terminal errors. NULL for default alert handler.
See also
vParserDtor()
Returns
pointer to a parser component context.

Definition at line 58 of file Parser.c.

◆ vpVecAt()

void* vpVecAt ( void *  vpCtx,
apg_uint  uiIndex 
)

Get a the indexed element in the array. The array is not altered.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor().
uiIndexthe index of the element to get (0-based)
See also
vpVecCtor()
Returns
a pointer to the indexed element in the array. NULL if the array is empty or the index is out of range.

Definition at line 433 of file Vector.c.

◆ vpVecBack()

void* vpVecBack ( void *  vpCtx)

Get a the last element in the array. The array is not altered.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor().
See also
vpVecCtor()
Returns
a pointer to the last element in the array. NULL if the array is empty.

Definition at line 414 of file Vector.c.

◆ vpVecCtor()

void* vpVecCtor ( void *  vpMemCtx,
apg_uint  uiElementSize,
apg_uint  uiInitialAlloc 
)

The Vector comonent constructor.

Parameters
vpMemCtxa Memory component context handle, previously returned from vpMemCtor().
uiElementSizesize, in bytes, of each array element. If 0, uses the default element size APG_VEC_ELEMENT.
uiInitialAllocnumber of elements to initially allocate. If 0, uses the default APG_VEC_ALLOC.
See also
vpMemCtor()
Returns
a Vector component context handle (a void pointer to an opaque data struct.) NULL on construction failure.

Definition at line 81 of file Vector.c.

◆ vpVecFront()

void* vpVecFront ( void *  vpCtx)

Get a the first element in the array. The array is not altered.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor().
See also
vpVecCtor()
Returns
a pointer to the first element in the array. NULL if the array is empty.

Definition at line 396 of file Vector.c.

◆ vpVecPop()

void* vpVecPop ( void *  vpCtx)

Pops one element from the end of the array.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor().
See also
vpVecCtor()
vpVecPopn()
vpVecPopTo()
vpVecPush()
vpVecPushn()
Returns
a pointer to the popped element. NULL if the Vector is empty.

Definition at line 315 of file Vector.c.

◆ vpVecPopn()

void* vpVecPopn ( void *  vpCtx,
apg_uint  uiCount 
)

Pops one or more elements from the end of the array.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor().
uiCountthe number of elements to pop.
See also
vpVecCtor()
vpVecPop()
vpVecPopTo()
vpVecPush()
vpVecPushn()
Returns
a pointer to the first popped element. NULL if the Vector is empty.

Definition at line 341 of file Vector.c.

◆ vpVecPopTo()

void* vpVecPopTo ( void *  vpCtx,
apg_uint  uiIndex 
)

Pops one or more elements from the end of the array.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor().
uiIndexindex of the first element to pop. Elements uiIndex and all higher indexed elements are popped.
See also
vpVecCtor()
vpVecPop()
vpVecPopn()
vpVecPush()
vpVecPushn()
Returns
a pointer to the first popped element. NULL if the Vector is empty or if uiIndex is larger than the largest indexed element in the array.

Definition at line 376 of file Vector.c.

◆ vpVecPush()

void* vpVecPush ( void *  vpCtx,
void *  vpElement 
)

Adds one element to the end of the array.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor().
vpElementpointer to the element to add. If NULL, space for a new element is added but no data is copied to it.
See also
vpVecCtor()
vpVecPushn()
vpVecPop()
vpVecPopn()
vpVecPopTo()
Returns
a pointer to the new element in the array. NULL on failure.

Definition at line 238 of file Vector.c.

◆ vpVecPushn()

void* vpVecPushn ( void *  vpCtx,
void *  vpElement,
apg_uint  uiCount 
)

Adds one or more elements to the end of the array.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor().
vpElementpointer to the first element to add. If NULL, space for the new elements is added but no data is copied to it.
uiCountthe number of elements to add.
See also
vpVecCtor()
vpVecPush()
vpVecPop()
vpVecPopn()
vpVecPopTo()
Returns
a pointer to the first new element in the array. NULL on failure.

Definition at line 276 of file Vector.c.

◆ vVecClear()

void vVecClear ( void *  vpCtx)

Clears all used elements in a Vector component.

This simply resents the current element pointer to zero. No data is actually deleted. No memory is released or re-allocated.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor(). NULL or invalid handles are silently ignored.
See also
vpVecCtor()

Definition at line 218 of file Vector.c.

◆ vVecDtor()

void vVecDtor ( void *  vpCtx)

The Vector component destructor. Frees all resouces allocated to this component.

Parameters
vpCtxa Vector component handle previously returned from vpVecCtor(). NULL or invalid handles are silently ignored.
See also
vpVecCtor()

Definition at line 123 of file Vector.c.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/licenses.html or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.