A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
energy-source-container.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8 * Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
9 */
10
11#ifndef ENERGY_SOURCE_CONTAINER_H
12#define ENERGY_SOURCE_CONTAINER_H
13
14#include "ns3/energy-source.h"
15#include "ns3/object.h"
16
17#include <stdint.h>
18#include <vector>
19
20namespace ns3
21{
22namespace energy
23{
24
25/**
26 * \ingroup energy
27 * \brief Holds a vector of ns3::EnergySource pointers.
28 *
29 * EnergySourceHelper returns a list of EnergySource pointers installed onto a
30 * node. Users can use this list to access EnergySource objects to obtain total
31 * energy consumption on a node easily.
32 *
33 * \see NetDeviceContainer
34 *
35 */
37{
38 public:
39 /// Const iterator for EnergySource container
40 typedef std::vector<Ptr<EnergySource>>::const_iterator Iterator;
41
42 public:
43 /**
44 * \brief Get the type ID.
45 * \return The object TypeId.
46 */
47 static TypeId GetTypeId();
48 /**
49 * Creates an empty EnergySourceContainer.
50 */
52 ~EnergySourceContainer() override;
53
54 /**
55 * \param source Pointer to an EnergySource.
56 *
57 * Creates an EnergySourceContainer with exactly one EnergySource previously
58 * instantiated.
59 */
61
62 /**
63 * \param sourceName Name of EnergySource.
64 *
65 * Creates an EnergySourceContainer with exactly one EnergySource previously
66 * instantiated and assigned a name using the Object name service. This
67 * EnergySource is specified by its assigned name.
68 */
69 EnergySourceContainer(std::string sourceName);
70
71 /**
72 * \param a A EnergySourceContainer.
73 * \param b Another EnergySourceContainer.
74 *
75 * Creates an EnergySourceContainer by concatenating EnergySourceContainer b
76 * to EnergySourceContainer a.
77 *
78 * \note Can be used to concatenate 2 Ptr<EnergySource> directly. C++ will be
79 * calling EnergySourceContainer constructor with Ptr<EnergySource> first.
80 */
82
83 /**
84 * \brief Get an iterator which refers to the first EnergySource pointer in
85 * the container.
86 *
87 * \returns An iterator which refers to the first EnergySource in container.
88 *
89 * EnergySources can be retrieved from the container in two ways. First,
90 * directly by an index into the container, and second, using an iterator.
91 * This method is used in the iterator method and is typically used in a
92 * for-loop to run through the EnergySources.
93 *
94 * \code
95 * EnergySourceContainer::Iterator i;
96 * for (i = container.Begin (); i != container.End (); ++i)
97 * {
98 * (*i)->method (); // some EnergySource method
99 * }
100 * \endcode
101 */
102 Iterator Begin() const;
103
104 /**
105 * \brief Get an iterator which refers to the last EnergySource pointer in
106 * the container.
107 *
108 * \returns An iterator which refers to the last EnergySource in container.
109 *
110 * EnergySources can be retrieved from the container in two ways. First,
111 * directly by an index into the container, and second, using an iterator.
112 * This method is used in the iterator method and is typically used in a
113 * for-loop to run through the EnergySources.
114 *
115 * \code
116 * EnergySourceContainer::Iterator i;
117 * for (i = container.Begin (); i != container.End (); ++i)
118 * {
119 * (*i)->method (); // some EnergySource method
120 * }
121 * \endcode
122 */
123 Iterator End() const;
124
125 /**
126 * \brief Get the number of Ptr<EnergySource> stored in this container.
127 *
128 * \returns The number of Ptr<EnergySource> stored in this container.
129 */
130 uint32_t GetN() const;
131
132 /**
133 * \brief Get the i-th Ptr<EnergySource> stored in this container.
134 *
135 * \param i Index of the requested Ptr<EnergySource>.
136 * \returns The requested Ptr<EnergySource>.
137 */
139
140 /**
141 * \param container Another EnergySourceContainer to append.
142 *
143 * Appends the contents of another EnergySourceContainer to the end of this
144 * EnergySourceContainer.
145 */
146 void Add(EnergySourceContainer container);
147
148 /**
149 * \brief Append a single Ptr<EnergySource> to the end of this container.
150 *
151 * \param source Pointer to an EnergySource.
152 */
153 void Add(Ptr<EnergySource> source);
154
155 /**
156 * \brief Append a single Ptr<EnergySource> referred to by its object name to
157 * the end of this container.
158 *
159 * \param sourceName Name of EnergySource object.
160 */
161 void Add(std::string sourceName);
162
163 private:
164 void DoDispose() override;
165
166 /**
167 * \brief Calls Object::Start () for all EnergySource objects.
168 */
169 void DoInitialize() override;
170
171 private:
172 std::vector<Ptr<EnergySource>> m_sources; //!< Energy source container
173};
174
175} // namespace energy
176} // namespace ns3
177
178#endif /* ENERGY_SOURCE_CONTAINER_H */
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
Holds a vector of ns3::EnergySource pointers.
static TypeId GetTypeId()
Get the type ID.
void DoDispose() override
Destructor implementation.
EnergySourceContainer()
Creates an empty EnergySourceContainer.
Iterator Begin() const
Get an iterator which refers to the first EnergySource pointer in the container.
std::vector< Ptr< EnergySource > > m_sources
Energy source container.
uint32_t GetN() const
Get the number of Ptr<EnergySource> stored in this container.
void Add(EnergySourceContainer container)
Iterator End() const
Get an iterator which refers to the last EnergySource pointer in the container.
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr<EnergySource> stored in this container.
std::vector< Ptr< EnergySource > >::const_iterator Iterator
Const iterator for EnergySource container.
void DoInitialize() override
Calls Object::Start () for all EnergySource objects.
Every class exported by the ns3 library is enclosed in the ns3 namespace.