diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-08-16 11:45:23 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-08-16 11:45:23 +0200 |
commit | c56f32eb5e0b88ef8297a691f5286ba4aa4aa8b4 (patch) | |
tree | b6978e5a2e90839f1b0f3faead5448b926b1b010 /odb/result.hxx | |
parent | b9376a8bd73d12c868dafa2d1f686058a77d35be (diff) |
Add pointer guard for naked pointer
Diffstat (limited to 'odb/result.hxx')
-rw-r--r-- | odb/result.hxx | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/odb/result.hxx b/odb/result.hxx index 87374e5..0323b66 100644 --- a/odb/result.hxx +++ b/odb/result.hxx @@ -32,12 +32,19 @@ namespace odb friend class result<T>; friend class result_iterator<T>; - typename object_traits<T>::pointer_type - current (bool /*release*/) + typedef object_traits<T> traits; + typedef typename traits::pointer_type pointer_type; + typedef typename traits::pointer_traits pointer_traits; + + pointer_type + current (bool release) { - if (object_traits<T>::pointer_ops::null_ptr (current_) && !end_) + if (pointer_traits::null_ptr (current_) && !end_) current (); + if (release) + guard_.release (); + return current_; } @@ -58,8 +65,18 @@ namespace odb next () = 0; protected: + void + current (pointer_type p) + { + current_ = p; + guard_.reset (current_); + } + bool end_; - typename object_traits<T>::pointer_type current_; + + private: + pointer_type current_; + typename pointer_traits::guard guard_; }; template <typename T> |