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 class IidManager : public Singleton<IidManager>
79 {
80 public:
86  uint16_t AllocateUid (std::string name);
92  void SetParent (uint16_t uid, uint16_t parent);
98  void SetGroupName (uint16_t uid, std::string groupName);
104  void SetSize (uint16_t uid, std::size_t size);
110  void AddConstructor (uint16_t uid, Callback<ObjectBase *> callback);
115  void HideFromDocumentation (uint16_t uid);
121  uint16_t GetUid (std::string name) const;
127  uint16_t GetUid (TypeId::hash_t hash) const;
133  std::string GetName (uint16_t uid) const;
139  TypeId::hash_t GetHash (uint16_t uid) const;
145  uint16_t GetParent (uint16_t uid) const;
151  std::string GetGroupName (uint16_t uid) const;
157  std::size_t GetSize (uint16_t uid) const;
163  Callback<ObjectBase *> GetConstructor (uint16_t uid) const;
169  bool HasConstructor (uint16_t uid) const;
174  uint32_t GetRegisteredN (void) const;
184  uint16_t GetRegistered (uint32_t i) const;
199  void AddAttribute (uint16_t uid,
200  std::string name,
201  std::string help,
202  uint32_t flags,
203  Ptr<const AttributeValue> initialValue,
212  void SetAttributeInitialValue(uint16_t uid,
213  uint32_t i,
214  Ptr<const AttributeValue> initialValue);
220  uint32_t GetAttributeN (uint16_t uid) const;
227  struct TypeId::AttributeInformation GetAttribute(uint16_t uid, uint32_t i) const;
241  void AddTraceSource (uint16_t uid,
242  std::string name,
243  std::string help,
245  std::string callback);
251  uint32_t GetTraceSourceN (uint16_t uid) const;
258  struct TypeId::TraceSourceInformation GetTraceSource(uint16_t uid, uint32_t i) const;
264  bool MustHideFromDocumentation (uint16_t uid) const;
265 
266 private:
273  bool HasTraceSource (uint16_t uid, std::string name);
280  bool HasAttribute (uint16_t uid, std::string name);
286  static TypeId::hash_t Hasher (const std::string name);
287 
289  struct IidInformation {
291  std::string name;
295  uint16_t parent;
297  std::string groupName;
299  std::size_t size;
307  std::vector<struct TypeId::AttributeInformation> attributes;
309  std::vector<struct TypeId::TraceSourceInformation> traceSources;
310  };
312  typedef std::vector<struct IidInformation>::const_iterator Iterator;
313 
319  struct IidManager::IidInformation *LookupInformation (uint16_t uid) const;
320 
322  std::vector<struct IidInformation> m_information;
323 
325  typedef std::map<std::string, uint16_t> namemap_t;
327  namemap_t m_namemap;
328 
330  typedef std::map<TypeId::hash_t, uint16_t> hashmap_t;
332  hashmap_t m_hashmap;
333 
334 
335  enum {
342  HashChainFlag = 0x80000000
343  };
344 };
345 
346 
347 //static
349 IidManager::Hasher (const std::string name)
350 {
351  static ns3::Hasher hasher ( Create<Hash::Function::Murmur3> () );
352  return hasher.clear ().GetHash32 (name);
353 }
354 
355 uint16_t
356 IidManager::AllocateUid (std::string name)
357 {
358  NS_LOG_FUNCTION (this << name);
359  // Type names are definitive: equal names are equal types
360  NS_ASSERT_MSG (m_namemap.count (name) == 0,
361  "Trying to allocate twice the same uid: " << name);
362 
363  TypeId::hash_t hash = Hasher (name) & (~HashChainFlag);
364  if (m_hashmap.count (hash) == 1) {
365  NS_LOG_ERROR ("Hash chaining TypeId for '" << name << "'. "
366  << "This is not a bug, but is extremely unlikely. "
367  << "Please contact the ns3 developers.");
368  // ns3 developer contacted about this message:
369  // You have four options (in order of difficulty):
370  // 1. Let it ride, and play the odds that a third collision
371  // never appears.
372  // 2. Change the name of the new (or old) tag, even trivially, to
373  // remove the collision.
374  // 3. Switch to 64-bit hashes.
375  // 4. Implement 2-bit (or higher) chaining.
376  //
377  // Oh, by the way, I owe you a beer, since I bet Mathieu that
378  // this would never happen.. -- Peter Barnes, LLNL
379 
380  NS_ASSERT_MSG (m_hashmap.count (hash | HashChainFlag) == 0,
381  "Triplicate hash detected while chaining TypeId for '"
382  << name
383  << "'. Please contact the ns3 developers for assistance.");
384  // ns3 developer contacted about this message:
385  // You have three options: #2-4 above.
386  //
387  // Oh, by the way, I have no idea how this crazy hashing idea got
388  // into ns3. -- Peter Barnes, LLNL
389 
390  // Alphabetize the two types, so it's deterministic
391  struct IidInformation * hinfo = LookupInformation (GetUid (hash));
392  if (name > hinfo->name)
393  { // new type gets chained
394  NS_LOG_LOGIC ("New TypeId '" << name << "' getting chained.");
395  hash = hash | HashChainFlag;
396  }
397  else
398  { // chain old type
399  NS_LOG_LOGIC ("Old TypeId '" << hinfo->name << "' getting chained.");
400  uint32_t oldUid = GetUid (hinfo->hash);
401  m_hashmap.erase (m_hashmap.find (hinfo->hash));
402  hinfo->hash = hash | HashChainFlag;
403  m_hashmap.insert (std::make_pair (hinfo->hash, oldUid));
404  // leave new hash unchained
405  }
406  }
407 
408  struct IidInformation information;
409  information.name = name;
410  information.hash = hash;
411  information.parent = 0;
412  information.groupName = "";
413  information.size = (std::size_t)(-1);
414  information.hasConstructor = false;
415  information.mustHideFromDocumentation = false;
416  m_information.push_back (information);
417  uint32_t uid = m_information.size ();
418  NS_ASSERT (uid <= 0xffff);
419 
420  // Add to both maps:
421  m_namemap.insert (std::make_pair (name, uid));
422  m_hashmap.insert (std::make_pair (hash, uid));
423  return uid;
424 }
425 
427 IidManager::LookupInformation (uint16_t uid) const
428 {
429  NS_LOG_FUNCTION (this << uid);
430  NS_ASSERT (uid <= m_information.size () && uid != 0);
431  return const_cast<struct IidInformation *> (&m_information[uid-1]);
432 }
433 
434 void
435 IidManager::SetParent (uint16_t uid, uint16_t parent)
436 {
437  NS_LOG_FUNCTION (this << uid << parent);
438  NS_ASSERT (parent <= m_information.size ());
439  struct IidInformation *information = LookupInformation (uid);
440  information->parent = parent;
441 }
442 void
443 IidManager::SetGroupName (uint16_t uid, std::string groupName)
444 {
445  NS_LOG_FUNCTION (this << uid << groupName);
446  struct IidInformation *information = LookupInformation (uid);
447  information->groupName = groupName;
448 }
449 void
450 IidManager::SetSize (uint16_t uid, std::size_t size)
451 {
452  NS_LOG_FUNCTION (this << uid << size);
453  struct IidInformation *information = LookupInformation (uid);
454  information->size = size;
455 }
456 void
458 {
459  NS_LOG_FUNCTION (this << uid);
460  struct IidInformation *information = LookupInformation (uid);
461  information->mustHideFromDocumentation = true;
462 }
463 
464 void
466 {
467  NS_LOG_FUNCTION (this << uid << &callback);
468  struct IidInformation *information = LookupInformation (uid);
469  if (information->hasConstructor)
470  {
471  NS_FATAL_ERROR (information->name<<" already has a constructor.");
472  }
473  information->hasConstructor = true;
474  information->constructor = callback;
475 }
476 
477 uint16_t
478 IidManager::GetUid (std::string name) const
479 {
480  NS_LOG_FUNCTION (this << name);
481  namemap_t::const_iterator it = m_namemap.find (name);
482  if (it != m_namemap.end ())
483  {
484  return it->second;
485  }
486  else
487  {
488  return 0;
489  }
490 }
491 uint16_t
493 {
494  hashmap_t::const_iterator it = m_hashmap.find (hash);
495  if (it != m_hashmap.end ())
496  {
497  return it->second;
498  }
499  else
500  { // hash not found
501  return 0;
502  }
503 }
504 std::string
505 IidManager::GetName (uint16_t uid) const
506 {
507  NS_LOG_FUNCTION (this << uid);
508  struct IidInformation *information = LookupInformation (uid);
509  return information->name;
510 }
512 IidManager::GetHash (uint16_t uid) const
513 {
514  NS_LOG_FUNCTION (this << uid);
515  struct IidInformation *information = LookupInformation (uid);
516  return information->hash;
517 }
518 uint16_t
519 IidManager::GetParent (uint16_t uid) const
520 {
521  NS_LOG_FUNCTION (this << uid);
522  struct IidInformation *information = LookupInformation (uid);
523  return information->parent;
524 }
525 std::string
526 IidManager::GetGroupName (uint16_t uid) const
527 {
528  NS_LOG_FUNCTION (this << uid);
529  struct IidInformation *information = LookupInformation (uid);
530  return information->groupName;
531 }
532 std::size_t
533 IidManager::GetSize (uint16_t uid) const
534 {
535  NS_LOG_FUNCTION (this << uid);
536  struct IidInformation *information = LookupInformation (uid);
537  return information->size;
538 }
539 
541 IidManager::GetConstructor (uint16_t uid) const
542 {
543  NS_LOG_FUNCTION (this << uid);
544  struct IidInformation *information = LookupInformation (uid);
545  if (!information->hasConstructor)
546  {
547  NS_FATAL_ERROR ("Requested constructor for "<<information->name<<" but it does not have one.");
548  }
549  return information->constructor;
550 }
551 
552 bool
553 IidManager::HasConstructor (uint16_t uid) const
554 {
555  NS_LOG_FUNCTION (this << uid);
556  struct IidInformation *information = LookupInformation (uid);
557  return information->hasConstructor;
558 }
559 
560 uint32_t
562 {
563  NS_LOG_FUNCTION (this);
564  return m_information.size ();
565 }
566 uint16_t
567 IidManager::GetRegistered (uint32_t i) const
568 {
569  NS_LOG_FUNCTION (this << i);
570  return i + 1;
571 }
572 
573 bool
575  std::string name)
576 {
577  NS_LOG_FUNCTION (this << uid << name);
578  struct IidInformation *information = LookupInformation (uid);
579  while (true)
580  {
581  for (std::vector<struct TypeId::AttributeInformation>::const_iterator i = information->attributes.begin ();
582  i != information->attributes.end (); ++i)
583  {
584  if (i->name == name)
585  {
586  return true;
587  }
588  }
589  struct IidInformation *parent = LookupInformation (information->parent);
590  if (parent == information)
591  {
592  // top of inheritance tree
593  return false;
594  }
595  // check parent
596  information = parent;
597  }
598  return false;
599 }
600 
601 void
603  std::string name,
604  std::string help,
605  uint32_t flags,
606  Ptr<const AttributeValue> initialValue,
609 {
610  NS_LOG_FUNCTION (this << uid << name << help << flags << initialValue << accessor << checker);
611  struct IidInformation *information = LookupInformation (uid);
612  if (HasAttribute (uid, name))
613  {
614  NS_FATAL_ERROR ("Attribute \"" << name << "\" already registered on tid=\"" <<
615  information->name << "\"");
616  }
617  struct TypeId::AttributeInformation info;
618  info.name = name;
619  info.help = help;
620  info.flags = flags;
621  info.initialValue = initialValue;
622  info.originalInitialValue = initialValue;
623  info.accessor = accessor;
624  info.checker = checker;
625  information->attributes.push_back (info);
626 }
627 void
629  uint32_t i,
630  Ptr<const AttributeValue> initialValue)
631 {
632  NS_LOG_FUNCTION (this << uid << i << initialValue);
633  struct IidInformation *information = LookupInformation (uid);
634  NS_ASSERT (i < information->attributes.size ());
635  information->attributes[i].initialValue = initialValue;
636 }
637 
638 
639 
640 uint32_t
641 IidManager::GetAttributeN (uint16_t uid) const
642 {
643  NS_LOG_FUNCTION (this << uid);
644  struct IidInformation *information = LookupInformation (uid);
645  return information->attributes.size ();
646 }
648 IidManager::GetAttribute(uint16_t uid, uint32_t i) const
649 {
650  NS_LOG_FUNCTION (this << uid << i);
651  struct IidInformation *information = LookupInformation (uid);
652  NS_ASSERT (i < information->attributes.size ());
653  return information->attributes[i];
654 }
655 
656 bool
658  std::string name)
659 {
660  NS_LOG_FUNCTION (this << uid << name);
661  struct IidInformation *information = LookupInformation (uid);
662  while (true)
663  {
664  for (std::vector<struct TypeId::TraceSourceInformation>::const_iterator i = information->traceSources.begin ();
665  i != information->traceSources.end (); ++i)
666  {
667  if (i->name == name)
668  {
669  return true;
670  }
671  }
672  struct IidInformation *parent = LookupInformation (information->parent);
673  if (parent == information)
674  {
675  // top of inheritance tree
676  return false;
677  }
678  // check parent
679  information = parent;
680  }
681  return false;
682 }
683 
684 void
686  std::string name,
687  std::string help,
689  std::string callback)
690 {
691  NS_LOG_FUNCTION (this << uid << name << help << accessor);
692  struct IidInformation *information = LookupInformation (uid);
693  if (HasTraceSource (uid, name))
694  {
695  NS_FATAL_ERROR ("Trace source \"" << name << "\" already registered on tid=\"" <<
696  information->name << "\"");
697  }
698  struct TypeId::TraceSourceInformation source;
699  source.name = name;
700  source.help = help;
701  source.accessor = accessor;
702  source.callback = callback;
703  information->traceSources.push_back (source);
704 }
705 uint32_t
706 IidManager::GetTraceSourceN (uint16_t uid) const
707 {
708  NS_LOG_FUNCTION (this << uid);
709  struct IidInformation *information = LookupInformation (uid);
710  return information->traceSources.size ();
711 }
713 IidManager::GetTraceSource(uint16_t uid, uint32_t i) const
714 {
715  NS_LOG_FUNCTION (this << uid << i);
716  struct IidInformation *information = LookupInformation (uid);
717  NS_ASSERT (i < information->traceSources.size ());
718  return information->traceSources[i];
719 }
720 bool
722 {
723  NS_LOG_FUNCTION (this << uid);
724  struct IidInformation *information = LookupInformation (uid);
725  return information->mustHideFromDocumentation;
726 }
727 
728 } // namespace ns3
729 
730 namespace ns3 {
731 
732 /*********************************************************************
733  * The TypeId class
734  *********************************************************************/
735 
736 TypeId::TypeId (const char *name)
737 {
738  NS_LOG_FUNCTION (this << name);
739  uint16_t uid = IidManager::Get ()->AllocateUid (name);
740  NS_ASSERT (uid != 0);
741  m_tid = uid;
742 }
743 
744 
745 TypeId::TypeId (uint16_t tid)
746  : m_tid (tid)
747 {
748  NS_LOG_FUNCTION (this << tid);
749 }
750 TypeId
751 TypeId::LookupByName (std::string name)
752 {
753  NS_LOG_FUNCTION (name);
754  uint16_t uid = IidManager::Get ()->GetUid (name);
755  NS_ASSERT_MSG (uid != 0, "Assert in TypeId::LookupByName: " << name << " not found");
756  return TypeId (uid);
757 }
758 bool
759 TypeId::LookupByNameFailSafe (std::string name, TypeId *tid)
760 {
761  NS_LOG_FUNCTION (name << tid);
762  uint16_t uid = IidManager::Get ()->GetUid (name);
763  if (uid == 0)
764  {
765  return false;
766  }
767  *tid = TypeId (uid);
768  return true;
769 }
770 TypeId
772 {
773  uint16_t uid = IidManager::Get ()->GetUid (hash);
774  NS_ASSERT_MSG (uid != 0, "Assert in TypeId::LookupByHash: 0x"
775  << std::hex << hash << std::dec << " not found");
776  return TypeId (uid);
777 }
778 bool
780 {
781  uint16_t uid = IidManager::Get ()->GetUid (hash);
782  if (uid == 0)
783  {
784  return false;
785  }
786  *tid = TypeId (uid);
787  return true;
788 }
789 
790 uint32_t
792 {
794  return IidManager::Get ()->GetRegisteredN ();
795 }
796 TypeId
798 {
799  NS_LOG_FUNCTION (i);
800  return TypeId (IidManager::Get ()->GetRegistered (i));
801 }
802 
803 bool
804 TypeId::LookupAttributeByName (std::string name, struct TypeId::AttributeInformation *info) const
805 {
806  NS_LOG_FUNCTION (this << name << info);
807  TypeId tid;
808  TypeId nextTid = *this;
809  do {
810  tid = nextTid;
811  for (uint32_t i = 0; i < tid.GetAttributeN (); i++)
812  {
813  struct TypeId::AttributeInformation tmp = tid.GetAttribute(i);
814  if (tmp.name == name)
815  {
816  *info = tmp;
817  return true;
818  }
819  }
820  nextTid = tid.GetParent ();
821  } while (nextTid != tid);
822  return false;
823 }
824 
825 TypeId
827 {
828  NS_LOG_FUNCTION (this << tid);
830  return *this;
831 }
832 TypeId
833 TypeId::SetGroupName (std::string groupName)
834 {
835  NS_LOG_FUNCTION (this << groupName);
836  IidManager::Get ()->SetGroupName (m_tid, groupName);
837  return *this;
838 }
839 TypeId
840 TypeId::SetSize (std::size_t size)
841 {
842  NS_LOG_FUNCTION (this << size);
843  IidManager::Get ()->SetSize (m_tid, size);
844  return *this;
845 }
846 TypeId
847 TypeId::GetParent (void) const
848 {
849  NS_LOG_FUNCTION (this);
850  uint16_t parent = IidManager::Get ()->GetParent (m_tid);
851  return TypeId (parent);
852 }
853 bool
854 TypeId::HasParent (void) const
855 {
856  NS_LOG_FUNCTION (this);
857  uint16_t parent = IidManager::Get ()->GetParent (m_tid);
858  return parent != m_tid;
859 }
860 bool
862 {
863  NS_LOG_FUNCTION (this << other);
864  TypeId tmp = *this;
865  while (tmp != other && tmp != tmp.GetParent ())
866  {
867  tmp = tmp.GetParent ();
868  }
869  return tmp == other && *this != other;
870 }
871 std::string
873 {
874  NS_LOG_FUNCTION (this);
875  std::string groupName = IidManager::Get ()->GetGroupName (m_tid);
876  return groupName;
877 }
878 
879 std::string
880 TypeId::GetName (void) const
881 {
882  NS_LOG_FUNCTION (this);
883  std::string name = IidManager::Get ()->GetName (m_tid);
884  return name;
885 }
886 
888 TypeId::GetHash (void) const
889 {
890  hash_t hash = IidManager::Get ()->GetHash (m_tid);
891  return hash;
892 }
893 std::size_t
894 TypeId::GetSize (void) const
895 {
896  NS_LOG_FUNCTION (this);
897  std::size_t size = IidManager::Get ()->GetSize (m_tid);
898  return size;
899 }
900 
901 bool
903 {
904  NS_LOG_FUNCTION (this);
905  bool hasConstructor = IidManager::Get ()->HasConstructor (m_tid);
906  return hasConstructor;
907 }
908 
909 void
911 {
912  NS_LOG_FUNCTION (this << &cb);
914 }
915 
916 TypeId
917 TypeId::AddAttribute (std::string name,
918  std::string help,
919  const AttributeValue &initialValue,
922 {
923  NS_LOG_FUNCTION (this << name << help << &initialValue << accessor << checker);
924  IidManager::Get ()->AddAttribute (m_tid, name, help, ATTR_SGC, initialValue.Copy (), accessor, checker);
925  return *this;
926 }
927 
928 TypeId
929 TypeId::AddAttribute (std::string name,
930  std::string help,
931  uint32_t flags,
932  const AttributeValue &initialValue,
935 {
936  NS_LOG_FUNCTION (this << name << help << flags << &initialValue << accessor << checker);
937  IidManager::Get ()->AddAttribute (m_tid, name, help, flags, initialValue.Copy (), accessor, checker);
938  return *this;
939 }
940 
941 bool
943  Ptr<const AttributeValue> initialValue)
944 {
945  NS_LOG_FUNCTION (this << i << initialValue);
946  IidManager::Get ()->SetAttributeInitialValue (m_tid, i, initialValue);
947  return true;
948 }
949 
950 
953 {
954  NS_LOG_FUNCTION (this);
956  return cb;
957 }
958 
959 bool
961 {
962  NS_LOG_FUNCTION (this);
963  bool mustHide = IidManager::Get ()->MustHideFromDocumentation (m_tid);
964  return mustHide;
965 }
966 
967 uint32_t
969 {
970  NS_LOG_FUNCTION (this);
971  uint32_t n = IidManager::Get ()->GetAttributeN (m_tid);
972  return n;
973 }
975 TypeId::GetAttribute(uint32_t i) const
976 {
977  NS_LOG_FUNCTION (this << i);
978  return IidManager::Get ()->GetAttribute(m_tid, i);
979 }
980 std::string
982 {
983  NS_LOG_FUNCTION (this << i);
985  return GetName () + "::" + info.name;
986 }
987 
988 uint32_t
990 {
991  NS_LOG_FUNCTION (this);
993 }
995 TypeId::GetTraceSource(uint32_t i) const
996 {
997  NS_LOG_FUNCTION (this << i);
998  return IidManager::Get ()->GetTraceSource(m_tid, i);
999 }
1000 
1001 TypeId
1002 TypeId::AddTraceSource (std::string name,
1003  std::string help,
1005 {
1006  return AddTraceSource (name, help, accessor, "(not yet documented)");
1007 }
1008 
1009 TypeId
1010 TypeId::AddTraceSource (std::string name,
1011  std::string help,
1013  std::string callback)
1014 {
1015  NS_LOG_FUNCTION (this << name << help << accessor);
1016  IidManager::Get ()->AddTraceSource (m_tid, name, help, accessor, callback);
1017  return *this;
1018 }
1019 
1020 TypeId
1022 {
1023  NS_LOG_FUNCTION (this);
1025  return *this;
1026 }
1027 
1028 
1030 TypeId::LookupTraceSourceByName (std::string name) const
1031 {
1032  NS_LOG_FUNCTION (this << name);
1033  TypeId tid;
1034  TypeId nextTid = *this;
1035  do {
1036  tid = nextTid;
1037  for (uint32_t i = 0; i < tid.GetTraceSourceN (); i++)
1038  {
1039  struct TypeId::TraceSourceInformation info = tid.GetTraceSource (i);
1040  if (info.name == name)
1041  {
1042  return info.accessor;
1043  }
1044  }
1045  nextTid = tid.GetParent ();
1046  } while (nextTid != tid);
1047  return 0;
1048 }
1049 
1050 uint16_t
1051 TypeId::GetUid (void) const
1052 {
1053  NS_LOG_FUNCTION (this);
1054  return m_tid;
1055 }
1056 void
1057 TypeId::SetUid (uint16_t tid)
1058 {
1059  NS_LOG_FUNCTION (this << tid);
1060  m_tid = tid;
1061 }
1062 
1063 std::ostream & operator << (std::ostream &os, TypeId tid)
1064 {
1065  os << tid.GetName ();
1066  return os;
1067 }
1068 std::istream & operator >> (std::istream &is, TypeId &tid)
1069 {
1070  std::string tidString;
1071  is >> tidString;
1072  bool ok = TypeId::LookupByNameFailSafe (tidString, &tid);
1073  if (!ok)
1074  {
1075  is.setstate (std::ios_base::badbit);
1076  }
1077  return is;
1078 }
1079 
1080 
1082 
1084 {
1085  return a.m_tid < b.m_tid;
1086 }
1087 
1088 } // namespace ns3
std::vector< struct TypeId::TraceSourceInformation > traceSources
The container of TraceSources.
Definition: type-id.cc:309
uint32_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:968
static TypeId::hash_t Hasher(const std::string name)
Hashing function.
Definition: type-id.cc:349
uint32_t hash_t
Type of hash values.
Definition: type-id.h:98
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
Record a new TraceSource.
Definition: type-id.cc:1002
bool HasAttribute(uint16_t uid, std::string name)
Check if a type id has a given Attribute.
Definition: type-id.cc:574
Callback< ObjectBase * > GetConstructor(uint16_t uid) const
Get the constructor Callback of a type id.
Definition: type-id.cc:541
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.
std::string help
Trace help string.
Definition: type-id.h:90
Callback template class.
Definition: callback.h:1164
bool HasTraceSource(uint16_t uid, std::string name)
Check if a type id has a given TraceSource.
Definition: type-id.cc:657
TypeId SetParent(void)
Set the parent TypeId.
Definition: type-id.h:585
std::vector< struct IidInformation > m_information
The container of all type id records.
Definition: type-id.cc:322
std::string GetGroupName(uint16_t uid) const
Get the group name of a type id.
Definition: type-id.cc:526
static TypeId LookupByHash(hash_t hash)
Get a TypeId by hash.
Definition: type-id.cc:771
hashmap_t m_hashmap
The by-hash index.
Definition: type-id.cc:332
namemap_t m_namemap
The by-name index.
Definition: type-id.cc:327
std::map< TypeId::hash_t, uint16_t > hashmap_t
Type of the by-hash index.
Definition: type-id.cc:330
Hold a value for an Attribute.
Definition: attribute.h:68
struct TypeId::AttributeInformation GetAttribute(uint16_t uid, uint32_t i) const
Get Attribute information by index.
Definition: type-id.cc:648
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
Ptr< const AttributeValue > originalInitialValue
Default initial value.
Definition: type-id.h:77
Ptr< const TraceSourceAccessor > accessor
Trace accessor.
Definition: type-id.h:94
void SetGroupName(uint16_t uid, std::string groupName)
Set the group name of a type id.
Definition: type-id.cc:443
TraceSource implementation.
Definition: type-id.h:86
#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
std::string groupName
The group name.
Definition: type-id.cc:297
#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:847
bool mustHideFromDocumentation
true if this type should be omitted from documentation.
Definition: type-id.cc:305
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:145
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:759
#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)
Record a new TraceSource.
Definition: type-id.cc:685
uint32_t GetRegisteredN(void) const
Get the total number of type ids.
Definition: type-id.cc:561
ns3::Hasher, ns3::Hash32() and ns3::Hash64() function declarations.
static IidManager * Get(void)
Get a pointer to the singleton instance.
Hash chaining flag.
Definition: type-id.cc:342
TypeId::hash_t hash
The type id hash value.
Definition: type-id.cc:293
Callback< ObjectBase * > GetConstructor(void) const
Get the constructor callback.
Definition: type-id.cc:952
static bool LookupByHashFailSafe(hash_t hash, TypeId *tid)
Get a TypeId by hash.
Definition: type-id.cc:779
bool HasConstructor(void) const
Check if this TypeId has a constructor.
Definition: type-id.cc:902
bool MustHideFromDocumentation(void) const
Check if this TypeId should not be listed in documentation.
Definition: type-id.cc:960
A template singleton.
Definition: singleton.h:63
TypeId information manager.
Definition: type-id.cc:78
Ptr< const AttributeAccessor > accessor
Accessor object.
Definition: type-id.h:81
bool hasConstructor
true if a constructor Callback has been registered.
Definition: type-id.cc:301
static uint32_t GetRegisteredN(void)
Get the number of registered TypeIds.
Definition: type-id.cc:791
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
Definition: type-id.cc:1030
uint32_t GetAttributeN(uint16_t uid) const
Get the number of attributes.
Definition: type-id.cc:641
Ptr< const AttributeValue > initialValue
Configured initial value.
Definition: type-id.h:79
uint16_t m_tid
The TypeId value.
Definition: type-id.h:515
uint16_t parent
The parent type id.
Definition: type-id.cc:295
The information record about a single type id.
Definition: type-id.cc:289
TypeId()
Default constructor.
Definition: type-id.h:554
bool HasParent(void) const
Check if this TypeId has a parent.
Definition: type-id.cc:854
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
Get the number of Trace sources.
Definition: type-id.cc:989
static TypeId GetRegistered(uint32_t i)
Get a TypeId by index.
Definition: type-id.cc:797
uint32_t GetTraceSourceN(uint16_t uid) const
Get the number of Trace sources.
Definition: type-id.cc:706
void SetAttributeInitialValue(uint16_t uid, uint32_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:628
std::vector< struct TypeId::AttributeInformation > attributes
The container of Attributes.
Definition: type-id.cc:307
Attribute implementation.
Definition: type-id.h:69
struct TypeId::TraceSourceInformation GetTraceSource(uint16_t uid, uint32_t i) const
Get the trace source by index.
Definition: type-id.cc:713
#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)
Mark this type id to be excluded from documentation.
Definition: type-id.cc:457
bool MustHideFromDocumentation(uint16_t uid) const
Check if this TypeId should not be listed in documentation.
Definition: type-id.cc:721
uint32_t flags
AttributeFlags value.
Definition: type-id.h:75
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:356
std::size_t size
The size of the object represented by this type id.
Definition: type-id.cc:299
TypeId SetGroupName(std::string groupName)
Set the group name.
Definition: type-id.cc:833
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)
Record in this TypeId the fact that a new attribute exists.
Definition: type-id.cc:917
std::string name
The type id name.
Definition: type-id.cc:291
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:83
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)
Set the internal id of this TypeId.
Definition: type-id.cc:1057
std::string name
Attribute name.
Definition: type-id.h:71
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name.
Definition: type-id.cc:804
ns3::TraceSourceAccessor and ns3::MakeTraceSourceAccessor declarations.
ns3::TypeId declaration; inline and template implementations.
std::string name
Trace name.
Definition: type-id.h:88
std::map< std::string, uint16_t > namemap_t
Type of the by-name index.
Definition: type-id.cc:325
uint16_t GetRegistered(uint32_t i) const
Get a type id by index.
Definition: type-id.cc:567
std::string GetName(void) const
Get the name.
Definition: type-id.cc:880
The attribute can be read, and written at any time.
Definition: type-id.h:66
uint16_t GetUid(void) const
Get the internal id of this TypeId.
Definition: type-id.cc:1051
void DoAddConstructor(Callback< ObjectBase * > callback)
Implementation for AddConstructor().
Definition: type-id.cc:910
hash_t GetHash(void) const
Get the hash.
Definition: type-id.cc:888
#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)
Set the initial value of an Attribute.
Definition: type-id.cc:942
uint16_t AllocateUid(std::string name)
Create a new unique type id.
Definition: type-id.cc:356
void SetParent(uint16_t uid, uint16_t parent)
Set the parent of a type id.
Definition: type-id.cc:435
std::size_t GetSize(void) const
Get the size of this object.
Definition: type-id.cc:894
uint16_t GetParent(uint16_t uid) const
Get the parent of a type id.
Definition: type-id.cc:519
void SetSize(uint16_t uid, std::size_t size)
Set the size of the object class referred to by this id.
Definition: type-id.cc:450
TypeId SetSize(std::size_t size)
Set the size of this type.
Definition: type-id.cc:840
std::string GetName(uint16_t uid) const
Get the name of a type id.
Definition: type-id.cc:505
std::string callback
Callback function signature type.
Definition: type-id.h:92
TypeId::hash_t GetHash(uint16_t uid) const
Get the hash of a type id.
Definition: type-id.cc:512
std::string GetAttributeFullName(uint32_t i) const
Get the Attribute name by index.
Definition: type-id.cc:981
bool HasConstructor(uint16_t uid) const
Check if a type id has a constructor Callback.
Definition: type-id.cc:553
bool IsChildOf(TypeId other) const
Check if this TypeId is a child of another.
Definition: type-id.cc:861
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:220
Callback< ObjectBase * > constructor
The constructor Callback.
Definition: type-id.cc:303
struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const
Get the trace source by index.
Definition: type-id.cc:995
std::string GetGroupName(void) const
Get the group name.
Definition: type-id.cc:872
struct IidManager::IidInformation * LookupInformation(uint16_t uid) const
Retrieve the information record for a type.
Definition: type-id.cc:427
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
Get Attribute information by index.
Definition: type-id.cc:975
Debug message logging.
void AddConstructor(uint16_t uid, Callback< ObjectBase * > callback)
Add a constructor Callback to this type id.
Definition: type-id.cc:465
a unique identifier for an interface.
Definition: type-id.h:58
std::vector< struct IidInformation >::const_iterator Iterator
Iterator type.
Definition: type-id.cc:312
std::size_t GetSize(uint16_t uid) const
Get the size of a type id.
Definition: type-id.cc:533
Generic Hash function interface.
Definition: hash.h:87
std::string help
Attribute help string.
Definition: type-id.h:73
TypeId HideFromDocumentation(void)
Hide this TypeId from documentation.
Definition: type-id.cc:1021
void AddAttribute(uint16_t uid, std::string name, std::string help, uint32_t flags, Ptr< const AttributeValue > initialValue, Ptr< const AttributeAccessor > accessor, Ptr< const AttributeChecker > checker)
Record a new attribute in a type id.
Definition: type-id.cc:602
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:751
uint16_t GetUid(std::string name) const
Get a type id by name.
Definition: type-id.cc:478