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
33/**
34 * \ingroup network
35 *
36 * \brief private implementation detail of the ChannelList API.
37 */
38class ChannelListPriv : public Object
39{
40 public:
41 /**
42 * \brief Get the type ID.
43 * \return the object TypeId
44 */
45 static TypeId GetTypeId();
47 ~ChannelListPriv() override;
48
49 /**
50 * \param channel channel to add
51 * \returns index of channel in list.
52 *
53 * This method is called automatically from Channel::Channel so
54 * the user has little reason to call it himself.
55 */
56 uint32_t Add(Ptr<Channel> channel);
57
58 /**
59 * \returns a C++ iterator located at the beginning of this
60 * list.
61 */
63 /**
64 * \returns a C++ iterator located at the end of this
65 * list.
66 */
68
69 /**
70 * \param n index of requested channel.
71 * \returns the Channel associated to index n.
72 */
74
75 /**
76 * \returns the number of channels currently in the list.
77 */
79
80 /**
81 * \brief Get the channel list object
82 * \returns the channel list
83 */
85
86 private:
87 /**
88 * \brief Get the channel list object
89 * \returns the channel list
90 */
92
93 /**
94 * \brief Delete the channel list object
95 */
96 static void Delete();
97
98 /**
99 * \brief Dispose the channels in the list
100 */
101 void DoDispose() override;
102
103 std::vector<Ptr<Channel>> m_channels; //!< channel objects container
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 (auto 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 Simulator::Schedule(TimeStep(0), &Channel::Initialize, channel);
182 return index;
183}
184
187{
188 NS_LOG_FUNCTION(this);
189 return m_channels.begin();
190}
191
194{
195 NS_LOG_FUNCTION(this);
196 return m_channels.end();
197}
198
201{
202 NS_LOG_FUNCTION(this);
203 return m_channels.size();
204}
205
208{
209 NS_LOG_FUNCTION(this << n);
210 NS_ASSERT_MSG(n < m_channels.size(),
211 "Channel index " << n << " is out of range (only have " << m_channels.size()
212 << " channels).");
213 return m_channels[n];
214}
215
218{
220 return ChannelListPriv::Get()->Add(channel);
221}
222
225{
227 return ChannelListPriv::Get()->Begin();
228}
229
232{
234 return ChannelListPriv::Get()->End();
235}
236
239{
241 return ChannelListPriv::Get()->GetChannel(n);
242}
243
246{
248 return ChannelListPriv::Get()->GetNChannels();
249}
250
251} // 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
void Initialize()
Invoke DoInitialize on all Objects aggregated to this one.
Definition: object.cc:214
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:444
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
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:622
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#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:1016
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:1009
#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.