BitInfo.h

00001 # ifndef BitInfo_h
00002 # define BitInfo_h BitInfo_h
00003 
00004 // Created 2006/06/10 by wade
00005 
00006 // IMPORTANT: NO VIRTUAL METHODS!
00007 
00008 # include "BitOverlay.h"  // parent
00009 
00010 namespace Conjecture {
00011     
00012     /*********************************************************************
00013      * \class BitInfo
00014      *
00015      * \brief Pre-computed bit-level information about an 32-bit word.
00016      *
00017      * This is an extension of BitOverlay that precomputes all
00018      * relevant information and caches it in fields. The constructor
00019      * performs a single pass over the bit-sequence to establish all
00020      * of the information of interest and stores that info in fields.
00021      *
00022      * In deciding when to use BitOverlay and when to use BitInfo,
00023      * almost any time more than one method from BitInfo is needed on
00024      * a particular bit sequence, using BitInfo is probably more
00025      * efficient. 
00026      *
00027      * The only downside is that we have serious code redundancy -
00028      * the individual methods in BitOverlay perform individual tasks,
00029      * while the constructor in BitInfo performs those some tasks in
00030      * one monolithic loop (calling individual methods in the
00031      * constructor would defeat the entire purpose of having BitInfo
00032      * - it is supposed to be faster than calling individual
00033      * methods).
00034      *
00035      *********************************************************************/
00036 
00037     class BitInfo : public BitOverlay {
00038       public:
00039         // Constructors/Destructors
00040         BitInfo(BitOverlay::Layout layout);
00041         
00042         // Accessors
00043         inline const BitOverlay::BitCount & largestRegion() const { return this->_largestRegion; }
00044         inline const unsigned short*        regions()       const { return this->_regions; }
00045         inline const BitOverlay::BitCount & regionCount()   const { return this->_regionCount; }
00046         inline const BitOverlay::BitPos &   firstLow()      const { return this->_firstLow; }
00047         inline const BitOverlay::BitPos &   firstHigh()     const { return this->_firstHigh; }
00048         
00049         // Input/Output
00050         std::ostream& print(std::ostream& os = std::cout, const std::string& indent = "") const;
00051         
00052         // Interface
00053         static void Test(int argc = 0, const char* argv[] = NULL);
00054         
00055       protected:
00056         // Accessors
00057         inline void            largestRegionIs(const BitOverlay::BitCount & largestRegion) { this->_largestRegion = largestRegion; }
00058         inline void            regionCountIs(const BitOverlay::BitCount & regionCount) { this->_regionCount = regionCount; }
00059         inline void            firstLowIs(const BitOverlay::BitPos & firstLow) { this->_firstLow = firstLow; }
00060         inline void            firstHighIs(const BitOverlay::BitPos & firstHigh) { this->_firstHigh = firstHigh; }
00061         
00062         // Methods 
00063         
00064       private: 
00065         // Accessors
00066         inline BitOverlay::BitCount &  largestRegionRef() { return this->_largestRegion; }
00067         inline unsigned short* regionsRef() { return this->_regions; }
00068         inline BitOverlay::BitCount &  regionCountRef() { return this->_regionCount; }
00069         inline BitOverlay::BitPos &    firstLowRef() { return this->_firstLow; }
00070         inline BitOverlay::BitPos &    firstHighRef() { return this->_firstHigh; }
00071         
00072         // Methods 
00073         
00074         // State
00075         BitOverlay::BitCount  _largestRegion;
00076 
00077         // could dynamically allocate smaller size, but this is faster.
00078         // Encodes both 'start' (least significant) and 'size' of region.
00079         // High 4-bits for start, 
00080         unsigned short        _regions[16]; 
00081         BitOverlay::BitCount  _regionCount;
00082         BitOverlay::BitPos    _firstLow;
00083         BitOverlay::BitPos    _firstHigh;
00084     };
00085 }
00086 
00087 # endif // BitInfo_h
00088 

Generated on Wed Jun 14 15:08:02 2006 for Conjecture by  doxygen 1.4.6