A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  .AddAttribute ("ChannelList", "The list of all channels created during the simulation.",
114  MakeObjectVectorChecker<Channel> ())
115  ;
116  return tid;
117 }
118 
121 {
123  return *DoGet ();
124 }
125 
128 {
130  static Ptr<ChannelListPriv> ptr = 0;
131  if (ptr == 0)
132  {
133  ptr = CreateObject<ChannelListPriv> ();
136  }
137  return &ptr;
138 }
139 
140 void
142 {
145  (*DoGet ()) = 0;
146 }
147 
149 {
150  NS_LOG_FUNCTION (this);
151 }
152 
154 {
155  NS_LOG_FUNCTION (this);
156 }
157 void
159 {
160  NS_LOG_FUNCTION (this);
161  for (std::vector<Ptr<Channel> >::iterator i = m_channels.begin ();
162  i != m_channels.end (); i++)
163  {
164  Ptr<Channel> channel = *i;
165  channel->Dispose ();
166  *i = 0;
167  }
168  m_channels.erase (m_channels.begin (), m_channels.end ());
170 }
171 
172 uint32_t
174 {
175  NS_LOG_FUNCTION (this << channel);
176  uint32_t index = m_channels.size ();
177  m_channels.push_back (channel);
178  return index;
179 
180 }
181 
184 {
185  NS_LOG_FUNCTION (this);
186  return m_channels.begin ();
187 }
188 
191 {
192  NS_LOG_FUNCTION (this);
193  return m_channels.end ();
194 }
195 
196 uint32_t
198 {
199  NS_LOG_FUNCTION (this);
200  return m_channels.size ();
201 }
202 
205 {
206  NS_LOG_FUNCTION (this << n);
207  NS_ASSERT_MSG (n < m_channels.size (), "Channel index " << n <<
208  " is out of range (only have " << m_channels.size () << " channels).");
209  return m_channels[n];
210 }
211 
212 uint32_t
214 {
216  return ChannelListPriv::Get ()->Add (channel);
217 }
218 
221 {
223  return ChannelListPriv::Get ()->Begin ();
224 }
225 
228 {
230  return ChannelListPriv::Get ()->End ();
231 }
232 
235 {
236  NS_LOG_FUNCTION (n);
237  return ChannelListPriv::Get ()->GetChannel (n);
238 }
239 
240 uint32_t
242 {
244  return ChannelListPriv::Get ()->GetNChannels ();
245 }
246 
247 } // namespace ns3
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberContainer)
Definition: object-vector.h:51
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#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 the class in the ns-3 factory.
Definition: object-base.h:38
static uint32_t GetNChannels(void)
Ptr< Channel > GetChannel(uint32_t n)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
virtual void DoDispose(void)
Dispose the channels in the list.
static Ptr< ChannelListPriv > Get(void)
Get the channel list object.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:335
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:751
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
uint32_t GetNChannels(void)
static Ptr< ChannelListPriv > * DoGet(void)
Get the channel list object.
std::vector< Ptr< Channel > > m_channels
channel objects container
uint32_t Add(Ptr< Channel > channel)
ChannelList::Iterator End(void) const
std::vector< Ptr< Channel > >::const_iterator Iterator
Channel container iterator.
Definition: channel-list.h:42
static Iterator Begin(void)
private implementation detail of the ChannelList API.
Definition: channel-list.cc:36
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:745
#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:84
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 at Destroy time.
Definition: simulator.h:1077
static Iterator End(void)
a base class which provides memory management and object aggregation
Definition: object.h:64
contain 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:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
ChannelList::Iterator Begin(void) const