//////////////////////////////////////////////////////////////////////////////////////// // RAVEN STANDARD TEMPLATE LIBRARY // (c) 2002 Activision // // // Bit Field // --------- // The bits class is a bit field of any length which supports all the // standard bitwize operations in addition to some operators for adding & removing // individual bits by their integer indicies and a string conversion method. // // // // NOTES: // - The SIZE template variable determines how many BITS are available in this template, // not how much memory (number of ints) were used to store it. // // //////////////////////////////////////////////////////////////////////////////////////// #if !defined(RATL_BITS_INC) #define RATL_BITS_INC //////////////////////////////////////////////////////////////////////////////////////// // Includes //////////////////////////////////////////////////////////////////////////////////////// #if !defined(RATL_COMMON_INC) #include "ratl_common.h" #endif namespace ratl { //////////////////////////////////////////////////////////////////////////////////////// // The Bit Field Class //////////////////////////////////////////////////////////////////////////////////////// template class bits_vs : public bits_base { //////////////////////////////////////////////////////////////////////////////////// // Call This Function To Set All Bits Beyond SIZE to Zero //////////////////////////////////////////////////////////////////////////////////// void clear_trailing_bits() { for (int i=SIZE; i>BITS_SHIFT] &= ~(1<<(i&BITS_AND)); } } public: //////////////////////////////////////////////////////////////////////////////////// // Capacity Enum //////////////////////////////////////////////////////////////////////////////////// enum { SIZE = SZ, CAPACITY = SZ, }; //////////////////////////////////////////////////////////////////////////////////// // Standard Constructor //////////////////////////////////////////////////////////////////////////////////// bits_vs(bool init=true,bool initValue=false) : bits_base(init,initValue) { } //////////////////////////////////////////////////////////////////////////////////// // Copy Constructor //////////////////////////////////////////////////////////////////////////////////// bits_vs(const bits_vs &B) { mem::cpy(mV, B.mV,BYTE_SIZE); } //////////////////////////////////////////////////////////////////////////////////// // String Constructor (Format: "100010100101") //////////////////////////////////////////////////////////////////////////////////// bits_vs(const char* Str) { clear(); for (int b=0; b=0 && i < SIZE); return ( (mV[i>>BITS_SHIFT] & (1<<(i&BITS_AND)))!=0 ); } //////////////////////////////////////////////////////////////////////////////////////// // Checks If There Are Any Values At All In This Bit Field //////////////////////////////////////////////////////////////////////////////////////// bool operator!() const { return empty(); } //////////////////////////////////////////////////////////////////////////////////////// // Equality Operator //////////////////////////////////////////////////////////////////////////////////////// bool operator==(const bits_vs &B) const { return (mem::eql(mV, B.mV,BYTE_SIZE)); } //////////////////////////////////////////////////////////////////////////////////////// // InEquality Operator //////////////////////////////////////////////////////////////////////////////////////// bool operator!=(const bits_vs &B) const { return !(operator==(B)); } //////////////////////////////////////////////////////////////////////////////////////// // Or In From Another Bits Object //////////////////////////////////////////////////////////////////////////////////////// void operator|=(const bits_vs &B) { for (int i=0; i