A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
channel-list.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
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
18#include "channel-list.h"
19
20#include "channel.h"
21
22#include "ns3/assert.h"
23#include "ns3/config.h"
24#include "ns3/log.h"
25#include "ns3/object-vector.h"
26#include "ns3/simulator.h"
27
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("ChannelList");
32
38class ChannelListPriv : public Object
39{
40 public:
45 static TypeId GetTypeId();
47 ~ChannelListPriv() override;
48
56 uint32_t Add(Ptr<Channel> channel);
57
68
74
79
85
86 private:
92
96 static void Delete();
97
101 void DoDispose() override;
102
103 std::vector<Ptr<Channel>> m_channels;
104};
105
107
108TypeId
110{
111 static TypeId tid = TypeId("ns3::ChannelListPriv")
112 .SetParent<Object>()
113 .SetGroupName("Network")
114 .AddAttribute("ChannelList",
115 "The list of all channels created during the simulation.",
118 MakeObjectVectorChecker<Channel>());
119 return tid;
120}
121
124{
126 return *DoGet();
127}
128
131{
133 static Ptr<ChannelListPriv> ptr = nullptr;
134 if (!ptr)
135 {
136 ptr = CreateObject<ChannelListPriv>();
139 }
140 return &ptr;
141}
142
143void
145{
148 (*DoGet()) = nullptr;
149}
150
152{
153 NS_LOG_FUNCTION(this);
154}
155
157{
158 NS_LOG_FUNCTION(this);
159}
160
161void
163{
164 NS_LOG_FUNCTION(this);
165 for (std::vector<Ptr<Channel>>::iterator i = m_channels.begin(); i != m_channels.end(); i++)
166 {
167 Ptr<Channel> channel = *i;
168 channel->Dispose();
169 *i = nullptr;
170 }
171 m_channels.erase(m_channels.begin(), m_channels.end());
173}
174
177{
178 NS_LOG_FUNCTION(this << channel);
179 uint32_t index = m_channels.size();
180 m_channels.push_back(channel);
181 return index;
182}
183
186{
187 NS_LOG_FUNCTION(this);
188 return m_channels.begin();
189}
190
193{
194 NS_LOG_FUNCTION(this);
195 return m_channels.end();
196}
197
200{
201 NS_LOG_FUNCTION(this);
202 return m_channels.size();
203}
204
207{
208 NS_LOG_FUNCTION(this << n);
209 NS_ASSERT_MSG(n < m_channels.size(),
210 "Channel index " << n << " is out of range (only have " << m_channels.size()
211 << " channels).");
212 return m_channels[n];
213}
214
217{
219 return ChannelListPriv::Get()->Add(channel);
220}
221
224{
226 return ChannelListPriv::Get()->Begin();
227}
228
231{
233 return ChannelListPriv::Get()->End();
234}
235
238{
240 return ChannelListPriv::Get()->GetChannel(n);
241}
242
245{
247 return ChannelListPriv::Get()->GetNChannels();
248}
249
250} // namespace ns3
static Ptr< Channel > GetChannel(uint32_t n)
static uint32_t Add(Ptr< Channel > channel)
static uint32_t GetNChannels()
static Iterator Begin()
std::vector< Ptr< Channel > >::const_iterator Iterator
Channel container iterator.
Definition: channel-list.h:42
static Iterator End()
private implementation detail of the ChannelList API.
Definition: channel-list.cc:39
uint32_t Add(Ptr< Channel > channel)
static TypeId GetTypeId()
Get the type ID.
~ChannelListPriv() override
static Ptr< ChannelListPriv > * DoGet()
Get the channel list object.
static Ptr< ChannelListPriv > Get()
Get the channel list object.
static void Delete()
Delete the channel list object.
ChannelList::Iterator Begin() const
Ptr< Channel > GetChannel(uint32_t n)
void DoDispose() override
Dispose the channels in the list.
ChannelList::Iterator End() const
std::vector< Ptr< Channel > > m_channels
channel objects container
A base class which provides memory management and object aggregation.
Definition: object.h:89
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:353
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static EventId ScheduleDestroy(FUNC f, Ts &&... args)
Schedule an event to run at the end of the simulation, when Simulator::Destroy() is called.
Definition: simulator.h:625
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Definition: object-vector.h:40
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:76
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:1013
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:1006
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.