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 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#include "channel-list.h"
8
9#include "channel.h"
10
11#include "ns3/assert.h"
12#include "ns3/config.h"
13#include "ns3/log.h"
14#include "ns3/object-vector.h"
15#include "ns3/simulator.h"
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("ChannelList");
21
22/**
23 * \ingroup network
24 *
25 * \brief private implementation detail of the ChannelList API.
26 */
27class ChannelListPriv : public Object
28{
29 public:
30 /**
31 * \brief Get the type ID.
32 * \return the object TypeId
33 */
34 static TypeId GetTypeId();
36 ~ChannelListPriv() override;
37
38 /**
39 * \param channel channel to add
40 * \returns index of channel in list.
41 *
42 * This method is called automatically from Channel::Channel so
43 * the user has little reason to call it himself.
44 */
45 uint32_t Add(Ptr<Channel> channel);
46
47 /**
48 * \returns a C++ iterator located at the beginning of this
49 * list.
50 */
52 /**
53 * \returns a C++ iterator located at the end of this
54 * list.
55 */
57
58 /**
59 * \param n index of requested channel.
60 * \returns the Channel associated to index n.
61 */
63
64 /**
65 * \returns the number of channels currently in the list.
66 */
68
69 /**
70 * \brief Get the channel list object
71 * \returns the channel list
72 */
74
75 private:
76 /**
77 * \brief Get the channel list object
78 * \returns the channel list
79 */
81
82 /**
83 * \brief Delete the channel list object
84 */
85 static void Delete();
86
87 /**
88 * \brief Dispose the channels in the list
89 */
90 void DoDispose() override;
91
92 std::vector<Ptr<Channel>> m_channels; //!< channel objects container
93};
94
96
99{
100 static TypeId tid = TypeId("ns3::ChannelListPriv")
101 .SetParent<Object>()
102 .SetGroupName("Network")
103 .AddAttribute("ChannelList",
104 "The list of all channels created during the simulation.",
108 return tid;
109}
110
113{
115 return *DoGet();
116}
117
120{
122 static Ptr<ChannelListPriv> ptr = nullptr;
123 if (!ptr)
124 {
128 }
129 return &ptr;
130}
131
132void
139
144
149
150void
152{
153 NS_LOG_FUNCTION(this);
154 for (auto i = m_channels.begin(); i != m_channels.end(); i++)
155 {
156 Ptr<Channel> channel = *i;
157 channel->Dispose();
158 *i = nullptr;
159 }
160 m_channels.erase(m_channels.begin(), m_channels.end());
162}
163
166{
167 NS_LOG_FUNCTION(this << channel);
168 uint32_t index = m_channels.size();
169 m_channels.push_back(channel);
170 Simulator::Schedule(TimeStep(0), &Channel::Initialize, channel);
171 return index;
172}
173
176{
177 NS_LOG_FUNCTION(this);
178 return m_channels.begin();
179}
180
183{
184 NS_LOG_FUNCTION(this);
185 return m_channels.end();
186}
187
190{
191 NS_LOG_FUNCTION(this);
192 return m_channels.size();
193}
194
197{
198 NS_LOG_FUNCTION(this << n);
199 NS_ASSERT_MSG(n < m_channels.size(),
200 "Channel index " << n << " is out of range (only have " << m_channels.size()
201 << " channels).");
202 return m_channels[n];
203}
204
207{
209 return ChannelListPriv::Get()->Add(channel);
210}
211
214{
216 return ChannelListPriv::Get()->Begin();
217}
218
221{
223 return ChannelListPriv::Get()->End();
224}
225
228{
230 return ChannelListPriv::Get()->GetChannel(n);
231}
232
235{
237 return ChannelListPriv::Get()->GetNChannels();
238}
239
240} // 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.
static Iterator End()
private implementation detail of the ChannelList API.
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:78
void Initialize()
Invoke DoInitialize on all Objects aggregated to this one.
Definition object.cc:203
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
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:611
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#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:75
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition config.cc:1005
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition config.cc:998
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeObjectVectorChecker()
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.