OpenZWave Library  1.6.962
Ref.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Ref.h
4 //
5 // Reference counting for objects.
6 //
7 // Copyright (c) 2010 Mal Lansell <mal@lansell.org>
8 // All rights reserved.
9 //
10 // SOFTWARE NOTICE AND LICENSE
11 //
12 // This file is part of OpenZWave.
13 //
14 // OpenZWave is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU Lesser General Public License as published
16 // by the Free Software Foundation, either version 3 of the License,
17 // or (at your option) any later version.
18 //
19 // OpenZWave is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU Lesser General Public License for more details.
23 //
24 // You should have received a copy of the GNU Lesser General Public License
25 // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
26 //
27 //-----------------------------------------------------------------------------
28 #ifndef _Ref_H
29 #define _Ref_H
30 
31 #pragma once
32 
33 #include "Defs.h"
34 
35 namespace OpenZWave
36 {
37  namespace Internal
38  {
39  namespace Platform
40  {
50  class Ref
51  {
52  public:
58  Ref()
59  {
60  m_refs = 1;
61  }
62 
69  void AddRef()
70  {
71  ++m_refs;
72  }
73 
81  {
82  if (0 >= (--m_refs))
83  {
84  delete this;
85  return 0;
86  }
87  return m_refs;
88  }
89 
90  protected:
91  virtual ~Ref()
92  {
93  }
94 
95  private:
96  // Reference counting
97  int32 m_refs;
98 
99  };
100  // class Ref
101  }// namespace Platform
102  } // namespace Internal
103 } // namespace OpenZWave
104 
105 #endif // _Ref_H
106 
Definition: Bitfield.cpp:30
virtual ~Ref()
Definition: Ref.h:91
void AddRef()
Definition: Ref.h:69
signed int int32
Definition: Defs.h:90
int32 Release()
Definition: Ref.h:80