MrSID Decode SDK for LiDAR Reference Manual 1.1.4.4709

- Main Page
- Classes
- Files

- File List
- File Members

Object.h
Go to the documentation of this file.
1 /* //////////////////////////////////////////////////////////////////////////
2 // //
3 // This code is Copyright (c) 2008-2010 LizardTech, Inc, 1008 Western //
4 // Avenue, Suite 200, Seattle, WA 98104. Unauthorized use or distribution //
5 // prohibited. Access to and use of this code is permitted only under //
6 // license from LizardTech, Inc. Portions of the code are protected by //
7 // US and foreign patents and other filings. All Rights Reserved. //
8 // //
10 /* PUBLIC */
11
12 #ifndef __LIDAR_OBJECT_H__
13 #define __LIDAR_OBJECT_H__
14
15 #include "lidar/Atomic.h"
16
17 LT_BEGIN_LIDAR_NAMESPACE
18
34 class Object
35 {
45 #define ABSTRACT_OBJECT(classname) \
46 DISABLE_COPY(classname); \
47 protected: \
48 classname(void); \
49 virtual ~classname(void)
50
55 #define CONCRETE_OBJECT(classname) \
56 ABSTRACT_OBJECT(classname); \
57 public: \
58 static classname *create(void)
59
60 #define IMPLEMENT_OBJECT_CREATE(classname) \
61 classname * classname::create(void) { return new classname; }
62
63 ABSTRACT_OBJECT(Object);
64 public:
68 int retain(void) const;
69
74 int release(void) const;
75
76 private:
77 mutable AtomicInt m_refCount;
78 };
79
84 template<typename OBJECT> static inline OBJECT *RETAIN(OBJECT *obj)
85 {
86 if(obj != NULL)
87 obj->retain();
88 return obj;
89 }
90
95 template<typename OBJECT> static inline void RELEASE(OBJECT *&obj)
96 {
97 if(obj != NULL)
98 {
99 obj->release();
100 obj = NULL;
101 }
102 }
103
151 template<typename TYPE>
152 class Scoped
153 {
154 public:
156 ~Scoped(void) { RELEASE(m_object); }
157
159 Scoped(void) : m_object(TYPE::create()) {}
160
169 Scoped(TYPE *object) : m_object(object) {}
170
176 Scoped &operator=(TYPE *object)
177 {
178 if(object != m_object)
179 {
180 RELEASE(m_object);
181 m_object = RETAIN(object);
182 }
183 return *this;
184 }
185 Scoped &operator=(const TYPE *object)
186 {
187 if(object != m_object)
188 {
189 RELEASE(m_object);
190 m_object = RETAIN(const_cast<TYPE *>(object));
191 }
192 return *this;
193 }
194
200 Scoped(const Scoped &object) : m_object(RETAIN(object.m_object)) {}
201
207 Scoped &operator=(const Scoped &object)
208 {
209 if(m_object != object.m_object)
210 {
211 RELEASE(m_object);
212 m_object = RETAIN(object.m_object);
213 }
214 return *this;
215 }
216
218 TYPE *operator->(void) { return m_object; }
219 const TYPE *operator->(void) const { return m_object; }
221 TYPE &operator*(void) { return *m_object; }
222 const TYPE &operator*(void) const { return *m_object; }
223 #ifndef SWIG
224
225 operator TYPE *&(void) { return m_object; }
226 operator const TYPE *&(void) const { return const_cast<const TYPE *&>(m_object); }
227 #endif
228
229 private:
230 TYPE *m_object;
231 };
232
233 template<typename OBJECT> static inline OBJECT *RETAIN(Scoped<OBJECT> &obj)
234 {
235 if(obj != NULL)
236 obj->retain();
237 return obj;
238 }
239
240 LT_END_LIDAR_NAMESPACE
241 #endif // __LIDAR_OBJECT_H__

LizardTech