A Discrete-Event Network Simulator
API
names.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
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 
19 #ifndef OBJECT_NAMES_H
20 #define OBJECT_NAMES_H
21 
22 #include "ptr.h"
23 #include "object.h"
24 
31 namespace ns3 {
32 
38 class Names
39 {
40 public:
41 
79  static void Add (std::string name, Ptr<Object> object);
80 
116  static void Add (std::string path, std::string name, Ptr<Object> object);
117 
172  static void Add (Ptr<Object> context, std::string name, Ptr<Object> object);
173 
204  static void Rename (std::string oldpath, std::string newname);
205 
229  static void Rename (std::string path, std::string oldname, std::string newname);
230 
275  static void Rename (Ptr<Object> context, std::string oldname, std::string newname);
276 
295  static std::string FindName (Ptr<Object> object);
296 
316  static std::string FindPath (Ptr<Object> object);
317 
322  static void Clear (void);
323 
344  template <typename T>
345  static Ptr<T> Find (std::string path);
346 
371  template <typename T>
372  static Ptr<T> Find (std::string path, std::string name);
373 
414  template <typename T>
415  static Ptr<T> Find (Ptr<Object> context, std::string name);
416 
417 private:
426  static Ptr<Object> FindInternal (std::string path);
427 
438  static Ptr<Object> FindInternal (std::string path, std::string name);
439 
449  static Ptr<Object> FindInternal (Ptr<Object> context, std::string name);
450 };
451 
452 
453 template <typename T>
454 /* static */
455 Ptr<T>
456 Names::Find (std::string path)
457 {
458  Ptr<Object> obj = FindInternal (path);
459  if (obj)
460  {
461  return obj->GetObject<T> ();
462  }
463  else
464  {
465  return 0;
466  }
467 }
468 
469 template <typename T>
470 /* static */
471 Ptr<T>
472 Names::Find (std::string path, std::string name)
473 {
474  Ptr<Object> obj = FindInternal (path, name);
475  if (obj)
476  {
477  return obj->GetObject<T> ();
478  }
479  else
480  {
481  return 0;
482  }
483 }
484 
485 template <typename T>
486 /* static */
487 Ptr<T>
488 Names::Find (Ptr<Object> context, std::string name)
489 {
490  Ptr<Object> obj = FindInternal (context, name);
491  if (obj)
492  {
493  return obj->GetObject<T> ();
494  }
495  else
496  {
497  return 0;
498  }
499 }
500 
501 } // namespace ns3
502 
503 #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:776
static Ptr< Object > FindInternal(std::string path)
Non-templated internal version of Names::Find.
Definition: names.cc:838
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Definition: names.cc:768
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:456
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:817
static void Clear(void)
Clear the list of objects associated with names.
Definition: names.cc:831
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:824
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
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.