A Discrete-Event Network Simulator
API
config.cc
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  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #include "config.h"
21 #include "singleton.h"
22 #include "object.h"
23 #include "global-value.h"
24 #include "object-ptr-container.h"
25 #include "names.h"
26 #include "pointer.h"
27 #include "log.h"
28 
29 #include <sstream>
30 
37 namespace ns3 {
38 
39 NS_LOG_COMPONENT_DEFINE ("Config");
40 
41 namespace Config {
42 
44 {
45  NS_LOG_FUNCTION (this);
46 }
47 MatchContainer::MatchContainer (const std::vector<Ptr<Object> > &objects,
48  const std::vector<std::string> &contexts,
49  std::string path)
50  : m_objects (objects),
51  m_contexts (contexts),
52  m_path (path)
53 {
54  NS_LOG_FUNCTION (this << &objects << &contexts << path);
55 }
58 {
59  NS_LOG_FUNCTION (this);
60  return m_objects.begin ();
61 }
63 MatchContainer::End (void) const
64 {
65  NS_LOG_FUNCTION (this);
66  return m_objects.end ();
67 }
68 std::size_t
70 {
71  NS_LOG_FUNCTION (this);
72  return m_objects.size ();
73 }
75 MatchContainer::Get (std::size_t i) const
76 {
77  NS_LOG_FUNCTION (this << i);
78  return m_objects[i];
79 }
80 std::string
82 {
83  NS_LOG_FUNCTION (this << i);
84  return m_contexts[i];
85 }
86 std::string
88 {
89  NS_LOG_FUNCTION (this);
90  return m_path;
91 }
92 
93 void
94 MatchContainer::Set (std::string name, const AttributeValue &value)
95 {
96  NS_LOG_FUNCTION (this << name << &value);
97  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
98  {
99  Ptr<Object> object = *tmp;
100  object->SetAttribute (name, value);
101  }
102 }
103 void
104 MatchContainer::Connect (std::string name, const CallbackBase &cb)
105 {
106  NS_LOG_FUNCTION (this << name << &cb);
107  NS_ASSERT (m_objects.size () == m_contexts.size ());
108  for (uint32_t i = 0; i < m_objects.size (); ++i)
109  {
110  Ptr<Object> object = m_objects[i];
111  std::string ctx = m_contexts[i] + name;
112  object->TraceConnect (name, ctx, cb);
113  }
114 }
115 void
117 {
118  NS_LOG_FUNCTION (this << name << &cb);
119 
120  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
121  {
122  Ptr<Object> object = *tmp;
123  object->TraceConnectWithoutContext (name, cb);
124  }
125 }
126 void
127 MatchContainer::Disconnect (std::string name, const CallbackBase &cb)
128 {
129  NS_LOG_FUNCTION (this << name << &cb);
130  NS_ASSERT (m_objects.size () == m_contexts.size ());
131  for (uint32_t i = 0; i < m_objects.size (); ++i)
132  {
133  Ptr<Object> object = m_objects[i];
134  std::string ctx = m_contexts[i] + name;
135  object->TraceDisconnect (name, ctx, cb);
136  }
137 }
138 void
140 {
141  NS_LOG_FUNCTION (this << name << &cb);
142  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
143  {
144  Ptr<Object> object = *tmp;
145  object->TraceDisconnectWithoutContext (name, cb);
146  }
147 }
148 
149 
155 {
156 public:
162  ArrayMatcher (std::string element);
169  bool Matches (std::size_t i) const;
170 private:
178  bool StringToUint32 (std::string str, uint32_t *value) const;
180  std::string m_element;
181 
182 }; // class ArrayMatcher
183 
184 
185 ArrayMatcher::ArrayMatcher (std::string element)
186  : m_element (element)
187 {
188  NS_LOG_FUNCTION (this << element);
189 }
190 bool
191 ArrayMatcher::Matches (std::size_t i) const
192 {
193  NS_LOG_FUNCTION (this << i);
194  if (m_element == "*")
195  {
196  NS_LOG_DEBUG ("Array "<<i<<" matches *");
197  return true;
198  }
199  std::string::size_type tmp;
200  tmp = m_element.find ("|");
201  if (tmp != std::string::npos)
202  {
203  std::string left = m_element.substr (0, tmp-0);
204  std::string right = m_element.substr (tmp+1, m_element.size () - (tmp + 1));
205  ArrayMatcher matcher = ArrayMatcher (left);
206  if (matcher.Matches (i))
207  {
208  NS_LOG_DEBUG ("Array "<<i<<" matches "<<left);
209  return true;
210  }
211  matcher = ArrayMatcher (right);
212  if (matcher.Matches (i))
213  {
214  NS_LOG_DEBUG ("Array "<<i<<" matches "<<right);
215  return true;
216  }
217  NS_LOG_DEBUG ("Array "<<i<<" does not match "<<m_element);
218  return false;
219  }
220  std::string::size_type leftBracket = m_element.find ("[");
221  std::string::size_type rightBracket = m_element.find ("]");
222  std::string::size_type dash = m_element.find ("-");
223  if (leftBracket == 0 && rightBracket == m_element.size () - 1 &&
224  dash > leftBracket && dash < rightBracket)
225  {
226  std::string lowerBound = m_element.substr (leftBracket + 1, dash - (leftBracket + 1));
227  std::string upperBound = m_element.substr (dash + 1, rightBracket - (dash + 1));
228  uint32_t min;
229  uint32_t max;
230  if (StringToUint32 (lowerBound, &min) &&
231  StringToUint32 (upperBound, &max) &&
232  i >= min && i <= max)
233  {
234  NS_LOG_DEBUG ("Array "<<i<<" matches "<<m_element);
235  return true;
236  }
237  else
238  {
239  NS_LOG_DEBUG ("Array "<<i<<" does not "<<m_element);
240  return false;
241  }
242  }
243  uint32_t value;
244  if (StringToUint32 (m_element, &value) &&
245  i == value)
246  {
247  NS_LOG_DEBUG ("Array "<<i<<" matches "<<m_element);
248  return true;
249  }
250  NS_LOG_DEBUG ("Array "<<i<<" does not match "<<m_element);
251  return false;
252 }
253 
254 bool
255 ArrayMatcher::StringToUint32 (std::string str, uint32_t *value) const
256 {
257  NS_LOG_FUNCTION (this << str << value);
258  std::istringstream iss;
259  iss.str (str);
260  iss >> (*value);
261  return !iss.bad () && !iss.fail ();
262 }
263 
268 class Resolver
269 {
270 public:
276  Resolver (std::string path);
278  virtual ~Resolver ();
279 
287  void Resolve (Ptr<Object> root);
288 
289 private:
291  void Canonicalize (void);
299  void DoResolve (std::string path, Ptr<Object> root);
306  void DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector);
312  void DoResolveOne (Ptr<Object> object);
318  std::string GetResolvedPath (void) const;
325  virtual void DoOne (Ptr<Object> object, std::string path) = 0;
326 
328  std::vector<std::string> m_workStack;
330  std::string m_path;
331 
332 }; // class Resolver
333 
334 Resolver::Resolver (std::string path)
335  : m_path (path)
336 {
337  NS_LOG_FUNCTION (this << path);
338  Canonicalize ();
339 }
341 {
342  NS_LOG_FUNCTION (this);
343 }
344 void
346 {
347  NS_LOG_FUNCTION (this);
348 
349  // ensure that we start and end with a '/'
350  std::string::size_type tmp = m_path.find ("/");
351  if (tmp != 0)
352  {
353  // no slash at start
354  m_path = "/" + m_path;
355  }
356  tmp = m_path.find_last_of ("/");
357  if (tmp != (m_path.size () - 1))
358  {
359  // no slash at end
360  m_path = m_path + "/";
361  }
362 }
363 
364 void
366 {
367  NS_LOG_FUNCTION (this << root);
368 
369  DoResolve (m_path, root);
370 }
371 
372 std::string
374 {
375  NS_LOG_FUNCTION (this);
376 
377  std::string fullPath = "/";
378  for (std::vector<std::string>::const_iterator i = m_workStack.begin (); i != m_workStack.end (); i++)
379  {
380  fullPath += *i + "/";
381  }
382  return fullPath;
383 }
384 
385 void
387 {
388  NS_LOG_FUNCTION (this << object);
389 
390  NS_LOG_DEBUG ("resolved="<<GetResolvedPath ());
391  DoOne (object, GetResolvedPath ());
392 }
393 
394 void
395 Resolver::DoResolve (std::string path, Ptr<Object> root)
396 {
397  NS_LOG_FUNCTION (this << path << root);
398  NS_ASSERT ((path.find ("/")) == 0);
399  std::string::size_type next = path.find ("/", 1);
400 
401  if (next == std::string::npos)
402  {
403  //
404  // If root is zero, we're beginning to see if we can use the object name
405  // service to resolve this path. It is impossible to have a object name
406  // associated with the root of the object name service since that root
407  // is not an object. This path must be referring to something in another
408  // namespace and it will have been found already since the name service
409  // is always consulted last.
410  //
411  if (root)
412  {
413  DoResolveOne (root);
414  }
415  return;
416  }
417  std::string item = path.substr (1, next-1);
418  std::string pathLeft = path.substr (next, path.size ()-next);
419 
420  //
421  // If root is zero, we're beginning to see if we can use the object name
422  // service to resolve this path. In this case, we must see the name space
423  // "/Names" on the front of this path. There is no object associated with
424  // the root of the "/Names" namespace, so we just ignore it and move on to
425  // the next segment.
426  //
427  if (root == 0)
428  {
429  std::string::size_type offset = path.find ("/Names");
430  if (offset == 0)
431  {
432  m_workStack.push_back (item);
433  DoResolve (pathLeft, root);
434  m_workStack.pop_back ();
435  return;
436  }
437  }
438 
439  //
440  // We have an item (possibly a segment of a namespace path. Check to see if
441  // we can determine that this segment refers to a named object. If root is
442  // zero, this means to look in the root of the "/Names" name space, otherwise
443  // it refers to a name space context (level).
444  //
445  Ptr<Object> namedObject = Names::Find<Object> (root, item);
446  if (namedObject)
447  {
448  NS_LOG_DEBUG ("Name system resolved item = " << item << " to " << namedObject);
449  m_workStack.push_back (item);
450  DoResolve (pathLeft, namedObject);
451  m_workStack.pop_back ();
452  return;
453  }
454 
455  //
456  // We're done with the object name service hooks, so proceed down the path
457  // of types and attributes; but only if root is nonzero. If root is zero
458  // and we find ourselves here, we are trying to check in the namespace for
459  // a path that is not in the "/Names" namespace. We will have previously
460  // found any matches, so we just bail out.
461  //
462  if (root == 0)
463  {
464  return;
465  }
466  std::string::size_type dollarPos = item.find ("$");
467  if (dollarPos == 0)
468  {
469  // This is a call to GetObject
470  std::string tidString = item.substr (1, item.size () - 1);
471  NS_LOG_DEBUG ("GetObject="<<tidString<<" on path="<<GetResolvedPath ());
472  TypeId tid = TypeId::LookupByName (tidString);
473  Ptr<Object> object = root->GetObject<Object> (tid);
474  if (object == 0)
475  {
476  NS_LOG_DEBUG ("GetObject ("<<tidString<<") failed on path="<<GetResolvedPath ());
477  return;
478  }
479  m_workStack.push_back (item);
480  DoResolve (pathLeft, object);
481  m_workStack.pop_back ();
482  }
483  else
484  {
485  // this is a normal attribute.
486  TypeId tid;
487  TypeId nextTid = root->GetInstanceTypeId ();
488  bool foundMatch = false;
489 
490  do
491  {
492  tid = nextTid;
493 
494  for (uint32_t i = 0; i < tid.GetAttributeN(); i++)
495  {
496  struct TypeId::AttributeInformation info;
497  info = tid.GetAttribute(i);
498  if (info.name != item && item != "*")
499  {
500  continue;
501  }
502  // attempt to cast to a pointer checker.
503  const PointerChecker *pChecker = dynamic_cast<const PointerChecker *> (PeekPointer(info.checker));
504  if (pChecker != 0)
505  {
506  NS_LOG_DEBUG ("GetAttribute(ptr)="<<info.name<<" on path="<<GetResolvedPath ());
507  PointerValue pValue;
508  root->GetAttribute (info.name, pValue);
509  Ptr<Object> object = pValue.Get<Object> ();
510  if (object == 0)
511  {
512  NS_LOG_ERROR ("Requested object name=\""<<item<<
513  "\" exists on path=\""<<GetResolvedPath ()<<"\""
514  " but is null.");
515  continue;
516  }
517  foundMatch = true;
518  m_workStack.push_back (info.name);
519  DoResolve (pathLeft, object);
520  m_workStack.pop_back ();
521  }
522  // attempt to cast to an object vector.
523  const ObjectPtrContainerChecker *vectorChecker =
524  dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
525  if (vectorChecker != 0)
526  {
527  NS_LOG_DEBUG ("GetAttribute(vector)="<<info.name<<" on path="<<GetResolvedPath () << pathLeft);
528  foundMatch = true;
530  root->GetAttribute (info.name, vector);
531  m_workStack.push_back (info.name);
532  DoArrayResolve (pathLeft, vector);
533  m_workStack.pop_back ();
534  }
535  // this could be anything else and we don't know what to do with it.
536  // So, we just ignore it.
537  }
538 
539  nextTid = tid.GetParent ();
540  } while (nextTid != tid);
541 
542  if (!foundMatch)
543  {
544  NS_LOG_DEBUG ("Requested item="<<item<<" does not exist on path="<<GetResolvedPath ());
545  return;
546  }
547  }
548 }
549 
550 void
551 Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &container)
552 {
553  NS_LOG_FUNCTION(this << path << &container);
554  NS_ASSERT (path != "");
555  NS_ASSERT ((path.find ("/")) == 0);
556  std::string::size_type next = path.find ("/", 1);
557  if (next == std::string::npos)
558  {
559  return;
560  }
561  std::string item = path.substr (1, next-1);
562  std::string pathLeft = path.substr (next, path.size ()-next);
563 
564  ArrayMatcher matcher = ArrayMatcher (item);
566  for (it = container.Begin (); it != container.End (); ++it)
567  {
568  if (matcher.Matches ((*it).first))
569  {
570  std::ostringstream oss;
571  oss << (*it).first;
572  m_workStack.push_back (oss.str ());
573  DoResolve (pathLeft, (*it).second);
574  m_workStack.pop_back ();
575  }
576  }
577 }
578 
583 class ConfigImpl : public Singleton<ConfigImpl>
584 {
585 public:
587  void Set (std::string path, const AttributeValue &value);
589  void ConnectWithoutContext (std::string path, const CallbackBase &cb);
591  void Connect (std::string path, const CallbackBase &cb);
593  void DisconnectWithoutContext (std::string path, const CallbackBase &cb);
595  void Disconnect (std::string path, const CallbackBase &cb);
597  MatchContainer LookupMatches (std::string path);
598 
603 
605  std::size_t GetRootNamespaceObjectN (void) const;
607  Ptr<Object> GetRootNamespaceObject (std::size_t i) const;
608 
609 private:
617  void ParsePath (std::string path, std::string *root, std::string *leaf) const;
618 
620  typedef std::vector<Ptr<Object> > Roots;
621 
624 
625 }; // class ConfigImpl
626 
627 void
628 ConfigImpl::ParsePath (std::string path, std::string *root, std::string *leaf) const
629 {
630  NS_LOG_FUNCTION (this << path << root << leaf);
631 
632  std::string::size_type slash = path.find_last_of ("/");
633  NS_ASSERT (slash != std::string::npos);
634  *root = path.substr (0, slash);
635  *leaf = path.substr (slash+1, path.size ()-(slash+1));
636  NS_LOG_FUNCTION (path << *root << *leaf);
637 }
638 
639 void
640 ConfigImpl::Set (std::string path, const AttributeValue &value)
641 {
642  NS_LOG_FUNCTION (this << path << &value);
643 
644  std::string root, leaf;
645  ParsePath (path, &root, &leaf);
646  MatchContainer container = LookupMatches (root);
647  container.Set (leaf, value);
648 }
649 void
650 ConfigImpl::ConnectWithoutContext (std::string path, const CallbackBase &cb)
651 {
652  NS_LOG_FUNCTION (this << path << &cb);
653  std::string root, leaf;
654  ParsePath (path, &root, &leaf);
655  MatchContainer container = LookupMatches (root);
656  container.ConnectWithoutContext (leaf, cb);
657 }
658 void
660 {
661  NS_LOG_FUNCTION (this << path << &cb);
662  std::string root, leaf;
663  ParsePath (path, &root, &leaf);
664  MatchContainer container = LookupMatches (root);
665  container.DisconnectWithoutContext (leaf, cb);
666 }
667 void
668 ConfigImpl::Connect (std::string path, const CallbackBase &cb)
669 {
670  NS_LOG_FUNCTION (this << path << &cb);
671 
672  std::string root, leaf;
673  ParsePath (path, &root, &leaf);
674  MatchContainer container = LookupMatches (root);
675  container.Connect (leaf, cb);
676 }
677 void
678 ConfigImpl::Disconnect (std::string path, const CallbackBase &cb)
679 {
680  NS_LOG_FUNCTION (this << path << &cb);
681 
682  std::string root, leaf;
683  ParsePath (path, &root, &leaf);
684  MatchContainer container = LookupMatches (root);
685  container.Disconnect (leaf, cb);
686 }
687 
689 ConfigImpl::LookupMatches (std::string path)
690 {
691  NS_LOG_FUNCTION (this << path);
692  class LookupMatchesResolver : public Resolver
693  {
694  public:
695  LookupMatchesResolver (std::string path)
696  : Resolver (path)
697  {}
698  virtual void DoOne (Ptr<Object> object, std::string path)
699  {
700  m_objects.push_back (object);
701  m_contexts.push_back (path);
702  }
703  std::vector<Ptr<Object> > m_objects;
704  std::vector<std::string> m_contexts;
705  } resolver = LookupMatchesResolver (path);
706  for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++)
707  {
708  resolver.Resolve (*i);
709  }
710 
711  //
712  // See if we can do something with the object name service. Starting with
713  // the root pointer zeroed indicates to the resolver that it should start
714  // looking at the root of the "/Names" namespace during this go.
715  //
716  resolver.Resolve (0);
717 
718  return MatchContainer (resolver.m_objects, resolver.m_contexts, path);
719 }
720 
721 void
723 {
724  NS_LOG_FUNCTION (this << obj);
725  m_roots.push_back (obj);
726 }
727 
728 void
730 {
731  NS_LOG_FUNCTION (this << obj);
732 
733  for (std::vector<Ptr<Object> >::iterator i = m_roots.begin (); i != m_roots.end (); i++)
734  {
735  if (*i == obj)
736  {
737  m_roots.erase (i);
738  return;
739  }
740  }
741 }
742 
743 std::size_t
745 {
746  NS_LOG_FUNCTION (this);
747  return m_roots.size ();
748 }
751 {
752  NS_LOG_FUNCTION (this << i);
753  return m_roots[i];
754 }
755 
756 
757 void Reset (void)
758 {
760  // First, let's reset the initial value of every attribute
761  for (uint16_t i = 0; i < TypeId::GetRegisteredN (); i++)
762  {
763  TypeId tid = TypeId::GetRegistered (i);
764  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
765  {
766  struct TypeId::AttributeInformation info = tid.GetAttribute (j);
768  }
769  }
770  // now, let's reset the initial value of every global value.
772  {
773  (*i)->ResetInitialValue ();
774  }
775 }
776 
777 void Set (std::string path, const AttributeValue &value)
778 {
779  NS_LOG_FUNCTION (path << &value);
780  ConfigImpl::Get ()->Set (path, value);
781 }
782 void SetDefault (std::string name, const AttributeValue &value)
783 {
784  NS_LOG_FUNCTION (name << &value);
785  if (!SetDefaultFailSafe(name, value))
786  {
787  NS_FATAL_ERROR ("Could not set default value for " << name);
788  }
789 }
790 bool SetDefaultFailSafe (std::string fullName, const AttributeValue &value)
791 {
792  NS_LOG_FUNCTION (fullName << &value);
793  std::string::size_type pos = fullName.rfind ("::");
794  if (pos == std::string::npos)
795  {
796  return false;
797  }
798  std::string tidName = fullName.substr (0, pos);
799  std::string paramName = fullName.substr (pos+2, fullName.size () - (pos+2));
800  TypeId tid;
801  bool ok = TypeId::LookupByNameFailSafe (tidName, &tid);
802  if (!ok)
803  {
804  return false;
805  }
806  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
807  {
808  struct TypeId::AttributeInformation tmp = tid.GetAttribute(j);
809  if (tmp.name == paramName)
810  {
811  Ptr<AttributeValue> v = tmp.checker->CreateValidValue (value);
812  if (v == 0)
813  {
814  return false;
815  }
816  tid.SetAttributeInitialValue (j, v);
817  return true;
818  }
819  }
820  return false;
821 }
822 void SetGlobal (std::string name, const AttributeValue &value)
823 {
824  NS_LOG_FUNCTION (name << &value);
825  GlobalValue::Bind (name, value);
826 }
827 bool SetGlobalFailSafe (std::string name, const AttributeValue &value)
828 {
829  NS_LOG_FUNCTION (name << &value);
830  return GlobalValue::BindFailSafe (name, value);
831 }
832 void ConnectWithoutContext (std::string path, const CallbackBase &cb)
833 {
834  NS_LOG_FUNCTION (path << &cb);
835  ConfigImpl::Get ()->ConnectWithoutContext (path, cb);
836 }
837 void DisconnectWithoutContext (std::string path, const CallbackBase &cb)
838 {
839  NS_LOG_FUNCTION (path << &cb);
841 }
842 void
843 Connect (std::string path, const CallbackBase &cb)
844 {
845  NS_LOG_FUNCTION (path << &cb);
846  ConfigImpl::Get ()->Connect (path, cb);
847 }
848 void
849 Disconnect (std::string path, const CallbackBase &cb)
850 {
851  NS_LOG_FUNCTION (path << &cb);
852  ConfigImpl::Get ()->Disconnect (path, cb);
853 }
854 MatchContainer LookupMatches (std::string path)
855 {
856  NS_LOG_FUNCTION (path);
857  return ConfigImpl::Get ()->LookupMatches (path);
858 }
859 
861 {
862  NS_LOG_FUNCTION (obj);
864 }
865 
867 {
868  NS_LOG_FUNCTION (obj);
870 }
871 
872 std::size_t GetRootNamespaceObjectN (void)
873 {
876 }
877 
879 {
880  NS_LOG_FUNCTION (i);
882 }
883 
884 } // namespace Config
885 
886 } // namespace ns3
std::string GetMatchedPath(uint32_t i) const
Definition: config.cc:81
void ParsePath(std::string path, std::string *root, std::string *leaf) const
Break a Config path into the leading path and the last leaf token.
Definition: config.cc:628
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ns3::Singleton declaration and template implementation.
bool SetDefaultFailSafe(std::string fullName, const AttributeValue &value)
Definition: config.cc:790
std::vector< std::string > m_workStack
Current list of path tokens.
Definition: config.cc:328
#define min(a, b)
Definition: 80211b.c:42
Roots m_roots
The list of Config path roots.
Definition: config.cc:623
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:777
bool SetGlobalFailSafe(std::string name, const AttributeValue &value)
Definition: config.cc:827
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:866
Hold a value for an Attribute.
Definition: attribute.h:68
Ptr< const AttributeValue > originalInitialValue
Default initial value.
Definition: type-id.h:84
std::size_t GetRootNamespaceObjectN(void) const
Definition: config.cc:744
Helper to test if an array entry matches a config path specification.
Definition: config.cc:154
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:722
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:564
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void DoResolveOne(Ptr< Object > object)
Handle one object found on the path.
Definition: config.cc:386
Vector::const_iterator Iterator
Iterator type for the list of all global values.
Definition: global-value.h:80
Base class for Callback class.
Definition: callback.h:1104
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:870
Config system implementation class.
Definition: config.cc:583
void Disconnect(std::string name, const CallbackBase &cb)
Definition: config.cc:127
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:837
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:832
Ptr< Object > GetRootNamespaceObject(std::size_t i) const
Definition: config.cc:750
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:729
Ptr< Object > Get(std::size_t i) const
Definition: config.cc:75
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
std::size_t GetN(void) const
Definition: config.cc:69
Declaration of the various ns3::Config functions and classes.
static ConfigImpl * Get(void)
Get a pointer to the singleton instance.
Definition: singleton.h:89
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:860
bool SetAttributeInitialValue(std::size_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1043
TypeId GetParent(void) const
Get the parent of this TypeId.
Definition: type-id.cc:936
A template singleton.
Definition: singleton.h:63
void ConnectWithoutContext(std::string name, const CallbackBase &cb)
Definition: config.cc:116
ns3::ObjectPtrContainerValue attribute value declarations and template implementations.
#define max(a, b)
Definition: 80211b.c:43
bool StringToUint32(std::string str, uint32_t *value) const
Convert a string to an uint32_t.
Definition: config.cc:255
static Iterator Begin(void)
The Begin iterator.
Iterator Begin(void) const
Get an iterator to the first Object.
ArrayMatcher(std::string element)
Construct from a Config path specification.
Definition: config.cc:185
std::string m_element
The Config path element.
Definition: config.cc:180
std::map< std::size_t, Ptr< Object > >::const_iterator Iterator
Iterator type for traversing this container.
MatchContainer LookupMatches(std::string path)
Definition: config.cc:689
Ptr< Object > GetRootNamespaceObject(uint32_t i)
Definition: config.cc:878
AttributeChecker implementation for ObjectPtrContainerValue.
Iterator End(void) const
Get an iterator to the past-the-end Object.
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:319
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:832
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
Attribute implementation.
Definition: type-id.h:76
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:668
void Canonicalize(void)
Ensure the Config path starts and ends with a &#39;/&#39;.
Definition: config.cc:345
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:843
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
MatchContainer::Iterator Begin(void) const
Definition: config.cc:57
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:90
std::string m_path
The path used to perform the object matching.
Definition: config.h:250
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
std::string name
Attribute name.
Definition: type-id.h:78
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:640
std::string GetResolvedPath(void) const
Get the current Config path.
Definition: config.cc:373
std::size_t GetRootNamespaceObjectN(void)
Definition: config.cc:872
ns3::GlobalValue declaration.
void Resolve(Ptr< Object > root)
Parse the stored Config path into an object reference, beginning at the indicated root object...
Definition: config.cc:365
hold a set of objects which match a specific search string.
Definition: config.h:151
std::vector< Ptr< Object > > m_objects
The list of objects in this container.
Definition: config.h:246
void Connect(std::string name, const CallbackBase &cb)
Definition: config.cc:104
void Reset(void)
Reset the initial value of every attribute as well as the value of every global to what they were bef...
Definition: config.cc:757
std::vector< Ptr< Object > > Roots
Container type to hold the root Config path tokens.
Definition: config.cc:620
MatchContainer LookupMatches(std::string path)
Definition: config.cc:854
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
void DisconnectWithoutContext(std::string name, const CallbackBase &cb)
Definition: config.cc:139
virtual void DoOne(Ptr< Object > object, std::string path)=0
Handle one found object.
bool Matches(std::size_t i) const
Test if a specific index matches the Config Path.
Definition: config.cc:191
void DoArrayResolve(std::string path, const ObjectPtrContainerValue &vector)
Parse an index on the Config path.
Definition: config.cc:551
AttributeChecker implementation for PointerValue.
Definition: pointer.h:97
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:659
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:822
std::vector< std::string > m_contexts
The context for each object.
Definition: config.h:248
Resolver(std::string path)
Construct from a base Config path.
Definition: config.cc:334
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:650
std::size_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:1069
void DoResolve(std::string path, Ptr< Object > root)
Parse the next element in the Config path.
Definition: config.cc:395
static Iterator End(void)
The End iterator.
static bool BindFailSafe(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
MatchContainer::Iterator End(void) const
Definition: config.cc:63
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:782
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1076
Ptr< T > Get(void) const
Definition: pointer.h:194
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:678
virtual ~Resolver()
Destructor.
Definition: config.cc:340
Declaration of class ns3::Names.
std::vector< Ptr< Object > >::const_iterator Iterator
Const iterator over the objects in this container.
Definition: config.h:155
Abstract class to parse Config paths into object references.
Definition: config.cc:268
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
void Set(std::string name, const AttributeValue &value)
Definition: config.cc:94
A base class which provides memory management and object aggregation.
Definition: object.h:87
Container for a set of ns3::Object pointers.
static uint16_t GetRegisteredN(void)
Get the number of registered TypeIds.
Definition: type-id.cc:864
Debug message logging.
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:849
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
ns3::PointerValue attribute value declarations and template implementations.
a unique identifier for an interface.
Definition: type-id.h:58
std::string m_path
The Config path.
Definition: config.cc:330
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:824
std::string GetPath(void) const
Definition: config.cc:87