A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
core
model
simple-ref-count.h
Go to the documentation of this file.
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 "
unused.h
"
29
#include <stdint.h>
30
#include <limits>
31
38
namespace
ns3
{
39
72
template
<
typename
T,
typename
PARENT = empty,
typename
DELETER = DefaultDeleter<T> >
73
class
SimpleRefCount
:
public
PARENT
74
{
75
public
:
77
SimpleRefCount
()
78
:
m_count
(1)
79
{}
84
SimpleRefCount
(
const
SimpleRefCount
&o)
85
:
m_count
(1)
86
{
87
NS_UNUSED
(o);
88
}
94
SimpleRefCount
&
operator =
(
const
SimpleRefCount
&o)
95
{
96
NS_UNUSED
(o);
97
return
*
this
;
98
}
105
inline
void
Ref
(
void
)
const
106
{
107
NS_ASSERT
(
m_count
<
std::numeric_limits<uint32_t>::max
());
108
m_count
++;
109
}
116
inline
void
Unref
(
void
)
const
117
{
118
m_count
--;
119
if
(
m_count
== 0)
120
{
121
DELETER::Delete (static_cast<T*> (const_cast<SimpleRefCount *> (
this
)));
122
}
123
}
124
131
inline
uint32_t
GetReferenceCount
(
void
)
const
132
{
133
return
m_count
;
134
}
135
136
private
:
144
mutable
uint32_t
m_count
;
145
};
146
147
}
// namespace ns3
148
149
#endif
/* SIMPLE_REF_COUNT_H */
ns3::SimpleRefCount::SimpleRefCount
SimpleRefCount(const SimpleRefCount &o)
Copy constructor.
Definition:
simple-ref-count.h:84
ns3::SimpleRefCount::operator=
SimpleRefCount & operator=(const SimpleRefCount &o)
Assignment operator.
Definition:
simple-ref-count.h:94
ns3::SimpleRefCount::Unref
void Unref(void) const
Decrement the reference count.
Definition:
simple-ref-count.h:116
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:67
NS_UNUSED
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition:
unused.h:36
max
#define max(a, b)
Definition:
80211b.c:43
assert.h
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
ns3::SimpleRefCount::GetReferenceCount
uint32_t GetReferenceCount(void) const
Get the reference count of the object.
Definition:
simple-ref-count.h:131
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::SimpleRefCount::SimpleRefCount
SimpleRefCount()
Default constructor.
Definition:
simple-ref-count.h:77
default-deleter.h
ns3::DefaultDeleter declaration and template implementation, for reference-counted smart pointers...
empty.h
ns3::empty declaration, used by callbacks.
ns3::SimpleRefCount::Ref
void Ref(void) const
Increment the reference count.
Definition:
simple-ref-count.h:105
ns3::SimpleRefCount::m_count
uint32_t m_count
The reference count.
Definition:
simple-ref-count.h:144
ns3::SimpleRefCount
A template-based reference counting class.
Definition:
simple-ref-count.h:73
unused.h
NS_UNUSED and NS_UNUSED_GLOBAL macro definitions.
Generated on Wed Nov 7 2018 10:01:50 for ns-3 by
1.8.14