2
0
Эх сурвалжийг харах

fix comment, expose verify_list

David Rose 24 жил өмнө
parent
commit
333bfc3050

+ 0 - 2
panda/src/putil/config_util.cxx

@@ -73,8 +73,6 @@ ConfigureFn(config_util) {
 
 //const bool track_memory_usage = config_util.GetBool("track-memory-usage", false);
 
-const bool paranoid_ordered_vector = config_util.GetBool("paranoid-ordered-vector", false);
-
 DSearchPath &
 get_model_path() {
   static DSearchPath *model_path = NULL;

+ 0 - 2
panda/src/putil/config_util.h

@@ -36,8 +36,6 @@ NotifyCategoryDecl(bam, EXPCL_PANDA, EXPTP_PANDA);
 
 //extern EXPCL_PANDA const bool track_memory_usage;
 
-extern EXPCL_PANDA const bool paranoid_ordered_vector;
-
 // These are functions instead of constant variables because they are
 // computed based on the concatenation of all appearances of the
 // corresponding variable in the config files.

+ 22 - 38
panda/src/putil/ordered_vector.I

@@ -326,7 +326,6 @@ insert_unique(const ordered_vector<Key, Compare>::VALUE_TYPE &key) {
   }
 
   ITERATOR result = _vector.insert(position, key);
-  verify_list();
   return pair<ITERATOR, bool>(result, true);
 }
 
@@ -348,7 +347,6 @@ insert_nonunique(const ordered_vector<Key, Compare>::VALUE_TYPE &key) {
   nassertr(position >= begin() && position <= end(), end());
 
   ITERATOR result = _vector.insert(position, key);
-  verify_list();
   return result;
 }
 
@@ -662,45 +660,9 @@ find_insert_position(ordered_vector<Key, Compare>::ITERATOR first,
                      ordered_vector<Key, Compare>::ITERATOR last,
                      const ordered_vector<Key, Compare>::KEY_TYPE &key) {
   ITERATOR result = r_find_insert_position(first, last, key);
-
-#ifndef NDEBUG
-  // Verify the result.
-  if (paranoid_ordered_vector) {
-    // If there is a node before the indicated position, this node
-    // must not precede it lexicograpically.
-    if (first < result) {
-      nassertr(!_compare(key, *(result - 1)), result);
-    }
-    // If there is a node after the indicated position, it must not
-    // precede this node lexicographically.
-    if (result < last) {
-      nassertr(!_compare(*(result), key), result);
-    }
-  }
-#endif
-
   return result;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: ordered_vector::verify_list
-//       Access: Private
-//  Description: Ensures that the indicated range of elements is
-//               sorted correctly, if paranoid_ordered_vector is set.
-//               Generates an assertion failure (and returns false) if
-//               this is not the case; otherwise, returns true.
-////////////////////////////////////////////////////////////////////
-template<class Key, class Compare>
-INLINE bool ordered_vector<Key, Compare>::
-verify_list() {
-#ifndef NDEBUG
-  if (paranoid_ordered_vector) {
-    return verify_list_impl(begin(), end());
-  }
-#endif
-  return true;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: ov_set::Constructor
 //       Access: Public
@@ -771,6 +733,17 @@ sort() {
   ordered_vector<Key, Compare>::sort_unique();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: ov_set::verify_list
+//       Access: Public
+//  Description: Maps to verify_list_unique().
+////////////////////////////////////////////////////////////////////
+template<class Key, class Compare>
+INLINE bool ov_set<Key, Compare>::
+verify_list() const {
+  return ordered_vector<Key, Compare>::verify_list_unique();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ov_multiset::Constructor
 //       Access: Public
@@ -840,3 +813,14 @@ INLINE void ov_multiset<Key, Compare>::
 sort() {
   ordered_vector<Key, Compare>::sort_nonunique();
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: ov_multiset::verify_list
+//       Access: Public
+//  Description: Maps to verify_list_nonunique().
+////////////////////////////////////////////////////////////////////
+template<class Key, class Compare>
+INLINE bool ov_multiset<Key, Compare>::
+verify_list() const {
+  return ordered_vector<Key, Compare>::verify_list_nonunique();
+}

+ 53 - 27
panda/src/putil/ordered_vector.T

@@ -62,7 +62,6 @@ insert_unique(ordered_vector<Key, Compare>::ITERATOR position,
 
   // Otherwise, we may insert where the caller requested.
   ITERATOR result = _vector.insert(position, key);
-  verify_list();
   return result;
 }
 
@@ -100,10 +99,62 @@ insert_nonunique(ordered_vector<Key, Compare>::ITERATOR position,
 
   // Otherwise, we may insert where the caller requested.
   ITERATOR result = _vector.insert(position, key);
-  verify_list();
   return result;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: ordered_vector::verify_list_unique
+//       Access: Public
+//  Description: Ensures that the indicated range of elements is
+//               sorted correctly.  Returns true if this is the case;
+//               otherwise, returns false.
+////////////////////////////////////////////////////////////////////
+template<class Key, class Compare>
+bool ordered_vector<Key, Compare>::
+verify_list_unique() const {
+  if (!empty()) {
+    CONST_ITERATOR prev = begin();
+    CONST_ITERATOR i = begin();
+    ++i;
+    while (i < end()) {
+      bool ordered_correctly = _compare(*prev, *i);
+      if (!ordered_correctly) {
+        return true;
+      }
+      prev = i;
+      ++i;
+    }
+  }
+  return true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ordered_vector::verify_list_nonunique
+//       Access: Public
+//  Description: Ensures that the indicated range of elements is
+//               sorted correctly.  Returns true if this is the case;
+//               otherwise, returns false.
+////////////////////////////////////////////////////////////////////
+template<class Key, class Compare>
+bool ordered_vector<Key, Compare>::
+verify_list_nonunique() const {
+  if (!empty()) {
+    CONST_ITERATOR prev = begin();
+    CONST_ITERATOR i = begin();
+    ++i;
+    while (i < end()) {
+      bool ordered_correctly = !_compare(*i, *prev);
+      if (!ordered_correctly) {
+        return true;
+      }
+      prev = i;
+      ++i;
+    }
+  }
+  return true;
+}
+
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ordered_vector::r_find_insert_position
 //       Access: Private
@@ -356,28 +407,3 @@ r_equal_range(ordered_vector<Key, Compare>::CONST_ITERATOR first,
     return pair_type(lower, upper);
   }
 }
-
-#ifndef NDEBUG
-////////////////////////////////////////////////////////////////////
-//     Function: ordered_vector::verify_list_impl
-//       Access: Private
-//  Description: The non-inline implementation of verify_list().
-////////////////////////////////////////////////////////////////////
-template<class Key, class Compare>
-bool ordered_vector<Key, Compare>::
-verify_list_impl(ordered_vector<Key, Compare>::ITERATOR first, 
-                 ordered_vector<Key, Compare>::ITERATOR last) {
-  if (first < last) {
-    ITERATOR prev = first;
-    ITERATOR i = first;
-    ++i;
-    while (i < last) {
-      bool ordered_correctly = !_compare(*i, *prev);
-      nassertr(ordered_correctly, false);
-      prev = i;
-      ++i;
-    }
-  }
-  return true;
-}
-#endif  // NDEBUG

+ 29 - 54
panda/src/putil/ordered_vector.h

@@ -26,53 +26,31 @@
 #include "pset.h"
 #include <algorithm>
 
-// Two different compilers that both should have known better had
-// problems parsing the inheritance of typedefs in the template
-// classes below.  Both gcc 2.95.3 and the Intel Windows compiler (not
-// sure of the version) got confused in different ways.  It is a
-// mystery how these compilers are able to handle the actual STL
-// headers, which do this sort of thing all over the place.
-
-// One effective workaround for both compilers seems to be to rename
-// the typedef names slightly.  If the following symbol is declared,
-// the macros in this file will do the job of renaming the typedef
-// names for these broken compilers.  We should probably make this a
-// configurable parameter, but since it doesn't do any harm to leave
-// it declared even for non-broken compilers, we might as well just
-// leave it alone.
-#define BROKEN_TYPEDEF_INHERITANCE 1
-
-// Maybe eventually, when STL is more than only about ten years old
-// and compiler support of anything more than trivial template classes
-// is more universal, we can pull this nonsense out of here.
-
-#ifdef BROKEN_TYPEDEF_INHERITANCE
-  #define KEY_TYPE key_type_0
-  #define VALUE_TYPE value_type_0
-  #define REFERENCE reference_0
-  #define CONST_REFERENCE const_reference_0
-  #define KEY_COMPARE key_compare_0
-  #define VALUE_COMPARE value_compare_0
-  #define ITERATOR iterator_0
-  #define CONST_ITERATOR const_iterator_0
-  #define REVERSE_ITERATOR reverse_iterator_0
-  #define CONST_REVERSE_ITERATOR const_reverse_iterator_0
-  #define DIFFERENCE_TYPE difference_type_0
-  #define SIZE_TYPE size_type_0
-#else
-  #define KEY_TYPE key_type
-  #define VALUE_TYPE value_type
-  #define REFERENCE reference
-  #define CONST_REFERENCE const_reference
-  #define KEY_COMPARE key_compare
-  #define VALUE_COMPARE value_compare
-  #define ITERATOR iterator
-  #define CONST_ITERATOR const_iterator
-  #define REVERSE_ITERATOR reverse_iterator
-  #define CONST_REVERSE_ITERATOR const_reverse_iterator
-  #define DIFFERENCE_TYPE difference_type
-  #define SIZE_TYPE size_type
-#endif
+// There are some inheritance issues with template classes and typedef
+// names.  Template classes that inherit typedef names from their base
+// class, which is also a template class, may confuse the typedef
+// names with globally scoped template names.  In particular, the
+// local "iterator" type is easily confused with the std::iterator
+// template class.
+
+// To work around this problem, as well as a problem in gcc 2.95.3
+// with value_type etc. not inheriting properly (even though we
+// explicitly typedef them in the derived class), we rename the
+// questionable typedefs here so that they no longer conflict with the
+// global template classes.
+
+#define KEY_TYPE key_type_0
+#define VALUE_TYPE value_type_0
+#define REFERENCE reference_0
+#define CONST_REFERENCE const_reference_0
+#define KEY_COMPARE key_compare_0
+#define VALUE_COMPARE value_compare_0
+#define ITERATOR iterator_0
+#define CONST_ITERATOR const_iterator_0
+#define REVERSE_ITERATOR reverse_iterator_0
+#define CONST_REVERSE_ITERATOR const_reverse_iterator_0
+#define DIFFERENCE_TYPE difference_type_0
+#define SIZE_TYPE size_type_0
 
 ////////////////////////////////////////////////////////////////////
 //       Class : ordered_vector
@@ -135,7 +113,6 @@ public:
   typedef Vector::difference_type DIFFERENCE_TYPE;
   typedef Vector::size_type SIZE_TYPE;
 
-#ifdef BROKEN_TYPEDEF_INHERITANCE
   // Since the #define symbols do not actually expand to the correct
   // names, we have to re-typedef them so callers can reference them
   // by their correct, lowercase names.
@@ -151,7 +128,6 @@ public:
   typedef CONST_REVERSE_ITERATOR const_reverse_iterator;
   typedef DIFFERENCE_TYPE difference_type;
   typedef SIZE_TYPE size_type;
-#endif
 
 public:
   // Constructors.  We don't implement the whole slew of STL
@@ -221,6 +197,8 @@ public:
   INLINE void reserve(SIZE_TYPE n);
   INLINE void sort_unique();
   INLINE void sort_nonunique();
+  bool verify_list_unique() const;
+  bool verify_list_nonunique() const;
 
   INLINE void push_back(const VALUE_TYPE &key);
 
@@ -245,11 +223,6 @@ private:
   pair<CONST_ITERATOR, CONST_ITERATOR>
   r_equal_range(CONST_ITERATOR first, CONST_ITERATOR last,
                 const KEY_TYPE &key) const;
-  INLINE bool verify_list();
-
-#ifndef NDEBUG
-  bool verify_list_impl(ITERATOR first, ITERATOR last);
-#endif
 
   // This function object is used in sort_unique().  It returns true
   // if two consecutive sorted elements are equivalent.
@@ -290,6 +263,7 @@ public:
   INLINE pair<ITERATOR, bool> insert(const VALUE_TYPE &key0);
 
   INLINE void sort();
+  INLINE bool verify_list() const;
 };
 
 ////////////////////////////////////////////////////////////////////
@@ -309,6 +283,7 @@ public:
   INLINE ITERATOR insert(const VALUE_TYPE &key);
 
   INLINE void sort();
+  INLINE bool verify_list() const;
 };
 
 #include "ordered_vector.I"