31 template<
class WType,
int nbits>
34 typedef WType WordType;
37 enum { num_bits = nbits };
40 ALWAYS_INLINE constexpr
BitMask(WordType init_value);
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);
67 INLINE
void set_word(WordType value);
81 void output(std::ostream &out)
const;
82 void output_binary(std::ostream &out,
int spaces_every = 4)
const;
83 void output_hex(std::ostream &out,
int spaces_every = 4)
const;
84 void write(std::ostream &out,
int indent_level = 0)
const;
104 operator << (
int shift)
const;
107 operator >> (
int shift)
const;
112 INLINE
void operator <<= (
int shift);
113 INLINE
void operator >>= (
int shift);
140 static void init_type(
const std::string &name);
148 template<
class WType,
int nbits>
156 #define BITMASK16_DEF BitMask<uint16_t, 16> 157 #define BITMASK32_DEF BitMask<uint32_t, 32> 158 #define BITMASK64_DEF BitMask<uint64_t, 64> 159 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, BITMASK16_DEF);
160 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, BITMASK32_DEF);
161 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, BITMASK64_DEF);
167 #if NATIVE_WORDSIZE == 32 169 #elif NATIVE_WORDSIZE == 64 172 #error No definition for NATIVE_WORDSIZE--should be defined in dtoolbase.h. 173 #endif // NATIVE_WORDSIZE void clear_bit(int index)
Sets the nth bit off.
static BitMask< WType, nbits > bit(int index)
Returns a BitMask with only the indicated bit on.
void flood_down_in_place()
Floods this bitmask's bits downwards.
int get_highest_off_bit() const
Returns the index of the highest 0 bit in the mask.
bool has_any_of(int low_bit, int size) const
Returns true if any bit in the indicated range is set, false otherwise.
This is a specific kind of HashGenerator that simply adds up all of the ints.
BitMask< WType, nbits > flood_bits_down() const
Returns a BitMask with the bits flooded down.
void invert_in_place()
Inverts all the bits in the BitMask.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static BitMask< WType, nbits > all_on()
Returns a BitMask whose bits are all on.
void set_range(int low_bit, int size)
Sets the indicated range of bits on.
void clear()
Sets all the bits in the BitMask off.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void store(WordType value, int low_bit, int size)
Stores the indicated word into the indicated range of bits with this BitMask.
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...
void write(std::ostream &out, int indent_level=0) const
Writes the BitMask out as a binary or a hex number, according to the number of bits.
bool operator<(const BitMask< WType, nbits > &other) const
The ordering operator is of limited usefulness with a BitMask, however, it has a definition which pla...
int get_lowest_off_bit() const
Returns the index of the lowest 0 bit in the mask.
bool __nonzero__() const
Returns true if the bitmask is not zero.
int compare_to(const BitMask< WType, nbits > &other) const
Returns a number less than zero if this BitMask sorts before the indicated other BitMask,...
BitMask< WType, nbits > keep_next_highest_bit() const
Returns a BitMask with only the next highest bit above the indicated bit on, or all_off.
constexpr int get_num_bits() const
Returns the number of bits available to set in the bitmask.
static BitMask< WType, nbits > all_off()
Returns a BitMask whose bits are all off.
int get_num_off_bits() const
Returns the number of bits that are set to 0 in the mask.
void set_word(WordType value)
Sets the entire BitMask to the value indicated by the given word.
static BitMask< WType, nbits > range(int low_bit, int size)
Returns a BitMask whose size bits, beginning at low_bit, are on.
void flood_up_in_place()
Floods this bitmask's bits upwards.
void clear_range(int low_bit, int size)
Sets the indicated range of bits off.
bool is_all_on() const
Returns true if the entire bitmask is one, false otherwise.
void output_hex(std::ostream &out, int spaces_every=4) const
Writes the BitMask out as a hexadecimal number, with spaces every four digits.
WordType get_word() const
Returns the entire BitMask as a single word.
bool get_bit(int index) const
Returns true if the nth bit is set, false if it is cleared.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static BitMask< WType, nbits > lower_on(int on_bits)
Returns a BitMask whose lower on_bits bits are on.
void generate_hash(ChecksumHashGenerator &hashgen) const
Adds the bitmask to the indicated hash generator.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_lowest_on_bit() const
Returns the index of the lowest 1 bit in the mask.
void set_bit_to(int index, bool value)
Sets the nth bit either on or off, according to the indicated bool value.
WordType extract(int low_bit, int size) const
Returns a word that represents only the indicated range of bits within this BitMask,...
void output(std::ostream &out) const
Writes the BitMask out as a binary or a hex number, according to the number of bits.
bool has_bits_in_common(const BitMask< WType, nbits > &other) const
Returns true if this BitMask has any "one" bits in common with the other one, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BitMask< WType, nbits > flood_bits_up() const
Returns a BitMask with the bits flooded upwards.
void set_range_to(bool value, int low_bit, int size)
Sets the indicated range of bits to either on or off.
int get_highest_on_bit() const
Returns the index of the highest 1 bit in the mask.
void set_bit(int index)
Sets the nth bit on.
bool has_all_of(int low_bit, int size) const
Returns true if all bits in the indicated range are set, false otherwise.
void output_binary(std::ostream &out, int spaces_every=4) const
Writes the BitMask out as a binary number, with spaces every four bits.
int get_key() const
Returns a mostly unique integer key per unique bitmask, suitable for using in a hash table.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool is_zero() const
Returns true if the entire bitmask is zero, false otherwise.
BitMask< WType, nbits > keep_next_lowest_bit() const
Returns a BitMask with only the next lower bit below the indicated bit on, or all_off.