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.1.1.1 $ $Name:  $
00015  *  @date $Date: 2005/06/15 21:08:12 $
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     psS32 n;                             ///< Number of bytes in the array
00040     char *bits;                        ///< Aray of bytes holding bits
00041 }
00042 psBitSet;
00043 
00044 /*****************************************************************************/
00045 /* FUNCTION PROTOTYPES                                                       */
00046 /*****************************************************************************/
00047 
00048 /** Allocate a psBitSet.
00049  *
00050  *  Create a psBitSet with the number of bits specified by the user. All bits are set to zero upon
00051  *  allocation.
00052  *
00053  *  @return  psBitSet* : Pointer to struct containing array of bits and size of array.
00054  */
00055 
00056 /*@null@*/
00057 psBitSet* psBitSetAlloc(
00058     psS32 n                            ///< Number of bits in psBitSet array
00059 );
00060 
00061 /** Set a bit.
00062  *
00063  *  Sets a bit at a given bit location. The bit is set based on a zero index with the
00064  *  first bit set in the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in
00065  *  an array with two elements would result in an psBitSet that looks like 00000000 00001000.
00066  *
00067  *  @return  psBitSet* : Pointer to struct containing psBitSet.
00068  */
00069 psBitSet* psBitSetSet(
00070     /* @returned@ */
00071     psBitSet* inMask,                  ///< Pointer to psBitSet to be set.
00072     psS32 bit                          ///< Bit to be set.
00073 );
00074 
00075 /** Clear a bit.
00076  *
00077  *  Clear a bit at a given bit location. The bit is cleared based on a zero
00078  *  index with the first bit set in the zero bit slot of the zero element of
00079  *  the byte array.
00080  *
00081  *  @return  psBitSet* : Pointer to struct containing psBitSet.
00082  */
00083 psBitSet* psBitSetClear(
00084     /* @returned@ */
00085     psBitSet* inMask,                  ///< Pointer to psBitSet to be cleared.
00086     psS32 bit                          ///< Bit to be cleared.
00087 );
00088 
00089 /** Test the value of a bit.
00090  *
00091  *  Prints the value of a bit at a given bit location, either one or zero. The resulting bit is based on a
00092  *  zero index format with the first bit set in the zero bit slot of the zero element of the byte array
00093  *  As an example, testing bit 3 in a psBitSet with two bytes that looks like 00000000 00001000 would return a
00094  *  value of one, since that is the value that was set.
00095  *
00096  *  @return  int: Value of bit, either one or zero.
00097  */
00098 
00099 psBool psBitSetTest(
00100     const psBitSet* inMask,            ///< Pointer psBitSet to be tested.
00101     psS32 bit                          ///< Bit to be tested.
00102 );
00103 
00104 /** Perform a binary operation on two psBitSets
00105  *
00106  *  Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, the operation will not
00107  *  be performed and an error message will be logged.
00108  *
00109  *  @return  psBitSet* : Pointer to struct containing result of binary operation.
00110  */
00111 psBitSet* psBitSetOp(
00112     /* @returned@ */
00113     psBitSet* outMask,                 ///< Resulting psBitSet from binary operation
00114     const psBitSet* inMask1,           ///< First psBitSet on which to operate
00115     char *operator,                    ///< Bit operation
00116     const psBitSet* inMask2            ///< First psBitSet on which to operate
00117 );
00118 
00119 /** Perform a not operation on a psBitSet
00120  *
00121  *  Toggles bits in a psBitset. All zero bits are set to one and all one bits are set to zero.
00122  *
00123  *  @return  psBitSet* : Pointer to struct containing result of operation.
00124  */
00125 
00126 psBitSet* psBitSetNot(
00127     psBitSet* outBitSet,               ///< Resulting psBitSet from operation
00128     const psBitSet* inBitSet           ///< Input psBitSet
00129 );
00130 
00131 /** Convert the psBitSet to a string of ones and zeros.
00132  *
00133  *  Converts the contents of a psBitSet to a string representation of its binary form of ones and zeros. The
00134  *  LSB is the right-most chracter. Each set of eight characters represents one byte.
00135  *
00136  *  @return  char*: Pointer to character array containing string data.
00137  */
00138 
00139 char *psBitSetToString(
00140     const psBitSet* inMask             ///< psBitSet to convert */
00141 );
00142 
00143 /// @}
00144 
00145 #endif // #ifndef PSBITSET_H

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