aboutsummaryrefslogtreecommitdiff
path: root/common/wrapper/test.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-04 13:29:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-04 13:29:43 +0200
commit18ef14486e46064f4317ab407c5fe0afa3209d4b (patch)
treef70e9fb4a7d492197dca3f1fcbf05ffdf308af1a /common/wrapper/test.hxx
parent84b6d8488a2415c1c6c91b2234993497ab8f792b (diff)
Add support for value wrappers
Wrapper is a class that wraps another type. Examples of wrappers are various smart pointers, holders, etc. A wrapper can be transparent or it can handle the NULL semantics. The new odb::nullable class template is a NULL wrapper that helps to add the NULL semantics to a value type. New test: common/wrapper.
Diffstat (limited to 'common/wrapper/test.hxx')
-rw-r--r--common/wrapper/test.hxx53
1 files changed, 53 insertions, 0 deletions
diff --git a/common/wrapper/test.hxx b/common/wrapper/test.hxx
new file mode 100644
index 0000000..68a8750
--- /dev/null
+++ b/common/wrapper/test.hxx
@@ -0,0 +1,53 @@
+// file : common/wrapper/test.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <common/config.hxx> // HAVE_TR1_MEMORY
+
+#include <string>
+#include <memory> // std::auto_ptr
+#include <vector>
+
+#include <odb/core.hxx>
+#include <odb/nullable.hxx>
+
+#ifdef HAVE_TR1_MEMORY
+# include <odb/tr1/memory.hxx>
+#endif
+
+using odb::nullable;
+
+typedef nullable<std::string> nullable_string;
+
+#ifdef HAVE_TR1_MEMORY
+typedef std::tr1::shared_ptr<std::string> tr1_nullable_string;
+#endif
+
+#pragma db object
+struct object
+{
+ #pragma db id auto
+ unsigned long id_;
+
+ std::auto_ptr<unsigned long> num;
+
+ #pragma db null
+ std::auto_ptr<std::string> str;
+
+ nullable_string nstr;
+ std::vector<nullable_string> nstrs;
+
+#ifdef HAVE_TR1_MEMORY
+ #pragma db null
+ tr1_nullable_string tr1_str;
+
+ #pragma db value_null
+ std::vector<tr1_nullable_string> tr1_strs;
+#endif
+};
+
+#endif // TEST_HXX