add BitMask::range()

This commit is contained in:
David Rose 2005-01-24 18:56:46 +00:00
parent bcc386430d
commit 7d3fa1b266
2 changed files with 22 additions and 0 deletions

View File

@ -123,6 +123,27 @@ bit(int index) {
return result; return result;
} }
////////////////////////////////////////////////////////////////////
// Function: BitMask::Named range constructor
// Access: Published, Static
// Description: Returns a BitMask whose size bits, beginning at
// low_bit, are on.
////////////////////////////////////////////////////////////////////
template<class WordType, int num_bits>
INLINE BitMask<WordType, num_bits> BitMask<WordType, num_bits>::
range(int low_bit, int size) {
BitMask result;
if (size <= 0) {
result._word = 0;
} else if (size >= num_bits) {
result._word = ~0;
} else {
result._word = ((WordType)1 << size) - 1;
}
result._word <<= low_bit;
return result;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: BitMask::Destructor // Function: BitMask::Destructor
// Access: Published // Access: Published

View File

@ -46,6 +46,7 @@ PUBLISHED:
INLINE static BitMask<WordType, num_bits> all_off(); INLINE static BitMask<WordType, num_bits> all_off();
INLINE static BitMask<WordType, num_bits> lower_on(int on_bits); INLINE static BitMask<WordType, num_bits> lower_on(int on_bits);
INLINE static BitMask<WordType, num_bits> bit(int index); INLINE static BitMask<WordType, num_bits> bit(int index);
INLINE static BitMask<WordType, num_bits> range(int low_bit, int size);
INLINE ~BitMask(); INLINE ~BitMask();