IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 5, 2004, 10:43:57 AM (22 years ago)
Author:
harman
Message:

Updated per SDR documentation bug fixes

File:
1 edited

Legend:

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

    r542 r578  
    1 /** @file  psBitMask.c
     1/** @file  psBitSet.c
    22 *
    3  *  @brief Creates an array of bits of arbitrary length.
     3 *  @brief Creates an array of bytes of arbitrary length for storing individual bits.
    44 *
    5  *  Bit masks are useful for turning options on and off. This module provides functions to create an array of
    6  *  bits of arbitrary length and manipulate them with basic binary operations. A print function is also
    7  *  provided to display the entire set of bits in binary form.
     5 *  Bit masks are useful tools for toggling various flags and options. This set of functions module provides
     6 *  a mechanism to create an array of bits of arbitrary length and manipulate them with basic binary
     7 *  operations. A print function is also provided to display the entire set of bits in binary format as a
     8 *  string.
    89 *
    910 *  @author Ross Harman, MHPCC
    1011 *   
    11  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-04-28 17:47:24 $
     12 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-05-05 20:43:22 $
    1314 *
    1415 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2223#include <ctype.h>
    2324
    24 #include "psBitMask.h"
     25#include "psBitSet.h"
    2526#include "psMemory.h"
     27#include "psError.h"
     28
     29/******************************************************************************/
     30/*  DEFINE STATEMENTS                                                         */
     31/******************************************************************************/
     32
     33// None
     34
     35/******************************************************************************/
     36/*  TYPE DEFINITIONS                                                          */
     37/******************************************************************************/
     38
     39// None
     40
     41/*****************************************************************************/
     42/*  GLOBAL VARIABLES                                                         */
     43/*****************************************************************************/
     44
     45// None
     46
     47/*****************************************************************************/
     48/*  FILE STATIC VARIABLES                                                    */
     49/*****************************************************************************/
     50
     51// None
    2652
    2753/*****************************************************************************/
    2854/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    2955/*****************************************************************************/
    30 static char* getByte(int bit, const psBitMask *restrict inMask)
     56
     57/** Private function to return a byte.
     58 *
     59 *  Finds the byte containing the bit within the byte array.
     60 *
     61 *  @return  char*: Pointer to byte in which bit is contained.
     62 */
     63static char* getByte(int bit, const psBitSet *restrict inMask)
    3164{
    3265    int index = 0;
     
    3871}
    3972
     73/** Private function to create a mask.
     74 *
     75 *  Creates an eight bit mask with the given bit set. All other bits in the byte are zero. The input bit uses
     76 *  zero-based indexing, and is the cumulitive index within the array, not the localized byte's bit position.
     77 *
     78 *  @return  char*: Pointer to byte in which bit is contained.
     79 */
    4080static char mask(int bit)
    4181{
     
    4989/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
    5090/*****************************************************************************/
    51 psBitMask* psBitMaskAlloc(int n)
     91psBitSet* psBitSetAlloc(int n)
    5292{
    53     psBitMask *newObj = psAlloc(sizeof(psBitMask));
     93    psBitSet *newObj = psAlloc(sizeof(psBitSet));
    5494    newObj->n = n;
    5595    newObj->bits = psAlloc(sizeof(char)*n);
     
    5999}
    60100
    61 void psBitMaskFree(psBitMask *restrict inMask)
     101void psBitSetFree(psBitSet *restrict inBitSet)
    62102{
    63     psFree(inMask->bits);
    64     psFree(inMask);
     103    psFree(inBitSet->bits);
     104    psFree(inBitSet);
    65105}
    66106
    67 psBitMask* psBitMaskSet(psBitMask *inMask, int bit)
     107psBitSet* psBitSetSet(psBitSet *inBitSet, int bit)
    68108{
    69     char* byte = getByte(bit, inMask);
     109    char* byte = getByte(bit, inBitSet);
    70110    *byte |= mask(bit);
    71111
    72     return inMask;
     112    return inBitSet;
    73113}
    74114
    75 int psBitMaskTest(const psBitMask *inMask, int bit)
     115int psBitSetTest(const psBitSet *inBitSet, int bit)
    76116{
    77     char* byte = getByte(bit, inMask);
     117    char* byte = getByte(bit, inBitSet);
    78118    if((*byte&mask(bit)) == 0) {
    79119        return 0;
     
    83123}
    84124
    85 psBitMask* psBitMaskOp(psBitMask *outMask, const psBitMask *restrict inMask1, char *operator,
    86                        const psBitMask *restrict inMask2)
     125psBitSet* psBitSetOp(psBitSet *outBitSet, const psBitSet *restrict inBitSet1, char *operator,
     126                     const psBitSet *restrict inBitSet2)
    87127{
    88128    int i = 0;
     
    93133    char *inBits2 = NULL;
    94134
    95     if(outMask == NULL) {
    96         printf("Null output psBitMask\n");
    97         return outMask;
     135    if(outBitSet == NULL) {
     136        psError(__func__, " : Line %d - Null psBitSet for outBitSet argument\n", __LINE__);
     137        return outBitSet;
    98138    }
    99139
    100     if(inMask1 == NULL) {
    101         printf("Null input psBitMask1\n");
    102         return outMask;
     140    if(inBitSet1 == NULL) {
     141        psError(__func__, " : Line %d - Null psBitSet for inBitSet1 argument\n", __LINE__);
     142        return outBitSet;
    103143    }
    104144
    105145    if(operator == NULL) {
    106         printf("Null input operator\n");
    107         return outMask;
    108 
     146        psError(__func__, " : Line %d - Null input operator\n", __LINE__);
     147        return outBitSet;
    109148    }
    110149
    111     if(inMask2 == NULL) {
    112         printf("Null input psBitMask2\n");
    113         return outMask;
     150    if(inBitSet2 == NULL) {
     151        psError(__func__, " : Line %d - Null psBitSet for inBitSet2 argument\n", __LINE__);
     152        return outBitSet;
    114153    }
    115154
    116     if(inMask1->n != inMask2->n || outMask->n != inMask1->n) {
    117         printf("Mask sizes not the same\n");
    118         return outMask;
     155    if(inBitSet1->n != inBitSet2->n || outBitSet->n != inBitSet1->n) {
     156        psError(__func__, " : Line %d - psBitSet sizes not the same\n", __LINE__);
     157        return outBitSet;
    119158    }
    120159
    121     n = outMask->n;
    122     outBits = outMask->bits;
    123     inBits1 = inMask1->bits;
    124     inBits2 = inMask2->bits;
     160    n = outBitSet->n;
     161    outBits = outBitSet->bits;
     162    inBits1 = inBitSet1->bits;
     163    inBits2 = inBitSet2->bits;
    125164
    126165    tempChar = toupper(*operator);
     
    142181        break;
    143182    default:
    144         printf("Invalid psBitMask option %s\n", operator);
     183        psError(__func__, " : Line %d - Invalid psBitMask binary operation: %s\n", __LINE__);
    145184    }
    146185
    147     return outMask;
     186    return outBitSet;
    148187}
    149188
    150 char *psBitMaskToString(const psBitMask *restrict inMask)
     189char *psBitSetToString(const psBitSet *restrict inBitSet)
    151190{
    152191    int i = 0;
    153     int numBits = inMask->n*8;
    154     char* outString = (char*)malloc(numBits);
     192    int numBits = inBitSet->n*8;
     193    char* outString = psAlloc(numBits);
    155194    for(i=0; i<numBits; i++) {
    156         outString[numBits-i-1] = (psBitMaskTest(inMask, i))?'1':'0';
     195        outString[numBits-i-1] = (psBitSetTest(inBitSet, i))?'1':'0';
    157196    }
    158197
Note: See TracChangeset for help on using the changeset viewer.