Changeset 2273 for trunk/psLib/src/collections/psMetadata.c
- Timestamp:
- Nov 3, 2004, 3:05:00 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psMetadata.c (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psMetadata.c
r2204 r2273 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.3 5$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-1 0-27 00:57:30$14 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-11-04 01:04:57 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 35 35 #include "psMetadata.h" 36 36 #include "psString.h" 37 #include "psAstronomyErrors.h" 38 #include "psConstants.h" 37 39 38 40 /******************************************************************************/ … … 123 125 124 126 125 if (name == NULL) { 126 psError(__func__, "Null value for name not allowed"); 127 return NULL; 128 } 127 PS_PTR_CHECK_NULL(name,NULL); 128 129 129 // Allocate metadata item 130 130 metadataItem = (psMetadataItem* ) psAlloc(sizeof(psMetadataItem)); … … 147 147 // Set metadata item type 148 148 metadataItem->type = type; 149 metadataItem->data.V = NULL; 150 151 // Allocate metadata items with same name. 152 metadataItem->items = psListAlloc(NULL); 153 154 // Allocate and set metadata item name 155 metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH); 156 vsprintf(metadataItem->name, name, argPtr); 149 157 150 158 // Set metadata item value 151 159 switch (type) { 152 160 case PS_META_ITEM_SET: 153 metadataItem->data.V = NULL;154 161 break; 155 162 case PS_META_BOOL: … … 180 187 case PS_META_UNKNOWN: 181 188 default: 182 psError(__func__, "Invalid psMetadataType: %d", type); 183 } 184 185 // Allocate and set metadata item name 186 metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH); 187 vsprintf(metadataItem->name, name, argPtr); 188 189 // Allocate metadata items with same name. 190 metadataItem->items = psListAlloc(NULL); 189 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 190 PS_ERRORTEXT_psMetadata_METATYPE_INVALID, 191 type); 192 psFree(metadataItem); 193 metadataItem = NULL; 194 } 191 195 192 196 return metadataItem; … … 224 228 psMetadataType newType = PS_META_ITEM_SET; 225 229 226 if(md == NULL) { 227 psError( __func__, "Null metadata collection not allowed" ); 228 return false; 229 } 230 231 if(metadataItem == NULL) { 232 psError( __func__, "Null metadata item not allowed" ); 233 return false; 234 } 230 PS_PTR_CHECK_NULL(md,NULL); 231 PS_PTR_CHECK_NULL(md->table,NULL); 232 PS_PTR_CHECK_NULL(md->list,NULL); 233 PS_PTR_CHECK_NULL(metadataItem,NULL); 234 PS_PTR_CHECK_NULL(metadataItem->name,NULL); 235 235 236 236 newType = metadataItem->type; 237 238 237 mdTable = md->table; 239 if(mdTable == NULL) {240 psError( __func__, "Null metadata table not allowed" );241 return false;242 }243 244 238 mdList = md->list; 245 if(mdList == NULL) {246 psError( __func__, "Null metadata list not allowed");247 return false;248 }249 250 239 key = metadataItem->name; 251 if(key == NULL) {252 psError(__func__, "Null key item not allowed");253 return false;254 }255 240 256 241 // See if key is already in table … … 262 247 // Add leaf node to existing folder node 263 248 if(!psListAdd(existingEntry->items, PS_LIST_TAIL, metadataItem)) { 264 psError( __func__, "Couldn't add metadata item to items list. Name: %s", 265 metadataItem->name ); 249 psError(PS_ERR_UNKNOWN,false, 250 PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED, 251 metadataItem->name ); 266 252 return false; 267 253 } … … 272 258 273 259 if(!psListAdd(newFolderEntry->items, PS_LIST_TAIL, existingEntry)) { 274 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 260 psError(PS_ERR_UNKNOWN,false, 261 PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED, 262 key); 275 263 psFree(newFolderEntry); 276 264 return false; … … 278 266 279 267 if(!psListAdd(newFolderEntry->items, PS_LIST_TAIL, metadataItem)) { 280 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 268 psError(PS_ERR_UNKNOWN,false, 269 PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED, 270 key); 281 271 psFree(newFolderEntry); 282 272 return false; … … 284 274 285 275 if(!psHashRemove(mdTable, key)) { 286 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key); 276 psError(PS_ERR_UNKNOWN,false, 277 PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED, 278 key); 287 279 psFree(newFolderEntry); 288 280 return false; … … 290 282 291 283 if(!psHashAdd(mdTable, key, newFolderEntry)) { 292 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 284 psError(PS_ERR_UNKNOWN,false, 285 PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED, 286 key); 293 287 psFree(newFolderEntry); 294 288 return false; … … 301 295 // Folder node replaces leaf or folder node - Put old node into new folder and remove from table 302 296 if(!psListAdd(metadataItem->items, PS_LIST_TAIL, existingEntry)) { 303 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 297 psError(PS_ERR_UNKNOWN,false, 298 PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED, 299 key); 304 300 return false; 305 301 } 306 302 307 303 if(!psHashRemove(mdTable, key)) { 308 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key); 304 psError(PS_ERR_UNKNOWN,false, 305 PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED, 306 key); 309 307 return false; 310 308 } 311 309 312 310 if(!psHashAdd(mdTable, key, metadataItem)) { 313 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 311 psError(PS_ERR_UNKNOWN,false, 312 PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED, 313 key); 314 314 return false; 315 315 } … … 319 319 // Node doesn't exist - Add new metadata item to metadata collection's hash 320 320 if(!psHashAdd(mdTable, key, metadataItem)) { 321 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 321 psError(PS_ERR_UNKNOWN,false, 322 PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED, 323 key); 322 324 return false; 323 325 } … … 328 330 if(metadataItem->type != PS_META_ITEM_SET) { 329 331 if(!psListAdd(mdList, location, metadataItem)) { 330 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s", 331 metadataItem->name ); 332 psError(PS_ERR_UNKNOWN,false, 333 PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED, 334 key); 332 335 return false; 333 336 } … … 348 351 349 352 if (!psMetadataAddItem(md, metadataItem, where)) { 350 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",351 metadataItem->name);353 psError(PS_ERR_UNKNOWN,false, 354 PS_ERRORTEXT_psMetadata_ADD_FAILED); 352 355 psFree(metadataItem); 353 356 return false; … … 368 371 369 372 370 if (md == NULL) { 371 psError(__func__, "Null metadata collection not allowed"); 372 return false; 373 } 373 PS_PTR_CHECK_NULL(md,NULL); 374 PS_PTR_CHECK_NULL(md->table,NULL); 375 PS_PTR_CHECK_NULL(md->list,NULL); 374 376 375 377 mdList = md->list; 376 if (mdList == NULL) {377 psError(__func__, "Null metadata list not allowed");378 return false;379 }380 381 378 mdTable = md->table; 382 if (mdTable == NULL) { 383 psError(__func__, "Null metadata table not allowed"); 384 return false; 385 } 379 386 380 // Select removal by key or index 387 381 if (key != NULL) { … … 390 384 entry = (psMetadataItem* ) psHashLookup(mdTable, key); 391 385 if (entry == NULL) { 392 psError(__func__, "Couldn't find metadata item. Name: %s", key); 386 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 387 PS_ERRORTEXT_psMetadata_FIND_FAILED, 388 key); 393 389 return false; 394 390 } … … 402 398 while (entryChild != NULL) { 403 399 if (!psListRemove(mdList, PS_LIST_UNKNOWN, entryChild)) { 404 psError(__func__, "Couldn't remove metadata item from list. Name: %s", key); 400 psError(PS_ERR_UNKNOWN,false, 401 PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED, 402 key); 405 403 return false; 406 404 } … … 411 409 // Table entry has no children. Remove entry from metadata collection's list 412 410 if (!psListRemove(mdList, PS_LIST_UNKNOWN, entry)) { 413 psError(__func__, "Couldn't remove metadata item from list. Name: %s", key); 411 psError(PS_ERR_UNKNOWN,false, 412 PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED, 413 key); 414 414 return false; 415 415 } … … 417 417 // Remove entry from metadata collection's table 418 418 if (!psHashRemove(mdTable, key)) { 419 psError(__func__, "Couldn't remove metadata item from table. Name: %s", key); 419 psError(PS_ERR_UNKNOWN,false, 420 PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED, 421 key); 420 422 return false; 421 423 } … … 425 427 entry = psListGet(mdList, where); 426 428 if (entry == NULL) { 427 psError(__func__, "Couldn't find metadata item in list. Index: %d", where); 429 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 430 PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED, 431 where); 428 432 return false; 429 433 } … … 431 435 key = entry->name; 432 436 if (key == NULL) { 433 psError(__func__, "Null key name not allowed. Index: %d", where); 437 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 438 PS_ERRORTEXT_psMetadata_REMOVE_LIST_INDEX_FAILED, 439 where); 434 440 return false; 435 441 } … … 447 453 448 454 449 if (md == NULL) { 450 psError(__func__, "Null metadata collection not allowed"); 451 return NULL; 452 } 455 PS_PTR_CHECK_NULL(md,NULL); 456 PS_PTR_CHECK_NULL(md->table,NULL); 457 PS_PTR_CHECK_NULL(key,NULL); 453 458 454 459 mdTable = md->table; 455 if (mdTable == NULL) {456 psError(__func__, "Null metadata table not allowed");457 return NULL;458 }459 460 if (key == NULL) {461 psError(__func__, "Null key name not allowed");462 return NULL;463 }464 460 465 461 entry = (psMetadataItem* ) psHashLookup(mdTable, key); … … 473 469 psMetadataItem* psMetadataGet(psMetadata* restrict md, psS32 where) 474 470 { 471 psMetadataItem* entry = NULL; 472 473 PS_PTR_CHECK_NULL(md,NULL); 474 PS_PTR_CHECK_NULL(md->list,NULL); 475 476 entry = (psMetadataItem* ) psListGet(md->list, where); 477 if (entry == NULL) { 478 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 479 PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED, 480 where); 481 return NULL; 482 } 483 484 return entry; 485 } 486 487 psBool psMetadataSetIterator(psMetadata* restrict md, psS32 where) 488 { 489 PS_PTR_CHECK_NULL(md,NULL); 490 PS_PTR_CHECK_NULL(md->list,NULL); 491 492 psListSetIterator(md->list, where); 493 494 return true; 495 } 496 497 psMetadataItem* psMetadataGetNext(psMetadata* restrict md, const char *restrict match, psS32 which) 498 { 475 499 psList* mdList = NULL; 476 500 psMetadataItem* entry = NULL; 477 501 478 502 479 if (md == NULL) { 480 psError(__func__, "Null metadata collection not allowed"); 481 return NULL; 482 } 503 PS_PTR_CHECK_NULL(md,NULL); 504 PS_PTR_CHECK_NULL(md->list,NULL); 483 505 484 506 mdList = md->list; 485 if (mdList == NULL) {486 psError(__func__, "Null metadata list not allowed");487 return NULL;488 }489 490 entry = (psMetadataItem* ) psListGet(mdList, where);491 if (entry == NULL) {492 psError(__func__, "Couldn't find metadata item with given index. Index: %d", where);493 return NULL;494 }495 496 return entry;497 }498 499 psBool psMetadataSetIterator(psMetadata* restrict md, psS32 where)500 {501 psList* mdList = NULL;502 503 if (md == NULL) {504 psError(__func__, "Null metadata collection not allowed");505 return false;506 }507 508 mdList = md->list;509 if (mdList == NULL) {510 psError(__func__, "Null metadata list not allowed");511 return false;512 }513 514 psListSetIterator(mdList, where);515 516 return true;517 }518 519 psMetadataItem* psMetadataGetNext(psMetadata* restrict md, const char *restrict match, psS32 which)520 {521 psList* mdList = NULL;522 psMetadataItem* entry = NULL;523 524 525 if (md == NULL) {526 psError(__func__, "Null metadata collection not allowed");527 return NULL;528 }529 530 mdList = md->list;531 if (mdList == NULL) {532 psError(__func__, "Null metadata list not allowed");533 return NULL;534 }535 507 536 508 psListSetIterator(mdList, which); … … 559 531 560 532 561 if (md == NULL) { 562 psError(__func__, "Null metadata collection not allowed"); 563 return NULL; 564 } 533 PS_PTR_CHECK_NULL(md,NULL); 534 PS_PTR_CHECK_NULL(md->list,NULL); 565 535 566 536 mdList = md->list; 567 if (mdList == NULL) {568 psError(__func__, "Null metadata list not allowed");569 return NULL;570 }571 537 572 538 psListSetIterator(mdList, which);
Note:
See TracChangeset
for help on using the changeset viewer.
