Index: trunk/psLib/src/collections/psMetadata.h
===================================================================
--- trunk/psLib/src/collections/psMetadata.h	(revision 3341)
+++ trunk/psLib/src/collections/psMetadata.h	(revision 3381)
@@ -11,6 +11,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-02-28 23:34:10 $
+*  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-03-07 20:58:50 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -21,4 +21,6 @@
 #include <stdarg.h>
 #include <stdio.h>
+#include <sys/types.h>
+#include <regex.h>
 
 #include "psHash.h"
@@ -35,8 +37,8 @@
  */
 typedef enum {
-    PS_META_S32,                       ///< Primitive data.
-    PS_META_F32,                       ///< Primitive data.
-    PS_META_F64,                       ///< Primitive data.
-    PS_META_BOOL,                       ///< Primitive data.
+    PS_META_S32,                       ///< psS32 primitive data.
+    PS_META_F32,                       ///< psF32 primitive data.
+    PS_META_F64,                       ///< psF64 primitive data.
+    PS_META_BOOL,                      ///< psBool primitive data.
     PS_META_LIST,                      ///< List data (Stored as item.data.list).
     PS_META_STR,                       ///< String data (Stored as item.data.V).
@@ -49,4 +51,5 @@
     PS_META_ASTROM,                    ///< Astrometric coefficients (Stored as item.data.V).
     PS_META_UNKNOWN,                   ///< Other data (Stored as item.data.V).
+    PS_META_MULTI,                     ///< Used internally, do not create an metadata item of this type.
     PS_META_NTYPE                      ///< Number of types. Must be last.
 } psMetadataType;
@@ -72,6 +75,10 @@
 typedef enum {
     PS_META_DEFAULT = 0,               ///< default behaviour (duplicate entry is an error)
-    PS_META_REPLACE = 0x10000          ///< allow entry to be replaced
+    PS_META_REPLACE = 0x1000000,       ///< allow entry to be replaced
+    PS_META_DUPLICATE_OK = 0x2000000   ///< allow duplicate entries
 } psMetadataFlags;
+
+#define PS_METADATA_FLAGS_MASK 0xFF000000
+#define PS_METADATA_TYPE_MASK 0x00FFFFFF
 
 /** Metadata data structure.
@@ -88,4 +95,16 @@
 }
 psMetadata;
+
+/** Metadata iterator
+ *
+ *  Iterator for metadata.
+ */
+typedef struct
+{
+    psListIterator* iter;              ///< iterator for the psMetadata's psList
+    regex_t* preg;                     ///< the subsetting regular expression
+}
+psMetadataIterator;
+
 
 /** Metadata item data structure.
@@ -134,32 +153,67 @@
 );
 
+/** Create a metadata item with specified string data.
+ *
+ *  Returns a fill psMetadataItem ready for insertion into the psMetadata
+ *  struct.
+ *
+ * @return psMetadataItem* : Pointer metadata item.
+ */
 psMetadataItem* psMetadataItemAllocStr(
-    const char* name,
-    const char* comment,
-    const char* value
-);
-
+    const char* name,                  ///< Name of metadata item.
+    const char* comment,               ///< Comment for metadata item.
+    const char* value                  ///< the value of the metadata item.
+);
+
+/** Create a metadata item with specified psF32 data.
+ *
+ *  Returns a fill psMetadataItem ready for insertion into the psMetadata
+ *  struct.
+ *
+ * @return psMetadataItem* : Pointer metadata item.
+ */
 psMetadataItem* psMetadataItemAllocF32(
-    const char* name,
-    const char* comment,
-    psF32 value
-);
-
+    const char* name,                  ///< Name of metadata item.
+    const char* comment,               ///< Comment for metadata item.
+    psF32 value                        ///< the value of the metadata item.
+);
+
+/** Create a metadata item with specified psF64 data.
+ *
+ *  Returns a fill psMetadataItem ready for insertion into the psMetadata
+ *  struct.
+ *
+ * @return psMetadataItem* : Pointer metadata item.
+ */
 psMetadataItem* psMetadataItemAllocF64(
-    const char* name,
-    const char* comment,
-    psF64 value
-);
-
+    const char* name,                  ///< Name of metadata item.
+    const char* comment,               ///< Comment for metadata item.
+    psF64 value                        ///< the value of the metadata item.
+);
+
+/** Create a metadata item with specified psS32 data.
+ *
+ *  Returns a fill psMetadataItem ready for insertion into the psMetadata
+ *  struct.
+ *
+ * @return psMetadataItem* : Pointer metadata item.
+ */
 psMetadataItem* psMetadataItemAllocS32(
-    const char* name,
-    const char* comment,
-    psS32 value
-);
-
+    const char* name,                  ///< Name of metadata item.
+    const char* comment,               ///< Comment for metadata item.
+    psS32 value                        ///< the value of the metadata item.
+);
+
+/** Create a metadata item with specified psBool data.
+ *
+ *  Returns a fill psMetadataItem ready for insertion into the psMetadata
+ *  struct.
+ *
+ * @return psMetadataItem* : Pointer metadata item.
+ */
 psMetadataItem* psMetadataItemAllocBool(
-    const char* name,
-    const char* comment,
-    psBool value
+    const char* name,                  ///< Name of metadata item.
+    const char* comment,               ///< Comment for metadata item.
+    psBool value                       ///< the value of the metadata item.
 );
 
