Implements pairs of reciprocally-connected pointers. More...
#include <reciprocal.hpp>
Public Member Functions | |
| Reciprocal_ptr (T *data) | |
constructs a Reciprocal_ptr and sets its mine to data (which can be null) | |
| operator bool () const | |
returns true iff this is not null | |
| U * | get () |
| U & | operator* () |
obtains a reference to the object this points to | |
| U * | operator-> () |
accesses the members of the object this points to | |
| U & | value () |
obtains a reference to the object this points to | |
| const U * | get () const |
| const U & | operator* () const |
obtains a reference to the object this points to | |
| const U * | operator-> () const |
accesses the members of the object this points to | |
| const U & | value () const |
obtains a reference to the object this points to | |
Public Member Functions inherited from hexed::mutual::Single< T, U > | |
| Single () | |
Constructs a Single with no partner (it is "unpaired") | |
| Single (const Single &)=delete | |
| Single (Single &&that) | |
steals that's partner, if it has one, leaving that unpaired | |
| Single & | operator= (const Single &)=delete |
| Single & | operator= (Single &&that) |
disconnects this from its partner, if it has one, and steals that's, if it has one | |
| void | pair (Base< U, T > &that) |
mutually connects this with that | |
| void | unpair () |
mutually disconnects this from that | |
| bool | paired () const |
returns true iff this is currently paired with a partner | |
| Base< U, T > * | partner () |
provides access to this's partner | |
| const Base< U, T > * | partner () const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Public Attributes | |
| Mortal_ptr< T > | mine |
The object that this is a proxy for in reciprocal connections. | |
Additional Inherited Members | |
Protected Member Functions inherited from hexed::mutual::Base< T, U > | |
| void | _connect (Base< U, T > &that) |
mutually connects this and that by calling both of their _set() member functions | |
| void | _disconnect (Base< U, T > &that) |
mutually disconnects this and that by calling both of their _unset() member functions | |
Static Protected Member Functions inherited from hexed::mutual::Base< T, U > | |
| static U * | _yours (Base< U, T > &that) |
Accesses the _mine() of that | |
| static const U * | _yours (const Base< U, T > &that) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Implements pairs of reciprocally-connected pointers.
This class addresses the case where object a needs to have a pointer to object b iff object b has a pointer to a. This might sound like exactly what mutual::Single does, but the problem is that a Single<T, U> can only point to a Single<U, T>. If you want an object to have a variety of reciprocal pointers to objects of multiple different types, you need another layer of indirection: a has a dedicated member which is a pointer object that derives from Single to point to b, and b needs to have a pointer object that points to a, and these pointers need to know about each other to enforce reciprocity. Furthermore, both a and b must be derived from Mortal. That is what this class provides. If you want objects of class A and of class B to be able to point to each other, give them members of type Reciprocal_ptr<A, B> and Reciprocal_ptr<B, A>, respectively, and pair() the Reciprocal_ptrs.
|
inline |
obtains a reference to the object this points to
undefined behavior if this is null
|
inline |
obtains a reference to the object this points to
undefined behavior if this is null
|
inline |
accesses the members of the object this points to
undefined behavior if this is null
|
inline |
accesses the members of the object this points to
undefined behavior if this is null
|
inline |
obtains a reference to the object this points to
throws an exception if this is null
|
inline |
obtains a reference to the object this points to
throws an exception if this is null
| Mortal_ptr<T> hexed::Reciprocal_ptr< T, U >::mine |
The object that this is a proxy for in reciprocal connections.
Usually, this will be a member of the object mine points to, but that is not technically necessary. The user should feel free to modify this data member at will (including setting it to null).