A Discrete-Event Network Simulator
API
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 
28 namespace ns3
29 {
30 
31 NS_LOG_COMPONENT_DEFINE("ChannelList");
32 
38 class ChannelListPriv : public Object
39 {
40  public:
45  static TypeId GetTypeId();
47  ~ChannelListPriv() override;
48 
56  uint32_t Add(Ptr<Channel> channel);
57 
67  ChannelList::Iterator End() const;
68 
73  Ptr<Channel> GetChannel(uint32_t n);
74 
78  uint32_t GetNChannels();
79 
84  static Ptr<ChannelListPriv> Get();
85 
86  private:
91  static Ptr<ChannelListPriv>* DoGet();
92 
96  static void Delete();
97 
101  void DoDispose() override;
102 
103  std::vector<Ptr<Channel>> m_channels;
104 };
105 
107 
108 TypeId
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 
143 void
145 {
148  (*DoGet()) = nullptr;
149 }
150 
152 {
153  NS_LOG_FUNCTION(this);
154 }
155 
157 {
158  NS_LOG_FUNCTION(this);
159 }
160 
161 void
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 
175 uint32_t
177 {
178  NS_LOG_FUNCTION(this << channel);
179  uint32_t index = m_channels.size();
180  m_channels.push_back(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 
199 uint32_t
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 
216 uint32_t
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 {
240  NS_LOG_FUNCTION(n);
241  return ChannelListPriv::Get()->GetChannel(n);
242 }
243 
244 uint32_t
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)
std::vector< Ptr< Channel > >::const_iterator Iterator
Channel container iterator.
Definition: channel-list.h:42
static uint32_t GetNChannels()
static Iterator Begin()
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:186
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:352
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:931
#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
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:1012
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:1005
#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.
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
channel
Definition: third.py:88