Nugget
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
eastl::linked_ptr< T, Deleter > Class Template Reference

#include <linked_ptr.h>

Inheritance diagram for eastl::linked_ptr< T, Deleter >:
Inheritance graph
[legend]
Collaboration diagram for eastl::linked_ptr< T, Deleter >:
Collaboration graph
[legend]

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_ptroperator= (const linked_ptr &linkedPtr)
 
template<typename U , typename D >
linked_ptroperator= (const linked_ptr< U, D > &linkedPtr)
 
template<typename U >
linked_ptroperator= (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_basempPrev
 
linked_ptr_basempNext
 

Detailed Description

template<typename T, typename Deleter = smart_ptr_deleter<T>>
class eastl::linked_ptr< T, Deleter >

linked_ptr

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).

Member Typedef Documentation

◆ bool_

template<typename T , typename Deleter = smart_ptr_deleter<T>>
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).

◆ element_type

template<typename T , typename Deleter = smart_ptr_deleter<T>>
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.

◆ this_type

template<typename T , typename Deleter = smart_ptr_deleter<T>>
typedef linked_ptr<T> eastl::linked_ptr< T, Deleter >::this_type
protected

this_type This is an alias for linked_ptr<T>, this class.

Constructor & Destructor Documentation

◆ linked_ptr() [1/4]

template<typename T , typename Deleter = smart_ptr_deleter<T>>
eastl::linked_ptr< T, Deleter >::linked_ptr ( )
inline

linked_ptr Default constructor.

◆ linked_ptr() [2/4]

template<typename T , typename Deleter = smart_ptr_deleter<T>>
template<typename U >
eastl::linked_ptr< T, Deleter >::linked_ptr ( U *  pValue)
inlineexplicit

linked_ptr Takes ownership of the pointer. It is OK if the input pointer is null.

◆ linked_ptr() [3/4]

template<typename T , typename Deleter = smart_ptr_deleter<T>>
eastl::linked_ptr< T, Deleter >::linked_ptr ( const linked_ptr< T, Deleter > &  linkedPtr)
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.

◆ linked_ptr() [4/4]

template<typename T , typename Deleter = smart_ptr_deleter<T>>
template<typename U , typename D >
eastl::linked_ptr< T, Deleter >::linked_ptr ( const linked_ptr< U, D > &  linkedPtr)
inline

linked_ptr Shares ownership of a pointer with another instance of linked_ptr.

◆ ~linked_ptr()

template<typename T , typename Deleter = smart_ptr_deleter<T>>
eastl::linked_ptr< T, Deleter >::~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.

Member Function Documentation

◆ detach()

template<typename T , typename Deleter = smart_ptr_deleter<T>>
T* eastl::linked_ptr< T, Deleter >::detach ( )
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).

◆ force_delete()

template<typename T , typename Deleter = smart_ptr_deleter<T>>
void eastl::linked_ptr< T, Deleter >::force_delete ( )
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).

◆ get()

template<typename T , typename Deleter = smart_ptr_deleter<T>>
T* eastl::linked_ptr< T, Deleter >::get ( ) const
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.

◆ operator!()

template<typename T , typename Deleter = smart_ptr_deleter<T>>
bool eastl::linked_ptr< T, Deleter >::operator! ( )
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.

◆ operator*()

template<typename T , typename Deleter = smart_ptr_deleter<T>>
T& eastl::linked_ptr< T, Deleter >::operator* ( ) const
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.

◆ operator->()

template<typename T , typename Deleter = smart_ptr_deleter<T>>
T* eastl::linked_ptr< T, Deleter >::operator-> ( ) const
inline

operator-> Allows access to the owned pointer via operator->()

◆ operator=() [1/3]

template<typename T , typename Deleter = smart_ptr_deleter<T>>
linked_ptr& eastl::linked_ptr< T, Deleter >::operator= ( const linked_ptr< T, Deleter > &  linkedPtr)
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.

◆ operator=() [2/3]

template<typename T , typename Deleter = smart_ptr_deleter<T>>
template<typename U , typename D >
linked_ptr& eastl::linked_ptr< T, Deleter >::operator= ( const linked_ptr< U, D > &  linkedPtr)
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.

◆ operator=() [3/3]

template<typename T , typename Deleter = smart_ptr_deleter<T>>
template<typename U >
linked_ptr& eastl::linked_ptr< T, Deleter >::operator= ( U *  pValue)
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.

◆ reset() [1/2]

template<typename T , typename Deleter = smart_ptr_deleter<T>>
void eastl::linked_ptr< T, Deleter >::reset ( )
inline

reset Resets the container with NULL. If the current pointer is non-NULL, it is unlinked and possibly destroyed.

◆ reset() [2/2]

template<typename T , typename Deleter = smart_ptr_deleter<T>>
template<typename U >
void eastl::linked_ptr< T, Deleter >::reset ( U *  pValue)
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.

◆ unique()

template<typename T , typename Deleter = smart_ptr_deleter<T>>
bool eastl::linked_ptr< T, Deleter >::unique ( ) const
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.

◆ use_count()

template<typename T , typename Deleter = smart_ptr_deleter<T>>
int eastl::linked_ptr< T, Deleter >::use_count ( ) const
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.


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