Panda3D
|
This is a special BitMask type that is implemented as a pair of lesser BitMask types, to present a double-wide bit mask. More...
#include "doubleBitMask.h"
Public Types | |
enum | { half_bits = BitMaskType::num_bits, num_bits = BitMaskType::num_bits * 2 } |
typedef BMType | BitMaskType |
typedef BMType::WordType | WordType |
Public Member Functions | |
DoubleBitMask (const DoubleBitMask< BMType > ©) | |
void | clear () |
Sets all the bits in the DoubleBitMask 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 DoubleBitMask< BMType > &other) const |
Returns a number less than zero if this DoubleBitMask sorts before the indicated other DoubleBitMask, 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 DoubleBitMask, shifted to the least-significant position. | |
void | generate_hash (ChecksumHashGenerator &hashgen) const |
Adds the doubleBitMask 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_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. | |
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. | |
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 DoubleBitMask< BMType > &other) const |
Returns true if this DoubleBitMask has any "one" bits in common with the other one, false otherwise. | |
void | invert_in_place () |
Inverts all the bits in the DoubleBitMask. | |
bool | is_all_on () const |
Returns true if the entire doubleBitMask is one, false otherwise. | |
bool | is_zero () const |
Returns true if the entire doubleBitMask is zero, false otherwise. | |
bool | operator!= (const DoubleBitMask< BMType > &other) const |
DoubleBitMask< BMType > | operator& (const DoubleBitMask< BMType > &other) const |
void | operator&= (const DoubleBitMask< BMType > &other) |
bool | operator< (const DoubleBitMask< BMType > &other) const |
The ordering operator is of limited usefulness with a DoubleBitMask, however, it has a definition which places all unique DoubleBitMasks into a unique ordering. | |
DoubleBitMask< BMType > | operator<< (int shift) const |
void | operator<<= (int shift) |
DoubleBitMask< BMType > & | operator= (const DoubleBitMask< BMType > ©) |
bool | operator== (const DoubleBitMask< BMType > &other) const |
DoubleBitMask< BMType > | operator>> (int shift) const |
void | operator>>= (int shift) |
DoubleBitMask< BMType > | operator^ (const DoubleBitMask< BMType > &other) const |
void | operator^= (const DoubleBitMask< BMType > &other) |
DoubleBitMask< BMType > | operator| (const DoubleBitMask< BMType > &other) const |
void | operator|= (const DoubleBitMask< BMType > &other) |
DoubleBitMask< BMType > | operator~ () const |
void | output (ostream &out) const |
Writes the DoubleBitMask out as a binary or a hex number, according to the number of bits. | |
void | output_binary (ostream &out, int spaces_every=4) const |
Writes the DoubleBitMask out as a binary number, with spaces every four bits. | |
void | output_hex (ostream &out, int spaces_every=4) const |
Writes the DoubleBitMask 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 | store (WordType value, int low_bit, int size) |
Stores the indicated word into the indicated range of bits with this DoubleBitMask. | |
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. | |
Static Public Member Functions | |
static DoubleBitMask< BMType > | all_off () |
Returns a DoubleBitMask whose bits are all off. | |
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. | |
static TypeHandle | get_class_type () |
static 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. | |
static int | get_num_bits () |
Returns the number of bits available to set in the doubleBitMask. | |
static bool | has_max_num_bits () |
Returns true if there is a maximum number of bits that may be stored in this structure, false otherwise. | |
static void | init_type () |
static DoubleBitMask< BMType > | lower_on (int on_bits) |
Returns a DoubleBitMask whose lower on_bits bits are on. | |
static DoubleBitMask< BMType > | range (int low_bit, int size) |
Returns a DoubleBitMask whose size bits, beginning at low_bit, are on. |
This is a special BitMask type that is implemented as a pair of lesser BitMask types, to present a double-wide bit mask.
For instance, on a 32-bit system, this can be used to make a single 64-bit bit mask. More of these can be ganged up together to make a 128-bit mask, and so on.
Definition at line 32 of file doubleBitMask.h.
DoubleBitMask< BMType > DoubleBitMask< BMType >::all_off | ( | ) | [inline, static] |
Returns a DoubleBitMask whose bits are all off.
Definition at line 75 of file doubleBitMask.I.
DoubleBitMask< BMType > DoubleBitMask< BMType >::all_on | ( | ) | [inline, static] |
Returns a DoubleBitMask whose bits are all on.
Definition at line 61 of file doubleBitMask.I.
DoubleBitMask< BMType > DoubleBitMask< BMType >::bit | ( | int | index | ) | [inline, static] |
Returns a DoubleBitMask with only the indicated bit on.
Definition at line 112 of file doubleBitMask.I.
References DoubleBitMask< BMType >::set_bit().
void DoubleBitMask< BMType >::clear | ( | ) | [inline] |
Sets all the bits in the DoubleBitMask off.
Definition at line 592 of file doubleBitMask.I.
void DoubleBitMask< BMType >::clear_bit | ( | int | index | ) | [inline] |
Sets the nth bit off.
index must be in the range [0, num_bits).
Definition at line 232 of file doubleBitMask.I.
void DoubleBitMask< BMType >::clear_range | ( | int | low_bit, |
int | size | ||
) | [inline] |
Sets the indicated range of bits off.
Definition at line 395 of file doubleBitMask.I.
int DoubleBitMask< BMType >::compare_to | ( | const DoubleBitMask< BMType > & | other | ) | const [inline] |
Returns a number less than zero if this DoubleBitMask sorts before the indicated other DoubleBitMask, 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 702 of file doubleBitMask.I.
DoubleBitMask< BMType >::WordType DoubleBitMask< BMType >::extract | ( | int | low_bit, |
int | size | ||
) | const [inline] |
Returns a word that represents only the indicated range of bits within this DoubleBitMask, shifted to the least-significant position.
Definition at line 290 of file doubleBitMask.I.
void DoubleBitMask< BMType >::generate_hash | ( | ChecksumHashGenerator & | hashgen | ) | const [inline] |
Adds the doubleBitMask to the indicated hash generator.
Definition at line 855 of file doubleBitMask.I.
bool DoubleBitMask< BMType >::get_bit | ( | int | index | ) | const [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 200 of file doubleBitMask.I.
int DoubleBitMask< BMType >::get_highest_off_bit | ( | ) | const [inline] |
Returns the index of the highest 0 bit in the mask.
Returns -1 if there are no 0 bits.
Definition at line 512 of file doubleBitMask.I.
int DoubleBitMask< BMType >::get_highest_on_bit | ( | ) | const [inline] |
Returns the index of the highest 1 bit in the mask.
Returns -1 if there are no 1 bits.
Definition at line 494 of file doubleBitMask.I.
int DoubleBitMask< BMType >::get_lowest_off_bit | ( | ) | const [inline] |
Returns the index of the lowest 0 bit in the mask.
Returns -1 if there are no 0 bits.
Definition at line 475 of file doubleBitMask.I.
int DoubleBitMask< BMType >::get_lowest_on_bit | ( | ) | const [inline] |
Returns the index of the lowest 1 bit in the mask.
Returns -1 if there are no 1 bits.
Definition at line 456 of file doubleBitMask.I.
int DoubleBitMask< BMType >::get_max_num_bits | ( | ) | [inline, 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 DoubleBitMask or BitArray interchangeably.
Definition at line 175 of file doubleBitMask.I.
int DoubleBitMask< BMType >::get_next_higher_different_bit | ( | int | low_bit | ) | const [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 535 of file doubleBitMask.I.
int DoubleBitMask< BMType >::get_num_bits | ( | ) | [inline, static] |
Returns the number of bits available to set in the doubleBitMask.
Definition at line 187 of file doubleBitMask.I.
int DoubleBitMask< BMType >::get_num_off_bits | ( | ) | const [inline] |
Returns the number of bits that are set to 0 in the mask.
Definition at line 444 of file doubleBitMask.I.
int DoubleBitMask< BMType >::get_num_on_bits | ( | ) | const [inline] |
Returns the number of bits that are set to 1 in the mask.
Definition at line 432 of file doubleBitMask.I.
bool DoubleBitMask< BMType >::has_all_of | ( | int | low_bit, |
int | size | ||
) | const [inline] |
Returns true if all bits in the indicated range are set, false otherwise.
Definition at line 354 of file doubleBitMask.I.
bool DoubleBitMask< BMType >::has_any_of | ( | int | low_bit, |
int | size | ||
) | const [inline] |
Returns true if any bit in the indicated range is set, false otherwise.
Definition at line 333 of file doubleBitMask.I.
bool DoubleBitMask< BMType >::has_bits_in_common | ( | const DoubleBitMask< BMType > & | other | ) | const [inline] |
Returns true if this DoubleBitMask 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 580 of file doubleBitMask.I.
bool DoubleBitMask< BMType >::has_max_num_bits | ( | ) | [inline, 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 DoubleBitMask or BitArray interchangeably.
Definition at line 156 of file doubleBitMask.I.
void DoubleBitMask< BMType >::invert_in_place | ( | ) | [inline] |
Inverts all the bits in the DoubleBitMask.
This is equivalent to mask = ~mask.
Definition at line 562 of file doubleBitMask.I.
bool DoubleBitMask< BMType >::is_all_on | ( | ) | const [inline] |
Returns true if the entire doubleBitMask is one, false otherwise.
Definition at line 277 of file doubleBitMask.I.
bool DoubleBitMask< BMType >::is_zero | ( | ) | const [inline] |
Returns true if the entire doubleBitMask is zero, false otherwise.
Definition at line 265 of file doubleBitMask.I.
DoubleBitMask< BMType > DoubleBitMask< BMType >::lower_on | ( | int | on_bits | ) | [inline, static] |
Returns a DoubleBitMask whose lower on_bits bits are on.
Definition at line 89 of file doubleBitMask.I.
bool DoubleBitMask< BMType >::operator< | ( | const DoubleBitMask< BMType > & | other | ) | const [inline] |
The ordering operator is of limited usefulness with a DoubleBitMask, however, it has a definition which places all unique DoubleBitMasks into a unique ordering.
It may be useful when defining ordered STL containers of DoubleBitMasks, for instance; and it's required in order to export any STL container (ordered or unordered) of DoubleBitMask under Windows.
Definition at line 684 of file doubleBitMask.I.
void DoubleBitMask< BMType >::output | ( | ostream & | out | ) | const |
Writes the DoubleBitMask out as a binary or a hex number, according to the number of bits.
Definition at line 605 of file doubleBitMask.I.
void DoubleBitMask< BMType >::output_binary | ( | ostream & | out, |
int | spaces_every = 4 |
||
) | const |
Writes the DoubleBitMask out as a binary number, with spaces every four bits.
Definition at line 617 of file doubleBitMask.I.
void DoubleBitMask< BMType >::output_hex | ( | ostream & | out, |
int | spaces_every = 4 |
||
) | const |
Writes the DoubleBitMask out as a hexadecimal number, with spaces every four digits.
Definition at line 631 of file doubleBitMask.I.
DoubleBitMask< BMType > DoubleBitMask< BMType >::range | ( | int | low_bit, |
int | size | ||
) | [inline, static] |
Returns a DoubleBitMask whose size bits, beginning at low_bit, are on.
Definition at line 126 of file doubleBitMask.I.
References DoubleBitMask< BMType >::set_range().
void DoubleBitMask< BMType >::set_bit | ( | int | index | ) | [inline] |
Sets the nth bit on.
index must be in the range [0, num_bits).
Definition at line 216 of file doubleBitMask.I.
Referenced by DoubleBitMask< BMType >::bit().
void DoubleBitMask< BMType >::set_bit_to | ( | int | index, |
bool | value | ||
) | [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 249 of file doubleBitMask.I.
void DoubleBitMask< BMType >::set_range | ( | int | low_bit, |
int | size | ||
) | [inline] |
Sets the indicated range of bits on.
Definition at line 374 of file doubleBitMask.I.
Referenced by DoubleBitMask< BMType >::range().
void DoubleBitMask< BMType >::set_range_to | ( | bool | value, |
int | low_bit, | ||
int | size | ||
) | [inline] |
Sets the indicated range of bits to either on or off.
Definition at line 416 of file doubleBitMask.I.
void DoubleBitMask< BMType >::store | ( | WordType | value, |
int | low_bit, | ||
int | size | ||
) | [inline] |
Stores the indicated word into the indicated range of bits with this DoubleBitMask.
Definition at line 311 of file doubleBitMask.I.
void DoubleBitMask< BMType >::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.
Definition at line 645 of file doubleBitMask.I.