Browse Source

allow casting bitmasks to their integer type, and make sure that bool(bitmask) is False when all bits are off

rdb 13 năm trước cách đây
mục cha
commit
47f3933489
1 tập tin đã thay đổi với 23 bổ sung0 xóa
  1. 23 0
      panda/src/putil/bitMask.I

+ 23 - 0
panda/src/putil/bitMask.I

@@ -821,6 +821,29 @@ operator >>= (int shift) {
   _word >>= shift;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: BitMask::operator WType
+//       Access: Published
+//  Description: Used to cast this BitMask back into the
+//               underlying integer type.
+////////////////////////////////////////////////////////////////////
+template<class WType, int nbits>
+INLINE BitMask<WType, nbits>::
+operator WType () const {
+  return _word;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: BitMask::operator bool
+//       Access: Published
+//  Description: Will return true, unless all bits are off.
+////////////////////////////////////////////////////////////////////
+template<class WType, int nbits>
+INLINE BitMask<WType, nbits>::
+operator bool () const {
+  return (_word != 0);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: BitMask::get_key
 //       Access: Published