![]() |
librnr
1.14.5
RoadNarrows Robotics Common Library 1
|
Simple associative map data and operator declarations. More...
Go to the source code of this file.
Classes | |
| struct | Nvp_T |
| struct | AssocMapVoidPoint_T |
| struct | AssocMapVoidMapper_T |
Macros | |
| #define | AMAP_NAME Void |
| #define | _AMAP_NAME AMAP_NAME |
| assoc. map name | |
| #define | AMAP_XTYPE void * |
| default assoc. map x data type More... | |
| #define | AMAP_YTYPE void * |
| default assoc. map y data type | |
| #define | _AMAP_XTYPE AMAP_XTYPE |
| assoc. map x data type | |
| #define | _AMAP_YTYPE AMAP_YTYPE |
| assoc. map y data type | |
| #define | _CONCAT_(x, y) x ## y |
| build concatenation operator More... | |
| #define | _CONCAT(x, y) _CONCAT_(x, y) |
| now concatenate | |
| #define | _AMAP_DEFPREFACE _CONCAT(AssocMap, _AMAP_NAME) |
| AssocMap (base or derived) definition preface. | |
| #define | _AMAP_DEF(name) _CONCAT(_AMAP_DEFPREFACE, name) |
| AssocMap (base or derived) definition name. | |
| #define | _RNR_ASSOC_H |
| include base declaration only once More... | |
Typedefs | |
| typedef int(* | AssocMapVoidCmp_T) (void *t1, void *t2) |
| base associative map comparator function type | |
Functions | |
| int | NvpName2Val (Nvp_T tbl[], size_t nTblEntries, const char *sName) |
| Get the value associated with the name. More... | |
| const char * | NvpVal2Name (Nvp_T tbl[], size_t nTblEntries, int iVal) |
| Get the name associated with the value. More... | |
| void * | AssocMapVoidXtoY (AssocMapVoidMapper_T *pMapper, void *px) |
| Get the y value associated with the given x value. More... | |
| void * | AssocMapVoidYtoX (AssocMapVoidMapper_T *pMapper, void *py) |
| Get the x value associated with the given y value. More... | |
Simple associative map data and operator declarations.
These associative maps are composed of tables (vectors) of discrete (x, y) points where x and y may be of any data types.
The specific Nvp_T Name-Value Pair associative map point provides a char* <–> int mapping.
The more general associative mapping is provided by the AssocMap<x> declarations.
The general associative maps are configured to support a "poor man's" C version of class inheritance and templating.
The "base" set of void* data types and functions are AssocMapVoid<x> named definitions with data types returning void*. These definitions are defined in librnr.
A "derived" associative map can be defined using the following three #define's (usually in a header file). Follow these #defines with the inclusion of this header file (assoc.h):
Multiple assoc. maps derived types and the base type may be used in the same C source.
—
Definition in file assoc.h.
| #define _CONCAT_ | ( | x, | |
| y | |||
| ) | x ## y |
| #define _RNR_ASSOC_H |
| #define AMAP_NAME Void |
Define the associative namespace (must be literal).
If AMAP_NAME is defined then a new set of assoc. map data types and functions will be defined, prefaced by AssocMap<AMAP_NAME>.
If AMAP_NAME is not defined, then the base set prefaced by AssocMapVoid data types and functions will be used (already defined in librnr).base assoc. map name not a "derived" assoc. map
| #define AMAP_XTYPE void * |
default assoc. map x data type
Define the derived associative map x and y data types (must be literal).
AMAP_XTYPE defines the x data type. If not defined, then void* is used.
AMAP_YTYPE defines the y data type. If not defined, then void* is used.
| void* AssocMapVoidXtoY | ( | AssocMapVoidMapper_T * | pMapper, |
| void * | px | ||
| ) |
Get the y value associated with the given x value.
The table search terminates at the first match or at the end of the table.
| pMapper | Associative map mapper container. |
| px | Pointer to X value in table to find. |
Definition at line 123 of file assoc.c.
References CHKPTR, AssocMapVoidMapper_T::m_opXCmp, AssocMapVoidMapper_T::m_pMapDft, AssocMapVoidMapper_T::m_tblAssocMap, AssocMapVoidMapper_T::m_tblSize, NULL, AssocMapVoidPoint_T::x, and AssocMapVoidPoint_T::y.
| void* AssocMapVoidYtoX | ( | AssocMapVoidMapper_T * | pMapper, |
| void * | py | ||
| ) |
Get the x value associated with the given y value.
The table search terminates at the first match or at the end of the table.
| pMapper | Associative map mapper container. |
| py | Pointer to Y value in table to find. |
Definition at line 159 of file assoc.c.
References CHKPTR, AssocMapVoidMapper_T::m_opYCmp, AssocMapVoidMapper_T::m_pMapDft, AssocMapVoidMapper_T::m_tblAssocMap, AssocMapVoidMapper_T::m_tblSize, NULL, AssocMapVoidPoint_T::x, and AssocMapVoidPoint_T::y.
| int NvpName2Val | ( | Nvp_T | tbl[], |
| size_t | nTblEntries, | ||
| const char * | sName | ||
| ) |
Get the value associated with the name.
The table search terminates at the first match or at the end of nTblEntries entries.
| tbl[] | Name-Value Pair table |
| nTblEntries | Number of name-value pair table entries |
| sName | Name to in table to find. |
Definition at line 64 of file assoc.c.
References CHKEXPR_ULONG, and Nvp_T::m_iVal.
Referenced by OptsCvtArgLogLevel(), and test_assoc().
| const char* NvpVal2Name | ( | Nvp_T | tbl[], |
| size_t | nTblEntries, | ||
| int | iVal | ||
| ) |
Get the name associated with the value.
The table search terminates at the first match or at the end of nTblEntries entries.
| tbl[] | Name-Value Pair table |
| nTblEntries | Number of name-value pair table entries |
| iVal | Value in table to find. |
Definition at line 94 of file assoc.c.
References CHKEXPR_ULONG, and Nvp_T::m_sName.
Referenced by AddNewBody(), PrintBody(), test_assoc(), and units_shortname().