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