A Discrete-Event Network Simulator
API
energy-source-container.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2008 INRIA
4 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20 * Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
21 */
22
24#include "ns3/names.h"
25
26namespace ns3 {
27
28NS_OBJECT_ENSURE_REGISTERED (EnergySourceContainer);
29
30TypeId
32{
33 static TypeId tid = TypeId ("ns3::EnergySourceContainer")
34 .SetParent<Object> ()
35 .SetGroupName ("Energy")
36 .AddConstructor<EnergySourceContainer> ()
37 ;
38 return tid;
39}
40
42{
43}
44
46{
47}
48
50{
51 NS_ASSERT (source != NULL);
52 m_sources.push_back (source);
53}
54
56{
57 Ptr<EnergySource> source = Names::Find<EnergySource> (sourceName);
58 NS_ASSERT (source != NULL);
59 m_sources.push_back (source);
60}
61
63 const EnergySourceContainer &b)
64{
65 *this = a;
66 Add (b);
67}
68
71{
72 return m_sources.begin ();
73}
74
77{
78 return m_sources.end ();
79}
80
83{
84 return m_sources.size ();
85}
86
89{
90 return m_sources[i];
91}
92
93void
95{
96 for (Iterator i = container.Begin (); i != container.End (); i++)
97 {
98 m_sources.push_back (*i);
99 }
100}
101
102void
104{
105 NS_ASSERT (source != NULL);
106 m_sources.push_back (source);
107}
108
109void
110EnergySourceContainer::Add (std::string sourceName)
111{
112 Ptr<EnergySource> source = Names::Find<EnergySource> (sourceName);
113 NS_ASSERT (source != NULL);
114 m_sources.push_back (source);
115}
116
117/*
118 * Private functions start here.
119 */
120
121void
123{
124 // call Object::Dispose for all EnergySource objects
125 for (std::vector< Ptr<EnergySource> >::iterator i = m_sources.begin ();
126 i != m_sources.end (); i++)
127 {
128 (*i)->DisposeDeviceModels ();
129 (*i)->Dispose ();
130 }
131 m_sources.clear ();
132}
133
134void
136{
137 // call Object::Start for all EnergySource objects
138 for (std::vector< Ptr<EnergySource> >::iterator i = m_sources.begin ();
139 i != m_sources.end (); i++)
140 {
141 (*i)->Initialize ();
142 (*i)->InitializeDeviceModels ();
143 }
144}
145
146} // namespace ns3
Holds a vector of ns3::EnergySource pointers.
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr<EnergySource> stored in this container.
EnergySourceContainer()
Creates an empty EnergySourceContainer.
static TypeId GetTypeId(void)
Get the type ID.
std::vector< Ptr< EnergySource > >::const_iterator Iterator
Const iterator for EnergySource container.
Iterator Begin(void) const
Get an iterator which refers to the first EnergySource pointer in the container.
std::vector< Ptr< EnergySource > > m_sources
Energy source container.
virtual void DoInitialize(void)
Calls Object::Start () for all EnergySource objects.
void Add(EnergySourceContainer container)
uint32_t GetN(void) const
Get the number of Ptr<EnergySource> stored in this container.
Iterator End(void) const
Get an iterator which refers to the last EnergySource pointer in the container.
virtual void DoDispose(void)
Destructor implementation.
A base class which provides memory management and object aggregation.
Definition: object.h:88
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.