Преглед на файлове

Add proper comparison operators and get_hash to ButtonHandle

rdb преди 11 години
родител
ревизия
3d19752dc0
променени са 2 файла, в които са добавени 60 реда и са изтрити 4 реда
  1. 53 0
      panda/src/putil/buttonHandle.I
  2. 7 4
      panda/src/putil/buttonHandle.h

+ 53 - 0
panda/src/putil/buttonHandle.I

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

+ 7 - 4
panda/src/putil/buttonHandle.h

@@ -29,16 +29,19 @@ class EXPCL_PANDA_PUTIL ButtonHandle {
 PUBLISHED:
   INLINE ButtonHandle();
   INLINE ButtonHandle(int index);
-  ButtonHandle(const string &name);
-
-public:
   INLINE ButtonHandle(const ButtonHandle &copy);
+  ButtonHandle(const string &name);
 
+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;