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  ;
31 
35 class ChannelListPriv : public Object
36 {
37 public:
38  static TypeId GetTypeId (void);
39  ChannelListPriv ();
41 
42  uint32_t Add (Ptr<Channel> channel);
43 
44  ChannelList::Iterator Begin (void) const;
45  ChannelList::Iterator End (void) const;
46 
47  Ptr<Channel> GetChannel (uint32_t n);
48  uint32_t GetNChannels (void);
49 
50  static Ptr<ChannelListPriv> Get (void);
51 
52 private:
53  static Ptr<ChannelListPriv> *DoGet (void);
54  static void Delete (void);
55  virtual void DoDispose (void);
56  std::vector<Ptr<Channel> > m_channels;
57 };
58 
60  ;
61 
62 TypeId
64 {
65  static TypeId tid = TypeId ("ns3::ChannelListPriv")
66  .SetParent<Object> ()
67  .AddAttribute ("ChannelList", "The list of all channels created during the simulation.",
70  MakeObjectVectorChecker<Channel> ())
71  ;
72  return tid;
73 }
74 
77 {
79  return *DoGet ();
80 }
81 
84 {
86  static Ptr<ChannelListPriv> ptr = 0;
87  if (ptr == 0)
88  {
89  ptr = CreateObject<ChannelListPriv> ();
92  }
93  return &ptr;
94 }
95 
96 void
98 {
101  (*DoGet ()) = 0;
102 }
103 
105 {
106  NS_LOG_FUNCTION (this);
107 }
108 
110 {
111  NS_LOG_FUNCTION (this);
112 }
113 void
115 {
116  NS_LOG_FUNCTION (this);
117  for (std::vector<Ptr<Channel> >::iterator i = m_channels.begin ();
118  i != m_channels.end (); i++)
119  {
120  Ptr<Channel> channel = *i;
121  channel->Dispose ();
122  *i = 0;
123  }
124  m_channels.erase (m_channels.begin (), m_channels.end ());
126 }
127 
128 uint32_t
130 {
131  NS_LOG_FUNCTION (this << channel);
132  uint32_t index = m_channels.size ();
133  m_channels.push_back (channel);
134  return index;
135 
136 }
137 
140 {
141  NS_LOG_FUNCTION (this);
142  return m_channels.begin ();
143 }
144 
147 {
148  NS_LOG_FUNCTION (this);
149  return m_channels.end ();
150 }
151 
152 uint32_t
154 {
155  NS_LOG_FUNCTION (this);
156  return m_channels.size ();
157 }
158 
161 {
162  NS_LOG_FUNCTION (this << n);
163  NS_ASSERT_MSG (n < m_channels.size (), "Channel index " << n <<
164  " is out of range (only have " << m_channels.size () << " channels).");
165  return m_channels[n];
166 }
167 
168 uint32_t
170 {
172  return ChannelListPriv::Get ()->Add (channel);
173 }
174 
177 {
179  return ChannelListPriv::Get ()->Begin ();
180 }
181 
184 {
186  return ChannelListPriv::Get ()->End ();
187 }
188 
191 {
192  NS_LOG_FUNCTION (n);
193  return ChannelListPriv::Get ()->GetChannel (n);
194 }
195 
196 uint32_t
198 {
200  return ChannelListPriv::Get ()->GetNChannels ();
201 }
202 
203 } // 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:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
static uint32_t GetNChannels(void)
Ptr< Channel > GetChannel(uint32_t n)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
static Ptr< ChannelListPriv > Get(void)
Definition: channel-list.cc:76
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:336
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:751
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
uint32_t GetNChannels(void)
static Ptr< ChannelListPriv > * DoGet(void)
Definition: channel-list.cc:83
std::vector< Ptr< Channel > > m_channels
Definition: channel-list.cc:56
uint32_t Add(Ptr< Channel > channel)
ChannelList::Iterator End(void) const
std::vector< Ptr< Channel > >::const_iterator Iterator
Definition: channel-list.h:41
static Iterator Begin(void)
private implementation detail of the ChannelList API.
Definition: channel-list.cc:35
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:745
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
static void Delete(void)
Definition: channel-list.cc:97
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:1076
static Iterator End(void)
a base class which provides memory management and object aggregation
Definition: object.h:63
contain a set of ns3::Object pointers.
static Ptr< Channel > GetChannel(uint32_t n)
static TypeId GetTypeId(void)
Definition: channel-list.cc:63
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
ChannelList::Iterator Begin(void) const