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 uint32_t
70 {
71  NS_LOG_FUNCTION (this);
72  return m_objects.size ();
73 }
75 MatchContainer::Get (uint32_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 } // namespace Config
150 
151 
154 {
155 public:
161  ArrayMatcher (std::string element);
168  bool Matches (uint32_t i) const;
169 private:
177  bool StringToUint32 (std::string str, uint32_t *value) const;
179  std::string m_element;
180 };
181 
182 
183 ArrayMatcher::ArrayMatcher (std::string element)
184  : m_element (element)
185 {
186  NS_LOG_FUNCTION (this << element);
187 }
188 bool
189 ArrayMatcher::Matches (uint32_t i) const
190 {
191  NS_LOG_FUNCTION (this << i);
192  if (m_element == "*")
193  {
194  NS_LOG_DEBUG ("Array "<<i<<" matches *");
195  return true;
196  }
197  std::string::size_type tmp;
198  tmp = m_element.find ("|");
199  if (tmp != std::string::npos)
200  {
201  std::string left = m_element.substr (0, tmp-0);
202  std::string right = m_element.substr (tmp+1, m_element.size () - (tmp + 1));
203  ArrayMatcher matcher = ArrayMatcher (left);
204  if (matcher.Matches (i))
205  {
206  NS_LOG_DEBUG ("Array "<<i<<" matches "<<left);
207  return true;
208  }
209  matcher = ArrayMatcher (right);
210  if (matcher.Matches (i))
211  {
212  NS_LOG_DEBUG ("Array "<<i<<" matches "<<right);
213  return true;
214  }
215  NS_LOG_DEBUG ("Array "<<i<<" does not match "<<m_element);
216  return false;
217  }
218  std::string::size_type leftBracket = m_element.find ("[");
219  std::string::size_type rightBracket = m_element.find ("]");
220  std::string::size_type dash = m_element.find ("-");
221  if (leftBracket == 0 && rightBracket == m_element.size () - 1 &&
222  dash > leftBracket && dash < rightBracket)
223  {
224  std::string lowerBound = m_element.substr (leftBracket + 1, dash - (leftBracket + 1));
225  std::string upperBound = m_element.substr (dash + 1, rightBracket - (dash + 1));
226  uint32_t min;
227  uint32_t max;
228  if (StringToUint32 (lowerBound, &min) &&
229  StringToUint32 (upperBound, &max) &&
230  i >= min && i <= max)
231  {
232  NS_LOG_DEBUG ("Array "<<i<<" matches "<<m_element);
233  return true;
234  }
235  else
236  {
237  NS_LOG_DEBUG ("Array "<<i<<" does not "<<m_element);
238  return false;
239  }
240  }
241  uint32_t value;
242  if (StringToUint32 (m_element, &value) &&
243  i == value)
244  {
245  NS_LOG_DEBUG ("Array "<<i<<" matches "<<m_element);
246  return true;
247  }
248  NS_LOG_DEBUG ("Array "<<i<<" does not match "<<m_element);
249  return false;
250 }
251 
252 bool
253 ArrayMatcher::StringToUint32 (std::string str, uint32_t *value) const
254 {
255  NS_LOG_FUNCTION (this << str << value);
256  std::istringstream iss;
257  iss.str (str);
258  iss >> (*value);
259  return !iss.bad () && !iss.fail ();
260 }
261 
265 class Resolver
266 {
267 public:
273  Resolver (std::string path);
275  virtual ~Resolver ();
276 
284  void Resolve (Ptr<Object> root);
285 
286 private:
288  void Canonicalize (void);
296  void DoResolve (std::string path, Ptr<Object> root);
303  void DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector);
309  void DoResolveOne (Ptr<Object> object);
315  std::string GetResolvedPath (void) const;
322  virtual void DoOne (Ptr<Object> object, std::string path) = 0;
323 
325  std::vector<std::string> m_workStack;
327  std::string m_path;
328 };
329 
330 Resolver::Resolver (std::string path)
331  : m_path (path)
332 {
333  NS_LOG_FUNCTION (this << path);
334  Canonicalize ();
335 }
337 {
338  NS_LOG_FUNCTION (this);
339 }
340 void
342 {
343  NS_LOG_FUNCTION (this);
344 
345  // ensure that we start and end with a '/'
346  std::string::size_type tmp = m_path.find ("/");
347  if (tmp != 0)
348  {
349  // no slash at start
350  m_path = "/" + m_path;
351  }
352  tmp = m_path.find_last_of ("/");
353  if (tmp != (m_path.size () - 1))
354  {
355  // no slash at end
356  m_path = m_path + "/";
357  }
358 }
359 
360 void
362 {
363  NS_LOG_FUNCTION (this << root);
364 
365  DoResolve (m_path, root);
366 }
367 
368 std::string
370 {
371  NS_LOG_FUNCTION (this);
372 
373  std::string fullPath = "/";
374  for (std::vector<std::string>::const_iterator i = m_workStack.begin (); i != m_workStack.end (); i++)
375  {
376  fullPath += *i + "/";
377  }
378  return fullPath;
379 }
380 
381 void
383 {
384  NS_LOG_FUNCTION (this << object);
385 
386  NS_LOG_DEBUG ("resolved="<<GetResolvedPath ());
387  DoOne (object, GetResolvedPath ());
388 }
389 
390 void
391 Resolver::DoResolve (std::string path, Ptr<Object> root)
392 {
393  NS_LOG_FUNCTION (this << path << root);
394  NS_ASSERT ((path.find ("/")) == 0);
395  std::string::size_type next = path.find ("/", 1);
396 
397  if (next == std::string::npos)
398  {
399  //
400  // If root is zero, we're beginning to see if we can use the object name
401  // service to resolve this path. It is impossible to have a object name
402  // associated with the root of the object name service since that root
403  // is not an object. This path must be referring to something in another
404  // namespace and it will have been found already since the name service
405  // is always consulted last.
406  //
407  if (root)
408  {
409  DoResolveOne (root);
410  }
411  return;
412  }
413  std::string item = path.substr (1, next-1);
414  std::string pathLeft = path.substr (next, path.size ()-next);
415 
416  //
417  // If root is zero, we're beginning to see if we can use the object name
418  // service to resolve this path. In this case, we must see the name space
419  // "/Names" on the front of this path. There is no object associated with
420  // the root of the "/Names" namespace, so we just ignore it and move on to
421  // the next segment.
422  //
423  if (root == 0)
424  {
425  std::string::size_type offset = path.find ("/Names");
426  if (offset == 0)
427  {
428  m_workStack.push_back (item);
429  DoResolve (pathLeft, root);
430  m_workStack.pop_back ();
431  return;
432  }
433  }
434 
435  //
436  // We have an item (possibly a segment of a namespace path. Check to see if
437  // we can determine that this segment refers to a named object. If root is
438  // zero, this means to look in the root of the "/Names" name space, otherwise
439  // it refers to a name space context (level).
440  //
441  Ptr<Object> namedObject = Names::Find<Object> (root, item);
442  if (namedObject)
443  {
444  NS_LOG_DEBUG ("Name system resolved item = " << item << " to " << namedObject);
445  m_workStack.push_back (item);
446  DoResolve (pathLeft, namedObject);
447  m_workStack.pop_back ();
448  return;
449  }
450 
451  //
452  // We're done with the object name service hooks, so proceed down the path
453  // of types and attributes; but only if root is nonzero. If root is zero
454  // and we find ourselves here, we are trying to check in the namespace for
455  // a path that is not in the "/Names" namespace. We will have previously
456  // found any matches, so we just bail out.
457  //
458  if (root == 0)
459  {
460  return;
461  }
462  std::string::size_type dollarPos = item.find ("$");
463  if (dollarPos == 0)
464  {
465  // This is a call to GetObject
466  std::string tidString = item.substr (1, item.size () - 1);
467  NS_LOG_DEBUG ("GetObject="<<tidString<<" on path="<<GetResolvedPath ());
468  TypeId tid = TypeId::LookupByName (tidString);
469  Ptr<Object> object = root->GetObject<Object> (tid);
470  if (object == 0)
471  {
472  NS_LOG_DEBUG ("GetObject ("<<tidString<<") failed on path="<<GetResolvedPath ());
473  return;
474  }
475  m_workStack.push_back (item);
476  DoResolve (pathLeft, object);
477  m_workStack.pop_back ();
478  }
479  else
480  {
481  // this is a normal attribute.
482  TypeId tid;
483  TypeId nextTid = root->GetInstanceTypeId ();
484  bool foundMatch = false;
485 
486  do
487  {
488  tid = nextTid;
489 
490  for (uint32_t i = 0; i < tid.GetAttributeN(); i++)
491  {
492  struct TypeId::AttributeInformation info;
493  info = tid.GetAttribute(i);
494  if (info.name != item && item != "*")
495  {
496  continue;
497  }
498  // attempt to cast to a pointer checker.
499  const PointerChecker *ptr = dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
500  if (ptr != 0)
501  {
502  NS_LOG_DEBUG ("GetAttribute(ptr)="<<info.name<<" on path="<<GetResolvedPath ());
503  PointerValue ptr;
504  root->GetAttribute (info.name, ptr);
505  Ptr<Object> object = ptr.Get<Object> ();
506  if (object == 0)
507  {
508  NS_LOG_ERROR ("Requested object name=\""<<item<<
509  "\" exists on path=\""<<GetResolvedPath ()<<"\""
510  " but is null.");
511  continue;
512  }
513  foundMatch = true;
514  m_workStack.push_back (info.name);
515  DoResolve (pathLeft, object);
516  m_workStack.pop_back ();
517  }
518  // attempt to cast to an object vector.
519  const ObjectPtrContainerChecker *vectorChecker =
520  dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
521  if (vectorChecker != 0)
522  {
523  NS_LOG_DEBUG ("GetAttribute(vector)="<<info.name<<" on path="<<GetResolvedPath () << pathLeft);
524  foundMatch = true;
526  root->GetAttribute (info.name, vector);
527  m_workStack.push_back (info.name);
528  DoArrayResolve (pathLeft, vector);
529  m_workStack.pop_back ();
530  }
531  // this could be anything else and we don't know what to do with it.
532  // So, we just ignore it.
533  }
534 
535  nextTid = tid.GetParent ();
536  } while (nextTid != tid);
537 
538  if (!foundMatch)
539  {
540  NS_LOG_DEBUG ("Requested item="<<item<<" does not exist on path="<<GetResolvedPath ());
541  return;
542  }
543  }
544 }
545 
546 void
547 Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &container)
548 {
549  NS_LOG_FUNCTION(this << path << &container);
550  NS_ASSERT (path != "");
551  NS_ASSERT ((path.find ("/")) == 0);
552  std::string::size_type next = path.find ("/", 1);
553  if (next == std::string::npos)
554  {
555  return;
556  }
557  std::string item = path.substr (1, next-1);
558  std::string pathLeft = path.substr (next, path.size ()-next);
559 
560  ArrayMatcher matcher = ArrayMatcher (item);
562  for (it = container.Begin (); it != container.End (); ++it)
563  {
564  if (matcher.Matches ((*it).first))
565  {
566  std::ostringstream oss;
567  oss << (*it).first;
568  m_workStack.push_back (oss.str ());
569  DoResolve (pathLeft, (*it).second);
570  m_workStack.pop_back ();
571  }
572  }
573 }
574 
576 class ConfigImpl : public Singleton<ConfigImpl>
577 {
578 public:
580  void Set (std::string path, const AttributeValue &value);
582  void ConnectWithoutContext (std::string path, const CallbackBase &cb);
584  void Connect (std::string path, const CallbackBase &cb);
586  void DisconnectWithoutContext (std::string path, const CallbackBase &cb);
588  void Disconnect (std::string path, const CallbackBase &cb);
590  Config::MatchContainer LookupMatches (std::string path);
591 
596 
598  uint32_t GetRootNamespaceObjectN (void) const;
600  Ptr<Object> GetRootNamespaceObject (uint32_t i) const;
601 
602 private:
610  void ParsePath (std::string path, std::string *root, std::string *leaf) const;
611 
613  typedef std::vector<Ptr<Object> > Roots;
614 
616  Roots m_roots;
617 };
618 
619 void
620 ConfigImpl::ParsePath (std::string path, std::string *root, std::string *leaf) const
621 {
622  NS_LOG_FUNCTION (this << path << root << leaf);
623 
624  std::string::size_type slash = path.find_last_of ("/");
625  NS_ASSERT (slash != std::string::npos);
626  *root = path.substr (0, slash);
627  *leaf = path.substr (slash+1, path.size ()-(slash+1));
628  NS_LOG_FUNCTION (path << *root << *leaf);
629 }
630 
631 void
632 ConfigImpl::Set (std::string path, const AttributeValue &value)
633 {
634  NS_LOG_FUNCTION (this << path << &value);
635 
636  std::string root, leaf;
637  ParsePath (path, &root, &leaf);
638  Config::MatchContainer container = LookupMatches (root);
639  container.Set (leaf, value);
640 }
641 void
642 ConfigImpl::ConnectWithoutContext (std::string path, const CallbackBase &cb)
643 {
644  NS_LOG_FUNCTION (this << path << &cb);
645  std::string root, leaf;
646  ParsePath (path, &root, &leaf);
647  Config::MatchContainer container = LookupMatches (root);
648  container.ConnectWithoutContext (leaf, cb);
649 }
650 void
652 {
653  NS_LOG_FUNCTION (this << path << &cb);
654  std::string root, leaf;
655  ParsePath (path, &root, &leaf);
656  Config::MatchContainer container = LookupMatches (root);
657  container.DisconnectWithoutContext (leaf, cb);
658 }
659 void
660 ConfigImpl::Connect (std::string path, const CallbackBase &cb)
661 {
662  NS_LOG_FUNCTION (this << path << &cb);
663 
664  std::string root, leaf;
665  ParsePath (path, &root, &leaf);
666  Config::MatchContainer container = LookupMatches (root);
667  container.Connect (leaf, cb);
668 }
669 void
670 ConfigImpl::Disconnect (std::string path, const CallbackBase &cb)
671 {
672  NS_LOG_FUNCTION (this << path << &cb);
673 
674  std::string root, leaf;
675  ParsePath (path, &root, &leaf);
676  Config::MatchContainer container = LookupMatches (root);
677  container.Disconnect (leaf, cb);
678 }
679 
681 ConfigImpl::LookupMatches (std::string path)
682 {
683  NS_LOG_FUNCTION (this << path);
684  class LookupMatchesResolver : public Resolver
685  {
686  public:
687  LookupMatchesResolver (std::string path)
688  : Resolver (path)
689  {}
690  virtual void DoOne (Ptr<Object> object, std::string path) {
691  m_objects.push_back (object);
692  m_contexts.push_back (path);
693  }
694  std::vector<Ptr<Object> > m_objects;
695  std::vector<std::string> m_contexts;
696  } resolver = LookupMatchesResolver (path);
697  for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++)
698  {
699  resolver.Resolve (*i);
700  }
701 
702  //
703  // See if we can do something with the object name service. Starting with
704  // the root pointer zeroed indicates to the resolver that it should start
705  // looking at the root of the "/Names" namespace during this go.
706  //
707  resolver.Resolve (0);
708 
709  return Config::MatchContainer (resolver.m_objects, resolver.m_contexts, path);
710 }
711 
712 void
714 {
715  NS_LOG_FUNCTION (this << obj);
716  m_roots.push_back (obj);
717 }
718 
719 void
721 {
722  NS_LOG_FUNCTION (this << obj);
723 
724  for (std::vector<Ptr<Object> >::iterator i = m_roots.begin (); i != m_roots.end (); i++)
725  {
726  if (*i == obj)
727  {
728  m_roots.erase (i);
729  return;
730  }
731  }
732 }
733 
734 uint32_t
736 {
737  NS_LOG_FUNCTION (this);
738  return m_roots.size ();
739 }
742 {
743  NS_LOG_FUNCTION (this << i);
744  return m_roots[i];
745 }
746 
747 namespace Config {
748 
749 void Reset (void)
750 {
752  // First, let's reset the initial value of every attribute
753  for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++)
754  {
755  TypeId tid = TypeId::GetRegistered (i);
756  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
757  {
758  struct TypeId::AttributeInformation info = tid.GetAttribute (j);
760  }
761  }
762  // now, let's reset the initial value of every global value.
764  {
765  (*i)->ResetInitialValue ();
766  }
767 }
768 
769 void Set (std::string path, const AttributeValue &value)
770 {
771  NS_LOG_FUNCTION (path << &value);
772  ConfigImpl::Get ()->Set (path, value);
773 }
774 void SetDefault (std::string name, const AttributeValue &value)
775 {
776  NS_LOG_FUNCTION (name << &value);
777  if (!SetDefaultFailSafe(name, value))
778  {
779  NS_FATAL_ERROR ("Could not set default value for " << name);
780  }
781 }
782 bool SetDefaultFailSafe (std::string fullName, const AttributeValue &value)
783 {
784  NS_LOG_FUNCTION (fullName << &value);
785  std::string::size_type pos = fullName.rfind ("::");
786  if (pos == std::string::npos)
787  {
788  return false;
789  }
790  std::string tidName = fullName.substr (0, pos);
791  std::string paramName = fullName.substr (pos+2, fullName.size () - (pos+2));
792  TypeId tid;
793  bool ok = TypeId::LookupByNameFailSafe (tidName, &tid);
794  if (!ok)
795  {
796  return false;
797  }
798  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
799  {
800  struct TypeId::AttributeInformation tmp = tid.GetAttribute(j);
801  if (tmp.name == paramName)
802  {
803  Ptr<AttributeValue> v = tmp.checker->CreateValidValue (value);
804  if (v == 0)
805  {
806  return false;
807  }
808  tid.SetAttributeInitialValue (j, v);
809  return true;
810  }
811  }
812  return false;
813 }
814 void SetGlobal (std::string name, const AttributeValue &value)
815 {
816  NS_LOG_FUNCTION (name << &value);
817  GlobalValue::Bind (name, value);
818 }
819 bool SetGlobalFailSafe (std::string name, const AttributeValue &value)
820 {
821  NS_LOG_FUNCTION (name << &value);
822  return GlobalValue::BindFailSafe (name, value);
823 }
824 void ConnectWithoutContext (std::string path, const CallbackBase &cb)
825 {
826  NS_LOG_FUNCTION (path << &cb);
827  ConfigImpl::Get ()->ConnectWithoutContext (path, cb);
828 }
829 void DisconnectWithoutContext (std::string path, const CallbackBase &cb)
830 {
831  NS_LOG_FUNCTION (path << &cb);
833 }
834 void
835 Connect (std::string path, const CallbackBase &cb)
836 {
837  NS_LOG_FUNCTION (path << &cb);
838  ConfigImpl::Get ()->Connect (path, cb);
839 }
840 void
841 Disconnect (std::string path, const CallbackBase &cb)
842 {
843  NS_LOG_FUNCTION (path << &cb);
844  ConfigImpl::Get ()->Disconnect (path, cb);
845 }
847 {
848  NS_LOG_FUNCTION (path);
849  return ConfigImpl::Get ()->LookupMatches (path);
850 }
851 
853 {
854  NS_LOG_FUNCTION (obj);
856 }
857 
859 {
860  NS_LOG_FUNCTION (obj);
862 }
863 
864 uint32_t GetRootNamespaceObjectN (void)
865 {
868 }
869 
871 {
872  NS_LOG_FUNCTION (i);
874 }
875 
876 } // namespace Config
877 
878 } // namespace ns3
uint32_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:1058
uint32_t GetRootNamespaceObjectN(void) const
Definition: config.cc:735
Ptr< T > Get(void) const
Definition: pointer.h:194
#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:782
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:651
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:462
#define min(a, b)
Definition: 80211b.c:44
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:769
bool SetGlobalFailSafe(std::string name, const AttributeValue &value)
Definition: config.cc:819
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:858
Hold a value for an Attribute.
Definition: attribute.h:68
Ptr< const AttributeValue > originalInitialValue
Default initial value.
Definition: type-id.h:84
void DoResolve(std::string path, Ptr< Object > root)
Parse the next element in the Config path.
Definition: config.cc:391
std::string m_element
The Config path element.
Definition: config.cc:179
#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:562
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
TypeId GetParent(void) const
Get the parent of this TypeId.
Definition: type-id.cc:925
Vector::const_iterator Iterator
Iterator type for the list of all global values.
Definition: global-value.h:77
Base class for Callback class.
Definition: callback.h:1104
std::string GetMatchedPath(uint32_t i) const
Definition: config.cc:81
void Disconnect(std::string name, const CallbackBase &cb)
Definition: config.cc:127
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:829
#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:821
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
std::vector< Ptr< Object > > Roots
Container type to hold the root Config path tokens.
Definition: config.cc:613
Declaration of the various ns3::Config functions and classes.
static ConfigImpl * Get(void)
Get a pointer to the singleton instance.
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:852
std::vector< std::string > m_workStack
Current list of path tokens.
Definition: config.cc:325
std::map< uint32_t, Ptr< Object > >::const_iterator Iterator
Iterator type for traversing this container.
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:720
MatchContainer::Iterator End(void) const
Definition: config.cc:63
virtual void DoOne(Ptr< Object > object, std::string path)=0
Handle one found object.
A template singleton.
Definition: singleton.h:63
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:642
Config::MatchContainer LookupMatches(std::string path)
Definition: config.cc:681
void ConnectWithoutContext(std::string name, const CallbackBase &cb)
Definition: config.cc:116
ObjectPtrContainer attribute value declarations and template implementations.
#define max(a, b)
Definition: 80211b.c:45
static uint32_t GetRegisteredN(void)
Get the number of registered TypeIds.
Definition: type-id.cc:853
static Iterator Begin(void)
The Begin iterator.
Ptr< Object > GetRootNamespaceObject(uint32_t i)
Definition: config.cc:870
void Resolve(Ptr< Object > root)
Parse the stored Config path into an object reference, beginning at the indicated root object...
Definition: config.cc:361
AttributeChecker implementation for ObjectPtrContainerValue.
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:325
static TypeId GetRegistered(uint32_t i)
Get a TypeId by index.
Definition: type-id.cc:859
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:824
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...
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:620
uint32_t GetRootNamespaceObjectN(void)
Definition: config.cc:864
Attribute implementation.
Definition: type-id.h:76
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:660
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:835
void DoResolveOne(Ptr< Object > object)
Handle one object found on the path.
Definition: config.cc:382
uint32_t GetN(void) const
Definition: config.cc:69
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:670
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:90
void DoArrayResolve(std::string path, const ObjectPtrContainerValue &vector)
Parse an index on the Config path.
Definition: config.cc:547
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:299
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr.
Definition: pointer.h:36
std::string name
Attribute name.
Definition: type-id.h:78
Abstract class to parse Config paths into object references.
Definition: config.cc:265
Helper to test if an array entry matches a config path specification.
Definition: config.cc:153
Ptr< Object > Get(uint32_t i) const
Definition: config.cc:75
Iterator Begin(void) const
Get an iterator to the first Object.
ns3::GlobalValue declaration.
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
std::string m_path
The Config path.
Definition: config.cc:327
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:749
bool SetAttributeInitialValue(uint32_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1032
Config::MatchContainer LookupMatches(std::string path)
Definition: config.cc:846
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 ~Resolver()
Destructor.
Definition: config.cc:336
AttributeChecker implementation for PointerValue.
Definition: pointer.h:97
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:814
std::vector< std::string > m_contexts
The context for each object.
Definition: config.h:248
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...
void Canonicalize(void)
Ensure the Config path starts and ends with a '/'.
Definition: config.cc:341
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:713
Iterator End(void) const
Get an iterator to the past-the-end Object.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:774
bool Matches(uint32_t i) const
Test if a specific index matches the Config Path.
Definition: config.cc:189
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:632
Declaration of class ns3::Names.
std::vector< Ptr< Object > >::const_iterator Iterator
Const iterator over the objects in this container.
Definition: config.h:155
std::string GetResolvedPath(void) const
Get the current Config path.
Definition: config.cc:369
bool StringToUint32(std::string str, uint32_t *value) const
Convert a string to an uint32_t.
Definition: config.cc:253
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:220
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
MatchContainer::Iterator Begin(void) const
Definition: config.cc:57
Container for a set of ns3::Object pointers.
ArrayMatcher(std::string element)
Construct from a Config path specification.
Definition: config.cc:183
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
Get Attribute information by index.
Definition: type-id.cc:1065
Debug message logging.
Ptr< Object > GetRootNamespaceObject(uint32_t i) const
Definition: config.cc:741
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:841
std::string GetPath(void) const
Definition: config.cc:87
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:191
Pointer attribute value declarations and template implementations.
a unique identifier for an interface.
Definition: type-id.h:58
Resolver(std::string path)
Construct from a base Config path.
Definition: config.cc:330
Roots m_roots
The list of Config path roots.
Definition: config.cc:616
Config system implementation class.
Definition: config.cc:576
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:813