From e288ee241317773c77d954c8c286f53a963e7c19 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 3 Sep 2012 12:02:29 +0200 Subject: Add support for Boost Multi-Index container in Boost profile --- NEWS | 4 ++ doc/manual.xhtml | 116 ++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 105 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index 09150fa..e03d90c 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,10 @@ Version 2.1.0 For more information, refer to Section 12.7, "Database Type Mapping Pragmas" in the ODB manual. + * The Boost profile now provides persistence support for the Boost Multi- + Index container (boost::multi_index_container). For more information, + refer to Section 19.3, "Multi-Index Container Library" in the ODB manual. + * New pragma, definition, allows the specification of an alternative code generation location for persistent classes, views, and composite value types. This mechanism is primarily useful for converting third-party diff --git a/doc/manual.xhtml b/doc/manual.xhtml index 203fe53..ab0ab65 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -707,15 +707,16 @@ for consistency. - + + - @@ -6590,7 +6591,7 @@ namespace odb consider using a more efficient implementation of the optional value concept such as the optional class template from Boost - (Section 19.3, "Optional Library").

+ (Section 19.4, "Optional Library").

Another common C++ representation of a value that can be NULL is a pointer. ODB will automatically @@ -17208,7 +17209,92 @@ class person }; -

19.3 Optional Library

+

19.3 Multi-Index Container Library

+ +

The multi-index sub-profile provides persistence support for + boost::multi_index_container from the Boost Multi-Index + library. To enable only this profile, pass boost/multi-index + to the --profile ODB compiler option. The following example + shows how multi_index_container may be used within a + persistent object.

+ +
+namespace mi = boost::multi_index;
+
+#pragma db object
+class person
+{
+  ...
+
+  typedef
+  mi::multi_index_container<
+    std::string,
+    mi::indexed_by<
+      mi::sequenced<>,
+      mi::ordered_unique<mi::identity<std::string> >
+    >
+  > emails;
+
+  emails emails_;
+};
+  
+ +

Note that a multi_index_container instantiation is + stored differently in the database depending on whether it has + any sequenced or random_access indexes. + If it does, then it is treated as an ordered container + (Section 5.1, "Ordered Containers") with the + first such index establishing the order. Otherwise, it is treated + as a set container (Section 5.2, "Set and Multiset + Containers").

+ +

Note also that there is a terminology clash between ODB and Boost + Multi-Index. The ODB term ordered container translates + to Multi-Index terms sequenced index and random access + index while the ODB term set container translates + to Multi-Index terms ordered index and hashed + index.

+ +

The emails container form the above example is stored + as an ordered container. In contrast, the following aliases + container is stored as a set.

+ +
+namespace mi = boost::multi_index;
+
+#pragma db value
+struct name
+{
+  std::string first;
+  std::string last;
+};
+
+bool operator< (const name&, const name&);
+
+#pragma db object
+class person
+{
+  ...
+
+  typedef
+  mi::multi_index_container<
+    name,
+    mi::indexed_by<
+      mi::ordered_unique<mi::identity<name> >
+      mi::ordered_non_unique<
+        mi::member<name, std::string, &name::first>
+      >,
+      mi::ordered_non_unique<
+        mi::member<name, std::string, &name::last>
+      >
+    >
+  > aliases;
+
+  aliases aliases_;
+};
+  
+ +

19.4 Optional Library

The optional sub-profile provides persistence support for the boost::optional container from the Boost @@ -17240,7 +17326,7 @@ class person this profile is used, the NULL values are automatically enabled for data members of the boost::optional type.

-

19.4 Date Time Library

+

19.5 Date Time Library

The date-time sub-profile provides persistence support for a subset of types from the Boost date_time library. It is @@ -17313,7 +17399,7 @@ namespace odb exceptions are thrown are database system dependent and are discussed in more detail in the following sub-sections.

-

19.4.1 MySQL Database Type Mapping

+

19.5.1 MySQL Database Type Mapping

The following table summarizes the default mapping between the currently supported Boost date_time types and the MySQL database @@ -17374,7 +17460,7 @@ class person the out_of_range exception. Refer to the MySQL documentation for more information on the MySQL data type ranges.

-

19.4.2 SQLite Database Type Mapping

+

19.5.2 SQLite Database Type Mapping

The following table summarizes the default mapping between the currently supported Boost date_time types and the SQLite database @@ -17452,7 +17538,7 @@ class person will result in the out_of_range exception.

-

19.4.3 PostgreSQL Database Type Mapping

+

19.5.3 PostgreSQL Database Type Mapping

The following table summarizes the default mapping between the currently supported Boost date_time types and the PostgreSQL database @@ -17503,7 +17589,7 @@ class person result in the special_value exception.

-

19.4.4 Oracle Database Type Mapping

+

19.5.4 Oracle Database Type Mapping

The following table summarizes the default mapping between the currently supported Boost date_time types and the Oracle database @@ -17565,7 +17651,7 @@ class person the special_value exception.

-

19.4.5 SQL Server Database Type Mapping

+

19.5.5 SQL Server Database Type Mapping

The following table summarizes the default mapping between the currently supported Boost date_time types and the SQL Server database -- cgit v1.1

19.1Smart Pointers Library
19.2Unordered Containers Library
19.3Optional Library
19.3Multi-Index Container Library
19.4Optional Library
19.4Date Time Library + 19.5Date Time Library - - - - - + + + + +
19.4.1MySQL Database Type Mapping
19.4.2SQLite Database Type Mapping
19.4.3PostgreSQL Database Type Mapping
19.4.4Oracle Database Type Mapping
19.4.5SQL Server Database Type Mapping
19.5.1MySQL Database Type Mapping
19.5.2SQLite Database Type Mapping
19.5.3PostgreSQL Database Type Mapping
19.5.4Oracle Database Type Mapping
19.5.5SQL Server Database Type Mapping