aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-04 13:33:21 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-04 13:33:21 +0200
commitfc0acda2f0a9f27b490df84de2580306942e42ea (patch)
tree9b77d9bf9cd30cfa2511504226b00ccb537933fe
parentcf2dee1c8fd934a74ea1dadd16e9cbc2b28220bb (diff)
Add support for Qt QSharedPointer as value wrapper
-rw-r--r--odb/qt/smart-ptr.options5
-rw-r--r--odb/qt/smart-ptr/wrapper-traits.hxx60
2 files changed, 65 insertions, 0 deletions
diff --git a/odb/qt/smart-ptr.options b/odb/qt/smart-ptr.options
index 636b130..f3dfbc6 100644
--- a/odb/qt/smart-ptr.options
+++ b/odb/qt/smart-ptr.options
@@ -14,3 +14,8 @@
#
--odb-epilogue '#include <odb/qt/smart-ptr/pointer-traits.hxx>'
--hxx-prologue '#include <odb/qt/smart-ptr/pointer-traits.hxx>'
+
+# Include wrapper traits.
+#
+--odb-epilogue '#include <odb/qt/smart-ptr/wrapper-traits.hxx>'
+--hxx-prologue '#include <odb/qt/smart-ptr/wrapper-traits.hxx>'
diff --git a/odb/qt/smart-ptr/wrapper-traits.hxx b/odb/qt/smart-ptr/wrapper-traits.hxx
new file mode 100644
index 0000000..1f61b5e
--- /dev/null
+++ b/odb/qt/smart-ptr/wrapper-traits.hxx
@@ -0,0 +1,60 @@
+// file : odb/qt/smart-ptr/wrapper-traits.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_SMART_PTR_WRAPPER_TRAITS_HXX
+#define ODB_QT_SMART_PTR_WRAPPER_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QSharedPointer>
+
+#include <odb/wrapper-traits.hxx>
+
+namespace odb
+{
+ // Specialization for QSharedPointer.
+ //
+ template <typename T>
+ class wrapper_traits< QSharedPointer<T> >
+ {
+ public:
+ typedef T wrapped_type;
+ typedef QSharedPointer<T> wrapper_type;
+
+ static const bool null_handler = true;
+ static const bool null_default = false;
+
+ static bool
+ get_null (const wrapper_type& p)
+ {
+ return p.isNull ();
+ }
+
+ static void
+ set_null (wrapper_type& p)
+ {
+ p.clear ();
+ }
+
+ static const wrapped_type&
+ get_ref (const wrapper_type& p)
+ {
+ return *p;
+ }
+
+ static wrapped_type&
+ set_ref (wrapper_type& p)
+ {
+ if (p.isNull ())
+ p = wrapper_type (new wrapped_type);
+
+ return *p;
+ }
+ };
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_SMART_PTR_WRAPPER_TRAITS_HXX