aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-03-01 12:34:41 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-03-01 12:34:41 +0200
commit0f25b194dcbcfa95a80284069999dd92341ce36d (patch)
tree50a265da9ed2ae8c87aa437dade6b945fb78a93d
parent6e9f54c33dd67b629ec2a31cadd6815a651f70f5 (diff)
Add support for using C++11 std::unique_ptr to pass connection factory
-rw-r--r--odb/details/transfer-ptr.hxx54
1 files changed, 54 insertions, 0 deletions
diff --git a/odb/details/transfer-ptr.hxx b/odb/details/transfer-ptr.hxx
new file mode 100644
index 0000000..e7ad42c
--- /dev/null
+++ b/odb/details/transfer-ptr.hxx
@@ -0,0 +1,54 @@
+// file : odb/details/transfer-ptr.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_DETAILS_TRANSFER_PTR_HXX
+#define ODB_DETAILS_TRANSFER_PTR_HXX
+
+#include <odb/pre.hxx>
+
+#include <memory> // std::auto_ptr, std::unique_ptr
+
+#include <odb/details/config.hxx> // ODB_CXX11
+
+namespace odb
+{
+ namespace details
+ {
+ template <typename T>
+ class transfer_ptr
+ {
+ public:
+ typedef T element_type;
+
+ transfer_ptr (): p_ (0) {}
+
+ template <typename T1>
+ transfer_ptr (std::auto_ptr<T1> p): p_ (p.release ()) {}
+
+#ifdef ODB_CXX11
+ transfer_ptr (std::nullptr_t): p_ (0) {}
+
+ template <typename T1>
+ transfer_ptr (std::unique_ptr<T1>&& p): p_ (p.release ()) {}
+#endif
+
+ ~transfer_ptr () {delete p_;}
+
+ T*
+ transfer ()
+ {
+ T* r (p_);
+ p_ = 0;
+ return r;
+ }
+
+ private:
+ T* p_;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_DETAILS_TRANSFER_PTR_HXX