Changeset 6874 for trunk/psLib/src/types
- Timestamp:
- Apr 17, 2006, 12:00:35 PM (20 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 3 edited
-
psMetadata.c (modified) (8 diffs)
-
psMetadata.h (modified) (4 diffs)
-
psPixels.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psMetadata.c
r6548 r6874 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.10 1$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-0 3-08 21:09:16$14 * @version $Revision: 1.102 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-04-17 22:00:03 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 293 293 case PS_DATA_POLYNOMIAL4D: // psPolynomial4D 294 294 case PS_DATA_PROJECTION: // psProjection 295 case PS_DATA_REGION: // psRegion 295 296 case PS_DATA_SCALAR: // psScalar 296 297 case PS_DATA_SPHERE: // psSphere … … 341 342 } 342 343 344 345 psMetadataItem *psMetadataItemCopy(const psMetadataItem *in 346 ) 347 { 348 PS_ASSERT_PTR_NON_NULL(in,NULL); 349 350 psMetadataItem *newItem = NULL; // New metadata item, to be returned 351 352 #define PS_METADATA_ITEM_COPY_CASE(NAME,TYPE) \ 353 case PS_DATA_##NAME: \ 354 newItem = psMetadataItemAlloc(in->name, PS_DATA_##NAME, in->comment, in->data.TYPE); \ 355 break; \ 356 357 switch (in->type) { 358 // Simple types 359 PS_METADATA_ITEM_COPY_CASE(BOOL,B); 360 PS_METADATA_ITEM_COPY_CASE(S8,S8); 361 PS_METADATA_ITEM_COPY_CASE(S16,S16); 362 PS_METADATA_ITEM_COPY_CASE(S32,S32); 363 PS_METADATA_ITEM_COPY_CASE(U8,U8); 364 PS_METADATA_ITEM_COPY_CASE(U16,U16); 365 PS_METADATA_ITEM_COPY_CASE(U32,U32); 366 PS_METADATA_ITEM_COPY_CASE(F32,F32); 367 PS_METADATA_ITEM_COPY_CASE(F64,F64); 368 PS_METADATA_ITEM_COPY_CASE(STRING,V); // This will copy the string, not point at it. 369 case PS_DATA_VECTOR: { 370 psVector *vecCopy = psVectorCopy(NULL, (psVector*)(in->data.V), 371 ((psVector*)(in->data.V))->type.type); 372 if (vecCopy == NULL) { 373 psError(PS_ERR_BAD_PARAMETER_NULL, false, 374 "Error copying vector. Vector skipped.\n"); 375 } else { 376 newItem = psMetadataItemAlloc(in->name, PS_DATA_VECTOR, in->comment, vecCopy); 377 psFree(vecCopy); // Drop reference 378 } 379 break; 380 } 381 case PS_DATA_TIME: { 382 psTime *timeCopy = p_psTimeCopy( (psTime*)(in->data.V) ); 383 if (timeCopy == NULL) { 384 psError(PS_ERR_BAD_PARAMETER_NULL, false, 385 "Error copying time. Time skipped.\n"); 386 } else { 387 newItem = psMetadataItemAlloc(in->name, PS_DATA_TIME, in->comment, timeCopy); 388 psFree(timeCopy); // Drop reference 389 } 390 break; 391 } 392 case PS_DATA_METADATA: { 393 // Metadata: copy the next level and stuff that in too 394 psMetadata *metadata = psMetadataCopy(NULL, in->data.md); 395 newItem = psMetadataItemAlloc(in->name, PS_DATA_METADATA, in->comment, metadata); 396 psFree(metadata); // Drop reference 397 break; 398 } 399 case PS_DATA_REGION: { 400 psRegion *region = in->data.V; // The region 401 psRegion *new = psRegionAlloc(region->x0, region->x1, region->y0, region->y1); // Copy of the region 402 newItem = psMetadataItemAlloc(in->name, PS_DATA_REGION, in->comment, new); 403 psFree(new); // Drop reference 404 break; 405 } 406 default: 407 // Other kinds of pointers 408 psLogMsg(__func__, PS_LOG_WARN, "Copying a pointer in the metadata item: %x\n", in->type); 409 newItem = psMetadataItemAlloc(in->name, in->type, in->comment, in->data.V); 410 break; 411 } 412 413 return newItem; 414 } 415 343 416 psMetadata *psMetadataCopy(psMetadata *out, 344 417 const psMetadata *in) … … 349 422 out = psMetadataAlloc(); 350 423 } 351 // psMetadataItem *item = NULL; 352 psMetadataIterator *iter = NULL; 353 iter = psMetadataIteratorAlloc(*(psMetadata**)&in, PS_LIST_HEAD, NULL); 354 /* 355 item = psMetadataGetAndIncrement(iter); 356 while (item != NULL) { 357 psMetadataAddItem(out, item, PS_LIST_TAIL, 0); 358 item = psMetadataGetAndIncrement(iter); 359 } 360 psFree(item); 361 psFree(iter); 362 return out; 363 */ 424 psMetadataIterator *iter = psMetadataIteratorAlloc(*(psMetadata**)&in, PS_LIST_HEAD, NULL); 364 425 psMetadataItem *inItem = NULL; 365 unsigned long numPointers = 0; // Number of pointers we were forced to copy366 426 while ((inItem = psMetadataGetAndIncrement(iter))) { 367 427 // Need to look for MULTI, which won't be picked up using the iterator. … … 370 430 if (multiCheckItem->type == PS_DATA_METADATA_MULTI) { 371 431 psTrace(__func__, 10, "MULTI: %s (%s)\n", inItem->name, inItem->comment); 372 flag = PS_ DATA_METADATA_MULTI;432 flag = PS_META_DUPLICATE_OK; 373 433 } 374 434 psTrace(__func__, 5, "Copying %s (%s)...\n", inItem->name, inItem->comment); 375 435 376 377 // case PS_TYPE_##NAME: 378 #define PS_METADATA_COPY_CASE(NAME,TYPE) \ 379 case PS_DATA_##NAME: \ 380 if (! psMetadataAdd(out, PS_LIST_TAIL, inItem->name, \ 381 PS_DATA_##NAME | flag, inItem->comment, inItem->data.TYPE)) { \ 382 psErrorStackPrint(stderr, "Error copying %s (%s) in the metadata\n", \ 383 inItem->name, inItem->comment); \ 384 } \ 385 break; 386 387 switch (inItem->type) { 388 // Numerical types 389 PS_METADATA_COPY_CASE(BOOL,B); 390 PS_METADATA_COPY_CASE(S8,S8); 391 PS_METADATA_COPY_CASE(S16,S16); 392 PS_METADATA_COPY_CASE(S32,S32); 393 PS_METADATA_COPY_CASE(U8,U8); 394 PS_METADATA_COPY_CASE(U16,U16); 395 PS_METADATA_COPY_CASE(U32,U32); 396 PS_METADATA_COPY_CASE(F32,F32); 397 PS_METADATA_COPY_CASE(F64,F64); 398 399 case PS_DATA_VECTOR: { 400 psVector *vecCopy = psVectorCopy(NULL, (psVector*)(inItem->data.V), 401 ((psVector*)(inItem->data.V))->type.type); 402 if (vecCopy == NULL) { 403 psError(PS_ERR_BAD_PARAMETER_NULL, false, 404 "Error copying vector. Vector skipped.\n"); 405 } else { 406 psMetadataAddVector(out, PS_LIST_TAIL, inItem->name, flag, 407 inItem->comment, vecCopy); 408 psFree(vecCopy); 409 } 410 break; 411 } 412 case PS_DATA_TIME: { 413 psTime *timeCopy = p_psTimeCopy( (psTime*)(inItem->data.V) ); 414 if (timeCopy == NULL) { 415 psError(PS_ERR_BAD_PARAMETER_NULL, false, 416 "Error copying time. Time skipped.\n"); 417 } else { 418 psMetadataAddTime(out, PS_LIST_TAIL, inItem->name, flag, 419 inItem->comment, timeCopy); 420 psFree(timeCopy); 421 } 422 break; 423 } 424 // String: relying on the fact that this will copy the string, not point at it. 425 case PS_DATA_STRING: 426 psMetadataAdd(out, PS_LIST_TAIL, inItem->name, PS_DATA_STRING | 427 flag, inItem->comment, inItem->data.V); 428 break; 429 // Metadata: copy the next level and stuff that in too 430 case PS_DATA_METADATA: { 431 psMetadata *metadata = psMetadataCopy(NULL, inItem->data.md); 432 psMetadataAdd(out, PS_LIST_TAIL, inItem->name, 433 PS_DATA_METADATA | flag, inItem->comment, metadata); 434 psFree(metadata); 435 break; 436 } 437 // Other kinds of pointers 438 default: 439 numPointers++; 440 psTrace(__func__, 10, "Copying a pointer in the metadata: %x\n", inItem->type); 441 psMetadataAdd(out, PS_LIST_TAIL, inItem->name, inItem->type | flag, 442 inItem->comment, inItem->data.V); 443 break; 444 } 436 // Copy the item and add it on 437 psMetadataItem *newItem = psMetadataItemCopy(inItem); // Copied item 438 if (!psMetadataAddItem(out, newItem, PS_LIST_TAIL, flag)) { 439 psErrorStackPrint(stderr, "Error copying %s (%s) in the metadata\n", inItem->name, 440 inItem->comment); 441 } 442 psFree(newItem); // Drop reference 445 443 } 446 444 psFree(iter); 447 448 if (numPointers > 0) {449 psLogMsg(__func__, PS_LOG_WARN,450 "Forced to copy %d pointers when copying metadata. Updating the "451 "copied psMetadata will affect the original!\n", numPointers);452 }453 445 454 446 return out; … … 528 520 } else { 529 521 // default is to error on duplicate entry. 522 if ((flags & PS_META_NO_REPLACE) != 0) { 523 return true; 524 } 530 525 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 531 526 PS_ERRORTEXT_psMetadata_DUPLICATE_NOT_ALLOWED); … … 554 549 const char *name, 555 550 int format, 556 const char *comment, 557 ...) 551 const char *comment,...) 558 552 { 559 553 PS_ASSERT_PTR_NON_NULL(md,false); … … 1140 1134 psMetadataPrint(item->data.V, level + 1); 1141 1135 break; 1136 case PS_DATA_REGION: { 1137 psString region = psRegionToString(*(psRegion*)item->data.V); 1138 printf("%s", region); 1139 psFree(region); 1140 break; 1141 } 1142 case PS_DATA_LIST: 1143 printf("<a list of unknown contents>"); 1144 break; 1145 case PS_DATA_TIME: { 1146 psString time = psTimeToISO(item->data.V); 1147 printf("%s", time); 1148 psFree(time); 1149 break; 1150 } 1142 1151 default: 1152 printf("\n"); 1143 1153 psError(PS_ERR_IO, false, "Non-printable metadata type: %x\n", item->type); 1144 1154 } -
trunk/psLib/src/types/psMetadata.h
r6251 r6874 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.7 4$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-0 1-30 20:28:33 $13 * @version $Revision: 1.75 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-04-17 22:00:03 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 59 59 PS_META_DEFAULT = 0, ///< default behaviour (duplicate entry is an error) 60 60 PS_META_REPLACE = 0x1000000, ///< allow entry to be replaced 61 PS_META_DUPLICATE_OK = 0x2000000, ///< allow duplicate entries 62 PS_META_NULL = 0x4000000 ///< psMetadataItem.data is a NULL value 61 PS_META_NO_REPLACE = 0x2000000, ///< duplicate entry is silently skipped 62 PS_META_DUPLICATE_OK = 0x4000000, ///< allow duplicate entries 63 PS_META_NULL = 0x8000000 ///< psMetadataItem.data is a NULL value 63 64 } psMetadataFlags; 64 65 … … 342 343 ); 343 344 345 /** Creates a new copy of a psMetadataItem. 346 * 347 * @return psMetadataItem*: the copy of the psMetadataItem 348 */ 349 psMetadataItem *psMetadataItemCopy(const psMetadataItem *in ///< metadata item to be copied 350 ); 351 352 344 353 /** Creates a new copy of all the psMetadataItems in the psMetadata collection, in, and 345 354 * returns them in out, or creates a new container if out is NULL. … … 939 948 940 949 950 psPolynomial2D *psPolynomial2DfromMD (psMetadata *folder); 951 bool psPolynomial2DtoMD (psMetadata *md, psPolynomial2D *poly, char *format, ...); 952 953 psPolynomial3D *psPolynomial3DfromMD (psMetadata *folder); 954 bool psPolynomial3DtoMD (psMetadata *md, psPolynomial3D *poly, char *format, ...); 955 956 psPolynomial4D *psPolynomial4DfromMD (psMetadata *folder); 957 bool psPolynomial4DtoMD (psMetadata *md, psPolynomial4D *poly, char *format, ...); 958 959 941 960 /// @} 942 961 -
trunk/psLib/src/types/psPixels.h
r6500 r6874 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 19$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-0 2-28 02:53:03 $9 * @version $Revision: 1.20 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-04-17 22:00:03 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 17 17 #include "psImage.h" 18 18 #include "psVector.h" 19 #include "psRegion.h" 19 20 20 21 /// @addtogroup Image … … 125 126 * 126 127 * psMaskToPixels shall return a psPixels consisting of the coordinates in 127 * the mask that match the maskVal. The out pixel list shall be modi ï¬ed if128 * the mask that match the maskVal. The out pixel list shall be modified if 128 129 * supplied, or allocated and returned if NULL. In hte event that mask is 129 130 * NULL, the function shall generate an error and return NULL.
Note:
See TracChangeset
for help on using the changeset viewer.
