Browse Source

add BitMask::range()

David Rose 21 years ago
parent
commit
7d3fa1b266
2 changed files with 22 additions and 0 deletions
  1. 21 0
      panda/src/putil/bitMask.I
  2. 1 0
      panda/src/putil/bitMask.h

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

@@ -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

+ 1 - 0
panda/src/putil/bitMask.h

@@ -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();