diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-09-20 18:00:14 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-09-20 18:00:14 +0200 |
commit | 666e48a82c343795c44a533ee71d3094fb7f064f (patch) | |
tree | 5f458f58900ca8c1bb49e4cae85c7c475f5c0d66 | |
parent | 2d3d20ee4e3ce52d6a2b235e86aa3fa63fe61611 (diff) |
Make result_iterator::operator* return reference
Add load() version that returns the dynamically-allocated instance.
-rw-r--r-- | odb/result.hxx | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/odb/result.hxx b/odb/result.hxx index 163b619..eb7f370 100644 --- a/odb/result.hxx +++ b/odb/result.hxx @@ -12,6 +12,7 @@ #include <iterator> // iterator categories #include <odb/forward.hxx> +#include <odb/pointer-traits.hxx> #include <odb/details/shared-ptr.hxx> @@ -45,10 +46,15 @@ namespace odb if (pointer_traits::null_ptr (current_) && !end_) current (); + pointer_type r (current_); + if (release) + { + current_ = pointer_type (); guard_.release (); + } - return current_; + return r; } bool @@ -89,7 +95,7 @@ namespace odb class result_iterator { public: - typedef typename object_traits<T>::pointer_type value_type; + typedef T value_type; typedef value_type& reference; typedef value_type* pointer; typedef std::ptrdiff_t difference_type; @@ -105,20 +111,20 @@ namespace odb // Input iterator requirements. // public: - value_type + reference operator* () const { - return res_->current (true); + return pointer_traits::get_ref (res_->current (false)); } // Our value_type is already a pointer so return it instead of // a pointer to it (operator-> will just have to go one deeper // in the latter case). // - value_type + pointer operator-> () const { - return res_->current (false); + return pointer_traits::get_ptr (res_->current (false)); } result_iterator& @@ -138,6 +144,12 @@ namespace odb } public: + typename object_traits<T>::pointer_type + load () + { + return res_->current (true); + } + void load (T& x) { @@ -152,6 +164,8 @@ namespace odb } private: + typedef typename object_traits<T>::pointer_traits pointer_traits; + result_impl<T>* res_; }; |