CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
AECSubPtr.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a
16// license agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24#ifndef __AECSUBPTR_H__
25#define __AECSUBPTR_H__
26
27#include <SmartPtr.h>
30
36template<class B>
37class AECBASE_API AECSubPtrBase
38{
39 public:
43 inline bool isNull() const
44 {
45 return m_pObject == 0;
46 }
47
51 inline B* get() const
52 {
53 return m_pObject;
54 }
55
56 protected:
60 inline AECSubPtrBase() : m_pObject(0)
61 {
62 }
63
64 // Pointer to sub-object.
66};
67
73template <class T, class B = AECImpObj, class TBase = AECSubPtrBase<B> > class AECSubPtr : public TBase
74{
75 private:
79 inline void internalAddRef()
80 {
81 if( TBase::m_pObject )
82 {
83 // New in AECSubPtr:
84 // Add reference to the object and it`s owners.
85 TBase::m_pObject->addRefSubPtr();
86 }
87 }
92 inline void internalQueryX( const OdRxObject* pObj )
93 {
94 if( pObj )
95 {
96 T* pImp = T::cast( pObj ).get();
97 if( pImp )
98 {
99 TBase::m_pObject = pImp;
100 internalAddRef();
101 }
102 else
104 }
105 }
106
109 inline void release()
110 {
111 if (TBase::m_pObject)
112 {
113 // New in AECSubPtr:
114 // Release the object and it`s owners.
115 TBase::m_pObject->releaseSubPtr();
116 TBase::m_pObject = 0;
117 }
118 }
119
122 inline void assign( const T* pObj )
123 {
124 release();
125 TBase::m_pObject = const_cast<T*>(pObj);
126 internalAddRef();
127 }
128
131 inline void assign( const OdRxObject* pObj )
132 {
133 release();
134 internalQueryX( pObj );
135 }
136
139 bool operator !() const
140 {
141 ODA_FAIL();
142 return false;
143 }
144
147 operator bool() const
148 {
149 ODA_FAIL();
150 return false;
151 }
152
155 operator bool()
156 {
157 ODA_FAIL();
158 return false;
159 }
160
161 public:
164 inline AECSubPtr()
165 {
166 TBase::m_pObject = 0;
167 }
168
171 inline AECSubPtr( const T* pObj )
172 {
173 TBase::m_pObject = const_cast<T*>(pObj);
174 internalAddRef();
175 }
176
177 private:
182 inline operator OdSmartPtr<T>()
183 {
184 return OdSmartPtr<T>( TBase::m_pObject );
185 }
186
187 public:
190 inline AECSubPtr( const OdRxObject* pObj )
191 {
192 internalQueryX( pObj );
193 }
194
197 inline AECSubPtr(const AECSubPtr& pObj)
198 {
199 TBase::m_pObject = const_cast<T*>(pObj.get());
200 internalAddRef();
201 }
202
203 inline AECSubPtr(const TBase& pObj)
204 {
205 internalQueryX( pObj.get() );
206 }
207
210 inline AECSubPtr( const OdBaseObjectPtr& pObj )
211 {
212 internalQueryX( pObj.get() );
213 }
214
217 inline ~AECSubPtr()
218 {
219 release();
220 }
221
224 inline AECSubPtr& operator = (const AECSubPtr& pObj)
225 {
226 release();
227 TBase::m_pObject = const_cast<T*>(pObj.get());
228 internalAddRef();
229 return *this;
230 }
231
234 inline AECSubPtr& operator = (const TBase& pObj)
235 {
236 assign( pObj.get() );
237 return *this;
238 }
239
243 {
244 assign( pObj.get() );
245 return *this;
246 }
247
251 inline AECSubPtr& operator = (const T* pObj)
252 {
253 assign(pObj);
254 return *this;
255 }
256
259 inline const T* get() const
260 {
261 return static_cast<T*>(TBase::m_pObject);
262 }
263
266 inline T* get()
267 {
268 return static_cast<T*>(TBase::m_pObject);
269 }
270
273 inline T* operator ->()
274 {
275 return static_cast<T*>(TBase::m_pObject);
276 }
277
280 inline const T* operator ->() const
281 {
282 return static_cast<T*>(TBase::m_pObject);
283 }
284
285#ifdef ODA_GCC_2_95
291 inline operator T*() const
292 {
293 return static_cast<T*>(TBase::m_pObject);
294 }
295#else
299 inline operator T*()
300 {
301 return static_cast<T*>(TBase::m_pObject);
302 }
303
307 inline operator const T*() const
308 {
309 return static_cast<T*>(TBase::m_pObject);
310 }
311#endif
315 inline bool operator==(const T* pObj) const
316 {
317 return ( TBase::m_pObject == pObj );
318 }
319
323 inline bool operator==(const AECSubPtr& ptr) const
324 {
325 return operator==(ptr.get());
326 }
327
331 inline bool operator!=(const T* pObj) const
332 {
333 return ( TBase::m_pObject != pObj );
334 }
335
339 inline bool operator!=(const AECSubPtr& ptr) const
340 {
341 return operator!=(ptr.get());
342 }
343};
344
347
350
351#endif // __AECSUBPTR_H__
OdSmartPtr< AECImpObj > AECImpObjPtr
Definition: AECSubPtr.h:345
AECSubPtr< AECImpObj > AECImpObjSubPtr
Definition: AECSubPtr.h:346
OdSmartPtr< AECSubObj > AECSubObjPtr
Definition: AECSubPtr.h:348
AECSubPtr< AECSubObj, AECSubObj > AECSubObjSubPtr
Definition: AECSubPtr.h:349
#define ODA_FAIL()
Definition: DebugStuff.h:88
@ eNotThatKindOfClass
bool isNull() const
Definition: AECSubPtr.h:43
B * get() const
Definition: AECSubPtr.h:51
bool operator==(const AECSubPtr &ptr) const
Definition: AECSubPtr.h:323
AECSubPtr & operator=(const AECSubPtr &pObj)
Definition: AECSubPtr.h:224
~AECSubPtr()
Definition: AECSubPtr.h:217
bool operator!=(const T *pObj) const
Definition: AECSubPtr.h:331
AECSubPtr(const AECSubPtr &pObj)
Definition: AECSubPtr.h:197
AECSubPtr(const TBase &pObj)
Definition: AECSubPtr.h:203
AECSubPtr(const OdRxObject *pObj)
Definition: AECSubPtr.h:190
bool operator!=(const AECSubPtr &ptr) const
Definition: AECSubPtr.h:339
T * get()
Definition: AECSubPtr.h:266
AECSubPtr(const OdBaseObjectPtr &pObj)
Definition: AECSubPtr.h:210
const T * get() const
Definition: AECSubPtr.h:259
T * operator->()
Definition: AECSubPtr.h:273
AECSubPtr(const T *pObj)
Definition: AECSubPtr.h:171
bool operator==(const T *pObj) const
Definition: AECSubPtr.h:315
OdRxObject * get() const
Definition: BaseObjectPtr.h:81