Go to the documentation of this file.
44 #ifndef _INCLUDED_Field3D_REF_COUNT_H_
45 #define _INCLUDED_Field3D_REF_COUNT_H_
47 #define FIELD3D_USE_ATOMIC_COUNT
50 #include <boost/intrusive_ptr.hpp>
52 #include <boost/shared_ptr.hpp>
53 #include <boost/weak_ptr.hpp>
55 #ifdef FIELD3D_USE_ATOMIC_COUNT
56 #include <boost/detail/atomic_count.hpp>
58 #include <boost/thread/mutex.hpp>
71 #define DEFINE_CHECK_RTTI_CALL \
72 virtual bool checkRTTI(const char *typenameStr) \
73 { return matchRTTI(typenameStr); } \
75 #define DEFINE_MATCH_RTTI_CALL \
76 bool matchRTTI(const char *typenameStr) \
78 if (strcmp(typenameStr,staticClassType()) == 0) { \
81 return base::matchRTTI(typenameStr); \
84 #define DEFINE_FIELD_RTTI_CONCRETE_CLASS \
85 DEFINE_CHECK_RTTI_CALL \
86 DEFINE_MATCH_RTTI_CALL \
88 #define DEFINE_FIELD_RTTI_ABSTRACT_CLASS \
89 DEFINE_MATCH_RTTI_CALL \
112 typedef boost::intrusive_ptr<RefBase>
Ptr;
147 {
return m_counter; }
152 #ifndef FIELD3D_USE_ATOMIC_COUNT
153 boost::mutex::scoped_lock lock(m_refMutex);
161 #ifndef FIELD3D_USE_ATOMIC_COUNT
162 boost::mutex::scoped_lock lock(m_refMutex);
172 {
return m_sharedPtr; }
189 virtual bool checkRTTI(
const char *typenameStr) = 0;
195 if (strcmp(staticClassType(), typenameStr) == 0)
210 #ifdef FIELD3D_USE_ATOMIC_COUNT
213 mutable long m_counter;
215 mutable boost::mutex m_refMutex;
254 template <
class Field_T>
255 typename Field_T::Ptr
261 const char *tgtTypeString = Field_T::staticClassType();
263 if (field->checkRTTI(tgtTypeString)) {
264 return static_cast<Field_T*>(field.get());
271 #define FIELD_DYNAMIC_CAST field_dynamic_cast
279 #endif // Include guard
#define FIELD3D_NAMESPACE_HEADER_CLOSE
RefBase(const RefBase &)
Copy constructor.
virtual ~RefBase()
Destructor.
bool matchRTTI(const char *typenameStr)
Performs a check to see if the given typename string matches this class' This needs to be implemented...
void intrusive_ptr_add_ref(RefBase *r)
size_t refcnt()
Used by boost::intrusive_pointer.
Used to let a shared pointer exist that doesn't delete anything. This is used by RefBase to hold a sh...
boost::shared_ptr< RefBase > m_sharedPtr
For use by the FieldCache only: The shared pointer lets us see if this object is still alive.
Field_T::Ptr field_dynamic_cast(RefBase::Ptr field)
Dynamic cast that uses string-comparison in order to be safe even after an object crosses a shared li...
void operator()(void const *) const
void ref() const
Used by boost::intrusive_pointer.
static const char * staticClassType()
boost::weak_ptr< RefBase > WeakPtr
void intrusive_ptr_release(RefBase *r)
boost::detail::atomic_count m_counter
For boost intrusive pointer.
void unref() const
Used by boost::intrusive_pointer.
boost::intrusive_ptr< RefBase > Ptr