aboutsummaryrefslogtreecommitdiff
path: root/odb
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
parent677d07f365c15ed62cbceb0990122c652e5751ec (diff)
Make result copy-assignable
Return result from database::query instead of pointer to impl
Diffstat (limited to 'odb')
-rw-r--r--odb/database.hxx6
-rw-r--r--odb/database.txx6
-rw-r--r--odb/result.hxx48
3 files changed, 30 insertions, 30 deletions
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 <typename T>
- shared_ptr<result_impl<T> >
+ result<T>
query ();
template <typename T>
- shared_ptr<result_impl<T> >
+ result<T>
query (const std::string&);
template <typename T>
- shared_ptr<result_impl<T> >
+ result<T>
query (const odb::query<T>&);
// 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 <typename T>
- shared_ptr<result_impl<T> > database::
+ result<T> database::
query ()
{
return query (odb::query<T> ());
}
template <typename T>
- shared_ptr<result_impl<T> > database::
+ result<T> database::
query (const std::string& q)
{
return query (odb::query<T> (q));
}
template <typename T>
- shared_ptr<result_impl<T> > database::
+ result<T> database::
query (const odb::query<T>& 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<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_;
};