diff --git a/panda/src/putil/bitArray.I b/panda/src/putil/bitArray.I index 2389b39406..f3b4fc2a34 100755 --- a/panda/src/putil/bitArray.I +++ b/panda/src/putil/bitArray.I @@ -411,6 +411,18 @@ clear() { _highest_bits = 0; } +//////////////////////////////////////////////////////////////////// +// Function: BitArray::operator bool +// Access: Published +// Description: The bool typecast operator returns true if any bits +// are set, false if none of them is set. That is, true +// if nonzero, false if zero. +//////////////////////////////////////////////////////////////////// +INLINE BitArray:: +operator bool () const { + return !is_zero(); +} + //////////////////////////////////////////////////////////////////// // Function: BitArray::operator == // Access: Published diff --git a/panda/src/putil/bitArray.h b/panda/src/putil/bitArray.h index 3a1a85f187..3e9fa157fb 100755 --- a/panda/src/putil/bitArray.h +++ b/panda/src/putil/bitArray.h @@ -102,6 +102,7 @@ PUBLISHED: void output_hex(ostream &out, int spaces_every = 4) const; void write(ostream &out, int indent_level = 0) const; + INLINE operator bool () const; INLINE bool operator == (const BitArray &other) const; INLINE bool operator != (const BitArray &other) const; INLINE bool operator < (const BitArray &other) const; diff --git a/panda/src/putil/bitMask.I b/panda/src/putil/bitMask.I index ffaf45052d..142c30aff0 100644 --- a/panda/src/putil/bitMask.I +++ b/panda/src/putil/bitMask.I @@ -631,6 +631,19 @@ write(ostream &out, int indent_level) const { indent(out, indent_level) << *this << "\n"; } +//////////////////////////////////////////////////////////////////// +// Function: BitMask::operator bool +// Access: Published +// Description: The bool typecast operator returns true if any bits +// are set, false if none of them is set. That is, true +// if nonzero, false if zero. +//////////////////////////////////////////////////////////////////// +template +INLINE BitMask:: +operator bool () const { + return !is_zero(); +} + //////////////////////////////////////////////////////////////////// // Function: BitMask::operator == // Access: Published diff --git a/panda/src/putil/bitMask.h b/panda/src/putil/bitMask.h index 2a3e494236..fcec8ae8b9 100644 --- a/panda/src/putil/bitMask.h +++ b/panda/src/putil/bitMask.h @@ -89,6 +89,7 @@ PUBLISHED: void output_hex(ostream &out, int spaces_every = 4) const; void write(ostream &out, int indent_level = 0) const; + INLINE operator bool () const; INLINE bool operator == (const BitMask &other) const; INLINE bool operator != (const BitMask &other) const; INLINE bool operator < (const BitMask &other) const; diff --git a/panda/src/putil/doubleBitMask.I b/panda/src/putil/doubleBitMask.I index 05febb27e2..55acf9b193 100644 --- a/panda/src/putil/doubleBitMask.I +++ b/panda/src/putil/doubleBitMask.I @@ -646,6 +646,19 @@ write(ostream &out, int indent_level) const { indent(out, indent_level) << *this << "\n"; } +//////////////////////////////////////////////////////////////////// +// Function: DoubleBitMask::operator bool +// Access: Published +// Description: The bool typecast operator returns true if any bits +// are set, false if none of them is set. That is, true +// if nonzero, false if zero. +//////////////////////////////////////////////////////////////////// +template +INLINE DoubleBitMask:: +operator bool () const { + return !is_zero(); +} + //////////////////////////////////////////////////////////////////// // Function: DoubleBitMask::operator == // Access: Published diff --git a/panda/src/putil/doubleBitMask.h b/panda/src/putil/doubleBitMask.h index bed4fa19ef..c9b1cf9ca3 100644 --- a/panda/src/putil/doubleBitMask.h +++ b/panda/src/putil/doubleBitMask.h @@ -89,6 +89,7 @@ PUBLISHED: void output_hex(ostream &out, int spaces_every = 4) const; void write(ostream &out, int indent_level = 0) const; + INLINE operator bool () const; INLINE bool operator == (const DoubleBitMask &other) const; INLINE bool operator != (const DoubleBitMask &other) const; INLINE bool operator < (const DoubleBitMask &other) const; diff --git a/panda/src/putil/sparseArray.I b/panda/src/putil/sparseArray.I index ed72375e8c..744498b806 100644 --- a/panda/src/putil/sparseArray.I +++ b/panda/src/putil/sparseArray.I @@ -360,6 +360,18 @@ clear() { _inverse = false; } +//////////////////////////////////////////////////////////////////// +// Function: SparseArray::operator bool +// Access: Published +// Description: The bool typecast operator returns true if any bits +// are set, false if none of them is set. That is, true +// if nonzero, false if zero. +//////////////////////////////////////////////////////////////////// +INLINE SparseArray:: +operator bool () const { + return !is_zero(); +} + //////////////////////////////////////////////////////////////////// // Function: SparseArray::operator == // Access: Published diff --git a/panda/src/putil/sparseArray.h b/panda/src/putil/sparseArray.h index b2d4bda0e9..a8c54644f3 100644 --- a/panda/src/putil/sparseArray.h +++ b/panda/src/putil/sparseArray.h @@ -93,6 +93,7 @@ PUBLISHED: void output(ostream &out) const; + INLINE operator bool () const; INLINE bool operator == (const SparseArray &other) const; INLINE bool operator != (const SparseArray &other) const; INLINE bool operator < (const SparseArray &other) const;