From a007b0a02adf04fdfe84a6169b03596fca490131 Mon Sep 17 00:00:00 2001
From: Boris Kolpackov
+ 7.3 NULL
Value Semantics
@@ -2002,8 +2002,9 @@ class name
create dynamically allocated instances of persistent classes and
return pointers to these instances. As we will see in later chapters,
pointers are also used to establish relationships between objects
- (Chapter 6, Relationships) as well as to cache
- persistent objects in a session (Chapter 9, Session).7.3 Pointers and NULL
Value Semantics
By default, all these mechanisms use raw pointers to return, pass, and cache objects. This is normally sufficient for applications @@ -3747,7 +3748,10 @@ private: behaves like a value type. That is, when an object is made persistent, the elements of the container are stored in the database. Similarly, when a persistent object is loaded from the database, the contents - of the container are automatically loaded as well.
+ of the container are automatically loaded as well. A data member + of a container type can also use a smart pointer, as discussed + in Section 7.3, "Pointers andNULL
+ Value Semantics".
While an ordinary member is mapped to one or more columns in the object's table, a member of a container type is mapped to a separate @@ -5407,7 +5411,7 @@ CREATE TABLE person_nickname (
Similar to columns, we can make the table prefix empty.
-NULL
Value SemanticsNULL
Value SemanticsRelational database systems have a notion of the special
NULL
value that is used to indicate the absence
@@ -5570,6 +5574,31 @@ class person
Qt), provide support for smart pointers found in these frameworks
and libraries (Part III, "Profiles").
Currently, ODB supports the NULL
semantics only
+ for simple values. In future versions this support will be extended
+ to composite values and containers. With this limitation in mind,
+ we can still use smart pointers in data members of composite value
+ and container types. The only restriction is that these pointers
+ must not be NULL
. For example:
+#pragma db value +struct name +{ + std::string first_; + std::string last_; +}; + +#pragma db object +class person +{ + ... + + std::auto_ptr<name> name_; + std::auto_ptr<std::vector<name> > aliases_; +}; ++ @@ -6710,10 +6739,10 @@ typedef shared_ptr<person> person_ptr;
For a more detailed discussion of the NULL
semantics
- for values, refer to Section 7.3, "NULL
- Value Semantics". For a more detailed discussion of the
- NULL
semantics for object pointers, refer to
- Chapter 6, "Relationships".
NULL
Value Semantics". For a more detailed
+ discussion of the NULL
semantics for object pointers,
+ refer to Chapter 6, "Relationships".
default
not_null
specifier), then a warning is issued.
For a more detailed discussion of the NULL
semantics
- for values, refer to Section 7.3, "NULL
- Value Semantics". For a more detailed discussion of the
- NULL
semantics for object pointers, refer to
- Chapter 6, "Relationships".
NULL
Value Semantics". For a more detailed
+ discussion of the NULL
semantics for object pointers,
+ refer to Chapter 6, "Relationships".
default
NULL
Value Semantics".
- When used as a pointer to a value, only boost::shared_ptr
- is supported. For example:
+ Section 7.3, "Pointers and NULL
Value
+ Semantics". When used as a pointer to a value, only
+ boost::shared_ptr
is supported. For example:
#pragma db object @@ -10067,8 +10096,8 @@ class personIn a relational database
boost::optional
is mapped to a column that can have aNULL
value. Similar to -odb::nullable
(Section 7.3, - "NULL
Value Semantics"), it can be used to add the +odb::nullable
(Section 7.3, "Pointers and +NULL
Value Semantics"), it can be used to add theNULL
semantics to existing C++ types. For example:@@ -10515,9 +10544,9 @@ class Person refer to Section 3.2, "Object Pointers" and Chapter 6, "Relationships". For more information on using smart pointers as pointers to values, refer to - Section 7.3, "NULL
Value Semantics". - When used as a pointer to a value, onlyQSharedPointer
- is supported. For example: + Section 7.3, "Pointers andNULL
Value + Semantics". When used as a pointer to a value, only +QSharedPointer
is supported. For example:#pragma db object @@ -10751,7 +10780,7 @@ class Person theINTEGER
type represents a clock time as the number of seconds since midnight. These mappings have to be explicitly requested using thedb type
pragma - (Section 10.3.3,value "type
"), as shown + (Section 10.3.3, "type
"), as shown in the following example:-- cgit v1.1