Add proper comparison operators and get_hash to ButtonHandle

This commit is contained in:
rdb 2014-07-29 13:25:43 +00:00
parent 0dc6c663a1
commit 3d19752dc0
2 changed files with 60 additions and 4 deletions

View File

@ -76,6 +76,59 @@ operator < (const ButtonHandle &other) const {
return (_index < other._index);
}
////////////////////////////////////////////////////////////////////
// Function: ButtonHandle::Ordering Operator
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool ButtonHandle::
operator <= (const ButtonHandle &other) const {
return (_index <= other._index);
}
////////////////////////////////////////////////////////////////////
// Function: ButtonHandle::Ordering Operator
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool ButtonHandle::
operator > (const ButtonHandle &other) const {
return (_index > other._index);
}
////////////////////////////////////////////////////////////////////
// Function: ButtonHandle::Ordering Operator
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool ButtonHandle::
operator >= (const ButtonHandle &other) const {
return (_index >= other._index);
}
////////////////////////////////////////////////////////////////////
// Function: ButtonHandle::compare_to
// Access: Published
// Description: Sorts ButtonHandles arbitrarily (according to <, >,
// etc.). Returns a number less than 0 if this type
// sorts before the other one, greater than zero if it
// sorts after, 0 if they are equivalent.
////////////////////////////////////////////////////////////////////
INLINE int ButtonHandle::
compare_to(const ButtonHandle &other) const {
return _index - other._index;
}
////////////////////////////////////////////////////////////////////
// Function: ButtonHandle::get_hash
// Access: Published
// Description: Returns a hash code suitable for phash_map.
////////////////////////////////////////////////////////////////////
INLINE size_t ButtonHandle::
get_hash() const {
return (size_t)_index;
}
////////////////////////////////////////////////////////////////////
// Function: ButtonHandle::has_ascii_equivalent
// Access: Published

View File

@ -29,16 +29,19 @@ class EXPCL_PANDA_PUTIL ButtonHandle {
PUBLISHED:
INLINE ButtonHandle();
INLINE ButtonHandle(int index);
INLINE ButtonHandle(const ButtonHandle &copy);
ButtonHandle(const string &name);
public:
INLINE ButtonHandle(const ButtonHandle &copy);
PUBLISHED:
INLINE bool operator == (const ButtonHandle &other) const;
INLINE bool operator != (const ButtonHandle &other) const;
INLINE bool operator < (const ButtonHandle &other) const;
INLINE bool operator <= (const ButtonHandle &other) const;
INLINE bool operator > (const ButtonHandle &other) const;
INLINE bool operator >= (const ButtonHandle &other) const;
INLINE int compare_to(const ButtonHandle &other) const;
INLINE size_t get_hash() const;
PUBLISHED:
string get_name() const;
INLINE bool has_ascii_equivalent() const;
INLINE char get_ascii_equivalent() const;