1 #ifndef _GEMFIRE_SHAREDPTR_HPP_ 2 #define _GEMFIRE_SHAREDPTR_HPP_ 14 #include "TypeHelper.hpp" 16 #include "SharedPtrHelper.hpp" 23 #if GF_DEVEL_ASSERTS == 1 24 #define GF_CHECK_NPE(x) if ( x != NULL ) { } else gemfire::SPEHelper::throwNullPointerException( typeid( *this ).name() ) 26 #define GF_CHECK_NPE(x) 32 template<
class Target>
53 : m_ptr(const_cast<Target *>(ptr))
72 : m_ptr( getTarget< Target >( other.ptr( ) ) )
87 inline Target* operator -> ()
const 89 GF_CHECK_NPE( m_ptr );
95 inline Target& operator * ()
const 97 GF_CHECK_NPE( m_ptr );
119 Target* otherPtr = other.m_ptr;
121 if ( NULL != otherPtr ) {
124 if ( NULL != m_ptr ) {
137 template<
class Other>
140 Other* otherPtr = other.ptr( );
142 Target* otherTargetPtr = getTarget< Target >( otherPtr );
144 if ( NULL != otherPtr ) {
147 if ( NULL != m_ptr ) {
150 m_ptr = otherTargetPtr;
170 template<
class Other>
173 Target* otherTargetPtr = getTarget< Target >( other );
175 if ( NULL != other ) {
178 if ( NULL != m_ptr ) {
181 m_ptr = otherTargetPtr;
186 inline bool operator == (
const Target* other)
const 187 {
return m_ptr == other; }
189 inline bool operator != (
const Target* other)
const 190 {
return m_ptr != other; }
193 {
return m_ptr == NULL; }
196 {
return m_ptr != NULL; }
198 inline bool operator == (
const SharedPtr& other)
const 199 {
return m_ptr == other.m_ptr; }
201 inline bool operator != (
const SharedPtr& other)
const 202 {
return m_ptr != other.m_ptr; }
204 template<
class Other>
207 return ((
const void*)m_ptr) == ((
const void*) other.ptr() );
210 template<
class Other>
212 {
return ! operator == (other); }
214 inline Target* ptr()
const 228 friend class MapEntry;
229 friend class MapEntryImpl;
247 template <
class TargetSP,
class Other>
251 (
dynamic_cast<GF_UNWRAP_SP( TargetSP )*
>( other.ptr( ) ) != NULL ) );
253 return TargetSP(
static_cast<GF_UNWRAP_SP( TargetSP )*
>( other.ptr( ) ) );
259 template <
class TargetSP,
class Other>
262 GF_UNWRAP_SP( TargetSP )* otherPtr;
264 if ( ( other.ptr( ) == NULL ) ) {
266 }
else if ( ( otherPtr =
dynamic_cast<GF_UNWRAP_SP( TargetSP )*
> 267 ( other.ptr( ) ) ) != NULL ) {
268 return TargetSP( otherPtr );
270 SPEHelper::throwClassCastException(
"dynCast: cast failed",
271 typeid( other ).name( ),
typeid( TargetSP ).name( ) );
279 template<
class TargetSP,
class Other>
282 return (
dynamic_cast<GF_UNWRAP_SP(TargetSP)*
> (other.ptr()) != NULL);
TargetSP staticCast(const SharedPtr< Other > &other)
Statically cast the underlying pointer to the given type.
Definition: SharedPtr.hpp:248
SharedPtr()
Constructor.
Definition: SharedPtr.hpp:40
Class encapsulating a NULL SharedBase smart pointer.
Definition: SharedBase.hpp:78
bool instanceOf(const SharedPtr< Other > &other)
Dynamically check if the underlying pointer is of the given SharedPtr type.
Definition: SharedPtr.hpp:280
SharedPtr(const Target *ptr)
Explicit copy constructor, given a pointer.
Definition: SharedPtr.hpp:52
SharedPtr(const SharedPtr< Other > &other)
Constructor, given another SharedPtr.
Definition: SharedPtr.hpp:71
#define GF_D_ASSERT(x)
Throws the given assertion if GF_DEBUG_ASSERTS is true.
Definition: Assert.hpp:73
~SharedPtr()
Destructor.
Definition: SharedPtr.hpp:79
SharedPtr & operator=(Target *other)
Assigns a pointer.
Definition: SharedPtr.hpp:104
This namespace contains all the GemFire C++ API classes, enumerations and globals.
Definition: Assert.hpp:19
SharedPtr(const SharedPtr &other)
Constructor, given another SharedPtr.
Definition: SharedPtr.hpp:60
Assertion functions for debugging.
SharedPtr(const NullSharedBase *ptr)
Constructor for the NULL pointer.
Definition: SharedPtr.hpp:45
TargetSP dynCast(const SharedPtr< Other > &other)
Dynamically cast the underlying pointer to the given type and throw ClassCastException if the cast fa...
Definition: SharedPtr.hpp:260
void preserveSB() const
Atomically increment reference count.
void releaseSB() const
Atomically decrement reference count, the SharedBase object is automatically deleted when its referen...
#define GF_DEV_ASSERT(x)
Throws the given assertion if GF_DEVEL_ASSERTS is true.
Definition: Assert.hpp:80
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:35