Changeset 6997
- Timestamp:
- Apr 27, 2006, 11:39:49 AM (20 years ago)
- Location:
- trunk/psModules/src/pslib
- Files:
-
- 2 edited
-
psMetadataItemParse.c (modified) (9 diffs)
-
psMetadataItemParse.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/pslib/psMetadataItemParse.c
r6927 r6997 1 1 #include <stdio.h> 2 #include <stdlib.h> 2 3 #include "pslib.h" 3 4 4 5 # define PS_METADATA_ITEM_PARSE_NUMBER(INTYPE,OUTTYPE) \ 5 case PS_DATA_##INTYPE: { \ 6 return (ps##OUTTYPE)(item->data.INTYPE); } \ 6 case PS_DATA_##INTYPE: \ 7 return (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) \ 12 case 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) \ 22 case 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 30 psBool 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 } 7 55 8 56 psF32 psMetadataItemParseF32(psMetadataItem *item … … 18 66 PS_METADATA_ITEM_PARSE_NUMBER(U16, F32); 19 67 PS_METADATA_ITEM_PARSE_NUMBER(U32, F32); 68 PS_METADATA_ITEM_PARSE_STRING_FLOAT(F32, strtof); 69 // Flow through 20 70 default: 21 71 psError(PS_ERR_IO, true, "Item %s (%s) is not of floating point type (%x) --- treating as NaN.\n", … … 37 87 PS_METADATA_ITEM_PARSE_NUMBER(U16, F64); 38 88 PS_METADATA_ITEM_PARSE_NUMBER(U32, F64); 89 PS_METADATA_ITEM_PARSE_STRING_FLOAT(F32, strtod); 90 // Flow through 39 91 default: 40 92 psError(PS_ERR_IO, true, "Item %s (%s) is not of double-precision floating point type (%x) " … … 56 108 PS_METADATA_ITEM_PARSE_NUMBER (U16, U8); 57 109 PS_METADATA_ITEM_PARSE_NUMBER (U32, U8); 110 PS_METADATA_ITEM_PARSE_STRING_INT(U8,strtoul); 111 // Flow through 58 112 default: 59 113 psError(PS_ERR_IO, true, "Item %s (%s) is not of integer type (%x) --- treating as zero.\n", … … 75 129 PS_METADATA_ITEM_PARSE_NUMBER (U16, U16); 76 130 PS_METADATA_ITEM_PARSE_NUMBER (U32, U16); 131 PS_METADATA_ITEM_PARSE_STRING_INT(U16,strtoul); 132 // Flow through 77 133 default: 78 134 psError(PS_ERR_IO, true, "Item %s (%s) is not of integer type (%x) --- treating as zero.\n", … … 94 150 PS_METADATA_ITEM_PARSE_NUMBER (U16, U32); 95 151 PS_METADATA_ITEM_PARSE_NUMBER (U32, U32); 152 PS_METADATA_ITEM_PARSE_STRING_INT(U32,strtoul); 153 // Flow through 96 154 default: 97 155 psError(PS_ERR_IO, true, "Item %s (%s) is not of integer type (%x) --- treating as zero.\n", … … 113 171 PS_METADATA_ITEM_PARSE_NUMBER(U16, S8); 114 172 PS_METADATA_ITEM_PARSE_NUMBER(U32, S8); 173 PS_METADATA_ITEM_PARSE_STRING_INT(S8,strtol); 174 // Flow through 115 175 default: 116 176 psError(PS_ERR_IO, true, "Item %s (%s) is not of integer type (%x) --- treating as zero.\n", … … 132 192 PS_METADATA_ITEM_PARSE_NUMBER(U16, S16); 133 193 PS_METADATA_ITEM_PARSE_NUMBER(U32, S16); 194 PS_METADATA_ITEM_PARSE_STRING_INT(S16,strtol); 195 // Flow through 134 196 default: 135 197 psError(PS_ERR_IO, true, "Item %s (%s) is not of integer type (%x) --- treating as zero.\n", … … 151 213 PS_METADATA_ITEM_PARSE_NUMBER(U16, S32); 152 214 PS_METADATA_ITEM_PARSE_NUMBER(U32, S32); 215 PS_METADATA_ITEM_PARSE_STRING_INT(S32,strtol); 216 // Flow through 153 217 default: 154 218 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 3 3 4 4 #include "pslib.h" 5 6 psBool psMetadataItemParseBool(psMetadataItem *item); 5 7 6 8 psF32 psMetadataItemParseF32(psMetadataItem *item);
Note:
See TracChangeset
for help on using the changeset viewer.
