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

psArray.h

Go to the documentation of this file.
00001 
00002 /** @file  psArray.h
00003  *
00004  *  @brief Contains basic array definitions and operations
00005  *
00006  *  This file defines the basic type for a array struct and functions useful
00007  *  in manupulating arrays.
00008  *
00009  *  @ingroup Array
00010  *
00011  *  @author Robert DeSonia, MHPCC
00012  *  @author Ross Harman, MHPCC
00013  *
00014  *  @version $Revision: 1.1.1.1 $ $Name:  $
00015  *  @date $Date: 2005/09/14 20:42:48 $
00016  *
00017  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00018  */
00019 
00020 #ifndef PS_ARRAY_H
00021 #define PS_ARRAY_H
00022 
00023 #include "psType.h"
00024 #include "psCompare.h"
00025 
00026 /// @addtogroup Array
00027 /// @{
00028 
00029 /** An array to support primitive types.
00030  *
00031  * Struct for maintaining an array of frequently used primitive types.
00032  *
00033  */
00034 typedef struct
00035 {
00036     long n;                            ///< Number of elements in use.
00037     const long nalloc;                 ///< Total number of elements available.
00038     psPtr* data;                       ///< An Array of pointer elements
00039     void *lock;                        ///< Optional lock for thread safety
00040 }
00041 psArray;
00042 
00043 /*****************************************************************************/
00044 
00045 /* FUNCTION PROTOTYPES                                                       */
00046 
00047 /*****************************************************************************/
00048 
00049 /** Checks the type of a particular pointer.
00050  *
00051  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00052  *
00053  *  @return bool:       True if the pointer matches a psArray structure, false otherwise.
00054  */
00055 bool psMemCheckArray(
00056     psPtr ptr                          ///< the pointer whose type to check
00057 )
00058 ;
00059 
00060 
00061 /** Allocate an array.
00062  *
00063  * Uses psLib memory allocation functions to create an array collection of
00064  * data
00065  *
00066  * @return psArray* : Pointer to psArray.
00067  *
00068  */
00069 psArray* psArrayAlloc(
00070     long nalloc                        ///< Total number of elements to make available.
00071 );
00072 
00073 /** Reallocate an array.
00074  *
00075  * Uses psLib memory allocation functions to reallocate an array collection
00076  * of data.
00077  *
00078  * @return psArray* : Pointer to psArray.
00079  *
00080  */
00081 psArray* psArrayRealloc(
00082     psArray* array,                    ///< array to reallocate.
00083     long nalloc                        ///< Total number of elements to make available.
00084 );
00085 
00086 /** Add an element to the end the array, expanding the array storage if
00087  *  necessary.
00088  *
00089  *  @return psArray*        The array with the element added
00090  */
00091 psArray* psArrayAdd(
00092     psArray* array,                    ///< array to operate on
00093     long delta,
00094     ///< the amount to expand array, if necessary.  If less than one, 10 will be used.
00095     psPtr data                         ///< the data pointer to add to psArray
00096 );
00097 
00098 /** Remove an element from the array
00099  *
00100  *  Finds and removes the specified data pointer from the list.
00101  *
00102  * @return bool:  TRUE if the specified data pointer was found and removed,
00103  *                otherwise FALSE.
00104  *
00105  */
00106 bool psArrayRemove(
00107     psArray* array,                    ///< array to operate on
00108     const psPtr data                   ///< the data pointer to remove from psArray
00109 );
00110 
00111 /** Deallocate/Dereference elements of an array.
00112  *
00113  * Uses psLib memory allocation functions to deallocate/dereference elements
00114  * of a array of void pointers.  The array psArr is not freed, and its elements
00115  * will all be set to NULL.
00116  *
00117  */
00118 void psArrayElementFree(
00119     psArray* psArr                     ///< Void pointer array to destroy.
00120 );
00121 
00122 /** Sort the array according to an external compare function.
00123  *
00124  *  Sorts an array via the specification of a comparison function
00125  *  to specify how the objects on the array should be sorted.
00126  *
00127  *  The comparison function must return an integer less than, equal to, or
00128  *  greater than zero if the first argument is considered to be respectively
00129  *  less than, equal to, or greater than the second.
00130  *
00131  *  If two members compare as equal, their order in the sorted array is
00132  *  undefined.
00133  *
00134  *  @return psArray* The sorted array.
00135  */
00136 psArray* psArraySort(
00137     psArray* array,                       ///< input array to sort.
00138     psComparePtrFunc func                 ///< the compare function
00139 );
00140 
00141 /** Set an element in the array.  If the current element is non-NULL, the old
00142  *  element is freed.
00143  *
00144  *  @return psBool  TRUE if the element was set successfully, otherwise FALSE
00145  */
00146 bool psArraySet(
00147     psArray* array,                    ///< input array to set element in
00148     long position,                     ///< the element position to set
00149     psPtr data                         ///< the value to set it to
00150 );
00151 
00152 /** Get an element from the array.
00153  *
00154  *  @return void*   the element at given position.
00155  */
00156 psPtr psArrayGet(
00157     const psArray* array,              ///< input array to get element from
00158     long position                      ///< the element position to get
00159 );
00160 
00161 /// @}
00162 
00163 #endif // #ifndef PS_ARRAY_H

Generated on Wed Sep 14 10:42:48 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2