3 #ifndef GEODE_SHAREDPTR_H_ 4 #define GEODE_SHAREDPTR_H_ 25 #include "TypeHelper.hpp" 27 #include "SharedPtrHelper.hpp" 36 #if GF_DEVEL_ASSERTS == 1 37 #define GF_CHECK_NPE(x) \ 40 apache::geode::client::SPEHelper::throwNullPointerException( \ 43 #define GF_CHECK_NPE(x) 49 template <
class Target>
66 : m_ptr(const_cast<Target*>(ptr)) {
80 template <
class Other>
82 : m_ptr(getTarget<Target>(other.ptr())) {
88 if (NULL != m_ptr) getSB(m_ptr)->
releaseSB();
93 inline Target* operator->()
const {
100 inline Target& operator*()
const {
111 if (NULL != other) getSB(other)->
preserveSB();
113 if (NULL != m_ptr) getSB(m_ptr)->
releaseSB();
121 Target* otherPtr = other.m_ptr;
123 if (NULL != otherPtr) {
142 template <
class Other>
144 Other* otherPtr = other.ptr();
146 Target* otherTargetPtr = getTarget<Target>(otherPtr);
148 if (NULL != otherPtr) {
154 m_ptr = otherTargetPtr;
177 template <
class Other>
179 Target* otherTargetPtr = getTarget<Target>(other);
187 m_ptr = otherTargetPtr;
192 inline bool operator==(
const Target* other)
const {
return m_ptr == other; }
194 inline bool operator!=(
const Target* other)
const {
return m_ptr != other; }
197 return m_ptr == NULL;
201 return m_ptr != NULL;
204 inline bool operator==(
const SharedPtr& other)
const {
205 return m_ptr == other.m_ptr;
208 inline bool operator!=(
const SharedPtr& other)
const {
209 return m_ptr != other.m_ptr;
212 template <
class Other>
214 return ((
const void*)m_ptr) == ((
const void*)other.ptr());
217 template <
class Other>
219 return !operator==(other);
222 inline Target* ptr()
const {
return m_ptr; }
226 inline explicit SharedPtr(
bool noInit) {}
230 friend class MapEntry;
231 friend class MapEntryImpl;
247 template <
class TargetSP,
class Other>
250 (
dynamic_cast<GF_UNWRAP_SP(TargetSP)*
>(other.ptr()) != NULL));
252 return TargetSP(
static_cast<GF_UNWRAP_SP(TargetSP)*
>(other.ptr()));
258 template <
class TargetSP,
class Other>
260 GF_UNWRAP_SP(TargetSP) * otherPtr;
262 if ((other.ptr() == NULL)) {
264 }
else if ((otherPtr =
dynamic_cast<GF_UNWRAP_SP(TargetSP)*
>(other.ptr())) !=
266 return TargetSP(otherPtr);
268 SPEHelper::throwClassCastException(
269 "dynCast: cast failed",
typeid(other).name(),
typeid(TargetSP).name());
277 template <
class TargetSP,
class Other>
279 return (
dynamic_cast<GF_UNWRAP_SP(TargetSP)*
>(other.ptr()) != NULL);
285 #endif // GEODE_SHAREDPTR_H_ #define GF_DEV_ASSERT(x)
Throws the given assertion if GF_DEVEL_ASSERTS is true.
Definition: Assert.hpp:97
Each enum represents a predefined RegionAttributes in a Cache.
Definition: Assert.hpp:31
SharedPtr & operator=(const SharedPtr< Other > &other)
Assigns a pointer of type Other from a SharedPtr object.
Definition: SharedPtr.hpp:143
void releaseSB() const
Atomically decrement reference count, the SharedBase object is automatically deleted when its referen...
SharedPtr(const NullSharedBase *ptr)
Constructor for the NULL pointer.
Definition: SharedPtr.hpp:58
SharedPtr & operator=(Other *other)
Assigns a pointer of type Other.
Definition: SharedPtr.hpp:178
SharedPtr(const Target *ptr)
Explicit copy constructor, given a pointer.
Definition: SharedPtr.hpp:65
Class encapsulating a NULL SharedBase smart pointer.
Definition: SharedBase.hpp:73
void preserveSB() const
Atomically increment reference count.
~SharedPtr()
Destructor.
Definition: SharedPtr.hpp:87
SharedPtr(const SharedPtr< Other > &other)
Constructor, given another SharedPtr.
Definition: SharedPtr.hpp:81
#define GF_D_ASSERT(x)
Throws the given assertion if GF_DEBUG_ASSERTS is true.
Definition: Assert.hpp:89
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:259
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:52
SharedPtr & operator=(Target *other)
Assigns a pointer.
Definition: SharedPtr.hpp:110
Assertion functions for debugging.
bool instanceOf(const SharedPtr< Other > &other)
Dynamically check if the underlying pointer is of the given SharedPtr type.
Definition: SharedPtr.hpp:278
SharedPtr(const SharedPtr &other)
Constructor, given another SharedPtr.
Definition: SharedPtr.hpp:71
TargetSP staticCast(const SharedPtr< Other > &other)
Statically cast the underlying pointer to the given type.
Definition: SharedPtr.hpp:248
SharedPtr()
Constructor.
Definition: SharedPtr.hpp:55
This namespace contains all the Geode C++ API classes, enumerations and globals.