mi32/bitsetd64.h

Go to the documentation of this file.
00001 /**
00002  * BitsetDeque.h - Definitions for BITSET DEQUE64 classes.
00003  *
00004  * This class is designed so that an access violation beyond 
00005  * the array size results in a bit setting of 'false'.
00006  *
00007  * $Id: bitsetd64.h_v 1.1 2003/09/24 02:45:20 mju Exp $
00008  *
00009  * $Log: bitsetd64.h_v $
00010  * Revision 1.1  2003/09/24 02:45:20  mju
00011  * Initial revision
00012  *
00013  * Revision 1.5  2003/02/20 16:49:05  dwilliss
00014  * never mind...
00015  *
00016  * Revision 1.4  2002/11/15 23:11:50  dwilliss
00017  * *** empty log message ***
00018  *
00019  * Revision 1.3  2002/11/01 23:36:22  scowan
00020  * Added begin and end methods.
00021  *
00022  * Revision 1.2  2002/11/01 16:26:35  scowan
00023  * Added get legacy method.
00024  *
00025  * Revision 1.1  2002/10/31 23:28:40  scowan
00026  * Initial revision
00027  *
00028  **/
00029 
00030 #ifndef INC_BITSETD64_H
00031 #define INC_BITSETD64_H
00032 
00033 #ifndef  INC_STDDEFNS_H
00034 #include <mi32/stddefns.h>
00035 #endif
00036 
00037 class BITSET_DEQUE64 {
00038    public:
00039    
00040       // Iterator to step forward through all selected items in a BITSET_DEQUE64.
00041       class ITERATOR {
00042          public:
00043 
00044             // Dereference operator, returns item number set.
00045             INT64 operator* (
00046                ) const { return (m_SetItemIndex); }
00047 
00048             // Cast operator to INT64.
00049             operator INT64 (
00050                ) const { return (m_SetItemIndex); }
00051 
00052             // Pre-increment operator.
00053             ITERATOR& operator++ (
00054                );
00055 
00056             // Equality operator.
00057             bool operator== (
00058                const ITERATOR& rhs
00059                ) const { return (m_BitSet == rhs.m_BitSet && (m_SetItemIndex == rhs.m_SetItemIndex || (m_SetItemIndex >= m_BitSet->m_NumEntries && rhs.m_SetItemIndex >= m_BitSet->m_NumEntries))); }
00060 
00061             // Inequality operator.
00062             bool operator!= (
00063                const ITERATOR& rhs
00064                ) const { return (!(*this == rhs)); }
00065 
00066          private:
00067             const BITSET_DEQUE64* m_BitSet;
00068             UINT32 m_SetItemIndex;
00069             UINT8 m_TestBit;
00070             UINT8 m_SkipByte;
00071 
00072             // Construct for "begin".
00073             ITERATOR (const BITSET_DEQUE64* BitSet, bool testvalue);
00074             // Construct for "end".
00075             ITERATOR (const BITSET_DEQUE64* BitSet);
00076 
00077             friend class BITSET_DEQUE64;
00078          };
00079    
00080       BITSET_DEQUE64 (
00081          );
00082    
00083       BITSET_DEQUE64 (
00084          const BITSET_DEQUE64& rhs
00085          );
00086    
00087       ~BITSET_DEQUE64 (
00088          );
00089    
00090       BITSET_DEQUE64& operator= (
00091          const BITSET_DEQUE64& rhs
00092          );
00093          
00094       // Initialize iterator with first set or unset item in the bit set.
00095       // Returns iterator to first set entry, otherwise the last+1 item if no matching item.
00096       ITERATOR Begin (
00097          bool value = true                // Value to iterate through
00098          ) const { return (ITERATOR(this, value)); }
00099 
00100       // Clear value at specified position.
00101       void Clear (
00102          INT64 posn
00103          );
00104 
00105       // Clear bit array with false.
00106       // Makes all the entries in the bit set 'false'.
00107       void ClearAll (
00108          );
00109 
00110       // Set range of entries to "false".
00111       void ClearRange (
00112          INT64 min,
00113          INT64 max
00114          );
00115          
00116       // Transfer value from source to dest entry.
00117       // Replaces putbit(set, DestPosn, getbit(set, SourcePosn)).
00118       void CopyBit (
00119          INT64 DestPosn,                  // where setting goes to
00120          INT64 SourcePosn                 // where setting comes from
00121          );
00122    
00123       // Initialize iterator with last+1 item in the bit set.
00124       // Returns iterator to last+1 item
00125       ITERATOR End (
00126          ) const { return (ITERATOR(this)); }
00127 
00128       // Erase BITSET_DEQUE64 internals, same as calling destructor.
00129       void Free (
00130          );
00131    
00132       // Retrieve value at the requested position, true or false.
00133       // Returns 'false' if the position given is outside the range of the BITSET
00134       bool GetBit (
00135          INT64 posn                       // position where value is retrieved from
00136          ) const;
00137 /*
00138       // Retrieve legacy bit array from 'this'
00139       // Returns number of items in the array
00140       INT32 GetBitArray (
00141          UINT8*& array                    // Must be freed by the caller
00142          ) const;
00143 */       
00144       // Return the number of valid entries.
00145       INT64 GetNumEntries (            
00146          ) const { return (m_NumEntries); }
00147 
00148       // Get a range of entries that are set continuously in the bitset
00149       // @return 'True' if a true range, 'false' if a false range
00150       bool GetRange (
00151          INT64 StartPosn,        // Staring position
00152          INT64 MaxEnd,           // Maximum ending position
00153          INT64& EndPosn       // Ending position (inclusive) RETURNED
00154          ) const;
00155    
00156       // Does bit set have any entries?
00157       bool HasEntries (
00158          ) const { return (m_NumEntries > 0); }
00159 
00160       // Invert value at specified position.
00161       void Invert (
00162          INT64 posn                       // Position to be inverted
00163          );
00164          
00165       // Invert all entries in bit set.
00166       void InvertAll (
00167          );
00168          
00169       // Set range of entries to inverse
00170       void InvertRange (
00171          INT64 min,
00172          INT64 max
00173          );
00174          
00175       // Resize BITSET to a new number of entries.
00176       ERRVALUE Resize (
00177          INT64 NumEntries                 // Number of elements to resize to
00178          );
00179          
00180       // Set a value at the requested position to "true".
00181       // Does nothing if the position given is outside range.
00182       void Set (              
00183          INT64 posn                       // Position to set
00184          );
00185          
00186       // Set all entries to true, opposite of ClearAll().
00187       // Turn all bit positions to true.
00188       void SetAll (              
00189          );
00190          
00191       // Set a value at the requested position, true or false.
00192       // Does nothing if the position given is outside range.
00193       void SetBit (              
00194          INT64 posn,                   // Position where value is set
00195          bool value                       // Value to be set at position
00196          );
00197          
00198       // Set range of entries to "true".
00199       void SetRange (
00200          INT64 min,
00201          INT64 max
00202          );
00203          
00204    private:
00205       struct TILE {
00206          UINT8* m_Array;
00207          bool m_IsValid;                  // Is the tile valid?  The tile can be allocated and be invalid
00208          bool m_IsSet;
00209          };
00210 
00211       TILE* m_Tiles; 
00212       INT64 m_NumEntries;                 // Actual number of bits used
00213       UINT32 m_NumTiles;                  // Number of tiles allocated
00214       UINT32 m_NumFreeTiles;              // Number of free tiles
00215       static const UINT32 s_TileSize;
00216       
00217       ERRVALUE GetTile (UINT32 ti);
00218 
00219       friend class ITERATOR;
00220    };
00221 
00222 
00223 #endif      // INC_BITSETD_H

Generated on Thu Apr 26 04:44:53 2007 for TNTsdk by  doxygen 1.5.2