A Discrete-Event Network Simulator
API
node-container.h
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2008 INRIA
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 */
20#ifndef NODE_CONTAINER_H
21#define NODE_CONTAINER_H
22
23#include <type_traits>
24#include <vector>
25#include "ns3/node.h"
26
27namespace ns3 {
28
39{
40public:
42 typedef std::vector<Ptr<Node>>::const_iterator Iterator;
43
56 static NodeContainer GetGlobal ();
57
62
70
78 NodeContainer (std::string nodeName);
79
94 explicit NodeContainer (uint32_t n, uint32_t systemId = 0);
95
112 template <typename... Ts>
113 NodeContainer (const NodeContainer& nc, Ts&&... args);
114
134 Iterator Begin (void) const;
135
155 Iterator End (void) const;
156
177 uint32_t GetN (void) const;
178
200 Ptr<Node> Get (uint32_t i) const;
201
212 void Create (uint32_t n);
213
226 void Create (uint32_t n, uint32_t systemId);
227
234 void Add (const NodeContainer& nc);
235
245 template <typename... Ts>
246 void Add (const NodeContainer& nc, Ts&&... args);
247
253 void Add (Ptr<Node> node);
254
261 void Add (std::string nodeName);
262
269 bool Contains (uint32_t id) const;
270
271private:
272 std::vector<Ptr<Node>> m_nodes;
273};
274
275} // namespace ns3
276
278// Implementation of the templates declared above
280
281namespace ns3 {
282
283template <typename... Ts>
285{
286 static_assert (std::conjunction_v<std::is_convertible<Ts, NodeContainer>...>,
287 "Variable types are not convertible to NodeContainer");
288
289 Add (nc, std::forward<Ts> (args)...);
290}
291
292template <typename... Ts>
293void
295{
296 static_assert (std::conjunction_v<std::is_convertible<Ts, NodeContainer>...>,
297 "Variable types are not convertible to NodeContainer");
298
299 Add (nc);
300 Add (std::forward<Ts> (args)...);
301}
302
303} // namespace ns3
304
305#endif /* NODE_CONTAINER_H */
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
std::vector< Ptr< Node > > m_nodes
Nodes smart pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the 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.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this 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.