A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
energy-source-container.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
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 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 * Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
20 */
21
23
24#include "ns3/names.h"
25
26namespace ns3
27{
28namespace energy
29{
30
31NS_OBJECT_ENSURE_REGISTERED(EnergySourceContainer);
32
33TypeId
35{
36 static TypeId tid = TypeId("ns3::EnergySourceContainer")
38 .SetGroupName("Energy")
39 .AddConstructor<EnergySourceContainer>();
40 return tid;
41}
42
44{
45}
46
48{
49}
50
52{
53 NS_ASSERT(source);
54 m_sources.push_back(source);
55}
56
58{
59 Ptr<EnergySource> source = Names::Find<EnergySource>(sourceName);
60 NS_ASSERT(source);
61 m_sources.push_back(source);
62}
63
65 const EnergySourceContainer& b)
66{
67 *this = a;
68 Add(b);
69}
70
73{
74 return m_sources.begin();
75}
76
79{
80 return m_sources.end();
81}
82
85{
86 return m_sources.size();
87}
88
91{
92 return m_sources[i];
93}
94
95void
97{
98 for (auto i = container.Begin(); i != container.End(); i++)
99 {
100 m_sources.push_back(*i);
101 }
102}
103
104void
106{
107 NS_ASSERT(source);
108 m_sources.push_back(source);
109}
110
111void
112EnergySourceContainer::Add(std::string sourceName)
113{
114 Ptr<EnergySource> source = Names::Find<EnergySource>(sourceName);
115 NS_ASSERT(source);
116 m_sources.push_back(source);
117}
118
119/*
120 * Private functions start here.
121 */
122
123void
125{
126 // call Object::Dispose for all EnergySource objects
127 for (auto i = m_sources.begin(); i != m_sources.end(); i++)
128 {
129 (*i)->DisposeDeviceModels();
130 (*i)->Dispose();
131 }
132 m_sources.clear();
133}
134
135void
137{
138 // call Object::Start for all EnergySource objects
139 for (auto i = m_sources.begin(); i != m_sources.end(); i++)
140 {
141 (*i)->Initialize();
142 (*i)->InitializeDeviceModels();
143 }
144}
145
146} // namespace energy
147} // namespace ns3
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Holds a vector of ns3::EnergySource pointers.
static TypeId GetTypeId()
Get the type ID.
void DoDispose() override
Destructor implementation.
EnergySourceContainer()
Creates an empty EnergySourceContainer.
Iterator Begin() const
Get an iterator which refers to the first EnergySource pointer in the container.
std::vector< Ptr< EnergySource > > m_sources
Energy source container.
uint32_t GetN() const
Get the number of Ptr<EnergySource> stored in this container.
void Add(EnergySourceContainer container)
Iterator End() const
Get an iterator which refers to the last EnergySource pointer in the container.
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr<EnergySource> stored in this container.
std::vector< Ptr< EnergySource > >::const_iterator Iterator
Const iterator for EnergySource container.
void DoInitialize() override
Calls Object::Start () for all EnergySource objects.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.