CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
RxObjectImpl.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 license
16// 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
25
26
27#if !defined(OdRxObjectImpl_INCLUDED_)
28#define OdRxObjectImpl_INCLUDED_
29
30#include "OdaCommon.h"
31#include "TD_PackPush.h"
32
33#include "RxObject.h"
34#include "OdMutex.h"
35
53template<class T, class TInterface = T>
54class OdRxObjectImpl : public T
55{
59 OdRefCounter m_nRefCounter;
60
64 OdRxObjectImpl& operator = (const OdRxObjectImpl&);
65
66protected:
68
69public:
74 {
75 m_nRefCounter = 1;
76 }
77
81 void addRef()
82 {
83 ++m_nRefCounter;
84 }
85
90 void release()
91 {
92 ODA_ASSERT((m_nRefCounter > 0));
93 if (!(--m_nRefCounter))
94 {
95 delete this;
96 }
97 }
98
102 long numRefs() const { return m_nRefCounter; }
103
108 {
109 return OdSmartPtr<TInterface>(static_cast<TInterface*>(new OdRxObjectImpl<T, TInterface>), kOdRxObjAttach);
110 }
111};
112
113#if (defined(_MSC_VER) && (_MSC_VER > 1700)) || (defined(__cplusplus) && (__cplusplus > 199711L))
131template<class T, class TInterface = T>
132class OdRxObjectImpl2 : public T
133{
137 OdRefCounter m_nRefCounter;
138
142 OdRxObjectImpl2& operator = (const OdRxObjectImpl2&);
143
144protected:
146
147public:
152 template<typename... Args>
153 OdRxObjectImpl2(Args&&... args)
154 : T(std::forward<Args>(args)...)
155 {
156 m_nRefCounter = 1;
157 }
158
162 void addRef()
163 {
164 ++m_nRefCounter;
165 }
166
171 void release()
172 {
173 ODA_ASSERT((m_nRefCounter > 0));
174 if (!(--m_nRefCounter))
175 {
176 delete this;
177 }
178 }
179
183 long numRefs() const { return m_nRefCounter; }
184
188 template<typename... Args>
189 static OdSmartPtr<TInterface> createObject(Args&&... args)
190 {
191 return OdSmartPtr<TInterface>(static_cast<TInterface*>(new OdRxObjectImpl2<T, TInterface>(std::forward<Args>(args)...)), kOdRxObjAttach);
192 }
193};
194
195#endif
196
200#define RXIMPL_CONSTR(ClassName) OdRxObjectImpl<ClassName>::createObject()
201
205#define ABSTRACTIMPL_CONSTR(CLASS) OdRxObjectImpl<CLASS##Impl>::createObject()
206
207template<class T, class TImpl>
208class OdObjectWithImpl : public T
209{
210protected:
211#ifdef ODA_NEED_TEMP_USING
212 using T::m_pImpl;
213#endif
214public:
215 TImpl m_Impl;
217 {
218 }
220 {
221 m_pImpl = NULL;
222 }
224 {
226 }
227};
228
229#define OD_IDCAT(ID, Postf) ID##Postf
230
231#define RXIMPLOBJCONSTRUCT(ClassName) OdRxObjectImpl<OdObjectWithImpl<ClassName, OD_IDCAT(ClassName,Impl)> >::createObject()
232
233#define IMPLOBJCONSTRUCT(ClassName) OdObjectWithImpl<ClassName, OD_IDCAT(ClassName,Impl)>::createObject()
234
235
236#include "TD_PackPop.h"
237
238#endif // !defined(OdRxObjectImpl_INCLUDED_)
239
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:57
#define ODRX_HEAP_OPERATORS()
Definition: OdHeap.h:76
int OdRefCounter
Definition: OdMutex.h:487
@ kOdRxObjAttach
Definition: RxObject.h:56
static OdSmartPtr< T > createObject()
Definition: RxObjectImpl.h:223
long numRefs() const
Definition: RxObjectImpl.h:102
static OdSmartPtr< TInterface > createObject()
Definition: RxObjectImpl.h:107