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

psBitSet.h

Go to the documentation of this file.
00001 /** @file  psBitSet.h
00002  *
00003  *  @brief Creates an array of bytes of arbitrary length for storing individual bits.
00004  *
00005  *  Bit masks are useful tools for toggling various flags and options. This set of functions module provides
00006  *  a mechanism to create an array of bits of arbitrary length and manipulate them with basic binary
00007  *  operations. A print function is also provided to display the entire set of bits in binary format as a
00008  *  string.
00009  *
00010  *  @ingroup BitSet
00011  *
00012  *  @author Ross Harman, MHPCC
00013  *
00014  *  @version $Revision: 1.24 $ $Name: rel8_0 $
00015  *  @date $Date: 2005/09/15 21:22:22 $
00016  *
00017  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00018  */
00019 
00020 #ifndef PSBITSET_H
00021 #define PSBITSET_H
00022 
00023 #include "psType.h"
00024 
00025 /// @addtogroup BitSet
00026 /// @{
00027 
00028 /******************************************************************************/
00029 /*  TYPE DEFINITIONS                                                          */
00030 /******************************************************************************/
00031 
00032 /** Struct containing array of bytes to hold bit data and corresponding array length.
00033  *
00034  *  The bits in the struct are assembled in as an array of bytes with eight bits per byte. The bits are
00035  *  arranged with the LSB in first (right most) position of the first array element.
00036  */
00037 typedef struct
00038 {
00039     long n;                            ///< Number of bytes in the array
00040     psU8 *bits;                        ///< Aray of bytes holding bits
00041     void *lock;                        ///< Optional lock for thread safety
00042 }
00043 psBitSet;
00044 
00045 /*****************************************************************************/
00046 /* FUNCTION PROTOTYPES                                                       */
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 psBitSet structure, false otherwise.
00054  */
00055 bool psMemCheckBitSet(
00056     psPtr ptr                          ///< the pointer whose type to check
00057 )
00058 ;
00059 
00060 /** Allocate a psBitSet.
00061  *
00062  *  Create a psBitSet with the number of bits specified by the user. All bits are set to zero upon
00063  *  allocation.
00064  *
00065  *  @return  psBitSet* : Pointer to struct containing array of bits and size of array.
00066  */
00067 psBitSet* psBitSetAlloc(
00068     long nalloc                            ///< Number of bits in psBitSet array
00069 );
00070 
00071 /** Set a bit.
00072  *
00073  *  Sets a bit at a given bit location. The bit is set based on a zero index with the
00074  *  first bit set in the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in
00075  *  an array with two elements would result in an psBitSet that looks like 00000000 00001000.
00076  *
00077  *  @return  psBitSet* : Pointer to struct containing psBitSet.
00078  */
00079 psBitSet* psBitSetSet(
00080     psBitSet* bitSet,                  ///< Pointer to psBitSet to be set.
00081     long bit                           ///< Bit to be set.
00082 );
00083 
00084 /** Clear a bit.
00085  *
00086  *  Clear a bit at a given bit location. The bit is cleared based on a zero
00087  *  index with the first bit set in the zero bit slot of the zero element of
00088  *  the byte array.
00089  *
00090  *  @return  psBitSet* : Pointer to struct containing psBitSet.
00091  */
00092 psBitSet* psBitSetClear(
00093     psBitSet* bitSet,                  ///< Pointer to psBitSet to be cleared.
00094     long bit                           ///< Bit to be cleared.
00095 );
00096 
00097 /** Test the value of a bit.
00098  *
00099  *  Prints the value of a bit at a given bit location, either one or zero. The resulting bit is based on a
00100  *  zero index format with the first bit set in the zero bit slot of the zero element of the byte array
00101  *  As an example, testing bit 3 in a psBitSet with two bytes that looks like 00000000 00001000 would return a
00102  *  value of one, since that is the value that was set.
00103  *
00104  *  @return  bool:      True if successful, otherwise false
00105  */
00106 
00107 bool psBitSetTest(
00108     const psBitSet* bitSet,            ///< Pointer psBitSet to be tested.
00109     long bit                           ///< Bit to be tested.
00110 );
00111 
00112 /** Perform a binary operation on two psBitSets
00113  *
00114  *  Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, the operation will not
00115  *  be performed and an error message will be logged.
00116  *
00117  *  @return  psBitSet* : Pointer to struct containing result of binary operation.
00118  */
00119 psBitSet* psBitSetOp(
00120     psBitSet* outBitSet,                 ///< Resulting psBitSet from binary operation
00121     const psBitSet* inBitSet1,           ///< First psBitSet on which to operate
00122     const char *operator,                    ///< Bit operation
00123     const psBitSet* inBitSet2            ///< First psBitSet on which to operate
00124 );
00125 
00126 /** Perform a not operation on a psBitSet
00127  *
00128  *  Toggles bits in a psBitset. All zero bits are set to one and all one bits are set to zero.
00129  *
00130  *  @return  psBitSet* : Pointer to struct containing result of operation.
00131  */
00132 
00133 psBitSet* psBitSetNot(
00134     psBitSet* outBitSet,               ///< Resulting psBitSet from operation
00135     const psBitSet* inBitSet           ///< Input psBitSet
00136 );
00137 
00138 /** Convert the psBitSet to a string of ones and zeros.
00139  *
00140  *  Converts the contents of a psBitSet to a string representation of its binary form of ones and zeros. The
00141  *  LSB is the right-most chracter. Each set of eight characters represents one byte.
00142  *
00143  *  @return  char*: Pointer to character array containing string data.
00144  */
00145 
00146 psString psBitSetToString(
00147     const psBitSet* bitSet             ///< psBitSet to convert */
00148 );
00149 
00150 /// @}
00151 
00152 #endif // #ifndef PSBITSET_H

Generated on Tue Dec 6 17:18:42 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2