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
* SPDX-License-Identifier: GPL-2.0-only
6
*
7
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8
* Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
9
*/
10
11
#include "
energy-source-container.h
"
12
13
#include "ns3/names.h"
14
15
namespace
ns3
16
{
17
namespace
energy
18
{
19
20
NS_OBJECT_ENSURE_REGISTERED
(EnergySourceContainer);
21
22
TypeId
23
EnergySourceContainer::GetTypeId
()
24
{
25
static
TypeId
tid =
TypeId
(
"ns3::energy::EnergySourceContainer"
)
26
.
AddDeprecatedName
(
"ns3::EnergySourceContainer"
)
27
.
SetParent
<
Object
>()
28
.SetGroupName(
"Energy"
)
29
.AddConstructor<
EnergySourceContainer
>();
30
return
tid;
31
}
32
33
EnergySourceContainer::EnergySourceContainer
()
34
{
35
}
36
37
EnergySourceContainer::~EnergySourceContainer
()
38
{
39
}
40
41
EnergySourceContainer::EnergySourceContainer
(
Ptr<EnergySource>
source)
42
{
43
NS_ASSERT
(source);
44
m_sources
.push_back(source);
45
}
46
47
EnergySourceContainer::EnergySourceContainer
(std::string sourceName)
48
{
49
Ptr<EnergySource>
source =
Names::Find<EnergySource>
(sourceName);
50
NS_ASSERT
(source);
51
m_sources
.push_back(source);
52
}
53
54
EnergySourceContainer::EnergySourceContainer
(
const
EnergySourceContainer
& a,
55
const
EnergySourceContainer
& b)
56
{
57
*
this
= a;
58
Add
(b);
59
}
60
61
EnergySourceContainer::Iterator
62
EnergySourceContainer::Begin
()
const
63
{
64
return
m_sources
.begin();
65
}
66
67
EnergySourceContainer::Iterator
68
EnergySourceContainer::End
()
const
69
{
70
return
m_sources
.end();
71
}
72
73
uint32_t
74
EnergySourceContainer::GetN
()
const
75
{
76
return
m_sources
.size();
77
}
78
79
Ptr<EnergySource>
80
EnergySourceContainer::Get
(
uint32_t
i)
const
81
{
82
return
m_sources
[i];
83
}
84
85
void
86
EnergySourceContainer::Add
(
EnergySourceContainer
container)
87
{
88
for
(
auto
i = container.Begin(); i != container.End(); i++)
89
{
90
m_sources
.push_back(*i);
91
}
92
}
93
94
void
95
EnergySourceContainer::Add
(
Ptr<EnergySource>
source)
96
{
97
NS_ASSERT
(source);
98
m_sources
.push_back(source);
99
}
100
101
void
102
EnergySourceContainer::Add
(std::string sourceName)
103
{
104
Ptr<EnergySource>
source =
Names::Find<EnergySource>
(sourceName);
105
NS_ASSERT
(source);
106
m_sources
.push_back(source);
107
}
108
109
/*
110
* Private functions start here.
111
*/
112
113
void
114
EnergySourceContainer::DoDispose
()
115
{
116
// call Object::Dispose for all EnergySource objects
117
for
(
auto
i =
m_sources
.begin(); i !=
m_sources
.end(); i++)
118
{
119
(*i)->DisposeDeviceModels();
120
(*i)->Dispose();
121
}
122
m_sources
.clear();
123
}
124
125
void
126
EnergySourceContainer::DoInitialize
()
127
{
128
// call Object::Start for all EnergySource objects
129
for
(
auto
i =
m_sources
.begin(); i !=
m_sources
.end(); i++)
130
{
131
(*i)->Initialize();
132
(*i)->InitializeDeviceModels();
133
}
134
}
135
136
}
// namespace energy
137
}
// 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::EnergySourceContainer
Holds a vector of ns3::EnergySource pointers.
Definition
energy-source-container.h:37
ns3::energy::EnergySourceContainer::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
energy-source-container.cc:23
ns3::energy::EnergySourceContainer::DoDispose
void DoDispose() override
Destructor implementation.
Definition
energy-source-container.cc:114
ns3::energy::EnergySourceContainer::EnergySourceContainer
EnergySourceContainer()
Creates an empty EnergySourceContainer.
Definition
energy-source-container.cc:33
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:62
ns3::energy::EnergySourceContainer::~EnergySourceContainer
~EnergySourceContainer() override
Definition
energy-source-container.cc:37
ns3::energy::EnergySourceContainer::m_sources
std::vector< Ptr< EnergySource > > m_sources
Energy source container.
Definition
energy-source-container.h:172
ns3::energy::EnergySourceContainer::GetN
uint32_t GetN() const
Get the number of Ptr<EnergySource> stored in this container.
Definition
energy-source-container.cc:74
ns3::energy::EnergySourceContainer::Add
void Add(EnergySourceContainer container)
Definition
energy-source-container.cc:86
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:68
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:80
ns3::energy::EnergySourceContainer::Iterator
std::vector< Ptr< EnergySource > >::const_iterator Iterator
Const iterator for EnergySource container.
Definition
energy-source-container.h:40
ns3::energy::EnergySourceContainer::DoInitialize
void DoInitialize() override
Calls Object::Start () for all EnergySource objects.
Definition
energy-source-container.cc:126
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:55
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-source-container.cc
Generated on Fri Nov 8 2024 13:59:00 for ns-3 by
1.11.0