IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16125


Ignore:
Timestamp:
Jan 17, 2008, 4:07:55 PM (18 years ago)
Author:
jhoblitt
Message:

expand PXOPT_* macro type coverage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/end_stage/ippTools/src/pxtools.h

    r16116 r16125  
    8080}
    8181
     82#define PXOPT_LOOKUP_F(var, md, key, type, required, ret) \
     83ps##type var; \
     84{ \
     85    bool status; \
     86 \
     87    var = psMetadataLookup##type(&status, md, key); \
     88    if (!status) { \
     89        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", key); \
     90        return ret; \
     91    } \
     92 \
     93    if (required && isnan(var)) { \
     94        psError(PS_ERR_UNKNOWN, true, "%s is required", key); \
     95        return ret; \
     96    } \
     97}
     98
    8299#define PXOPT_LOOKUP_F32(var, md, key, required, ret) \
    83 psF32 var; \
    84 { \
    85     bool status; \
    86  \
    87     var = psMetadataLookupF32(&status, md, key); \
    88     if (!status) { \
    89         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", key); \
    90         return ret; \
    91     } \
    92  \
    93     if (required && isnan(var)) { \
    94         psError(PS_ERR_UNKNOWN, true, "%s is required", key); \
    95         return ret; \
    96     } \
    97 }
     100    PXOPT_LOOKUP_F(var, md, key, F64, required, ret)
    98101
    99102#define PXOPT_LOOKUP_F64(var, md, key, required, ret) \
    100 psF64 var; \
    101 { \
    102     bool status; \
    103  \
    104     var = psMetadataLookupF64(&status, md, key); \
    105     if (!status) { \
    106         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", key); \
    107         return ret; \
    108     } \
    109  \
    110     if (required && isnan(var)) { \
    111         psError(PS_ERR_UNKNOWN, true, "%s is required", key); \
    112         return ret; \
    113     } \
    114 }
     103    PXOPT_LOOKUP_F(var, md, key, F64, required, ret)
     104
     105#define PXOPT_LOOKUP_PRIMITIVE(var, md, key, type, suffix, max, required, ret) \
     106type var; \
     107{ \
     108    bool status; \
     109 \
     110    var = psMetadataLookup##suffix(&status, md, key); \
     111    if (!status) { \
     112        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", key); \
     113        return ret; \
     114    } \
     115 \
     116    if (required && (var != max)) { \
     117        psError(PS_ERR_UNKNOWN, true, "%s is required", key); \
     118        return ret; \
     119    } \
     120}
     121
     122#define PXOPT_LOOKUP_S16(var, md, key, required, ret) \
     123    PXOPT_LOOKUP_PRIMITIVE(var, md, key, psS16, S16, INT16_MAX, required, ret)
     124
     125#define PXOPT_LOOKUP_S32(var, md, key, required, ret) \
     126    PXOPT_LOOKUP_PRIMITIVE(var, md, key, psS32, S32, INT32_MAX, required, ret)
     127
     128#define PXOPT_LOOKUP_S64(var, md, key, required, ret) \
     129    PXOPT_LOOKUP_PRIMITIVE(var, md, key, psS64, S64, INT64_MAX, required, ret)
     130
     131#define PXOPT_LOOKUP_U16(var, md, key, required, ret) \
     132    PXOPT_LOOKUP_PRIMITIVE(var, md, key, psU16, U16, UINT16_MAX, required, ret)
     133
     134#define PXOPT_LOOKUP_U32(var, md, key, required, ret) \
     135    PXOPT_LOOKUP_PRIMITIVE(var, md, key, psU32, U32, UINT32_MAX, required, ret)
    115136
    116137#define PXOPT_LOOKUP_U64(var, md, key, required, ret) \
    117 psU64 var; \
    118 { \
    119     bool status; \
    120  \
    121     var = psMetadataLookupU64(&status, md, key); \
    122     if (!status) { \
    123         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", key); \
    124         return ret; \
    125     } \
    126  \
    127     if (required && (var != UINT64_MAX)) { \
    128         psError(PS_ERR_UNKNOWN, true, "%s is required", key); \
    129         return ret; \
    130     } \
    131 }
    132 
    133 #define PXOPT_LOOKUP_S16(var, md, key, required, ret) \
    134 psS16 var; \
    135 { \
    136     bool status; \
    137  \
    138     var = psMetadataLookupS16(&status, md, key); \
    139     if (!status) { \
    140         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", key); \
    141         return ret; \
    142     } \
    143  \
    144     if (required && (var != INT16_MAX)) { \
    145         psError(PS_ERR_UNKNOWN, true, "%s is required", key); \
    146         return ret; \
    147     } \
    148 }
     138    PXOPT_LOOKUP_PRIMITIVE(var, md, key, psU64, U64, UINT64_MAX, required, ret)
    149139
    150140#define PXOPT_LOOKUP_TIME(var, md, key, required, ret) \
     
    177167}
    178168
     169// XXX the PXOPT_COPY_* macros free 'to' on error
     170
     171#define PXOPT_COPY_PRIMITIVE(from, to, type, suffix, oldname, newname, comment) \
     172{ \
     173    bool status = false; \
     174    type var = psMetadataLookup##suffix(&status, from, oldname); \
     175    if (!status) { \
     176        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for " oldname); \
     177        return false; \
     178    } \
     179    if (var) { \
     180        if (!psMetadataAdd##suffix(to, PS_LIST_TAIL, newname, PS_META_DUPLICATE_OK, comment, var)) { \
     181            psError(PS_ERR_UNKNOWN, false, "failed to add item " newname); \
     182            psFree(to); \
     183            return false; \
     184        } \
     185    } \
     186}
     187
     188#define PXOPT_COPY_V(from, to, type, suffix, oldname, newname, comment) \
     189    PXOPT_COPY_PRIMITIVE(from, to, type*, suffix, oldname, newname, comment) \
     190
     191#define PXOPT_COPY_F(from, to, type, oldname, newname, comment) \
     192{ \
     193    bool status = false; \
     194    ps##type var = psMetadataLookup##type(&status, from, oldname); \
     195    if (!status) { \
     196        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for " oldname); \
     197        return false; \
     198    } \
     199    if (!isnan(var)) { \
     200        if (!psMetadataAdd##type(to, PS_LIST_TAIL, newname, PS_META_DUPLICATE_OK, comment, var)) { \
     201            psError(PS_ERR_UNKNOWN, false, "failed to add item " newname); \
     202            psFree(to); \
     203            return false; \
     204        } \
     205    } \
     206}
     207
     208#define PXOPT_COPY_F32(from, to, oldname, newname, comment) \
     209  PXOPT_COPY_F(from, to, F32, oldname, newname, comment)
     210
     211#define PXOPT_COPY_F64(from, to, oldname, newname, comment) \
     212  PXOPT_COPY_F(from, to, F64, oldname, newname, comment)
     213
     214#define PXOPT_COPY_TIME(from, to, oldname, newname, comment) \
     215  PXOPT_COPY_V(from, to, psTime, Time, oldname, newname, comment)
     216
     217#define PXOPT_COPY_STR(from, to, oldname, newname, comment) \
     218  PXOPT_COPY_PRIMITIVE(from, to, psString, Str, oldname, newname, comment)
     219
    179220#endif // PXTOOLS_H
Note: See TracChangeset for help on using the changeset viewer.