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 * @author PAP, EAM, IfA 00011 * @author Ross Harman, MHPCC 00012 * 00013 * @version $Revision: 1.28 $ $Name: $ 00014 * @date $Date: 2007/01/23 22:47:23 $ 00015 * 00016 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 00017 */ 00018 00019 #ifndef PSBITSET_H 00020 #define PSBITSET_H 00021 00022 #include "psType.h" 00023 00024 /// @addtogroup DataContainer Data Containers 00025 /// @{ 00026 00027 /******************************************************************************/ 00028 /* TYPE DEFINITIONS */ 00029 /******************************************************************************/ 00030 00031 /** Struct containing array of bytes to hold bit data and corresponding array length. 00032 * 00033 * The bits in the struct are assembled in as an array of bytes with eight bits per 00034 * byte. The bits are arranged with the LSB in first (right most) position of the 00035 * 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 00063 * to zero upon 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 00075 * example, setting bit 3 in an array with two elements would result in an psBitSet 00076 * that looks like 00000000 00001000. 00077 * 00078 * @return psBitSet* : Pointer to struct containing psBitSet. 00079 */ 00080 psBitSet* psBitSetSet( 00081 psBitSet* bitSet, ///< Pointer to psBitSet to be set. 00082 long bit ///< Bit to be set. 00083 ); 00084 00085 /** Clear a bit. 00086 * 00087 * Clear a bit at a given bit location. The bit is cleared based on a zero 00088 * index with the first bit set in the zero bit slot of the zero element of 00089 * the byte array. 00090 * 00091 * @return psBitSet* : Pointer to struct containing psBitSet. 00092 */ 00093 psBitSet* psBitSetClear( 00094 psBitSet* bitSet, ///< Pointer to psBitSet to be cleared. 00095 long bit ///< Bit to be cleared. 00096 ); 00097 00098 /** Test the value of a bit. 00099 * 00100 * Prints the value of a bit at a given bit location, either one or zero. The resulting 00101 * bit is based on a zero index format with the first bit set in the zero bit slot of 00102 * the zero element of the byte array. As an example, testing bit 3 in a psBitSet with 00103 * two bytes that looks like 00000000 00001000 would return a value of one, since that 00104 * is the value that was set. 00105 * 00106 * @return bool: True if successful, otherwise false 00107 */ 00108 bool psBitSetTest( 00109 const psBitSet* bitSet, ///< Pointer psBitSet to be tested. 00110 long bit ///< Bit to be tested. 00111 ); 00112 00113 /** Perform a binary operation on two psBitSets 00114 * 00115 * Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, 00116 * the operation will not be performed and an error message will be logged. 00117 * 00118 * @return psBitSet* : Pointer to struct containing result of binary operation. 00119 */ 00120 psBitSet* psBitSetOp( 00121 psBitSet* outBitSet, ///< Resulting psBitSet from binary operation 00122 const psBitSet* inBitSet1, ///< First psBitSet on which to operate 00123 const char *operator, ///< Bit operation 00124 const psBitSet* inBitSet2 ///< Second psBitSet on which to operate 00125 ); 00126 00127 /** Perform a not operation on a psBitSet 00128 * 00129 * Toggles bits in a psBitset. All zero bits are set to one and all one bits are set 00130 * to zero. 00131 * 00132 * @return psBitSet* : Pointer to struct containing result of operation. 00133 */ 00134 psBitSet* psBitSetNot( 00135 psBitSet* outBitSet, ///< Resulting psBitSet from operation 00136 const psBitSet* inBitSet ///< Input psBitSet 00137 ); 00138 00139 /** Convert the psBitSet to a string of ones and zeros. 00140 * 00141 * Converts the contents of a psBitSet to a string representation of its binary form of 00142 * ones and zeros. The LSB is the right-most chracter. Each set of eight characters 00143 * represents one byte. 00144 * 00145 * @return psString: Pointer to character array containing string data. 00146 */ 00147 psString psBitSetToString( 00148 const psBitSet* bitSet ///< psBitSet to convert 00149 ); 00150 00151 /// @} 00152 #endif // #ifndef PSBITSET_H
1.5.1