mi32/bitsetd.h

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

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