ucommon
7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
![]() ![]() |
Smart pointer base class for auto-retained objects. More...
#include <typeref.h>
Classes | |
class | Counted |
Heap base-class container for typeref objects. More... | |
Public Member Functions | |
virtual | ~TypeRef () |
Destroy pointer when falling out of scope. More... | |
void | set (const TypeRef &pointer) |
Set our smart pointer based on another pointer instance. More... | |
void | clear (void) |
Manually release the current container. More... | |
size_t | size (void) const |
Get size of referenced heap object. More... | |
unsigned | copies () const |
Get number of references to container. More... | |
operator bool () const | |
Check if pointer currently has a heap container. More... | |
bool | operator! () const |
Check if we are currently not pointing to anything. More... | |
bool | is_released (void) |
Static Public Member Functions | |
static void | put (TypeRef &target, Counted *object) |
Special weak-public means to copy a container reference. More... | |
Protected Member Functions | |
TypeRef (Counted *object) | |
Create a smart pointer referencing an existing heap object. More... | |
TypeRef (const TypeRef &pointer) | |
Create a smart pointer based on another pointer. More... | |
TypeRef () | |
Create a smart pointer referencing nothing. More... | |
void | set (Counted *object) |
Set our smart pointer to a specific heap container. More... | |
void | assign (const typeref_guard &ref) |
Assign from a guarded typeref. More... | |
Static Protected Member Functions | |
static caddr_t | mem (caddr_t address) |
Adjust memory pointer to atomic boundry. More... | |
Protected Attributes | |
Counted * | ref |
Friends | |
class | ArrayRef |
class | SharedRef |
class | MapRef |
class | TypeRelease |
Smart pointer base class for auto-retained objects.
The underlying container is heap allocated and page aligned. A heap object is automatically de-referenced by release during destruction. The smart pointer is a protected base class used to derive strongly typed templates.
|
protected |
Create a smart pointer referencing an existing heap object.
object | to reference. |
Definition at line 70 of file typeref.cpp.
References ref, and ucommon::TypeRef::Counted::retain().
|
protected |
Create a smart pointer based on another pointer.
Both pointers then reference the same object.
pointer | instance to share reference with. |
Definition at line 77 of file typeref.cpp.
References ucommon::copy(), ref, and ucommon::TypeRef::Counted::retain().
|
protected |
Create a smart pointer referencing nothing.
Definition at line 65 of file typeref.cpp.
References ref.
|
virtual |
Destroy pointer when falling out of scope.
This de-references the heap container.
Definition at line 84 of file typeref.cpp.
References clear().
|
protected |
Assign from a guarded typeref.
Definition at line 115 of file typeref.cpp.
References ucommon::Mutex::acquire(), clear(), ref, ucommon::Mutex::release(), ucommon::TypeRef::Counted::retain(), and ucommon::typeref_guard::sync.
Referenced by ucommon::typeref< T, R >::operator=(), ucommon::typeref< T, R >::typeref(), ucommon::typeref< const char * >::typeref(), and ucommon::typeref< const uint8_t * >::typeref().
void ucommon::TypeRef::clear | ( | void | ) |
Manually release the current container.
Definition at line 89 of file typeref.cpp.
References ref, and ucommon::TypeRef::Counted::release().
Referenced by assign(), set(), ucommon::typeref< T, R >::set(), and ~TypeRef().
unsigned ucommon::TypeRef::copies | ( | ) | const |
Get number of references to container.
Definition at line 512 of file typeref.cpp.
References ucommon::TypeRef::Counted::copies(), and ref.
bool ucommon::TypeRef::is_released | ( | void | ) |
Definition at line 96 of file typeref.cpp.
References ucommon::TypeRef::Counted::autorelease, and ref.
Adjust memory pointer to atomic boundry.
address | that was allocated. |
Definition at line 133 of file typeref.cpp.
References ucommon::addr(), and ucommon::Thread::cache().
Referenced by ucommon::ArrayRef::create(), ucommon::MapRef::create(), ucommon::typeref< T, R >::set(), and ucommon::typeref< T, R >::typeref().
|
inline |
|
inline |
Special weak-public means to copy a container reference.
This uses the base class container which is not public, so only derived type specific smart pointers can actually use this method. It is made public because making it protected actually makes it inaccessible to template derived classes.
target | smart pointer object to set. |
object | to have it reference. |
Definition at line 259 of file typeref.h.
References set().
Referenced by ucommon::arrayref< T >::put().
void ucommon::TypeRef::set | ( | const TypeRef & | pointer | ) |
Set our smart pointer based on another pointer instance.
If we are already referencing, we release the current container.
pointer | instance to share reference with. |
Definition at line 107 of file typeref.cpp.
References clear(), ref, and ucommon::TypeRef::Counted::retain().
|
protected |
Set our smart pointer to a specific heap container.
If we were pointing to something already we release that.
object | to reference. |
Definition at line 125 of file typeref.cpp.
Referenced by ucommon::arrayref< T >::operator=(), ucommon::listref< T >::operator=(), ucommon::mapref< K, V >::operator=(), ucommon::queueref< T >::operator=(), ucommon::stackref< T >::operator=(), ucommon::typeref< T, R >::operator=(), put(), ucommon::ArrayRef::realloc(), ucommon::stackref< T >::release(), ucommon::queueref< T >::release(), ucommon::arrayref< T >::release(), ucommon::ArrayRef::resize(), ucommon::typeref_guard::set(), ucommon::typeref< T, R >::set(), and ucommon::typeref< T, R >::typeref().
size_t ucommon::TypeRef::size | ( | void | ) | const |
Get size of referenced heap object.
Definition at line 504 of file typeref.cpp.
References ref, and ucommon::TypeRef::Counted::size.
Referenced by ucommon::MapRef::Map::access(), ucommon::TypeRelease::allocate(), ucommon::ArrayRef::ArrayRef(), ucommon::ArrayRef::Array::assign(), ucommon::ArrayRef::Array::count(), ucommon::ArrayRef::create(), ucommon::MapRef::Map::create(), ucommon::stringref< R >::create(), ucommon::byteref< R >::create(), ucommon::ArrayRef::Array::dealloc(), ucommon::MapRef::Map::dealloc(), ucommon::MapRef::Instance::eol(), ucommon::ArrayRef::Array::get(), ucommon::Cipher::Key::Key(), ucommon::MapRef::Map::modify(), ucommon::MapRef::Instance::next(), ucommon::ArrayRef::realloc(), ucommon::MapRef::Map::remove(), ucommon::ArrayRef::Array::remove(), ucommon::ArrayRef::resize(), ucommon::Cipher::Key::set(), ucommon::HMAC::set(), and ucommon::byteref< R >::set().
|
friend |
|
protected |
Definition at line 164 of file typeref.h.
Referenced by ucommon::MapRef::access(), ucommon::MapRef::add(), ucommon::MapRef::append(), ucommon::ArrayRef::ArrayRef(), assign(), ucommon::MapRef::Instance::assign(), ucommon::ArrayRef::assign(), clear(), ucommon::MapRef::commit(), copies(), ucommon::ArrayRef::count(), ucommon::MapRef::count(), ucommon::SharedRef::get(), ucommon::ArrayRef::get(), ucommon::MapRef::Instance::Instance(), is_released(), ucommon::MapRef::modify(), ucommon::typeref< T, R >::operator const T &(), ucommon::sharedref< T >::operator typeref< T >(), ucommon::typeref< T, R >::operator()(), ucommon::sharedref< T >::operator*(), ucommon::typeref< T, R >::operator*(), ucommon::typeref< T, R >::operator->(), ucommon::typeref< const char * >::operator<(), ucommon::typeref< T, R >::operator==(), ucommon::ArrayRef::pop(), ucommon::ArrayRef::pull(), ucommon::ArrayRef::push(), ucommon::SharedRef::put(), ucommon::ArrayRef::realloc(), ucommon::MapRef::release(), ucommon::MapRef::remove(), ucommon::ArrayRef::reset(), ucommon::ArrayRef::resize(), set(), size(), TypeRef(), ucommon::MapRef::update(), and ucommon::MapRef::used().