Panda3D
|
A general bitmask class. More...
#include "bitMask.h"
Public Types | |
enum | { num_bits = nbits } |
typedef WType | WordType |
Public Member Functions | |
BitMask (WordType init_value) | |
BitMask (const BitMask< WType, nbits > ©) | |
bool | __nonzero__ () const |
Returns true if the bitmask is not zero. More... | |
void | clear () |
Sets all the bits in the BitMask off. More... | |
void | clear_bit (int index) |
Sets the nth bit off. More... | |
void | clear_range (int low_bit, int size) |
Sets the indicated range of bits off. More... | |
int | compare_to (const BitMask< WType, nbits > &other) const |
Returns a number less than zero if this BitMask sorts before the indicated other BitMask, greater than zero if it sorts after, or 0 if they are equivalent. More... | |
WordType | extract (int low_bit, int size) const |
Returns a word that represents only the indicated range of bits within this BitMask, shifted to the least-significant position. More... | |
BitMask< WType, nbits > | flood_bits_down () const |
Returns a BitMask with the bits flooded down. More... | |
BitMask< WType, nbits > | flood_bits_up () const |
Returns a BitMask with the bits flooded upwards. More... | |
void | flood_down_in_place () |
Floods this bitmask's bits downwards. More... | |
void | flood_up_in_place () |
Floods this bitmask's bits upwards. More... | |
void | generate_hash (ChecksumHashGenerator &hashgen) const |
Adds the bitmask to the indicated hash generator. More... | |
bool | get_bit (int index) const |
Returns true if the nth bit is set, false if it is cleared. More... | |
int | get_highest_off_bit () const |
Returns the index of the highest 0 bit in the mask. More... | |
int | get_highest_on_bit () const |
Returns the index of the highest 1 bit in the mask. More... | |
int | get_key () const |
Returns a mostly unique integer key per unique bitmask, suitable for using in a hash table. More... | |
int | get_lowest_off_bit () const |
Returns the index of the lowest 0 bit in the mask. More... | |
int | get_lowest_on_bit () const |
Returns the index of the lowest 1 bit in the mask. More... | |
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 of low_bit. More... | |
int | get_num_off_bits () const |
Returns the number of bits that are set to 0 in the mask. More... | |
int | get_num_on_bits () const |
Returns the number of bits that are set to 1 in the mask. More... | |
WordType | get_word () const |
Returns the entire BitMask as a single word. More... | |
bool | has_all_of (int low_bit, int size) const |
Returns true if all bits in the indicated range are set, false otherwise. More... | |
bool | has_any_of (int low_bit, int size) const |
Returns true if any bit in the indicated range is set, false otherwise. More... | |
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. More... | |
void | invert_in_place () |
Inverts all the bits in the BitMask. More... | |
bool | is_all_on () const |
Returns true if the entire bitmask is one, false otherwise. More... | |
bool | is_zero () const |
Returns true if the entire bitmask is zero, false otherwise. More... | |
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. More... | |
BitMask< WType, nbits > | keep_next_highest_bit (int index) const |
Returns a BitMask with only the next highest bit above the indicated bit on, or all. More... | |
BitMask< WType, nbits > | keep_next_highest_bit (const BitMask< WType, nbits > &other) const |
Returns a BitMask with only the next highest "on" bit above all "on" bits in the passed in bitmask, or all_off. More... | |
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. More... | |
BitMask< WType, nbits > | keep_next_lowest_bit (int index) const |
Returns a BitMask with only the next lower bit below the indicated bit on, or all_off. More... | |
BitMask< WType, nbits > | keep_next_lowest_bit (const BitMask< WType, nbits > &other) const |
Returns a BitMask with only the next lowest "on" bit below all "on" bits in the passed in bitmask, or all_off. More... | |
bool | operator!= (const BitMask< WType, nbits > &other) const |
BitMask< WType, nbits > | operator& (const BitMask< WType, nbits > &other) const |
void | operator&= (const BitMask< WType, nbits > &other) |
bool | operator< (const BitMask< WType, nbits > &other) const |
The ordering operator is of limited usefulness with a BitMask, however, it has a definition which places all unique BitMasks into a unique ordering. More... | |
BitMask< WType, nbits > | operator<< (int shift) const |
void | operator<<= (int shift) |
BitMask< WType, nbits > & | operator= (const BitMask< WType, nbits > ©) |
bool | operator== (const BitMask< WType, nbits > &other) const |
BitMask< WType, nbits > | operator>> (int shift) const |
void | operator>>= (int shift) |
BitMask< WType, nbits > | operator^ (const BitMask< WType, nbits > &other) const |
void | operator^= (const BitMask< WType, nbits > &other) |
BitMask< WType, nbits > | operator| (const BitMask< WType, nbits > &other) const |
void | operator|= (const BitMask< WType, nbits > &other) |
BitMask< WType, nbits > | operator~ () const |
void | output (ostream &out) const |
Writes the BitMask out as a binary or a hex number, according to the number of bits. More... | |
void | output_binary (ostream &out, int spaces_every=4) const |
Writes the BitMask out as a binary number, with spaces every four bits. More... | |
void | output_hex (ostream &out, int spaces_every=4) const |
Writes the BitMask out as a hexadecimal number, with spaces every four digits. More... | |
void | set_bit (int index) |
Sets the nth bit on. More... | |
void | set_bit_to (int index, bool value) |
Sets the nth bit either on or off, according to the indicated bool value. More... | |
void | set_range (int low_bit, int size) |
Sets the indicated range of bits on. More... | |
void | set_range_to (bool value, int low_bit, int size) |
Sets the indicated range of bits to either on or off. More... | |
void | set_word (WordType value) |
Sets the entire BitMask to the value indicated by the given word. More... | |
void | store (WordType value, int low_bit, int size) |
Stores the indicated word into the indicated range of bits with this BitMask. More... | |
void | write (ostream &out, int indent_level=0) const |
Writes the BitMask out as a binary or a hex number, according to the number of bits. More... | |
Static Public Member Functions | |
static BitMask< WType, nbits > | all_off () |
Returns a BitMask whose bits are all off. More... | |
static BitMask< WType, nbits > | all_on () |
Returns a BitMask whose bits are all on. More... | |
static BitMask< WType, nbits > | bit (int index) |
Returns a BitMask with only the indicated bit on. More... | |
static TypeHandle | get_class_type () |
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 that may be stored in this structure. More... | |
static CONSTEXPR int | get_num_bits () |
Returns the number of bits available to set in the bitmask. More... | |
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. More... | |
static void | init_type () |
static BitMask< WType, nbits > | lower_on (int on_bits) |
Returns a BitMask whose lower on_bits bits are on. More... | |
static BitMask< WType, nbits > | range (int low_bit, int size) |
Returns a BitMask whose size bits, beginning at low_bit, are on. More... | |
A general bitmask class.
This stores an array of bits of some length that must fit within a given word of the indicated type. See also BitArray.
|
inline |
Returns true if the bitmask is not zero.
Definition at line 843 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::get_key().
|
inlinestatic |
Returns a BitMask whose bits are all off.
Definition at line 86 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::all_on(), BitMask< PN_uint32, 32 >::keep_next_highest_bit(), BitMask< PN_uint32, 32 >::keep_next_lowest_bit(), and BitMask< PN_uint32, 32 >::lower_on().
|
inlinestatic |
Returns a BitMask whose bits are all on.
Definition at line 73 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::lower_on().
|
inlinestatic |
Returns a BitMask with only the indicated bit on.
Definition at line 117 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::keep_next_highest_bit(), BitMask< PN_uint32, 32 >::keep_next_lowest_bit(), and BitMask< PN_uint32, 32 >::lower_on().
|
inline |
Sets all the bits in the BitMask off.
Definition at line 561 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::has_bits_in_common().
|
inline |
Sets the nth bit off.
index must be in the range [0, num_bits).
Definition at line 238 of file bitMask.I.
Referenced by RenderState::bin_removed(), RenderState::compare_mask(), RenderState::compare_to(), RenderState::cull_callback(), BitMask< PN_uint32, 32 >::set_bit(), BitMask< PN_uint32, 32 >::set_bit_to(), and RenderState::write_datagram().
|
inline |
Sets the indicated range of bits off.
Definition at line 356 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::set_range(), and BitMask< PN_uint32, 32 >::set_range_to().
|
inline |
Returns a number less than zero if this BitMask sorts before the indicated other BitMask, greater than zero if it sorts after, or 0 if they are equivalent.
This is based on the same ordering defined by operator <.
Definition at line 683 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::operator<().
|
inline |
Returns a word that represents only the indicated range of bits within this BitMask, shifted to the least-significant position.
Definition at line 293 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::is_all_on(), and BitMask< PN_uint32, 32 >::output_hex().
|
inline |
Returns a BitMask with the bits flooded down.
Definition at line 912 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::flood_bits_down(), BitMask< PN_uint32, 32 >::flood_bits_up(), and BitMask< PN_uint32, 32 >::flood_down_in_place().
|
inline |
Returns a BitMask with the bits flooded upwards.
Definition at line 900 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::flood_bits_up(), BitMask< PN_uint32, 32 >::flood_down_in_place(), and BitMask< PN_uint32, 32 >::flood_up_in_place().
|
inline |
Floods this bitmask's bits downwards.
Definition at line 889 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::flood_up_in_place(), BitMask< PN_uint32, 32 >::keep_next_highest_bit(), and BitMask< PN_uint32, 32 >::keep_next_lowest_bit().
|
inline |
Floods this bitmask's bits upwards.
Definition at line 878 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::generate_hash(), BitMask< PN_uint32, 32 >::keep_next_highest_bit(), and BitMask< PN_uint32, 32 >::keep_next_lowest_bit().
|
inline |
Adds the bitmask to the indicated hash generator.
Definition at line 854 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::__nonzero__().
|
inline |
Returns true if the nth bit is set, false if it is cleared.
index must be in the range [0, num_bits).
Definition at line 212 of file bitMask.I.
Referenced by BulletWorld::contact_test_pair(), BitMask< PN_uint32, 32 >::get_num_bits(), GraphicsStateGuardian::get_supports_compressed_texture_format(), and BitMask< PN_uint32, 32 >::output_binary().
|
inline |
Returns the index of the highest 0 bit in the mask.
Returns -1 if there are no 0 bits.
Definition at line 467 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::get_highest_on_bit().
|
inline |
Returns the index of the highest 1 bit in the mask.
Returns -1 if there are no 1 bits.
Definition at line 455 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::get_lowest_off_bit(), BitMask< PN_uint32, 32 >::keep_next_highest_bit(), and BitMask< PN_uint32, 32 >::keep_next_lowest_bit().
|
inline |
Returns a mostly unique integer key per unique bitmask, suitable for using in a hash table.
Definition at line 832 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::compare_to().
|
inline |
Returns the index of the lowest 0 bit in the mask.
Returns -1 if there are no 0 bits.
Definition at line 443 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::get_lowest_on_bit().
|
inline |
Returns the index of the lowest 1 bit in the mask.
Returns -1 if there are no 1 bits.
Definition at line 431 of file bitMask.I.
Referenced by RenderState::bin_removed(), RenderState::compare_mask(), RenderState::compare_to(), RenderState::cull_callback(), BitMask< PN_uint32, 32 >::get_num_off_bits(), BitMask< PN_uint32, 32 >::keep_next_highest_bit(), BitMask< PN_uint32, 32 >::keep_next_lowest_bit(), and RenderState::write_datagram().
|
static |
If get_max_num_bits() returned true, this method may be called to return the maximum number of bits that may be stored in this structure.
It is an error to call this if get_max_num_bits() return false.
It is never an error to call this method. This returns the same thing as get_num_bits(). This method is defined so generic programming algorithms can use BitMask or BitArray interchangeably.
Definition at line 187 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::has_max_num_bits().
|
inline |
Returns the index of the next bit in the mask, above low_bit, whose value is different that the value of low_bit.
Returns low_bit again if all bits higher than low_bit have the same value.
This can be used to quickly iterate through all of the bits in the mask.
Definition at line 484 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::get_highest_off_bit().
|
static |
Returns the number of bits available to set in the bitmask.
Definition at line 199 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::get_max_num_bits().
|
inline |
Returns the number of bits that are set to 0 in the mask.
Definition at line 419 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::get_num_on_bits().
|
inline |
Returns the number of bits that are set to 1 in the mask.
Definition at line 407 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::set_word().
|
inline |
Returns the entire BitMask as a single word.
Definition at line 383 of file bitMask.I.
Referenced by OdeGeom::get_id(), OdeSpace::get_id(), and BitMask< PN_uint32, 32 >::set_range_to().
|
inline |
Returns true if all bits in the indicated range are set, false otherwise.
Definition at line 332 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::has_any_of().
|
inline |
Returns true if any bit in the indicated range is set, false otherwise.
Definition at line 319 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::store().
|
inline |
Returns true if this BitMask has any "one" bits in common with the other one, false otherwise.
This is equivalent to (mask & other) != 0, but may be faster. (Actually, it should only be faster in the BitArray case, but this method is provided for the benefit of generic programming algorithms).
Definition at line 550 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::invert_in_place().
|
static |
Returns true if there is a maximum number of bits that may be stored in this structure, false otherwise.
If this returns true, the number may be queried in get_max_num_bits().
This method always returns true. This method is defined so generic programming algorithms can use BitMask or BitArray interchangeably.
Definition at line 168 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::range().
|
inline |
Inverts all the bits in the BitMask.
This is equivalent to mask = ~mask.
Definition at line 533 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::get_next_higher_different_bit(), BitMask< PN_uint32, 32 >::keep_next_highest_bit(), and BitMask< PN_uint32, 32 >::keep_next_lowest_bit().
|
inline |
Returns true if the entire bitmask is one, false otherwise.
Definition at line 280 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::is_zero().
|
inline |
Returns true if the entire bitmask is zero, false otherwise.
Definition at line 268 of file bitMask.I.
Referenced by PandaNode::adjust_draw_mask(), RenderState::is_empty(), PandaNode::is_under_scene_root(), and BitMask< PN_uint32, 32 >::set_bit_to().
|
inline |
Returns a BitMask with only the next highest bit above the indicated bit on, or all_off.
Definition at line 926 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::flood_bits_down(), BitMask< PN_uint32, 32 >::keep_next_highest_bit(), and BitMask< PN_uint32, 32 >::keep_next_lowest_bit().
|
inline |
Returns a BitMask with only the next highest "on" bit above all "on" bits in the passed in bitmask, or all_off.
If there are no "on" bits in the passed in bitmask, it will return keep_next_highest_bit().
|
inline |
Returns a BitMask with only the next lower bit below the indicated bit on, or all_off.
Definition at line 943 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::keep_next_highest_bit(), and BitMask< PN_uint32, 32 >::keep_next_lowest_bit().
|
inline |
Returns a BitMask with only the next lowest "on" bit below all "on" bits in the passed in bitmask, or all_off.
If there are no "on" bits in the passed in bitmask, it will return keep_next_lowest_bit().
|
inlinestatic |
Returns a BitMask whose lower on_bits bits are on.
Definition at line 99 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::all_off(), and BitMask< PN_uint32, 32 >::extract().
|
inline |
The ordering operator is of limited usefulness with a BitMask, however, it has a definition which places all unique BitMasks into a unique ordering.
It may be useful when defining ordered STL containers of BitMasks, for instance; and it's required in order to export any STL container (ordered or unordered) of BitMask under Windows.
Definition at line 669 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::write().
void BitMask< WType, nbits >::output | ( | ostream & | out | ) | const |
Writes the BitMask out as a binary or a hex number, according to the number of bits.
Definition at line 573 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::clear().
void BitMask< WType, nbits >::output_binary | ( | ostream & | out, |
int | spaces_every = 4 |
||
) | const |
Writes the BitMask out as a binary number, with spaces every four bits.
Definition at line 589 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::output().
void BitMask< WType, nbits >::output_hex | ( | ostream & | out, |
int | spaces_every = 4 |
||
) | const |
Writes the BitMask out as a hexadecimal number, with spaces every four digits.
Definition at line 606 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::output(), and BitMask< PN_uint32, 32 >::output_binary().
|
inlinestatic |
Returns a BitMask whose size bits, beginning at low_bit, are on.
Definition at line 131 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::bit(), BitMask< PN_uint32, 32 >::clear_range(), BitMask< PN_uint32, 32 >::has_all_of(), BitMask< PN_uint32, 32 >::has_any_of(), BitMask< PN_uint32, 32 >::set_range(), and BitMask< PN_uint32, 32 >::store().
|
inline |
Sets the nth bit on.
index must be in the range [0, num_bits).
Definition at line 225 of file bitMask.I.
Referenced by RenderState::bin_removed(), BitMask< PN_uint32, 32 >::bit(), RenderState::cull_callback(), BitMask< PN_uint32, 32 >::get_bit(), BitMask< PN_uint32, 32 >::keep_next_highest_bit(), BitMask< PN_uint32, 32 >::keep_next_lowest_bit(), and BitMask< PN_uint32, 32 >::set_bit_to().
|
inline |
Sets the nth bit either on or off, according to the indicated bool value.
index must be in the range [0, num_bits).
Definition at line 252 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::clear_bit().
|
inline |
Sets the indicated range of bits on.
Definition at line 344 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::has_all_of(), and BitMask< PN_uint32, 32 >::set_range_to().
|
inline |
Sets the indicated range of bits to either on or off.
Definition at line 368 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::clear_range().
|
inline |
Sets the entire BitMask to the value indicated by the given word.
Definition at line 395 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::get_word(), and PandaNode::write_recorder().
|
inline |
Stores the indicated word into the indicated range of bits with this BitMask.
Definition at line 306 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::extract().
void BitMask< WType, nbits >::write | ( | ostream & | out, |
int | indent_level = 0 |
||
) | const |
Writes the BitMask out as a binary or a hex number, according to the number of bits.
Definition at line 630 of file bitMask.I.
Referenced by BitMask< PN_uint32, 32 >::output_hex().