From a482f1c4dd4efab83d3b19309900f1cbf54383a5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 15 Oct 2013 07:01:17 +0200 Subject: Automatically map C++11 enum classes (strong enums) --- doc/manual.xhtml | 138 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 114 insertions(+), 24 deletions(-) (limited to 'doc') diff --git a/doc/manual.xhtml b/doc/manual.xhtml index 79722db..9537121 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -15809,10 +15809,11 @@ class person

Default values specified as enumerators are only supported for members that are mapped to an ENUM or an integer type in the database, which is the case for the automatic - mapping of C++ enums to suitable database types as performed - by the ODB compiler. If you have mapped a C++ enum to another - database type, then you should use a literal corresponding - to that type to specify the default value. For example:

+ mapping of C++ enums and enum classes to suitable database + types as performed by the ODB compiler. If you have mapped + a C++ enum or enum class to another database type, then you + should use a literal corresponding to that type to specify + the default value. For example:

 enum gender {male, female, undisclosed};
@@ -18670,16 +18671,18 @@ person.hxx
      to the VARCHAR(255) MySQL type. Otherwise,
      it is mapped to TEXT.

-

Additionally, by default, C++ enumerations are automatically - mapped to a suitable MySQL type. Contiguous enumerations with - the zero first enumerator are mapped to the MySQL ENUM - type. All other enumerations are mapped to INT or - INT UNSIGNED. In both cases the default NULL - semantics is NOT NULL. For example:

+

Additionally, by default, C++ enums and C++11 enum classes are + automatically mapped to suitable MySQL types. Contiguous + enumerations with the zero first enumerator are mapped to + the MySQL ENUM type. All other enumerations + are mapped to the MySQL types corresponding to their + underlying integral types (see table above). In both + cases the default NULL semantics is + NOT NULL. For example:

 enum color {red, green, blue};
-enum taste
+enum class taste: unsigned char
 {
   bitter = 1, // Non-zero first enumerator.
   sweet,
@@ -18693,7 +18696,7 @@ class object
   ...
 
   color color_; // Mapped to ENUM ('red', 'green', 'blue') NOT NULL.
-  taste taste_; // Mapped to INT UNSIGNED NOT NULL.
+  taste taste_; // Mapped to TINYNT UNSIGNED NOT NULL.
 };
   
@@ -19433,9 +19436,30 @@ class object db not_null pragma (Section 14.4.6, "null/not_null").

-

Additionally, by default, C++ enumerations are automatically mapped to - the SQLite INTEGER type with the default NULL - semantics being NOT NULL.

+

Additionally, by default, C++ enums and C++11 enum classes are + automatically mapped to the SQLite INTEGER type with + the default NULL semantics being NOT NULL. + For example:

+ +
+enum color {red, green, blue};
+enum class taste: unsigned char
+{
+  bitter = 1,
+  sweet,
+  sour = 4,
+  salty
+};
+
+#pragma db object
+class object
+{
+  ...
+
+  color color_; // Automatically mapped to INTEGER.
+  taste taste_; // Automatically mapped to INTEGER.
+};
+  

Note also that SQLite only operates with signed integers and the largest value that an SQLite database can store is a signed 64-bit integer. As @@ -20406,9 +20430,31 @@ class object db type pragma (Section 14.4.3, "type").

-

Additionally, by default, C++ enumerations are automatically - mapped to INTEGER with the default NULL - semantics being NOT NULL.

+

Additionally, by default, C++ enums and C++11 enum classes are + automatically mapped to the PostgreSQL types corresponding to their + underlying integral types (see table above). The default + NULL semantics is NOT NULL. For + example:

+ +
+enum color {red, green, blue};
+enum class taste: unsigned char
+{
+  bitter = 1,
+  sweet,
+  sour = 4,
+  salty
+};
+
+#pragma db object
+class object
+{
+  ...
+
+  color color_; // Automatically mapped to INTEGER.
+  taste taste_; // Automatically mapped to SMALLINT.
+};
+  

Note also that because PostgreSQL does not support unsigned integers, the unsigned short, unsigned int, and @@ -21174,9 +21220,31 @@ class object object ids that are mapped to these Oracle types, an empty string is an invalid value.

-

Additionally, by default, C++ enumerations are automatically - mapped to NUMBER(10) with the default NULL - semantics being NOT NULL.

+

Additionally, by default, C++ enums and C++11 enum classes are + automatically mapped to the Oracle types corresponding to their + underlying integral types (see table above). The default + NULL semantics is NOT NULL. For + example:

+ +
+enum color {red, green, blue};
+enum class taste: unsigned char
+{
+  bitter = 1,
+  sweet,
+  sour = 4,
+  salty
+};
+
+#pragma db object
+class object
+{
+  ...
+
+  color color_; // Automatically mapped to NUMBER(10).
+  taste taste_; // Automatically mapped to NUMBER(3).
+};
+  

It is also possible to add support for additional Oracle types, such as XML, geospatial types, user-defined types, @@ -22114,9 +22182,31 @@ class object always change this mapping using the db type pragma (Section 14.4.3, "type").

-

Additionally, by default, C++ enumerations are automatically - mapped to INT with the default NULL - semantics being NOT NULL.

+

Additionally, by default, C++ enums and C++11 enum classes are + automatically mapped to the SQL Server types corresponding to their + underlying integral types (see table above). The default + NULL semantics is NOT NULL. For + example:

+ +
+enum color {red, green, blue};
+enum class taste: unsigned char
+{
+  bitter = 1,
+  sweet,
+  sour = 4,
+  salty
+};
+
+#pragma db object
+class object
+{
+  ...
+
+  color color_; // Automatically mapped to INT.
+  taste taste_; // Automatically mapped to TINYINT.
+};
+  

Note also that because SQL Server does not support unsigned integers, the unsigned short, unsigned int, and -- cgit v1.1