From 4fd6bca4e75870958ea61b94e0a1e60e78cd91bc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 8 Jan 2012 17:27:40 +0200 Subject: Add support for defining composite value type as class template instantiations --- doc/manual.xhtml | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/manual.xhtml b/doc/manual.xhtml index e21185b..ef36090 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -5665,7 +5665,7 @@ class basic_name

The complete version of the above code fragment and the other code - samples presented in this chapter can be found in the composite + samples presented in this section can be found in the composite example in the odb-examples package.

A composite value type does not have to define a default constructor, @@ -5749,6 +5749,53 @@ class person }; +

A composite value type can also be defined as an instantiation + of a C++ class template, for example:

+ +
+template <typename T>
+struct point
+{
+  T x;
+  T y;
+  T z;
+};
+
+typedef point<int> int_point;
+#pragma db value(int_point)
+
+#pragma db object
+class object
+{
+  ...
+
+  int_point center_;
+};
+
+ +

Note that the database support code for such a composite value type + is generated when compiling the header containing the + db value pragma and not the header containing + the template definition or the typedef name. This + allows us to use templates defined in other files, such as + std::pair defined in the utility + standard header file:

+ +
+#include <utility> // std::pair
+
+typedef std::pair<std::string, std::string> phone_numbers;
+#pragma db value(phone_numbers)
+
+#pragma db object
+class person
+{
+  ...
+
+  phone_numbers phone_;
+};
+
+

We can also use data members from composite value types in database queries (Chapter 4, "Querying the Database"). For each composite value in a persistent class, the -- cgit v1.1