14 #ifndef DOUBLEBITMASK_H 15 #define DOUBLEBITMASK_H 27 template<
class BMType>
30 typedef typename BMType::WordType WordType;
33 typedef BMType BitMaskType;
36 half_bits = BMType::num_bits,
37 num_bits = BMType::num_bits * 2,
48 constexpr
static bool has_max_num_bits() {
return true;}
49 constexpr
static int get_max_num_bits() {
return num_bits;}
52 INLINE
bool get_bit(
int index)
const;
59 INLINE WordType
extract(
int low_bit,
int size)
const;
60 INLINE
void store(WordType value,
int low_bit,
int size);
61 INLINE
bool has_any_of(
int low_bit,
int size)
const;
62 INLINE
bool has_all_of(
int low_bit,
int size)
const;
63 INLINE
void set_range(
int low_bit,
int size);
65 INLINE
void set_range_to(
bool value,
int low_bit,
int size);
79 void output(std::ostream &out)
const;
80 void output_binary(std::ostream &out,
int spaces_every = 4)
const;
81 void output_hex(std::ostream &out,
int spaces_every = 4)
const;
82 void write(std::ostream &out,
int indent_level = 0)
const;
102 operator << (
int shift)
const;
105 operator >> (
int shift)
const;
110 INLINE
void operator <<= (
int shift);
111 INLINE
void operator >>= (
int shift);
117 BitMaskType _lo, _hi;
123 static void init_type();
131 template<
class BMType>
133 doubleBitMask.
output(out);
bool is_all_on() const
Returns true if the entire doubleBitMask is one, false otherwise.
void output_binary(std::ostream &out, int spaces_every=4) const
Writes the DoubleBitMask out as a binary number, with spaces every four bits.
This is a specific kind of HashGenerator that simply adds up all of the ints.
void clear_range(int low_bit, int size)
Sets the indicated range of bits off.
static DoubleBitMask< BMType > range(int low_bit, int size)
Returns a DoubleBitMask whose size bits, beginning at low_bit, are on.
constexpr int get_num_bits() const
Returns the number of bits available to set in the doubleBitMask.
bool operator<(const DoubleBitMask< BMType > &other) const
The ordering operator is of limited usefulness with a DoubleBitMask, however, it has a definition whi...
int get_lowest_on_bit() const
Returns the index of the lowest 1 bit in the mask.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_range_to(bool value, int low_bit, int size)
Sets the indicated range of bits to either on or off.
void generate_hash(ChecksumHashGenerator &hashgen) const
Adds the doubleBitMask to the indicated hash generator.
int get_highest_on_bit() const
Returns the index of the highest 1 bit in the mask.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a special BitMask type that is implemented as a pair of lesser BitMask types,...
void write(std::ostream &out, int indent_level=0) 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.
bool has_any_of(int low_bit, int size) const
Returns true if any bit in the indicated range is set, false otherwise.
void clear_bit(int index)
Sets the nth bit off.
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 DoubleBitMask< BMType > lower_on(int on_bits)
Returns a DoubleBitMask whose lower on_bits bits are on.
bool get_bit(int index) const
Returns true if the nth bit is set, false if it is cleared.
int get_lowest_off_bit() const
Returns the index of the lowest 0 bit in the mask.
void output(std::ostream &out) const
Writes the DoubleBitMask out as a binary or a hex number, according to the number of bits.
void set_range(int low_bit, int size)
Sets the indicated range of bits on.
WordType extract(int low_bit, int size) const
Returns a word that represents only the indicated range of bits within this DoubleBitMask,...
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.
int get_num_off_bits() const
Returns the number of bits that are set to 0 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.
bool is_zero() const
Returns true if the entire doubleBitMask is zero, false otherwise.
void output_hex(std::ostream &out, int spaces_every=4) const
Writes the DoubleBitMask out as a hexadecimal number, with spaces every four digits.
static DoubleBitMask< BMType > bit(int index)
Returns a DoubleBitMask with only the indicated bit on.
int get_num_on_bits() const
Returns the number of bits that are set to 1 in the mask.
TypeHandle is the identifier used to differentiate C++ class types.
int compare_to(const DoubleBitMask< BMType > &other) const
Returns a number less than zero if this DoubleBitMask sorts before the indicated other DoubleBitMask,...
void invert_in_place()
Inverts all the bits in the DoubleBitMask.
int get_highest_off_bit() const
Returns the index of the highest 0 bit in the mask.
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,...
static DoubleBitMask< BMType > all_off()
Returns a DoubleBitMask whose bits are all off.
bool has_all_of(int low_bit, int size) const
Returns true if all bits in the indicated range are set, false otherwise.