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-source-container.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008 INRIA
3
* Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
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
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
* Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
20
*/
21
22
#include "
energy-source-container.h
"
23
24
#include "ns3/names.h"
25
26
namespace
ns3
27
{
28
namespace
energy
29
{
30
31
NS_OBJECT_ENSURE_REGISTERED
(
EnergySourceContainer
);
32
33
TypeId
34
EnergySourceContainer::GetTypeId
()
35
{
36
static
TypeId
tid =
TypeId
(
"ns3::EnergySourceContainer"
)
37
.
SetParent
<
Object
>()
38
.SetGroupName(
"Energy"
)
39
.AddConstructor<
EnergySourceContainer
>();
40
return
tid;
41
}
42
43
EnergySourceContainer::EnergySourceContainer
()
44
{
45
}
46
47
EnergySourceContainer::~EnergySourceContainer
()
48
{
49
}
50
51
EnergySourceContainer::EnergySourceContainer
(
Ptr<EnergySource>
source)
52
{
53
NS_ASSERT
(source);
54
m_sources
.push_back(source);
55
}
56
57
EnergySourceContainer::EnergySourceContainer
(std::string sourceName)
58
{
59
Ptr<EnergySource>
source = Names::Find<EnergySource>(sourceName);
60
NS_ASSERT
(source);
61
m_sources
.push_back(source);
62
}
63
64
EnergySourceContainer::EnergySourceContainer
(
const
EnergySourceContainer
& a,
65
const
EnergySourceContainer
& b)
66
{
67
*
this
= a;
68
Add
(b);
69
}
70
71
EnergySourceContainer::Iterator
72
EnergySourceContainer::Begin
()
const
73
{
74
return
m_sources
.begin();
75
}
76
77
EnergySourceContainer::Iterator
78
EnergySourceContainer::End
()
const
79
{
80
return
m_sources
.end();
81
}
82
83
uint32_t
84
EnergySourceContainer::GetN
()
const
85
{
86
return
m_sources
.size();
87
}
88
89
Ptr<EnergySource>
90
EnergySourceContainer::Get
(
uint32_t
i)
const
91
{
92
return
m_sources
[i];
93
}
94
95
void
96
EnergySourceContainer::Add
(
EnergySourceContainer
container)
97
{
98
for
(
auto
i = container.Begin(); i != container.End(); i++)
99
{
100
m_sources
.push_back(*i);
101
}
102
}
103
104
void
105
EnergySourceContainer::Add
(
Ptr<EnergySource>
source)
106
{
107
NS_ASSERT
(source);
108
m_sources
.push_back(source);
109
}
110
111
void
112
EnergySourceContainer::Add
(std::string sourceName)
113
{
114
Ptr<EnergySource>
source = Names::Find<EnergySource>(sourceName);
115
NS_ASSERT
(source);
116
m_sources
.push_back(source);
117
}
118
119
/*
120
* Private functions start here.
121
*/
122
123
void
124
EnergySourceContainer::DoDispose
()
125
{
126
// call Object::Dispose for all EnergySource objects
127
for
(
auto
i =
m_sources
.begin(); i !=
m_sources
.end(); i++)
128
{
129
(*i)->DisposeDeviceModels();
130
(*i)->Dispose();
131
}
132
m_sources
.clear();
133
}
134
135
void
136
EnergySourceContainer::DoInitialize
()
137
{
138
// call Object::Start for all EnergySource objects
139
for
(
auto
i =
m_sources
.begin(); i !=
m_sources
.end(); i++)
140
{
141
(*i)->Initialize();
142
(*i)->InitializeDeviceModels();
143
}
144
}
145
146
}
// namespace energy
147
}
// namespace ns3
EnergySourceContainer
ns3::Object
A base class which provides memory management and object aggregation.
Definition:
object.h:89
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:77
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:932
ns3::energy::EnergySourceContainer
Holds a vector of ns3::EnergySource pointers.
Definition:
energy-source-container.h:48
ns3::energy::EnergySourceContainer::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
energy-source-container.cc:34
ns3::energy::EnergySourceContainer::DoDispose
void DoDispose() override
Destructor implementation.
Definition:
energy-source-container.cc:124
ns3::energy::EnergySourceContainer::EnergySourceContainer
EnergySourceContainer()
Creates an empty EnergySourceContainer.
Definition:
energy-source-container.cc:43
ns3::energy::EnergySourceContainer::Begin
Iterator Begin() const
Get an iterator which refers to the first EnergySource pointer in the container.
Definition:
energy-source-container.cc:72
ns3::energy::EnergySourceContainer::~EnergySourceContainer
~EnergySourceContainer() override
Definition:
energy-source-container.cc:47
ns3::energy::EnergySourceContainer::m_sources
std::vector< Ptr< EnergySource > > m_sources
Energy source container.
Definition:
energy-source-container.h:183
ns3::energy::EnergySourceContainer::GetN
uint32_t GetN() const
Get the number of Ptr<EnergySource> stored in this container.
Definition:
energy-source-container.cc:84
ns3::energy::EnergySourceContainer::Add
void Add(EnergySourceContainer container)
Definition:
energy-source-container.cc:96
ns3::energy::EnergySourceContainer::End
Iterator End() const
Get an iterator which refers to the last EnergySource pointer in the container.
Definition:
energy-source-container.cc:78
ns3::energy::EnergySourceContainer::Get
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr<EnergySource> stored in this container.
Definition:
energy-source-container.cc:90
ns3::energy::EnergySourceContainer::Iterator
std::vector< Ptr< EnergySource > >::const_iterator Iterator
Const iterator for EnergySource container.
Definition:
energy-source-container.h:51
ns3::energy::EnergySourceContainer::DoInitialize
void DoInitialize() override
Calls Object::Start () for all EnergySource objects.
Definition:
energy-source-container.cc:136
uint32_t
energy-source-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:66
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:46
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
energy
helper
energy-source-container.cc
Generated on Tue May 28 2024 23:35:16 for ns-3 by
1.9.6