8 #ifndef __LIDAR_OBJECT_H__
9 #define __LIDAR_OBJECT_H__
13 LT_BEGIN_LIDAR_NAMESPACE
41 #define ABSTRACT_OBJECT(classname) \
42 DISABLE_COPY(classname); \
45 virtual ~classname(void)
51 #define CONCRETE_OBJECT(classname) \
52 ABSTRACT_OBJECT(classname); \
54 static classname *create(void)
56 #define IMPLEMENT_OBJECT_CREATE(classname) \
57 classname * classname::create(void) { return new classname; }
73 mutable AtomicInt m_refCount;
80 template<
typename OBJECT>
static inline OBJECT *
RETAIN(OBJECT *obj)
91 template<
typename OBJECT>
static inline void RELEASE(OBJECT *&obj)
147 template<
typename TYPE>
155 Scoped(
void) : m_object(TYPE::create()) {}
165 Scoped(TYPE *
object) : m_object(object) {}
174 if(
object != m_object)
177 m_object =
RETAIN(
object);
183 if(
object != m_object)
186 m_object =
RETAIN(
const_cast<TYPE *
>(
object));
205 if(m_object !=
object.m_object)
208 m_object =
RETAIN(
object.m_object);
221 operator TYPE *&(void) {
return m_object; }
222 operator const TYPE *&(void)
const {
return const_cast<const TYPE *&
>(m_object); }
236 LT_END_LIDAR_NAMESPACE
#define ABSTRACT_OBJECT(classname)
Macros for defining boilerplate parts of derived Object classes.
static void RELEASE(OBJECT *&obj)
Helper function for calling Object::release().
static OBJECT * RETAIN(OBJECT *obj)
Helper function for calling Object::retain().
Object is the base class for implementing reference counting.
int retain(void) const
Increment the reference count by one.
int release(void) const
Decrement the reference count by one.
Scoped is a wrapper class around Object that gives it block scoping.
const TYPE * operator->(void) const
TYPE & operator*(void)
Make Scoped behave like a pointer to TYPE.
Scoped & operator=(const TYPE *object)
Scoped(TYPE *object)
Manage an existing object.
const TYPE & operator*(void) const
Scoped & operator=(const Scoped &object)
Assignment operator.
~Scoped(void)
Releases the object when Scoped<> goes out of scope.
Scoped(const Scoped &object)
Copy constructor.
Scoped(void)
Create an object on the heap.
TYPE * operator->(void)
Make Scoped behave like a pointer to TYPE.
Scoped & operator=(TYPE *object)
Assignment operator.