safe_iterator_body(const O* owner, N* node) throw() : \r
m_owner(owner), m_node(node), m_count(1)\r
{\r
-// std::cerr << "constructing " \r
-// << std::hex << ((unsigned long)this) \r
-// << " => " << ((unsigned long)m_owner) << ":" << ((unsigned long)m_node)\r
-// << ":" << std::dec << m_count << std::endl;\r
}\r
\r
~safe_iterator_body(void) throw()\r
{\r
-// std::cerr << "destroying " \r
-// << std::hex << ((unsigned long)this) \r
-// << " => " << ((unsigned long)m_owner) << ":" << ((unsigned long)m_node)\r
-// << ":" << std::dec << m_count << std::endl;\r
m_owner = 0;\r
m_node = 0;\r
}\r
void increment(void)\r
{\r
++m_count;\r
-// std::cerr << "incremented " \r
-// << std::hex << ((unsigned long)this) \r
-// << " => " << ((unsigned long)m_owner) << ":" << ((unsigned long)m_node)\r
-// << ":" << std::dec << m_count << std::endl;\r
}\r
\r
bool decrement(void)\r
{\r
--m_count;\r
-// std::cerr << "decremented " \r
-// << std::hex << ((unsigned long)this) \r
-// << " => " << ((unsigned long)m_owner) << ":" << ((unsigned long)m_node)\r
-// << ":" << std::dec << m_count << std::endl;\r
return m_count == 0;\r
}\r
\r
\r
bool equal(const safe_iterator_body<O,N>* right) const throw()\r
{\r
-// return m_node == right->m_node;\r
- return compare(right) == 0;\r
+ return m_node == right->m_node;\r
}\r
\r
int compare(const safe_iterator_body<O,N>* right) const throw()\r
{\r
- return ((long)m_node) - ((long)right->m_node);\r
+ if (m_node == right->m_node) return 0;\r
+ return (m_node < right->m_node) ? -1 : 1;\r
}\r
\r
bool null(void) const throw()\r
void assert_valid(void) const throw(null_dereference,end_dereference)\r
{\r
if (null())\r
- throw null_dereference("stlplus::safe_iterator");\r
+ throw null_dereference("stlplus::safe_iterator: dereferencing null iterator");\r
if (end())\r
- throw end_dereference("stlplus::safe_iterator");\r
+ throw end_dereference("stlplus::safe_iterator: dereferencing end iterator");\r
}\r
\r
void assert_non_null(void) const throw(null_dereference)\r
{\r
if (null())\r
- throw null_dereference("stlplus::safe_iterator");\r
+ throw null_dereference("stlplus::safe_iterator: dereferencing null iterator");\r
}\r
\r
void assert_owner(const O* owner) const throw(wrong_object)\r
{\r
if (owner != m_owner)\r
- throw wrong_object("stlplus::safe_iterator");\r
+ throw wrong_object("stlplus::safe_iterator: using iterator with wrong object");\r
}\r
};\r
\r
template<typename O, typename N>\r
bool safe_iterator<O,N>::equal(const safe_iterator<O,N>& right) const throw()\r
{\r
- return compare(right) == 0;\r
+ if (m_body == right.m_body) return true;\r
+ return m_body->equal(right.m_body);\r
}\r
\r
template<typename O, typename N>\r
int safe_iterator<O,N>::compare(const safe_iterator<O,N>& right) const throw()\r
{\r
- if (m_body == right.m_body) return 0;\r
return m_body->compare(right.m_body);\r
}\r
\r