Wt
3.3.8
|
A weak pointer for a database object. More...
#include <Wt/Dbo/weak_ptr>
Public Member Functions | |
weak_ptr () | |
Creates a new weak pointer. More... | |
weak_ptr (const weak_ptr< C > &other) | |
Copy constructor. | |
void | reset (C *obj=0) |
Sets the value. More... | |
weak_ptr< C > & | operator= (const weak_ptr< C > &other) |
Assignment operator. More... | |
weak_ptr< C > & | operator= (const ptr< C > &other) |
Assignment operator. More... | |
const C * | operator-> () const |
Dereference operator. More... | |
C * | modify () const |
Dereference operator, for writing. More... | |
bool | operator== (const weak_ptr< C > &other) const |
Comparison operator. More... | |
bool | operator== (const ptr< C > &other) const |
Comparison operator. More... | |
bool | operator!= (const weak_ptr< C > &other) const |
Comparison operator. More... | |
bool | operator!= (const ptr< C > &other) const |
Comparison operator. More... | |
operator bool () const | |
Checks for null. More... | |
operator ptr< C > () const | |
Casting operator to a ptr. More... | |
ptr< C > | query () const |
Promotes to a ptr. More... | |
ptr< C > | lock () const |
Promotes to a ptr. More... | |
dbo_traits< C >::IdType | id () const |
Returns the object id. More... | |
A weak pointer for a database object.
A weak_ptr has similar API and capabilities as a ptr, but does not actually store a reference to the object itself. Instead, it uses a query to retrieve the object.
It is used only to implement a OneToOne relation:
This cannot be implemented using two plain ptr's because otherwise a cycle would be created which interferes with the count-based shared pointer implementation of ptr.
Only in a OneToOne relation, the required querying logic for the weak_ptr to function properly is provided by the hasOne() call, and thus a weak_ptr cannot be used outside of a OneToOne relation.
The weak_ptr has almost the same capabilities as a ptr, except that it does not provide a dereference operator (*).
It's important to realize that reading a weak_ptr results in a query, and thus you may want to first convert the weak_ptr into a plain ptr when needing multiple operations.
A Wt::Dbo::ptr<C> can be converted to a Wt::Dbo::ptr<const C> when extracting data from Dbo objects. There are overloads for the copy constructor, copy assignment, and comparison operators to make this work as expected.
Wt::Dbo::weak_ptr< C >::weak_ptr | ( | ) |
Creates a new weak pointer.
The ptr does not point to anything.
dbo_traits< C >::IdType Wt::Dbo::weak_ptr< C >::id | ( | ) | const |
Returns the object id.
Since this needs to query the value, you should have an active transaction.
ptr< C > Wt::Dbo::weak_ptr< C >::lock | ( | ) | const |
Promotes to a ptr.
Returns the value as a plain ptr.
Since this needs to query the value, you should have an active transaction.
This is equivalent to query() or the ptr<C> cast operator.
weak_ptr< C >::mutator Wt::Dbo::weak_ptr< C >::modify | ( | ) | const |
Dereference operator, for writing.
Returns the underlying object (or, rather, a proxy for it) with the intention to modify it. The proxy object will mark the object as dirty from its destructor. An involved modification should therefore preferably be implemented as a separate method or function to make sure that the object is marked as dirty after the whole modification:
Since this needs to query the value, you should have an active transaction.
|
explicit |
Checks for null.
Returns true if the pointer is pointing to a non-null object.
Since this needs to query the value, you should have an active transaction.
Wt::Dbo::weak_ptr< C >::operator ptr< C > | ( | ) | const |
Casting operator to a ptr.
Returns the value as a plain ptr.
Since this needs to query the value, you should have an active transaction.
bool Wt::Dbo::weak_ptr< C >::operator!= | ( | const weak_ptr< C > & | other | ) | const |
Comparison operator.
Two pointers are equal if and only if they reference the same database object.
Since this needs to query the value, you should have an active transaction.
bool Wt::Dbo::weak_ptr< C >::operator!= | ( | const ptr< C > & | other | ) | const |
Comparison operator.
Two pointers are equal if and only if they reference the same database object.
Since this needs to query the value, you should have an active transaction.
weak_ptr< C >::accessor Wt::Dbo::weak_ptr< C >::operator-> | ( | ) | const |
Dereference operator.
Note that this operator returns a const copy of the referenced object. Use modify() to get a non-const reference.
Since this needs to query the value, you should have an active transaction.
weak_ptr< C > & Wt::Dbo::weak_ptr< C >::operator= | ( | const weak_ptr< C > & | other | ) |
Assignment operator.
Since this needs to query the previous value, you should have an active transaction.
weak_ptr< C > & Wt::Dbo::weak_ptr< C >::operator= | ( | const ptr< C > & | other | ) |
Assignment operator.
Since this needs to query the previous value, you should have an active transaction.
bool Wt::Dbo::weak_ptr< C >::operator== | ( | const weak_ptr< C > & | other | ) | const |
Comparison operator.
Two pointers are equal if and only if they reference the same database object.
Since this needs to query the value, you should have an active transaction.
bool Wt::Dbo::weak_ptr< C >::operator== | ( | const ptr< C > & | other | ) | const |
Comparison operator.
Two pointers are equal if and only if they reference the same database object.
Since this needs to query the value, you should have an active transaction.
ptr< C > Wt::Dbo::weak_ptr< C >::query | ( | ) | const |
Promotes to a ptr.
Returns the value as a plain ptr.
Since this needs to query the value, you should have an active transaction.
This is equivalent to lock() or the ptr<C> cast operator.
void Wt::Dbo::weak_ptr< C >::reset | ( | C * | obj = 0 | ) |
Sets the value.
This is assigns a new value, and:
is equivalent to:
Since this needs to query the previous value, you should have an active transaction.