IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14008


Ignore:
Timestamp:
Jul 3, 2007, 3:36:14 PM (19 years ago)
Author:
magnier
Message:

adding psMetadataOverlay function and rudimentary tests

Location:
trunk/psLib
Files:
1 added
3 edited

Legend:

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

    r13689 r14008  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.161 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2007-06-07 00:42:13 $
     14 *  @version $Revision: 1.162 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2007-07-04 01:36:14 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    509509        }
    510510        psTrace("psLib.types", 5, "Copying %s (%s)...\n", inItem->name, inItem->comment);
     511
     512        // Copy the item and add it on.  report all errors so we get a listing
     513        psMetadataItem *newItem = psMetadataItemCopy(inItem); // Copied item
     514        if (!psMetadataAddItem(out, newItem, PS_LIST_TAIL, flag)) {
     515            fprintf (stderr, "Error copying %s\n", inItem->name);
     516            result = false;
     517        }
     518        psFree(newItem);                // Drop reference
     519    }
     520    psFree(iter);
     521
     522    if (!result) {
     523        psError(PS_ERR_UNKNOWN, false, "failed to update metadata\n");
     524    }
     525    return result;
     526}
     527
     528// this function copies the input metadata to the output, supplementing existing metadata
     529// folders with the contents from corresponding folders in the output
     530bool p_psMetadataOverlay(const char *file,
     531                         unsigned int lineno,
     532                         const char *func,
     533                         psMetadata *out,
     534                         const psMetadata *in)
     535{
     536    PS_ASSERT_METADATA_NON_NULL(in, NULL);
     537    PS_ASSERT_METADATA_NON_NULL(out, NULL);
     538
     539    bool result = true;
     540
     541    psMetadataIterator *iter = psMetadataIteratorAlloc(in, PS_LIST_HEAD, NULL);
     542    psMetadataItem *inItem = NULL;
     543    while ((inItem = psMetadataGetAndIncrement(iter))) {
     544        // Need to look for MULTI, which won't be picked up using the iterator.
     545        psMetadataItem *multiCheckItem = psMetadataLookup(in, inItem->name);
     546        unsigned int flag = PS_META_REPLACE; // Flag to indicate MULTI; otherwise, replace
     547        if (multiCheckItem->type == PS_DATA_METADATA_MULTI) {
     548            psTrace("psLib.types", 10, "MULTI: %s (%s)\n", inItem->name, inItem->comment);
     549            flag = PS_META_DUPLICATE_OK;
     550        }
     551        psTrace("psLib.types", 5, "Copying %s (%s)...\n", inItem->name, inItem->comment);
     552
     553        // if this is a metadata, and it has a corresponding match, overlay them
     554        if (inItem->type == PS_DATA_METADATA) {
     555            bool status;
     556            psMetadata *outFolder = psMetadataLookupMetadata (&status, out, inItem->name);
     557            if (outFolder) {
     558                if (!psMetadataOverlay (outFolder, inItem->data.md)) {
     559                    fprintf (stderr, "Error overlaying metadata folder\n");
     560                    result = false;
     561                }
     562                continue;
     563            }
     564        }
    511565
    512566        // Copy the item and add it on.  report all errors so we get a listing
  • trunk/psLib/src/types/psMetadata.h

    r12532 r14008  
    99*  @author Ross Harman, MHPCC
    1010*
    11 *  @version $Revision: 1.101 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2007-03-22 01:14:52 $
     11*  @version $Revision: 1.102 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2007-07-04 01:36:14 $
    1313*
    1414*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    507507
    508508
     509/** Overlays an existing psMetadata collection with elements from a metadata collection
     510 *
     511 *  Creates a new copy of all the psMetadataItems in the psMetadata collection 'in' and places
     512 *  them in out.  matching metadata structures in 'out' are supplemented with corresponding
     513 *  entries from 'in'
     514 *
     515 *  @return psMetadata*:        the copy of the psMetadata container.
     516 */
     517#ifdef DOXYGEN
     518bool psMetadataOverlay(
     519    psMetadata *out,                   ///< output Metadata container for copying.
     520    const psMetadata *in               ///< Metadata collection to be copied.
     521    );
     522#else // ifdef DOXYGEN
     523bool p_psMetadataOverlay(
     524    const char *file,                   ///< File of caller
     525    unsigned int lineno,                ///< Line number of caller
     526    const char *func,                   ///< Function name of caller
     527    psMetadata *out,                    ///< output Metadata container for copying.
     528    const psMetadata *in                ///< Metadata collection to be copied.
     529    );
     530#define psMetadataOverlay(out, in) \
     531      p_psMetadataOverlay(__FILE__, __LINE__, __func__, out, in)
     532#endif // ifdef DOXYGEN
     533
     534
    509535/** Supplements a metadata with an item from another metadata.
    510536 *
  • trunk/psLib/test/types/Makefile.am

    r12532 r14008  
    1919        tap_psMetadataItemParse \
    2020        tap_psMetadataUpdate \
     21        tap_psMetadataOverlay \
    2122        tap_psMetadata_printing \
    2223        tap_psMetadata_copying \
Note: See TracChangeset for help on using the changeset viewer.