UCommon
|
A general purpose smart pointer helper class. More...
#include <object.h>
Public Member Functions | |
operator bool () const | |
Test if the pointer is referencing an object. More... | |
bool | operator! () const |
Test if the pointer is not set. More... | |
void | release (void) |
Manually release the pointer. More... | |
Protected Member Functions | |
AutoObject (ObjectProtocol *object) | |
Construct an auto-pointer referencing an existing object. More... | |
AutoObject (const AutoObject &pointer) | |
Construct an auto-pointer as a copy of another pointer. More... | |
void | set (ObjectProtocol *object) |
Set our pointer to a specific object. More... | |
~AutoObject () | |
Delete auto pointer. More... | |
Protected Attributes | |
ObjectProtocol * | object |
A general purpose smart pointer helper class.
This is particularly useful in conjunction with reference counted objects which can be managed and automatically removed from the heap when they are no longer being referenced by a smart pointer. The smart pointer itself would normally be constructed and initialized as an auto variable in a method call, and will dereference the object when the pointer falls out of scope. This is actually a helper class for the typed pointer template.
|
protected |
Construct an auto-pointer referencing an existing object.
object | we point to. |
|
protected |
Construct an auto-pointer as a copy of another pointer.
The retention of the object being pointed to will be increased.
pointer | we are a copy of. |
|
protected |
Delete auto pointer.
When it falls out of scope, the retention of the object it references is reduced. If it falls to zero in a reference counted object, then the object is auto-deleted.
ucommon::AutoObject::operator bool | ( | ) | const |
Test if the pointer is referencing an object.
bool ucommon::AutoObject::operator! | ( | ) | const |
Test if the pointer is not set.
void ucommon::AutoObject::release | ( | void | ) |
Manually release the pointer.
This reduces the retention level of the object and resets the pointer to point to nobody.
|
protected |
Set our pointer to a specific object.
If the pointer currently references another object, that object is released. The pointer references our new object and that new object is retained.
object | to assign to. |