aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-01-08 17:27:40 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-01-08 17:27:40 +0200
commit4fd6bca4e75870958ea61b94e0a1e60e78cd91bc (patch)
tree2119cae72f45e1ceff1982d8364b4b678ac4ee69 /doc
parent7cd11b5f604c7d786261568aa31cd2ae3638f61e (diff)
Add support for defining composite value type as class template instantiations
Diffstat (limited to 'doc')
-rw-r--r--doc/manual.xhtml49
1 files changed, 48 insertions, 1 deletions
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
</pre>
<p>The complete version of the above code fragment and the other code
- samples presented in this chapter can be found in the <code>composite</code>
+ samples presented in this section can be found in the <code>composite</code>
example in the <code>odb-examples</code> package.</p>
<p>A composite value type does not have to define a default constructor,
@@ -5749,6 +5749,53 @@ class person
};
</pre>
+ <p>A composite value type can also be defined as an instantiation
+ of a C++ class template, for example:</p>
+
+<pre class="c++">
+template &lt;typename T>
+struct point
+{
+ T x;
+ T y;
+ T z;
+};
+
+typedef point&lt;int> int_point;
+#pragma db value(int_point)
+
+#pragma db object
+class object
+{
+ ...
+
+ int_point center_;
+};
+</pre>
+
+ <p>Note that the database support code for such a composite value type
+ is generated when compiling the header containing the
+ <code>db&nbsp;value</code> pragma and not the header containing
+ the template definition or the <code>typedef</code> name. This
+ allows us to use templates defined in other files, such as
+ <code>std::pair</code> defined in the <code>utility</code>
+ standard header file:</p>
+
+<pre class="c++">
+#include &lt;utility> // std::pair
+
+typedef std::pair&lt;std::string, std::string> phone_numbers;
+#pragma db value(phone_numbers)
+
+#pragma db object
+class person
+{
+ ...
+
+ phone_numbers phone_;
+};
+</pre>
+
<p>We can also use data members from composite value types
in database queries (<a href="#4">Chapter 4, "Querying the
Database"</a>). For each composite value in a persistent class, the