Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::base::SharedPtr< T > Class Template Reference

A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting. More...

#include "sharedptr.h"

Inheritance diagram for ion::base::SharedPtr< T >:

Public Member Functions

 SharedPtr ()
 The default constructor initializes the pointer to NULL. More...
 
 SharedPtr (T *shared)
 Constructor that takes a raw shared pointer. More...
 
template<typename U >
 SharedPtr (const SharedPtr< U > &p)
 Constructor that allows sharing of a pointer to a type that is compatible with T*. More...
 
 SharedPtr (const SharedPtr< T > &p)
 The copy constructor shares the instance from the other pointer. More...
 
 ~SharedPtr ()
 
TGet () const
 Returns a raw pointer to the instance, which may be NULL. More...
 
void Reset (T *new_shared)
 Changes the pointer to point to the given shared, which may be NULL. More...
 
void Reset ()
 Make the SharedPtr point to NULL. More...
 
SharedPtr< T > & operator= (T *new_shared)
 Assignment to a raw pointer is the same as Reset(). More...
 
template<typename U >
SharedPtr< T > & operator= (U *new_shared)
 Allow assignment to a compatible raw pointer. More...
 
SharedPtr< T > & operator= (const SharedPtr< T > &p)
 Allow assignment to a SharedPtr of the same type. More...
 
template<typename U >
SharedPtr< T > & operator= (const SharedPtr< U > &p)
 Allow assignment to a compatible SharedPtr. More...
 
Toperator-> () const
 The -> operator forwards to the raw pointer. More...
 
Toperator* () const
 The * operator returns the underlying instance. More...
 
bool operator== (const SharedPtr< T > &p) const
 The equality operator returns true if the raw pointers are the same. More...
 
bool operator!= (const SharedPtr< T > &p) const
 The inequality operator returns true if the raw pointers differ. More...
 
void swap (SharedPtr< T > &p)
 STL-style function to swap the raw pointer with another SharedPtr without the need for copying. More...
 

Detailed Description

template<typename T>
class ion::base::SharedPtr< T >

A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting.

The class passed as the template parameter must support the following interface:

void IncrementRefCount() const; void DecrementRefCount() const;

The DecrementRefCount() function should typically delete the instance when the count goes to zero.

Note
the Shareable class supports exactly this interface, so any class derived from Shareable can be used automatically with SharedPtr.

If the type instantiating the SharedPtr is incomplete, only the following operations are supported:

  • Default construction.
  • Copy construction from a SharedPtr of the same type.
  • Destruction.
  • Get().
  • Reset() without arguments.
  • Assignment from a SharedPtr of the same type.
  • Operator* and Operator-> (although the latter is unlikely to be useful).
  • Operator== and Operator!=.
  • swap(). The remaining operators require a complete type:
  • Construction from a T*.
  • Copy construction requiring a type conversion.
  • Reset(args) with any arguments, even NULL.
  • Assignment from a T*.
  • Assignment from a SharedPtr requiring a type conversion.

Definition at line 60 of file sharedptr.h.

Constructor & Destructor Documentation

template<typename T>
ion::base::SharedPtr< T >::SharedPtr ( )
inline

The default constructor initializes the pointer to NULL.

Definition at line 63 of file sharedptr.h.

template<typename T>
ion::base::SharedPtr< T >::SharedPtr ( T shared)
inlineexplicit

Constructor that takes a raw shared pointer.

Definition at line 66 of file sharedptr.h.

template<typename T>
template<typename U >
ion::base::SharedPtr< T >::SharedPtr ( const SharedPtr< U > &  p)
inline

Constructor that allows sharing of a pointer to a type that is compatible with T*.

Definition at line 72 of file sharedptr.h.

template<typename T>
ion::base::SharedPtr< T >::SharedPtr ( const SharedPtr< T > &  p)
inline

The copy constructor shares the instance from the other pointer.

Definition at line 78 of file sharedptr.h.

