aboutsummaryrefslogtreecommitdiff
path: root/odb/result.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-09-23 11:59:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-09-23 11:59:05 +0200
commit0a1552132435813f25c32c59bca2366e28a320da (patch)
treefe9f62c4ab19c46b0f7726c0a2d899ba173827fa /odb/result.hxx
parent2b6eabb7411469faead3949f2fe9cfd950643123 (diff)
Add swap(), empty(), and size() to result class template
Diffstat (limited to 'odb/result.hxx')
-rw-r--r--odb/result.hxx40
1 files changed, 34 insertions, 6 deletions
diff --git a/odb/result.hxx b/odb/result.hxx
index eb7f370..9f7dcb0 100644
--- a/odb/result.hxx
+++ b/odb/result.hxx
@@ -76,6 +76,9 @@ namespace odb
virtual void
cache () = 0;
+ virtual std::size_t
+ size () = 0;
+
protected:
void
current (pointer_type p)
@@ -233,6 +236,29 @@ namespace odb
return *this;
}
+ void
+ swap (result& r)
+ {
+ // @@ add swap() to shared_ptr.
+ //
+ details::shared_ptr<result_impl<T> > p (impl_);
+ impl_ = r.impl_;
+ r.impl_ = p;
+ }
+
+ public:
+ iterator
+ begin ()
+ {
+ return iterator (impl_.get ());
+ }
+
+ iterator
+ end ()
+ {
+ return iterator ();
+ }
+
// Cache the result instead of fetching the data from the database
// one object at a time. This is necessary if you plan on performing
// database operations while iterating over the result.
@@ -246,16 +272,18 @@ namespace odb
}
public:
- iterator
- begin ()
+ bool
+ empty () const
{
- return iterator (impl_.get ());
+ return impl_ == 0 || impl_->end ();
}
- iterator
- end ()
+ // Size is only known in cached results.
+ //
+ size_type
+ size () const
{
- return iterator ();
+ return impl_ ? impl_->size () : 0;
}
private: