aboutsummaryrefslogtreecommitdiff
path: root/odb/result.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-08-10 13:16:47 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-08-10 13:16:47 +0200
commit9bafeadb554fd4dfc11ce5c2b036a937008455f9 (patch)
tree7dfee55101ec7cc98684a1bfdd90a4356dccac34 /odb/result.hxx
parent677d07f365c15ed62cbceb0990122c652e5751ec (diff)
Make result copy-assignable
Return result from database::query instead of pointer to impl
Diffstat (limited to 'odb/result.hxx')
-rw-r--r--odb/result.hxx48
1 files changed, 24 insertions, 24 deletions
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<T>& res)
- : res_ (&res)
+ result_iterator (result_impl<T>* res = 0)
+ : res_ (res)
{
}
@@ -140,24 +135,41 @@ namespace odb
typedef std::ptrdiff_t difference_type;
public:
+ result ()
+ {
+ }
+
+ explicit
result (shared_ptr<result_impl<T> > 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<result_impl<T> > 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<result_impl<T> > ()
- {
- return impl_;
- }
-
- // Copying or assignment of results is not supported.
- //
- private:
- result (const result&);
- result& operator= (const result&);
-
private:
shared_ptr<result_impl<T> > impl_;
};