IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 43033


Ignore:
Timestamp:
May 20, 2026, 11:30:22 AM (2 months ago)
Author:
eugene
Message:

function abstractions were sloppy, updated to be more explicit; fix two errors in usage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-pstamp-20260421/ippTools/src/bgtool.c

    r35672 r43033  
    6767
    6868// Tables to import/export
     69/* ChatGPT suggested fix */
     70typedef struct {
     71    const char *name;
     72    void *(*parse)(psMetadata *);
     73    bool (*insert)(psDB *, void *);
     74} tableData;
     75static const tableData chipTables[] = {
     76    { "chipBackgroundRun",
     77      (void *(*)(psMetadata *))  chipBackgroundRunObjectFromMetadata,
     78      (bool (*)(psDB *, void *)) chipBackgroundRunInsertObject },
     79    { "chipBackgroundImfile",
     80      (void *(*)(psMetadata *))  chipBackgroundImfileObjectFromMetadata,
     81      (bool (*)(psDB *, void *)) chipBackgroundImfileInsertObject },
     82    { NULL, NULL, NULL }
     83};
     84static const tableData warpTables[] = {
     85    { "warpBackgroundRun",
     86      (void *(*)(psMetadata *))  warpBackgroundRunObjectFromMetadata,
     87      (bool (*)(psDB *, void *)) warpBackgroundRunInsertObject },
     88    { "warpBackgroundSkyfile",
     89      (void *(*)(psMetadata *))  warpBackgroundSkyfileObjectFromMetadata,
     90      (bool (*)(psDB *, void *)) warpBackgroundSkyfileInsertObject },
     91    { NULL, NULL, NULL }
     92};
     93
     94
     95/* old version
    6996typedef struct {
    7097    const char *name;                   // Table name
     
    82109    { NULL, NULL, NULL }
    83110};
    84 
     111*/
    85112
    86113# define MODECASE(caseName, func) \
     
    255282        psAssert(item, "%s not in input", name);
    256283        psAssert(item->type == PS_DATA_METADATA_MULTI, "%s not MULTI type", name);
     284
    257285        psAssert(psListLength(item->data.list) == 1, "%s has multiple entries", name);
     286
    258287        psMetadataItem *entry = psListGet(item->data.list, PS_LIST_HEAD); // Entry of interest
    259         void *data = tables[i].parse(entry);                             // Parsed entry
     288        assert (entry);
     289        assert (entry->type == PS_DATA_METADATA);
     290
     291        void *data = tables[i].parse(entry->data.md);                             // Parsed entry
    260292        if (!data) {
    261293            psError(PXTOOLS_ERR_CONFIG, false, "Unable to parse entry %s", name);
     
    263295            return false;
    264296        }
    265         if (!tables[0].insert(config->dbh, data)) {
     297        if (!tables[i].insert(config->dbh, data)) {
    266298            psError(psErrorCodeLast(), false, "Unable to insert entry %s", name);
    267299            psFree(input);
Note: See TracChangeset for help on using the changeset viewer.