Panda3D
Public Types | Public Member Functions | Static Public Member Functions | List of all members
DoubleBitMask< BMType > Class Template Reference

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 = BMType::num_bits, num_bits = BMType::num_bits * 2 }
 
typedef BMType BitMaskType
 
typedef BMType::WordType WordType
 

Public Member Functions

void clear ()
 Sets all the bits in the DoubleBitMask 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 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. More...
 
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. More...
 
void generate_hash (ChecksumHashGenerator &hashgen) const
 Adds the doubleBitMask 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_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 doubleBitMask. 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...
 
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 DoubleBitMask< BMType > &other) const
 Returns true if this DoubleBitMask has any "one" bits in common with the other one, false otherwise. More...
 
void invert_in_place ()
 Inverts all the bits in the DoubleBitMask. More...
 
bool is_all_on () const
 Returns true if the entire doubleBitMask is one, false otherwise. More...
 
bool is_zero () const
 Returns true if the entire doubleBitMask is zero, false otherwise. More...
 
bool operator != (const DoubleBitMask< BMType > &other) const
 
DoubleBitMask< BMType > operator & (const DoubleBitMask< BMType > &other) const
 
void operator &= (const DoubleBitMask< BMType > &other)
 
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
 
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. More...
 
DoubleBitMask< BMType > operator<< (int shift) const
 
void operator<<= (int shift)
 
bool operator== (const DoubleBitMask< BMType > &other) const
 
DoubleBitMask< BMType > operator| (const DoubleBitMask< BMType > &other) const
 
void operator|= (const DoubleBitMask< BMType > &other)
 
void output (std::ostream &out) const
 Writes the DoubleBitMask 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 DoubleBitMask out as a binary number, with spaces every four bits. More...
 
void output_hex (std::ostream &out, int spaces_every=4) const
 Writes the DoubleBitMask 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 store (WordType value, int low_bit, int size)
 Stores the indicated word into the indicated range of bits with this DoubleBitMask. More...
 
void write (std::ostream &out, int indent_level=0) const
 Writes the DoubleBitMask out as a binary or a hex number, according to the number of bits. More...
 

Static Public Member Functions

static DoubleBitMask< BMType > all_off ()
 Returns a DoubleBitMask whose bits are all off. More...
 
static DoubleBitMask< BMType > all_on ()
 Returns a DoubleBitMask whose bits are all on. More...
 
static DoubleBitMask< BMType > bit (int index)
 Returns a DoubleBitMask 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 ()
 
static DoubleBitMask< BMType > lower_on (int on_bits)
 Returns a DoubleBitMask whose lower on_bits bits are on. More...
 
static DoubleBitMask< BMType > range (int low_bit, int size)
 Returns a DoubleBitMask whose size bits, beginning at low_bit, are on. More...
 

Detailed Description

template<class BMType>
class DoubleBitMask< BMType >

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 28 of file doubleBitMask.h.

Member Function Documentation

◆ all_off()

template<class BMType >
DoubleBitMask< BMType > DoubleBitMask< BMType >::all_off ( )
inlinestatic

Returns a DoubleBitMask whose bits are all off.

Definition at line 34 of file doubleBitMask.I.

◆ all_on()

template<class BMType >
DoubleBitMask< BMType > DoubleBitMask< BMType >::all_on ( )
inlinestatic

Returns a DoubleBitMask whose bits are all on.

Definition at line 22 of file doubleBitMask.I.

◆ bit()

template<class BMType >
DoubleBitMask< BMType > DoubleBitMask< BMType >::bit ( int  index)
inlinestatic

Returns a DoubleBitMask with only the indicated bit on.

Definition at line 67 of file doubleBitMask.I.

References DoubleBitMask< BMType >::set_bit().

◆ clear()

template<class BMType >
void DoubleBitMask< BMType >::clear ( )
inline

Sets all the bits in the DoubleBitMask off.

Definition at line 434 of file doubleBitMask.I.

◆ clear_bit()

template<class BMType >
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 125 of file doubleBitMask.I.

◆ clear_range()

template<class BMType >
void DoubleBitMask< BMType >::clear_range ( int  low_bit,
int  size 
)
inline

Sets the indicated range of bits off.

Definition at line 264 of file doubleBitMask.I.

◆ compare_to()

template<class BMType>
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 526 of file doubleBitMask.I.

