A Discrete-Event Network Simulator
API
energy-harvester-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
4  * University of Rochester, Rochester, NY, USA.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
20  */
21 
23 #include "ns3/config.h"
24 #include "ns3/names.h"
25 
26 namespace ns3 {
27 
28 /*
29  * EnergyHarvesterHelper
30  */
32 {
33 }
34 
37 {
38  return Install (EnergySourceContainer (source));
39 }
40 
43 {
44  EnergyHarvesterContainer container;
45  for (EnergySourceContainer::Iterator i = sourceContainer.Begin (); i != sourceContainer.End (); ++i)
46  {
47  Ptr<EnergyHarvester> harvester = DoInstall (*i);
48  container.Add (harvester);
49  Ptr<Node> node = (*i)->GetNode ();
50  /*
51  * Check if EnergyHarvesterContainer is already aggregated to target node. If
52  * not, create a new EnergyHarvesterContainer and aggregate it to the node.
53  */
54  Ptr<EnergyHarvesterContainer> EnergyHarvesterContainerOnNode =
56  if (EnergyHarvesterContainerOnNode == 0)
57  {
58  ObjectFactory fac;
59  fac.SetTypeId ("ns3::EnergyHarvesterContainer");
60  EnergyHarvesterContainerOnNode = fac.Create<EnergyHarvesterContainer> ();
61  EnergyHarvesterContainerOnNode->Add (harvester);
62  node->AggregateObject (EnergyHarvesterContainerOnNode);
63  }
64  else
65  {
66  EnergyHarvesterContainerOnNode->Add (harvester); // append new EnergyHarvester
67  }
68  }
69  return container;
70 }
71 
73 EnergyHarvesterHelper::Install (std::string sourceName) const
74 {
75  Ptr<EnergySource> source = Names::Find<EnergySource> (sourceName);
76  return Install (source);
77 }
78 
79 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Holds a vector of ns3::EnergySource pointers.
Iterator End(void) const
Get an iterator which refers to the last EnergySource pointer in the container.
virtual Ptr< EnergyHarvester > DoInstall(Ptr< EnergySource > source) const =0
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
std::vector< Ptr< EnergySource > >::const_iterator Iterator
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
void Add(EnergyHarvesterContainer container)
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
EnergyHarvesterContainer Install(Ptr< EnergySource > source) const
Iterator Begin(void) const
Get an iterator which refers to the first EnergySource pointer in the container.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:464
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Holds a vector of ns3::EnergyHarvester pointers.
Instantiate subclasses of ns3::Object.