A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
simple-ref-count.h
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 Georgia Tech Research Corporation, INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Authors: George Riley <riley@ece.gatech.edu>
19
* Gustavo Carneiro <gjcarneiro@gmail.com>,
20
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
21
*/
22
#ifndef SIMPLE_REF_COUNT_H
23
#define SIMPLE_REF_COUNT_H
24
25
#include "empty.h"
26
#include "default-deleter.h"
27
#include "assert.h"
28
#include <stdint.h>
29
#include <limits>
30
31
namespace
ns3 {
32
62
template
<
typename
T,
typename
PARENT = empty,
typename
DELETER = DefaultDeleter<T> >
63
class
SimpleRefCount
:
public
PARENT
64
{
65
public
:
66
SimpleRefCount
()
67
: m_count (1)
68
{}
69
SimpleRefCount
(
const
SimpleRefCount
&o)
70
: m_count (1)
71
{}
72
SimpleRefCount
&operator = (
const
SimpleRefCount
&o)
73
{
74
return
*
this
;
75
}
82
inline
void
Ref
(
void
)
const
83
{
84
NS_ASSERT
(m_count < std::numeric_limits<uint32_t>::max());
85
m_count++;
86
}
93
inline
void
Unref
(
void
)
const
94
{
95
m_count--;
96
if
(m_count == 0)
97
{
98
DELETER::Delete (static_cast<T*> (const_cast<SimpleRefCount *> (
this
)));
99
}
100
}
101
106
inline
uint32_t
GetReferenceCount
(
void
)
const
107
{
108
return
m_count;
109
}
110
111
static
void
Cleanup (
void
) {}
112
private
:
113
// Note we make this mutable so that the const methods can still
114
// change it.
115
mutable
uint32_t m_count;
116
};
117
118
}
// namespace ns3
119
120
#endif
/* SIMPLE_REF_COUNT_H */
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::SimpleRefCount::GetReferenceCount
uint32_t GetReferenceCount(void) const
Definition:
simple-ref-count.h:106
ns3::SimpleRefCount::Unref
void Unref(void) const
Definition:
simple-ref-count.h:93
ns3::SimpleRefCount::Ref
void Ref(void) const
Definition:
simple-ref-count.h:82
ns3::SimpleRefCount
A template-based reference counting class.
Definition:
simple-ref-count.h:63
src
core
model
simple-ref-count.h
Generated on Sun Mar 16 2014 11:25:02 for ns-3 by
1.8.6