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 
25 namespace ns3 {
26 
31 class Names
32 {
33 public:
34 
68  static void Add (std::string name, Ptr<Object> object);
69 
101  static void Add (std::string path, std::string name, Ptr<Object> object);
102 
150  static void Add (Ptr<Object> context, std::string name, Ptr<Object> object);
151 
179  static void Rename (std::string oldpath, std::string newname);
180 
201  static void Rename (std::string path, std::string oldname, std::string newname);
202 
240  static void Rename (Ptr<Object> context, std::string oldname, std::string newname);
241 
259  static std::string FindName (Ptr<Object> object);
260 
278  static std::string FindPath (Ptr<Object> object);
279 
284  static void Clear (void);
285 
303  template <typename T>
304  static Ptr<T> Find (std::string path);
305 
327  template <typename T>
328  static Ptr<T> Find (std::string path, std::string name);
329 
364  template <typename T>
365  static Ptr<T> Find (Ptr<Object> context, std::string name);
366 
367 private:
375  static Ptr<Object> FindInternal (std::string path);
376 
385  static Ptr<Object> FindInternal (std::string path, std::string name);
386 
396  static Ptr<Object> FindInternal (Ptr<Object> context, std::string name);
397 };
398 
402 template <typename T>
403 Ptr<T>
404 Names::Find (std::string name)
405 {
406  Ptr<Object> obj = FindInternal (name);
407  if (obj)
408  {
409  return obj->GetObject<T> ();
410  }
411  else
412  {
413  return 0;
414  }
415 }
416 
420 template <typename T>
421 Ptr<T>
422 Names::Find (std::string path, std::string name)
423 {
424  Ptr<Object> obj = FindInternal (path, name);
425  if (obj)
426  {
427  return obj->GetObject<T> ();
428  }
429  else
430  {
431  return 0;
432  }
433 }
434 
438 template <typename T>
439 Ptr<T>
440 Names::Find (Ptr<Object> context, std::string name)
441 {
442  Ptr<Object> obj = FindInternal (context, name);
443  if (obj)
444  {
445  return obj->GetObject<T> ();
446  }
447  else
448  {
449  return 0;
450  }
451 }
452 
453 } // namespace ns3
454 
455 #endif /* OBJECT_NAMES_H */
Smart pointer implementation.
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr obj.
Definition: names.cc:615
A directory of name and Ptr associations that allows us to give any ns3 Object a name...
Definition: names.h:31
static void Clear(void)
Clear the list of objects associated with names.
Definition: names.cc:678
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static void Rename(std::string oldpath, std::string newname)
Rename a previously associated name.
Definition: names.cc:623
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:671
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
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:664
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
static Ptr< Object > FindInternal(std::string path)
Non-templated internal version of Names::Find.
Definition: names.cc:685
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:404