sl@25: /*************************************************************************** sl@25: * Arrays of Arbitrary Bit Length sl@25: * sl@25: * File : bitarray.h sl@25: * Purpose : Header file for class supporting the creation and sl@25: * manipulation of arbitrary length arrays of bits. sl@25: * Author : Michael Dipperstein sl@25: * Date : July 23, 2004 sl@25: * sl@25: **************************************************************************** sl@25: * HISTORY sl@25: * sl@25: * $Id: bitarray.h,v 1.5 2010/02/04 03:31:43 michael Exp $ sl@25: * $Log: bitarray.h,v $ sl@25: * Revision 1.5 2010/02/04 03:31:43 michael sl@25: * Replaced vector with an array of unsigned char. sl@25: * sl@25: * Made updates for GCC 4.4. sl@25: * sl@25: * Revision 1.4 2007/08/06 05:23:12 michael sl@25: * Updated for LGPL Version 3. sl@25: * sl@25: * All methods that don't modify object have been made sl@25: * const to increase functionality of const bit_array_c. sl@25: * sl@25: * All assignment operators return a reference to the object being assigned a value so that operator chaining will work. sl@25: * sl@25: * Added >> and << operators. sl@25: * sl@25: * Revision 1.3 2006/04/30 23:34:07 michael sl@25: * Improved performance by incorporating Benjamin Schindler's sl@25: * changes to pass arguments as a reference. sl@25: * sl@25: * Revision 1.2 2004/08/05 22:17:04 michael sl@25: * Add overloads for bitwise operators returning values. sl@25: * Add a more natural looking way to set bit values. sl@25: * sl@25: * Revision 1.1.1.1 2004/08/04 13:28:20 michael sl@25: * bit_array_c sl@25: * sl@25: **************************************************************************** sl@25: * sl@25: * Bitarray: An ANSI C++ class for manipulating arbitrary length bit arrays sl@25: * Copyright (C) 2004, 2006-2007, 2010 by sl@25: * Michael Dipperstein (mdipper@alumni.engr.ucsb.edu) sl@25: * sl@25: * This file is part of the bit array library. sl@25: * sl@25: * The bit array library is free software; you can redistribute it and/or sl@25: * modify it under the terms of the GNU Lesser General Public License as sl@25: * published by the Free Software Foundation; either version 3 of the sl@25: * License, or (at your option) any later version. sl@25: * sl@25: * The bit array library is distributed in the hope that it will be useful, sl@25: * but WITHOUT ANY WARRANTY; without even the implied warranty of sl@25: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser sl@25: * General Public License for more details. sl@25: * sl@25: * You should have received a copy of the GNU Lesser General Public License sl@25: * along with this program. If not, see . sl@25: * sl@25: ***************************************************************************/ sl@25: #ifndef BIT_ARRAY_H sl@25: #define BIT_ARRAY_H sl@25: sl@25: /*************************************************************************** sl@25: * INCLUDED FILES sl@25: ***************************************************************************/ sl@25: #include sl@25: sl@25: /*************************************************************************** sl@25: * TYPE DEFINITIONS sl@25: ***************************************************************************/ sl@25: class BitArray; sl@25: sl@25: /** sl@25: */ sl@25: class BitArrayIndex sl@25: { sl@25: public: sl@25: BitArrayIndex(BitArray *array, const unsigned int index); sl@25: sl@25: /* assignment */ sl@25: void operator=(const bool src); sl@25: sl@25: private: sl@25: BitArray *m_BitArray; /* array index applies to */ sl@25: unsigned int m_Index; /* index of bit in array */ sl@25: }; sl@25: sl@25: /** sl@27: TODO: Derive a Bit Frame class from this one for X Y access to pixels. sl@25: */ sl@25: class BitArray sl@25: { sl@25: public: sl@25: BitArray(const int numBits); sl@25: BitArray(unsigned char *array, const int numBits); sl@25: sl@25: virtual ~BitArray(void); sl@25: sl@25: void Dump(std::ostream &outStream); sl@25: sl@25: const unsigned int SizeInBits() { return m_NumBits; }; sl@25: const unsigned int SizeInBytes() { return m_SizeInBytes; }; sl@25: sl@25: /* set/clear functions */ sl@25: void SetAll(void); sl@25: void ClearAll(void); sl@25: void SetBit(const unsigned int bit); sl@25: void SetBitValue(const unsigned int bit, bool aValue); sl@25: void ClearBit(const unsigned int bit); sl@25: sl@25: BitArrayIndex operator()(const unsigned int bit); sl@25: sl@25: /* boolean operator */ sl@25: bool operator[](const unsigned int bit) const; sl@25: bool operator==(const BitArray &other) const; sl@25: bool operator!=(const BitArray &other) const; sl@25: bool operator<(const BitArray &other) const; sl@25: bool operator<=(const BitArray &other) const; sl@25: bool operator>(const BitArray &other) const; sl@25: bool operator>=(const BitArray &other) const; sl@25: sl@25: /* bitwise operators */ sl@25: BitArray operator&(const BitArray &other) const; sl@25: BitArray operator^(const BitArray &other) const; sl@25: BitArray operator|(const BitArray &other) const; sl@25: BitArray operator~(void) const; sl@25: sl@25: BitArray operator<<(const unsigned int count) const; sl@25: BitArray operator>>(const unsigned int count) const; sl@25: sl@25: /* increment/decrement */ sl@25: BitArray& operator++(void); /* prefix */ sl@25: BitArray& operator++(int dummy); /* postfix */ sl@25: BitArray& operator--(void); /* prefix */ sl@25: BitArray& operator--(int dummy); /* postfix */ sl@25: sl@25: /* assignments */ sl@25: BitArray& operator=(const BitArray &src); sl@25: sl@25: BitArray& operator&=(const BitArray &src); sl@25: BitArray& operator^=(const BitArray &src); sl@25: BitArray& operator|=(const BitArray &src); sl@25: BitArray& Not(void); /* negate (~=) */ sl@25: sl@25: BitArray& operator<<=(unsigned const int shifts); sl@25: BitArray& operator>>=(unsigned const int shifts); sl@25: sl@25: unsigned char* Ptr(){return m_Array;} sl@25: const unsigned char* Ptr() const{return m_Array;} sl@25: sl@25: protected: sl@25: unsigned int m_NumBits; /* number of bits in the array */ sl@25: unsigned int m_SizeInBytes; sl@25: unsigned char *m_Array; /* vector of characters */ sl@25: }; sl@25: sl@25: #endif /* ndef BIT_ARRAY_H */