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 
34 class ChannelListPriv : public Object
35 {
36 public:
37  static TypeId GetTypeId (void);
38  ChannelListPriv ();
40 
41  uint32_t Add (Ptr<Channel> channel);
42 
43  ChannelList::Iterator Begin (void) const;
44  ChannelList::Iterator End (void) const;
45 
46  Ptr<Channel> GetChannel (uint32_t n);
47  uint32_t GetNChannels (void);
48 
49  static Ptr<ChannelListPriv> Get (void);
50 
51 private:
52  static Ptr<ChannelListPriv> *DoGet (void);
53  static void Delete (void);
54  virtual void DoDispose (void);
55  std::vector<Ptr<Channel> > m_channels;
56 };
57 
59 
60 TypeId
62 {
63  static TypeId tid = TypeId ("ns3::ChannelListPriv")
64  .SetParent<Object> ()
65  .AddAttribute ("ChannelList", "The list of all channels created during the simulation.",
68  MakeObjectVectorChecker<Channel> ())
69  ;
70  return tid;
71 }
72 
75 {
77  return *DoGet ();
78 }
79 
82 {
84  static Ptr<ChannelListPriv> ptr = 0;
85  if (ptr == 0)
86  {
87  ptr = CreateObject<ChannelListPriv> ();
90  }
91  return &ptr;
92 }
93 
94 void
96 {
99  (*DoGet ()) = 0;
100 }
101 
103 {
104  NS_LOG_FUNCTION (this);
105 }
106 
108 {
109  NS_LOG_FUNCTION (this);
110 }
111 void
113 {
114  NS_LOG_FUNCTION (this);
115  for (std::vector<Ptr<Channel> >::iterator i = m_channels.begin ();
116  i != m_channels.end (); i++)
117  {
118  Ptr<Channel> channel = *i;
119  channel->Dispose ();
120  *i = 0;
121  }
122  m_channels.erase (m_channels.begin (), m_channels.end ());
124 }
125 
126 uint32_t
128 {
129  NS_LOG_FUNCTION (this << channel);
130  uint32_t index = m_channels.size ();
131  m_channels.push_back (channel);
132  return index;
133 
134 }
135 
138 {
139  NS_LOG_FUNCTION (this);
140  return m_channels.begin ();
141 }
142 
145 {
146  NS_LOG_FUNCTION (this);
147  return m_channels.end ();
148 }
149 
150 uint32_t
152 {
153  NS_LOG_FUNCTION (this);
154  return m_channels.size ();
155 }
156 
159 {
160  NS_LOG_FUNCTION (this << n);
161  NS_ASSERT_MSG (n < m_channels.size (), "Channel index " << n <<
162  " is out of range (only have " << m_channels.size () << " channels).");
163  return m_channels[n];
164 }
165 
166 uint32_t
168 {
170  return ChannelListPriv::Get ()->Add (channel);
171 }
172 
175 {
177  return ChannelListPriv::Get ()->Begin ();
178 }
179 
182 {
184  return ChannelListPriv::Get ()->End ();
185 }
186 
189 {
190  NS_LOG_FUNCTION (n);
191  return ChannelListPriv::Get ()->GetChannel (n);
192 }
193 
194 uint32_t
196 {
198  return ChannelListPriv::Get ()->GetNChannels ();
199 }
200 
201 } // namespace ns3