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