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
commit839a84b996d89dcf3d553af23e4ed5e0e4fa60e2 (patch)
treebed8baf6721eb0109a260d170b507b597fe9790d
parent0b641f182c0b89b0c903f8756aa14b6b3a2f60f2 (diff)
Add support for Qt QSharedPointer as value wrapper
-rw-r--r--qt/common/smart-ptr/driver.cxx25
-rw-r--r--qt/common/smart-ptr/test.hxx23
2 files changed, 48 insertions, 0 deletions
diff --git a/qt/common/smart-ptr/driver.cxx b/qt/common/smart-ptr/driver.cxx
index ee53c57..49e2ae1 100644
--- a/qt/common/smart-ptr/driver.cxx
+++ b/qt/common/smart-ptr/driver.cxx
@@ -212,6 +212,31 @@ main (int argc, char* argv[])
t.commit ();
}
+
+ //
+ // Test QSharedPointer as a value wrapper.
+ //
+
+ {
+ obj2 o1 (1);
+ obj2 o2 (2);
+ o2.num = QSharedPointer<unsigned long> (new unsigned long (123));
+
+ transaction t (db->begin ());
+ db->persist (o1);
+ db->persist (o2);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ QSharedPointer<obj2> o1 (db->load<obj2> (1));
+ QSharedPointer<obj2> o2 (db->load<obj2> (2));
+ t.commit ();
+
+ assert (!o1->num);
+ assert (o2->num && *o2->num == 123);
+ }
}
catch (const odb::exception& e)
{
diff --git a/qt/common/smart-ptr/test.hxx b/qt/common/smart-ptr/test.hxx
index 0a4ce03..86e4fba 100644
--- a/qt/common/smart-ptr/test.hxx
+++ b/qt/common/smart-ptr/test.hxx
@@ -8,6 +8,8 @@
#include <vector>
+#include <QtCore/QSharedPointer>
+
#include <odb/core.hxx>
#include <odb/qt/lazy-ptr.hxx>
@@ -53,4 +55,25 @@ struct obj
QLazySharedPointer<cont> c;
};
+// Test QSharedPointer as a value wrapper.
+//
+#pragma db object
+struct obj2
+{
+ obj2 ()
+ {
+ }
+
+ obj2 (unsigned long id)
+ : id (id)
+ {
+ }
+
+ #pragma db id
+ unsigned long id;
+
+ #pragma db null
+ QSharedPointer<unsigned long> num;
+};
+
#endif // TEST_HXX