A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
simple-ref-count.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007 Georgia Tech Research Corporation, INRIA
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Authors: George Riley <riley@ece.gatech.edu>
18
* Gustavo Carneiro <gjcarneiro@gmail.com>,
19
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20
*/
21
#ifndef SIMPLE_REF_COUNT_H
22
#define SIMPLE_REF_COUNT_H
23
24
#include "
assert.h
"
25
#include "
default-deleter.h
"
26
27
#include <limits>
28
#include <stdint.h>
29
36
namespace
ns3
37
{
38
43
class
Empty
44
{
45
};
46
79
template
<
typename
T,
typename
PARENT = Empty,
typename
DELETER = DefaultDeleter<T>>
80
class
SimpleRefCount
:
public
PARENT
81
{
82
public
:
84
SimpleRefCount
()
85
:
m_count
(1)
86
{
87
}
88
93
SimpleRefCount
(
const
SimpleRefCount
& o [[maybe_unused]])
94
:
m_count
(1)
95
{
96
}
97
103
SimpleRefCount
&
operator=
(
const
SimpleRefCount
& o [[maybe_unused]])
104
{
105
return
*
this
;
106
}
107
114
inline
void
Ref
()
const
115
{
116
NS_ASSERT
(
m_count
<
std::numeric_limits<uint32_t>::max
());
117
m_count
++;
118
}
119
126
inline
void
Unref
()
const
127
{
128
m_count
--;
129
if
(
m_count
== 0)
130
{
131
DELETER::Delete(
static_cast<
T*
>
(
const_cast<
SimpleRefCount
*
>
(
this
)));
132
}
133
}
134
141
inline
uint32_t
GetReferenceCount
()
const
142
{
143
return
m_count
;
144
}
145
146
private
:
154
mutable
uint32_t
m_count
;
155
};
156
157
}
// namespace ns3
158
159
#endif
/* SIMPLE_REF_COUNT_H */
max
#define max(a, b)
Definition:
80211b.c:42
assert.h
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
ns3::Empty
Empty class, used as a default parent class for SimpleRefCount.
Definition:
simple-ref-count.h:44
ns3::SimpleRefCount
A template-based reference counting class.
Definition:
simple-ref-count.h:81
ns3::SimpleRefCount::SimpleRefCount
SimpleRefCount(const SimpleRefCount &o[[maybe_unused]])
Copy constructor.
Definition:
simple-ref-count.h:93
ns3::SimpleRefCount::GetReferenceCount
uint32_t GetReferenceCount() const
Get the reference count of the object.
Definition:
simple-ref-count.h:141
ns3::SimpleRefCount::SimpleRefCount
SimpleRefCount()
Default constructor.
Definition:
simple-ref-count.h:84
ns3::SimpleRefCount::operator=
SimpleRefCount & operator=(const SimpleRefCount &o[[maybe_unused]])
Assignment operator.
Definition:
simple-ref-count.h:103
ns3::SimpleRefCount::Ref
void Ref() const
Increment the reference count.
Definition:
simple-ref-count.h:114
ns3::SimpleRefCount::m_count
uint32_t m_count
The reference count.
Definition:
simple-ref-count.h:154
ns3::SimpleRefCount::Unref
void Unref() const
Decrement the reference count.
Definition:
simple-ref-count.h:126
default-deleter.h
ns3::DefaultDeleter declaration and template implementation, for reference-counted smart pointers.
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition:
assert.h:66
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
model
simple-ref-count.h
Generated on Sun Mar 3 2024 17:10:55 for ns-3 by
1.9.1