00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef DOUBLEBITMASK_H
00016 #define DOUBLEBITMASK_H
00017
00018 #include "pandabase.h"
00019
00020 #include "bitMask.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 template<class BMType>
00032 class DoubleBitMask {
00033 public:
00034 typedef BMType BitMaskType;
00035 typedef TYPENAME BMType::WordType WordType;
00036 #ifndef CPPPARSER // interrogate has a problem with these lines.
00037 enum {
00038 half_bits = BitMaskType::num_bits,
00039 num_bits = BitMaskType::num_bits * 2,
00040 };
00041 #endif // CPPPARSER
00042
00043 PUBLISHED:
00044 INLINE DoubleBitMask();
00045 INLINE DoubleBitMask(const DoubleBitMask<BMType> ©);
00046 INLINE DoubleBitMask<BMType> &operator = (const DoubleBitMask<BMType> ©);
00047
00048 INLINE static DoubleBitMask<BMType> all_on();
00049 INLINE static DoubleBitMask<BMType> all_off();
00050 INLINE static DoubleBitMask<BMType> lower_on(int on_bits);
00051 INLINE static DoubleBitMask<BMType> bit(int index);
00052 INLINE static DoubleBitMask<BMType> range(int low_bit, int size);
00053
00054 INLINE ~DoubleBitMask();
00055
00056 INLINE static bool has_max_num_bits();
00057 INLINE static int get_max_num_bits();
00058
00059 INLINE static int get_num_bits();
00060 INLINE bool get_bit(int index) const;
00061 INLINE void set_bit(int index);
00062 INLINE void clear_bit(int index);
00063 INLINE void set_bit_to(int index, bool value);
00064 INLINE bool is_zero() const;
00065 INLINE bool is_all_on() const;
00066
00067 INLINE WordType extract(int low_bit, int size) const;
00068 INLINE void store(WordType value, int low_bit, int size);
00069 INLINE bool has_any_of(int low_bit, int size) const;
00070 INLINE bool has_all_of(int low_bit, int size) const;
00071 INLINE void set_range(int low_bit, int size);
00072 INLINE void clear_range(int low_bit, int size);
00073 INLINE void set_range_to(bool value, int low_bit, int size);
00074
00075 INLINE int get_num_on_bits() const;
00076 INLINE int get_num_off_bits() const;
00077 INLINE int get_lowest_on_bit() const;
00078 INLINE int get_lowest_off_bit() const;
00079 INLINE int get_highest_on_bit() const;
00080 INLINE int get_highest_off_bit() const;
00081 INLINE int get_next_higher_different_bit(int low_bit) const;
00082
00083 INLINE void invert_in_place();
00084 INLINE bool has_bits_in_common(const DoubleBitMask<BMType> &other) const;
00085 INLINE void clear();
00086
00087 void output(ostream &out) const;
00088 void output_binary(ostream &out, int spaces_every = 4) const;
00089 void output_hex(ostream &out, int spaces_every = 4) const;
00090 void write(ostream &out, int indent_level = 0) const;
00091
00092 INLINE bool operator == (const DoubleBitMask<BMType> &other) const;
00093 INLINE bool operator != (const DoubleBitMask<BMType> &other) const;
00094 INLINE bool operator < (const DoubleBitMask<BMType> &other) const;
00095 INLINE int compare_to(const DoubleBitMask<BMType> &other) const;
00096
00097 INLINE DoubleBitMask<BMType>
00098 operator & (const DoubleBitMask<BMType> &other) const;
00099
00100 INLINE DoubleBitMask<BMType>
00101 operator | (const DoubleBitMask<BMType> &other) const;
00102
00103 INLINE DoubleBitMask<BMType>
00104 operator ^ (const DoubleBitMask<BMType> &other) const;
00105
00106 INLINE DoubleBitMask<BMType>
00107 operator ~ () const;
00108
00109 INLINE DoubleBitMask<BMType>
00110 operator << (int shift) const;
00111
00112 INLINE DoubleBitMask<BMType>
00113 operator >> (int shift) const;
00114
00115 INLINE void operator &= (const DoubleBitMask<BMType> &other);
00116 INLINE void operator |= (const DoubleBitMask<BMType> &other);
00117 INLINE void operator ^= (const DoubleBitMask<BMType> &other);
00118 INLINE void operator <<= (int shift);
00119 INLINE void operator >>= (int shift);
00120
00121 public:
00122 INLINE void generate_hash(ChecksumHashGenerator &hashgen) const;
00123
00124 private:
00125 BitMaskType _lo, _hi;
00126
00127 public:
00128 static TypeHandle get_class_type() {
00129 return _type_handle;
00130 }
00131 static void init_type();
00132
00133 private:
00134 static TypeHandle _type_handle;
00135 };
00136
00137 #include "doubleBitMask.I"
00138
00139 template<class BMType>
00140 INLINE ostream &operator << (ostream &out, const DoubleBitMask<BMType> &doubleBitMask) {
00141 doubleBitMask.output(out);
00142 return out;
00143 }
00144
00145 typedef DoubleBitMask<BitMaskNative> DoubleBitMaskNative;
00146 typedef DoubleBitMask<DoubleBitMaskNative> QuadBitMaskNative;
00147
00148
00149 #ifdef __GNUC__
00150 #pragma interface
00151 #endif
00152
00153 #endif