CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
RefCountImpl.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(_ODREFCOUNTIMPL_INCLUDED_)
28#define _ODREFCOUNTIMPL_INCLUDED_
29
30#include "TD_PackPush.h"
31
32#include "RxObject.h"
33
40template<class T, class TInterface = T>
41class OdRefCountImpl : public T
42{
46 OdUInt32 m_nRefCounter;
47
51 OdRefCountImpl& operator = (const OdRefCountImpl&);
52
56 ODRX_HEAP_OPERATORS();
57
61 OdRefCountImpl() : m_nRefCounter(1) {}
62public:
63
67 void addRef()
68 {
69 ++m_nRefCounter;
70 }
71
76 void release()
77 {
78 ODA_ASSERT((m_nRefCounter > 0));
79 if (!(--m_nRefCounter))
80 {
81 T::onFinalRelease();
82 delete this;
83 }
84 }
85
86 long numRefs() const { return m_nRefCounter; }
87
93 {
94 return OdSmartPtr<TInterface>(static_cast<TInterface*>(new OdRefCountImpl<T, TInterface>), kOdRxObjAttach);
95 }
96};
97
98#define ODREFCOUNTIMPL_CONSTR(CLASS, pRes) pRes = OdRefCountImpl<CLASS>::createObject()
99
100#include "TD_PackPop.h"
101
102#endif // !defined(_ODREFCOUNTIMPL_INCLUDED_)
103
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:57
unsigned int OdUInt32
@ kOdRxObjAttach
Definition: RxObject.h:56
static OdSmartPtr< TInterface > createObject()
Definition: RefCountImpl.h:92
long numRefs() const
Definition: RefCountImpl.h:86