aboutsummaryrefslogtreecommitdiff
path: root/boost/common/smart-ptr
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-04 13:32:25 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-04 13:32:25 +0200
commit0b641f182c0b89b0c903f8756aa14b6b3a2f60f2 (patch)
tree83ec50fe5702f58345efea3cb5c6d7a0abdf84a2 /boost/common/smart-ptr
parent18ef14486e46064f4317ab407c5fe0afa3209d4b (diff)
Add support for boost::optional and boost::shared_ptr as value wrappers
New test: boost/common/optional.
Diffstat (limited to 'boost/common/smart-ptr')
-rw-r--r--boost/common/smart-ptr/driver.cxx25
-rw-r--r--boost/common/smart-ptr/test.hxx25
2 files changed, 50 insertions, 0 deletions
diff --git a/boost/common/smart-ptr/driver.cxx b/boost/common/smart-ptr/driver.cxx
index eaa4bbd..af5767c 100644
--- a/boost/common/smart-ptr/driver.cxx
+++ b/boost/common/smart-ptr/driver.cxx
@@ -169,6 +169,31 @@ main (int argc, char* argv[])
t.commit ();
}
+
+ //
+ // Test shared_ptr as a value wrapper.
+ //
+
+ {
+ obj2 o1 (1);
+ obj2 o2 (2);
+ o2.str.reset (new string ("abc"));
+
+ transaction t (db->begin ());
+ db->persist (o1);
+ db->persist (o2);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ shared_ptr<obj2> o1 (db->load<obj2> (1));
+ shared_ptr<obj2> o2 (db->load<obj2> (2));
+ t.commit ();
+
+ assert (!o1->str);
+ assert (o2->str && *o2->str == "abc");
+ }
}
catch (const odb::exception& e)
{
diff --git a/boost/common/smart-ptr/test.hxx b/boost/common/smart-ptr/test.hxx
index 575c2e2..62a9ae6 100644
--- a/boost/common/smart-ptr/test.hxx
+++ b/boost/common/smart-ptr/test.hxx
@@ -6,13 +6,17 @@
#ifndef TEST_HXX
#define TEST_HXX
+#include <string>
#include <vector>
+#include <boost/shared_ptr.hpp>
+
#include <odb/core.hxx>
#include <odb/boost/smart-ptr/lazy-ptr.hxx>
struct obj;
+using boost::shared_ptr;
using odb::boost::lazy_shared_ptr;
using odb::boost::lazy_weak_ptr;
@@ -56,4 +60,25 @@ struct obj
lazy_shared_ptr<cont> c;
};
+// Test shared_ptr 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
+ shared_ptr<std::string> str;
+};
+
#endif // TEST_HXX