A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
10
#include "
energy-harvester-container.h
"
11
12
#include "ns3/log.h"
13
#include "ns3/names.h"
14
15
namespace
ns3
16
{
17
namespace
energy
18
{
19
20
NS_LOG_COMPONENT_DEFINE
(
"EnergyHarvesterContainer"
);
21
NS_OBJECT_ENSURE_REGISTERED
(
EnergyHarvesterContainer
);
22
23
TypeId
24
EnergyHarvesterContainer::GetTypeId
()
25
{
26
static
TypeId
tid =
TypeId
(
"ns3::energy::EnergyHarvesterContainer"
)
27
.
AddDeprecatedName
(
"ns3::EnergyHarvesterContainer"
)
28
.
SetParent
<
Object
>()
29
.SetGroupName(
"Energy"
)
30
.AddConstructor<
EnergyHarvesterContainer
>();
31
return
tid;
32
}
33
34
EnergyHarvesterContainer::EnergyHarvesterContainer
()
35
{
36
NS_LOG_FUNCTION
(
this
);
37
}
38
39
EnergyHarvesterContainer::~EnergyHarvesterContainer
()
40
{
41
NS_LOG_FUNCTION
(
this
);
42
}
43
44
EnergyHarvesterContainer::EnergyHarvesterContainer
(
Ptr<EnergyHarvester>
harvester)
45
{
46
NS_LOG_FUNCTION
(
this
<< harvester);
47
NS_ASSERT
(harvester);
48
m_harvesters
.push_back(harvester);
49
}
50
51
EnergyHarvesterContainer::EnergyHarvesterContainer
(std::string harvesterName)
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
59
EnergyHarvesterContainer::EnergyHarvesterContainer
(
const
EnergyHarvesterContainer
& a,
60
const
EnergyHarvesterContainer
& b)
61
{
62
NS_LOG_FUNCTION
(
this
<< &a << &b);
63
*
this
= a;
64
Add
(b);
65
}
66
67
EnergyHarvesterContainer::Iterator
68
EnergyHarvesterContainer::Begin
()
const
69
{
70
NS_LOG_FUNCTION
(
this
);
71
return
m_harvesters
.begin();
72
}
73
74
EnergyHarvesterContainer::Iterator
75
EnergyHarvesterContainer::End
()
const
76
{
77
NS_LOG_FUNCTION
(
this
);
78
return
m_harvesters
.end();
79
}
80
81
uint32_t
82
EnergyHarvesterContainer::GetN
()
const
83
{
84
NS_LOG_FUNCTION
(
this
);
85
return
m_harvesters
.size();
86
}
87
88
Ptr<EnergyHarvester>
89
EnergyHarvesterContainer::Get
(
uint32_t
i)
const
90
{
91
NS_LOG_FUNCTION
(
this
<< i);
92
return
m_harvesters
[i];
93
}
94
95
void
96
EnergyHarvesterContainer::Add
(
EnergyHarvesterContainer
container)
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
105
void
106
EnergyHarvesterContainer::Add
(
Ptr<EnergyHarvester>
harvester)
107
{
108
NS_LOG_FUNCTION
(
this
<< harvester);
109
NS_ASSERT
(harvester);
110
m_harvesters
.push_back(harvester);
111
}
112
113
void
114
EnergyHarvesterContainer::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
122
void
123
EnergyHarvesterContainer::Clear
()
124
{
125
NS_LOG_FUNCTION
(
this
);
126
m_harvesters
.clear();
127
}
128
129
/*
130
* Private functions start here.
131
*/
132
133
void
134
EnergyHarvesterContainer::DoDispose
()
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
144
void
145
EnergyHarvesterContainer::DoInitialize
()
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
ns3::Names::Find
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
ns3::Object
A base class which provides memory management and object aggregation.
Definition
object.h:78
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::TypeId::AddDeprecatedName
TypeId AddDeprecatedName(const std::string &name)
Add an deprecated name for a TypeId.
Definition
type-id.cc:862
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
ns3::energy::EnergyHarvesterContainer
Holds a vector of ns3::EnergyHarvester pointers.
Definition
energy-harvester-container.h:38
ns3::energy::EnergyHarvesterContainer::~EnergyHarvesterContainer
~EnergyHarvesterContainer() override
Definition
energy-harvester-container.cc:39
ns3::energy::EnergyHarvesterContainer::GetN
uint32_t GetN() const
Get the number of Ptr<EnergyHarvester> stored in this container.
Definition
energy-harvester-container.cc:82
ns3::energy::EnergyHarvesterContainer::DoInitialize
void DoInitialize() override
Calls Object::Initialize () for all EnergySource objects.
Definition
energy-harvester-container.cc:145
ns3::energy::EnergyHarvesterContainer::Get
Ptr< EnergyHarvester > Get(uint32_t i) const
Get the i-th Ptr<EnergyHarvester> stored in this container.
Definition
energy-harvester-container.cc:89
ns3::energy::EnergyHarvesterContainer::EnergyHarvesterContainer
EnergyHarvesterContainer()
Creates an empty EnergyHarvesterContainer.
Definition
energy-harvester-container.cc:34
ns3::energy::EnergyHarvesterContainer::Clear
void Clear()
Removes all elements in the container.
Definition
energy-harvester-container.cc:123
ns3::energy::EnergyHarvesterContainer::Iterator
std::vector< Ptr< EnergyHarvester > >::const_iterator Iterator
Const iterator for EnergyHarvester container.
Definition
energy-harvester-container.h:41
ns3::energy::EnergyHarvesterContainer::End
Iterator End() const
Get an iterator which refers to the last EnergyHarvester pointer in the container.
Definition
energy-harvester-container.cc:75
ns3::energy::EnergyHarvesterContainer::Add
void Add(EnergyHarvesterContainer container)
Definition
energy-harvester-container.cc:96
ns3::energy::EnergyHarvesterContainer::m_harvesters
std::vector< Ptr< EnergyHarvester > > m_harvesters
Harvester container.
Definition
energy-harvester-container.h:179
ns3::energy::EnergyHarvesterContainer::DoDispose
void DoDispose() override
Destructor implementation.
Definition
energy-harvester-container.cc:134
ns3::energy::EnergyHarvesterContainer::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
energy-harvester-container.cc:24
ns3::energy::EnergyHarvesterContainer::Begin
Iterator Begin() const
Get an iterator which refers to the first EnergyHarvester pointer in the container.
Definition
energy-harvester-container.cc:68
uint32_t
energy-harvester-container.h
NS_ASSERT
#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
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
energy
helper
energy-harvester-container.cc
Generated on Fri Nov 8 2024 13:59:00 for ns-3 by
1.11.0