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

Public Member Functions

 DoubleBitMask (const DoubleBitMask< BMType > &copy)
 
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...
 
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)
 
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)
 
DoubleBitMask< BMType > & operator= (const DoubleBitMask< BMType > &copy)
 
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. More...
 
void output_binary (ostream &out, int spaces_every=4) const
 Writes the DoubleBitMask out as a binary number, with spaces every four bits. More...
 
void output_hex (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 (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 ()
 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 doubleBitMask. 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 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 32 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 75 of file doubleBitMask.I.

References DoubleBitMask< BMType >::lower_on().

Referenced by DoubleBitMask< BMType >::all_on(), and DoubleBitMask< BMType >::lower_on().

◆ all_on()

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

Returns a DoubleBitMask whose bits are all on.

Definition at line 61 of file doubleBitMask.I.

References DoubleBitMask< BMType >::all_off().

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

◆ bit()

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

Returns a DoubleBitMask with only the indicated bit on.

Definition at line 112 of file doubleBitMask.I.

References DoubleBitMask< BMType >::range(), and DoubleBitMask< BMType >::set_bit().

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

◆ clear()

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

Sets all the bits in the DoubleBitMask off.

Definition at line 592 of file doubleBitMask.I.

References DoubleBitMask< BMType >::output().

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

◆ 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 232 of file doubleBitMask.I.

References DoubleBitMask< BMType >::set_bit_to().

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

◆ 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 395 of file doubleBitMask.I.

References DoubleBitMask< BMType >::set_range_to().

Referenced by DoubleBitMask< BMType >::set_range(), and DoubleBitMask< BMType >::set_range_to().

◆ 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 702 of file doubleBitMask.I.

References DoubleBitMask< BMType >::generate_hash(), and DoubleBitMask< BMType >::invert_in_place().

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

◆ 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 290 of file doubleBitMask.I.

References DoubleBitMask< BMType >::store().

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

◆ 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 855 of file doubleBitMask.I.

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

◆ 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 200 of file doubleBitMask.I.

References DoubleBitMask< BMType >::set_bit().

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

◆ 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 512 of file doubleBitMask.I.

References DoubleBitMask< BMType >::get_next_higher_different_bit().

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

◆ 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 494 of file doubleBitMask.I.

References DoubleBitMask< BMType >::get_highest_off_bit().

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

◆ 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 475 of file doubleBitMask.I.

References DoubleBitMask< BMType >::get_highest_on_bit().

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

◆ 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 456 of file doubleBitMask.I.

References DoubleBitMask< BMType >::get_lowest_off_bit().

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

◆ get_max_num_bits()

template<class BMType >
CONSTEXPR int DoubleBitMask< BMType >::get_max_num_bits ( )
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.

References DoubleBitMask< BMType >::get_num_bits().

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

◆ 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 535 of file doubleBitMask.I.

References DoubleBitMask< BMType >::invert_in_place().

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

◆ get_num_bits()

template<class BMType >
CONSTEXPR int DoubleBitMask< BMType >::get_num_bits ( )
static

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

Definition at line 187 of file doubleBitMask.I.

References DoubleBitMask< BMType >::get_bit().

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

◆ 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 444 of file doubleBitMask.I.

References DoubleBitMask< BMType >::get_lowest_on_bit().

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

◆ 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 432 of file doubleBitMask.I.

References DoubleBitMask< BMType >::get_num_off_bits().

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

◆ 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 354 of file doubleBitMask.I.

References DoubleBitMask< BMType >::set_range().

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

◆ 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 333 of file doubleBitMask.I.

References DoubleBitMask< BMType >::has_all_of().

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

◆ 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 580 of file doubleBitMask.I.

References DoubleBitMask< BMType >::clear().

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

◆ has_max_num_bits()

template<class BMType >
CONSTEXPR bool DoubleBitMask< BMType >::has_max_num_bits ( )
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.

References DoubleBitMask< BMType >::get_max_num_bits().

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

◆ 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 562 of file doubleBitMask.I.

References DoubleBitMask< BMType >::has_bits_in_common().

Referenced by DoubleBitMask< BMType >::compare_to(), and DoubleBitMask< BMType >::get_next_higher_different_bit().

◆ 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 277 of file doubleBitMask.I.

References DoubleBitMask< BMType >::extract().

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

◆ 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 265 of file doubleBitMask.I.

References DoubleBitMask< BMType >::is_all_on().

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

◆ 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 89 of file doubleBitMask.I.

References DoubleBitMask< BMType >::all_off(), DoubleBitMask< BMType >::all_on(), and DoubleBitMask< BMType >::bit().

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

◆ 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 684 of file doubleBitMask.I.

References DoubleBitMask< BMType >::compare_to().

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

◆ output()

template<class BMType >
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.

References DoubleBitMask< BMType >::output_binary(), and DoubleBitMask< BMType >::output_hex().

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

◆ output_binary()

template<class BMType >
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.

References DoubleBitMask< BMType >::output_hex().

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

◆ output_hex()

template<class BMType >
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.

References DoubleBitMask< BMType >::write().

Referenced by DoubleBitMask< BMType >::output(), and DoubleBitMask< BMType >::output_binary().

◆ 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 126 of file doubleBitMask.I.

References DoubleBitMask< BMType >::has_max_num_bits(), and DoubleBitMask< BMType >::set_range().

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

◆ 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 216 of file doubleBitMask.I.

References DoubleBitMask< BMType >::clear_bit().

Referenced by DoubleBitMask< BMType >::bit(), and DoubleBitMask< BMType >::get_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 249 of file doubleBitMask.I.

References DoubleBitMask< BMType >::is_zero().

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

◆ set_range()

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

◆ 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 416 of file doubleBitMask.I.

References DoubleBitMask< BMType >::clear_range(), DoubleBitMask< BMType >::get_num_on_bits(), and DoubleBitMask< BMType >::set_range().

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

◆ 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 311 of file doubleBitMask.I.

References DoubleBitMask< BMType >::has_any_of().

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

◆ write()

template<class BMType >
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.

References DoubleBitMask< BMType >::operator<().

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


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