template<typename T>
ion::base::SharedPtr< T >::~SharedPtr ( )
inline

Definition at line 82 of file sharedptr.h.

Member Function Documentation

template<typename T>
T* ion::base::SharedPtr< T >::Get ( ) const
inline

Returns a raw pointer to the instance, which may be NULL.

Definition at line 89 of file sharedptr.h.

Referenced by ion::gfx::AttributeArray::AddAttribute(), ion::gfx::Node::AddChild(), ion::text::FreeTypeFont::AddFallbackFont(), ion::text::FontManager::AddFont(), ion::text::FontManager::AddFontFromZipasset(), ion::remote::NodeGraphHandler::AddNode(), ion::gfx::Node::AddShape(), ion::gfx::Node::AddUniformBlock(), ion::base::StlAllocator< T >::allocate(), ion::base::Allocator::AllocateMemory(), ion::base::DataContainer::AllocatorDeleter(), ion::gfx::FramebufferObject::Attachment::Attachment(), ion::gfx::Renderer::BindFramebuffer(), ion::gfx::BufferObject::BufferSubData::BufferSubData(), ion::text::Builder::Build(), ion::image::NinePatch::BuildImage(), ion::gfxutils::BuildWireframeIndexBuffer(), ion::text::FontManager::CacheFontImage(), ion::gfx::BufferObject::CopySubData(), ion::base::DataContainer::CreateAndCopy(), ion::gfx::Renderer::CreateOrUpdateResources(), ion::gfx::Renderer::CreateOrUpdateShapeResources(), ion::base::Allocator::DeallocateMemory(), ion::base::internal_variant_utils::ManualConstructor< T15 >::Destroy(), ion::gfx::Renderer::DrawScene(), ion::base::DynamicPtrCast(), ion::gfx::BufferObject::GetData(), ion::text::Builder::GetFont(), ion::text::Builder::GetFontImageTexture(), ion::gfx::ShaderProgram::GetFragmentShader(), ion::gfxprofile::GpuProfiler::GetGraphicsManagerOrNull(), ion::gfx::TextureBase::Face::GetImage(), ion::gfx::TextureBase::GetImmutableImage(), ion::image::NinePatch::GetMinimumSize(), ion::base::AllocationManager::GetNonNullAllocator(), ion::image::NinePatch::GetPaddingBox(), ion::gfx::TextureBase::GetSampler(), ion::image::NinePatch::GetSizeToFitContent(), ion::gfx::ShaderProgram::GetVertexShader(), ion::gfx::ShaderInputRegistry::Include(), ion::base::internal_variant_utils::ManualConstructor< T15 >::Init(), ion::base::internal_variant_utils::ManualConstructor< T15 >::InitArray(), ion::gfx::Renderer::MapBufferObjectData(), ion::gfx::Renderer::MapBufferObjectDataRange(), ion::base::Notifier::Notify(), ion::gfx::FramebufferObject::Attachment::operator!=(), ion::base::SharedPtr< AllocationTracker >::operator=(), ion::base::WeakReferentPtr< FramebufferObject >::operator=(), ion::remote::HttpServer::RegisterHandler(), ion::remote::NodeGraphHandler::RemoveNode(), ion::gfx::Renderer::Renderer(), ion::gfx::AttributeArray::ReplaceAttribute(), ion::gfx::Node::ReplaceChild(), ion::gfx::Node::ReplaceShape(), ion::gfx::Node::ReplaceUniformBlock(), ion::gfx::Renderer::RequestForcedShapeUpdates(), ion::gfx::Renderer::RequestForcedUpdates(), ion::gfx::ResourceManager::RequestResourceInfo(), ion::gfx::Renderer::ResolveMultisampleFramebuffer(), ion::gfx::BufferObject::SetData(), ion::base::AllocationManager::SetDefaultAllocatorForLifetime(), ion::gfx::ShaderProgram::SetFragmentShader(), ion::text::OutlineBuilder::SetHalfSmoothWidth(), ion::gfx::TextureBase::Face::SetImage(), ion::gfx::TextureBase::SetImmutableImage(), ion::text::OutlineBuilder::SetOutlineColor(), ion::text::OutlineBuilder::SetOutlineWidth(), ion::text::BasicBuilder::SetSdfPadding(), ion::text::OutlineBuilder::SetSdfPadding(), ion::gfx::BufferObject::SetSubData(), ion::text::BasicBuilder::SetTextColor(), ion::text::OutlineBuilder::SetTextColor(), ion::gfx::ShaderProgram::SetVertexShader(), ion::gfx::ShaderProgram::ShaderProgram(), ion::remote::TracingHandler::TracingHandler(), ion::gfx::Renderer::UnmapBufferObjectData(), ion::text::BasicBuilder::UpdateUniforms(), ion::gfxutils::ResourceCallback< T >::WaitForCompletion(), ion::base::WeakReferentPtr< FramebufferObject >::WeakReferentPtr(), ion::base::Allocatable::~Allocatable(), ion::gfx::Image::~Image(), ion::gfxutils::ResourceCallback< T >::~ResourceCallback(), ion::gfx::Texture::~Texture(), and ion::remote::TracingHandler::~TracingHandler().