◆ extract()

template<class BMType >
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 171 of file doubleBitMask.I.

◆ generate_hash()

template<class BMType >
void DoubleBitMask< BMType >::generate_hash ( ChecksumHashGenerator hashgen) const
inline

Adds the doubleBitMask to the indicated hash generator.

Definition at line 655 of file doubleBitMask.I.

◆ get_bit()

template<class BMType >
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 99 of file doubleBitMask.I.

◆ get_highest_off_bit()

template<class BMType >
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 365 of file doubleBitMask.I.

◆ get_highest_on_bit()

template<class BMType >
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 349 of file doubleBitMask.I.

◆ get_lowest_off_bit()

template<class BMType >
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 332 of file doubleBitMask.I.

◆ get_lowest_on_bit()

template<class BMType >
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 315 of file doubleBitMask.I.

◆ get_next_higher_different_bit()

template<class BMType >
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 384 of file doubleBitMask.I.

◆ get_num_bits()

template<class BMType >
constexpr int DoubleBitMask< BMType >::get_num_bits ( ) const

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

Definition at line 89 of file doubleBitMask.I.

◆ get_num_off_bits()

template<class BMType >
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 305 of file doubleBitMask.I.

◆ get_num_on_bits()

template<class BMType >
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 296 of file doubleBitMask.I.

◆ has_all_of()

template<class BMType >
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 227 of file doubleBitMask.I.

◆ has_any_of()

template<class BMType >
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 209 of file doubleBitMask.I.

◆ has_bits_in_common()

template<class BMType>
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 424 of file doubleBitMask.I.

◆ invert_in_place()

template<class BMType >
void DoubleBitMask< BMType >::invert_in_place ( )
inline

Inverts all the bits in the DoubleBitMask.

This is equivalent to mask = ~mask.

Definition at line 409 of file doubleBitMask.I.

◆ is_all_on()

template<class BMType >
bool DoubleBitMask< BMType >::is_all_on ( ) const
inline

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

Definition at line 161 of file doubleBitMask.I.

◆ is_zero()

template<class BMType >
bool DoubleBitMask< BMType >::is_zero ( ) const
inline

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

Definition at line 152 of file doubleBitMask.I.

◆ lower_on()

template<class BMType >
DoubleBitMask< BMType > DoubleBitMask< BMType >::lower_on ( int  on_bits)
inlinestatic

Returns a DoubleBitMask whose lower on_bits bits are on.

Definition at line 46 of file doubleBitMask.I.

◆ operator<()

template<class BMType>
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 510 of file doubleBitMask.I.

◆ output()

template<class BMType >
void DoubleBitMask< BMType >::output ( std::ostream &  out) const

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

Definition at line 445 of file doubleBitMask.I.

◆ output_binary()

template<class BMType >
void DoubleBitMask< BMType >::output_binary ( std::ostream &  out,
int  spaces_every = 4 
) const

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

Definition at line 455 of file doubleBitMask.I.

◆ output_hex()

template<class BMType >
void DoubleBitMask< BMType >::output_hex ( std::ostream &  out,
int  spaces_every = 4 
) const

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

Definition at line 467 of file doubleBitMask.I.

◆ range()

template<class BMType >
DoubleBitMask< BMType > DoubleBitMask< BMType >::range ( int  low_bit,
int  size 
)
inlinestatic

Returns a DoubleBitMask whose size bits, beginning at low_bit, are on.

Definition at line 78 of file doubleBitMask.I.

References DoubleBitMask< BMType >::set_range().

◆ set_bit()

template<class BMType >
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 112 of file doubleBitMask.I.

Referenced by DoubleBitMask< BMType >::bit().

◆ set_bit_to()

template<class BMType >
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 139 of file doubleBitMask.I.

◆ set_range()

template<class BMType >
void DoubleBitMask< BMType >::set_range ( int  low_bit,
int  size 
)
inline

Sets the indicated range of bits on.

Definition at line 245 of file doubleBitMask.I.

Referenced by DoubleBitMask< BMType >::range().

◆ set_range_to()

template<class BMType >
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 283 of file doubleBitMask.I.

◆ store()

template<class BMType >
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 190 of file doubleBitMask.I.

◆ write()

template<class BMType >
void DoubleBitMask< BMType >::write ( std::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 479 of file doubleBitMask.I.

References indent().


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