From 9bafeadb554fd4dfc11ce5c2b036a937008455f9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 10 Aug 2010 13:16:47 +0200 Subject: Make result copy-assignable Return result from database::query instead of pointer to impl --- odb/database.hxx | 6 +++--- odb/database.txx | 6 +++--- odb/result.hxx | 48 ++++++++++++++++++++++++------------------------ 3 files changed, 30 insertions(+), 30 deletions(-) (limited to 'odb') diff --git a/odb/database.hxx b/odb/database.hxx index 1b3a6d6..0a993d5 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -71,15 +71,15 @@ namespace odb // Object query API. // template - shared_ptr > + result query (); template - shared_ptr > + result query (const std::string&); template - shared_ptr > + result query (const odb::query&); // Transaction API. diff --git a/odb/database.txx b/odb/database.txx index 7440127..a120afa 100644 --- a/odb/database.txx +++ b/odb/database.txx @@ -94,21 +94,21 @@ namespace odb } template - shared_ptr > database:: + result database:: query () { return query (odb::query ()); } template - shared_ptr > database:: + result database:: query (const std::string& q) { return query (odb::query (q)); } template - shared_ptr > database:: + result database:: query (const odb::query& q) { if (!transaction::has_current ()) diff --git a/odb/result.hxx b/odb/result.hxx index 979988a..7356395 100644 --- a/odb/result.hxx +++ b/odb/result.hxx @@ -31,14 +31,9 @@ namespace odb typedef std::input_iterator_tag iterator_category; public: - result_iterator () - : res_ (0) - { - } - explicit - result_iterator (result_impl& res) - : res_ (&res) + result_iterator (result_impl* res = 0) + : res_ (res) { } @@ -140,24 +135,41 @@ namespace odb typedef std::ptrdiff_t difference_type; public: + result () + { + } + + explicit result (shared_ptr > impl) : impl_ (impl) { } - /* + // Copying or assignment of a result object leads to one instance + // being an alias for another. Think of copying a result as copying + // a file handle -- the file you access through either of them is + // still the same. + // + public: + result (const result& r) + : impl_ (r.impl_) + { + } + result& - operator= (shared_ptr > impl) + operator= (const result& r) { - impl_ = impl; + if (impl_ != r.impl_) + impl_ = r.impl_; + + return *this; } - */ public: iterator begin () { - return iterator (*impl_); + return iterator (impl_.get ()); } iterator @@ -166,18 +178,6 @@ namespace odb return iterator (); } - public: - operator shared_ptr > () - { - return impl_; - } - - // Copying or assignment of results is not supported. - // - private: - result (const result&); - result& operator= (const result&); - private: shared_ptr > impl_; }; -- cgit v1.1