IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12532


Ignore:
Timestamp:
Mar 21, 2007, 3:14:52 PM (19 years ago)
Author:
magnier
Message:

adding psMetadataUpdate function and tests, additional PS_META_.. entries to match

Location:
trunk/psLib
Files:
1 added
5 edited

Legend:

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

    r12460 r12532  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.155 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2007-03-16 01:46:56 $
     14 *  @version $Revision: 1.156 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2007-03-22 01:14:52 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    463463        psMetadataItem *newItem = psMetadataItemCopy(inItem); // Copied item
    464464        if (!psMetadataAddItem(out, newItem, PS_LIST_TAIL, flag)) {
    465             psErrorStackPrint(stderr, "Error copying %s (%s) in the metadata\n", inItem->name,
    466                               inItem->comment);
     465            psError(PS_ERR_UNKNOWN, false, "Error copying %s (%s) in the metadata\n",
     466                    inItem->name, inItem->comment);
    467467            if (outAlloced) {
    468468                psFree(out);
     
    483483
    484484    return out;
     485}
     486
     487// this function copies the input metadata to the output, raising an error
     488// if any entries in 'in' a) do not exist in 'out' or b) have a different type
     489bool p_psMetadataUpdate(const char *file,
     490                        unsigned int lineno,
     491                        const char *func,
     492                        psMetadata *out,
     493                        const psMetadata *in)
     494{
     495    PS_ASSERT_METADATA_NON_NULL(in, NULL);
     496    PS_ASSERT_METADATA_NON_NULL(out, NULL);
     497
     498    psMetadataIterator *iter = psMetadataIteratorAlloc(in, PS_LIST_HEAD, NULL);
     499    psMetadataItem *inItem = NULL;
     500    while ((inItem = psMetadataGetAndIncrement(iter))) {
     501        // Need to look for MULTI, which won't be picked up using the iterator.
     502        psMetadataItem *multiCheckItem = psMetadataLookup(in, inItem->name);
     503        unsigned int flag = PS_META_REPLACE | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE; // Flag to indicate MULTI; otherwise, replace
     504        if (multiCheckItem->type == PS_DATA_METADATA_MULTI) {
     505            psTrace("psLib.types", 10, "MULTI: %s (%s)\n", inItem->name, inItem->comment);
     506            flag = PS_META_DUPLICATE_OK | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;
     507        }
     508        psTrace("psLib.types", 5, "Copying %s (%s)...\n", inItem->name, inItem->comment);
     509
     510        // Copy the item and add it on
     511        psMetadataItem *newItem = psMetadataItemCopy(inItem); // Copied item
     512        if (!psMetadataAddItem(out, newItem, PS_LIST_TAIL, flag)) {
     513            psError(PS_ERR_UNKNOWN, false, "Error copying %s (%s) in the metadata\n",
     514                    inItem->name, inItem->comment);
     515            psFree(newItem);
     516            psFree(iter);
     517            return false;
     518        }
     519        psFree(newItem);                // Drop reference
     520    }
     521    psFree(iter);
     522    return true;
    485523}
    486524
     
    572610        } else if ((flags & PS_META_REPLACE) != 0) {
    573611            // replace entry instead of creating a duplicate entry.
     612
     613            if ((flags & PS_META_REQUIRE_TYPE) && (existingEntry->type != item->type)) {
     614                psError (PS_ERR_UNKNOWN, true, _("existing item does not match type for item requiring matching type"));
     615                return false;
     616            }
    574617
    575618            // remove the existing entry from metadata
     
    601644    } else {
    602645        // OK, this is a new item.
     646        if (flags & PS_META_REQUIRE_ENTRY) {
     647            psError (PS_ERR_UNKNOWN, true, _("no matching item found for item requiring existing entry"));
     648            return false;
     649        }
    603650
    604651        // Node doesn't exist - Add new metadata item to metadata collection's hash
  • trunk/psLib/src/types/psMetadata.h

    r12475 r12532  
    99*  @author Ross Harman, MHPCC
    1010*
    11 *  @version $Revision: 1.100 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2007-03-17 02:38:53 $
     11*  @version $Revision: 1.101 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2007-03-22 01:14:52 $
    1313*
    1414*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6161    PS_META_NO_REPLACE = 0x2000000,    ///< duplicate entry is silently skipped
    6262    PS_META_DUPLICATE_OK = 0x4000000,  ///< allow duplicate entries
    63     PS_META_NULL = 0x8000000           ///< psMetadataItem.data is a NULL value
     63    PS_META_NULL = 0x8000000,           ///< psMetadataItem.data is a NULL value
     64    PS_META_REQUIRE_ENTRY = 0x10000000, ///< require pre-existing entry with same name
     65    PS_META_REQUIRE_TYPE = 0x20000000   ///< require pre-existing entry to have same type
    6466} psMetadataFlags;
    6567
     
    480482
    481483
     484/** Updates an existing psMetadata collection with elements from a metadata collection
     485 *
     486 *  Creates a new copy of all the psMetadataItems in the psMetadata collection 'in' and places
     487 *  them in out.  all items in 'in' must already be in 'out' and be of the same type.
     488 *
     489 *  @return psMetadata*:        the copy of the psMetadata container.
     490 */
     491#ifdef DOXYGEN
     492bool psMetadataUpdate(
     493    psMetadata *out,                   ///< output Metadata container for copying.
     494    const psMetadata *in               ///< Metadata collection to be copied.
     495    );
     496#else // ifdef DOXYGEN
     497bool p_psMetadataUpdate(
     498    const char *file,                   ///< File of caller
     499    unsigned int lineno,                ///< Line number of caller
     500    const char *func,                   ///< Function name of caller
     501    psMetadata *out,                    ///< output Metadata container for copying.
     502    const psMetadata *in                ///< Metadata collection to be copied.
     503    );
     504#define psMetadataUpdate(out, in) \
     505      p_psMetadataUpdate(__FILE__, __LINE__, __func__, out, in)
     506#endif // ifdef DOXYGEN
     507
     508
    482509/** Supplements a metadata with an item from another metadata.
    483510 *
  • trunk/psLib/test/types

    • Property svn:ignore
      •  

        old new  
        7272tap_psMetadata_printing
        7373tap_psPixels_all
         74tap_psMetadataUpdate
  • trunk/psLib/test/types/.cvsignore

    r10821 r12532  
    7474tap_psMetadata_printing
    7575tap_psPixels_all
     76
     77tap_psMetadataUpdate
  • trunk/psLib/test/types/Makefile.am

    r12477 r12532  
    1818        tap_psMetadataItemCompare \
    1919        tap_psMetadataItemParse \
     20        tap_psMetadataUpdate \
    2021        tap_psMetadata_printing \
    2122        tap_psMetadata_copying \
Note: See TracChangeset for help on using the changeset viewer.