UCommon
Public Member Functions | Protected Member Functions | Protected Attributes
ucommon::AutoObject Class Reference

A general purpose smart pointer helper class. More...

#include <object.h>

Inheritance diagram for ucommon::AutoObject:
Inheritance graph
[legend]
Collaboration diagram for ucommon::AutoObject:
Collaboration graph
[legend]

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

ObjectProtocolobject
 

Detailed Description

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.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 137 of file object.h.

Constructor & Destructor Documentation

◆ AutoObject() [1/2]

ucommon::AutoObject::AutoObject ( ObjectProtocol object)
protected

Construct an auto-pointer referencing an existing object.

Parameters
objectwe point to.

◆ AutoObject() [2/2]

ucommon::AutoObject::AutoObject ( const AutoObject pointer)
protected

Construct an auto-pointer as a copy of another pointer.

The retention of the object being pointed to will be increased.

Parameters
pointerwe are a copy of.

◆ ~AutoObject()

ucommon::AutoObject::~AutoObject ( )
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.

Member Function Documentation

◆ operator bool()

ucommon::AutoObject::operator bool ( ) const

Test if the pointer is referencing an object.

Returns
true if the pointer is currently referencing an object.

◆ operator!()

bool ucommon::AutoObject::operator! ( ) const

Test if the pointer is not set.

Returns
true if the pointer is not referencing anything.

◆ release()

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.

◆ set()

void ucommon::AutoObject::set ( ObjectProtocol object)
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.

Parameters
objectto assign to.

The documentation for this class was generated from the following file: