ScummVM API documentation
dgRefCounter.h
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 public:
27  dgRefCounter(void);
28  int GetRef() const;
29  int Release();
30  void AddRef();
31 
32 protected:
33  virtual ~dgRefCounter(void);
34 
35 private:
36  int m_refCount;
37 };
38 
39 
40 inline dgRefCounter::dgRefCounter(void) {
41  m_refCount = 1;
42 }
43 
44 inline dgRefCounter::~dgRefCounter(void) {
45  NEWTON_ASSERT(m_refCount <= 1);
46 }
47 
48 
49 inline int dgRefCounter::GetRef() const {
50  return m_refCount;
51 }
52 
53 inline int dgRefCounter::Release() {
54  m_refCount --;
55  if (!m_refCount) {
56  delete this;
57  return 0;
58  }
59  return m_refCount;
60 }
61 
62 inline void dgRefCounter::AddRef() {
63  m_refCount ++;
64 }
65 
66 #endif
Definition: dgRefCounter.h:25