A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("EnergyHarvesterContainer");
28 
29 namespace ns3 {
30 
31 TypeId
33 {
34  static TypeId tid = TypeId ("ns3::EnergyHarvesterContainer")
35  .SetParent<Object> ()
36  .AddConstructor<EnergyHarvesterContainer> ()
37  ;
38  return tid;
39 }
40 
42 {
43  NS_LOG_FUNCTION (this);
44 }
45 
47 {
48  NS_LOG_FUNCTION (this);
49 }
50 
52 {
53  NS_LOG_FUNCTION (this << harvester);
54  NS_ASSERT (harvester != 0);
55  m_harvesters.push_back (harvester);
56 }
57 
59 {
60  NS_LOG_FUNCTION (this << harvesterName);
61  Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester> (harvesterName);
62  NS_ASSERT (harvester != 0);
63  m_harvesters.push_back (harvester);
64 }
65 
67  const EnergyHarvesterContainer &b)
68 {
69  NS_LOG_FUNCTION (this << &a << &b);
70  *this = a;
71  Add (b);
72 }
73 
76 {
77  NS_LOG_FUNCTION (this);
78  return m_harvesters.begin ();
79 }
80 
83 {
84  NS_LOG_FUNCTION (this);
85  return m_harvesters.end ();
86 }
87 
88 uint32_t
90 {
91  NS_LOG_FUNCTION (this);
92  return m_harvesters.size ();
93 }
94 
97 {
98  NS_LOG_FUNCTION (this << i);
99  return m_harvesters[i];
100 }
101 
102 void
104 {
105  NS_LOG_FUNCTION (this << &container);
106  for (Iterator i = container.Begin (); i != container.End (); i++)
107  {
108  m_harvesters.push_back (*i);
109  }
110 }
111 
112 void
114 {
115  NS_LOG_FUNCTION (this << harvester);
116  NS_ASSERT (harvester != 0);
117  m_harvesters.push_back (harvester);
118 }
119 
120 void
121 EnergyHarvesterContainer::Add (std::string harvesterName)
122 {
123  NS_LOG_FUNCTION (this << harvesterName);
124  Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester> (harvesterName);
125  NS_ASSERT (harvester != 0);
126  m_harvesters.push_back (harvester);
127 }
128 
129 void
131 {
132  NS_LOG_FUNCTION (this);
133  m_harvesters.clear ();
134 }
135 
136 
137 /*
138  * Private functions start here.
139  */
140 
141 void
143 {
144  // call Object::Dispose for all EnergyHarvester objects
145  for (std::vector< Ptr<EnergyHarvester> >::iterator i = m_harvesters.begin ();
146  i != m_harvesters.end (); i++)
147  {
148  (*i)->Dispose ();
149  }
150  m_harvesters.clear ();
151 }
152 
153 void
155 {
156  // call Object::Initialize for all EnergyHarvester objects
157  for (std::vector< Ptr<EnergyHarvester> >::iterator i = m_harvesters.begin ();
158  i != m_harvesters.end (); i++)
159  {
160  (*i)->Initialize ();
161  }
162 }
163 
164 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#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_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:170
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
Holds a vector of ns3::EnergyHarvester pointers.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
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:64
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610