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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
channel-list.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 University of Washington
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
19
#include "ns3/simulator.h"
20
#include "ns3/object-vector.h"
21
#include "ns3/config.h"
22
#include "ns3/log.h"
23
#include "ns3/assert.h"
24
#include "
channel-list.h
"
25
#include "
channel.h
"
26
27
namespace
ns3 {
28
29
NS_LOG_COMPONENT_DEFINE
(
"ChannelList"
);
30
34
class
ChannelListPriv
:
public
Object
35
{
36
public
:
37
static
TypeId
GetTypeId
(
void
);
38
ChannelListPriv
();
39
~ChannelListPriv
();
40
41
uint32_t
Add
(
Ptr<Channel>
channel);
42
43
ChannelList::Iterator
Begin
(
void
)
const
;
44
ChannelList::Iterator
End
(
void
)
const
;
45
46
Ptr<Channel>
GetChannel
(uint32_t n);
47
uint32_t
GetNChannels
(
void
);
48
49
static
Ptr<ChannelListPriv>
Get
(
void
);
50
51
private
:
52
static
Ptr<ChannelListPriv>
*
DoGet
(
void
);
53
static
void
Delete
(
void
);
54
virtual
void
DoDispose
(
void
);
55
std::vector<Ptr<Channel> >
m_channels
;
56
};
57
58
NS_OBJECT_ENSURE_REGISTERED
(
ChannelListPriv
);
59
60
TypeId
61
ChannelListPriv::GetTypeId
(
void
)
62
{
63
static
TypeId
tid =
TypeId
(
"ns3::ChannelListPriv"
)
64
.
SetParent
<
Object
> ()
65
.AddAttribute (
"ChannelList"
,
"The list of all channels created during the simulation."
,
66
ObjectVectorValue
(),
67
MakeObjectVectorAccessor
(&
ChannelListPriv::m_channels
),
68
MakeObjectVectorChecker<Channel> ())
69
;
70
return
tid;
71
}
72
73
Ptr<ChannelListPriv>
74
ChannelListPriv::Get
(
void
)
75
{
76
return
*
DoGet
();
77
}
78
79
Ptr<ChannelListPriv>
*
80
ChannelListPriv::DoGet
(
void
)
81
{
82
static
Ptr<ChannelListPriv>
ptr = 0;
83
if
(ptr == 0)
84
{
85
ptr = CreateObject<ChannelListPriv> ();
86
Config::RegisterRootNamespaceObject
(ptr);
87
Simulator::ScheduleDestroy
(&
ChannelListPriv::Delete
);
88
}
89
return
&ptr;
90
}
91
92
void
93
ChannelListPriv::Delete
(
void
)
94
{
95
NS_LOG_FUNCTION_NOARGS
();
96
Config::UnregisterRootNamespaceObject
(
Get
());
97
(*
DoGet
()) = 0;
98
}
99
100
ChannelListPriv::ChannelListPriv
()
101
{
102
NS_LOG_FUNCTION_NOARGS
();
103
}
104
105
ChannelListPriv::~ChannelListPriv
()
106
{
107
}
108
void
109
ChannelListPriv::DoDispose
(
void
)
110
{
111
NS_LOG_FUNCTION_NOARGS
();
112
for
(std::vector<
Ptr<Channel>
>::iterator i =
m_channels
.begin ();
113
i !=
m_channels
.end (); i++)
114
{
115
Ptr<Channel>
channel = *i;
116
channel->
Dispose
();
117
*i = 0;
118
}
119
m_channels
.erase (
m_channels
.begin (),
m_channels
.end ());
120
Object::DoDispose
();
121
}
122
123
uint32_t
124
ChannelListPriv::Add
(
Ptr<Channel>
channel)
125
{
126
uint32_t index =
m_channels
.size ();
127
m_channels
.push_back (channel);
128
return
index;
129
130
}
131
132
ChannelList::Iterator
133
ChannelListPriv::Begin
(
void
)
const
134
{
135
return
m_channels
.begin ();
136
}
137
138
ChannelList::Iterator
139
ChannelListPriv::End
(
void
)
const
140
{
141
return
m_channels
.end ();
142
}
143
144
uint32_t
145
ChannelListPriv::GetNChannels
(
void
)
146
{
147
return
m_channels
.size ();
148
}
149
150
Ptr<Channel>
151
ChannelListPriv::GetChannel
(uint32_t n)
152
{
153
NS_ASSERT_MSG
(n <
m_channels
.size (),
"Channel index "
<< n <<
154
" is out of range (only have "
<<
m_channels
.size () <<
" channels)."
);
155
return
m_channels
[n];
156
}
157
158
uint32_t
159
ChannelList::Add
(
Ptr<Channel>
channel)
160
{
161
return
ChannelListPriv::Get
()->Add (channel);
162
}
163
164
ChannelList::Iterator
165
ChannelList::Begin
(
void
)
166
{
167
return
ChannelListPriv::Get
()->Begin ();
168
}
169
170
ChannelList::Iterator
171
ChannelList::End
(
void
)
172
{
173
return
ChannelListPriv::Get
()->End ();
174
}
175
176
Ptr<Channel>
177
ChannelList::GetChannel
(uint32_t n)
178
{
179
return
ChannelListPriv::Get
()->GetChannel (n);
180
}
181
182
uint32_t
183
ChannelList::GetNChannels
(
void
)
184
{
185
return
ChannelListPriv::Get
()->GetNChannels ();
186
}
187
188
}
// namespace ns3
src
network
model
channel-list.cc
Generated on Tue Oct 9 2012 16:45:43 for ns-3 by
1.8.1.2