|
|
@@ -16,16 +16,16 @@
|
|
|
//
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-template<class WordType, int num_bits>
|
|
|
-TypeHandle BitMask<WordType, num_bits>::_type_handle;
|
|
|
+template<class WType, int nbits>
|
|
|
+TypeHandle BitMask<WType, nbits>::_type_handle;
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: BitMask::Constructor
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits>::
|
|
|
BitMask() :
|
|
|
_word(0)
|
|
|
{
|
|
|
@@ -36,8 +36,8 @@ BitMask() :
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits>::
|
|
|
BitMask(WordType init_value) :
|
|
|
_word(init_value)
|
|
|
{
|
|
|
@@ -48,9 +48,9 @@ BitMask(WordType init_value) :
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits>::
|
|
|
-BitMask(const BitMask<WordType, num_bits> ©) :
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits>::
|
|
|
+BitMask(const BitMask<WType, nbits> ©) :
|
|
|
_word(copy._word)
|
|
|
{
|
|
|
}
|
|
|
@@ -60,9 +60,9 @@ BitMask(const BitMask<WordType, num_bits> ©) :
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
-operator = (const BitMask<WordType, num_bits> ©) {
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
+operator = (const BitMask<WType, nbits> ©) {
|
|
|
_word = copy._word;
|
|
|
}
|
|
|
|
|
|
@@ -71,8 +71,8 @@ operator = (const BitMask<WordType, num_bits> ©) {
|
|
|
// Access: Published, Static
|
|
|
// Description: Returns a BitMask whose bits are all on.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits> BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits> BitMask<WType, nbits>::
|
|
|
all_on() {
|
|
|
BitMask result;
|
|
|
result._word = ~0;
|
|
|
@@ -84,8 +84,8 @@ all_on() {
|
|
|
// Access: Published, Static
|
|
|
// Description: Returns a BitMask whose bits are all off.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits> BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits> BitMask<WType, nbits>::
|
|
|
all_off() {
|
|
|
BitMask result;
|
|
|
result._word = 0;
|
|
|
@@ -95,10 +95,10 @@ all_off() {
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: BitMask::Named lower_on constructor
|
|
|
// Access: Published, Static
|
|
|
-// Description: Returns a BitMask whose lower num_bits bits are on.
|
|
|
+// Description: Returns a BitMask whose lower on_bits bits are on.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits> BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits> BitMask<WType, nbits>::
|
|
|
lower_on(int on_bits) {
|
|
|
if (on_bits <= 0) {
|
|
|
return all_off();
|
|
|
@@ -115,8 +115,8 @@ lower_on(int on_bits) {
|
|
|
// Access: Published, Static
|
|
|
// Description: Returns a BitMask with only the indicated bit on.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits> BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits> BitMask<WType, nbits>::
|
|
|
bit(int index) {
|
|
|
BitMask result;
|
|
|
result.set_bit(index);
|
|
|
@@ -129,8 +129,8 @@ bit(int index) {
|
|
|
// 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>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits> BitMask<WType, nbits>::
|
|
|
range(int low_bit, int size) {
|
|
|
BitMask result;
|
|
|
if (size <= 0) {
|
|
|
@@ -149,19 +149,56 @@ range(int low_bit, int size) {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits>::
|
|
|
~BitMask() {
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: BitMask::has_max_num_bits
|
|
|
+// Access: Published, Static
|
|
|
+// Description: 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
|
|
|
+// BitMask or BitArray interchangeably.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE bool BitMask<WType, nbits>::
|
|
|
+has_max_num_bits() {
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: BitMask::get_max_num_bits
|
|
|
+// Access: Published, Static
|
|
|
+// Description: 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 BitMask or BitArray interchangeably.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE int BitMask<WType, nbits>::
|
|
|
+get_max_num_bits() {
|
|
|
+ return num_bits;
|
|
|
+}
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: BitMask::get_num_bits
|
|
|
// Access: Published, Static
|
|
|
// Description: Returns the number of bits available to set in the
|
|
|
// bitmask.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE int BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE int BitMask<WType, nbits>::
|
|
|
get_num_bits() {
|
|
|
return num_bits;
|
|
|
}
|
|
|
@@ -171,10 +208,10 @@ get_num_bits() {
|
|
|
// Access: Published
|
|
|
// Description: Returns true if the nth bit is set, false if it is
|
|
|
// cleared. index must be in the range [0,
|
|
|
-// get_num_bits).
|
|
|
+// num_bits).
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE bool BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE bool BitMask<WType, nbits>::
|
|
|
get_bit(int index) const {
|
|
|
nassertr(index >= 0 && index < num_bits, false);
|
|
|
return (_word & ((WordType)1 << index)) != 0;
|
|
|
@@ -184,10 +221,10 @@ get_bit(int index) const {
|
|
|
// Function: BitMask::set_bit
|
|
|
// Access: Published
|
|
|
// Description: Sets the nth bit on. index must be in the range
|
|
|
-// [0, get_num_bits).
|
|
|
+// [0, num_bits).
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
set_bit(int index) {
|
|
|
nassertv(index >= 0 && index < num_bits);
|
|
|
_word |= ((WordType)1 << index);
|
|
|
@@ -197,10 +234,10 @@ set_bit(int index) {
|
|
|
// Function: BitMask::clear_bit
|
|
|
// Access: Published
|
|
|
// Description: Sets the nth bit off. index must be in the range
|
|
|
-// [0, get_num_bits).
|
|
|
+// [0, num_bits).
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
clear_bit(int index) {
|
|
|
nassertv(index >= 0 && index < num_bits);
|
|
|
_word &= ~((WordType)1 << index);
|
|
|
@@ -211,10 +248,10 @@ clear_bit(int index) {
|
|
|
// Access: Published
|
|
|
// Description: Sets the nth bit either on or off, according to the
|
|
|
// indicated bool value. index must be in the range [0,
|
|
|
-// get_num_bits).
|
|
|
+// num_bits).
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
set_bit_to(int index, bool value) {
|
|
|
if (value) {
|
|
|
set_bit(index);
|
|
|
@@ -229,8 +266,8 @@ set_bit_to(int index, bool value) {
|
|
|
// Description: Returns true if the entire bitmask is zero, false
|
|
|
// otherwise.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE bool BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE bool BitMask<WType, nbits>::
|
|
|
is_zero() const {
|
|
|
return (_word == 0);
|
|
|
}
|
|
|
@@ -242,11 +279,11 @@ is_zero() const {
|
|
|
// range of bits within this BitMask, shifted to the
|
|
|
// least-significant position.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE WordType BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE TYPENAME BitMask<WType, nbits>::WordType BitMask<WType, nbits>::
|
|
|
extract(int low_bit, int size) const {
|
|
|
return (_word >> low_bit) &
|
|
|
- BitMask<WordType, num_bits>::lower_on(size)._word;
|
|
|
+ BitMask<WType, nbits>::lower_on(size)._word;
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
@@ -255,21 +292,59 @@ extract(int low_bit, int size) const {
|
|
|
// Description: Stores the indicated word into the indicated range of
|
|
|
// bits with this BitMask.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
store(WordType value, int low_bit, int size) {
|
|
|
- WordType mask =
|
|
|
- BitMask<WordType, num_bits>::lower_on(size)._word << low_bit;
|
|
|
+ WordType mask = BitMask<WType, nbits>::range(low_bit, size)._word;
|
|
|
_word = (_word & ~mask) | ((value << low_bit) & mask);
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: BitMask::set_range
|
|
|
+// Access: Published
|
|
|
+// Description: Sets the indicated range of bits on.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
+set_range(int low_bit, int size) {
|
|
|
+ WordType mask = BitMask<WType, nbits>::range(low_bit, size)._word;
|
|
|
+ _word |= mask;
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: BitMask::clear_range
|
|
|
+// Access: Published
|
|
|
+// Description: Sets the indicated range of bits off.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
+clear_range(int low_bit, int size) {
|
|
|
+ WordType mask = BitMask<WType, nbits>::range(low_bit, size)._word;
|
|
|
+ _word &= ~mask;
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: BitMask::set_range_to
|
|
|
+// Access: Published
|
|
|
+// Description: Sets the indicated range of bits to either on or off.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
+set_range_to(bool value, int low_bit, int size) {
|
|
|
+ if (value) {
|
|
|
+ set_range(low_bit, size);
|
|
|
+ } else {
|
|
|
+ clear_range(low_bit, size);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: BitMask::get_word
|
|
|
// Access: Published
|
|
|
// Description: Returns the entire BitMask as a single word.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE WordType BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE TYPENAME BitMask<WType, nbits>::WordType BitMask<WType, nbits>::
|
|
|
get_word() const {
|
|
|
return _word;
|
|
|
}
|
|
|
@@ -280,8 +355,8 @@ get_word() const {
|
|
|
// Description: Sets the entire BitMask to the value indicated by the
|
|
|
// given word.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
set_word(WordType value) {
|
|
|
_word = value;
|
|
|
}
|
|
|
@@ -289,21 +364,39 @@ set_word(WordType value) {
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: BitMask::invert_in_place
|
|
|
// Access: Published
|
|
|
-// Description: Inverts all the bits in the BitMask.
|
|
|
+// Description: Inverts all the bits in the BitMask. This is
|
|
|
+// equivalent to mask = ~mask.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
invert_in_place() {
|
|
|
_word = ~_word;
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: BitMask::has_bits_in_common
|
|
|
+// Access: Published
|
|
|
+// Description: 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).
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE bool BitMask<WType, nbits>::
|
|
|
+has_bits_in_common(const BitMask<WType, nbits> &other) const {
|
|
|
+ return (_word & other._word) != 0;
|
|
|
+}
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: BitMask::clear
|
|
|
// Access: Published
|
|
|
// Description: Sets all the bits in the BitMask off.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
clear() {
|
|
|
_word = 0;
|
|
|
}
|
|
|
@@ -314,8 +407,8 @@ clear() {
|
|
|
// Description: Writes the BitMask out as a binary or a hex number,
|
|
|
// according to the number of bits.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+void BitMask<WType, nbits>::
|
|
|
output(ostream &out) const {
|
|
|
if (num_bits >= 40) {
|
|
|
output_hex(out);
|
|
|
@@ -330,8 +423,8 @@ output(ostream &out) const {
|
|
|
// Description: Writes the BitMask out as a binary number, with
|
|
|
// spaces every four bits.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+void BitMask<WType, nbits>::
|
|
|
output_binary(ostream &out, int spaces_every) const {
|
|
|
for (int i = num_bits - 1; i >= 0; i--) {
|
|
|
if (spaces_every != 0 && ((i % spaces_every) == spaces_every - 1)) {
|
|
|
@@ -347,8 +440,8 @@ output_binary(ostream &out, int spaces_every) const {
|
|
|
// Description: Writes the BitMask out as a hexadecimal number, with
|
|
|
// spaces every four digits.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+void BitMask<WType, nbits>::
|
|
|
output_hex(ostream &out, int spaces_every) const {
|
|
|
int num_digits = (num_bits + 3) / 4;
|
|
|
|
|
|
@@ -371,8 +464,8 @@ output_hex(ostream &out, int spaces_every) const {
|
|
|
// Description: Writes the BitMask out as a binary or a hex number,
|
|
|
// according to the number of bits.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+void BitMask<WType, nbits>::
|
|
|
write(ostream &out, int indent_level) const {
|
|
|
indent(out, indent_level) << *this << "\n";
|
|
|
}
|
|
|
@@ -382,9 +475,9 @@ write(ostream &out, int indent_level) const {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE bool BitMask<WordType, num_bits>::
|
|
|
-operator == (const BitMask<WordType, num_bits> &other) const {
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE bool BitMask<WType, nbits>::
|
|
|
+operator == (const BitMask<WType, nbits> &other) const {
|
|
|
return _word == other._word;
|
|
|
}
|
|
|
|
|
|
@@ -393,9 +486,9 @@ operator == (const BitMask<WordType, num_bits> &other) const {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE bool BitMask<WordType, num_bits>::
|
|
|
-operator != (const BitMask<WordType, num_bits> &other) const {
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE bool BitMask<WType, nbits>::
|
|
|
+operator != (const BitMask<WType, nbits> &other) const {
|
|
|
return _word != other._word;
|
|
|
}
|
|
|
|
|
|
@@ -410,9 +503,9 @@ operator != (const BitMask<WordType, num_bits> &other) const {
|
|
|
// export any STL container (ordered or unordered) of
|
|
|
// BitMask under Windows.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE bool BitMask<WordType, num_bits>::
|
|
|
-operator < (const BitMask<WordType, num_bits> &other) const {
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE bool BitMask<WType, nbits>::
|
|
|
+operator < (const BitMask<WType, nbits> &other) const {
|
|
|
return _word < other._word;
|
|
|
}
|
|
|
|
|
|
@@ -424,9 +517,9 @@ operator < (const BitMask<WordType, num_bits> &other) const {
|
|
|
// if it sorts after, or 0 if they are equivalent. This
|
|
|
// is based on the same ordering defined by operator <.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE int BitMask<WordType, num_bits>::
|
|
|
-compare_to(const BitMask<WordType, num_bits> &other) const {
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE int BitMask<WType, nbits>::
|
|
|
+compare_to(const BitMask<WType, nbits> &other) const {
|
|
|
if ((*this) < other) {
|
|
|
return -1;
|
|
|
} else if (other < (*this)) {
|
|
|
@@ -441,10 +534,10 @@ compare_to(const BitMask<WordType, num_bits> &other) const {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits> BitMask<WordType, num_bits>::
|
|
|
-operator & (const BitMask<WordType, num_bits> &other) const {
|
|
|
- BitMask<WordType, num_bits> result(*this);
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits> BitMask<WType, nbits>::
|
|
|
+operator & (const BitMask<WType, nbits> &other) const {
|
|
|
+ BitMask<WType, nbits> result(*this);
|
|
|
result &= other;
|
|
|
return result;
|
|
|
}
|
|
|
@@ -454,10 +547,10 @@ operator & (const BitMask<WordType, num_bits> &other) const {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits> BitMask<WordType, num_bits>::
|
|
|
-operator | (const BitMask<WordType, num_bits> &other) const {
|
|
|
- BitMask<WordType, num_bits> result(*this);
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits> BitMask<WType, nbits>::
|
|
|
+operator | (const BitMask<WType, nbits> &other) const {
|
|
|
+ BitMask<WType, nbits> result(*this);
|
|
|
result |= other;
|
|
|
return result;
|
|
|
}
|
|
|
@@ -467,10 +560,10 @@ operator | (const BitMask<WordType, num_bits> &other) const {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits> BitMask<WordType, num_bits>::
|
|
|
-operator ^ (const BitMask<WordType, num_bits> &other) const {
|
|
|
- BitMask<WordType, num_bits> result(*this);
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits> BitMask<WType, nbits>::
|
|
|
+operator ^ (const BitMask<WType, nbits> &other) const {
|
|
|
+ BitMask<WType, nbits> result(*this);
|
|
|
result ^= other;
|
|
|
return result;
|
|
|
}
|
|
|
@@ -480,12 +573,10 @@ operator ^ (const BitMask<WordType, num_bits> &other) const {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits> BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits> BitMask<WType, nbits>::
|
|
|
operator ~ () const {
|
|
|
- BitMask<WordType, num_bits> result(*this);
|
|
|
- result._word = ~result._word;
|
|
|
- return result;
|
|
|
+ return BitMask<WType, nbits>(~_word);
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
@@ -493,10 +584,10 @@ operator ~ () const {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits> BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits> BitMask<WType, nbits>::
|
|
|
operator << (int shift) const {
|
|
|
- BitMask<WordType, num_bits> result(*this);
|
|
|
+ BitMask<WType, nbits> result(*this);
|
|
|
result <<= shift;
|
|
|
return result;
|
|
|
}
|
|
|
@@ -506,10 +597,10 @@ operator << (int shift) const {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE BitMask<WordType, num_bits> BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE BitMask<WType, nbits> BitMask<WType, nbits>::
|
|
|
operator >> (int shift) const {
|
|
|
- BitMask<WordType, num_bits> result(*this);
|
|
|
+ BitMask<WType, nbits> result(*this);
|
|
|
result >>= shift;
|
|
|
return result;
|
|
|
}
|
|
|
@@ -519,9 +610,9 @@ operator >> (int shift) const {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
-operator &= (const BitMask<WordType, num_bits> &other) {
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
+operator &= (const BitMask<WType, nbits> &other) {
|
|
|
_word &= other._word;
|
|
|
}
|
|
|
|
|
|
@@ -530,9 +621,9 @@ operator &= (const BitMask<WordType, num_bits> &other) {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
-operator |= (const BitMask<WordType, num_bits> &other) {
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
+operator |= (const BitMask<WType, nbits> &other) {
|
|
|
_word |= other._word;
|
|
|
}
|
|
|
|
|
|
@@ -541,9 +632,9 @@ operator |= (const BitMask<WordType, num_bits> &other) {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
-operator ^= (const BitMask<WordType, num_bits> &other) {
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
+operator ^= (const BitMask<WType, nbits> &other) {
|
|
|
_word ^= other._word;
|
|
|
}
|
|
|
|
|
|
@@ -552,8 +643,8 @@ operator ^= (const BitMask<WordType, num_bits> &other) {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
operator <<= (int shift) {
|
|
|
_word <<= shift;
|
|
|
}
|
|
|
@@ -563,8 +654,8 @@ operator <<= (int shift) {
|
|
|
// Access: Published
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
operator >>= (int shift) {
|
|
|
_word >>= shift;
|
|
|
}
|
|
|
@@ -574,8 +665,8 @@ operator >>= (int shift) {
|
|
|
// Access: Public
|
|
|
// Description: Adds the bitmask to the indicated hash generator.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-INLINE void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+INLINE void BitMask<WType, nbits>::
|
|
|
generate_hash(ChecksumHashGenerator &hashgen) const {
|
|
|
hashgen.add_int(_word);
|
|
|
}
|
|
|
@@ -585,8 +676,8 @@ generate_hash(ChecksumHashGenerator &hashgen) const {
|
|
|
// Access: Public
|
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-template<class WordType, int num_bits>
|
|
|
-void BitMask<WordType, num_bits>::
|
|
|
+template<class WType, int nbits>
|
|
|
+void BitMask<WType, nbits>::
|
|
|
init_type() {
|
|
|
ostringstream str;
|
|
|
str << "BitMask" << num_bits;
|