A Discrete-Event Network Simulator
API
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 
36 class ChannelListPriv : public Object
37 {
38 public:
43  static TypeId GetTypeId (void);
44  ChannelListPriv ();
46 
54  uint32_t Add (Ptr<Channel> channel);
55 
60  ChannelList::Iterator Begin (void) const;
65  ChannelList::Iterator End (void) const;
66 
71  Ptr<Channel> GetChannel (uint32_t n);
72 
76  uint32_t GetNChannels (void);
77 
82  static Ptr<ChannelListPriv> Get (void);
83 
84 private:
89  static Ptr<ChannelListPriv> *DoGet (void);
90 
94  static void Delete (void);
95 
99  virtual void DoDispose (void);
100 
101  std::vector<Ptr<Channel> > m_channels;
102 };
103 
105 
106 TypeId
108 {
109  static TypeId tid = TypeId ("ns3::ChannelListPriv")
110  .SetParent<Object> ()
111  .SetGroupName("Network")
112  .AddAttribute ("ChannelList", "The list of all channels created during the simulation.",
115  MakeObjectVectorChecker<Channel> ())
116  ;
117  return tid;
118 }
119 
122 {
124  return *DoGet ();
125 }
126 
129 {
131  static Ptr<ChannelListPriv> ptr = 0;
132  if (ptr == 0)
133  {
134  ptr = CreateObject<ChannelListPriv> ();
137  }
138  return &ptr;
139 }
140 
141 void
143 {
146  (*DoGet ()) = 0;
147 }
148 
150 {
151  NS_LOG_FUNCTION (this);
152 }
153 
155 {
156  NS_LOG_FUNCTION (this);
157 }
158 void
160 {
161  NS_LOG_FUNCTION (this);
162  for (std::vector<Ptr<Channel> >::iterator i = m_channels.begin ();
163  i != m_channels.end (); i++)
164  {
165  Ptr<Channel> channel = *i;
166  channel->Dispose ();
167  *i = 0;
168  }
169  m_channels.erase (m_channels.begin (), m_channels.end ());
171 }
172 
173 uint32_t
175 {
176  NS_LOG_FUNCTION (this << channel);
177  uint32_t index = m_channels.size ();
178  m_channels.push_back (channel);
179  return index;
180 
181 }
182 
185 {
186  NS_LOG_FUNCTION (this);
187  return m_channels.begin ();
188 }
189 
192 {
193  NS_LOG_FUNCTION (this);
194  return m_channels.end ();
195 }
196 
197 uint32_t
199 {
200  NS_LOG_FUNCTION (this);
201  return m_channels.size ();
202 }
203 
206 {
207  NS_LOG_FUNCTION (this << n);
208  NS_ASSERT_MSG (n < m_channels.size (), "Channel index " << n <<
209  " is out of range (only have " << m_channels.size () << " channels).");
210  return m_channels[n];
211 }
212 
213 uint32_t
215 {
217  return ChannelListPriv::Get ()->Add (channel);
218 }
219 
222 {
224  return ChannelListPriv::Get ()->Begin ();
225 }
226 
229 {
231  return ChannelListPriv::Get ()->End ();
232 }
233 
236 {
237  NS_LOG_FUNCTION (n);
238  return ChannelListPriv::Get ()->GetChannel (n);
239 }
240 
241 uint32_t
243 {
245  return ChannelListPriv::Get ()->GetNChannels ();
246 }
247 
248 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ChannelList::Iterator End(void) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:866
static uint32_t GetNChannels(void)
Ptr< Channel > GetChannel(uint32_t n)
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:81
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
virtual void DoDispose(void)
Dispose the channels in the list.
static Ptr< ChannelListPriv > Get(void)
Get the channel list object.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
uint32_t GetNChannels(void)
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:860
channel
Definition: third.py:85
static Ptr< ChannelListPriv > * DoGet(void)
Get the channel list object.
ChannelList::Iterator Begin(void) const
std::vector< Ptr< Channel > > m_channels
channel objects container
uint32_t Add(Ptr< Channel > channel)
std::vector< Ptr< Channel > >::const_iterator Iterator
Channel container iterator.
Definition: channel-list.h:42
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static Iterator Begin(void)
private implementation detail of the ChannelList API.
Definition: channel-list.cc:36
static void Delete(void)
Delete the channel list object.
static uint32_t Add(Ptr< Channel > channel)
static EventId ScheduleDestroy(MEM mem_ptr, OBJ obj)
Schedule an event to expire when Simulator::Destroy is called.
Definition: simulator.h:1677
static Iterator End(void)
A base class which provides memory management and object aggregation.
Definition: object.h:87
Container for a set of ns3::Object pointers.
static Ptr< Channel > GetChannel(uint32_t n)
static TypeId GetTypeId(void)
Get the type ID.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915