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  .AddConstructor<EnergyHarvesterContainer> ()
39  ;
40  return tid;
41 }
42 
44 {
45  NS_LOG_FUNCTION (this);
46 }
47 
49 {
50  NS_LOG_FUNCTION (this);
51 }
52 
54 {
55  NS_LOG_FUNCTION (this << harvester);
56  NS_ASSERT (harvester != 0);
57  m_harvesters.push_back (harvester);
58 }
59 
61 {
62  NS_LOG_FUNCTION (this << harvesterName);
63  Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester> (harvesterName);
64  NS_ASSERT (harvester != 0);
65  m_harvesters.push_back (harvester);
66 }
67 
69  const EnergyHarvesterContainer &b)
70 {
71  NS_LOG_FUNCTION (this << &a << &b);
72  *this = a;
73  Add (b);
74 }
75 
78 {
79  NS_LOG_FUNCTION (this);
80  return m_harvesters.begin ();
81 }
82 
85 {
86  NS_LOG_FUNCTION (this);
87  return m_harvesters.end ();
88 }
89 
90 uint32_t
92 {
93  NS_LOG_FUNCTION (this);
94  return m_harvesters.size ();
95 }
96 
99 {
100  NS_LOG_FUNCTION (this << i);
101  return m_harvesters[i];
102 }
103 
104 void
106 {
107  NS_LOG_FUNCTION (this << &container);
108  for (Iterator i = container.Begin (); i != container.End (); i++)
109  {
110  m_harvesters.push_back (*i);
111  }
112 }
113 
114 void
116 {
117  NS_LOG_FUNCTION (this << harvester);
118  NS_ASSERT (harvester != 0);
119  m_harvesters.push_back (harvester);
120 }
121 
122 void
123 EnergyHarvesterContainer::Add (std::string harvesterName)
124 {
125  NS_LOG_FUNCTION (this << harvesterName);
126  Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester> (harvesterName);
127  NS_ASSERT (harvester != 0);
128  m_harvesters.push_back (harvester);
129 }
130 
131 void
133 {
134  NS_LOG_FUNCTION (this);
135  m_harvesters.clear ();
136 }
137 
138 
139 /*
140  * Private functions start here.
141  */
142 
143 void
145 {
146  // call Object::Dispose for all EnergyHarvester objects
147  for (std::vector< Ptr<EnergyHarvester> >::iterator i = m_harvesters.begin ();
148  i != m_harvesters.end (); i++)
149  {
150  (*i)->Dispose ();
151  }
152  m_harvesters.clear ();
153 }
154 
155 void
157 {
158  // call Object::Initialize for all EnergyHarvester objects
159  for (std::vector< Ptr<EnergyHarvester> >::iterator i = m_harvesters.begin ();
160  i != m_harvesters.end (); i++)
161  {
162  (*i)->Initialize ();
163  }
164 }
165 
166 } // 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 "...
Iterator Begin(void) const
Get an iterator which refers to the first EnergyHarvester pointer in the container.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
virtual void DoInitialize(void)
Calls Object::Initialize () for all EnergySource objects.
void Add(EnergyHarvesterContainer container)
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
Ptr< EnergyHarvester > Get(uint32_t i) const
Get the i-th Ptr stored in this container.
EnergyHarvesterContainer()
Creates an empty EnergyHarvesterContainer.
std::vector< Ptr< EnergyHarvester > >::const_iterator Iterator
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
Iterator End(void) const
Get an iterator which refers to the last EnergyHarvester pointer in the 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:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631