A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
energy-harvester-helper.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 * 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 * Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
19 */
20
22
23#include "ns3/config.h"
24#include "ns3/names.h"
25
26namespace ns3
27{
28
29/*
30 * EnergyHarvesterHelper
31 */
33{
34}
35
38{
39 return Install(EnergySourceContainer(source));
40}
41
44{
46 for (auto i = sourceContainer.Begin(); i != sourceContainer.End(); ++i)
47 {
48 Ptr<EnergyHarvester> harvester = DoInstall(*i);
49 container.Add(harvester);
50 Ptr<Node> node = (*i)->GetNode();
51 /*
52 * Check if EnergyHarvesterContainer is already aggregated to target node. If
53 * not, create a new EnergyHarvesterContainer and aggregate it to the node.
54 */
55 Ptr<EnergyHarvesterContainer> EnergyHarvesterContainerOnNode =
56 node->GetObject<EnergyHarvesterContainer>();
57 if (!EnergyHarvesterContainerOnNode)
58 {
59 ObjectFactory fac;
60 fac.SetTypeId("ns3::EnergyHarvesterContainer");
61 EnergyHarvesterContainerOnNode = fac.Create<EnergyHarvesterContainer>();
62 EnergyHarvesterContainerOnNode->Add(harvester);
63 node->AggregateObject(EnergyHarvesterContainerOnNode);
64 }
65 else
66 {
67 EnergyHarvesterContainerOnNode->Add(harvester); // append new EnergyHarvester
68 }
69 }
70 return container;
71}
72
74EnergyHarvesterHelper::Install(std::string sourceName) const
75{
76 Ptr<EnergySource> source = Names::Find<EnergySource>(sourceName);
77 return Install(source);
78}
79
80} // namespace ns3
Holds a vector of ns3::EnergyHarvester pointers.
virtual Ptr< EnergyHarvester > DoInstall(Ptr< EnergySource > source) const =0
EnergyHarvesterContainer Install(Ptr< EnergySource > source) const
Holds a vector of ns3::EnergySource pointers.
Iterator Begin() const
Get an iterator which refers to the first EnergySource pointer in the container.
Iterator End() const
Get an iterator which refers to the last EnergySource pointer in the container.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Every class exported by the ns3 library is enclosed in the ns3 namespace.