A Discrete-Event Network Simulator
API
energy-harvester-container.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 
24 #include "ns3/names.h"
25 #include "ns3/log.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("EnergyHarvesterContainer");
30 
31 NS_OBJECT_ENSURE_REGISTERED (EnergyHarvesterContainer);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::EnergyHarvesterContainer")
37  .SetParent<Object> ()
38  .SetGroupName ("Energy")
39  .AddConstructor<EnergyHarvesterContainer> ()
40  ;
41  return tid;
42 }
43 
45 {
46  NS_LOG_FUNCTION (this);
47 }
48 
50 {
51  NS_LOG_FUNCTION (this);
52 }
53 
55 {
56  NS_LOG_FUNCTION (this << harvester);
57  NS_ASSERT (harvester != 0);
58  m_harvesters.push_back (harvester);
59 }
60 
62 {
63  NS_LOG_FUNCTION (this << harvesterName);
64  Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester> (harvesterName);
65  NS_ASSERT (harvester != 0);
66  m_harvesters.push_back (harvester);
67 }
68 
70  const EnergyHarvesterContainer &b)
71 {
72  NS_LOG_FUNCTION (this << &a << &b);
73  *this = a;
74  Add (b);
75 }
76 
79 {
80  NS_LOG_FUNCTION (this);
81  return m_harvesters.begin ();
82 }
83 
86 {
87  NS_LOG_FUNCTION (this);
88  return m_harvesters.end ();
89 }
90 
91 uint32_t
93 {
94  NS_LOG_FUNCTION (this);
95  return m_harvesters.size ();
96 }
97 
100 {
101  NS_LOG_FUNCTION (this << i);
102  return m_harvesters[i];
103 }
104 
105 void
107 {
108  NS_LOG_FUNCTION (this << &container);
109  for (Iterator i = container.Begin (); i != container.End (); i++)
110  {
111  m_harvesters.push_back (*i);
112  }
113 }
114 
115 void
117 {
118  NS_LOG_FUNCTION (this << harvester);
119  NS_ASSERT (harvester != 0);
120  m_harvesters.push_back (harvester);
121 }
122 
123 void
124 EnergyHarvesterContainer::Add (std::string harvesterName)
125 {
126  NS_LOG_FUNCTION (this << harvesterName);
127  Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester> (harvesterName);
128  NS_ASSERT (harvester != 0);
129  m_harvesters.push_back (harvester);
130 }
131 
132 void
134 {
135  NS_LOG_FUNCTION (this);
136  m_harvesters.clear ();
137 }
138 
139 
140 /*
141  * Private functions start here.
142  */
143 
144 void
146 {
147  // call Object::Dispose for all EnergyHarvester objects
148  for (std::vector< Ptr<EnergyHarvester> >::iterator i = m_harvesters.begin ();
149  i != m_harvesters.end (); i++)
150  {
151  (*i)->Dispose ();
152  }
153  m_harvesters.clear ();
154 }
155 
156 void
158 {
159  // call Object::Initialize for all EnergyHarvester objects
160  for (std::vector< Ptr<EnergyHarvester> >::iterator i = m_harvesters.begin ();
161  i != m_harvesters.end (); i++)
162  {
163  (*i)->Initialize ();
164  }
165 }
166 
167 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
virtual void DoInitialize(void)
Calls Object::Initialize () for all EnergySource objects.
void Add(EnergyHarvesterContainer container)
EnergyHarvesterContainer()
Creates an empty EnergyHarvesterContainer.
std::vector< Ptr< EnergyHarvester > >::const_iterator Iterator
Iterator End(void) const
Get an iterator which refers to the last EnergyHarvester pointer in the container.
Iterator Begin(void) const
Get an iterator which refers to the first EnergyHarvester pointer in the container.
uint32_t GetN(void) const
Get the number of Ptr<EnergyHarvester> stored in this container.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Holds a vector of ns3::EnergyHarvester pointers.
virtual void DoDispose(void)
Destructor implementation.
void Clear(void)
Removes all elements in the container.
std::vector< Ptr< EnergyHarvester > > m_harvesters
Ptr< EnergyHarvester > Get(uint32_t i) const
Get the i-th Ptr<EnergyHarvester> stored in this container.
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915