diff --git a/panda/src/putil/ordered_vector.I b/panda/src/putil/ordered_vector.I index fa89545cf6..05a9cdb1b3 100644 --- a/panda/src/putil/ordered_vector.I +++ b/panda/src/putil/ordered_vector.I @@ -72,7 +72,7 @@ INLINE ordered_vector:: // the ordered vector. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::iterator ordered_vector:: +INLINE ordered_vector::ITERATOR ordered_vector:: begin() { return _vector.begin(); } @@ -84,7 +84,7 @@ begin() { // ordered vector. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::iterator ordered_vector:: +INLINE ordered_vector::ITERATOR ordered_vector:: end() { return _vector.end(); } @@ -96,7 +96,7 @@ end() { // the ordered vector, when viewed in reverse order. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::reverse_iterator ordered_vector:: +INLINE ordered_vector::REVERSE_ITERATOR ordered_vector:: rbegin() { return _vector.rbegin(); } @@ -108,7 +108,7 @@ rbegin() { // ordered vector, when viewed in reverse order. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::reverse_iterator ordered_vector:: +INLINE ordered_vector::REVERSE_ITERATOR ordered_vector:: rend() { return _vector.rend(); } @@ -120,7 +120,7 @@ rend() { // the ordered vector. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::const_iterator ordered_vector:: +INLINE ordered_vector::CONST_ITERATOR ordered_vector:: begin() const { return _vector.begin(); } @@ -132,7 +132,7 @@ begin() const { // ordered vector. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::const_iterator ordered_vector:: +INLINE ordered_vector::CONST_ITERATOR ordered_vector:: end() const { return _vector.end(); } @@ -144,7 +144,7 @@ end() const { // the ordered vector, when viewed in reverse order. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::const_reverse_iterator ordered_vector:: +INLINE ordered_vector::CONST_REVERSE_ITERATOR ordered_vector:: rbegin() const { return _vector.rbegin(); } @@ -156,7 +156,7 @@ rbegin() const { // ordered vector, when viewed in reverse order. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::const_reverse_iterator ordered_vector:: +INLINE ordered_vector::CONST_REVERSE_ITERATOR ordered_vector:: rend() const { return _vector.rend(); } @@ -167,8 +167,8 @@ rend() const { // Description: Returns the nth element. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::reference ordered_vector:: -operator [] (ordered_vector::size_type n) { +INLINE ordered_vector::REFERENCE ordered_vector:: +operator [] (ordered_vector::SIZE_TYPE n) { return _vector[n]; } @@ -178,8 +178,8 @@ operator [] (ordered_vector::size_type n) { // Description: Returns the nth element. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::const_reference ordered_vector:: -operator [] (ordered_vector::size_type n) const { +INLINE ordered_vector::CONST_REFERENCE ordered_vector:: +operator [] (ordered_vector::SIZE_TYPE n) const { return _vector[n]; } @@ -189,7 +189,7 @@ operator [] (ordered_vector::size_type n) const { // Description: Returns the number of elements in the ordered vector. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::size_type ordered_vector:: +INLINE ordered_vector::SIZE_TYPE ordered_vector:: size() const { return _vector.size(); } @@ -201,7 +201,7 @@ size() const { // possibly be stored in an ordered vector. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::size_type ordered_vector:: +INLINE ordered_vector::SIZE_TYPE ordered_vector:: max_size() const { return _vector.max_size(); } @@ -309,25 +309,25 @@ operator >= (const ordered_vector &other) const { // the insert operation has taken place. //////////////////////////////////////////////////////////////////// template -INLINE pair::iterator, bool> ordered_vector:: -insert_unique(const ordered_vector::value_type &key) { - iterator position = find_insert_position(begin(), end(), key); +INLINE pair::ITERATOR, bool> ordered_vector:: +insert_unique(const ordered_vector::VALUE_TYPE &key) { + ITERATOR position = find_insert_position(begin(), end(), key); #ifdef NDEBUG - pair bogus_result(end(), false); + pair bogus_result(end(), false); nassertr(position >= begin() && position <= end(), bogus_result); #endif // If there's already an equivalent key in the vector, it's at // *(position - 1). if (position != begin() && !_compare(*(position - 1), key)) { - pair result(position - 1, false); + pair result(position - 1, false); nassertr(!_compare(key, *(position - 1)), result); return result; } - iterator result = _vector.insert(position, key); + ITERATOR result = _vector.insert(position, key); verify_list(); - return pair(result, true); + return pair(result, true); } //////////////////////////////////////////////////////////////////// @@ -342,12 +342,12 @@ insert_unique(const ordered_vector::value_type &key) { // element. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::iterator ordered_vector:: -insert_nonunique(const ordered_vector::value_type &key) { - iterator position = find_insert_position(begin(), end(), key); +INLINE ordered_vector::ITERATOR ordered_vector:: +insert_nonunique(const ordered_vector::VALUE_TYPE &key) { + ITERATOR position = find_insert_position(begin(), end(), key); nassertr(position >= begin() && position <= end(), end()); - iterator result = _vector.insert(position, key); + ITERATOR result = _vector.insert(position, key); verify_list(); return result; } @@ -360,9 +360,9 @@ insert_nonunique(const ordered_vector::value_type &key) { // and returns the next sequential iterator. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::iterator ordered_vector:: -erase(ordered_vector::iterator position) { - size_type count = position - begin(); +INLINE ordered_vector::ITERATOR ordered_vector:: +erase(ordered_vector::ITERATOR position) { + SIZE_TYPE count = position - begin(); _vector.erase(position); return begin() + count; } @@ -374,10 +374,10 @@ erase(ordered_vector::iterator position) { // returns the number of elements removed. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::size_type ordered_vector:: -erase(const ordered_vector::key_type &key) { - pair result = equal_range(key); - size_type count = result.second - result.first; +INLINE ordered_vector::SIZE_TYPE ordered_vector:: +erase(const ordered_vector::KEY_TYPE &key) { + pair result = equal_range(key); + SIZE_TYPE count = result.second - result.first; erase(result.first, result.second); return count; } @@ -390,8 +390,8 @@ erase(const ordered_vector::key_type &key) { //////////////////////////////////////////////////////////////////// template INLINE void ordered_vector:: -erase(ordered_vector::iterator first, - ordered_vector::iterator last) { +erase(ordered_vector::ITERATOR first, + ordered_vector::ITERATOR last) { _vector.erase(first, last); } @@ -415,8 +415,8 @@ clear() { // key, the particular iterator returned is not defined. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::iterator ordered_vector:: -find(const ordered_vector::key_type &key) { +INLINE ordered_vector::ITERATOR ordered_vector:: +find(const ordered_vector::KEY_TYPE &key) { return nci(r_find(begin(), end(), end(), key)); } @@ -429,8 +429,8 @@ find(const ordered_vector::key_type &key) { // key, the particular iterator returned is not defined. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::const_iterator ordered_vector:: -find(const ordered_vector::key_type &key) const { +INLINE ordered_vector::CONST_ITERATOR ordered_vector:: +find(const ordered_vector::KEY_TYPE &key) const { return r_find(begin(), end(), end(), key); } @@ -451,8 +451,8 @@ find(const ordered_vector::key_type &key) const { // !Compare(b, a), but not necessarily the converse. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::iterator ordered_vector:: -find_particular(const ordered_vector::key_type &key) { +INLINE ordered_vector::ITERATOR ordered_vector:: +find_particular(const ordered_vector::KEY_TYPE &key) { return nci(r_find_particular(begin(), end(), end(), key)); } @@ -470,8 +470,8 @@ find_particular(const ordered_vector::key_type &key) { // particular iterator returned is not defined./ //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::const_iterator ordered_vector:: -find_particular(const ordered_vector::key_type &key) const { +INLINE ordered_vector::CONST_ITERATOR ordered_vector:: +find_particular(const ordered_vector::KEY_TYPE &key) const { return r_find_particular(begin(), end(), end(), key); } @@ -482,7 +482,7 @@ find_particular(const ordered_vector::key_type &key) const { // to the key that are in the vector. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::size_type ordered_vector:: +INLINE ordered_vector::SIZE_TYPE ordered_vector:: count(const key_type &key) const { return r_count(begin(), end(), key); } @@ -494,8 +494,8 @@ count(const key_type &key) const { // than key, or end() if all elements are less than key. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::iterator ordered_vector:: -lower_bound(const ordered_vector::key_type &key) { +INLINE ordered_vector::ITERATOR ordered_vector:: +lower_bound(const ordered_vector::KEY_TYPE &key) { return nci(r_lower_bound(begin(), end(), key)); } @@ -506,8 +506,8 @@ lower_bound(const ordered_vector::key_type &key) { // than key, or end() if all elements are less than key. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::const_iterator ordered_vector:: -lower_bound(const ordered_vector::key_type &key) const { +INLINE ordered_vector::CONST_ITERATOR ordered_vector:: +lower_bound(const ordered_vector::KEY_TYPE &key) const { return r_lower_bound(begin(), end(), key); } @@ -519,8 +519,8 @@ lower_bound(const ordered_vector::key_type &key) const { // key. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::iterator ordered_vector:: -upper_bound(const ordered_vector::key_type &key) { +INLINE ordered_vector::ITERATOR ordered_vector:: +upper_bound(const ordered_vector::KEY_TYPE &key) { return nci(r_upper_bound(begin(), end(), key)); } @@ -532,8 +532,8 @@ upper_bound(const ordered_vector::key_type &key) { // key. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::const_iterator ordered_vector:: -upper_bound(const ordered_vector::key_type &key) const { +INLINE ordered_vector::CONST_ITERATOR ordered_vector:: +upper_bound(const ordered_vector::KEY_TYPE &key) const { return r_upper_bound(begin(), end(), key); } @@ -543,11 +543,11 @@ upper_bound(const ordered_vector::key_type &key) const { // Description: Returns the pair (lower_bound(key), upper_bound(key)). //////////////////////////////////////////////////////////////////// template -INLINE pair::iterator, ordered_vector::iterator> ordered_vector:: -equal_range(const ordered_vector::key_type &key) { - pair::const_iterator, ordered_vector::const_iterator> result; +INLINE pair::ITERATOR, ordered_vector::ITERATOR> ordered_vector:: +equal_range(const ordered_vector::KEY_TYPE &key) { + pair::CONST_ITERATOR, ordered_vector::CONST_ITERATOR> result; result = r_equal_range(begin(), end(), key); - return pair::iterator, ordered_vector::iterator>(nci(result.first), nci(result.second)); + return pair::ITERATOR, ordered_vector::ITERATOR>(nci(result.first), nci(result.second)); } //////////////////////////////////////////////////////////////////// @@ -556,8 +556,8 @@ equal_range(const ordered_vector::key_type &key) { // Description: Returns the pair (lower_bound(key), upper_bound(key)). //////////////////////////////////////////////////////////////////// template -INLINE pair::const_iterator, ordered_vector::const_iterator> ordered_vector:: -equal_range(const ordered_vector::key_type &key) const { +INLINE pair::CONST_ITERATOR, ordered_vector::CONST_ITERATOR> ordered_vector:: +equal_range(const ordered_vector::KEY_TYPE &key) const { return r_equal_range(begin(), end(), key); } @@ -582,7 +582,7 @@ swap(ordered_vector ©) { //////////////////////////////////////////////////////////////////// template INLINE void ordered_vector:: -reserve(ordered_vector::size_type n) { +reserve(ordered_vector::SIZE_TYPE n) { _vector.reserve(n); } @@ -644,9 +644,9 @@ push_back(const value_type &key) { // some of these methods. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::iterator ordered_vector:: -nci(ordered_vector::const_iterator iterator) { - return begin() + (iterator - begin()); +INLINE ordered_vector::ITERATOR ordered_vector:: +nci(ordered_vector::CONST_ITERATOR i) { + return begin() + (i - begin()); } //////////////////////////////////////////////////////////////////// @@ -657,11 +657,11 @@ nci(ordered_vector::const_iterator iterator) { // corresponding iterator. //////////////////////////////////////////////////////////////////// template -INLINE ordered_vector::iterator ordered_vector:: -find_insert_position(ordered_vector::iterator first, - ordered_vector::iterator last, - const ordered_vector::key_type &key) { - iterator result = r_find_insert_position(first, last, key); +INLINE ordered_vector::ITERATOR ordered_vector:: +find_insert_position(ordered_vector::ITERATOR first, + ordered_vector::ITERATOR last, + const ordered_vector::KEY_TYPE &key) { + ITERATOR result = r_find_insert_position(first, last, key); #ifndef NDEBUG // Verify the result. @@ -743,9 +743,9 @@ operator = (const ov_set ©) { // Description: Maps to insert_unique(). //////////////////////////////////////////////////////////////////// template -ov_set::iterator ov_set:: -insert(ordered_vector::iterator position, - const ordered_vector::value_type &key) { +ordered_vector::ITERATOR ov_set:: +insert(ordered_vector::ITERATOR position, + const ordered_vector::VALUE_TYPE &key) { return ordered_vector::insert_unique(position, key); } @@ -755,8 +755,8 @@ insert(ordered_vector::iterator position, // Description: Maps to insert_unique(). //////////////////////////////////////////////////////////////////// template -INLINE pair::iterator, bool> ov_set:: -insert(const ordered_vector::value_type &key) { +INLINE pair::ITERATOR, bool> ov_set:: +insert(const ordered_vector::VALUE_TYPE &key) { return ordered_vector::insert_unique(key); } @@ -813,9 +813,9 @@ operator = (const ov_multiset ©) { // Description: Maps to insert_nonunique(). //////////////////////////////////////////////////////////////////// template -ov_multiset::iterator ov_multiset:: -insert(ov_multiset::iterator position, - const ov_multiset::value_type &key) { +ordered_vector::ITERATOR ov_multiset:: +insert(ordered_vector::ITERATOR position, + const ordered_vector::VALUE_TYPE &key) { return ordered_vector::insert_nonunique(position, key); } @@ -825,8 +825,8 @@ insert(ov_multiset::iterator position, // Description: Maps to insert_nonunique(). //////////////////////////////////////////////////////////////////// template -INLINE ov_multiset::iterator ov_multiset:: -insert(const ov_multiset::value_type &key) { +INLINE ordered_vector::ITERATOR ov_multiset:: +insert(const ordered_vector::VALUE_TYPE &key) { return ordered_vector::insert_nonunique(key); } diff --git a/panda/src/putil/ordered_vector.T b/panda/src/putil/ordered_vector.T index 53811627ec..4622e39243 100644 --- a/panda/src/putil/ordered_vector.T +++ b/panda/src/putil/ordered_vector.T @@ -32,9 +32,9 @@ // referencing the original value is returned. //////////////////////////////////////////////////////////////////// template -ordered_vector::iterator ordered_vector:: -insert_unique(ordered_vector::iterator position, - const ordered_vector::value_type &key) { +ordered_vector::ITERATOR ordered_vector:: +insert_unique(ordered_vector::ITERATOR position, + const ordered_vector::VALUE_TYPE &key) { if (position != end()) { // If we're not inserting at the end, the element we're // inserting before should not lexicographically precede this one. @@ -61,7 +61,7 @@ insert_unique(ordered_vector::iterator position, } // Otherwise, we may insert where the caller requested. - iterator result = _vector.insert(position, key); + ITERATOR result = _vector.insert(position, key); verify_list(); return result; } @@ -79,9 +79,9 @@ insert_unique(ordered_vector::iterator position, // same key to be inserted. //////////////////////////////////////////////////////////////////// template -ordered_vector::iterator ordered_vector:: -insert_nonunique(ordered_vector::iterator position, - const ordered_vector::value_type &key) { +ordered_vector::ITERATOR ordered_vector:: +insert_nonunique(ordered_vector::ITERATOR position, + const ordered_vector::VALUE_TYPE &key) { if (position != end()) { // If we're not inserting at the end, the element we're // inserting before should not lexicographically precede this one. @@ -99,7 +99,7 @@ insert_nonunique(ordered_vector::iterator position, } // Otherwise, we may insert where the caller requested. - iterator result = _vector.insert(position, key); + ITERATOR result = _vector.insert(position, key); verify_list(); return result; } @@ -111,16 +111,16 @@ insert_nonunique(ordered_vector::iterator position, // find_insert_position(). //////////////////////////////////////////////////////////////////// template -ordered_vector::iterator ordered_vector:: -r_find_insert_position(ordered_vector::iterator first, - ordered_vector::iterator last, - const ordered_vector::key_type &key) { +ordered_vector::ITERATOR ordered_vector:: +r_find_insert_position(ordered_vector::ITERATOR first, + ordered_vector::ITERATOR last, + const ordered_vector::KEY_TYPE &key) { if (first == last) { // The list is empty; the insert position is the last of the list. return last; } - iterator center = first + (last - first) / 2; + ITERATOR center = first + (last - first) / 2; nassertr(center < last, last); if (_compare(key, *center)) { @@ -139,17 +139,17 @@ r_find_insert_position(ordered_vector::iterator first, // Description: The recursive implementation of find(). //////////////////////////////////////////////////////////////////// template -ordered_vector::const_iterator ordered_vector:: -r_find(ordered_vector::const_iterator first, - ordered_vector::const_iterator last, - ordered_vector::const_iterator not_found, - const ordered_vector::key_type &key) const { +ordered_vector::CONST_ITERATOR ordered_vector:: +r_find(ordered_vector::CONST_ITERATOR first, + ordered_vector::CONST_ITERATOR last, + ordered_vector::CONST_ITERATOR not_found, + const ordered_vector::KEY_TYPE &key) const { if (first == last) { // The list is empty; the key is not on the list. return not_found; } - const_iterator center = first + (last - first) / 2; + CONST_ITERATOR center = first + (last - first) / 2; nassertr(center < last, last); if (_compare(key, *center)) { @@ -172,17 +172,17 @@ r_find(ordered_vector::const_iterator first, // Description: The recursive implementation of find_particular(). //////////////////////////////////////////////////////////////////// template -ordered_vector::const_iterator ordered_vector:: -r_find_particular(ordered_vector::const_iterator first, - ordered_vector::const_iterator last, - ordered_vector::const_iterator not_found, - const ordered_vector::key_type &key) const { +ordered_vector::CONST_ITERATOR ordered_vector:: +r_find_particular(ordered_vector::CONST_ITERATOR first, + ordered_vector::CONST_ITERATOR last, + ordered_vector::CONST_ITERATOR not_found, + const ordered_vector::KEY_TYPE &key) const { if (first == last) { // The list is empty; the key is not on the list. return not_found; } - const_iterator center = first + (last - first) / 2; + CONST_ITERATOR center = first + (last - first) / 2; nassertr(center < last, last); if (_compare(key, *center)) { @@ -196,7 +196,7 @@ r_find_particular(ordered_vector::const_iterator first, } else { // The center's sort matches the key's sort. It could be either // before or after the center. First try after. - const_iterator i = center; + CONST_ITERATOR i = center; while (i < last && !_compare(key, *i)) { if ((*i) == key) { return i; @@ -225,18 +225,18 @@ r_find_particular(ordered_vector::const_iterator first, // Description: The recursive implementation of count(). //////////////////////////////////////////////////////////////////// template -ordered_vector::size_type ordered_vector:: -r_count(ordered_vector::const_iterator first, - ordered_vector::const_iterator last, - const ordered_vector::key_type &key) const { - typedef pair::const_iterator, ordered_vector::const_iterator> pair_type; +ordered_vector::SIZE_TYPE ordered_vector:: +r_count(ordered_vector::CONST_ITERATOR first, + ordered_vector::CONST_ITERATOR last, + const ordered_vector::KEY_TYPE &key) const { + typedef pair::CONST_ITERATOR, ordered_vector::CONST_ITERATOR> pair_type; if (first == last) { // The list is empty; the key is not on the list. return 0; } - const_iterator center = first + (last - first) / 2; + CONST_ITERATOR center = first + (last - first) / 2; nassertr(center < last, 0); if (_compare(key, *center)) { @@ -261,16 +261,16 @@ r_count(ordered_vector::const_iterator first, // Description: The recursive implementation of lower_bound(). //////////////////////////////////////////////////////////////////// template -ordered_vector::const_iterator ordered_vector:: -r_lower_bound(ordered_vector::const_iterator first, - ordered_vector::const_iterator last, - const ordered_vector::key_type &key) const { +ordered_vector::CONST_ITERATOR ordered_vector:: +r_lower_bound(ordered_vector::CONST_ITERATOR first, + ordered_vector::CONST_ITERATOR last, + const ordered_vector::KEY_TYPE &key) const { if (first == last) { // The list is empty; the key is not on the list. return last; } - const_iterator center = first + (last - first) / 2; + CONST_ITERATOR center = first + (last - first) / 2; nassertr(center < last, last); if (_compare(key, *center)) { @@ -294,10 +294,10 @@ r_lower_bound(ordered_vector::const_iterator first, // Description: The recursive implementation of upper_bound(). //////////////////////////////////////////////////////////////////// template -ordered_vector::const_iterator ordered_vector:: -r_upper_bound(ordered_vector::const_iterator first, - ordered_vector::const_iterator last, - const ordered_vector::key_type &key) const { +ordered_vector::CONST_ITERATOR ordered_vector:: +r_upper_bound(ordered_vector::CONST_ITERATOR first, + ordered_vector::CONST_ITERATOR last, + const ordered_vector::KEY_TYPE &key) const { if (first == last) { // The list is empty; the key is not on the list. return last; @@ -327,18 +327,18 @@ r_upper_bound(ordered_vector::const_iterator first, // Description: The recursive implementation of equal_range(). //////////////////////////////////////////////////////////////////// template -pair::const_iterator, ordered_vector::const_iterator> ordered_vector:: -r_equal_range(ordered_vector::const_iterator first, - ordered_vector::const_iterator last, - const ordered_vector::key_type &key) const { - typedef pair::const_iterator, ordered_vector::const_iterator> pair_type; +pair::CONST_ITERATOR, ordered_vector::CONST_ITERATOR> ordered_vector:: +r_equal_range(ordered_vector::CONST_ITERATOR first, + ordered_vector::CONST_ITERATOR last, + const ordered_vector::KEY_TYPE &key) const { + typedef pair::CONST_ITERATOR, ordered_vector::CONST_ITERATOR> pair_type; if (first == last) { // The list is empty; the key is not on the list. return pair_type(last, last); } - const_iterator center = first + (last - first) / 2; + CONST_ITERATOR center = first + (last - first) / 2; nassertr(center < last, pair_type(last, last)); if (_compare(key, *center)) { @@ -351,8 +351,8 @@ r_equal_range(ordered_vector::const_iterator first, } else { // The center matches the key; the range is here. - const_iterator lower = r_lower_bound(first, center, key); - const_iterator upper = r_upper_bound(center + 1, last, key); + CONST_ITERATOR lower = r_lower_bound(first, center, key); + CONST_ITERATOR upper = r_upper_bound(center + 1, last, key); return pair_type(lower, upper); } } @@ -365,11 +365,11 @@ r_equal_range(ordered_vector::const_iterator first, //////////////////////////////////////////////////////////////////// template bool ordered_vector:: -verify_list_impl(ordered_vector::iterator first, - ordered_vector::iterator last) { +verify_list_impl(ordered_vector::ITERATOR first, + ordered_vector::ITERATOR last) { if (first < last) { - iterator prev = first; - iterator i = first; + ITERATOR prev = first; + ITERATOR i = first; ++i; while (i < last) { bool ordered_correctly = !_compare(*i, *prev); diff --git a/panda/src/putil/ordered_vector.h b/panda/src/putil/ordered_vector.h index 4042f58bd5..79971dbd2a 100644 --- a/panda/src/putil/ordered_vector.h +++ b/panda/src/putil/ordered_vector.h @@ -26,6 +26,54 @@ #include "pset.h" #include +// 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 + //////////////////////////////////////////////////////////////////// // Class : ordered_vector // Description : This template class presents an interface similar to @@ -69,23 +117,41 @@ private: public: // Typedefs - typedef Key key_type; - typedef Key value_type; - typedef Key &reference; - typedef const Key &const_reference; - typedef Compare key_compare; - typedef Compare value_compare; + typedef Key KEY_TYPE; + typedef Key VALUE_TYPE; + typedef Key &REFERENCE; + typedef const Key &CONST_REFERENCE; + typedef Compare KEY_COMPARE; + typedef Compare VALUE_COMPARE; // Be careful when using the non-const iterators that you do not // disturb the sorted order of the vector, or that if you do, you // call sort() when you are done. - typedef Vector::iterator iterator; - typedef Vector::const_iterator const_iterator; - typedef Vector::reverse_iterator reverse_iterator; - typedef Vector::const_reverse_iterator const_reverse_iterator; + typedef Vector::iterator ITERATOR; + typedef Vector::const_iterator CONST_ITERATOR; + typedef Vector::reverse_iterator REVERSE_ITERATOR; + typedef Vector::const_reverse_iterator CONST_REVERSE_ITERATOR; - typedef Vector::difference_type difference_type; - typedef Vector::size_type size_type; + 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. + typedef KEY_TYPE key_type; + typedef VALUE_TYPE value_type; + typedef REFERENCE reference; + typedef CONST_REFERENCE const_reference; + typedef KEY_COMPARE key_compare; + typedef VALUE_COMPARE value_compare; + typedef ITERATOR iterator; + typedef CONST_ITERATOR const_iterator; + typedef REVERSE_ITERATOR reverse_iterator; + 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 @@ -96,23 +162,23 @@ public: INLINE ~ordered_vector(); // Iterator access. - INLINE iterator begin(); - INLINE iterator end(); - INLINE reverse_iterator rbegin(); - INLINE reverse_iterator rend(); + INLINE ITERATOR begin(); + INLINE ITERATOR end(); + INLINE REVERSE_ITERATOR rbegin(); + INLINE REVERSE_ITERATOR rend(); - INLINE const_iterator begin() const; - INLINE const_iterator end() const; - INLINE const_reverse_iterator rbegin() const; - INLINE const_reverse_iterator rend() const; + INLINE CONST_ITERATOR begin() const; + INLINE CONST_ITERATOR end() const; + INLINE CONST_REVERSE_ITERATOR rbegin() const; + INLINE CONST_REVERSE_ITERATOR rend() const; // Random access. - INLINE reference operator [] (size_type n); - INLINE const_reference operator [] (size_type n) const; + INLINE reference operator [] (SIZE_TYPE n); + INLINE const_reference operator [] (SIZE_TYPE n) const; // Size information. - INLINE size_type size() const; - INLINE size_type max_size() const; + INLINE SIZE_TYPE size() const; + INLINE SIZE_TYPE max_size() const; INLINE bool empty() const; // Equivalence and lexicographical comparisons. @@ -125,64 +191,64 @@ public: INLINE bool operator >= (const ordered_vector &other) const; // Insert operations. - iterator insert_unique(iterator position, const value_type &key); - iterator insert_nonunique(iterator position, const value_type &key); - INLINE pair insert_unique(const value_type &key); - INLINE iterator insert_nonunique(const value_type &key); + ITERATOR insert_unique(ITERATOR position, const VALUE_TYPE &key); + ITERATOR insert_nonunique(ITERATOR position, const VALUE_TYPE &key); + INLINE pair insert_unique(const VALUE_TYPE &key); + INLINE ITERATOR insert_nonunique(const VALUE_TYPE &key); // Erase operations. - INLINE iterator erase(iterator position); - INLINE size_type erase(const key_type &key); - INLINE void erase(iterator first, iterator last); + INLINE ITERATOR erase(ITERATOR position); + INLINE SIZE_TYPE erase(const KEY_TYPE &key); + INLINE void erase(ITERATOR first, ITERATOR last); INLINE void clear(); // Find operations. - INLINE iterator find(const key_type &key); - INLINE const_iterator find(const key_type &key) const; - INLINE iterator find_particular(const key_type &key); - INLINE const_iterator find_particular(const key_type &key) const; - INLINE size_type count(const key_type &key) const; + INLINE ITERATOR find(const KEY_TYPE &key); + INLINE CONST_ITERATOR find(const KEY_TYPE &key) const; + INLINE ITERATOR find_particular(const KEY_TYPE &key); + INLINE CONST_ITERATOR find_particular(const KEY_TYPE &key) const; + INLINE SIZE_TYPE count(const KEY_TYPE &key) const; - INLINE iterator lower_bound(const key_type &key); - INLINE const_iterator lower_bound(const key_type &key) const; - INLINE iterator upper_bound(const key_type &key); - INLINE const_iterator upper_bound(const key_type &key) const; - INLINE pair equal_range(const key_type &key); - INLINE pair equal_range(const key_type &key) const; + INLINE ITERATOR lower_bound(const KEY_TYPE &key); + INLINE CONST_ITERATOR lower_bound(const KEY_TYPE &key) const; + INLINE ITERATOR upper_bound(const KEY_TYPE &key); + INLINE CONST_ITERATOR upper_bound(const KEY_TYPE &key) const; + INLINE pair equal_range(const KEY_TYPE &key); + INLINE pair equal_range(const KEY_TYPE &key) const; // Special operations. INLINE void swap(ordered_vector &other); - INLINE void reserve(size_type n); + INLINE void reserve(SIZE_TYPE n); INLINE void sort_unique(); INLINE void sort_nonunique(); - INLINE void push_back(const value_type &key); + INLINE void push_back(const VALUE_TYPE &key); private: - INLINE iterator nci(const_iterator iterator); - INLINE iterator find_insert_position(iterator first, iterator last, - const key_type &key); - iterator r_find_insert_position(iterator first, iterator last, - const key_type &key); - const_iterator r_find(const_iterator first, const_iterator last, - const_iterator not_found, - const key_type &key) const; - const_iterator r_find_particular(const_iterator first, const_iterator last, - const_iterator not_found, - const key_type &key) const; - size_type r_count(const_iterator first, const_iterator last, - const key_type &key) const; - const_iterator r_lower_bound(const_iterator first, const_iterator last, - const key_type &key) const; - const_iterator r_upper_bound(const_iterator first, const_iterator last, - const key_type &key) const; - pair - r_equal_range(const_iterator first, const_iterator last, - const key_type &key) const; + INLINE ITERATOR nci(CONST_ITERATOR i); + INLINE ITERATOR find_insert_position(ITERATOR first, ITERATOR last, + const KEY_TYPE &key); + ITERATOR r_find_insert_position(ITERATOR first, ITERATOR last, + const KEY_TYPE &key); + CONST_ITERATOR r_find(CONST_ITERATOR first, CONST_ITERATOR last, + CONST_ITERATOR not_found, + const KEY_TYPE &key) const; + CONST_ITERATOR r_find_particular(CONST_ITERATOR first, CONST_ITERATOR last, + CONST_ITERATOR not_found, + const KEY_TYPE &key) const; + SIZE_TYPE r_count(CONST_ITERATOR first, CONST_ITERATOR last, + const KEY_TYPE &key) const; + CONST_ITERATOR r_lower_bound(CONST_ITERATOR first, CONST_ITERATOR last, + const KEY_TYPE &key) const; + CONST_ITERATOR r_upper_bound(CONST_ITERATOR first, CONST_ITERATOR last, + const KEY_TYPE &key) const; + pair + 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); + bool verify_list_impl(ITERATOR first, ITERATOR last); #endif // This function object is used in sort_unique(). It returns true @@ -195,7 +261,7 @@ private: // template class cannot be defined outside the class". INLINE EquivalentTest(const Compare &compare) : _compare(compare) { } - INLINE bool operator () (const key_type &a, const key_type &b) { + INLINE bool operator () (const KEY_TYPE &a, const KEY_TYPE &b) { nassertr(!_compare(b, a), false); return !_compare(a, b); } @@ -216,28 +282,12 @@ private: template > class ov_set : public ordered_vector { public: - // The Intel compiler doesn't seem to inherit these typedefs - // completely--it gets confused in certain cases. We'll make it - // explicit. - typedef ordered_vector::key_type key_type; - typedef ordered_vector::value_type value_type; - typedef ordered_vector::reference reference; - typedef ordered_vector::const_reference const_reference; - typedef ordered_vector::key_compare key_compare; - typedef ordered_vector::value_compare value_compare; - typedef ordered_vector::iterator iterator; - typedef ordered_vector::const_iterator const_iterator; - typedef ordered_vector::reverse_iterator reverse_iterator; - typedef ordered_vector::const_reverse_iterator const_reverse_iterator; - typedef ordered_vector::difference_type difference_type; - typedef ordered_vector::size_type size_type; - INLINE ov_set(const Compare &compare = Compare()); INLINE ov_set(const ov_set ©); INLINE ov_set &operator = (const ov_set ©); - INLINE iterator insert(iterator position, const value_type &key); - INLINE pair insert(const value_type &key); + INLINE ITERATOR insert(ITERATOR position, const VALUE_TYPE &key0); + INLINE pair insert(const VALUE_TYPE &key0); INLINE void sort(); }; @@ -251,28 +301,12 @@ public: template > class ov_multiset : public ordered_vector { public: - // The Intel compiler doesn't seem to inherit these typedefs - // completely--it gets confused in certain cases. We'll make it - // explicit. - typedef ordered_vector::key_type key_type; - typedef ordered_vector::value_type value_type; - typedef ordered_vector::reference reference; - typedef ordered_vector::const_reference const_reference; - typedef ordered_vector::key_compare key_compare; - typedef ordered_vector::value_compare value_compare; - typedef ordered_vector::iterator iterator; - typedef ordered_vector::const_iterator const_iterator; - typedef ordered_vector::reverse_iterator reverse_iterator; - typedef ordered_vector::const_reverse_iterator const_reverse_iterator; - typedef ordered_vector::difference_type difference_type; - typedef ordered_vector::size_type size_type; - INLINE ov_multiset(const Compare &compare = Compare()); INLINE ov_multiset(const ov_multiset ©); INLINE ov_multiset &operator = (const ov_multiset ©); - INLINE iterator insert(iterator position, const value_type &key); - INLINE iterator insert(const value_type &key); + INLINE ITERATOR insert(ITERATOR position, const VALUE_TYPE &key); + INLINE ITERATOR insert(const VALUE_TYPE &key); INLINE void sort(); };