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
File Members
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 <stdint.h>
29
#include <limits>
30
37
namespace
ns3
{
38
71
template
<
typename
T,
typename
PARENT = empty,
typename
DELETER = DefaultDeleter<T> >
72
class
SimpleRefCount
:
public
PARENT
73
{
74
public
:
78
SimpleRefCount
()
79
:
m_count
(1)
80
{}
84
SimpleRefCount
(
const
SimpleRefCount
&o)
85
:
m_count
(1)
86
{}
90
SimpleRefCount
&
operator =
(
const
SimpleRefCount
&o)
91
{
92
return
*
this
;
93
}
100
inline
void
Ref
(
void
)
const
101
{
102
NS_ASSERT
(
m_count
< std::numeric_limits<uint32_t>::max());
103
m_count
++;
104
}
111
inline
void
Unref
(
void
)
const
112
{
113
m_count
--;
114
if
(
m_count
== 0)
115
{
116
DELETER::Delete (static_cast<T*> (const_cast<SimpleRefCount *> (
this
)));
117
}
118
}
119
126
inline
uint32_t
GetReferenceCount
(
void
)
const
127
{
128
return
m_count
;
129
}
130
134
static
void
Cleanup
(
void
) {}
135
private
:
143
mutable
uint32_t
m_count
;
144
};
145
146
}
// namespace ns3
147
148
#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.
Definition:
simple-ref-count.h:90
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
ns3::SimpleRefCount::GetReferenceCount
uint32_t GetReferenceCount(void) const
Get the reference count of the object.
Definition:
simple-ref-count.h:126
assert.h
Definition of assertion macros NS_ASSERT() and NS_ASSERT_MSG().
ns3::SimpleRefCount::Unref
void Unref(void) const
Decrement the reference count.
Definition:
simple-ref-count.h:111
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::SimpleRefCount::SimpleRefCount
SimpleRefCount()
Constructor.
Definition:
simple-ref-count.h:78
ns3::SimpleRefCount::Ref
void Ref(void) const
Increment the reference count.
Definition:
simple-ref-count.h:100
default-deleter.h
Default deletion implementation for reference-counted smart pointers.
empty.h
Definition of class ns3::empty, used by callbacks.
ns3::SimpleRefCount::m_count
uint32_t m_count
The reference count.
Definition:
simple-ref-count.h:143
ns3::SimpleRefCount::Cleanup
static void Cleanup(void)
Noop.
Definition:
simple-ref-count.h:134
ns3::SimpleRefCount
A template-based reference counting class.
Definition:
simple-ref-count.h:72
src
core
model
simple-ref-count.h
Generated on Thu Jan 28 2016 11:05:16 for ns-3 by
1.8.9.1