Nugget
|
#include <linked_ptr.h>
Public Types | |
typedef T | element_type |
typedef T *(this_type::* | bool_) () const |
Public Member Functions | |
linked_ptr () | |
template<typename U > | |
linked_ptr (U *pValue) | |
linked_ptr (const linked_ptr &linkedPtr) | |
template<typename U , typename D > | |
linked_ptr (const linked_ptr< U, D > &linkedPtr) | |
~linked_ptr () | |
linked_ptr & | operator= (const linked_ptr &linkedPtr) |
template<typename U , typename D > | |
linked_ptr & | operator= (const linked_ptr< U, D > &linkedPtr) |
template<typename U > | |
linked_ptr & | operator= (U *pValue) |
template<typename U > | |
void | reset (U *pValue) |
void | reset () |
T & | operator* () const |
T * | operator-> () const |
T * | get () const |
int | use_count () const |
bool | unique () const |
operator bool_ () const | |
bool | operator! () |
T * | detach () |
void | force_delete () |
Protected Types | |
typedef linked_ptr< T > | this_type |
typedef Deleter | deleter_type |
deleter_type | |
Protected Member Functions | |
template<typename U , typename D > | |
void | link (const linked_ptr< U, D > &linkedPtr) |
The owned pointer. | |
Protected Attributes | |
T * | mpValue |
Additional Inherited Members | |
Public Attributes inherited from eastl::linked_ptr_base | |
linked_ptr_base * | mpPrev |
linked_ptr_base * | mpNext |
This class implements a linked_ptr template. A linked_ptr is like the C++ Standard Library auto_ptr except that it allows sharing of pointers between instances of auto_ptr via reference counting. linked_ptr objects can safely be copied and can safely be used in C++ Standard Library containers such as std::vector or std::list. This implementation, however, is not thread-safe. you would need to use a separate linked_ptr_mt (multi-threaded) to get thread safety.
linked_ptr is a variation of shared_ptr (a.k.a. counted_ptr) which differs in that instead of being implemented by a shared integer stored on the heap, it is implemented by linked list stored within the linked_ptr object itself. The result is that no memory is explicitly allocated from the heap, though the cost of each linked_ptr object is 12 bytes of memory (32 bit machine) instead of 4 bytes for the case of shared_ptr (depending on the heap).
typedef T*(this_type::* eastl::linked_ptr< T, Deleter >::bool_) () const |
Implicit operator bool Allows for using a linked_ptr as a boolean. Note that below we do not use operator bool(). The reason for this is that booleans automatically convert up to short, int, float, etc. The result is that this: if(linkedPtr == 1) would yield true (bad).
typedef T eastl::linked_ptr< T, Deleter >::element_type |
element_type Synonym for type T, useful for external code to reference the type in a generic way.
|
protected |
this_type This is an alias for linked_ptr<T>, this class.
|
inline |
linked_ptr Default constructor.
|
inlineexplicit |
linked_ptr Takes ownership of the pointer. It is OK if the input pointer is null.
|
inline |
linked_ptr Construction with self type. If we want a shared_ptr constructor that is templated on linked_ptr, then we need to make it in addition to this function, as otherwise the compiler will generate this function and things will go wrong.
|
inline |
linked_ptr Shares ownership of a pointer with another instance of linked_ptr.
|
inline |
~linked_ptr Removes this object from the of objects using the shared pointer. If this object is the last owner of the shared pointer, the shared pointer is deleted.
|
inline |
detach Returns ownership of the pointer to the caller. Fixes all references to the pointer by any other owners to be NULL. This function can work properly only if all entries in the list refer to type T and none refer to any other type (e.g. U).
|
inline |
force_delete Forces deletion of the shared pointer. Fixes all references to the pointer by any other owners to be NULL. This function can work properly only if all entries in the list refer to type T and none refer to any other type (e.g. U).
|
inline |
get Returns the owned pointer. Note that this class does not provide an operator T() function. This is because such a thing (automatic conversion) is deemed unsafe.
|
inline |
operator! This returns the opposite of operator bool; it returns true if the owned pointer is null. Some compilers require this and some don't.
|
inline |
swap Exchanges the owned pointer beween two linkedPtr objects.
This function is disabled as it is currently deemed unsafe. The problem is that the only way to implement this function is to transfer pointers between the objects; you cannot transfer the linked list membership between the objects. Thus unless both linked_ptr objects were 'unique()', the shared pointers would be duplicated amongst containers, resulting in a crash. operator* Returns the owner pointer dereferenced.
|
inline |
operator-> Allows access to the owned pointer via operator->()
|
inline |
operator= If we want a shared_ptr operator= that is templated on linked_ptr, then we need to make it in addition to this function, as otherwise the compiler will generate this function and things will go wrong.
|
inline |
operator= Copies another linked_ptr to this object. Note that this object may already own a shared pointer with another different pointer (but still of the same type) before this call. In that case, this function removes ownership of the old pointer and takes shared ownership of the new pointer and increments its reference count.
|
inline |
operator= Assigns a new pointer. If the new pointer is equivalent to the current pointer, nothing is done. Otherwise the current pointer is unlinked and possibly destroyed. The new pointer can be NULL.
|
inline |
reset Resets the container with NULL. If the current pointer is non-NULL, it is unlinked and possibly destroyed.
|
inline |
reset Releases the owned pointer and takes ownership of the passed in pointer. If the passed in pointer is the same as the owned pointer, nothing is done. The passed in pointer can be NULL, in which case the use count is set to 1.
|
inline |
unique Returns true if the use count of the owned pointer is one. The return value is true if the owned pointer is null.
|
inline |
use_count Returns the use count of the shared pointer. The return value is one if the owned pointer is null. This function is provided for compatibility with the proposed C++ standard and for debugging purposes. It is not intended for runtime use given that its execution time is not constant.