MrSID Decode SDK for Raster Reference Manual 9.5.4.4709

- Main Page
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

lti_referenceCountedObject.h
Go to the documentation of this file.
1 /* $Id$ */
2 /* //////////////////////////////////////////////////////////////////////////
3 // //
4 // This code is Copyright (c) 2004 LizardTech, Inc, 1008 Western Avenue, //
5 // Suite 200, Seattle, WA 98104. Unauthorized use or distribution //
6 // prohibited. Access to and use of this code is permitted only under //
7 // license from LizardTech, Inc. Portions of the code are protected by //
8 // US and foreign patents and other filings. All Rights Reserved. //
9 // //
11 /* PUBLIC */
12
13 #ifndef LTI_REFERENCE_COUNTED_OBJECT_H
14 #define LTI_REFERENCE_COUNTED_OBJECT_H
15
16 // lt_lib_mrsid_core
17 #include "lti_types.h"
18
19 LT_BEGIN_NAMESPACE(LizardTech)
20
21
33 class LTIReferenceCountedObject
34 {
45 #define LTI_REFERENCE_COUNTED_BOILERPLATE_BASE(classname) \
46 LT_DISALLOW_COPY_CONSTRUCTOR(classname); \
47 protected: \
48 classname(void); \
49 virtual ~classname(void)
50
51 #define LTI_REFERENCE_COUNTED_BOILERPLATE(classname) \
52 LTI_REFERENCE_COUNTED_BOILERPLATE_BASE(classname); \
53 public: \
54 static classname *create(void)
55
56 LTI_REFERENCE_COUNTED_BOILERPLATE_BASE(LTIReferenceCountedObject);
57 public:
58
60 virtual void retain(void) const;
61
63 virtual void release(void) const;
64
65 private:
66 mutable lt_int32 m_referenceCount;
67 };
68
75 template<typename TYPE> inline TYPE *
76 LTI_RETAIN(TYPE *object)
77 {
78 if(object != NULL)
79 object->retain();
80 return object;
81 }
82
84 template<typename TYPE> inline void
85 LTI_RELEASE(TYPE *&object)
86 {
87 if(object != NULL)
88 object->release();
89 object = NULL;
90 }
91
92
99 template<typename TYPE>
100 class RC
101 {
102 public:
104 ~RC(void) { LTI_RELEASE(m_object); }
105
111 RC(void) : m_object(TYPE::create()) {}
112
118 RC(TYPE *object) : m_object(LTI_RETAIN(object)) {}
119 RC &operator=(TYPE *object)
120 {
121 // retain first because object may equal m_object
122 LTI_RETAIN(object);
123 LTI_RELEASE(m_object);
124 m_object = object;
125 return *this;
126 }
127
128 RC(const RC &object) : m_object(LTI_RETAIN(object.m_object)) {}
129 RC &operator=(const RC &object)
130 {
131 // retain first because object may equal m_object
132 LTI_RETAIN(object.m_object);
133 LTI_RELEASE(m_object);
134 m_object = object.m_object;
135 return *this;
136 }
137
139 TYPE *operator->(void) { return m_object; }
140 const TYPE *operator->(void) const { return m_object; }
142 TYPE &operator*(void) { return *m_object; }
143 const TYPE &operator*(void) const { return *m_object; }
144 #ifndef SWIG
145
146 operator TYPE *&(void) { return m_object; }
147 operator const TYPE *&(void) const { return m_object; }
148 #endif
149
150 private:
151 TYPE *m_object;
152 };
153
155 template<typename TYPE> inline RC<TYPE> &
156 LTI_RETAIN(RC<TYPE> &object)
157 {
158 if(object != NULL)
159 object->retain();
160 return object;
161 }
162
163
164
165
166 LT_END_NAMESPACE(LizardTech)
167
168 #endif // LTI_REFERENCE_COUNTED_OBJECT_H

LizardTech