1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/MiniDisplay/BitArray.h Tue May 27 19:50:28 2014 +0200
1.3 @@ -0,0 +1,160 @@
1.4 +/***************************************************************************
1.5 +* Arrays of Arbitrary Bit Length
1.6 +*
1.7 +* File : bitarray.h
1.8 +* Purpose : Header file for class supporting the creation and
1.9 +* manipulation of arbitrary length arrays of bits.
1.10 +* Author : Michael Dipperstein
1.11 +* Date : July 23, 2004
1.12 +*
1.13 +****************************************************************************
1.14 +* HISTORY
1.15 +*
1.16 +* $Id: bitarray.h,v 1.5 2010/02/04 03:31:43 michael Exp $
1.17 +* $Log: bitarray.h,v $
1.18 +* Revision 1.5 2010/02/04 03:31:43 michael
1.19 +* Replaced vector<unsigned char> with an array of unsigned char.
1.20 +*
1.21 +* Made updates for GCC 4.4.
1.22 +*
1.23 +* Revision 1.4 2007/08/06 05:23:12 michael
1.24 +* Updated for LGPL Version 3.
1.25 +*
1.26 +* All methods that don't modify object have been made
1.27 +* const to increase functionality of const bit_array_c.
1.28 +*
1.29 +* All assignment operators return a reference to the object being assigned a value so that operator chaining will work.
1.30 +*
1.31 +* Added >> and << operators.
1.32 +*
1.33 +* Revision 1.3 2006/04/30 23:34:07 michael
1.34 +* Improved performance by incorporating Benjamin Schindler's
1.35 +* <bschindler@student.ethz.ch> changes to pass arguments as a reference.
1.36 +*
1.37 +* Revision 1.2 2004/08/05 22:17:04 michael
1.38 +* Add overloads for bitwise operators returning values.
1.39 +* Add a more natural looking way to set bit values.
1.40 +*
1.41 +* Revision 1.1.1.1 2004/08/04 13:28:20 michael
1.42 +* bit_array_c
1.43 +*
1.44 +****************************************************************************
1.45 +*
1.46 +* Bitarray: An ANSI C++ class for manipulating arbitrary length bit arrays
1.47 +* Copyright (C) 2004, 2006-2007, 2010 by
1.48 +* Michael Dipperstein (mdipper@alumni.engr.ucsb.edu)
1.49 +*
1.50 +* This file is part of the bit array library.
1.51 +*
1.52 +* The bit array library is free software; you can redistribute it and/or
1.53 +* modify it under the terms of the GNU Lesser General Public License as
1.54 +* published by the Free Software Foundation; either version 3 of the
1.55 +* License, or (at your option) any later version.
1.56 +*
1.57 +* The bit array library is distributed in the hope that it will be useful,
1.58 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
1.59 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
1.60 +* General Public License for more details.
1.61 +*
1.62 +* You should have received a copy of the GNU Lesser General Public License
1.63 +* along with this program. If not, see <http://www.gnu.org/licenses/>.
1.64 +*
1.65 +***************************************************************************/
1.66 +#ifndef BIT_ARRAY_H
1.67 +#define BIT_ARRAY_H
1.68 +
1.69 +/***************************************************************************
1.70 +* INCLUDED FILES
1.71 +***************************************************************************/
1.72 +#include <ostream>
1.73 +
1.74 +/***************************************************************************
1.75 +* TYPE DEFINITIONS
1.76 +***************************************************************************/
1.77 +class BitArray;
1.78 +
1.79 +/**
1.80 +*/
1.81 +class BitArrayIndex
1.82 +{
1.83 + public:
1.84 + BitArrayIndex(BitArray *array, const unsigned int index);
1.85 +
1.86 + /* assignment */
1.87 + void operator=(const bool src);
1.88 +
1.89 + private:
1.90 + BitArray *m_BitArray; /* array index applies to */
1.91 + unsigned int m_Index; /* index of bit in array */
1.92 +};
1.93 +
1.94 +/**
1.95 +TODO: Derive a Bit Frame class from this one for X Y access to pixels.
1.96 +*/
1.97 +class BitArray
1.98 +{
1.99 + public:
1.100 + BitArray(const int numBits);
1.101 + BitArray(unsigned char *array, const int numBits);
1.102 +
1.103 + virtual ~BitArray(void);
1.104 +
1.105 + void Dump(std::ostream &outStream);
1.106 +
1.107 + const unsigned int SizeInBits() { return m_NumBits; };
1.108 + const unsigned int SizeInBytes() { return m_SizeInBytes; };
1.109 +
1.110 + /* set/clear functions */
1.111 + void SetAll(void);
1.112 + void ClearAll(void);
1.113 + void SetBit(const unsigned int bit);
1.114 + void SetBitValue(const unsigned int bit, bool aValue);
1.115 + void ClearBit(const unsigned int bit);
1.116 +
1.117 + BitArrayIndex operator()(const unsigned int bit);
1.118 +
1.119 + /* boolean operator */
1.120 + bool operator[](const unsigned int bit) const;
1.121 + bool operator==(const BitArray &other) const;
1.122 + bool operator!=(const BitArray &other) const;
1.123 + bool operator<(const BitArray &other) const;
1.124 + bool operator<=(const BitArray &other) const;
1.125 + bool operator>(const BitArray &other) const;
1.126 + bool operator>=(const BitArray &other) const;
1.127 +
1.128 + /* bitwise operators */
1.129 + BitArray operator&(const BitArray &other) const;
1.130 + BitArray operator^(const BitArray &other) const;
1.131 + BitArray operator|(const BitArray &other) const;
1.132 + BitArray operator~(void) const;
1.133 +
1.134 + BitArray operator<<(const unsigned int count) const;
1.135 + BitArray operator>>(const unsigned int count) const;
1.136 +
1.137 + /* increment/decrement */
1.138 + BitArray& operator++(void); /* prefix */
1.139 + BitArray& operator++(int dummy); /* postfix */
1.140 + BitArray& operator--(void); /* prefix */
1.141 + BitArray& operator--(int dummy); /* postfix */
1.142 +
1.143 + /* assignments */
1.144 + BitArray& operator=(const BitArray &src);
1.145 +
1.146 + BitArray& operator&=(const BitArray &src);
1.147 + BitArray& operator^=(const BitArray &src);
1.148 + BitArray& operator|=(const BitArray &src);
1.149 + BitArray& Not(void); /* negate (~=) */
1.150 +
1.151 + BitArray& operator<<=(unsigned const int shifts);
1.152 + BitArray& operator>>=(unsigned const int shifts);
1.153 +
1.154 + unsigned char* Ptr(){return m_Array;}
1.155 + const unsigned char* Ptr() const{return m_Array;}
1.156 +
1.157 + protected:
1.158 + unsigned int m_NumBits; /* number of bits in the array */
1.159 + unsigned int m_SizeInBytes;
1.160 + unsigned char *m_Array; /* vector of characters */
1.161 +};
1.162 +
1.163 +#endif /* ndef BIT_ARRAY_H */