A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
energy-harvester-container.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
3 * University of Rochester, Rochester, NY, USA.
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 * Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
19 */
20
22
23#include "ns3/log.h"
24#include "ns3/names.h"
25
26namespace ns3
27{
28namespace energy
29{
30
31NS_LOG_COMPONENT_DEFINE("EnergyHarvesterContainer");
33
36{
37 static TypeId tid = TypeId("ns3::EnergyHarvesterContainer")
39 .SetGroupName("Energy")
40 .AddConstructor<EnergyHarvesterContainer>();
41 return tid;
42}
43
45{
46 NS_LOG_FUNCTION(this);
47}
48
50{
51 NS_LOG_FUNCTION(this);
52}
53
55{
56 NS_LOG_FUNCTION(this << harvester);
57 NS_ASSERT(harvester);
58 m_harvesters.push_back(harvester);
59}
60
62{
63 NS_LOG_FUNCTION(this << harvesterName);
64 Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester>(harvesterName);
65 NS_ASSERT(harvester);
66 m_harvesters.push_back(harvester);
67}
68
71{
72 NS_LOG_FUNCTION(this << &a << &b);
73 *this = a;
74 Add(b);
75}
76
79{
80 NS_LOG_FUNCTION(this);
81 return m_harvesters.begin();
82}
83
86{
87 NS_LOG_FUNCTION(this);
88 return m_harvesters.end();
89}
90
93{
94 NS_LOG_FUNCTION(this);
95 return m_harvesters.size();
96}
97
100{
101 NS_LOG_FUNCTION(this << i);
102 return m_harvesters[i];
103}
104
105void
107{
108 NS_LOG_FUNCTION(this << &container);
109 for (auto i = container.Begin(); i != container.End(); i++)
110 {
111 m_harvesters.push_back(*i);
112 }
113}
114
115void
117{
118 NS_LOG_FUNCTION(this << harvester);
119 NS_ASSERT(harvester);
120 m_harvesters.push_back(harvester);
121}
122
123void
124EnergyHarvesterContainer::Add(std::string harvesterName)
125{
126 NS_LOG_FUNCTION(this << harvesterName);
127 Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester>(harvesterName);
128 NS_ASSERT(harvester);
129 m_harvesters.push_back(harvester);
130}
131
132void
134{
135 NS_LOG_FUNCTION(this);
136 m_harvesters.clear();
137}
138
139/*
140 * Private functions start here.
141 */
142
143void
145{
146 // call Object::Dispose for all EnergyHarvester objects
147 for (auto i = m_harvesters.begin(); i != m_harvesters.end(); i++)
148 {
149 (*i)->Dispose();
150 }
151 m_harvesters.clear();
152}
153
154void
156{
157 // call Object::Initialize for all EnergyHarvester objects
158 for (auto i = m_harvesters.begin(); i != m_harvesters.end(); i++)
159 {
160 (*i)->Initialize();
161 }
162}
163
164} // namespace energy
165} // 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::EnergyHarvester pointers.
uint32_t GetN() const
Get the number of Ptr<EnergyHarvester> stored in this container.
void DoInitialize() override
Calls Object::Initialize () for all EnergySource objects.
Ptr< EnergyHarvester > Get(uint32_t i) const
Get the i-th Ptr<EnergyHarvester> stored in this container.
EnergyHarvesterContainer()
Creates an empty EnergyHarvesterContainer.
void Clear()
Removes all elements in the container.
std::vector< Ptr< EnergyHarvester > >::const_iterator Iterator
Const iterator for EnergyHarvester container.
Iterator End() const
Get an iterator which refers to the last EnergyHarvester pointer in the container.
void Add(EnergyHarvesterContainer container)
std::vector< Ptr< EnergyHarvester > > m_harvesters
Harvester container.
void DoDispose() override
Destructor implementation.
Iterator Begin() const
Get an iterator which refers to the first EnergyHarvester pointer in the container.
#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_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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.