BitArray.h
changeset 13 70907579a3b6
parent 0 0f874d9e4130
     1.1 --- a/BitArray.h	Tue Aug 26 19:24:57 2014 +0200
     1.2 +++ b/BitArray.h	Fri Aug 29 22:32:13 2014 +0200
     1.3 @@ -71,26 +71,39 @@
     1.4  /***************************************************************************
     1.5  *                            TYPE DEFINITIONS
     1.6  ***************************************************************************/
     1.7 +typedef unsigned char (*TBitInChar)(const unsigned int aBit);
     1.8 +template <TBitInChar F>
     1.9  class BitArray;
    1.10  
    1.11 +
    1.12 +//Bits are indexed: 76543210
    1.13 +inline unsigned char HighBitHighIndex(const unsigned int aBit) { return (1 << (((aBit)  % CHAR_BIT)));};
    1.14 +
    1.15 +//Bits are indexed: 01234567
    1.16 +inline unsigned char HighBitLowIndex(const unsigned int aBit) { return (1 << (CHAR_BIT - 1 - ((aBit)  % CHAR_BIT)));};
    1.17 +
    1.18 +
    1.19 +
    1.20  /**
    1.21  */
    1.22 +template <TBitInChar F>
    1.23  class BitArrayIndex
    1.24  {
    1.25      public:
    1.26 -        BitArrayIndex(BitArray *array, const unsigned int index);
    1.27 +        BitArrayIndex(BitArray<F> *array, const unsigned int index);
    1.28  
    1.29          /* assignment */
    1.30          void operator=(const bool src);
    1.31  
    1.32      private:
    1.33 -        BitArray *m_BitArray;        /* array index applies to */
    1.34 +        BitArray<F> *m_BitArray;        /* array index applies to */
    1.35          unsigned int m_Index;           /* index of bit in array */
    1.36  };
    1.37  
    1.38  /**
    1.39  TODO: Derive a Bit Frame class from this one for X Y access to pixels.
    1.40  */
    1.41 +template <TBitInChar F>
    1.42  class BitArray
    1.43  {
    1.44      public:
    1.45 @@ -111,42 +124,42 @@
    1.46  		void SetBitValue(const unsigned int bit, bool aValue);
    1.47          void ClearBit(const unsigned int bit);
    1.48  
    1.49 -        BitArrayIndex operator()(const unsigned int bit);
    1.50 +        BitArrayIndex<F> operator()(const unsigned int bit);
    1.51  
    1.52          /* boolean operator */
    1.53          bool operator[](const unsigned int bit) const;
    1.54 -        bool operator==(const BitArray &other) const;
    1.55 -        bool operator!=(const BitArray &other) const;
    1.56 -        bool operator<(const BitArray &other) const;
    1.57 -        bool operator<=(const BitArray &other) const;
    1.58 -        bool operator>(const BitArray &other) const;
    1.59 -        bool operator>=(const BitArray &other) const;
    1.60 +        bool operator==(const BitArray<F> &other) const;
    1.61 +        bool operator!=(const BitArray<F> &other) const;
    1.62 +        bool operator<(const BitArray<F> &other) const;
    1.63 +        bool operator<=(const BitArray<F> &other) const;
    1.64 +        bool operator>(const BitArray<F> &other) const;
    1.65 +        bool operator>=(const BitArray<F> &other) const;
    1.66  
    1.67          /* bitwise operators */
    1.68 -        BitArray operator&(const BitArray &other) const;
    1.69 -        BitArray operator^(const BitArray &other) const;
    1.70 -        BitArray operator|(const BitArray &other) const;
    1.71 -        BitArray operator~(void) const;
    1.72 +        BitArray<F> operator&(const BitArray<F> &other) const;
    1.73 +        BitArray<F> operator^(const BitArray<F> &other) const;
    1.74 +        BitArray<F> operator|(const BitArray<F> &other) const;
    1.75 +        BitArray<F> operator~(void) const;
    1.76  
    1.77 -        BitArray operator<<(const unsigned int count) const;
    1.78 -        BitArray operator>>(const unsigned int count) const;
    1.79 +        BitArray<F> operator<<(const unsigned int count) const;
    1.80 +        BitArray<F> operator>>(const unsigned int count) const;
    1.81  
    1.82          /* increment/decrement */
    1.83 -        BitArray& operator++(void);          /* prefix */
    1.84 -        BitArray& operator++(int dummy);     /* postfix */
    1.85 -        BitArray& operator--(void);          /* prefix */
    1.86 -        BitArray& operator--(int dummy);     /* postfix */
    1.87 +        BitArray<F>& operator++(void);          /* prefix */
    1.88 +        BitArray<F>& operator++(int dummy);     /* postfix */
    1.89 +        BitArray<F>& operator--(void);          /* prefix */
    1.90 +        BitArray<F>& operator--(int dummy);     /* postfix */
    1.91  
    1.92          /* assignments */
    1.93 -        BitArray& operator=(const BitArray &src);
    1.94 +        BitArray<F>& operator=(const BitArray<F> &src);
    1.95  
    1.96 -        BitArray& operator&=(const BitArray &src);
    1.97 -        BitArray& operator^=(const BitArray &src);
    1.98 -        BitArray& operator|=(const BitArray &src);
    1.99 -        BitArray& Not(void);                 /* negate (~=) */
   1.100 +        BitArray<F>& operator&=(const BitArray<F> &src);
   1.101 +        BitArray<F>& operator^=(const BitArray<F> &src);
   1.102 +        BitArray<F>& operator|=(const BitArray<F> &src);
   1.103 +        BitArray<F>& Not(void);                 /* negate (~=) */
   1.104  
   1.105 -        BitArray& operator<<=(unsigned const int shifts);
   1.106 -        BitArray& operator>>=(unsigned const int shifts);
   1.107 +        BitArray<F>& operator<<=(unsigned const int shifts);
   1.108 +        BitArray<F>& operator>>=(unsigned const int shifts);
   1.109  
   1.110  		unsigned char* Ptr(){return m_Array;}
   1.111  		const unsigned char* Ptr() const{return m_Array;}
   1.112 @@ -158,4 +171,7 @@
   1.113          bool m_OwnsBuffer;
   1.114  };
   1.115  
   1.116 +typedef BitArray<HighBitHighIndex> BitArrayHigh;
   1.117 +typedef BitArray<HighBitLowIndex> BitArrayLow;
   1.118 +
   1.119  #endif  /* ndef BIT_ARRAY_H */