IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9082 for trunk/psLib/src/types


Ignore:
Timestamp:
Sep 30, 2006, 2:40:35 PM (20 years ago)
Author:
drobbin
Message:

Fixed BitSet test and corresponding small fixes to src/psBitSet's. Updated Makefile in test/types and execute tap. Added <string.h> to tap tests missing it.

Location:
trunk/psLib/src/types
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psBitSet.c

    r8973 r9082  
    1111 *  @author Robert DeSonia, MHPCC
    1212 *
    13  *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-09-26 02:55:34 $
     13 *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-10-01 00:40:35 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2727#include "psAbort.h"
    2828#include "psString.h"
     29#include "psAssert.h"
    2930
    3031
     
    6061static void bitSetFree(psBitSet* inBitSet)
    6162{
    62     if (inBitSet == NULL) {
    63         return;
    64     }
    6563    psFree(inBitSet->bits);
    6664}
     
    7775psBitSet* psBitSetAlloc(long nalloc)
    7876{
     77    if (nalloc < 0) {
     78        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     79                _("The number of bit in a psBitSet (%ld) must be greater than zero."),
     80                nalloc);
     81        return NULL;
     82    }
     83
    7984    psS32 numBytes = 0;
    8085    psBitSet* newObj = NULL;
    81 
    82     if (nalloc < 0) {
    83         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    84                 _("The number of bit in a psBitSet (%ld) must be greater than zero."),
    85                 nalloc);
    86         return NULL;
    87     }
    8886
    8987    numBytes = ceil(nalloc / 8.0);
     
    174172                     const psBitSet* inBitSet2)
    175173{
     174    if (inBitSet1 == NULL) {
     175        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     176                _("First psBitSet operand can not be NULL."));
     177        psFree(outBitSet);
     178        return NULL;
     179    }
     180    if (operator == NULL) {
     181        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     182                _("Specified operator is NULL.  Must specify desired operator."));
     183        psFree(outBitSet);
     184        return NULL;
     185    }
    176186    psS32 i = 0;
    177187    psS32 n = 0;
     
    181191    psS32 op = UNKNOWN_OP;
    182192
    183     if (inBitSet1 == NULL) {
    184         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    185                 _("First psBitSet operand can not be NULL."));
    186         psFree(outBitSet);
    187         return NULL;
    188     }
    189193    inBits1 = inBitSet1->bits;
    190194
    191     if (operator == NULL) {
    192         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    193                 _("Specified operator is NULL.  Must specify desired operator."));
    194         psFree(outBitSet);
    195         return NULL;
    196     }
    197195
    198196    // parse the operator
     
    257255        break;
    258256    case NOT_OP:
     257    default:
    259258        for (i = 0; i < n; i++) {
    260259            outBits[i] = ~inBits1[i];
    261260        }
    262261        break;
    263     default:
    264         psAbort("psBitSetOp",
    265                 "Unexpected error - operator parsed successfully but not valid?");
    266262    }
    267263
     
    281277    outBitSet = psBitSetOp(outBitSet,inBitSet,"NOT",NULL);
    282278
    283     if (outBitSet == NULL) {
    284         psError(PS_ERR_UNKNOWN, false,
    285                 _("Could not perform NOT operation."));
    286     }
    287 
    288279    return outBitSet;
    289280}
     
    291282psString psBitSetToString(const psBitSet* bitSet)
    292283{
     284    PS_ASSERT_PTR_NON_NULL(bitSet, NULL);
    293285    psS32 i = 0;
    294286    psS32 numBits = bitSet->n * 8;
    295     char *outString = psAlloc((size_t) numBits + 1);
     287    //    char *outString = psAlloc((size_t) numBits + 1);
     288    psString outString = psStringAlloc(numBits + 1);
    296289
    297290    for (i = 0; i < numBits; i++) {
  • trunk/psLib/src/types/psBitSet.h

    r8973 r9082  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2006-09-26 02:55:34 $
     14 *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-10-01 00:40:35 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3232/** Struct containing array of bytes to hold bit data and corresponding array length.
    3333 *
    34  *  The bits in the struct are assembled in as an array of bytes with eight bits per byte. The bits are
    35  *  arranged with the LSB in first (right most) position of the first array element.
     34 *  The bits in the struct are assembled in as an array of bytes with eight bits per
     35 *  byte. The bits are arranged with the LSB in first (right most) position of the
     36 *  first array element.
    3637 */
    3738typedef struct
     
    5152 *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
    5253 *
    53  *  @return bool:       True if the pointer matches a psBitSet structure, false otherwise.
     54 *  @return bool:     True if the pointer matches a psBitSet structure, false otherwise.
    5455 */
    5556bool psMemCheckBitSet(
     
    6061/** Allocate a psBitSet.
    6162 *
    62  *  Create a psBitSet with the number of bits specified by the user. All bits are set to zero upon
    63  *  allocation.
     63 *  Create a psBitSet with the number of bits specified by the user. All bits are set
     64 *  to zero upon allocation.
    6465 *
    6566 *  @return  psBitSet* : Pointer to struct containing array of bits and size of array.
    6667 */
    6768psBitSet* psBitSetAlloc(
    68     long nalloc                            ///< Number of bits in psBitSet array
     69    long nalloc                        ///< Number of bits in psBitSet array
    6970);
    7071
     
    7273 *
    7374 *  Sets a bit at a given bit location. The bit is set based on a zero index with the
    74  *  first bit set in the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in
    75  *  an array with two elements would result in an psBitSet that looks like 00000000 00001000.
     75 *  first bit set in the zero bit slot of the zero element of the byte array. As an
     76 *  example, setting bit 3 in an array with two elements would result in an psBitSet
     77 *  that looks like 00000000 00001000.
    7678 *
    7779 *  @return  psBitSet* : Pointer to struct containing psBitSet.
     
    9799/** Test the value of a bit.
    98100 *
    99  *  Prints the value of a bit at a given bit location, either one or zero. The resulting bit is based on a
    100  *  zero index format with the first bit set in the zero bit slot of the zero element of the byte array
    101  *  As an example, testing bit 3 in a psBitSet with two bytes that looks like 00000000 00001000 would return a
    102  *  value of one, since that is the value that was set.
     101 *  Prints the value of a bit at a given bit location, either one or zero. The resulting
     102 *  bit is based on a zero index format with the first bit set in the zero bit slot of
     103 *  the zero element of the byte array.  As an example, testing bit 3 in a psBitSet with
     104 *  two bytes that looks like 00000000 00001000 would return a value of one, since that
     105 *  is the value that was set.
    103106 *
    104107 *  @return  bool:      True if successful, otherwise false
    105108 */
    106 
    107109bool psBitSetTest(
    108110    const psBitSet* bitSet,            ///< Pointer psBitSet to be tested.
     
    112114/** Perform a binary operation on two psBitSets
    113115 *
    114  *  Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, the operation will not
    115  *  be performed and an error message will be logged.
     116 *  Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size,
     117 *  the operation will not be performed and an error message will be logged.
    116118 *
    117119 *  @return  psBitSet* : Pointer to struct containing result of binary operation.
    118120 */
    119121psBitSet* psBitSetOp(
    120     psBitSet* outBitSet,                 ///< Resulting psBitSet from binary operation
    121     const psBitSet* inBitSet1,           ///< First psBitSet on which to operate
    122     const char *operator,                    ///< Bit operation
    123     const psBitSet* inBitSet2            ///< First psBitSet on which to operate
     122    psBitSet* outBitSet,               ///< Resulting psBitSet from binary operation
     123    const psBitSet* inBitSet1,         ///< First psBitSet on which to operate
     124    const char *operator,              ///< Bit operation
     125    const psBitSet* inBitSet2          ///< Second psBitSet on which to operate
    124126);
    125127
    126128/** Perform a not operation on a psBitSet
    127129 *
    128  *  Toggles bits in a psBitset. All zero bits are set to one and all one bits are set to zero.
     130 *  Toggles bits in a psBitset. All zero bits are set to one and all one bits are set
     131 *  to zero.
    129132 *
    130133 *  @return  psBitSet* : Pointer to struct containing result of operation.
    131134 */
    132 
    133135psBitSet* psBitSetNot(
    134136    psBitSet* outBitSet,               ///< Resulting psBitSet from operation
     
    138140/** Convert the psBitSet to a string of ones and zeros.
    139141 *
    140  *  Converts the contents of a psBitSet to a string representation of its binary form of ones and zeros. The
    141  *  LSB is the right-most chracter. Each set of eight characters represents one byte.
     142 *  Converts the contents of a psBitSet to a string representation of its binary form of
     143 *  ones and zeros. The LSB is the right-most chracter. Each set of eight characters
     144 *  represents one byte.
    142145 *
    143  *  @return  char*: Pointer to character array containing string data.
     146 *  @return  psString:      Pointer to character array containing string data.
    144147 */
    145 
    146148psString psBitSetToString(
    147     const psBitSet* bitSet             ///< psBitSet to convert */
     149    const psBitSet* bitSet             ///< psBitSet to convert
    148150);
    149151
Note: See TracChangeset for help on using the changeset viewer.