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{
28
29NS_LOG_COMPONENT_DEFINE("EnergyHarvesterContainer");
30
31NS_OBJECT_ENSURE_REGISTERED(EnergyHarvesterContainer);
32
33TypeId
35{
36 static TypeId tid = TypeId("ns3::EnergyHarvesterContainer")
38 .SetGroupName("Energy")
39 .AddConstructor<EnergyHarvesterContainer>();
40 return tid;
41}
42
44{
45 NS_LOG_FUNCTION(this);
46}
47
49{
50 NS_LOG_FUNCTION(this);
51}
52
54{
55 NS_LOG_FUNCTION(this << harvester);
56 NS_ASSERT(harvester);
57 m_harvesters.push_back(harvester);
58}
59
61{
62 NS_LOG_FUNCTION(this << harvesterName);
63 Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester>(harvesterName);
64 NS_ASSERT(harvester);
65 m_harvesters.push_back(harvester);
66}
67
70{
71 NS_LOG_FUNCTION(this << &a << &b);
72 *this = a;
73 Add(b);
74}
75
78{
79 NS_LOG_FUNCTION(this);
80 return m_harvesters.begin();
81}
82
85{
86 NS_LOG_FUNCTION(this);
87 return m_harvesters.end();
88}
89
92{
93 NS_LOG_FUNCTION(this);
94 return m_harvesters.size();
95}
96
99{
100 NS_LOG_FUNCTION(this << i);
101 return m_harvesters[i];
102}
103
104void
106{
107 NS_LOG_FUNCTION(this << &container);
108 for (auto i = container.Begin(); i != container.End(); i++)
109 {
110 m_harvesters.push_back(*i);
111 }
112}
113
114void
116{
117 NS_LOG_FUNCTION(this << harvester);
118 NS_ASSERT(harvester);
119 m_harvesters.push_back(harvester);
120}
121
122void
123EnergyHarvesterContainer::Add(std::string harvesterName)
124{
125 NS_LOG_FUNCTION(this << harvesterName);
126 Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester>(harvesterName);
127 NS_ASSERT(harvester);
128 m_harvesters.push_back(harvester);
129}
130
131void
133{
134 NS_LOG_FUNCTION(this);
135 m_harvesters.clear();
136}
137
138/*
139 * Private functions start here.
140 */
141
142void
144{
145 // call Object::Dispose for all EnergyHarvester objects
146 for (auto i = m_harvesters.begin(); i != m_harvesters.end(); i++)
147 {
148 (*i)->Dispose();
149 }
150 m_harvesters.clear();
151}
152
153void
155{
156 // call Object::Initialize for all EnergyHarvester objects
157 for (auto i = m_harvesters.begin(); i != m_harvesters.end(); i++)
158 {
159 (*i)->Initialize();
160 }
161}
162
163} // namespace ns3
Holds a vector of ns3::EnergyHarvester pointers.
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 DoDispose() override
Destructor implementation.
Iterator Begin() const
Get an iterator which refers to the first EnergyHarvester pointer in the 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.
void Add(EnergyHarvesterContainer container)
EnergyHarvesterContainer()
Creates an empty EnergyHarvesterContainer.
uint32_t GetN() const
Get the number of Ptr<EnergyHarvester> stored in this container.
static TypeId GetTypeId()
Get the type ID.
std::vector< Ptr< EnergyHarvester > > m_harvesters
Harvester container.
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
#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.