Panda3D
Public Types | Public Member Functions | Static Public Member Functions | List of all members
BitMask< WType, nbits > Class Template Reference

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. 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...
 
constexpr int get_num_bits () const
 Returns the number of bits available to set in the bitmask. 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)
 
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
 
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)
 
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)
 
void output (std::ostream &out) const
 Writes the BitMask out as a binary or a hex number, according to the number of bits. More...
 
void output_binary (std::ostream &out, int spaces_every=4) const
 Writes the BitMask out as a binary number, with spaces every four bits. More...
 
void output_hex (std::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 (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. 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 ()
 
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. More...
 
static BitMask< WType, nbits > range (int low_bit, int size)
 Returns a BitMask whose size bits, beginning at low_bit, are on. More...
 

Detailed Description

template<class WType, int nbits>
class BitMask< WType, nbits >

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.

Definition at line 32 of file bitMask.h.

Member Function Documentation

◆ __nonzero__()

template<class WType , int nbits>
bool BitMask< WType, nbits >::__nonzero__ ( ) const
inline

Returns true if the bitmask is not zero.

Definition at line 631 of file bitMask.I.

◆ all_off()

template<class WType , int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::all_off ( )
inlinestatic

Returns a BitMask whose bits are all off.

Definition at line 43 of file bitMask.I.

Referenced by BitMask< uint32_t, 32 >::keep_next_highest_bit(), and BitMask< uint32_t, 32 >::keep_next_lowest_bit().

◆ all_on()

template<class WType , int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::all_on ( )
inlinestatic

◆ bit()

template<class WType , int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::bit ( int  index)
inlinestatic

Returns a BitMask with only the indicated bit on.

Definition at line 70 of file bitMask.I.

Referenced by TagStateManager::get_mask(), BitMask< uint32_t, 32 >::keep_next_highest_bit(), and BitMask< uint32_t, 32 >::keep_next_lowest_bit().

◆ clear()

template<class WType , int nbits>
void BitMask< WType, nbits >::clear ( )
inline

◆ clear_bit()

template<class WType , int nbits>
void BitMask< WType, nbits >::clear_bit ( int  index)
inline

Sets the nth bit off.

index must be in the range [0, num_bits).

Definition at line 129 of file bitMask.I.

Referenced by RenderState::compare_mask(), RenderState::compare_to(), and GraphicsStateGuardian::do_issue_color().

◆ clear_range()

template<class WType , int nbits>
void BitMask< WType, nbits >::clear_range ( int  low_bit,
int  size 
)
inline

Sets the indicated range of bits off.

Definition at line 223 of file bitMask.I.

◆ compare_to()

template<class WType, int nbits>
int BitMask< WType, nbits >::compare_to ( const BitMask< WType, nbits > &  other) const
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 497 of file bitMask.I.

◆ extract()

template<class WType , int nbits>
BitMask< WType, nbits >::WordType BitMask< WType, nbits >::extract ( int  low_bit,
int  size 
) const
inline

Returns a word that represents only the indicated range of bits within this BitMask, shifted to the least-significant position.

Definition at line 172 of file bitMask.I.

◆ flood_bits_down()

template<class WType , int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::flood_bits_down ( ) const
inline

Returns a BitMask with the bits flooded down.

Definition at line 686 of file bitMask.I.

◆ flood_bits_up()

template<class WType , int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::flood_bits_up ( ) const
inline

Returns a BitMask with the bits flooded upwards.

Definition at line 676 of file bitMask.I.

◆ flood_down_in_place()

template<class WType , int nbits>
void BitMask< WType, nbits >::flood_down_in_place ( )
inline

Floods this bitmask's bits downwards.

Definition at line 667 of file bitMask.I.

◆ flood_up_in_place()

template<class WType , int nbits>
void BitMask< WType, nbits >::flood_up_in_place ( )
inline

Floods this bitmask's bits upwards.

Definition at line 658 of file bitMask.I.

◆ generate_hash()

template<class WType , int nbits>
void BitMask< WType, nbits >::generate_hash ( ChecksumHashGenerator hashgen) const
inline

Adds the bitmask to the indicated hash generator.

Definition at line 640 of file bitMask.I.

◆ get_bit()

template<class WType , int nbits>
bool BitMask< WType, nbits >::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 109 of file bitMask.I.

Referenced by GraphicsStateGuardian::get_supports_compressed_texture_format().

◆ get_highest_off_bit()

template<class WType , int nbits>
int BitMask< WType, nbits >::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 313 of file bitMask.I.

◆ get_highest_on_bit()

template<class WType , int nbits>
int BitMask< WType, nbits >::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 303 of file bitMask.I.

Referenced by BitMask< uint32_t, 32 >::keep_next_highest_bit().

◆ get_key()

template<class WType , int nbits>
int BitMask< WType, nbits >::get_key ( ) const
inline

Returns a mostly unique integer key per unique bitmask, suitable for using in a hash table.

Definition at line 622 of file bitMask.I.

◆ get_lowest_off_bit()

template<class WType , int nbits>
int BitMask< WType, nbits >::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 293 of file bitMask.I.

◆ get_lowest_on_bit()

template<class WType , int nbits>
int BitMask< WType, nbits >::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 283 of file bitMask.I.

Referenced by RenderState::compare_mask(), RenderState::compare_to(), and BitMask< uint32_t, 32 >::keep_next_lowest_bit().

◆ get_next_higher_different_bit()

template<class WType , int nbits>
int BitMask< WType, nbits >::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 326 of file bitMask.I.

◆ get_num_bits()

template<class WType , int nbits>
constexpr int BitMask< WType, nbits >::get_num_bits ( ) const

Returns the number of bits available to set in the bitmask.

Definition at line 99 of file bitMask.I.

◆ get_num_off_bits()

template<class WType , int nbits>
int BitMask< WType, nbits >::get_num_off_bits ( ) const
inline

Returns the number of bits that are set to 0 in the mask.

Definition at line 273 of file bitMask.I.

◆ get_num_on_bits()

template<class WType , int nbits>
int BitMask< WType, nbits >::get_num_on_bits ( ) const
inline

Returns the number of bits that are set to 1 in the mask.

Definition at line 264 of file bitMask.I.

Referenced by RenderState::write_datagram().

◆ get_word()

template<class WType , int nbits>
BitMask< WType, nbits >::WordType BitMask< WType, nbits >::get_word ( ) const
inline

Returns the entire BitMask as a single word.

Definition at line 246 of file bitMask.I.

Referenced by Camera::write_datagram().

◆ has_all_of()

template<class WType , int nbits>
bool BitMask< WType, nbits >::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 203 of file bitMask.I.

◆ has_any_of()

template<class WType , int nbits>
bool BitMask< WType, nbits >::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 193 of file bitMask.I.

◆ has_bits_in_common()

template<class WType, int nbits>
bool BitMask< WType, nbits >::has_bits_in_common ( const BitMask< WType, nbits > &  other) const
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 386 of file bitMask.I.

◆ invert_in_place()

template<class WType , int nbits>
void BitMask< WType, nbits >::invert_in_place ( )
inline

Inverts all the bits in the BitMask.

This is equivalent to mask = ~mask.

Definition at line 372 of file bitMask.I.

◆ is_all_on()

template<class WType , int nbits>
bool BitMask< WType, nbits >::is_all_on ( ) const
inline

Returns true if the entire bitmask is one, false otherwise.

Definition at line 162 of file bitMask.I.

◆ is_zero()

template<class WType , int nbits>
bool BitMask< WType, nbits >::is_zero ( ) const
inline

Returns true if the entire bitmask is zero, false otherwise.

Definition at line 153 of file bitMask.I.

Referenced by RenderState::is_empty().

◆ keep_next_highest_bit() [1/3]

template<class WType , int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::keep_next_highest_bit ( ) const
inline

Returns a BitMask with only the next highest bit above the indicated bit on, or all_off.

Definition at line 698 of file bitMask.I.

◆ keep_next_highest_bit() [2/3]

template<class WType , int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::keep_next_highest_bit ( int  index) const
inline

Returns a BitMask with only the next highest bit above the indicated bit on, or all.

Definition at line 728 of file bitMask.I.

◆ keep_next_highest_bit() [3/3]

template<class WType, int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::keep_next_highest_bit ( const BitMask< WType, nbits > &  other) const
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 777 of file bitMask.I.

◆ keep_next_lowest_bit() [1/3]

template<class WType , int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::keep_next_lowest_bit ( ) const
inline

Returns a BitMask with only the next lower bit below the indicated bit on, or all_off.

Definition at line 713 of file bitMask.I.

◆ keep_next_lowest_bit() [2/3]

template<class WType , int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::keep_next_lowest_bit ( int  index) const
inline

Returns a BitMask with only the next lower bit below the indicated bit on, or all_off.

Definition at line 752 of file bitMask.I.

◆ keep_next_lowest_bit() [3/3]

template<class WType, int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::keep_next_lowest_bit ( const BitMask< WType, nbits > &  other) const
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 793 of file bitMask.I.

◆ lower_on()

template<class WType , int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::lower_on ( int  on_bits)
inlinestatic

Returns a BitMask whose lower on_bits bits are on.

Definition at line 54 of file bitMask.I.

Referenced by BitMask< uint32_t, 32 >::extract().

◆ operator<()

template<class WType, int nbits>
bool BitMask< WType, nbits >::operator< ( const BitMask< WType, nbits > &  other) const
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 486 of file bitMask.I.

◆ output()

template<class WType , int nbits>
void BitMask< WType, nbits >::output ( std::ostream &  out) const

Writes the BitMask out as a binary or a hex number, according to the number of bits.

Definition at line 405 of file bitMask.I.

◆ output_binary()

template<class WType , int nbits>
void BitMask< WType, nbits >::output_binary ( std::ostream &  out,
int  spaces_every = 4 
) const

Writes the BitMask out as a binary number, with spaces every four bits.

Definition at line 418 of file bitMask.I.

◆ output_hex()

template<class WType , int nbits>
void BitMask< WType, nbits >::output_hex ( std::ostream &  out,
int  spaces_every = 4 
) const

Writes the BitMask out as a hexadecimal number, with spaces every four digits.

Definition at line 433 of file bitMask.I.

◆ range()

template<class WType , int nbits>
BitMask< WType, nbits > BitMask< WType, nbits >::range ( int  low_bit,
int  size 
)
inlinestatic

◆ set_bit()

template<class WType , int nbits>
void BitMask< WType, nbits >::set_bit ( int  index)
inline

Sets the nth bit on.

index must be in the range [0, num_bits).

Definition at line 119 of file bitMask.I.

Referenced by BitMask< uint32_t, 32 >::bit(), and CPT().

◆ set_bit_to()

template<class WType , int nbits>
void BitMask< WType, nbits >::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 140 of file bitMask.I.

◆ set_range()

template<class WType , int nbits>
void BitMask< WType, nbits >::set_range ( int  low_bit,
int  size 
)
inline

Sets the indicated range of bits on.

Definition at line 213 of file bitMask.I.

◆ set_range_to()

template<class WType , int nbits>
void BitMask< WType, nbits >::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 233 of file bitMask.I.

◆ set_word()

template<class WType , int nbits>
void BitMask< WType, nbits >::set_word ( WordType  value)
inline

Sets the entire BitMask to the value indicated by the given word.

Definition at line 255 of file bitMask.I.

◆ store()

template<class WType , int nbits>
void BitMask< WType, nbits >::store ( WordType  value,
int  low_bit,
int  size 
)
inline

Stores the indicated word into the indicated range of bits with this BitMask.

Definition at line 183 of file bitMask.I.

◆ write()

template<class WType , int nbits>
void BitMask< WType, nbits >::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.

Definition at line 455 of file bitMask.I.


The documentation for this class was generated from the following files: