A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
energy-harvester-container.h
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 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
8 */
9
10#ifndef ENERGY_HARVESTER_CONTAINER_H
11#define ENERGY_HARVESTER_CONTAINER_H
12
13#include "ns3/energy-harvester.h"
14#include "ns3/object.h"
15
16#include <stdint.h>
17#include <vector>
18
19namespace ns3
20{
21namespace energy
22{
23
24class EnergyHarvester;
25
26/**
27 * @ingroup energy
28 * @brief Holds a vector of ns3::EnergyHarvester pointers.
29 *
30 * EnergyHarvesterContainer returns a list of EnergyHarvester pointers
31 * installed on a node. Users can use this list to access EnergyHarvester
32 * objects to obtain the total energy harvested on a node easily.
33 *
34 * @see NetDeviceContainer
35 *
36 */
38{
39 public:
40 /// Const iterator for EnergyHarvester container
41 typedef std::vector<Ptr<EnergyHarvester>>::const_iterator Iterator;
42
43 public:
44 /**
45 * @brief Get the type ID.
46 * @return The object TypeId.
47 */
48 static TypeId GetTypeId();
49 /**
50 * Creates an empty EnergyHarvesterContainer.
51 */
54
55 /**
56 * @param harvester Pointer to an EnergyHarvester.
57 *
58 * Creates a EnergyHarvesterContainer with exactly one EnergyHarvester
59 * previously instantiated.
60 */
62
63 /**
64 * @param harvesterName Name of EnergyHarvester.
65 *
66 * Creates an EnergyHarvesterContainer with exactly one EnergyHarvester
67 * previously instantiated and assigned a name using the Object name service.
68 * This EnergyHarvester is specified by its assigned name.
69 */
71
72 /**
73 * @param a A EnergyHarvesterContainer.
74 * @param b Another EnergyHarvesterContainer.
75 *
76 * Creates a EnergyHarvesterContainer by concatenating EnergyHarvesterContainer b
77 * to EnergyHarvesterContainer a.
78 *
79 * @note Can be used to concatenate 2 Ptr<EnergyHarvester> directly. C++
80 * will be calling EnergyHarvesterContainer constructor with Ptr<EnergyHarvester>
81 * first.
82 */
84
85 /**
86 * @brief Get an iterator which refers to the first EnergyHarvester pointer
87 * in the container.
88 *
89 * @returns An iterator which refers to the first EnergyHarvester in container.
90 *
91 * EnergyHarvesters can be retrieved from the container in two ways. First,
92 * directly by an index into the container, and second, using an iterator.
93 * This method is used in the iterator method and is typically used in a
94 * for-loop to run through the EnergyHarvesters.
95 *
96 * @code
97 * EnergyHarvesterContainer::Iterator i;
98 * for (i = container.Begin (); i != container.End (); ++i)
99 * {
100 * (*i)->method (); // some EnergyHarvester method
101 * }
102 * @endcode
103 */
104 Iterator Begin() const;
105
106 /**
107 * @brief Get an iterator which refers to the last EnergyHarvester pointer
108 * in the container.
109 *
110 * @returns An iterator which refers to the last EnergyHarvester in container.
111 *
112 * EnergyHarvesters can be retrieved from the container in two ways. First,
113 * directly by an index into the container, and second, using an iterator.
114 * This method is used in the iterator method and is typically used in a
115 * for-loop to run through the EnergyHarvesters.
116 *
117 * @code
118 * EnergyHarvesterContainer::Iterator i;
119 * for (i = container.Begin (); i != container.End (); ++i)
120 * {
121 * (*i)->method (); // some EnergyHarvester method
122 * }
123 * @endcode
124 */
125 Iterator End() const;
126
127 /**
128 * @brief Get the number of Ptr<EnergyHarvester> stored in this container.
129 *
130 * @returns The number of Ptr<EnergyHarvester> stored in this container.
131 */
132 uint32_t GetN() const;
133
134 /**
135 * @brief Get the i-th Ptr<EnergyHarvester> stored in this container.
136 *
137 * @param i Index of the requested Ptr<EnergyHarvester>.
138 * @returns The requested Ptr<EnergyHarvester>.
139 */
141
142 /**
143 * @param container Another EnergyHarvesterContainer.
144 *
145 * Appends the contents of another EnergyHarvesterContainer to the end of
146 * this EnergyHarvesterContainer.
147 */
148 void Add(EnergyHarvesterContainer container);
149
150 /**
151 * @brief Append a single Ptr<EnergyHarvester> to the end of this container.
152 *
153 * @param harvester Pointer to an EnergyHarvester.
154 */
156
157 /**
158 * @brief Append a single Ptr<EnergyHarvester> referred to by its object
159 * name to the end of this container.
160 *
161 * @param harvesterName Name of EnergyHarvester object.
162 */
163 void Add(std::string harvesterName);
164
165 /**
166 * @brief Removes all elements in the container.
167 */
168 void Clear();
169
170 private:
171 void DoDispose() override;
172
173 /**
174 * @brief Calls Object::Initialize () for all EnergySource objects.
175 */
176 void DoInitialize() override;
177
178 private:
179 std::vector<Ptr<EnergyHarvester>> m_harvesters; //!< Harvester container
180};
181
182} // namespace energy
183} // namespace ns3
184
185#endif /* defined(ENERGY_HARVESTER_CONTAINER_H) */
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
a unique identifier for an interface.
Definition type-id.h:49
Holds a vector of ns3::EnergyHarvester pointers.
uint32_t GetN() const
Get the number of Ptr<EnergyHarvester> stored in this container.
void DoInitialize() override
Calls Object::Initialize () for all EnergySource objects.
Ptr< EnergyHarvester > Get(uint32_t i) const
Get the i-th Ptr<EnergyHarvester> stored in this container.
EnergyHarvesterContainer()
Creates an empty EnergyHarvesterContainer.
void Clear()
Removes all elements in the container.
std::vector< Ptr< EnergyHarvester > >::const_iterator Iterator
Const iterator for EnergyHarvester container.
Iterator End() const
Get an iterator which refers to the last EnergyHarvester pointer in the container.
void Add(EnergyHarvesterContainer container)
std::vector< Ptr< EnergyHarvester > > m_harvesters
Harvester container.
void DoDispose() override
Destructor implementation.
Iterator Begin() const
Get an iterator which refers to the first EnergyHarvester pointer in the container.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.