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; }
195 if (strcmp(staticClassType(), typenameStr) == 0)
210#ifdef FIELD3D_USE_ATOMIC_COUNT
213 mutable long m_counter;
215 mutable boost::mutex m_refMutex;
254template <
class Field_T>
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
void intrusive_ptr_add_ref(RefBase *r)
void intrusive_ptr_release(RefBase *r)
bool matchRTTI(const char *typenameStr)
Performs a check to see if the given typename string matches this class' This needs to be implemented...
void ref() const
Used by boost::intrusive_pointer.
boost::intrusive_ptr< RefBase > Ptr
virtual ~RefBase()
Destructor.
boost::weak_ptr< RefBase > WeakPtr
virtual bool checkRTTI(const char *typenameStr)=0
This function is only implemented by concrete classes and triggers the actual RTTI check through matc...
boost::shared_ptr< RefBase > m_sharedPtr
For use by the FieldCache only: The shared pointer lets us see if this object is still alive.
size_t refcnt()
Used by boost::intrusive_pointer.
boost::detail::atomic_count m_counter
For boost intrusive pointer.
static const char * staticClassType()
void unref() const
Used by boost::intrusive_pointer.
RefBase(const RefBase &)
Copy constructor.
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...
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Used to let a shared pointer exist that doesn't delete anything. This is used by RefBase to hold a sh...
void operator()(void const *) const