template<typename T>
bool ion::base::SharedPtr< T >::operator!= ( const SharedPtr< T > &  p) const
inline

The inequality operator returns true if the raw pointers differ.

Definition at line 157 of file sharedptr.h.

template<typename T>
T& ion::base::SharedPtr< T >::operator* ( ) const
inline

The * operator returns the underlying instance.

Definition at line 146 of file sharedptr.h.

template<typename T>
T* ion::base::SharedPtr< T >::operator-> ( ) const
inline

The -> operator forwards to the raw pointer.

Definition at line 140 of file sharedptr.h.

template<typename T>
SharedPtr<T>& ion::base::SharedPtr< T >::operator= ( T new_shared)
inline

Assignment to a raw pointer is the same as Reset().

Definition at line 109 of file sharedptr.h.

template<typename T>
template<typename U >
SharedPtr<T>& ion::base::SharedPtr< T >::operator= ( U *  new_shared)
inline

Allow assignment to a compatible raw pointer.

Definition at line 115 of file sharedptr.h.

template<typename T>
SharedPtr<T>& ion::base::SharedPtr< T >::operator= ( const SharedPtr< T > &  p)
inline

Allow assignment to a SharedPtr of the same type.

Don't delegate to Reset() here because Reset() requires a complete type. We can do this version without that requirement.

Definition at line 123 of file sharedptr.h.

template<typename T>
template<typename U >
SharedPtr<T>& ion::base::SharedPtr< T >::operator= ( const SharedPtr< U > &  p)
inline

Allow assignment to a compatible SharedPtr.

Definition at line 134 of file sharedptr.h.

template<typename T>
bool ion::base::SharedPtr< T >::operator== ( const SharedPtr< T > &  p) const
inline

The equality operator returns true if the raw pointers are the same.

Definition at line 152 of file sharedptr.h.

template<typename T>
void ion::base::SharedPtr< T >::Reset ( T new_shared)
inline

Changes the pointer to point to the given shared, which may be NULL.

Definition at line 92 of file sharedptr.h.

Referenced by ion::text::FontManager::AddFont(), ion::text::Builder::Build(), ion::remote::RemoteServer::RemoteServer(), and ion::gfxutils::ResourceCallback< T >::ResourceCallback().

template<typename T>
void ion::base::SharedPtr< T >::Reset ( )
inline

Make the SharedPtr point to NULL.

Definition at line 102 of file sharedptr.h.

Referenced by ion::base::SharedPtr< AllocationTracker >::operator=().

template<typename T>
void ion::base::SharedPtr< T >::swap ( SharedPtr< T > &  p)
inline

STL-style function to swap the raw pointer with another SharedPtr without the need for copying.

Definition at line 163 of file sharedptr.h.


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