15 #ifndef DOUBLEBITMASK_H
16 #define DOUBLEBITMASK_H
18 #include "pandabase.h"
31 template<
class BMType>
34 typedef TYPENAME BMType::WordType WordType;
37 typedef BMType BitMaskType;
40 half_bits = BitMaskType::num_bits,
41 num_bits = BitMaskType::num_bits * 2,
54 INLINE ~DoubleBitMask();
60 INLINE
bool get_bit(
int index)
const;
67 INLINE WordType
extract(
int low_bit,
int size)
const;
68 INLINE
void store(WordType value,
int low_bit,
int size);
69 INLINE
bool has_any_of(
int low_bit,
int size)
const;
70 INLINE
bool has_all_of(
int low_bit,
int size)
const;
71 INLINE
void set_range(
int low_bit,
int size);
73 INLINE
void set_range_to(
bool value,
int low_bit,
int size);
87 void output(ostream &out)
const;
89 void output_hex(ostream &out,
int spaces_every = 4)
const;
90 void write(ostream &out,
int indent_level = 0)
const;
94 INLINE
bool operator < (const DoubleBitMask<BMType> &other)
const;
110 operator << (
int shift)
const;
113 operator >> (
int shift)
const;
118 INLINE
void operator <<= (
int shift);
119 INLINE
void operator >>= (
int shift);
125 BitMaskType _lo, _hi;
131 static void init_type();
137 #include "doubleBitMask.I"
139 template<
class BMType>
140 INLINE ostream &operator << (ostream &out, const DoubleBitMask<BMType> &doubleBitMask) {
141 doubleBitMask.output(out);
This is a specific kind of HashGenerator that simply adds up all of the ints.
int get_num_off_bits() const
Returns the number of bits that are set to 0 in the mask.
void output_binary(ostream &out, int spaces_every=4) const
Writes the DoubleBitMask out as a binary number, with spaces every four bits.
void clear_range(int low_bit, int size)
Sets the indicated range of bits off.
int get_highest_off_bit() const
Returns the index of the highest 0 bit in the mask.
static DoubleBitMask< BMType > range(int low_bit, int size)
Returns a DoubleBitMask whose size bits, beginning at low_bit, are on.
bool has_bits_in_common(const DoubleBitMask< BMType > &other) const
Returns true if this DoubleBitMask has any "one" bits in common with the other one, false otherwise.
bool is_all_on() const
Returns true if the entire doubleBitMask is one, false otherwise.
void set_range_to(bool value, int low_bit, int size)
Sets the indicated range of bits to either on or off.
bool has_any_of(int low_bit, int size) const
Returns true if any bit in the indicated range is set, false otherwise.
bool has_all_of(int low_bit, int size) const
Returns true if all bits in the indicated range are set, false otherwise.
This is a special BitMask type that is implemented as a pair of lesser BitMask types, to present a double-wide bit mask.
void output(ostream &out) const
Writes the DoubleBitMask out as a binary or a hex number, according to the number of bits...
void store(WordType value, int low_bit, int size)
Stores the indicated word into the indicated range of bits with this DoubleBitMask.
int get_highest_on_bit() const
Returns the index of the highest 1 bit in the mask.
int get_num_on_bits() const
Returns the number of bits that are set to 1 in the mask.
void clear_bit(int index)
Sets the nth bit off.
static DoubleBitMask< BMType > lower_on(int on_bits)
Returns a DoubleBitMask whose lower on_bits bits are on.
int get_next_higher_different_bit(int low_bit) const
Returns the index of the next bit in the mask, above low_bit, whose value is different that the value...
static CONSTEXPR int get_max_num_bits()
If get_max_num_bits() returned true, this method may be called to return the maximum number of bits t...
WordType extract(int low_bit, int size) const
Returns a word that represents only the indicated range of bits within this DoubleBitMask, shifted to the least-significant position.
int get_lowest_off_bit() const
Returns the index of the lowest 0 bit in the mask.
void set_range(int low_bit, int size)
Sets the indicated range of bits on.
void clear()
Sets all the bits in the DoubleBitMask off.
void set_bit_to(int index, bool value)
Sets the nth bit either on or off, according to the indicated bool value.
static CONSTEXPR int get_num_bits()
Returns the number of bits available to set in the doubleBitMask.
int compare_to(const DoubleBitMask< BMType > &other) const
Returns a number less than zero if this DoubleBitMask sorts before the indicated other DoubleBitMask...
int get_lowest_on_bit() const
Returns the index of the lowest 1 bit in the mask.
void set_bit(int index)
Sets the nth bit on.
static DoubleBitMask< BMType > all_on()
Returns a DoubleBitMask whose bits are all on.
static DoubleBitMask< BMType > bit(int index)
Returns a DoubleBitMask with only the indicated bit on.
void generate_hash(ChecksumHashGenerator &hashgen) const
Adds the doubleBitMask to the indicated hash generator.
bool is_zero() const
Returns true if the entire doubleBitMask is zero, false otherwise.
bool get_bit(int index) const
Returns true if the nth bit is set, false if it is cleared.
TypeHandle is the identifier used to differentiate C++ class types.
static CONSTEXPR bool has_max_num_bits()
Returns true if there is a maximum number of bits that may be stored in this structure, false otherwise.
void invert_in_place()
Inverts all the bits in the DoubleBitMask.
static DoubleBitMask< BMType > all_off()
Returns a DoubleBitMask whose bits are all off.
void output_hex(ostream &out, int spaces_every=4) const
Writes the DoubleBitMask out as a hexadecimal number, with spaces every four digits.
void write(ostream &out, int indent_level=0) const
Writes the DoubleBitMask out as a binary or a hex number, according to the number of bits...