@@ -207,5 +261,6 @@
     psMetadata*  md,                   ///< Metadata collection to insert metadat item.
     psMetadataItem*  item,             ///< Metadata item to be added.
-    psS32 location                     ///< Location to be added.
+    psS32 location,                    ///< Location to be added.
+    psS32 flags                        ///< Options flag mask, see psMetadataFlags enum
 );
 
@@ -218,30 +273,47 @@
 psBool psMetadataAdd(
     psMetadata* md,                    ///< Metadata collection to insert metadat item.
-    psS32 where,                       ///< Location to be added.
+    psS32 location,                    ///< Location to be added.
     const char *name,                  ///< Name of metadata item.
-    psMetadataType type,               ///< Type of metadata item.
+    int type,                          ///< Type of metadata item (psMetadataType) and options (psMetadataFlags)
     const char *comment,               ///< Comment for metadata item.
     ...                                ///< Arguments for name formatting and metadata item data.
 );
 
-psBool psMetadataAddS32(psMetadata* md, psS32 where, const char* name,
+#ifndef SWIG
+/** Create and add a metadata item to metadata collection.
+ *
+ * Creates a new metadata item add to the metadata collection.
+ *
+ * @return bool: True for success, false for failure.
+ */
+psBool psMetadataAddV(
+    psMetadata* md,                    ///< Metadata collection to insert metadat item.
+    psS32 location,                    ///< Location to be added.
+    const char *name,                  ///< Name of metadata item.
+    int type,                          ///< Type of metadata item (psMetadataType) and options (psMetadataFlags)
+    const char *comment,               ///< Comment for metadata item.
+    va_list list                       ///< Arguments for name formatting and metadata item data.
+);
+#endif
+
+psBool psMetadataAddS32(psMetadata* md, psS32 location, const char* name,
                         const char* comment, psS32 value);
-psBool psMetadataAddF32(psMetadata* md, psS32 where, const char* name,
+psBool psMetadataAddF32(psMetadata* md, psS32 location, const char* name,
                         const char* comment, psF32 value);
-psBool psMetadataAddF64(psMetadata* md, psS32 where, const char* name,
+psBool psMetadataAddF64(psMetadata* md, psS32 location, const char* name,
                         const char* comment, psF64 value);
-psBool psMetadataAddList(psMetadata* md, psS32 where, const char* name,
+psBool psMetadataAddList(psMetadata* md, psS32 location, const char* name,
                          const char* comment, psList* value);
-psBool psMetadataAddStr(psMetadata* md, psS32 where, const char* name,
+psBool psMetadataAddStr(psMetadata* md, psS32 location, const char* name,
                         const char* comment, const char* value);
-psBool psMetadataAddVector(psMetadata* md, psS32 where, const char* name,
+psBool psMetadataAddVector(psMetadata* md, psS32 location, const char* name,
                            const char* comment, psVector* value);
-psBool psMetadataAddImage(psMetadata* md, psS32 where, const char* name,
+psBool psMetadataAddImage(psMetadata* md, psS32 location, const char* name,
                           const char* comment, psImage* value);
-psBool psMetadataAddHash(psMetadata* md, psS32 where, const char* name,
+psBool psMetadataAddHash(psMetadata* md, psS32 location, const char* name,
                          const char* comment, psHash* value);
-psBool psMetadataAddLookupTable(psMetadata* md, psS32 where, const char* name,
+psBool psMetadataAddLookupTable(psMetadata* md, psS32 location, const char* name,
                                 const char* comment, psLookupTable* value);
-psBool psMetadataAddUnknown(psMetadata* md, psS32 where, const char* name,
+psBool psMetadataAddUnknown(psMetadata* md, psS32 location, const char* name,
                             const char* comment, psPtr value);
 
@@ -340,5 +412,5 @@
  * @return void* : Value of metadata item.
  */
-void* psMetadataLookupPtr(
+psPtr psMetadataLookupPtr(
     psBool *status,                    ///< Status of lookup.
     psMetadata* md,                    ///< Metadata collection to lookup metadata item.
@@ -354,6 +426,53 @@
  */
 psMetadataItem* psMetadataGet(
-    psMetadata*  md,           ///< Metadata collection to insert metadat item.
-    psS32 where                ///< Location to be retrieved.
+    psMetadata*  md,                   ///< Metadata collection to insert metadat item.
+    psS32 location                     ///< Location to be retrieved.
+);
+
+/** Creates a psMetadataIterator to iterate over the specified psMetadata.
+ *
+ *  Supports the subsetting of the metadata via keyword using regular
+ *  expression.  If no regular expression is specified, iteration
+ *  over the entire psMetadata is performed.
+ *
+ *  @return psMetadataIterator*        a new psMetadataIterator, of NULL if error occurred
+ */
+psMetadataIterator* psMetadataIteratorAlloc(
+    psMetadata* md,                    ///< the psMetadata to iterate with
+    int location,                      ///< the initial starting point (after subsetting).
+    const char* regex
+    ///< A regular expression for subsetting the psMetadata.  If NULL, no
+    ///< subsetting is performed.
+);
+
+/** Set the iterator of the psMetadat to a given position.  If location is
+ *  invalid the iterator position is not changed.
+ *
+ *  @return psBool        TRUE if iterator successfully set, otherwise FALSE.
+*/
+psBool psMetadataIteratorSet(
+    psMetadataIterator* iterator,      ///< psMetadata iterator
+    int location                       ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL
+);
+
+/** Position the specified iterator to the next matching item in psMetadata,
+ *  given the regular expression of the iterator
+ *
+ *  @return psPtr       the psMetadataItem at the original iterator position
+ *                      or NULL if the iterator went past the end of the list.
+ */
+psMetadataItem* psMetadataGetAndIncrement(
+    psMetadataIterator* iterator           ///< iterator to move
+);
+
+/** Position the specified iterator to the previous matching item in psMetadata,
+ *  given the regular expression of the iterator
+ *
+ *  @return psPtr       the psMetadataItem at the original iterator position
+ *                      or NULL if the iterator went past the beginning of the
+ *                      list.
+ */
+psMetadataItem* psMetadataGetAndDecrement(
+    psMetadataIterator* iterator           ///< iterator to move
 );
 
