IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6997


Ignore:
Timestamp:
Apr 27, 2006, 11:39:49 AM (20 years ago)
Author:
Paul Price
Message:

Adding psMetadataItemParseBool. Adding string handling to the psMetadataItemParse functions (convert string to float, int, etc).

Location:
trunk/psModules/src/pslib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/pslib/psMetadataItemParse.c

    r6927 r6997  
    11#include <stdio.h>
     2#include <stdlib.h>
    23#include "pslib.h"
    34
    45# define PS_METADATA_ITEM_PARSE_NUMBER(INTYPE,OUTTYPE) \
    5 case PS_DATA_##INTYPE: { \
    6     return (ps##OUTTYPE)(item->data.INTYPE); } \
     6case PS_DATA_##INTYPE: \
     7return (ps##OUTTYPE)(item->data.INTYPE); \
     8
     9
     10// NOTE: This function flows through so that errors may be handled by the "default" case.
     11#define PS_METADATA_ITEM_PARSE_STRING_FLOAT(OUTTYPE,FUNCTION) \
     12case PS_DATA_STRING: { \
     13    char *end = NULL; \
     14    ps##OUTTYPE number = FUNCTION(item->data.V, &end); \
     15    if (end != item->data.V) { \
     16        return number; \
     17    } \
     18}
     19
     20// NOTE: This function flows through so that errors may be handled by the "default" case.
     21#define PS_METADATA_ITEM_PARSE_STRING_INT(OUTTYPE,FUNCTION) \
     22case PS_DATA_STRING: { \
     23    char *end = NULL; \
     24    ps##OUTTYPE number = FUNCTION(item->data.V, &end, 10); \
     25    if (end != item->data.V) { \
     26        return number; \
     27    } \
     28}
     29
     30psBool psMetadataItemParseBool(psMetadataItem *item
     31                              )
     32{
     33    switch (item->type) {
     34        PS_METADATA_ITEM_PARSE_NUMBER(F32, Bool);
     35        PS_METADATA_ITEM_PARSE_NUMBER(F64, Bool);
     36        PS_METADATA_ITEM_PARSE_NUMBER(S8,  Bool);
     37        PS_METADATA_ITEM_PARSE_NUMBER(S16, Bool);
     38        PS_METADATA_ITEM_PARSE_NUMBER(S32, Bool);
     39        PS_METADATA_ITEM_PARSE_NUMBER(U8,  Bool);
     40        PS_METADATA_ITEM_PARSE_NUMBER(U16, Bool);
     41        PS_METADATA_ITEM_PARSE_NUMBER(U32, Bool);
     42    case PS_DATA_STRING:
     43        if (strcasecmp(item->data.V, "true") == 0) {
     44            return true;
     45        } else if (strcasecmp(item->data.V, "false") == 0) {
     46            return false;
     47        }
     48        // Flow through
     49    default:
     50        psError(PS_ERR_IO, true, "Item %s (%s) is not of boolean type (%x) --- treating as false.\n",
     51                item->name, item->comment, item->type);
     52        return false;
     53    }
     54}
    755
    856psF32 psMetadataItemParseF32(psMetadataItem *item
     
    1866        PS_METADATA_ITEM_PARSE_NUMBER(U16, F32);
    1967        PS_METADATA_ITEM_PARSE_NUMBER(U32, F32);
     68        PS_METADATA_ITEM_PARSE_STRING_FLOAT(F32, strtof);
     69        // Flow through
    2070    default:
    2171        psError(PS_ERR_IO, true, "Item %s (%s) is not of floating point type (%x) --- treating as NaN.\n",
     
    3787        PS_METADATA_ITEM_PARSE_NUMBER(U16, F64);
    3888        PS_METADATA_ITEM_PARSE_NUMBER(U32, F64);
     89        PS_METADATA_ITEM_PARSE_STRING_FLOAT(F32, strtod);
     90        // Flow through
    3991    default:
    4092        psError(PS_ERR_IO, true, "Item %s (%s) is not of double-precision floating point type (%x) "
     
    56108        PS_METADATA_ITEM_PARSE_NUMBER (U16, U8);
    57109        PS_METADATA_ITEM_PARSE_NUMBER (U32, U8);
     110        PS_METADATA_ITEM_PARSE_STRING_INT(U8,strtoul);
     111        // Flow through
    58112    default:
    59113        psError(PS_ERR_IO, true, "Item %s (%s) is not of integer type (%x) --- treating as zero.\n",
     
    75129        PS_METADATA_ITEM_PARSE_NUMBER (U16, U16);
    76130        PS_METADATA_ITEM_PARSE_NUMBER (U32, U16);
     131        PS_METADATA_ITEM_PARSE_STRING_INT(U16,strtoul);
     132        // Flow through
    77133    default:
    78134        psError(PS_ERR_IO, true, "Item %s (%s) is not of integer type (%x) --- treating as zero.\n",
     
    94150        PS_METADATA_ITEM_PARSE_NUMBER (U16, U32);
    95151        PS_METADATA_ITEM_PARSE_NUMBER (U32, U32);
     152        PS_METADATA_ITEM_PARSE_STRING_INT(U32,strtoul);
     153        // Flow through
    96154    default:
    97155        psError(PS_ERR_IO, true, "Item %s (%s) is not of integer type (%x) --- treating as zero.\n",
     
    113171        PS_METADATA_ITEM_PARSE_NUMBER(U16, S8);
    114172        PS_METADATA_ITEM_PARSE_NUMBER(U32, S8);
     173        PS_METADATA_ITEM_PARSE_STRING_INT(S8,strtol);
     174        // Flow through
    115175    default:
    116176        psError(PS_ERR_IO, true, "Item %s (%s) is not of integer type (%x) --- treating as zero.\n",
     
    132192        PS_METADATA_ITEM_PARSE_NUMBER(U16, S16);
    133193        PS_METADATA_ITEM_PARSE_NUMBER(U32, S16);
     194        PS_METADATA_ITEM_PARSE_STRING_INT(S16,strtol);
     195        // Flow through
    134196    default:
    135197        psError(PS_ERR_IO, true, "Item %s (%s) is not of integer type (%x) --- treating as zero.\n",
     
    151213        PS_METADATA_ITEM_PARSE_NUMBER(U16, S32);
    152214        PS_METADATA_ITEM_PARSE_NUMBER(U32, S32);
     215        PS_METADATA_ITEM_PARSE_STRING_INT(S32,strtol);
     216        // Flow through
    153217    default:
    154218        psError(PS_ERR_IO, true, "Item %s (%s) is not of integer type (%x) --- treating as zero.\n",
  • trunk/psModules/src/pslib/psMetadataItemParse.h

    r6909 r6997  
    33
    44#include "pslib.h"
     5
     6psBool psMetadataItemParseBool(psMetadataItem *item);
    57
    68psF32 psMetadataItemParseF32(psMetadataItem *item);
Note: See TracChangeset for help on using the changeset viewer.