A Discrete-Event Network Simulator
API
type-id.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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #include "log.h" // NS_ASSERT and NS_LOG
21 #include "hash.h"
22 #include "type-id.h"
23 #include "singleton.h"
24 #include "trace-source-accessor.h"
25 
26 #include <map>
27 #include <vector>
28 #include <sstream>
29 #include <iomanip>
30 
38 /*********************************************************************
39  * Helper code
40  *********************************************************************/
41 
42 namespace ns3 {
43 
44 NS_LOG_COMPONENT_DEFINE ("TypeId");
45 
46 // IidManager needs to be in ns3 namespace for NS_ASSERT and NS_LOG
47 // to find g_log
48 
78 {
79 public:
80  IidManager ();
81  uint16_t AllocateUid (std::string name);
82  void SetParent (uint16_t uid, uint16_t parent);
83  void SetGroupName (uint16_t uid, std::string groupName);
84  void SetSize (uint16_t uid, std::size_t size);
85  void AddConstructor (uint16_t uid, Callback<ObjectBase *> callback);
86  void HideFromDocumentation (uint16_t uid);
87  uint16_t GetUid (std::string name) const;
88  uint16_t GetUid (TypeId::hash_t hash) const;
89  std::string GetName (uint16_t uid) const;
90  TypeId::hash_t GetHash (uint16_t uid) const;
91  uint16_t GetParent (uint16_t uid) const;
92  std::string GetGroupName (uint16_t uid) const;
93  std::size_t GetSize (uint16_t uid) const;
94  Callback<ObjectBase *> GetConstructor (uint16_t uid) const;
95  bool HasConstructor (uint16_t uid) const;
96  uint32_t GetRegisteredN (void) const;
97  uint16_t GetRegistered (uint32_t i) const;
98  void AddAttribute (uint16_t uid,
99  std::string name,
100  std::string help,
101  uint32_t flags,
102  Ptr<const AttributeValue> initialValue,
105  void SetAttributeInitialValue(uint16_t uid,
106  uint32_t i,
107  Ptr<const AttributeValue> initialValue);
108  uint32_t GetAttributeN (uint16_t uid) const;
109  struct TypeId::AttributeInformation GetAttribute(uint16_t uid, uint32_t i) const;
110  void AddTraceSource (uint16_t uid,
111  std::string name,
112  std::string help,
114  std::string callback);
115  uint32_t GetTraceSourceN (uint16_t uid) const;
116  struct TypeId::TraceSourceInformation GetTraceSource(uint16_t uid, uint32_t i) const;
117  bool MustHideFromDocumentation (uint16_t uid) const;
118 
119 private:
120  bool HasTraceSource (uint16_t uid, std::string name);
121  bool HasAttribute (uint16_t uid, std::string name);
122  static TypeId::hash_t Hasher (const std::string name);
123 
124  struct IidInformation {
125  std::string name;
127  uint16_t parent;
128  std::string groupName;
129  std::size_t size;
133  std::vector<struct TypeId::AttributeInformation> attributes;
134  std::vector<struct TypeId::TraceSourceInformation> traceSources;
135  };
136  typedef std::vector<struct IidInformation>::const_iterator Iterator;
137 
138  struct IidManager::IidInformation *LookupInformation (uint16_t uid) const;
139 
140  std::vector<struct IidInformation> m_information;
141 
142  typedef std::map<std::string, uint16_t> namemap_t;
143  namemap_t m_namemap;
144 
145  typedef std::map<TypeId::hash_t, uint16_t> hashmap_t;
146  hashmap_t m_hashmap;
147 
148 
149  // To handle the first collision, we reserve the high bit as a
150  // chain flag:
151  enum { HashChainFlag = 0x80000000};
152 };
153 
155 {
156  NS_LOG_FUNCTION (this);
157 }
158 
159  //static
161 IidManager::Hasher (const std::string name)
162 {
163  static ns3::Hasher hasher ( Create<Hash::Function::Murmur3> () );
164  return hasher.clear ().GetHash32 (name);
165 }
166 
167 uint16_t
168 IidManager::AllocateUid (std::string name)
169 {
170  NS_LOG_FUNCTION (this << name);
171  // Type names are definitive: equal names are equal types
172  NS_ASSERT_MSG (m_namemap.count (name) == 0,
173  "Trying to allocate twice the same uid: " << name);
174 
175  TypeId::hash_t hash = Hasher (name) & (~HashChainFlag);
176  if (m_hashmap.count (hash) == 1) {
177  NS_LOG_ERROR ("Hash chaining TypeId for '" << name << "'. "
178  << "This is not a bug, but is extremely unlikely. "
179  << "Please contact the ns3 developers.");
180  // ns3 developer contacted about this message:
181  // You have four options (in order of difficulty):
182  // 1. Let it ride, and play the odds that a third collision
183  // never appears.
184  // 2. Change the name of the new (or old) tag, even trivially, to
185  // remove the collision.
186  // 3. Switch to 64-bit hashes.
187  // 4. Implement 2-bit (or higher) chaining.
188  //
189  // Oh, by the way, I owe you a beer, since I bet Mathieu that
190  // this would never happen.. -- Peter Barnes, LLNL
191 
192  NS_ASSERT_MSG (m_hashmap.count (hash | HashChainFlag) == 0,
193  "Triplicate hash detected while chaining TypeId for '"
194  << name
195  << "'. Please contact the ns3 developers for assistance.");
196  // ns3 developer contacted about this message:
197  // You have three options: #2-4 above.
198  //
199  // Oh, by the way, I have no idea how this crazy hashing idea got
200  // into ns3. -- Peter Barnes, LLNL
201 
202  // Alphabetize the two types, so it's deterministic
203  struct IidInformation * hinfo = LookupInformation (GetUid (hash));
204  if (name > hinfo->name)
205  { // new type gets chained
206  NS_LOG_LOGIC ("New TypeId '" << name << "' getting chained.");
207  hash = hash | HashChainFlag;
208  }
209  else
210  { // chain old type
211  NS_LOG_LOGIC ("Old TypeId '" << hinfo->name << "' getting chained.");
212  uint32_t oldUid = GetUid (hinfo->hash);
213  m_hashmap.erase (m_hashmap.find (hinfo->hash));
214  hinfo->hash = hash | HashChainFlag;
215  m_hashmap.insert (std::make_pair (hinfo->hash, oldUid));
216  // leave new hash unchained
217  }
218  }
219 
220  struct IidInformation information;
221  information.name = name;
222  information.hash = hash;
223  information.parent = 0;
224  information.groupName = "";
225  information.size = (std::size_t)(-1);
226  information.hasConstructor = false;
227  information.mustHideFromDocumentation = false;
228  m_information.push_back (information);
229  uint32_t uid = m_information.size ();
230  NS_ASSERT (uid <= 0xffff);
231 
232  // Add to both maps:
233  m_namemap.insert (std::make_pair (name, uid));
234  m_hashmap.insert (std::make_pair (hash, uid));
235  return uid;
236 }
237 
239 IidManager::LookupInformation (uint16_t uid) const
240 {
241  NS_LOG_FUNCTION (this << uid);
242  NS_ASSERT (uid <= m_information.size () && uid != 0);
243  return const_cast<struct IidInformation *> (&m_information[uid-1]);
244 }
245 
246 void
247 IidManager::SetParent (uint16_t uid, uint16_t parent)
248 {
249  NS_LOG_FUNCTION (this << uid << parent);
250  NS_ASSERT (parent <= m_information.size ());
251  struct IidInformation *information = LookupInformation (uid);
252  information->parent = parent;
253 }
254 void
255 IidManager::SetGroupName (uint16_t uid, std::string groupName)
256 {
257  NS_LOG_FUNCTION (this << uid << groupName);
258  struct IidInformation *information = LookupInformation (uid);
259  information->groupName = groupName;
260 }
261 void
262 IidManager::SetSize (uint16_t uid, std::size_t size)
263 {
264  NS_LOG_FUNCTION (this << uid << size);
265  struct IidInformation *information = LookupInformation (uid);
266  information->size = size;
267 }
268 void
270 {
271  NS_LOG_FUNCTION (this << uid);
272  struct IidInformation *information = LookupInformation (uid);
273  information->mustHideFromDocumentation = true;
274 }
275 
276 void
278 {
279  NS_LOG_FUNCTION (this << uid << &callback);
280  struct IidInformation *information = LookupInformation (uid);
281  if (information->hasConstructor)
282  {
283  NS_FATAL_ERROR (information->name<<" already has a constructor.");
284  }
285  information->hasConstructor = true;
286  information->constructor = callback;
287 }
288 
289 uint16_t
290 IidManager::GetUid (std::string name) const
291 {
292  NS_LOG_FUNCTION (this << name);
293  namemap_t::const_iterator it = m_namemap.find (name);
294  if (it != m_namemap.end ())
295  {
296  return it->second;
297  }
298  else
299  {
300  return 0;
301  }
302 }
303 uint16_t
305 {
306  hashmap_t::const_iterator it = m_hashmap.find (hash);
307  if (it != m_hashmap.end ())
308  {
309  return it->second;
310  }
311  else
312  { // hash not found
313  return 0;
314  }
315 }
316 std::string
317 IidManager::GetName (uint16_t uid) const
318 {
319  NS_LOG_FUNCTION (this << uid);
320  struct IidInformation *information = LookupInformation (uid);
321  return information->name;
322 }
324 IidManager::GetHash (uint16_t uid) const
325 {
326  NS_LOG_FUNCTION (this << uid);
327  struct IidInformation *information = LookupInformation (uid);
328  return information->hash;
329 }
330 uint16_t
331 IidManager::GetParent (uint16_t uid) const
332 {
333  NS_LOG_FUNCTION (this << uid);
334  struct IidInformation *information = LookupInformation (uid);
335  return information->parent;
336 }
337 std::string
338 IidManager::GetGroupName (uint16_t uid) const
339 {
340  NS_LOG_FUNCTION (this << uid);
341  struct IidInformation *information = LookupInformation (uid);
342  return information->groupName;
343 }
344 std::size_t
345 IidManager::GetSize (uint16_t uid) const
346 {
347  NS_LOG_FUNCTION (this << uid);
348  struct IidInformation *information = LookupInformation (uid);
349  return information->size;
350 }
351 
353 IidManager::GetConstructor (uint16_t uid) const
354 {
355  NS_LOG_FUNCTION (this << uid);
356  struct IidInformation *information = LookupInformation (uid);
357  if (!information->hasConstructor)
358  {
359  NS_FATAL_ERROR ("Requested constructor for "<<information->name<<" but it does not have one.");
360  }
361  return information->constructor;
362 }
363 
364 bool
365 IidManager::HasConstructor (uint16_t uid) const
366 {
367  NS_LOG_FUNCTION (this << uid);
368  struct IidInformation *information = LookupInformation (uid);
369  return information->hasConstructor;
370 }
371 
372 uint32_t
374 {
375  NS_LOG_FUNCTION (this);
376  return m_information.size ();
377 }
378 uint16_t
379 IidManager::GetRegistered (uint32_t i) const
380 {
381  NS_LOG_FUNCTION (this << i);
382  return i + 1;
383 }
384 
385 bool
387  std::string name)
388 {
389  NS_LOG_FUNCTION (this << uid << name);
390  struct IidInformation *information = LookupInformation (uid);
391  while (true)
392  {
393  for (std::vector<struct TypeId::AttributeInformation>::const_iterator i = information->attributes.begin ();
394  i != information->attributes.end (); ++i)
395  {
396  if (i->name == name)
397  {
398  return true;
399  }
400  }
401  struct IidInformation *parent = LookupInformation (information->parent);
402  if (parent == information)
403  {
404  // top of inheritance tree
405  return false;
406  }
407  // check parent
408  information = parent;
409  }
410  return false;
411 }
412 
413 void
415  std::string name,
416  std::string help,
417  uint32_t flags,
418  Ptr<const AttributeValue> initialValue,
421 {
422  NS_LOG_FUNCTION (this << uid << name << help << flags << initialValue << accessor << checker);
423  struct IidInformation *information = LookupInformation (uid);
424  if (HasAttribute (uid, name))
425  {
426  NS_FATAL_ERROR ("Attribute \"" << name << "\" already registered on tid=\"" <<
427  information->name << "\"");
428  }
429  struct TypeId::AttributeInformation info;
430  info.name = name;
431  info.help = help;
432  info.flags = flags;
433  info.initialValue = initialValue;
434  info.originalInitialValue = initialValue;
435  info.accessor = accessor;
436  info.checker = checker;
437  information->attributes.push_back (info);
438 }
439 void
441  uint32_t i,
442  Ptr<const AttributeValue> initialValue)
443 {
444  NS_LOG_FUNCTION (this << uid << i << initialValue);
445  struct IidInformation *information = LookupInformation (uid);
446  NS_ASSERT (i < information->attributes.size ());
447  information->attributes[i].initialValue = initialValue;
448 }
449 
450 
451 
452 uint32_t
453 IidManager::GetAttributeN (uint16_t uid) const
454 {
455  NS_LOG_FUNCTION (this << uid);
456  struct IidInformation *information = LookupInformation (uid);
457  return information->attributes.size ();
458 }
460 IidManager::GetAttribute(uint16_t uid, uint32_t i) const
461 {
462  NS_LOG_FUNCTION (this << uid << i);
463  struct IidInformation *information = LookupInformation (uid);
464  NS_ASSERT (i < information->attributes.size ());
465  return information->attributes[i];
466 }
467 
468 bool
470  std::string name)
471 {
472  NS_LOG_FUNCTION (this << uid << name);
473  struct IidInformation *information = LookupInformation (uid);
474  while (true)
475  {
476  for (std::vector<struct TypeId::TraceSourceInformation>::const_iterator i = information->traceSources.begin ();
477  i != information->traceSources.end (); ++i)
478  {
479  if (i->name == name)
480  {
481  return true;
482  }
483  }
484  struct IidInformation *parent = LookupInformation (information->parent);
485  if (parent == information)
486  {
487  // top of inheritance tree
488  return false;
489  }
490  // check parent
491  information = parent;
492  }
493  return false;
494 }
495 
496 void
498  std::string name,
499  std::string help,
501  std::string callback)
502 {
503  NS_LOG_FUNCTION (this << uid << name << help << accessor);
504  struct IidInformation *information = LookupInformation (uid);
505  if (HasTraceSource (uid, name))
506  {
507  NS_FATAL_ERROR ("Trace source \"" << name << "\" already registered on tid=\"" <<
508  information->name << "\"");
509  }
510  struct TypeId::TraceSourceInformation source;
511  source.name = name;
512  source.help = help;
513  source.accessor = accessor;
514  source.callback = callback;
515  information->traceSources.push_back (source);
516 }
517 uint32_t
518 IidManager::GetTraceSourceN (uint16_t uid) const
519 {
520  NS_LOG_FUNCTION (this << uid);
521  struct IidInformation *information = LookupInformation (uid);
522  return information->traceSources.size ();
523 }
525 IidManager::GetTraceSource(uint16_t uid, uint32_t i) const
526 {
527  NS_LOG_FUNCTION (this << uid << i);
528  struct IidInformation *information = LookupInformation (uid);
529  NS_ASSERT (i < information->traceSources.size ());
530  return information->traceSources[i];
531 }
532 bool
534 {
535  NS_LOG_FUNCTION (this << uid);
536  struct IidInformation *information = LookupInformation (uid);
537  return information->mustHideFromDocumentation;
538 }
539 
540 } // namespace ns3
541 
542 namespace ns3 {
543 
544 /*********************************************************************
545  * The TypeId class
546  *********************************************************************/
547 
548 TypeId::TypeId (const char *name)
549 {
550  NS_LOG_FUNCTION (this << name);
551  uint16_t uid = Singleton<IidManager>::Get ()->AllocateUid (name);
552  NS_ASSERT (uid != 0);
553  m_tid = uid;
554 }
555 
556 
557 TypeId::TypeId (uint16_t tid)
558  : m_tid (tid)
559 {
560  NS_LOG_FUNCTION (this << tid);
561 }
562 TypeId
563 TypeId::LookupByName (std::string name)
564 {
565  NS_LOG_FUNCTION (name);
566  uint16_t uid = Singleton<IidManager>::Get ()->GetUid (name);
567  NS_ASSERT_MSG (uid != 0, "Assert in TypeId::LookupByName: " << name << " not found");
568  return TypeId (uid);
569 }
570 bool
571 TypeId::LookupByNameFailSafe (std::string name, TypeId *tid)
572 {
573  NS_LOG_FUNCTION (name << tid);
574  uint16_t uid = Singleton<IidManager>::Get ()->GetUid (name);
575  if (uid == 0)
576  {
577  return false;
578  }
579  *tid = TypeId (uid);
580  return true;
581 }
582 TypeId
584 {
585  uint16_t uid = Singleton<IidManager>::Get ()->GetUid (hash);
586  NS_ASSERT_MSG (uid != 0, "Assert in TypeId::LookupByHash: 0x"
587  << std::hex << hash << std::dec << " not found");
588  return TypeId (uid);
589 }
590 bool
592 {
593  uint16_t uid = Singleton<IidManager>::Get ()->GetUid (hash);
594  if (uid == 0)
595  {
596  return false;
597  }
598  *tid = TypeId (uid);
599  return true;
600 }
601 
602 uint32_t
604 {
606  return Singleton<IidManager>::Get ()->GetRegisteredN ();
607 }
608 TypeId
610 {
611  NS_LOG_FUNCTION (i);
613 }
614 
615 bool
616 TypeId::LookupAttributeByName (std::string name, struct TypeId::AttributeInformation *info) const
617 {
618  NS_LOG_FUNCTION (this << name << info);
619  TypeId tid;
620  TypeId nextTid = *this;
621  do {
622  tid = nextTid;
623  for (uint32_t i = 0; i < tid.GetAttributeN (); i++)
624  {
625  struct TypeId::AttributeInformation tmp = tid.GetAttribute(i);
626  if (tmp.name == name)
627  {
628  *info = tmp;
629  return true;
630  }
631  }
632  nextTid = tid.GetParent ();
633  } while (nextTid != tid);
634  return false;
635 }
636 
637 TypeId
639 {
640  NS_LOG_FUNCTION (this << tid);
641  Singleton<IidManager>::Get ()->SetParent (m_tid, tid.m_tid);
642  return *this;
643 }
644 TypeId
645 TypeId::SetGroupName (std::string groupName)
646 {
647  NS_LOG_FUNCTION (this << groupName);
648  Singleton<IidManager>::Get ()->SetGroupName (m_tid, groupName);
649  return *this;
650 }
651 TypeId
652 TypeId::SetSize (std::size_t size)
653 {
654  NS_LOG_FUNCTION (this << size);
655  Singleton<IidManager>::Get ()->SetSize (m_tid, size);
656  return *this;
657 }
658 TypeId
659 TypeId::GetParent (void) const
660 {
661  NS_LOG_FUNCTION (this);
662  uint16_t parent = Singleton<IidManager>::Get ()->GetParent (m_tid);
663  return TypeId (parent);
664 }
665 bool
666 TypeId::HasParent (void) const
667 {
668  NS_LOG_FUNCTION (this);
669  uint16_t parent = Singleton<IidManager>::Get ()->GetParent (m_tid);
670  return parent != m_tid;
671 }
672 bool
674 {
675  NS_LOG_FUNCTION (this << other);
676  TypeId tmp = *this;
677  while (tmp != other && tmp != tmp.GetParent ())
678  {
679  tmp = tmp.GetParent ();
680  }
681  return tmp == other && *this != other;
682 }
683 std::string
685 {
686  NS_LOG_FUNCTION (this);
687  std::string groupName = Singleton<IidManager>::Get ()->GetGroupName (m_tid);
688  return groupName;
689 }
690 
691 std::string
692 TypeId::GetName (void) const
693 {
694  NS_LOG_FUNCTION (this);
695  std::string name = Singleton<IidManager>::Get ()->GetName (m_tid);
696  return name;
697 }
698 
700 TypeId::GetHash (void) const
701 {
702  hash_t hash = Singleton<IidManager>::Get ()->GetHash (m_tid);
703  return hash;
704 }
705 std::size_t
706 TypeId::GetSize (void) const
707 {
708  NS_LOG_FUNCTION (this);
709  std::size_t size = Singleton<IidManager>::Get ()->GetSize (m_tid);
710  return size;
711 }
712 
713 bool
715 {
716  NS_LOG_FUNCTION (this);
717  bool hasConstructor = Singleton<IidManager>::Get ()->HasConstructor (m_tid);
718  return hasConstructor;
719 }
720 
721 void
723 {
724  NS_LOG_FUNCTION (this << &cb);
725  Singleton<IidManager>::Get ()->AddConstructor (m_tid, cb);
726 }
727 
728 TypeId
729 TypeId::AddAttribute (std::string name,
730  std::string help,
731  const AttributeValue &initialValue,
734 {
735  NS_LOG_FUNCTION (this << name << help << &initialValue << accessor << checker);
736  Singleton<IidManager>::Get ()->AddAttribute (m_tid, name, help, ATTR_SGC, initialValue.Copy (), accessor, checker);
737  return *this;
738 }
739 
740 TypeId
741 TypeId::AddAttribute (std::string name,
742  std::string help,
743  uint32_t flags,
744  const AttributeValue &initialValue,
747 {
748  NS_LOG_FUNCTION (this << name << help << flags << &initialValue << accessor << checker);
749  Singleton<IidManager>::Get ()->AddAttribute (m_tid, name, help, flags, initialValue.Copy (), accessor, checker);
750  return *this;
751 }
752 
753 bool
755  Ptr<const AttributeValue> initialValue)
756 {
757  NS_LOG_FUNCTION (this << i << initialValue);
758  Singleton<IidManager>::Get ()->SetAttributeInitialValue (m_tid, i, initialValue);
759  return true;
760 }
761 
762 
765 {
766  NS_LOG_FUNCTION (this);
767  Callback<ObjectBase *> cb = Singleton<IidManager>::Get ()->GetConstructor (m_tid);
768  return cb;
769 }
770 
771 bool
773 {
774  NS_LOG_FUNCTION (this);
775  bool mustHide = Singleton<IidManager>::Get ()->MustHideFromDocumentation (m_tid);
776  return mustHide;
777 }
778 
779 uint32_t
781 {
782  NS_LOG_FUNCTION (this);
783  uint32_t n = Singleton<IidManager>::Get ()->GetAttributeN (m_tid);
784  return n;
785 }
787 TypeId::GetAttribute(uint32_t i) const
788 {
789  NS_LOG_FUNCTION (this << i);
790  return Singleton<IidManager>::Get ()->GetAttribute(m_tid, i);
791 }
792 std::string
794 {
795  NS_LOG_FUNCTION (this << i);
797  return GetName () + "::" + info.name;
798 }
799 
800 uint32_t
802 {
803  NS_LOG_FUNCTION (this);
804  return Singleton<IidManager>::Get ()->GetTraceSourceN (m_tid);
805 }
807 TypeId::GetTraceSource(uint32_t i) const
808 {
809  NS_LOG_FUNCTION (this << i);
810  return Singleton<IidManager>::Get ()->GetTraceSource(m_tid, i);
811 }
812 
813 TypeId
814 TypeId::AddTraceSource (std::string name,
815  std::string help,
817 {
818  return AddTraceSource (name, help, accessor, "(not yet documented)");
819 }
820 
821 TypeId
822 TypeId::AddTraceSource (std::string name,
823  std::string help,
825  std::string callback)
826 {
827  NS_LOG_FUNCTION (this << name << help << accessor);
828  Singleton<IidManager>::Get ()->AddTraceSource (m_tid, name, help, accessor, callback);
829  return *this;
830 }
831 
832 TypeId
834 {
835  NS_LOG_FUNCTION (this);
836  Singleton<IidManager>::Get ()->HideFromDocumentation (m_tid);
837  return *this;
838 }
839 
840 
842 TypeId::LookupTraceSourceByName (std::string name) const
843 {
844  NS_LOG_FUNCTION (this << name);
845  TypeId tid;
846  TypeId nextTid = *this;
847  do {
848  tid = nextTid;
849  for (uint32_t i = 0; i < tid.GetTraceSourceN (); i++)
850  {
851  struct TypeId::TraceSourceInformation info = tid.GetTraceSource (i);
852  if (info.name == name)
853  {
854  return info.accessor;
855  }
856  }
857  nextTid = tid.GetParent ();
858  } while (nextTid != tid);
859  return 0;
860 }
861 
862 uint16_t
863 TypeId::GetUid (void) const
864 {
865  NS_LOG_FUNCTION (this);
866  return m_tid;
867 }
868 void
869 TypeId::SetUid (uint16_t tid)
870 {
871  NS_LOG_FUNCTION (this << tid);
872  m_tid = tid;
873 }
874 
875 std::ostream & operator << (std::ostream &os, TypeId tid)
876 {
877  os << tid.GetName ();
878  return os;
879 }
880 std::istream & operator >> (std::istream &is, TypeId &tid)
881 {
882  std::string tidString;
883  is >> tidString;
884  bool ok = TypeId::LookupByNameFailSafe (tidString, &tid);
885  if (!ok)
886  {
887  is.setstate (std::ios_base::badbit);
888  }
889  return is;
890 }
891 
892 
894 
896 {
897  return a.m_tid < b.m_tid;
898 }
899 
900 } // namespace ns3
std::vector< struct TypeId::TraceSourceInformation > traceSources
Definition: type-id.cc:134
uint32_t GetAttributeN(void) const
Definition: type-id.cc:780
static TypeId::hash_t Hasher(const std::string name)
Definition: type-id.cc:161
uint32_t hash_t
Type of hash values.
Definition: type-id.h:88
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
TypeId AddTraceSource(std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor) NS_DEPRECATED
Definition: type-id.cc:814
bool HasAttribute(uint16_t uid, std::string name)
Definition: type-id.cc:386
Callback< ObjectBase * > GetConstructor(uint16_t uid) const
Definition: type-id.cc:353
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#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.
Callback template class.
Definition: callback.h:984
bool HasTraceSource(uint16_t uid, std::string name)
Definition: type-id.cc:469
TypeId SetParent(void)
Definition: type-id.h:453
std::vector< struct IidInformation > m_information
Definition: type-id.cc:140
std::string GetGroupName(uint16_t uid) const
Definition: type-id.cc:338
static TypeId LookupByHash(hash_t hash)
Definition: type-id.cc:583
hashmap_t m_hashmap
Definition: type-id.cc:146
namemap_t m_namemap
Definition: type-id.cc:143
std::map< TypeId::hash_t, uint16_t > hashmap_t
Definition: type-id.cc:145
Hold a value for an Attribute.
Definition: attribute.h:68
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
Ptr< const AttributeValue > originalInitialValue
Definition: type-id.h:73
Ptr< const TraceSourceAccessor > accessor
Definition: type-id.h:82
void SetGroupName(uint16_t uid, std::string groupName)
Definition: type-id.cc:255
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
TypeId GetParent(void) const
Definition: type-id.cc:659
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Definition: type-id.cc:571
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
void AddTraceSource(uint16_t uid, std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor, std::string callback)
Definition: type-id.cc:497
uint32_t GetRegisteredN(void) const
Definition: type-id.cc:373
ns3::Hasher, ns3::Hash32() and ns3::Hash64() function declarations.
The attribute can be read, and written at any time.
Definition: type-id.h:67
static T * Get(void)
Get a pointer to the singleton instance.
Definition: singleton.h:97
Callback< ObjectBase * > GetConstructor(void) const
Definition: type-id.cc:764
static bool LookupByHashFailSafe(hash_t hash, TypeId *tid)
Definition: type-id.cc:591
bool HasConstructor(void) const
Definition: type-id.cc:714
bool MustHideFromDocumentation(void) const
Definition: type-id.cc:772
A template singleton.
Definition: singleton.h:49
TypeId information manager.
Definition: type-id.cc:77
Ptr< const AttributeAccessor > accessor
Definition: type-id.h:75
static uint32_t GetRegisteredN(void)
Definition: type-id.cc:603
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Definition: type-id.cc:842
uint32_t GetAttributeN(uint16_t uid) const
Definition: type-id.cc:453
Ptr< const AttributeValue > initialValue
Definition: type-id.h:74
uint16_t m_tid
Definition: type-id.h:407
bool HasParent(void) const
Definition: type-id.cc:666
uint32_t GetHash32(const char *buffer, const size_t size)
Compute 32-bit hash of a byte buffer.
Definition: hash.h:239
uint32_t GetTraceSourceN(void) const
Definition: type-id.cc:801
static TypeId GetRegistered(uint32_t i)
Definition: type-id.cc:609
uint32_t GetTraceSourceN(uint16_t uid) const
Definition: type-id.cc:518
void AddAttribute(uint16_t uid, std::string name, std::string help, uint32_t flags, Ptr< const AttributeValue > initialValue, Ptr< const AttributeAccessor > spec, Ptr< const AttributeChecker > checker)
Definition: type-id.cc:414
void SetAttributeInitialValue(uint16_t uid, uint32_t i, Ptr< const AttributeValue > initialValue)
Definition: type-id.cc:440
std::vector< struct TypeId::AttributeInformation > attributes
Definition: type-id.cc:133
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
void HideFromDocumentation(uint16_t uid)
Definition: type-id.cc:269
bool MustHideFromDocumentation(uint16_t uid) const
Definition: type-id.cc:533
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:356
TypeId SetGroupName(std::string groupName)
Definition: type-id.cc:645
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
TypeId AddAttribute(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeAccessor > accessor, Ptr< const AttributeChecker > checker)
Definition: type-id.cc:729
Ptr< const AttributeChecker > checker
Definition: type-id.h:76
virtual Ptr< AttributeValue > Copy(void) const =0
Hasher & clear(void)
Restore initial state.
Definition: hash.cc:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetUid(uint16_t tid)
Definition: type-id.cc:869
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Definition: type-id.cc:616
ns3::TraceSourceAccessor and ns3::MakeTraceSourceAccessor declarations.
ns3::TypeId declaration; inline and template implementations.
std::map< std::string, uint16_t > namemap_t
Definition: type-id.cc:142
uint16_t GetRegistered(uint32_t i) const
Definition: type-id.cc:379
std::string GetName(void) const
Definition: type-id.cc:692
uint16_t GetUid(void) const
Definition: type-id.cc:863
void DoAddConstructor(Callback< ObjectBase * > callback)
Definition: type-id.cc:722
hash_t GetHash(void) const
Definition: type-id.cc:700
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
bool SetAttributeInitialValue(uint32_t i, Ptr< const AttributeValue > initialValue)
Definition: type-id.cc:754
uint16_t AllocateUid(std::string name)
Definition: type-id.cc:168
void SetParent(uint16_t uid, uint16_t parent)
Definition: type-id.cc:247
std::size_t GetSize(void) const
Definition: type-id.cc:706
uint16_t GetParent(uint16_t uid) const
Definition: type-id.cc:331
void SetSize(uint16_t uid, std::size_t size)
Definition: type-id.cc:262
TypeId SetSize(std::size_t size)
Set the size of this type, based on the sizeof operator.
Definition: type-id.cc:652
std::string GetName(uint16_t uid) const
Definition: type-id.cc:317
TypeId::hash_t GetHash(uint16_t uid) const
Definition: type-id.cc:324
std::string GetAttributeFullName(uint32_t i) const
Definition: type-id.cc:793
bool HasConstructor(uint16_t uid) const
Definition: type-id.cc:365
bool IsChildOf(TypeId other) const
Definition: type-id.cc:673
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:220
Callback< ObjectBase * > constructor
Definition: type-id.cc:131
struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const
Definition: type-id.cc:807
std::string GetGroupName(void) const
Definition: type-id.cc:684
struct IidManager::IidInformation * LookupInformation(uint16_t uid) const
Definition: type-id.cc:239
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
Definition: type-id.cc:787
Debug message logging.
void AddConstructor(uint16_t uid, Callback< ObjectBase * > callback)
Definition: type-id.cc:277
a unique identifier for an interface.
Definition: type-id.h:57
std::vector< struct IidInformation >::const_iterator Iterator
Definition: type-id.cc:136
std::size_t GetSize(uint16_t uid) const
Definition: type-id.cc:345
Generic Hash function interface.
Definition: hash.h:87
TypeId HideFromDocumentation(void)
Definition: type-id.cc:833
static TypeId LookupByName(std::string name)
Definition: type-id.cc:563
uint16_t GetUid(std::string name) const
Definition: type-id.cc:290