Changeset 1458
- Timestamp:
- Aug 10, 2004, 1:32:51 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 3 edited
-
astronomy/psMetadata.c (modified) (13 diffs)
-
collections/psMetadata.c (modified) (13 diffs)
-
types/psMetadata.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astronomy/psMetadata.c
r1447 r1458 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-08-10 01:43:05$14 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-08-10 23:32:51 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 20 20 /******************************************************************************/ 21 22 21 /* INCLUDE FILES */ 23 24 22 /******************************************************************************/ 25 23 #include<stdio.h> … … 38 36 39 37 /******************************************************************************/ 40 41 38 /* DEFINE STATEMENTS */ 42 43 39 /******************************************************************************/ 44 40 … … 60 56 61 57 /******************************************************************************/ 62 63 58 /* TYPE DEFINITIONS */ 64 65 59 /******************************************************************************/ 66 60 … … 68 62 69 63 /*****************************************************************************/ 70 71 64 /* GLOBAL VARIABLES */ 72 73 65 /*****************************************************************************/ 74 66 … … 76 68 77 69 /*****************************************************************************/ 78 79 70 /* FILE STATIC VARIABLES */ 80 81 71 /*****************************************************************************/ 82 72 … … 84 74 85 75 /*****************************************************************************/ 86 87 76 /* FUNCTION IMPLEMENTATION - LOCAL */ 88 89 77 /*****************************************************************************/ 78 90 79 static void metadataItemFree(psMetadataItem* metadataItem) 91 80 { … … 119 108 120 109 /*****************************************************************************/ 121 122 110 /* FUNCTION IMPLEMENTATION - PUBLIC */ 123 124 111 /*****************************************************************************/ 125 112 … … 175 162 // Set metadata item value 176 163 switch (type) { 164 case PS_META_ITEM_SET: 165 metadataItem->data.V = NULL; 166 break; 177 167 case PS_META_BOOL: 178 metadataItem->data.B = (bool) va_arg(argPtr, int); 179 168 metadataItem->data.B = (bool)va_arg(argPtr, int); 180 169 break; 181 170 case PS_META_S32: … … 183 172 break; 184 173 case PS_META_F32: 185 metadataItem->data.F32 = (psF32) va_arg(argPtr, psF64);174 metadataItem->data.F32 = (psF32)va_arg(argPtr, psF64); 186 175 break; 187 176 case PS_META_F64: … … 190 179 case PS_META_STR: 191 180 metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH); 192 193 181 break; 194 182 case PS_META_IMG: … … 242 230 } 243 231 244 bool psMetadataAddItem(psMetadata* restrict md, int where, psMetadataItem* restrict metadataItem) 245 { 246 char *key = NULL; 247 psHash* mdTable = NULL; 248 psList* mdList = NULL; 249 psMetadataItem* value = NULL; 250 psMetadataType type = PS_META_ITEM_SET; 251 252 if (md == NULL) { 253 psError(__func__, "Null metadata collection not allowed"); 254 return false; 255 } 256 257 if (metadataItem == NULL) { 258 psError(__func__, "Null metadata item not allowed"); 259 return false; 260 } 261 262 type = metadataItem->type; 232 bool psMetadataAddItem( psMetadata *restrict md, int where, psMetadataItem *restrict metadataItem ) 233 { 234 char * key = NULL; 235 psHash *mdTable = NULL; 236 psList *mdList = NULL; 237 psMetadataItem *existingEntry = NULL; 238 psMetadataItem *newFolderEntry = NULL; 239 psMetadataType newType = PS_META_ITEM_SET; 240 241 if(md == NULL) { 242 psError( __func__, "Null metadata collection not allowed" ); 243 return false; 244 } 245 246 if(metadataItem == NULL) { 247 psError( __func__, "Null metadata item not allowed" ); 248 return false; 249 } 250 251 newType = metadataItem->type; 263 252 264 253 mdTable = md->table; 265 if (mdTable == NULL) {266 psError( __func__, "Null metadata table not allowed");254 if(mdTable == NULL) { 255 psError( __func__, "Null metadata table not allowed" ); 267 256 return false; 268 257 } 269 258 270 259 mdList = md->list; 271 if (mdList == NULL) {272 psError( __func__, "Null metadata list not allowed");260 if(mdList == NULL) { 261 psError( __func__, "Null metadata list not allowed"); 273 262 return false; 274 263 } 275 264 276 265 key = metadataItem->name; 277 if (key == NULL) {266 if(key == NULL) { 278 267 psError(__func__, "Null key item not allowed"); 279 268 return false; 280 269 } 281 // Check if key is already in table 282 value = (psMetadataItem* ) psHashLookup(mdTable, key); 283 if (value != NULL && type != PS_META_ITEM_SET) { 284 285 // The key was found and the new metadata item is a leaf node (its type isn't PS_META_ITEM_SET), so 286 // add the new metadata item to hash as a child of the existing metadata item folder node. 287 if (!psListAdd(value->items, metadataItem, where)) { 288 psError(__func__, "Couldn't add metadata item to items list. Name: %s", metadataItem->name); 270 271 // See if key is already in table 272 existingEntry = (psMetadataItem*)psHashLookup(mdTable, key); 273 if(existingEntry != NULL) { 274 275 if(existingEntry->type == PS_META_ITEM_SET) { 276 277 // Add leaf node to existing folder node 278 if(!psListAdd(existingEntry->items, metadataItem, PS_LIST_TAIL)) { 279 psError( __func__, "Couldn't add metadata item to items list. Name: %s", 280 metadataItem->name ); 281 return false; 282 } 283 } else if(existingEntry->type != PS_META_ITEM_SET && newType!= PS_META_ITEM_SET) { 284 285 // Leaf node replaces another leaf. Make new folder node and add leaves. 286 newFolderEntry = psMetadataItemAlloc(key, PS_META_ITEM_SET, NULL, NULL); 287 288 if(!psListAdd(newFolderEntry->items, existingEntry, PS_LIST_TAIL)) { 289 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 290 psFree(newFolderEntry); 291 return false; 292 } 293 294 if(!psListAdd(newFolderEntry->items, metadataItem, PS_LIST_TAIL)) { 295 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 296 psFree(newFolderEntry); 297 return false; 298 } 299 300 if(!psHashRemove(mdTable, key)) { 301 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key); 302 psFree(newFolderEntry); 303 return false; 304 } 305 306 if(!psHashAdd(mdTable, key, newFolderEntry)) { 307 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 308 psFree(newFolderEntry); 309 return false; 310 } 311 312 // Remove local reference to new folder node 313 psMemDecrRefCounter(newFolderEntry); 314 } else { 315 316 // Folder node replaces leaf or folder node - Put old node into new folder and remove from table 317 if(!psListAdd(metadataItem->items, existingEntry, PS_LIST_TAIL)) { 318 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 319 return false; 320 } 321 322 if(!psHashRemove(mdTable, key)) { 323 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key); 324 return false; 325 } 326 327 if(!psHashAdd(mdTable, key, metadataItem)) { 328 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 329 return false; 330 } 331 } 332 } else { 333 334 // Node doesn't exist - Add new metadata item to metadata collection's hash 335 if(!psHashAdd(mdTable, key, metadataItem)) { 336 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 289 337 return false; 290 338 } 291 } else if (value != NULL) {292 293 // The key was found and the new metadata item is a folder node. Don't add new metadata item, since294 // it will wipe out existing node.295 psError(__func__, "Metadata already exists in metadata collection. Item not added. Name: %s",296 metadataItem->name);297 return false;298 } else {299 300 // Duplicate key not found. Add new metadata item to metadata collection's hash301 if (!psHashAdd(mdTable, key, metadataItem)) {302 psError(__func__, "Couldn't add metadata item to metadata collection table. Name: %s",303 metadataItem->name);304 return false;305 }306 339 } 307 340 308 341 // Add all items to metadata collection's list, even if they have the same metadata item names 309 if (!psListAdd(md->list, metadataItem, where)) {310 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",311 metadataItem->name);342 if(!psListAdd( mdList, metadataItem, where )) { 343 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s", 344 metadataItem->name ); 312 345 return false; 313 346 } … … 338 371 return true; 339 372 } 373 374 340 375 341 376 bool psMetadataRemove(psMetadata* restrict md, int where, const char *restrict key) -
trunk/psLib/src/collections/psMetadata.c
r1447 r1458 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-08-10 01:43:05$14 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-08-10 23:32:51 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 20 20 /******************************************************************************/ 21 22 21 /* INCLUDE FILES */ 23 24 22 /******************************************************************************/ 25 23 #include<stdio.h> … … 38 36 39 37 /******************************************************************************/ 40 41 38 /* DEFINE STATEMENTS */ 42 43 39 /******************************************************************************/ 44 40 … … 60 56 61 57 /******************************************************************************/ 62 63 58 /* TYPE DEFINITIONS */ 64 65 59 /******************************************************************************/ 66 60 … … 68 62 69 63 /*****************************************************************************/ 70 71 64 /* GLOBAL VARIABLES */ 72 73 65 /*****************************************************************************/ 74 66 … … 76 68 77 69 /*****************************************************************************/ 78 79 70 /* FILE STATIC VARIABLES */ 80 81 71 /*****************************************************************************/ 82 72 … … 84 74 85 75 /*****************************************************************************/ 86 87 76 /* FUNCTION IMPLEMENTATION - LOCAL */ 88 89 77 /*****************************************************************************/ 78 90 79 static void metadataItemFree(psMetadataItem* metadataItem) 91 80 { … … 119 108 120 109 /*****************************************************************************/ 121 122 110 /* FUNCTION IMPLEMENTATION - PUBLIC */ 123 124 111 /*****************************************************************************/ 125 112 … … 175 162 // Set metadata item value 176 163 switch (type) { 164 case PS_META_ITEM_SET: 165 metadataItem->data.V = NULL; 166 break; 177 167 case PS_META_BOOL: 178 metadataItem->data.B = (bool) va_arg(argPtr, int); 179 168 metadataItem->data.B = (bool)va_arg(argPtr, int); 180 169 break; 181 170 case PS_META_S32: … … 183 172 break; 184 173 case PS_META_F32: 185 metadataItem->data.F32 = (psF32) va_arg(argPtr, psF64);174 metadataItem->data.F32 = (psF32)va_arg(argPtr, psF64); 186 175 break; 187 176 case PS_META_F64: … … 190 179 case PS_META_STR: 191 180 metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH); 192 193 181 break; 194 182 case PS_META_IMG: … … 242 230 } 243 231 244 bool psMetadataAddItem(psMetadata* restrict md, int where, psMetadataItem* restrict metadataItem) 245 { 246 char *key = NULL; 247 psHash* mdTable = NULL; 248 psList* mdList = NULL; 249 psMetadataItem* value = NULL; 250 psMetadataType type = PS_META_ITEM_SET; 251 252 if (md == NULL) { 253 psError(__func__, "Null metadata collection not allowed"); 254 return false; 255 } 256 257 if (metadataItem == NULL) { 258 psError(__func__, "Null metadata item not allowed"); 259 return false; 260 } 261 262 type = metadataItem->type; 232 bool psMetadataAddItem( psMetadata *restrict md, int where, psMetadataItem *restrict metadataItem ) 233 { 234 char * key = NULL; 235 psHash *mdTable = NULL; 236 psList *mdList = NULL; 237 psMetadataItem *existingEntry = NULL; 238 psMetadataItem *newFolderEntry = NULL; 239 psMetadataType newType = PS_META_ITEM_SET; 240 241 if(md == NULL) { 242 psError( __func__, "Null metadata collection not allowed" ); 243 return false; 244 } 245 246 if(metadataItem == NULL) { 247 psError( __func__, "Null metadata item not allowed" ); 248 return false; 249 } 250 251 newType = metadataItem->type; 263 252 264 253 mdTable = md->table; 265 if (mdTable == NULL) {266 psError( __func__, "Null metadata table not allowed");254 if(mdTable == NULL) { 255 psError( __func__, "Null metadata table not allowed" ); 267 256 return false; 268 257 } 269 258 270 259 mdList = md->list; 271 if (mdList == NULL) {272 psError( __func__, "Null metadata list not allowed");260 if(mdList == NULL) { 261 psError( __func__, "Null metadata list not allowed"); 273 262 return false; 274 263 } 275 264 276 265 key = metadataItem->name; 277 if (key == NULL) {266 if(key == NULL) { 278 267 psError(__func__, "Null key item not allowed"); 279 268 return false; 280 269 } 281 // Check if key is already in table 282 value = (psMetadataItem* ) psHashLookup(mdTable, key); 283 if (value != NULL && type != PS_META_ITEM_SET) { 284 285 // The key was found and the new metadata item is a leaf node (its type isn't PS_META_ITEM_SET), so 286 // add the new metadata item to hash as a child of the existing metadata item folder node. 287 if (!psListAdd(value->items, metadataItem, where)) { 288 psError(__func__, "Couldn't add metadata item to items list. Name: %s", metadataItem->name); 270 271 // See if key is already in table 272 existingEntry = (psMetadataItem*)psHashLookup(mdTable, key); 273 if(existingEntry != NULL) { 274 275 if(existingEntry->type == PS_META_ITEM_SET) { 276 277 // Add leaf node to existing folder node 278 if(!psListAdd(existingEntry->items, metadataItem, PS_LIST_TAIL)) { 279 psError( __func__, "Couldn't add metadata item to items list. Name: %s", 280 metadataItem->name ); 281 return false; 282 } 283 } else if(existingEntry->type != PS_META_ITEM_SET && newType!= PS_META_ITEM_SET) { 284 285 // Leaf node replaces another leaf. Make new folder node and add leaves. 286 newFolderEntry = psMetadataItemAlloc(key, PS_META_ITEM_SET, NULL, NULL); 287 288 if(!psListAdd(newFolderEntry->items, existingEntry, PS_LIST_TAIL)) { 289 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 290 psFree(newFolderEntry); 291 return false; 292 } 293 294 if(!psListAdd(newFolderEntry->items, metadataItem, PS_LIST_TAIL)) { 295 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 296 psFree(newFolderEntry); 297 return false; 298 } 299 300 if(!psHashRemove(mdTable, key)) { 301 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key); 302 psFree(newFolderEntry); 303 return false; 304 } 305 306 if(!psHashAdd(mdTable, key, newFolderEntry)) { 307 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 308 psFree(newFolderEntry); 309 return false; 310 } 311 312 // Remove local reference to new folder node 313 psMemDecrRefCounter(newFolderEntry); 314 } else { 315 316 // Folder node replaces leaf or folder node - Put old node into new folder and remove from table 317 if(!psListAdd(metadataItem->items, existingEntry, PS_LIST_TAIL)) { 318 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 319 return false; 320 } 321 322 if(!psHashRemove(mdTable, key)) { 323 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key); 324 return false; 325 } 326 327 if(!psHashAdd(mdTable, key, metadataItem)) { 328 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 329 return false; 330 } 331 } 332 } else { 333 334 // Node doesn't exist - Add new metadata item to metadata collection's hash 335 if(!psHashAdd(mdTable, key, metadataItem)) { 336 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 289 337 return false; 290 338 } 291 } else if (value != NULL) {292 293 // The key was found and the new metadata item is a folder node. Don't add new metadata item, since294 // it will wipe out existing node.295 psError(__func__, "Metadata already exists in metadata collection. Item not added. Name: %s",296 metadataItem->name);297 return false;298 } else {299 300 // Duplicate key not found. Add new metadata item to metadata collection's hash301 if (!psHashAdd(mdTable, key, metadataItem)) {302 psError(__func__, "Couldn't add metadata item to metadata collection table. Name: %s",303 metadataItem->name);304 return false;305 }306 339 } 307 340 308 341 // Add all items to metadata collection's list, even if they have the same metadata item names 309 if (!psListAdd(md->list, metadataItem, where)) {310 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",311 metadataItem->name);342 if(!psListAdd( mdList, metadataItem, where )) { 343 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s", 344 metadataItem->name ); 312 345 return false; 313 346 } … … 338 371 return true; 339 372 } 373 374 340 375 341 376 bool psMetadataRemove(psMetadata* restrict md, int where, const char *restrict key) -
trunk/psLib/src/types/psMetadata.c
r1447 r1458 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-08-10 01:43:05$14 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-08-10 23:32:51 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 20 20 /******************************************************************************/ 21 22 21 /* INCLUDE FILES */ 23 24 22 /******************************************************************************/ 25 23 #include<stdio.h> … … 38 36 39 37 /******************************************************************************/ 40 41 38 /* DEFINE STATEMENTS */ 42 43 39 /******************************************************************************/ 44 40 … … 60 56 61 57 /******************************************************************************/ 62 63 58 /* TYPE DEFINITIONS */ 64 65 59 /******************************************************************************/ 66 60 … … 68 62 69 63 /*****************************************************************************/ 70 71 64 /* GLOBAL VARIABLES */ 72 73 65 /*****************************************************************************/ 74 66 … … 76 68 77 69 /*****************************************************************************/ 78 79 70 /* FILE STATIC VARIABLES */ 80 81 71 /*****************************************************************************/ 82 72 … … 84 74 85 75 /*****************************************************************************/ 86 87 76 /* FUNCTION IMPLEMENTATION - LOCAL */ 88 89 77 /*****************************************************************************/ 78 90 79 static void metadataItemFree(psMetadataItem* metadataItem) 91 80 { … … 119 108 120 109 /*****************************************************************************/ 121 122 110 /* FUNCTION IMPLEMENTATION - PUBLIC */ 123 124 111 /*****************************************************************************/ 125 112 … … 175 162 // Set metadata item value 176 163 switch (type) { 164 case PS_META_ITEM_SET: 165 metadataItem->data.V = NULL; 166 break; 177 167 case PS_META_BOOL: 178 metadataItem->data.B = (bool) va_arg(argPtr, int); 179 168 metadataItem->data.B = (bool)va_arg(argPtr, int); 180 169 break; 181 170 case PS_META_S32: … … 183 172 break; 184 173 case PS_META_F32: 185 metadataItem->data.F32 = (psF32) va_arg(argPtr, psF64);174 metadataItem->data.F32 = (psF32)va_arg(argPtr, psF64); 186 175 break; 187 176 case PS_META_F64: … … 190 179 case PS_META_STR: 191 180 metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH); 192 193 181 break; 194 182 case PS_META_IMG: … … 242 230 } 243 231 244 bool psMetadataAddItem(psMetadata* restrict md, int where, psMetadataItem* restrict metadataItem) 245 { 246 char *key = NULL; 247 psHash* mdTable = NULL; 248 psList* mdList = NULL; 249 psMetadataItem* value = NULL; 250 psMetadataType type = PS_META_ITEM_SET; 251 252 if (md == NULL) { 253 psError(__func__, "Null metadata collection not allowed"); 254 return false; 255 } 256 257 if (metadataItem == NULL) { 258 psError(__func__, "Null metadata item not allowed"); 259 return false; 260 } 261 262 type = metadataItem->type; 232 bool psMetadataAddItem( psMetadata *restrict md, int where, psMetadataItem *restrict metadataItem ) 233 { 234 char * key = NULL; 235 psHash *mdTable = NULL; 236 psList *mdList = NULL; 237 psMetadataItem *existingEntry = NULL; 238 psMetadataItem *newFolderEntry = NULL; 239 psMetadataType newType = PS_META_ITEM_SET; 240 241 if(md == NULL) { 242 psError( __func__, "Null metadata collection not allowed" ); 243 return false; 244 } 245 246 if(metadataItem == NULL) { 247 psError( __func__, "Null metadata item not allowed" ); 248 return false; 249 } 250 251 newType = metadataItem->type; 263 252 264 253 mdTable = md->table; 265 if (mdTable == NULL) {266 psError( __func__, "Null metadata table not allowed");254 if(mdTable == NULL) { 255 psError( __func__, "Null metadata table not allowed" ); 267 256 return false; 268 257 } 269 258 270 259 mdList = md->list; 271 if (mdList == NULL) {272 psError( __func__, "Null metadata list not allowed");260 if(mdList == NULL) { 261 psError( __func__, "Null metadata list not allowed"); 273 262 return false; 274 263 } 275 264 276 265 key = metadataItem->name; 277 if (key == NULL) {266 if(key == NULL) { 278 267 psError(__func__, "Null key item not allowed"); 279 268 return false; 280 269 } 281 // Check if key is already in table 282 value = (psMetadataItem* ) psHashLookup(mdTable, key); 283 if (value != NULL && type != PS_META_ITEM_SET) { 284 285 // The key was found and the new metadata item is a leaf node (its type isn't PS_META_ITEM_SET), so 286 // add the new metadata item to hash as a child of the existing metadata item folder node. 287 if (!psListAdd(value->items, metadataItem, where)) { 288 psError(__func__, "Couldn't add metadata item to items list. Name: %s", metadataItem->name); 270 271 // See if key is already in table 272 existingEntry = (psMetadataItem*)psHashLookup(mdTable, key); 273 if(existingEntry != NULL) { 274 275 if(existingEntry->type == PS_META_ITEM_SET) { 276 277 // Add leaf node to existing folder node 278 if(!psListAdd(existingEntry->items, metadataItem, PS_LIST_TAIL)) { 279 psError( __func__, "Couldn't add metadata item to items list. Name: %s", 280 metadataItem->name ); 281 return false; 282 } 283 } else if(existingEntry->type != PS_META_ITEM_SET && newType!= PS_META_ITEM_SET) { 284 285 // Leaf node replaces another leaf. Make new folder node and add leaves. 286 newFolderEntry = psMetadataItemAlloc(key, PS_META_ITEM_SET, NULL, NULL); 287 288 if(!psListAdd(newFolderEntry->items, existingEntry, PS_LIST_TAIL)) { 289 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 290 psFree(newFolderEntry); 291 return false; 292 } 293 294 if(!psListAdd(newFolderEntry->items, metadataItem, PS_LIST_TAIL)) { 295 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 296 psFree(newFolderEntry); 297 return false; 298 } 299 300 if(!psHashRemove(mdTable, key)) { 301 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key); 302 psFree(newFolderEntry); 303 return false; 304 } 305 306 if(!psHashAdd(mdTable, key, newFolderEntry)) { 307 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 308 psFree(newFolderEntry); 309 return false; 310 } 311 312 // Remove local reference to new folder node 313 psMemDecrRefCounter(newFolderEntry); 314 } else { 315 316 // Folder node replaces leaf or folder node - Put old node into new folder and remove from table 317 if(!psListAdd(metadataItem->items, existingEntry, PS_LIST_TAIL)) { 318 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 319 return false; 320 } 321 322 if(!psHashRemove(mdTable, key)) { 323 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key); 324 return false; 325 } 326 327 if(!psHashAdd(mdTable, key, metadataItem)) { 328 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 329 return false; 330 } 331 } 332 } else { 333 334 // Node doesn't exist - Add new metadata item to metadata collection's hash 335 if(!psHashAdd(mdTable, key, metadataItem)) { 336 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 289 337 return false; 290 338 } 291 } else if (value != NULL) {292 293 // The key was found and the new metadata item is a folder node. Don't add new metadata item, since294 // it will wipe out existing node.295 psError(__func__, "Metadata already exists in metadata collection. Item not added. Name: %s",296 metadataItem->name);297 return false;298 } else {299 300 // Duplicate key not found. Add new metadata item to metadata collection's hash301 if (!psHashAdd(mdTable, key, metadataItem)) {302 psError(__func__, "Couldn't add metadata item to metadata collection table. Name: %s",303 metadataItem->name);304 return false;305 }306 339 } 307 340 308 341 // Add all items to metadata collection's list, even if they have the same metadata item names 309 if (!psListAdd(md->list, metadataItem, where)) {310 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",311 metadataItem->name);342 if(!psListAdd( mdList, metadataItem, where )) { 343 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s", 344 metadataItem->name ); 312 345 return false; 313 346 } … … 338 371 return true; 339 372 } 373 374 340 375 341 376 bool psMetadataRemove(psMetadata* restrict md, int where, const char *restrict key)
Note:
See TracChangeset
for help on using the changeset viewer.
