A Discrete-Event Network Simulator
API
names.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 University of Washington
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 
18 #ifndef OBJECT_NAMES_H
19 #define OBJECT_NAMES_H
20 
21 #include "object.h"
22 #include "ptr.h"
23 
30 namespace ns3
31 {
32 
38 class Names
39 {
40  public:
78  static void Add(std::string name, Ptr<Object> object);
79 
115  static void Add(std::string path, std::string name, Ptr<Object> object);
116 
171  static void Add(Ptr<Object> context, std::string name, Ptr<Object> object);
172 
203  static void Rename(std::string oldpath, std::string newname);
204 
228  static void Rename(std::string path, std::string oldname, std::string newname);
229 
274  static void Rename(Ptr<Object> context, std::string oldname, std::string newname);
275 
294  static std::string FindName(Ptr<Object> object);
295 
315  static std::string FindPath(Ptr<Object> object);
316 
321  static void Clear();
322 
343  template <typename T>
344  static Ptr<T> Find(std::string path);
345 
370  template <typename T>
371  static Ptr<T> Find(std::string path, std::string name);
372 
413  template <typename T>
414  static Ptr<T> Find(Ptr<Object> context, std::string name);
415 
416  private:
425  static Ptr<Object> FindInternal(std::string path);
426 
437  static Ptr<Object> FindInternal(std::string path, std::string name);
438 
448  static Ptr<Object> FindInternal(Ptr<Object> context, std::string name);
449 };
450 
451 template <typename T>
452 /* static */
453 Ptr<T>
454 Names::Find(std::string path)
455 {
456  Ptr<Object> obj = FindInternal(path);
457  if (obj)
458  {
459  return obj->GetObject<T>();
460  }
461  else
462  {
463  return nullptr;
464  }
465 }
466 
467 template <typename T>
468 /* static */
469 Ptr<T>
470 Names::Find(std::string path, std::string name)
471 {
472  Ptr<Object> obj = FindInternal(path, name);
473  if (obj)
474  {
475  return obj->GetObject<T>();
476  }
477  else
478  {
479  return nullptr;
480  }
481 }
482 
483 template <typename T>
484 /* static */
485 Ptr<T>
486 Names::Find(Ptr<Object> context, std::string name)
487 {
488  Ptr<Object> obj = FindInternal(context, name);
489  if (obj)
490  {
491  return obj->GetObject<T>();
492  }
493  else
494  {
495  return nullptr;
496  }
497 }
498 
499 } // namespace ns3
500 
501 #endif /* OBJECT_NAMES_H */
A directory of name and Ptr<Object> associations that allows us to give any ns3 Object a name.
Definition: names.h:39
static void Rename(std::string oldpath, std::string newname)
Rename a previously associated name.
Definition: names.cc:783
static Ptr< Object > FindInternal(std::string path)
Non-templated internal version of Names::Find.
Definition: names.cc:850
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Definition: names.cc:775
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
Definition: names.h:454
static void Clear()
Clear the list of objects associated with names.
Definition: names.cc:843
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and,...
Definition: names.cc:829
static std::string FindPath(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and return the...
Definition: names.cc:836
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
ns3::Ptr smart pointer declaration and implementation.