A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
energy-harvester-container.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
4
* University of Rochester, Rochester, NY, USA.
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
20
*/
21
22
#include "
energy-harvester-container.h
"
23
24
#include "ns3/names.h"
25
#include "ns3/log.h"
26
27
namespace
ns3
{
28
29
NS_LOG_COMPONENT_DEFINE
(
"EnergyHarvesterContainer"
);
30
31
NS_OBJECT_ENSURE_REGISTERED
(EnergyHarvesterContainer);
32
33
TypeId
34
EnergyHarvesterContainer::GetTypeId
(
void
)
35
{
36
static
TypeId
tid =
TypeId
(
"ns3::EnergyHarvesterContainer"
)
37
.
SetParent
<
Object
> ()
38
.SetGroupName (
"Energy"
)
39
.AddConstructor<
EnergyHarvesterContainer
> ()
40
;
41
return
tid;
42
}
43
44
EnergyHarvesterContainer::EnergyHarvesterContainer
()
45
{
46
NS_LOG_FUNCTION
(
this
);
47
}
48
49
EnergyHarvesterContainer::~EnergyHarvesterContainer
()
50
{
51
NS_LOG_FUNCTION
(
this
);
52
}
53
54
EnergyHarvesterContainer::EnergyHarvesterContainer
(
Ptr<EnergyHarvester>
harvester)
55
{
56
NS_LOG_FUNCTION
(
this
<< harvester);
57
NS_ASSERT
(harvester != 0);
58
m_harvesters
.push_back (harvester);
59
}
60
61
EnergyHarvesterContainer::EnergyHarvesterContainer
(std::string harvesterName)
62
{
63
NS_LOG_FUNCTION
(
this
<< harvesterName);
64
Ptr<EnergyHarvester>
harvester = Names::Find<EnergyHarvester> (harvesterName);
65
NS_ASSERT
(harvester != 0);
66
m_harvesters
.push_back (harvester);
67
}
68
69
EnergyHarvesterContainer::EnergyHarvesterContainer
(
const
EnergyHarvesterContainer
&a,
70
const
EnergyHarvesterContainer
&b)
71
{
72
NS_LOG_FUNCTION
(
this
<< &a << &b);
73
*
this
= a;
74
Add
(b);
75
}
76
77
EnergyHarvesterContainer::Iterator
78
EnergyHarvesterContainer::Begin
(
void
)
const
79
{
80
NS_LOG_FUNCTION
(
this
);
81
return
m_harvesters
.begin ();
82
}
83
84
EnergyHarvesterContainer::Iterator
85
EnergyHarvesterContainer::End
(
void
)
const
86
{
87
NS_LOG_FUNCTION
(
this
);
88
return
m_harvesters
.end ();
89
}
90
91
uint32_t
92
EnergyHarvesterContainer::GetN
(
void
)
const
93
{
94
NS_LOG_FUNCTION
(
this
);
95
return
m_harvesters
.size ();
96
}
97
98
Ptr<EnergyHarvester>
99
EnergyHarvesterContainer::Get
(uint32_t i)
const
100
{
101
NS_LOG_FUNCTION
(
this
<< i);
102
return
m_harvesters
[i];
103
}
104
105
void
106
EnergyHarvesterContainer::Add
(
EnergyHarvesterContainer
container)
107
{
108
NS_LOG_FUNCTION
(
this
<< &container);
109
for
(
Iterator
i = container.
Begin
(); i != container.
End
(); i++)
110
{
111
m_harvesters
.push_back (*i);
112
}
113
}
114
115
void
116
EnergyHarvesterContainer::Add
(
Ptr<EnergyHarvester>
harvester)
117
{
118
NS_LOG_FUNCTION
(
this
<< harvester);
119
NS_ASSERT
(harvester != 0);
120
m_harvesters
.push_back (harvester);
121
}
122
123
void
124
EnergyHarvesterContainer::Add
(std::string harvesterName)
125
{
126
NS_LOG_FUNCTION
(
this
<< harvesterName);
127
Ptr<EnergyHarvester>
harvester = Names::Find<EnergyHarvester> (harvesterName);
128
NS_ASSERT
(harvester != 0);
129
m_harvesters
.push_back (harvester);
130
}
131
132
void
133
EnergyHarvesterContainer::Clear
(
void
)
134
{
135
NS_LOG_FUNCTION
(
this
);
136
m_harvesters
.clear ();
137
}
138
139
140
/*
141
* Private functions start here.
142
*/
143
144
void
145
EnergyHarvesterContainer::DoDispose
(
void
)
146
{
147
// call Object::Dispose for all EnergyHarvester objects
148
for
(std::vector<
Ptr<EnergyHarvester>
>::iterator i =
m_harvesters
.begin ();
149
i !=
m_harvesters
.end (); i++)
150
{
151
(*i)->Dispose ();
152
}
153
m_harvesters
.clear ();
154
}
155
156
void
157
EnergyHarvesterContainer::DoInitialize
(
void
)
158
{
159
// call Object::Initialize for all EnergyHarvester objects
160
for
(std::vector<
Ptr<EnergyHarvester>
>::iterator i =
m_harvesters
.begin ();
161
i !=
m_harvesters
.end (); i++)
162
{
163
(*i)->Initialize ();
164
}
165
}
166
167
}
// namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
ns3::EnergyHarvesterContainer::GetTypeId
static TypeId GetTypeId(void)
Definition:
energy-harvester-container.cc:34
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:45
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:67
ns3::EnergyHarvesterContainer::Clear
void Clear(void)
Removes all elements in the container.
Definition:
energy-harvester-container.cc:133
ns3::EnergyHarvesterContainer::Get
Ptr< EnergyHarvester > Get(uint32_t i) const
Get the i-th Ptr<EnergyHarvester> stored in this container.
Definition:
energy-harvester-container.cc:99
ns3::EnergyHarvesterContainer::Iterator
std::vector< Ptr< EnergyHarvester > >::const_iterator Iterator
Definition:
energy-harvester-container.h:48
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::EnergyHarvesterContainer::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition:
energy-harvester-container.cc:145
ns3::EnergyHarvesterContainer::m_harvesters
std::vector< Ptr< EnergyHarvester > > m_harvesters
Definition:
energy-harvester-container.h:183
ns3::EnergyHarvesterContainer::~EnergyHarvesterContainer
~EnergyHarvesterContainer()
Definition:
energy-harvester-container.cc:49
ns3::EnergyHarvesterContainer::GetN
uint32_t GetN(void) const
Get the number of Ptr<EnergyHarvester> stored in this container.
Definition:
energy-harvester-container.cc:92
ns3::EnergyHarvesterContainer::End
Iterator End(void) const
Get an iterator which refers to the last EnergyHarvester pointer in the container.
Definition:
energy-harvester-container.cc:85
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:923
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:74
ns3::Object
A base class which provides memory management and object aggregation.
Definition:
object.h:88
ns3::EnergyHarvesterContainer
Holds a vector of ns3::EnergyHarvester pointers.
Definition:
energy-harvester-container.h:46
energy-harvester-container.h
ns3::EnergyHarvesterContainer::DoInitialize
virtual void DoInitialize(void)
Calls Object::Initialize () for all EnergySource objects.
Definition:
energy-harvester-container.cc:157
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:244
ns3::EnergyHarvesterContainer::EnergyHarvesterContainer
EnergyHarvesterContainer()
Creates an empty EnergyHarvesterContainer.
Definition:
energy-harvester-container.cc:44
ns3::EnergyHarvesterContainer::Add
void Add(EnergyHarvesterContainer container)
Definition:
energy-harvester-container.cc:106
ns3::EnergyHarvesterContainer::Begin
Iterator Begin(void) const
Get an iterator which refers to the first EnergyHarvester pointer in the container.
Definition:
energy-harvester-container.cc:78
src
energy
helper
energy-harvester-container.cc
Generated on Fri Oct 1 2021 17:03:03 for ns-3 by
1.8.20