CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
RxObjectImpl.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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-2024 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
69 OdRxObjectImpl(OdRxObjectImpl&&);
70
71protected:
73
74public:
79 template<typename... Args>
80 OdRxObjectImpl(Args&&... args)
81 : T(std::forward<Args>(args)...)
82 {
83 m_nRefCounter = 1;
84 }
85
89 void addRef()
90 {
91 ++m_nRefCounter;
92 }
93
99 {
100 ODA_ASSERT((m_nRefCounter > 0));
101 if (!(--m_nRefCounter))
102 {
103 delete this;
104 }
105 }
106
110 long numRefs() const { return m_nRefCounter; }
111
115 template<typename... Args>
117 {
118 return OdSmartPtr<TInterface>(static_cast<TInterface*>(new OdRxObjectImpl<T, TInterface>(std::forward<Args>(args)...)), kOdRxObjAttach);
119 }
120};
121
122// VS 2013 does support arguments forwarding but does not quite support `using`
123#if (defined(_MSC_VER) && (_MSC_VER > 1800)) || (defined(__cplusplus) && (__cplusplus > 199711L))
124template<class T, class TInterface = T> using OdRxObjectImpl2 = OdRxObjectImpl<T, TInterface>;
125#else
126#define OdRxObjectImpl2 OdRxObjectImpl
127#endif
128
132#define RXIMPL_CONSTR(ClassName) OdRxObjectImpl<ClassName>::createObject()
133
137#define ABSTRACTIMPL_CONSTR(CLASS) OdRxObjectImpl<CLASS##Impl>::createObject()
138
139template<class T, class TImpl>
140class OdObjectWithImpl : public T
141{
142protected:
143#ifdef ODA_NEED_TEMP_USING
144 using T::m_pImpl;
145#endif
146public:
147 TImpl m_Impl;
149 {
150 }
152 {
153 m_pImpl = NULL;
154 }
159};
160
161#define OD_IDCAT(ID, Postf) ID##Postf
162
163#define RXIMPLOBJCONSTRUCT(ClassName) OdRxObjectImpl<OdObjectWithImpl<ClassName, OD_IDCAT(ClassName,Impl)> >::createObject()
164
165#define IMPLOBJCONSTRUCT(ClassName) OdObjectWithImpl<ClassName, OD_IDCAT(ClassName,Impl)>::createObject()
166
167
168#include "TD_PackPop.h"
169
170#endif // !defined(OdRxObjectImpl_INCLUDED_)
171
#define ODA_ASSERT(exp)
Definition DebugStuff.h:57
int OdRefCounter
Definition OdMutex.h:478
#define ODRX_NOEXCEPT
@ kOdRxObjAttach
Definition RxObject.h:56
#define OdRxObjectImpl2
static OdSmartPtr< T > createObject()
long numRefs() const
OdRxObjectImpl(Args &&... args)
static OdSmartPtr< TInterface > createObject(Args &&... args)
void release() ODRX_NOEXCEPT