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