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 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
8 */
9
11
12#include "ns3/log.h"
13#include "ns3/names.h"
14
15namespace ns3
16{
17namespace energy
18{
19
20NS_LOG_COMPONENT_DEFINE("EnergyHarvesterContainer");
22
25{
26 static TypeId tid = TypeId("ns3::energy::EnergyHarvesterContainer")
27 .AddDeprecatedName("ns3::EnergyHarvesterContainer")
29 .SetGroupName("Energy")
30 .AddConstructor<EnergyHarvesterContainer>();
31 return tid;
32}
33
38
43
45{
46 NS_LOG_FUNCTION(this << harvester);
47 NS_ASSERT(harvester);
48 m_harvesters.push_back(harvester);
49}
50
52{
53 NS_LOG_FUNCTION(this << harvesterName);
54 Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester>(harvesterName);
55 NS_ASSERT(harvester);
56 m_harvesters.push_back(harvester);
57}
58
66
69{
70 NS_LOG_FUNCTION(this);
71 return m_harvesters.begin();
72}
73
76{
77 NS_LOG_FUNCTION(this);
78 return m_harvesters.end();
79}
80
83{
84 NS_LOG_FUNCTION(this);
85 return m_harvesters.size();
86}
87
90{
91 NS_LOG_FUNCTION(this << i);
92 return m_harvesters[i];
93}
94
95void
97{
98 NS_LOG_FUNCTION(this << &container);
99 for (auto i = container.Begin(); i != container.End(); i++)
100 {
101 m_harvesters.push_back(*i);
102 }
103}
104
105void
107{
108 NS_LOG_FUNCTION(this << harvester);
109 NS_ASSERT(harvester);
110 m_harvesters.push_back(harvester);
111}
112
113void
114EnergyHarvesterContainer::Add(std::string harvesterName)
115{
116 NS_LOG_FUNCTION(this << harvesterName);
117 Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester>(harvesterName);
118 NS_ASSERT(harvester);
119 m_harvesters.push_back(harvester);
120}
121
122void
128
129/*
130 * Private functions start here.
131 */
132
133void
135{
136 // call Object::Dispose for all EnergyHarvester objects
137 for (auto i = m_harvesters.begin(); i != m_harvesters.end(); i++)
138 {
139 (*i)->Dispose();
140 }
141 m_harvesters.clear();
142}
143
144void
146{
147 // call Object::Initialize for all EnergyHarvester objects
148 for (auto i = m_harvesters.begin(); i != m_harvesters.end(); i++)
149 {
150 (*i)->Initialize();
151 }
152}
153
154} // namespace energy
155} // namespace ns3
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
Definition names.h:443
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId AddDeprecatedName(const std::string &name)
Add an deprecated name for a TypeId.
Definition type-id.cc:862
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.