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 {
76  return *DoGet ();
77 }
78 
81 {
82  static Ptr<ChannelListPriv> ptr = 0;
83  if (ptr == 0)
84  {
85  ptr = CreateObject<ChannelListPriv> ();
88  }
89  return &ptr;
90 }
91 
92 void
94 {
97  (*DoGet ()) = 0;
98 }
99 
101 {
103 }
104 
106 {
107 }
108 void
110 {
112  for (std::vector<Ptr<Channel> >::iterator i = m_channels.begin ();
113  i != m_channels.end (); i++)
114  {
115  Ptr<Channel> channel = *i;
116  channel->Dispose ();
117  *i = 0;
118  }
119  m_channels.erase (m_channels.begin (), m_channels.end ());
121 }
122 
123 uint32_t
125 {
126  uint32_t index = m_channels.size ();
127  m_channels.push_back (channel);
128  return index;
129 
130 }
131 
134 {
135  return m_channels.begin ();
136 }
137 
140 {
141  return m_channels.end ();
142 }
143 
144 uint32_t
146 {
147  return m_channels.size ();
148 }
149 
152 {
153  NS_ASSERT_MSG (n < m_channels.size (), "Channel index " << n <<
154  " is out of range (only have " << m_channels.size () << " channels).");
155  return m_channels[n];
156 }
157 
158 uint32_t
160 {
161  return ChannelListPriv::Get ()->Add (channel);
162 }
163 
166 {
167  return ChannelListPriv::Get ()->Begin ();
168 }
169 
172 {
173  return ChannelListPriv::Get ()->End ();
174 }
175 
178 {
179  return ChannelListPriv::Get ()->GetChannel (n);
180 }
181 
182 uint32_t
184 {
185  return ChannelListPriv::Get ()->GetNChannels ();
186 }
187 
188 } // namespace ns3