From 2e1c7a69b8d1e65ceb339956f7dae3eb5f8453bf Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 10 Aug 2010 17:59:48 +0200 Subject: Rework result/result_iterator interaction --- odb/result.hxx | 70 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/odb/result.hxx b/odb/result.hxx index 42939a9..ea1834f 100644 --- a/odb/result.hxx +++ b/odb/result.hxx @@ -18,7 +18,49 @@ namespace odb class result; template - class result_impl; + class result_iterator; + + template + class result_impl: public shared_base + { + public: + virtual + ~result_impl (); + result_impl () : end_ (false), current_ () {} + + protected: + friend class result; + friend class result_iterator; + + typename object_traits::pointer_type + current (bool release) + { + if (object_traits::pointer_ops::null_ptr (current_) && !end_) + current (); + + return current_; + } + + bool + end () const + { + return end_; + } + + protected: + virtual void + current () = 0; + + virtual void + current (T&) = 0; + + virtual void + next () = 0; + + protected: + bool end_; + typename object_traits::pointer_type current_; + }; template class result_iterator @@ -81,10 +123,9 @@ namespace odb public: bool - equal (const result_iterator& j) + equal (result_iterator j) const { - return (res_ ? res_->current (false) : 0) == - (j.res_ ? j.res_->current (false) : 0); + return (res_ ? res_->end () : true) == (j.res_ ? j.res_->end () : true); } private: @@ -110,27 +151,6 @@ namespace odb // // template - class result_impl: public shared_base - { - public: - virtual - ~result_impl (); - - protected: - friend class result; - friend class result_iterator; - - virtual typename object_traits::pointer_type - current (bool release) = 0; - - virtual void - current (T&) = 0; - - virtual void - next () = 0; - }; - - template class result { public: -- cgit v1.1