IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 11, 2005, 10:38:56 AM (21 years ago)
Author:
desonia
Message:

made adjustments to psMetadata and added psFitsUpdateTable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psMetadata.c

    r3381 r3407  
    1212*  @author Ross Harman, MHPCC
    1313*
    14 *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2005-03-07 20:58:50 $
     14*  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2005-03-11 20:38:56 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6767/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    6868/*****************************************************************************/
     69
     70static psMetadataItem* makeMetaMulti(psHash* table, const char* key, psMetadataItem* existing)
     71{
     72
     73    if (existing != NULL && existing->type == PS_META_MULTI) {
     74        return existing;
     75    }
     76
     77    // move any existing entry into a psList
     78    psList* newList = psListAlloc(existing);
     79
     80    psMetadataItem* item = psMetadataItemAlloc(key,
     81                           PS_META_MULTI,
     82                           "",
     83                           newList);
     84
     85    if (existing != NULL) {
     86        psHashRemove(table,key); // take out the old entry
     87    }
     88
     89    psHashAdd(table, key, item); // put in the new entry
     90
     91    // free local references of newly allocated items.
     92    psFree(newList);
     93    psFree(item);
     94
     95    return item;
     96}
    6997
    7098static void metadataItemFree(psMetadataItem* metadataItem)
     
    253281    existingEntry = (psMetadataItem*)psHashLookup(mdTable, key);
    254282
    255     // how the item is added to the hash depends on flags & prior existence
    256     if(existingEntry != NULL) {
    257         if ((flags & PS_META_DUPLICATE_OK) != 0) {
     283    if (metadataItem->type == PS_META_MULTI) {
     284        // the incoming entry is PS_META_MULTI
     285
     286        // force the hash entry to be PS_META_MULTI
     287        existingEntry = makeMetaMulti(mdTable,key,existingEntry);
     288
     289        // add all the items in the incoming entry to metadata
     290        psList* list = metadataItem->data.list;
     291        if (list != NULL) {
     292            psListIterator* iter = psListIteratorAlloc(list,PS_LIST_HEAD,true);
     293            psMetadataItem* listItem;
     294            while ((listItem=(psMetadataItem*)psListGetAndIncrement(iter)) != NULL) {
     295                psMetadataAddItem(md,listItem,location,flags);
     296            }
     297            psFree(iter);
     298        }
     299
     300        return true; // all done.
     301    }
     302
     303    // how the item is added to the hash depends on prior existence, flags, etc.
     304    if(existingEntry != NULL) { // prior existence
     305        if (existingEntry->type == PS_META_MULTI || (flags & PS_META_DUPLICATE_OK) != 0) {
    258306            // duplicate entries allowed - add another entry.
    259             if (existingEntry->type != PS_META_MULTI) {
    260                 // first duplicate, transfer the hash's old entry into a
    261                 // list of entries with the type PS_META_MULTI.
    262 
    263                 // add entry to a list and dereference the local pointer
    264                 psList* newList = psListAlloc(existingEntry);
    265 
    266                 existingEntry = psMetadataItemAlloc(key,
    267                                                     PS_META_MULTI,
    268                                                     "",
    269                                                     newList);
    270                 psHashRemove(mdTable,key); // take out the old entry
    271                 psHashAdd(mdTable, key, existingEntry); // put in the new entry
    272 
    273                 // free local references of newly allocated items.
    274                 psFree(newList);
    275                 psFree(existingEntry);
    276 
    277             }
     307
     308            // make sure the existing entry is PS_META_MULTI
     309            existingEntry = makeMetaMulti(mdTable,key,existingEntry);
    278310
    279311            // add to the hash's list of duplicate entries
     
    282314                return false;
    283315            }
    284             // (added to list below)
    285 
    286316        } else if ((flags & PS_META_REPLACE) != 0) {
    287317            // replace entry instead of creating a duplicate entry.
    288318
    289319            // remove the existing entry from metadata
    290             psListRemoveData(mdList, existingEntry);
    291             psHashRemove(mdTable, key);
     320            psMetadataRemove(md,0,key);
    292321
    293322            // treat as if new (added to list below)
     
    423452            // multiple entries with same key, remove just the specified one
    424453            psListRemoveData(tableItem->data.list, entry);
    425             if (psListGet(tableItem->data.list,PS_LIST_HEAD) == NULL) {
    426                 // list is empty, so let's clear the whole entry now.
    427                 if (!psHashRemove(mdTable, key)) {
    428                     psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED, key);
    429                     return false;
    430                 }
    431             }
    432454        } else {
    433455            if (!psHashRemove(mdTable, key)) {
Note: See TracChangeset for help on using the changeset viewer.