A Discrete-Event Network Simulator
API
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 (EnergySourceContainer::Iterator i = sourceContainer.Begin(); i != sourceContainer.End();
47 ++i)
48 {
49 Ptr<EnergyHarvester> harvester = DoInstall(*i);
50 container.Add(harvester);
51 Ptr<Node> node = (*i)->GetNode();
52 /*
53 * Check if EnergyHarvesterContainer is already aggregated to target node. If
54 * not, create a new EnergyHarvesterContainer and aggregate it to the node.
55 */
56 Ptr<EnergyHarvesterContainer> EnergyHarvesterContainerOnNode =
58 if (!EnergyHarvesterContainerOnNode)
59 {
60 ObjectFactory fac;
61 fac.SetTypeId("ns3::EnergyHarvesterContainer");
62 EnergyHarvesterContainerOnNode = fac.Create<EnergyHarvesterContainer>();
63 EnergyHarvesterContainerOnNode->Add(harvester);
64 node->AggregateObject(EnergyHarvesterContainerOnNode);
65 }
66 else
67 {
68 EnergyHarvesterContainerOnNode->Add(harvester); // append new EnergyHarvester
69 }
70 }
71 return container;
72}
73
75EnergyHarvesterHelper::Install(std::string sourceName) const
76{
77 Ptr<EnergySource> source = Names::Find<EnergySource>(sourceName);
78 return Install(source);
79}
80
81} // namespace ns3
Holds a vector of ns3::EnergyHarvester pointers.
void Add(EnergyHarvesterContainer container)
virtual Ptr< EnergyHarvester > DoInstall(Ptr< EnergySource > source) const =0
EnergyHarvesterContainer Install(std::string sourceName) const
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.
std::vector< Ptr< EnergySource > >::const_iterator Iterator
Const iterator for EnergySource 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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:259
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Every class exported by the ns3 library is enclosed in the ns3 namespace.