A Discrete-Event Network Simulator
API
node-container.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #ifndef NODE_CONTAINER_H
20 #define NODE_CONTAINER_H
21 
22 #include "ns3/node.h"
23 
24 #include <type_traits>
25 #include <vector>
26 
27 namespace ns3
28 {
29 
40 {
41  public:
43  typedef std::vector<Ptr<Node>>::const_iterator Iterator;
44 
57  static NodeContainer GetGlobal();
58 
62  NodeContainer();
63 
71 
79  NodeContainer(std::string nodeName);
80 
95  explicit NodeContainer(uint32_t n, uint32_t systemId = 0);
96 
113  template <typename... Ts>
114  NodeContainer(const NodeContainer& nc, Ts&&... args);
115 
135  Iterator Begin() const;
136 
156  Iterator End() const;
157 
178  uint32_t GetN() const;
179 
201  Ptr<Node> Get(uint32_t i) const;
202 
213  void Create(uint32_t n);
214 
227  void Create(uint32_t n, uint32_t systemId);
228 
235  void Add(const NodeContainer& nc);
236 
246  template <typename... Ts>
247  void Add(const NodeContainer& nc, Ts&&... args);
248 
254  void Add(Ptr<Node> node);
255 
262  void Add(std::string nodeName);
263 
270  bool Contains(uint32_t id) const;
271 
272  private:
273  std::vector<Ptr<Node>> m_nodes;
274 };
275 
276 } // namespace ns3
277 
279 // Implementation of the templates declared above
281 
282 namespace ns3
283 {
284 
285 template <typename... Ts>
287 {
288  static_assert(std::conjunction_v<std::is_convertible<Ts, NodeContainer>...>,
289  "Variable types are not convertible to NodeContainer");
290 
291  Add(nc, std::forward<Ts>(args)...);
292 }
293 
294 template <typename... Ts>
295 void
297 {
298  static_assert(std::conjunction_v<std::is_convertible<Ts, NodeContainer>...>,
299  "Variable types are not convertible to NodeContainer");
300 
301  Add(nc);
302  Add(std::forward<Ts>(args)...);
303 }
304 
305 } // namespace ns3
306 
307 #endif /* NODE_CONTAINER_H */
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
std::vector< Ptr< Node > > m_nodes
Nodes smart pointers.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
bool Contains(uint32_t id) const
Return true if container contains a Node with index id.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
NodeContainer()
Create an empty NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Every class exported by the ns3 library is enclosed in the ns3 namespace.