OpenZWave Library 1.2
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
35namespace OpenZWave
36{
45 class Ref
46 {
47 public:
53 Ref(){ m_refs = 1; }
54
61 void AddRef(){ ++m_refs; }
62
70 {
71 if( 0 >= ( --m_refs ) )
72 {
73 delete this;
74 return 0;
75 }
76 return m_refs;
77 }
78
79 protected:
80 virtual ~Ref(){}
81
82 private:
83 // Reference counting
84 int32 m_refs;
85
86 }; // class Ref
87
88} // namespace OpenZWave
89
90#endif // _Ref_H
91
signed int int32
Definition: Defs.h:68
Definition: Ref.h:46
Ref()
Definition: Ref.h:53
virtual ~Ref()
Definition: Ref.h:80
void AddRef()
Definition: Ref.h:61
int32 Release()
Definition: Ref.h:69
Definition: Bitfield.h:35