IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 16, 2004, 4:43:59 PM (22 years ago)
Author:
harman
Message:

Added Doxygen comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psBitMask.h

    r437 r438  
     1/** @file  psBitMask.h
     2 *
     3 *  @brief Creates an array of bits of arbitrary length.
     4 *
     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.
     8 *
     9 *  @author Ross Harman, MHPCC
     10 *   
     11 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-04-17 02:43:59 $
     13 *
     14 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     15 */
     16 
     17#ifndef PSBITMASK_H
     18#define PSBITMASK_H
     19 
     20/******************************************************************************/
     21/*  TYPE DEFINITIONS                                                          */
     22/******************************************************************************/
     23
     24/** Struct containing array of bits and its length.
     25 *
     26 *  The bits in the struct are assembled in as an array of bytes with eight bits per byte. The bits are
     27 *  arranged with the LSB in first position of the first array element.
     28 */
    129typedef struct {
    2     int n;
    3     char *bits;
     30    int n;      /**< Number of bytes in the array */
     31    char *bits; /**< Aray of bytes holding bits */
    432} psBitMask;
    533
    6 psBitMask* psBitMaskAlloc(int n);
    7 void psBitMaskFree(psBitMask *restrict inMask);
    8 psBitMask* psBitMaskSet(psBitMask *inMask, int bit);
    9 int psBitMaskTest(const psBitMask *inMask, int bit);
    10 psBitMask* psBitMaskOp(psBitMask *outMask, const psBitMask *restrict inMask1, char *operator, const psBitMask *restrict inMask2);
    11 char *psBitMaskToString(const psBitMask *restrict inMask);
    12 static char* getByte(int bit, const psBitMask* inMask);
    13 static char mask(int bit);
     34/*****************************************************************************/
     35/* FUNCTION PROTOTYPES                                                       */
     36/*****************************************************************************/
     37
     38/** Allocate a psBitMask.
     39 *
     40 *  Create a psBitMask with number of bytes specified by the user. All bits are set to zero upon allocation.
     41 *
     42 *  @return  psBitMask*: Pointer to struct containing array of bits and size of array.
     43 */
     44psBitMask* psBitMaskAlloc(
     45    int n   /**< Number of bytes in array */
     46);
     47
     48/** Free a psBitMask
     49 *
     50 *  Deletes a psBitMask array and its byte count.
     51 */
     52void psBitMaskFree(
     53    psBitMask *restrict inMask  /**< Pointer to psBitMask struct to be deleted. */
     54);
     55
     56/** Set a bit.
     57 *
     58 *  Sets a bit at a given bit location. The bit is set based on a zero index with the first bit set in
     59 *  the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in an array with
     60 *  two elements would result in an psBitMask that looks like 00000000 00001000.
     61 *
     62 *  @return  psBitMask*: Pointer to struct containing array with bit set.
     63 */
     64psBitMask* psBitMaskSet(
     65    psBitMask *inMask, /**< Pointer to struct to be set. */
     66    int bit            /**< Bit to be set. */
     67);
     68
     69/** Test the value of a bit.
     70 *
     71 *  Prints the value of a bit at a given bit location. The bit printed based on a zero index with the first
     72 *  bit set in the zero bit slot of the zero element of the byte array. As an example, testing bit 3 in an array with
     73 *  two elements that looks like 00000000 00001000 would retrun a value of one, since that value was already set.
     74 *
     75 *  @return  int: Value of bit, either one or zero.
     76 */
     77int psBitMaskTest(
     78    const psBitMask *inMask,    /**< Pointer to struct to be tested. */
     79    int bit                     /**< Bit to be tested. */
     80);
     81
     82/** Perform a binary operation on two psBitMasks
     83 *
     84 *  Perform an AND, OR, or XOR on two psBitMasks. If the BitMasks are not the same size, the operation will not
     85 *  be performed and an error message will be printed.
     86 *
     87 *  @return  psBitMask*: Pointer to struct containing result of binary operation.
     88 */
     89psBitMask* psBitMaskOp(
     90    psBitMask *outMask,                 /**< Resulting psBitMask from binary operation */
     91    const psBitMask *restrict inMask1,  /**< First psBitMask on which to operate */
     92    char *operator,                     /**< Bit operation */
     93    const psBitMask *restrict inMask2   /**< First psBitMask on which to operate */
     94);
     95
     96/** Print the contents of a psBitMask.
     97 *
     98 *  Prints the contents of a psBitMask in its binary form of ones and zeros. The LSB is the left-most chracter.
     99 *
     100 *  @return  char*: Pointer to character array containing binary formatted data.
     101 */
     102char *psBitMaskToString(
     103    const psBitMask *restrict inMask /**< psBitMask to print */
     104);
     105
     106/** Private function to return a byte.
     107 *
     108 *  Finds the byte containing the bit within the byte array.
     109 *
     110 *  @return  char*: Pointer to byte in which bit is contained.
     111 */
     112static char* getByte(
     113    int bit,                            /**< Bit to index to search. */
     114    const psBitMask *restrict inMask    /**< psBitMask to search. */
     115);
     116
     117/** Private function to create a mask.
     118 *
     119 *  Creates an eight bit mask with the given bit set. All other bits in the byte are zero. The input bit uses
     120 *  zero-based indexing, and is the cumulitive index within the array, not the localized byte's bit position.
     121 *
     122 *  @return  char*: Pointer to byte in which bit is contained.
     123 */
     124static char mask(
     125    int bit /**< Bit to set within mask */
     126);
     127
     128#endif
Note: See TracChangeset for help on using the changeset viewer.