A Discrete-Event Network Simulator
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
12
13#include "ns3/names.h"
14
15namespace ns3
16{
17namespace energy
18{
19
20NS_OBJECT_ENSURE_REGISTERED(EnergySourceContainer);
21
22TypeId
24{
25 static TypeId tid = TypeId("ns3::energy::EnergySourceContainer")
26 .AddDeprecatedName("ns3::EnergySourceContainer")
28 .SetGroupName("Energy")
29 .AddConstructor<EnergySourceContainer>();
30 return tid;
31}
32
36
40
46
48{
50 NS_ASSERT(source);
51 m_sources.push_back(source);
52}
53
60
63{
64 return m_sources.begin();
65}
66
69{
70 return m_sources.end();
71}
72
75{
76 return m_sources.size();
77}
78
81{
82 return m_sources[i];
83}
84
85void
87{
88 for (auto i = container.Begin(); i != container.End(); i++)
89 {
90 m_sources.push_back(*i);
91 }
92}
93
94void
96{
97 NS_ASSERT(source);
98 m_sources.push_back(source);
99}
100
101void
102EnergySourceContainer::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
113void
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
125void
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
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::EnergySource pointers.
static TypeId GetTypeId()
Get the type ID.
void DoDispose() override
Destructor implementation.
EnergySourceContainer()
Creates an empty EnergySourceContainer.
Iterator Begin() const
Get an iterator which refers to the first EnergySource pointer in the container.
std::vector< Ptr< EnergySource > > m_sources
Energy source container.
uint32_t GetN() const
Get the number of Ptr<EnergySource> stored in this container.
void Add(EnergySourceContainer container)
Iterator End() const
Get an iterator which refers to the last EnergySource pointer in the container.
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr<EnergySource> stored in this container.
std::vector< Ptr< EnergySource > >::const_iterator Iterator
Const iterator for EnergySource container.
void DoInitialize() override
Calls Object::Start () for all EnergySource objects.
#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_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.