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.1.1.1 $ $Name:  $
00014 *  @date $Date: 2005/06/15 21:08:12 $
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     PS_META_META                       ///< Metadata data (Stored as item.data.md).
00055 } psMetadataType;
00056 
00057 #define PS_META_IS_PRIMITIVE(TYPE) \
00058 (TYPE == PS_META_S32 || \
00059  TYPE == PS_META_F32 || \
00060  TYPE == PS_META_F64 || \
00061  TYPE == PS_META_BOOL)
00062 
00063 #define PS_META_PRIMITIVE_TYPE(METATYPE) ( \
00064         (METATYPE==PS_META_S32) ? PS_TYPE_S32 : \
00065         (METATYPE==PS_META_F32) ? PS_TYPE_F32 : \
00066         (METATYPE==PS_META_F64) ? PS_TYPE_F64 : \
00067         (METATYPE==PS_META_BOOL) ? PS_TYPE_BOOL : 0 )
00068 
00069 /** Option flags for psMetadata functions
00070  *
00071  *  Enumeration for the modification of the behaviour in psMetadataAddItem.
00072  *
00073  *  @see psMetadataAddItem
00074  */
00075 typedef enum {
00076     PS_META_DEFAULT = 0,               ///< default behaviour (duplicate entry is an error)
00077     PS_META_REPLACE = 0x1000000,       ///< allow entry to be replaced
00078     PS_META_DUPLICATE_OK = 0x2000000   ///< allow duplicate entries
00079 } psMetadataFlags;
00080 
00081 #define PS_METADATA_FLAGS_MASK 0xFF000000
00082 #define PS_METADATA_TYPE_MASK 0x00FFFFFF
00083 
00084 /** Metadata data structure.
00085  *
00086  *  Struct for holding metadata items. Metadata items are held in two
00087  *  containers. The first employs a doubly-linked list to preserve the order
00088  *  of the metadata. The second container employs a hash table which
00089  *  allows fast lookup when given a metadata keyword.
00090  */
00091 typedef struct psMetadata
00092 {
00093     psList*  list;                     ///< Metadata in linked-list
00094     psHash*  table;                    ///< Metadata in a hash table
00095 }
00096 psMetadata;
00097 
00098 /** Metadata iterator
00099  *
00100  *  Iterator for metadata.
00101  */
00102 typedef struct
00103 {
00104     psListIterator* iter;              ///< iterator for the psMetadata's psList
00105     regex_t* preg;                     ///< the subsetting regular expression
00106 }
00107 psMetadataIterator;
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 // #ifndef SWIG
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,                    ///< Index number, PS_LIST_HEAD, or PS_LIST_TAIL
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,                    ///< Index number, PS_LIST_HEAD, or PS_LIST_TAIL
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,                    ///< Index number, PS_LIST_HEAD, or PS_LIST_TAIL
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 // #ifndef SWIG
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 psBool psMetadataAddMetadata(psMetadata* md, psS32 location, const char* name,
00319                              const char* comment, psMetadata* value);
00320 
00321 /** Remove an item from metadata collection.
00322  *
00323  *  Items may be removed from metadata by specifing a key or location. If the
00324  *  name is null, the where argument is used instead. If name is not null,
00325  *  where is set to PS_LIST_UNKNOWN. If the item is found, it is removed from
00326  *  the metadata and true is returned.  If the key is not unique, then all
00327  *  items corresponding to it are removed.
00328  *
00329  * @return bool: True for success, false for failure.
00330  */
00331 psBool psMetadataRemove(
00332     psMetadata*  md,           ///< Metadata collection to remove metadata item.
00333     psS32 where,               ///< Index number, PS_LIST_HEAD, or PS_LIST_TAIL
00334     const char * key           ///< Name of metadata key.
00335 );
00336 
00337 /** Find an item in the metadata collection based on key name.
00338  *
00339  *  Items may be found in the metadata by providing a key. If the key is
00340  *  non-unique, the first item is returned. If the item is not found, null is
00341  *  returned.
00342  *
00343  * @return psMetadataItem* : Pointer metadata item.
00344  */
00345 psMetadataItem* psMetadataLookup(
00346     psMetadata * md,                   ///< Metadata collection to lookup metadata item.
00347     const char * key                   ///< Name of metadata key.
00348 );
00349 
00350 /** Find an item in the metadata collection based on key name and return its double precision value.
00351  *
00352  *  Items may be found in the metadata by providing a key. If the key is
00353  *  non-unique, the value of the first item is returned. If the item is not found, zero is
00354  *  returned.
00355  *
00356  * @return psF64 : Value of metadata item.
00357  */
00358 psF64 psMetadataLookupF64(
00359     psBool *status,                    ///< Status of lookup.
00360     psMetadata *md,                    ///< Metadata collection to lookup metadata item.
00361     const char *key                    ///< Name of metadata key.
00362 );
00363 
00364 /** Find an item in the metadata collection based on key name and return its single precision value.
00365  *
00366  *  Items may be found in the metadata by providing a key. If the key is
00367  *  non-unique, the value of the first item is returned. If the item is not found, zero is
00368  *  returned.
00369  *
00370  * @return psF32 : Value of metadata item.
00371  */
00372 psF32 psMetadataLookupF32(
00373     psBool *status,                    ///< Status of lookup.
00374     psMetadata *md,                    ///< Metadata collection to lookup metadata item.
00375     const char *key                    ///< Name of metadata key.
00376 );
00377 
00378 /** Find an item in the metadata collection based on key name and return its integer value.
00379  *
00380  *  Items may be found in the metadata by providing a key. If the key is
00381  *  non-unique, the value of the first item is returned. If the item is not found, zero is
00382  *  returned.
00383  *
00384  * @return psS32 : Value of metadata item.
00385  */
00386 psS32 psMetadataLookupS32(
00387     psBool *status,                    ///< Status of lookup.
00388     psMetadata *md,                    ///< Metadata collection to lookup metadata item.
00389     const char *key                    ///< Name of metadata key.
00390 );
00391 
00392 /** Find an item in the metadata collection based on key name and return its boolean value.
00393  *
00394  *  Items may be found in the metadata by providing a key. If the key is
00395  *  non-unique, the value of the first item is returned. If the item is not found, zero is
00396  *  returned.
00397  *
00398  * @return psBool : Value of metadata item.
00399  */
00400 psBool psMetadataLookupBool(
00401     psBool *status,                    ///< Status of lookup.
00402     psMetadata *md,                    ///< Metadata collection to lookup metadata item.
00403     const char *key                    ///< Name of metadata key.
00404 );
00405 
00406 /** Find an item in the metadata collection based on key name and return its integer value.
00407  *
00408  *  Items may be found in the metadata by providing a key. If the key is
00409  *  non-unique, the value of the first item is returned. If the item is not found, zero is
00410  *  returned.
00411  *
00412  * @return void* : Value of metadata item.
00413  */
00414 psPtr psMetadataLookupPtr(
00415     psBool *status,                    ///< Status of lookup.
00416     psMetadata* md,                    ///< Metadata collection to lookup metadata item.
00417     const char *key                    ///< Name of metadata key.
00418 );
00419 
00420 /** Find an item in the metadata collection based on list index.
00421  *
00422  *  Items may be found in the metadata by their entry position in the list
00423  *  container.
00424  *
00425  *  @return psMetadataItem* : Pointer metadata item.
00426  */
00427 psMetadataItem* psMetadataGet(
00428     psMetadata*  md,                   ///< Metadata collection to retrieve metadata item.
00429     psS32 location                     ///< Index number, PS_LIST_HEAD, or PS_LIST_TAIL
00430 );
00431 
00432 /** Creates a psMetadataIterator to iterate over the specified psMetadata.
00433  *
00434  *  Supports the subsetting of the metadata via keyword using regular
00435  *  expression.  If no regular expression is specified, iteration
00436  *  over the entire psMetadata is performed.
00437  *
00438  *  @return psMetadataIterator*        a new psMetadataIterator, of NULL if error occurred
00439  */
00440 psMetadataIterator* psMetadataIteratorAlloc(
00441     psMetadata* md,                    ///< the psMetadata to iterate with
00442     int location,                      ///< Index number, PS_LIST_HEAD, or PS_LIST_TAIL
00443     const char* regex
00444     ///< A regular expression for subsetting the psMetadata.  If NULL, no
00445     ///< subsetting is performed.
00446 );
00447 
00448 /** Set the iterator of the psMetadat to a given position.  If location is
00449  *  invalid the iterator position is not changed.
00450  *
00451  *  @return psBool        TRUE if iterator successfully set, otherwise FALSE.
00452 */
00453 psBool psMetadataIteratorSet(
00454     psMetadataIterator* iterator,      ///< psMetadata iterator
00455     int location                       ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL
00456 );
00457 
00458 /** Position the specified iterator to the next matching item in psMetadata,
00459  *  given the regular expression of the iterator
00460  *
00461  *  @return psPtr       the psMetadataItem at the original iterator position
00462  *                      or NULL if the iterator went past the end of the list.
00463  */
00464 psMetadataItem* psMetadataGetAndIncrement(
00465     psMetadataIterator* iterator           ///< iterator to move
00466 );
00467 
00468 /** Position the specified iterator to the previous matching item in psMetadata,
00469  *  given the regular expression of the iterator
00470  *
00471  *  @return psPtr       the psMetadataItem at the original iterator position
00472  *                      or NULL if the iterator went past the beginning of the
00473  *                      list.
00474  */
00475 psMetadataItem* psMetadataGetAndDecrement(
00476     psMetadataIterator* iterator           ///< iterator to move
00477 );
00478 
00479 /// @}
00480 
00481 #endif // #ifndef PS_METADATA_H

Generated on Wed Jun 15 11:00:57 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.1