nux-1.16.0
|
A smart pointer class. Implemented as an intrusive smart pointer. More...
#include <NuxCore/ObjectPtr.h>
Public Member Functions | |
ObjectPtr () | |
Constructor. | |
ObjectPtr (ObjectPtr< T > const &other) | |
Copy constructor. | |
template<typename O > | |
ObjectPtr (ObjectPtr< O > const &other) | |
Copy constructor. | |
ObjectPtr (T *ptr, bool WarnMissuse=false) | |
Construction with a base pointer of type T. | |
template<typename O > | |
ObjectPtr (O *ptr, bool WarnMissuse=false) | |
Construction with a base pointer of type O that inherits from type T. | |
void | Adopt (T *ptr) |
Take ownership of ptr. | |
ObjectPtr & | operator= (T *ptr) |
Assignment of a smart pointer of type T. | |
ObjectPtr & | operator= (ObjectPtr< T > const &other) |
Assignment of a smart pointer of type T. | |
template<typename O > | |
ObjectPtr & | operator= (ObjectPtr< O > const &other) |
Assignment of a smart pointer of type O that inherits from type T. | |
T & | operator* () const |
T * | operator-> () const |
const T * | GetPointer () const |
Return the stored pointer. | |
T * | GetPointer () |
Return the stored pointer. | |
void | Swap (ObjectPtr< T > &other) |
Swap the content of 2 smart pointers. | |
operator bool () const | |
bool | operator() () const |
Test validity of the smart pointer. | |
bool | IsNull () const |
Test validity of the smart pointer. | |
bool | IsValid () const |
Test validity of the smart pointer. | |
bool | operator< (T *ptr) const |
bool | operator> (T *ptr) const |
bool | operator< (ObjectPtr< T > other) const |
bool | operator> (ObjectPtr< T > other) const |
bool | operator== (T *ptr) const |
template<typename U > | |
bool | operator!= (U other) const |
template<typename U > | |
bool | operator== (U *ptr) const |
template<typename U > | |
bool | operator== (ObjectPtr< U > const &other) const |
template<typename U > | |
bool | operator== (ObjectWeakPtr< U > const &other) const |
bool | Release () |
Release the hosted pointer from this object. | |
Friends | |
class | ObjectPtr |
class | ObjectWeakPtr |
A smart pointer class. Implemented as an intrusive smart pointer.
Definition at line 40 of file ObjectPtr.h.
nux::ObjectPtr< T >::ObjectPtr | ( | ObjectPtr< O > const & | other | ) | [inline] |
Copy constructor.
This method takes advantage of the nux type information using the virtual Type function.
other | Parameter with a type derived from T. |
Definition at line 68 of file ObjectPtr.h.
: ptr_(nullptr) { if (other.ptr_ && other.ptr_->Type().IsDerivedFromType(T::StaticObjectType)) { ptr_ = static_cast<T*>(other.ptr_); ptr_->objectptr_count_->Increment(); ptr_->Reference(); } }
nux::ObjectPtr< T >::ObjectPtr | ( | T * | ptr, |
bool | WarnMissuse = false |
||
) | [inline, explicit] |
Construction with a base pointer of type T.
ptr | Start maintaining a reference count of the passed pointer. |
WarnMissuse | If True, then ObjectPtr test is ptr is owned or not. If ptr is not owned and WarnMissuse is True, then Print a warning message. This is a debug feature to detect cases such as "ObjectPtr(ObjectA) myobject(ptr);", because the calling code will no longer have a reference on ptr. |
Definition at line 89 of file ObjectPtr.h.
: ptr_(nullptr) { if (ptr) { if (WarnMissuse && (!ptr->OwnsTheReference())) { nuxDebugMsg (TEXT ("[ObjectPtr::ObjectPtr] Warning: Constructing a smart pointer from an object with a floating reference.") ); } ptr_ = ptr; ptr_->objectptr_count_->Increment(); ptr_->Reference(); } }
nux::ObjectPtr< T >::ObjectPtr | ( | O * | ptr, |
bool | WarnMissuse = false |
||
) | [inline, explicit] |
Construction with a base pointer of type O that inherits from type T.
ptr | Start maintaining a reference count of the passed pointer. |
WarnMissuse | If True, then ObjectPtr test is ptr is owned or not. If ptr is not owned and WarnMissuse is True, then Print a warning message. This is a debug feature to detect cases such as "ObjectPtr(ObjectA) myobject(ptr);", because the calling code will no longer have a reference on ptr. |
Definition at line 115 of file ObjectPtr.h.
: ptr_(nullptr) { if (ptr && ptr->Type().IsDerivedFromType(T::StaticObjectType)) { if (WarnMissuse && (!ptr->OwnsTheReference())) { nuxDebugMsg (TEXT ("[ObjectPtr::ObjectPtr] Warning: Constructing a smart pointer from an object with a floating reference.") ); } ptr_ = static_cast<T*>(ptr); ptr_->objectptr_count_->Increment(); ptr_->Reference(); } }
T* nux::ObjectPtr< T >::GetPointer | ( | ) | [inline] |
Return the stored pointer.
Caller of this function should Reference the pointer if they intend to keep it.
Return | the stored pointer. |
Definition at line 212 of file ObjectPtr.h.
{
return ptr_;
}
const T* nux::ObjectPtr< T >::GetPointer | ( | ) | const [inline] |
Return the stored pointer.
Caller of this function should Reference the pointer if they intend to keep it.
Return | the stored pointer. |
Definition at line 201 of file ObjectPtr.h.
{
return ptr_;
}
bool nux::ObjectPtr< T >::IsNull | ( | ) | const [inline] |
Test validity of the smart pointer.
Return True if the internal pointer is null.
Definition at line 244 of file ObjectPtr.h.
Referenced by nux::GraphicsEngine::GraphicsEngine().
{ return !IsValid(); }
bool nux::ObjectPtr< T >::IsValid | ( | ) | const [inline] |
Test validity of the smart pointer.
Return True if the internal pointer is not null.
Definition at line 253 of file ObjectPtr.h.
Referenced by nux::GraphicsEngine::ApplyClippingRectangle(), nux::TResourceCache< int, CachedResourceData >::FlushResourceId(), nux::ObjectPtr< IOpenGLAsmShaderProgram >::IsNull(), nux::GraphicsEngine::QRP_ASM_GetAlphaTexture(), nux::GraphicsEngine::QRP_ASM_GetColorMatrixTexture(), nux::GraphicsEngine::QRP_ASM_GetPixelBlocks(), nux::GraphicsEngine::QRP_ASM_GetPower(), nux::GraphicsEngine::QRP_GLSL_GetPixelBlocks(), nux::GraphicsEngine::SetOpenGLClippingRectangle(), and nux::GraphicsEngine::UpdateResource().
{
return bool(ptr_);
}
bool nux::ObjectPtr< T >::operator() | ( | ) | const [inline] |
Test validity of the smart pointer.
Return True if the internal pointer is not null.
Definition at line 235 of file ObjectPtr.h.
{
return bool(ptr_);
}
ObjectPtr& nux::ObjectPtr< T >::operator= | ( | ObjectPtr< O > const & | other | ) | [inline] |
Assignment of a smart pointer of type O that inherits from type T.
other | Smart pointer of type O. |
Definition at line 171 of file ObjectPtr.h.
{ ObjectPtr<T> temp(other); Swap(temp); return *this; }
ObjectPtr& nux::ObjectPtr< T >::operator= | ( | T * | ptr | ) | [inline] |
Assignment of a smart pointer of type T.
other | Smart pointer of type T. |
Definition at line 148 of file ObjectPtr.h.
{ ObjectPtr<T> temp(ptr); Swap(temp); return *this; }
ObjectPtr& nux::ObjectPtr< T >::operator= | ( | ObjectPtr< T > const & | other | ) | [inline] |
Assignment of a smart pointer of type T.
other | Smart pointer of type T. |
Definition at line 159 of file ObjectPtr.h.
{ ObjectPtr<T> temp(other); Swap(temp); return *this; }
bool nux::ObjectPtr< T >::Release | ( | ) | [inline] |
Release the hosted pointer from this object.
Release the hosted pointer from this object. After this call, all the members are null.
Definition at line 325 of file ObjectPtr.h.
Referenced by nux::CachedIndexBuffer::UpdateResource(), and nux::CachedVertexBuffer::UpdateResource().
{
return ReleaseReference();
}
void nux::ObjectPtr< T >::Swap | ( | ObjectPtr< T > & | other | ) | [inline] |
Swap the content of 2 smart pointers.
other | Smart pointer to swap with. |
Definition at line 221 of file ObjectPtr.h.
Referenced by nux::ObjectPtr< IOpenGLAsmShaderProgram >::Adopt(), and nux::ObjectPtr< IOpenGLAsmShaderProgram >::operator=().
{ std::swap(ptr_, other.ptr_); }