Panda3D
|
A general bitmask class. More...
#include "bitMask.h"
Public Types | |
enum | { num_bits = nbits } |
typedef WType | WordType |
Public Member Functions | |
constexpr | BitMask (WordType init_value) |
bool | __nonzero__ () const |
Returns true if the bitmask is not zero. | |
void | clear () |
Sets all the bits in the BitMask off. | |
void | clear_bit (int index) |
Sets the nth bit off. | |
void | clear_range (int low_bit, int size) |
Sets the indicated range of bits off. | |
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. | |
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. | |
BitMask< WType, nbits > | flood_bits_down () const |
Returns a BitMask with the bits flooded down. | |
BitMask< WType, nbits > | flood_bits_up () const |
Returns a BitMask with the bits flooded upwards. | |
void | flood_down_in_place () |
Floods this bitmask's bits downwards. | |
void | flood_up_in_place () |
Floods this bitmask's bits upwards. | |
void | generate_hash (ChecksumHashGenerator &hashgen) const |
Adds the bitmask to the indicated hash generator. | |
bool | get_bit (int index) const |
Returns true if the nth bit is set, false if it is cleared. | |
int | get_highest_off_bit () const |
Returns the index of the highest 0 bit in the mask. | |
int | get_highest_on_bit () const |
Returns the index of the highest 1 bit in the mask. | |
int | get_key () const |
Returns a mostly unique integer key per unique bitmask, suitable for using in a hash table. | |
int | get_lowest_off_bit () const |
Returns the index of the lowest 0 bit in the mask. | |
int | get_lowest_on_bit () const |
Returns the index of the lowest 1 bit in the mask. | |
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. | |
constexpr int | get_num_bits () const |
Returns the number of bits available to set in the bitmask. | |
int | get_num_off_bits () const |
Returns the number of bits that are set to 0 in the mask. | |
int | get_num_on_bits () const |
Returns the number of bits that are set to 1 in the mask. | |
WordType | get_word () const |
Returns the entire BitMask as a single word. | |
bool | has_all_of (int low_bit, int size) const |
Returns true if all bits in the indicated range are set, false otherwise. | |
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_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. | |
void | invert_in_place () |
Inverts all the bits in the BitMask. | |
bool | is_all_on () const |
Returns true if the entire bitmask is one, false otherwise. | |
bool | is_zero () const |
Returns true if the entire bitmask is zero, false otherwise. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
BitMask< WType, nbits > | operator<< (int shift) const |
void | operator<<= (int shift) |
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 (std::ostream &out) const |
Writes the BitMask out as a binary or a hex number, according to the number of bits. | |
void | output_binary (std::ostream &out, int spaces_every=4) const |
Writes the BitMask out as a binary number, with spaces every four bits. | |
void | output_hex (std::ostream &out, int spaces_every=4) const |
Writes the BitMask out as a hexadecimal number, with spaces every four digits. | |
void | set_bit (int index) |
Sets the nth bit on. | |
void | set_bit_to (int index, bool value) |
Sets the nth bit either on or off, according to the indicated bool value. | |
void | set_range (int low_bit, int size) |
Sets the indicated range of bits on. | |
void | set_range_to (bool value, int low_bit, int size) |
Sets the indicated range of bits to either on or off. | |
void | set_word (WordType value) |
Sets the entire BitMask to the value indicated by the given word. | |
void | store (WordType value, int low_bit, int size) |
Stores the indicated word into the indicated range of bits with this BitMask. | |
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. | |
Static Public Member Functions | |
static BitMask< WType, nbits > | all_off () |
Returns a BitMask whose bits are all off. | |
static BitMask< WType, nbits > | all_on () |
Returns a BitMask whose bits are all on. | |
static BitMask< WType, nbits > | bit (int index) |
Returns a BitMask with only the indicated bit on. | |
static TypeHandle | get_class_type () |
static constexpr int | get_max_num_bits () |
static constexpr bool | has_max_num_bits () |
static void | init_type (const std::string &name) |
static BitMask< WType, nbits > | lower_on (int on_bits) |
Returns a BitMask whose lower on_bits bits are on. | |
static BitMask< WType, nbits > | range (int low_bit, int size) |
Returns a BitMask whose size bits, beginning at low_bit, are on. | |
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.
typedef WType BitMask< WType, nbits >::WordType |
|
inline |
|
inlinestatic |
Returns a BitMask whose bits are all off.
Definition at line 42 of file bitMask.I.
Referenced by BitMask< WType, nbits >::keep_next_highest_bit(), and BitMask< WType, nbits >::keep_next_lowest_bit().
|
inlinestatic |
Returns a BitMask with only the indicated bit on.
Definition at line 69 of file bitMask.I.
Referenced by BitMask< WType, nbits >::keep_next_highest_bit(), and BitMask< WType, nbits >::keep_next_lowest_bit().
|
inline |
Sets all the bits in the BitMask off.
Definition at line 394 of file bitMask.I.
Referenced by GraphicsStateGuardian::begin_frame(), GraphicsStateGuardian::clear_state_and_transform(), GraphicsStateGuardian::end_scene(), and GraphicsStateGuardian::reset().
|
inline |
Sets the nth bit off.
index must be in the range [0, num_bits).
Definition at line 128 of file bitMask.I.
Referenced by RenderState::compare_mask(), RenderState::compare_to(), RenderState::cull_callback(), GraphicsStateGuardian::do_issue_color(), and RenderState::write_datagram().
|
inline |
Sets the indicated range of bits off.
Definition at line 222 of file bitMask.I.
References BitMask< WType, nbits >::range().
|
inline |
|
inline |
Returns a word that represents only the indicated range of bits within this BitMask, shifted to the least-significant position.
Definition at line 171 of file bitMask.I.
References BitMask< WType, nbits >::lower_on().
|
inline |
Returns a BitMask with the bits flooded down.
Definition at line 685 of file bitMask.I.
References flood_bits_down().
|
inline |
Returns a BitMask with the bits flooded upwards.
Definition at line 675 of file bitMask.I.
References flood_bits_up().
|
inline |
Floods this bitmask's bits downwards.
Definition at line 666 of file bitMask.I.
References flood_bits_down().
Referenced by BitMask< WType, nbits >::keep_next_highest_bit(), and BitMask< WType, nbits >::keep_next_lowest_bit().
|
inline |
Floods this bitmask's bits upwards.
Definition at line 657 of file bitMask.I.
References flood_bits_up().
Referenced by BitMask< WType, nbits >::keep_next_highest_bit(), and BitMask< WType, nbits >::keep_next_lowest_bit().
|
inline |
Adds the bitmask to the indicated hash generator.
Definition at line 639 of file bitMask.I.
References ChecksumHashGenerator::add_int().
|
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 108 of file bitMask.I.
Referenced by RenderState::compare_sort(), and GraphicsStateGuardian::get_supports_compressed_texture_format().
|
inlinestatic |
|
inline |
|
inline |
Returns the index of the highest 1 bit in the mask.
Returns -1 if there are no 1 bits.
Definition at line 302 of file bitMask.I.
Referenced by BitMask< WType, nbits >::keep_next_highest_bit().
|
inline |
|
inline |
|
inline |
Returns the index of the lowest 1 bit in the mask.
Returns -1 if there are no 1 bits.
Definition at line 282 of file bitMask.I.
Referenced by RenderState::compare_mask(), RenderState::compare_to(), RenderState::cull_callback(), BitMask< WType, nbits >::keep_next_lowest_bit(), and RenderState::write_datagram().
|
inlinestaticconstexpr |
|
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 325 of file bitMask.I.
References count_bits_in_word().
|
constexpr |
|
inline |
Returns the number of bits that are set to 0 in the mask.
Definition at line 272 of file bitMask.I.
References count_bits_in_word().
|
inline |
Returns the number of bits that are set to 1 in the mask.
Definition at line 263 of file bitMask.I.
References count_bits_in_word().
Referenced by RenderState::write_datagram().
|
inline |
Returns the entire BitMask as a single word.
Definition at line 245 of file bitMask.I.
Referenced by CollisionNode::write_datagram(), and Camera::write_datagram().
|
inline |
Returns true if all bits in the indicated range are set, false otherwise.
Definition at line 202 of file bitMask.I.
References BitMask< WType, nbits >::range().
|
inline |
Returns true if any bit in the indicated range is set, false otherwise.
Definition at line 192 of file bitMask.I.
References BitMask< WType, nbits >::range().
|
inline |
|
inlinestaticconstexpr |
|
static |
|
inline |
Inverts all the bits in the BitMask.
This is equivalent to mask = ~mask.
Definition at line 371 of file bitMask.I.
Referenced by BitMask< WType, nbits >::keep_next_highest_bit(), and BitMask< WType, nbits >::keep_next_lowest_bit().
|
inline |
|
inline |
Returns true if the entire bitmask is zero, false otherwise.
Definition at line 152 of file bitMask.I.
Referenced by PandaNode::adjust_draw_mask(), and RenderState::is_empty().
|
inline |
Returns a BitMask with only the next highest bit above the indicated bit on, or all_off.
Definition at line 697 of file bitMask.I.
References BitMask< WType, nbits >::all_off(), BitMask< WType, nbits >::bit(), and get_lowest_on_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().
Definition at line 776 of file bitMask.I.
References BitMask< WType, nbits >::get_highest_on_bit().
|
inline |
Returns a BitMask with only the next highest bit above the indicated bit on, or all.
Definition at line 727 of file bitMask.I.
References BitMask< WType, nbits >::flood_down_in_place(), BitMask< WType, nbits >::flood_up_in_place(), BitMask< WType, nbits >::invert_in_place(), and BitMask< WType, nbits >::set_bit().
|
inline |
Returns a BitMask with only the next lower bit below the indicated bit on, or all_off.
Definition at line 712 of file bitMask.I.
References BitMask< WType, nbits >::all_off(), BitMask< WType, nbits >::bit(), and get_highest_on_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().
Definition at line 792 of file bitMask.I.
References BitMask< WType, nbits >::get_lowest_on_bit().
|
inline |
Returns a BitMask with only the next lower bit below the indicated bit on, or all_off.
Definition at line 751 of file bitMask.I.
References BitMask< WType, nbits >::flood_down_in_place(), BitMask< WType, nbits >::flood_up_in_place(), BitMask< WType, nbits >::invert_in_place(), and BitMask< WType, nbits >::set_bit().
|
inlinestatic |
Returns a BitMask whose lower on_bits bits are on.
Definition at line 53 of file bitMask.I.
Referenced by BitMask< WType, nbits >::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.
|
inline |
|
inline |
void BitMask< WType, nbits >::output | ( | std::ostream & | out | ) | const |
void BitMask< WType, nbits >::output_binary | ( | std::ostream & | out, |
int | spaces_every = 4 ) const |
void BitMask< WType, nbits >::output_hex | ( | std::ostream & | out, |
int | spaces_every = 4 ) const |
|
inlinestatic |
Returns a BitMask whose size bits, beginning at low_bit, are on.
Definition at line 80 of file bitMask.I.
Referenced by BitMask< WType, nbits >::clear_range(), BitMask< WType, nbits >::has_all_of(), BitMask< WType, nbits >::has_any_of(), BitMask< WType, nbits >::set_range(), and BitMask< WType, nbits >::store().
|
inline |
Sets the nth bit on.
index must be in the range [0, num_bits).
Definition at line 118 of file bitMask.I.
Referenced by RenderState::complete_pointers(), CPT(), BitMask< WType, nbits >::keep_next_highest_bit(), and BitMask< WType, nbits >::keep_next_lowest_bit().
|
inline |
|
inline |
Sets the indicated range of bits on.
Definition at line 212 of file bitMask.I.
References BitMask< WType, nbits >::range().
|
inline |
|
inline |
|
inline |
Stores the indicated word into the indicated range of bits with this BitMask.
Definition at line 182 of file bitMask.I.
References BitMask< WType, nbits >::range().
void BitMask< WType, nbits >::write | ( | std::ostream & | out, |
int | indent_level = 0 ) const |