Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

psMetadata.h

Go to the documentation of this file.
00001 /** @file  psMetadata.h
00002 *
00003 *  @brief Contains metadata struuctures, enumerations and functions prototypes
00004 *
00005 *  This file defines metadata item, metadata type, metadata flags, metadata containers, and function
00006 *  prototypes necessary creating psLib metadata APIs
00007 *
00008 *  @ingroup Metadata
00009 *
00010 *  @author Robert DeSonia, MHPCC
00011 *  @author Ross Harman, MHPCC
00012 *
00013 *  @version $Revision: 1.42 $ $Name: rel5_0 $
00014 *  @date $Date: 2005/03/29 22:13:53 $
00015 *
00016 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00017 */
00018 #ifndef PS_METADATA_H
00019 #define PS_METADATA_H
00020 
00021 #include <stdarg.h>
00022 #include <stdio.h>
00023 #include <sys/types.h>
00024 #include <regex.h>
00025 
00026 #include "psHash.h"
00027 #include "psList.h"
00028 #include "psImage.h"
00029 #include "psLookupTable.h"
00030 
00031 /// @addtogroup Metadata
00032 /// @{
00033 
00034 /** Metadata item type.
00035  *
00036  * Enumeration for maintaining metadata item types.
00037  */
00038 typedef enum {
00039     PS_META_S32 = PS_TYPE_S32,         ///< psS32 primitive data.
00040     PS_META_F32 = PS_TYPE_F32,         ///< psF32 primitive data.
00041     PS_META_F64 = PS_TYPE_F64,         ///< psF64 primitive data.
00042     PS_META_BOOL = PS_TYPE_BOOL,       ///< psBool primitive data.
00043     PS_META_LIST = 0x10000,            ///< List data (Stored as item.data.list).
00044     PS_META_STR,                       ///< String data (Stored as item.data.V).
00045     PS_META_VEC,                       ///< Vector data (Stored as item.data.V).
00046     PS_META_IMG,                       ///< Image data (Stored as item.data.V).
00047     PS_META_HASH,                      ///< Hash data (Stored as item.data.V).
00048     PS_META_LOOKUPTABLE,               ///< Lookup table data (Stored as item.data.V).
00049     PS_META_JPEG,                      ///< JPEG data (Stored as item.data.V).
00050     PS_META_PNG,                       ///< PNG data (Stored as item.data.V).
00051     PS_META_ASTROM,                    ///< Astrometric coefficients (Stored as item.data.V).
00052     PS_META_UNKNOWN,                   ///< Other data (Stored as item.data.V).
00053     PS_META_MULTI                      ///< Used internally, do not create an metadata item of this type.
00054 } psMetadataType;
00055 
00056 #define PS_META_IS_PRIMITIVE(TYPE) \
00057 (TYPE == PS_META_S32 || \
00058  TYPE == PS_META_F32 || \
00059  TYPE == PS_META_F64 || \
00060  TYPE == PS_META_BOOL)
00061 
00062 #define PS_META_PRIMITIVE_TYPE(METATYPE) ( \
00063         (METATYPE==PS_META_S32) ? PS_TYPE_S32 : \
00064         (METATYPE==PS_META_F32) ? PS_TYPE_F32 : \
00065         (METATYPE==PS_META_F64) ? PS_TYPE_F64 : \
00066         (METATYPE==PS_META_BOOL) ? PS_TYPE_BOOL : PS_TYPE_PTR )
00067 
00068 /** Option flags for psMetadata functions
00069  *
00070  *  Enumeration for the modification of the behaviour in psMetadataAddItem.
00071  * 
00072  *  @see psMetadataAddItem
00073  */
00074 typedef enum {
00075     PS_META_DEFAULT = 0,               ///< default behaviour (duplicate entry is an error)
00076     PS_META_REPLACE = 0x1000000,       ///< allow entry to be replaced
00077     PS_META_DUPLICATE_OK = 0x2000000   ///< allow duplicate entries
00078 } psMetadataFlags;
00079 
00080 #define PS_METADATA_FLAGS_MASK 0xFF000000
00081 #define PS_METADATA_TYPE_MASK 0x00FFFFFF
00082 
00083 /** Metadata data structure.
00084  *
00085  *  Struct for holding metadata items. Metadata items are held in two
00086  *  containers. The first employs a doubly-linked list to preserve the order
00087  *  of the metadata. The second container employs a hash table which
00088  *  allows fast lookup when given a metadata keyword.
00089  */
00090 typedef struct psMetadata
00091 {
00092     psList*  list;                     ///< Metadata in linked-list
00093     psHash*  table;                    ///< Metadata in a hash table
00094 }
00095 psMetadata;
00096 
00097 /** Metadata iterator
00098  *
00099  *  Iterator for metadata.
00100  */
00101 typedef struct
00102 {
00103     psListIterator* iter;              ///< iterator for the psMetadata's psList
00104     regex_t* preg;                     ///< the subsetting regular expression
00105 }
00106 psMetadataIterator;
00107 
00108 
00109 /** Metadata item data structure.
00110  *
00111  * Struct for maintaining metadata items of varying types. It also contains
00112  * information about the item name, flags, comments, and other items with the same name.
00113  */
00114 typedef struct psMetadataItem
00115 {
00116     const psS32 id;                    ///< Unique ID for metadata item.
00117     char *name;                        ///< Name of metadata item.
00118     psMetadataType type;               ///< Type of metadata item.
00119     union {
00120         psBool B;                      ///< boolean data
00121         psS32 S32;                     ///< Signed 32-bit integer data.
00122         psF32 F32;                     ///< Single-precision float data.
00123         psF64 F64;                     ///< Double-precision float data.
00124         psList *list;                  ///< List data.
00125         psMetadata *md;                ///< Metadata data.
00126         psPtr V;                       ///< Pointer to other type of data.
00127     } data;                            ///< Union for data types.
00128     char *comment;                     ///< Optional comment ("", not NULL).
00129 }
00130 psMetadataItem;
00131 
00132 /** Create a metadata item.
00133  *
00134  *  Returns a fill psMetadataItem ready for insertion into the psMetadata
00135  *  struct. The name argument specifies the name to use for this item, and
00136  *  may include sprintf formatting codes. The format entry specifies both
00137  *  the metadata type and optional flags and is created by bit-wise or of the
00138  *  appropriate type and flag. The comment argument is a fixed string used to
00139  *  comment the metadata item. The arguments to the name formatting codes and
00140  *  the metadata itself are passed as arguments following the comment string.
00141  *  The data must be a pointer for any of the elements stored in data.void.
00142  *  The argument list must be interpreted appropriately by the va_list
00143  *  operators in the function specified size and type.
00144  *
00145  * @return psMetadataItem* : Pointer metadata item.
00146  */
00147 psMetadataItem* psMetadataItemAlloc(
00148     const char *name,                  ///< Name of metadata item.
00149     psMetadataType type,               ///< Type of metadata item.
00150     const char *comment,               ///< Comment for metadata item.
00151     ...                                ///< Arguments for name formatting and metadata item data.
00152 );
00153 
00154 /** Create a metadata item with specified string data.
00155  *
00156  *  Returns a fill psMetadataItem ready for insertion into the psMetadata
00157  *  struct.
00158  *
00159  * @return psMetadataItem* : Pointer metadata item.
00160  */
00161 psMetadataItem* psMetadataItemAllocStr(
00162     const char* name,                  ///< Name of metadata item.
00163     const char* comment,               ///< Comment for metadata item.
00164     const char* value                  ///< the value of the metadata item.
00165 );
00166 
00167 /** Create a metadata item with specified psF32 data.
00168  *
00169  *  Returns a fill psMetadataItem ready for insertion into the psMetadata
00170  *  struct.
00171  *
00172  * @return psMetadataItem* : Pointer metadata item.
00173  */
00174 psMetadataItem* psMetadataItemAllocF32(
00175     const char* name,                  ///< Name of metadata item.
00176     const char* comment,               ///< Comment for metadata item.
00177     psF32 value                        ///< the value of the metadata item.
00178 );
00179 
00180 /** Create a metadata item with specified psF64 data.
00181  *
00182  *  Returns a fill psMetadataItem ready for insertion into the psMetadata
00183  *  struct.
00184  *
00185  * @return psMetadataItem* : Pointer metadata item.
00186  */
00187 psMetadataItem* psMetadataItemAllocF64(
00188     const char* name,                  ///< Name of metadata item.
00189     const char* comment,               ///< Comment for metadata item.
00190     psF64 value                        ///< the value of the metadata item.
00191 );
00192 
00193 /** Create a metadata item with specified psS32 data.
00194  *
00195  *  Returns a fill psMetadataItem ready for insertion into the psMetadata
00196  *  struct.
00197  *
00198  * @return psMetadataItem* : Pointer metadata item.
00199  */
00200 psMetadataItem* psMetadataItemAllocS32(
00201     const char* name,                  ///< Name of metadata item.
00202     const char* comment,               ///< Comment for metadata item.
00203     psS32 value                        ///< the value of the metadata item.
00204 );
00205 
00206 /** Create a metadata item with specified psBool data.
00207  *
00208  *  Returns a fill psMetadataItem ready for insertion into the psMetadata
00209  *  struct.
00210  *
00211  * @return psMetadataItem* : Pointer metadata item.
00212  */
00213 psMetadataItem* psMetadataItemAllocBool(
00214     const char* name,                  ///< Name of metadata item.
00215     const char* comment,               ///< Comment for metadata item.
00216     psBool value                       ///< the value of the metadata item.
00217 );
00218 
00219 #ifndef SWIG
00220 /** Create a metadata item with va_list.
00221  *
00222  *  Returns a fill psMetadataItem ready for insertion into the psMetadata
00223  *  struct. The name argument specifies the name to use for this item, and
00224  *  may include sprintf formatting codes. The format entry specifies both
00225  *  the metadata type and optional flags and is created by bit-wise or of the
00226  *  appropriate type and flag. The comment argument is a fixed string used to
00227  *  comment the metadata item. The arguments to the name formatting codes and
00228  *  the metadata itself are passed as arguments following the comment string.
00229  *  The data must be a pointer for any of the elements stored in data.void.
00230  *  The argument list must be interpreted appropriately by the va_list
00231  *  operators in the function specified size and type.
00232  *
00233  * @return psMetadataItem* : Pointer metadata item.
00234  */
00235 psMetadataItem* psMetadataItemAllocV(
00236     const char *name,                  ///< Name of metadata item.
00237     psMetadataType type,               ///< Type of metadata item.
00238     const char *comment,               ///< Comment for metadata item.
00239     va_list list                       ///< Arguments for name formatting and metadata item data.
00240 );
00241 #endif
00242 
00243 /** Create a metadata collection.
00244  *
00245  *  Returns an empty metadata container with fully allocated internal metadata
00246  *  containers.
00247  *
00248  *  @return psMetadata* : Pointer metadata.
00249  */
00250 psMetadata* psMetadataAlloc(void);
00251 
00252 /** Add existing metadata item to metadata collection.
00253  *
00254  *  Add a metadata item that has already been created to the metadata
00255  *  collection.
00256  *
00257  *  @return bool: True for success, false for failure.
00258  */
00259 psBool psMetadataAddItem(
00260     psMetadata*  md,                   ///< Metadata collection to insert metadat item.
00261     psMetadataItem*  item,             ///< Metadata item to be added.
00262     psS32 location,                    ///< Location to be added.
00263     psS32 flags                        ///< Options flag mask, see psMetadataFlags enum
00264 );
00265 
00266 /** Create and add a metadata item to metadata collection.
00267  *
00268  * Creates a new metadata item add to the metadata collection.
00269  *
00270  * @return bool: True for success, false for failure.
00271  */
00272 psBool psMetadataAdd(
00273     psMetadata* md,                    ///< Metadata collection to insert metadata item.
00274     psS32 location,                    ///< Location to be added.
00275     const char *name,                  ///< Name of metadata item.
00276     int type,                          ///< Type of metadata item (psMetadataType) and options (psMetadataFlags)
00277     const char *comment,               ///< Comment for metadata item.
00278     ...                                ///< Arguments for name formatting and metadata item data.
00279 );
00280 
00281 #ifndef SWIG
00282 /** Create and add a metadata item to metadata collection.
00283  *
00284  * Creates a new metadata item add to the metadata collection.
00285  *
00286  * @return bool: True for success, false for failure.
00287  */
00288 psBool psMetadataAddV(
00289     psMetadata* md,                    ///< Metadata collection to insert metadat item.
00290     psS32 location,                    ///< Location to be added.
00291     const char *name,                  ///< Name of metadata item.
00292     int type,                          ///< Type of metadata item (psMetadataType) and options (psMetadataFlags)
00293     const char *comment,               ///< Comment for metadata item.
00294     va_list list                       ///< Arguments for name formatting and metadata item data.
00295 );
00296 #endif
00297 
00298 psBool psMetadataAddS32(psMetadata* md, psS32 location, const char* name,
00299                         const char* comment, psS32 value);
00300 psBool psMetadataAddF32(psMetadata* md, psS32 location, const char* name,
00301                         const char* comment, psF32 value);
00302 psBool psMetadataAddF64(psMetadata* md, psS32 location, const char* name,
00303                         const char* comment, psF64 value);
00304 psBool psMetadataAddList(psMetadata* md, psS32 location, const char* name,
00305                          const char* comment, psList* value);
00306 psBool psMetadataAddStr(psMetadata* md, psS32 location, const char* name,
00307                         const char* comment, const char* value);
00308 psBool psMetadataAddVector(psMetadata* md, psS32 location, const char* name,
00309                            const char* comment, psVector* value);
00310 psBool psMetadataAddImage(psMetadata* md, psS32 location, const char* name,
00311                           const char* comment, psImage* value);
00312 psBool psMetadataAddHash(psMetadata* md, psS32 location, const char* name,
00313                          const char* comment, psHash* value);
00314 psBool psMetadataAddLookupTable(psMetadata* md, psS32 location, const char* name,
00315                                 const char* comment, psLookupTable* value);
00316 psBool psMetadataAddUnknown(psMetadata* md, psS32 location, const char* name,
00317                             const char* comment, psPtr value);
00318 
00319 
00320 /** Remove an item from metadata collection.
00321  *
00322  *  Items may be removed from metadata by specifing a key or location. If the
00323  *  name is null, the where argument is used instead. If name is not null,
00324  *  where is set to PS_LIST_UNKNOWN. If the item is found, it is removed from
00325  *  the metadata and true is returned.  If the key is not unique, then all
00326  *  items corresponding to it are removed.
00327  *
00328  * @return bool: True for success, false for failure.
00329  */
00330 psBool psMetadataRemove(
00331     psMetadata*  md,           ///< Metadata collection to remove metadata item.
00332     psS32 where,               ///< Location to be removed.
00333     const char * key           ///< Name of metadata key.
00334 );
00335 
00336 /** Find an item in the metadata collection based on key name.
00337  *
00338  *  Items may be found in the metadata by providing a key. If the key is
00339  *  non-unique, the first item is returned. If the item is not found, null is
00340  *  returned.
00341  *
00342  * @return psMetadataItem* : Pointer metadata item.
00343  */
00344 psMetadataItem* psMetadataLookup(
00345     psMetadata * md,                   ///< Metadata collection to lookup metadata item.
00346     const char * key                   ///< Name of metadata key.
00347 );
00348 
00349 /** Find an item in the metadata collection based on key name and return its double precision value.
00350  *
00351  *  Items may be found in the metadata by providing a key. If the key is
00352  *  non-unique, the value of the first item is returned. If the item is not found, zero is
00353  *  returned.
00354  *
00355  * @return psF64 : Value of metadata item.
00356  */
00357 psF64 psMetadataLookupF64(
00358     psBool *status,                    ///< Status of lookup.
00359     psMetadata *md,                    ///< Metadata collection to lookup metadata item.
00360     const char *key                    ///< Name of metadata key.
00361 );
00362 
00363 /** Find an item in the metadata collection based on key name and return its single precision value.
00364  *
00365  *  Items may be found in the metadata by providing a key. If the key is
00366  *  non-unique, the value of the first item is returned. If the item is not found, zero is
00367  *  returned.
00368  *
00369  * @return psF32 : Value of metadata item.
00370  */
00371 psF32 psMetadataLookupF32(
00372     psBool *status,                    ///< Status of lookup.
00373     psMetadata *md,                    ///< Metadata collection to lookup metadata item.
00374     const char *key                    ///< Name of metadata key.
00375 );
00376 
00377 /** Find an item in the metadata collection based on key name and return its integer value.
00378  *
00379  *  Items may be found in the metadata by providing a key. If the key is
00380  *  non-unique, the value of the first item is returned. If the item is not found, zero is
00381  *  returned.
00382  *
00383  * @return psS32 : Value of metadata item.
00384  */
00385 psS32 psMetadataLookupS32(
00386     psBool *status,                    ///< Status of lookup.
00387     psMetadata *md,                    ///< Metadata collection to lookup metadata item.
00388     const char *key                    ///< Name of metadata key.
00389 );
00390 
00391 /** Find an item in the metadata collection based on key name and return its boolean value.
00392  *
00393  *  Items may be found in the metadata by providing a key. If the key is
00394  *  non-unique, the value of the first item is returned. If the item is not found, zero is
00395  *  returned.
00396  *
00397  * @return psBool : Value of metadata item.
00398  */
00399 psBool psMetadataLookupBool(
00400     psBool *status,                    ///< Status of lookup.
00401     psMetadata *md,                    ///< Metadata collection to lookup metadata item.
00402     const char *key                    ///< Name of metadata key.
00403 );
00404 
00405 /** Find an item in the metadata collection based on key name and return its integer value.
00406  *
00407  *  Items may be found in the metadata by providing a key. If the key is
00408  *  non-unique, the value of the first item is returned. If the item is not found, zero is
00409  *  returned.
00410  *
00411  * @return void* : Value of metadata item.
00412  */
00413 psPtr psMetadataLookupPtr(
00414     psBool *status,                    ///< Status of lookup.
00415     psMetadata* md,                    ///< Metadata collection to lookup metadata item.
00416     const char *key                    ///< Name of metadata key.
00417 );
00418 
00419 /** Find an item in the metadata collection based on list index.
00420  *
00421  *  Items may be found in the metadata by their entry position in the list
00422  *  container.
00423  *
00424  *  @return psMetadataItem* : Pointer metadata item.
00425  */
00426 psMetadataItem* psMetadataGet(
00427     psMetadata*  md,                   ///< Metadata collection to insert metadat item.
00428     psS32 location                     ///< Location to be retrieved.
00429 );
00430 
00431 /** Creates a psMetadataIterator to iterate over the specified psMetadata.
00432  *
00433  *  Supports the subsetting of the metadata via keyword using regular
00434  *  expression.  If no regular expression is specified, iteration
00435  *  over the entire psMetadata is performed.
00436  *
00437  *  @return psMetadataIterator*        a new psMetadataIterator, of NULL if error occurred
00438  */
00439 psMetadataIterator* psMetadataIteratorAlloc(
00440     psMetadata* md,                    ///< the psMetadata to iterate with
00441     int location,                      ///< the initial starting point (after subsetting).
00442     const char* regex
00443     ///< A regular expression for subsetting the psMetadata.  If NULL, no
00444     ///< subsetting is performed.
00445 );
00446 
00447 /** Set the iterator of the psMetadat to a given position.  If location is
00448  *  invalid the iterator position is not changed.
00449  *
00450  *  @return psBool        TRUE if iterator successfully set, otherwise FALSE.
00451 */
00452 psBool psMetadataIteratorSet(
00453     psMetadataIterator* iterator,      ///< psMetadata iterator
00454     int location                       ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL
00455 );
00456 
00457 /** Position the specified iterator to the next matching item in psMetadata,
00458  *  given the regular expression of the iterator
00459  *
00460  *  @return psPtr       the psMetadataItem at the original iterator position
00461  *                      or NULL if the iterator went past the end of the list.
00462  */
00463 psMetadataItem* psMetadataGetAndIncrement(
00464     psMetadataIterator* iterator           ///< iterator to move
00465 );
00466 
00467 /** Position the specified iterator to the previous matching item in psMetadata,
00468  *  given the regular expression of the iterator
00469  *
00470  *  @return psPtr       the psMetadataItem at the original iterator position
00471  *                      or NULL if the iterator went past the beginning of the
00472  *                      list.
00473  */
00474 psMetadataItem* psMetadataGetAndDecrement(
00475     psMetadataIterator* iterator           ///< iterator to move
00476 );
00477 
00478 /// @}
00479 
00480 #endif

Generated on Mon Apr 4 18:24:45 2005 for Pan-STARRS Foundation Library by  doxygen 1.3.9.1