Here is an example of creating a list of functions mapped to a simple string.
First enter typedefs:
typedef GenList *(*DBLISTLOADER)(Database *pDB, char *quellCD, char *profilName); typedef ObjDescription *(*DBCOLUMNLOADER)(); typedef struct dbinfo { char *dbName; DBLISTLOADER dbListLoader; DBCOLUMNLOADER dbColumnLoader; char *options; } DBINFO;
Then the mapping table:
DBINFO dbInfoList[] = { { "SRCDOC", loadSRCDOC, colSRCDOC, "q" }, { "PRF_CD", loadPRF_CD, colPRF_CD, "" }, { "MEDIA", loadMEDIA, colMEDIA, "" }, { NULL, NULL, NULL } };
Now, to find the function from this table and call it:
while (dbInfoList[i].dbName != NULL) { if (strcmp(dbInfoList[i].dbName, szDatabase) == 0) { return (dbInfoList[i].dbListLoader)(pDB, quellCD, profilName); } i++; }
Sorry if it's a little raw. Glued directly from our code; -)
source share