aboutsummaryrefslogtreecommitdiff
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
parent2b6eabb7411469faead3949f2fe9cfd950643123 (diff)
Add swap(), empty(), and size() to result class template
-rw-r--r--odb/exceptions.cxx6
-rw-r--r--odb/exceptions.hxx6
-rw-r--r--odb/result.hxx40
3 files changed, 46 insertions, 6 deletions
diff --git a/odb/exceptions.cxx b/odb/exceptions.cxx
index b27cc37..597f40d 100644
--- a/odb/exceptions.cxx
+++ b/odb/exceptions.cxx
@@ -37,6 +37,12 @@ namespace odb
return "object not persistent";
}
+ const char* result_not_cached::
+ what () const throw ()
+ {
+ return "query result in not cached";
+ }
+
const char* object_already_persistent::
what () const throw ()
{
diff --git a/odb/exceptions.hxx b/odb/exceptions.hxx
index 8c9e826..8c0fe27 100644
--- a/odb/exceptions.hxx
+++ b/odb/exceptions.hxx
@@ -50,6 +50,12 @@ namespace odb
what () const throw ();
};
+ struct LIBODB_EXPORT result_not_cached: odb::exception
+ {
+ virtual const char*
+ what () const throw ();
+ };
+
struct LIBODB_EXPORT database_exception: odb::exception
{
};
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: