My Project: dynamics.mod/NewtonDynamics/source/core/dgRefCounter.h Source File

My Project

dgRefCounter.h
Go to the documentation of this file.
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21
22 #ifndef __DGREF_COUNTER__
23 #define __DGREF_COUNTER__
24
25 class dgRefCounter
26 {
27 public:
28 dgRefCounter(void);
29 int GetRef() const;
30 int Release();
31 void AddRef();
32
33 protected:
34 virtual ~dgRefCounter(void);
35
36 private:
37 int m_refCount;
38 };
39
40
41 inline dgRefCounter::dgRefCounter(void)
42 {
43 m_refCount = 1;
44 }
45
46 inline dgRefCounter::~dgRefCounter(void)
47 {
48 dgAssert (m_refCount <= 1);
49 }
50
51
52 inline int dgRefCounter::GetRef() const
53 {
54 return m_refCount;
55 }
56
57 inline int dgRefCounter::Release()
58 {
59 m_refCount --;
60 if (!m_refCount) {
61 delete this;
62 return 0;
63 }
64 return m_refCount;
65 }
66
67 inline void dgRefCounter::AddRef()
68 {
69 m_refCount ++;
70 }
71
72 #endif
dgAssert
#define dgAssert(x)
Definition: dgTypes.h:158
dgRefCounter::dgRefCounter
dgRefCounter(void)
Definition: dgRefCounter.h:41
dgRefCounter
Definition: dgRefCounter.h:25
dgRefCounter::Release
int Release()
Definition: dgRefCounter.h:57
dgRefCounter::~dgRefCounter
virtual ~dgRefCounter(void)
Definition: dgRefCounter.h:46
dgRefCounter::AddRef
void AddRef()
Definition: dgRefCounter.h:67
dgRefCounter::GetRef
int GetRef() const
Definition: dgRefCounter.h:52