X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fstlplus%2Fcontainers%2Fsafe_iterator.tpp;h=4bbf9b8b18029102df2387109f15389b190ff07d;hp=14d89b992b30b7af42868fd3a2411c222d93bba9;hb=4f6e4488a55f7e3ba3f7485d78177f793c0eab9a;hpb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c diff --git a/src/stlplus/containers/safe_iterator.tpp b/src/stlplus/containers/safe_iterator.tpp index 14d89b9..4bbf9b8 100644 --- a/src/stlplus/containers/safe_iterator.tpp +++ b/src/stlplus/containers/safe_iterator.tpp @@ -17,18 +17,10 @@ namespace stlplus safe_iterator_body(const O* owner, N* node) throw() : m_owner(owner), m_node(node), m_count(1) { -// std::cerr << "constructing " -// << std::hex << ((unsigned long)this) -// << " => " << ((unsigned long)m_owner) << ":" << ((unsigned long)m_node) -// << ":" << std::dec << m_count << std::endl; } ~safe_iterator_body(void) throw() { -// std::cerr << "destroying " -// << std::hex << ((unsigned long)this) -// << " => " << ((unsigned long)m_owner) << ":" << ((unsigned long)m_node) -// << ":" << std::dec << m_count << std::endl; m_owner = 0; m_node = 0; } @@ -41,19 +33,11 @@ namespace stlplus void increment(void) { ++m_count; -// std::cerr << "incremented " -// << std::hex << ((unsigned long)this) -// << " => " << ((unsigned long)m_owner) << ":" << ((unsigned long)m_node) -// << ":" << std::dec << m_count << std::endl; } bool decrement(void) { --m_count; -// std::cerr << "decremented " -// << std::hex << ((unsigned long)this) -// << " => " << ((unsigned long)m_owner) << ":" << ((unsigned long)m_node) -// << ":" << std::dec << m_count << std::endl; return m_count == 0; } @@ -74,13 +58,13 @@ namespace stlplus bool equal(const safe_iterator_body* right) const throw() { -// return m_node == right->m_node; - return compare(right) == 0; + return m_node == right->m_node; } int compare(const safe_iterator_body* right) const throw() { - return ((long)m_node) - ((long)right->m_node); + if (m_node == right->m_node) return 0; + return (m_node < right->m_node) ? -1 : 1; } bool null(void) const throw() @@ -112,21 +96,21 @@ namespace stlplus void assert_valid(void) const throw(null_dereference,end_dereference) { if (null()) - throw null_dereference("stlplus::safe_iterator"); + throw null_dereference("stlplus::safe_iterator: dereferencing null iterator"); if (end()) - throw end_dereference("stlplus::safe_iterator"); + throw end_dereference("stlplus::safe_iterator: dereferencing end iterator"); } void assert_non_null(void) const throw(null_dereference) { if (null()) - throw null_dereference("stlplus::safe_iterator"); + throw null_dereference("stlplus::safe_iterator: dereferencing null iterator"); } void assert_owner(const O* owner) const throw(wrong_object) { if (owner != m_owner) - throw wrong_object("stlplus::safe_iterator"); + throw wrong_object("stlplus::safe_iterator: using iterator with wrong object"); } }; @@ -313,13 +297,13 @@ namespace stlplus template bool safe_iterator::equal(const safe_iterator& right) const throw() { - return compare(right) == 0; + if (m_body == right.m_body) return true; + return m_body->equal(right.m_body); } template int safe_iterator::compare(const safe_iterator& right) const throw() { - if (m_body == right.m_body) return 0; return m_body->compare(right.m_body); }