From d9ef0f11aeca10dbed4312c675ae0da74b2040da Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 20 Mar 2012 10:59:21 +0000 Subject: [PATCH] allow comparison between BitMask and integer --- panda/src/putil/bitMask.I | 59 +++++++++++++++++++++++++++++++++++++++ panda/src/putil/bitMask.h | 5 ++++ 2 files changed, 64 insertions(+) diff --git a/panda/src/putil/bitMask.I b/panda/src/putil/bitMask.I index 125bf564d1..bb742b5ac4 100644 --- a/panda/src/putil/bitMask.I +++ b/panda/src/putil/bitMask.I @@ -690,6 +690,65 @@ compare_to(const BitMask &other) const { } } +//////////////////////////////////////////////////////////////////// +// Function: BitMask::operator == +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE bool BitMask:: +operator == (WordType other) const { + return _word == other; +} + +//////////////////////////////////////////////////////////////////// +// Function: BitMask::operator != +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +template +INLINE bool BitMask:: +operator != (WordType other) const { + return _word != other; +} + +//////////////////////////////////////////////////////////////////// +// Function: BitMask::operator < +// Access: Published +// Description: The ordering operator is of limited usefulness with a +// BitMask, however, it has a definition which places +// all unique BitMasks into a unique ordering. It may +// be useful when defining ordered STL containers of +// BitMasks, for instance; and it's required in order to +// export any STL container (ordered or unordered) of +// BitMask under Windows. +//////////////////////////////////////////////////////////////////// +template +INLINE bool BitMask:: +operator < (WordType other) const { + return _word < other; +} + +//////////////////////////////////////////////////////////////////// +// Function: BitMask::compare_to +// Access: Published +// Description: Returns a number less than zero if this BitMask sorts +// before the indicated other BitMask, greater than zero +// if it sorts after, or 0 if they are equivalent. This +// is based on the same ordering defined by operator <. +//////////////////////////////////////////////////////////////////// +template +INLINE int BitMask:: +compare_to(WordType other) const { + if ((*this) < other) { + return -1; + } else if (other < (*this)) { + return 1; + } else { + return 0; + } +} + //////////////////////////////////////////////////////////////////// // Function: BitMask::operator & // Access: Published diff --git a/panda/src/putil/bitMask.h b/panda/src/putil/bitMask.h index 318ced9665..2aecc198d9 100644 --- a/panda/src/putil/bitMask.h +++ b/panda/src/putil/bitMask.h @@ -94,6 +94,11 @@ PUBLISHED: INLINE bool operator < (const BitMask &other) const; INLINE int compare_to(const BitMask &other) const; + INLINE bool operator == (WordType other) const; + INLINE bool operator != (WordType other) const; + INLINE bool operator < (WordType other) const; + INLINE int compare_to(WordType other) const; + INLINE BitMask operator & (const BitMask &other) const;