aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-08-10 17:59:48 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-08-10 17:59:48 +0200
commit2e1c7a69b8d1e65ceb339956f7dae3eb5f8453bf (patch)
treee588e727cea741149551ac359157a6d2b1a7e066
parent0748ec6af7ca878d30e7bb20ae2792cd70c88cad (diff)
Rework result/result_iterator interaction
-rw-r--r--odb/result.hxx70
1 files 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 <typename T>
- class result_impl;
+ class result_iterator;
+
+ template <typename T>
+ class result_impl: public shared_base
+ {
+ public:
+ virtual
+ ~result_impl ();
+ result_impl () : end_ (false), current_ () {}
+
+ protected:
+ friend class result<T>;
+ friend class result_iterator<T>;
+
+ typename object_traits<T>::pointer_type
+ current (bool release)
+ {
+ if (object_traits<T>::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<T>::pointer_type current_;
+ };
template <typename T>
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 <typename T>
- class result_impl: public shared_base
- {
- public:
- virtual
- ~result_impl ();
-
- protected:
- friend class result<T>;
- friend class result_iterator<T>;
-
- virtual typename object_traits<T>::pointer_type
- current (bool release) = 0;
-
- virtual void
- current (T&) = 0;
-
- virtual void
- next () = 0;
- };
-
- template <typename T>
class result
{
public: