OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2008 INRIA | 3 * Copyright (c) 2008 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 /** | 99 /** |
100 * Set the size of the object class referred to by this id. | 100 * Set the size of the object class referred to by this id. |
101 * \param [in] uid The id. | 101 * \param [in] uid The id. |
102 * \param [in] size The object size. | 102 * \param [in] size The object size. |
103 */ | 103 */ |
104 void SetSize (uint16_t uid, std::size_t size); | 104 void SetSize (uint16_t uid, std::size_t size); |
105 /** | 105 /** |
106 * Add a constructor Callback to this type id. | 106 * Add a constructor Callback to this type id. |
107 * \param [in] uid The id. | 107 * \param [in] uid The id. |
108 * \param [in] callback The Callback for the constructor. | 108 * \param [in] callback The Callback for the constructor. |
| 109 * \param [in] canBeDuplicate If true, this class can be registered more than
once |
109 */ | 110 */ |
110 void AddConstructor (uint16_t uid, Callback<ObjectBase *> callback); | 111 void AddConstructor (uint16_t uid, Callback<ObjectBase *> callback, bool canBe
Duplicate = false); |
111 /** | 112 /** |
112 * Mark this type id to be excluded from documentation. | 113 * Mark this type id to be excluded from documentation. |
113 * \param [in] uid The id. | 114 * \param [in] uid The id. |
114 */ | 115 */ |
115 void HideFromDocumentation (uint16_t uid); | 116 void HideFromDocumentation (uint16_t uid); |
116 /** | 117 /** |
117 * Get a type id by name. | 118 * Get a type id by name. |
118 * \param [in] name The type id to find. | 119 * \param [in] name The type id to find. |
119 * \returns The type id. A type id of 0 means \p name wasn't found. | 120 * \returns The type id. A type id of 0 means \p name wasn't found. |
120 */ | 121 */ |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 * \param [in] name The name of the new trace source | 236 * \param [in] name The name of the new trace source |
236 * \param [in] help Some help text which describes the purpose of this | 237 * \param [in] help Some help text which describes the purpose of this |
237 * trace source. | 238 * trace source. |
238 * \param [in] accessor A pointer to a TraceSourceAccessor which can be | 239 * \param [in] accessor A pointer to a TraceSourceAccessor which can be |
239 * used to connect/disconnect sinks to this trace source. | 240 * used to connect/disconnect sinks to this trace source. |
240 * \param [in] callback Fully qualified typedef name for the callback | 241 * \param [in] callback Fully qualified typedef name for the callback |
241 * signature. Generally this should begin with the | 242 * signature. Generally this should begin with the |
242 * "ns3::" namespace qualifier.·· | 243 * "ns3::" namespace qualifier.·· |
243 * \param [in] supportLevel The support/deprecation status for this attribute. | 244 * \param [in] supportLevel The support/deprecation status for this attribute. |
244 * \param [in] supportMsg Upgrade hint if this attribute is no longer supporte
d. | 245 * \param [in] supportMsg Upgrade hint if this attribute is no longer supporte
d. |
| 246 * \param [in] canBeDuplicate If true, this class can be registered more than
once |
245 * \returns This TypeId instance. | 247 * \returns This TypeId instance. |
246 */ | 248 */ |
247 void AddTraceSource (uint16_t uid, | 249 void AddTraceSource (uint16_t uid, |
248 std::string name,· | 250 std::string name,· |
249 std::string help, | 251 std::string help, |
250 Ptr<const TraceSourceAccessor> accessor, | 252 Ptr<const TraceSourceAccessor> accessor, |
251 std::string callback, | 253 std::string callback, |
252 TypeId::SupportLevel supportLevel = TypeId::SUPPORTED, | 254 TypeId::SupportLevel supportLevel = TypeId::SUPPORTED, |
253 const std::string &supportMsg = ""); | 255 const std::string &supportMsg = "", |
| 256 bool canBeDuplicate = false); |
254 /** | 257 /** |
255 * Get the number of Trace sources. | 258 * Get the number of Trace sources. |
256 * \param [in] uid The id. | 259 * \param [in] uid The id. |
257 * \returns The number of trace sources defined in this TypeId. | 260 * \returns The number of trace sources defined in this TypeId. |
258 */ | 261 */ |
259 std::size_t GetTraceSourceN (uint16_t uid) const; | 262 std::size_t GetTraceSourceN (uint16_t uid) const; |
260 /** | 263 /** |
261 * Get the trace source by index. | 264 * Get the trace source by index. |
262 * \param [in] uid The id. | 265 * \param [in] uid The id. |
263 * \param [in] i Index into trace source array. | 266 * \param [in] i Index into trace source array. |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 487 } |
485 void | 488 void |
486 IidManager::HideFromDocumentation (uint16_t uid) | 489 IidManager::HideFromDocumentation (uint16_t uid) |
487 { | 490 { |
488 NS_LOG_FUNCTION (IID << uid); | 491 NS_LOG_FUNCTION (IID << uid); |
489 struct IidInformation *information = LookupInformation (uid); | 492 struct IidInformation *information = LookupInformation (uid); |
490 information->mustHideFromDocumentation = true; | 493 information->mustHideFromDocumentation = true; |
491 } | 494 } |
492 | 495 |
493 void· | 496 void· |
494 IidManager::AddConstructor (uint16_t uid, Callback<ObjectBase *> callback) | 497 IidManager::AddConstructor (uint16_t uid, Callback<ObjectBase *> callback, bool
canBeDuplicate) |
495 { | 498 { |
496 NS_LOG_FUNCTION (IID << uid << &callback); | 499 NS_LOG_FUNCTION (IID << uid << &callback); |
497 struct IidInformation *information = LookupInformation (uid); | 500 struct IidInformation *information = LookupInformation (uid); |
498 if (information->hasConstructor) | 501 if (!canBeDuplicate && information->hasConstructor) |
499 { | 502 { |
500 NS_FATAL_ERROR (information->name<<" already has a constructor."); | 503 NS_FATAL_ERROR (information->name<<" already has a constructor."); |
501 } | 504 } |
502 information->hasConstructor = true; | 505 information->hasConstructor = true; |
503 information->constructor = callback; | 506 information->constructor = callback; |
504 } | 507 } |
505 | 508 |
506 uint16_t· | 509 uint16_t· |
507 IidManager::GetUid (std::string name) const | 510 IidManager::GetUid (std::string name) const |
508 { | 511 { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 return false; | 744 return false; |
742 } | 745 } |
743 | 746 |
744 void· | 747 void· |
745 IidManager::AddTraceSource (uint16_t uid, | 748 IidManager::AddTraceSource (uint16_t uid, |
746 std::string name,· | 749 std::string name,· |
747 std::string help, | 750 std::string help, |
748 Ptr<const TraceSourceAccessor> accessor, | 751 Ptr<const TraceSourceAccessor> accessor, |
749 std::string callback, | 752 std::string callback, |
750 TypeId::SupportLevel supportLevel, | 753 TypeId::SupportLevel supportLevel, |
751 const std::string &supportMsg) | 754 const std::string &supportMsg, |
| 755 bool canBeDuplicate) |
752 { | 756 { |
753 NS_LOG_FUNCTION (IID << uid << name << help | 757 NS_LOG_FUNCTION (IID << uid << name << help |
754 << accessor << callback | 758 << accessor << callback |
755 << supportLevel << supportMsg); | 759 << supportLevel << supportMsg); |
756 struct IidInformation *information = LookupInformation (uid); | 760 struct IidInformation *information = LookupInformation (uid); |
757 if (HasTraceSource (uid, name)) | 761 if (!canBeDuplicate && HasTraceSource(uid, name)) |
758 { | 762 { |
759 NS_FATAL_ERROR ("Trace source \"" << name << "\" already registered on tid
=\"" <<· | 763 NS_FATAL_ERROR ("Trace source \"" << name << "\" already registered on tid
=\"" <<· |
760 information->name << "\""); | 764 information->name << "\""); |
761 } | 765 } |
762 struct TypeId::TraceSourceInformation source; | 766 struct TypeId::TraceSourceInformation source; |
763 source.name = name; | 767 source.name = name; |
764 source.help = help; | 768 source.help = help; |
765 source.accessor = accessor; | 769 source.accessor = accessor; |
766 source.callback = callback; | 770 source.callback = callback; |
767 source.supportLevel = supportLevel; | 771 source.supportLevel = supportLevel; |
(...skipping 30 matching lines...) Expand all Loading... |
798 } | 802 } |
799 | 803 |
800 } // namespace ns3 | 804 } // namespace ns3 |
801 | 805 |
802 namespace ns3 { | 806 namespace ns3 { |
803 | 807 |
804 /********************************************************************* | 808 /********************************************************************* |
805 * The TypeId class | 809 * The TypeId class |
806 *********************************************************************/ | 810 *********************************************************************/ |
807 | 811 |
808 TypeId::TypeId (const char *name) | 812 TypeId::TypeId (const char *name, bool canBeDuplicate) |
809 { | 813 { |
810 NS_LOG_FUNCTION (this << name); | 814 NS_LOG_FUNCTION (this << name); |
811 uint16_t uid = IidManager::Get ()->AllocateUid (name); | 815 uint16_t uid = 0; |
| 816 if (canBeDuplicate) |
| 817 { |
| 818 uid = IidManager::Get ()->GetUid(name); |
| 819 NS_LOG_LOGIC(uid); |
| 820 if (uid != 0) |
| 821 { |
| 822 m_tid = uid; |
| 823 return; |
| 824 } |
| 825 } |
| 826 |
| 827 uid = IidManager::Get()->AllocateUid (name); |
812 NS_LOG_LOGIC (uid); | 828 NS_LOG_LOGIC (uid); |
813 NS_ASSERT (uid != 0); | 829 NS_ASSERT (uid != 0); |
814 m_tid = uid; | 830 m_tid = uid; |
815 } | 831 } |
816 | 832 |
817 | 833 |
818 TypeId::TypeId (uint16_t tid) | 834 TypeId::TypeId (uint16_t tid) |
819 : m_tid (tid) | 835 : m_tid (tid) |
820 { | 836 { |
821 NS_LOG_FUNCTION (this << tid); | 837 NS_LOG_FUNCTION (this << tid); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 | 1005 |
990 bool· | 1006 bool· |
991 TypeId::HasConstructor (void) const | 1007 TypeId::HasConstructor (void) const |
992 { | 1008 { |
993 NS_LOG_FUNCTION (this); | 1009 NS_LOG_FUNCTION (this); |
994 bool hasConstructor = IidManager::Get ()->HasConstructor (m_tid); | 1010 bool hasConstructor = IidManager::Get ()->HasConstructor (m_tid); |
995 return hasConstructor; | 1011 return hasConstructor; |
996 } | 1012 } |
997 | 1013 |
998 void | 1014 void |
999 TypeId::DoAddConstructor (Callback<ObjectBase *> cb) | 1015 TypeId::DoAddConstructor (Callback<ObjectBase *> cb, bool canBeDuplicate) |
1000 { | 1016 { |
1001 NS_LOG_FUNCTION (this << &cb); | 1017 NS_LOG_FUNCTION (this << &cb); |
1002 IidManager::Get ()->AddConstructor (m_tid, cb); | 1018 IidManager::Get ()->AddConstructor (m_tid, cb, canBeDuplicate); |
1003 } | 1019 } |
1004 | 1020 |
1005 TypeId· | 1021 TypeId· |
1006 TypeId::AddAttribute (std::string name, | 1022 TypeId::AddAttribute (std::string name, |
1007 std::string help,· | 1023 std::string help,· |
1008 const AttributeValue &initialValue, | 1024 const AttributeValue &initialValue, |
1009 Ptr<const AttributeAccessor> accessor, | 1025 Ptr<const AttributeAccessor> accessor, |
1010 Ptr<const AttributeChecker> checker, | 1026 Ptr<const AttributeChecker> checker, |
1011 SupportLevel supportLevel, | 1027 SupportLevel supportLevel, |
1012 const std::string &supportMsg) | 1028 const std::string &supportMsg) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 { | 1122 { |
1107 return AddTraceSource (name, help, accessor, "(not yet documented)"); | 1123 return AddTraceSource (name, help, accessor, "(not yet documented)"); |
1108 } | 1124 } |
1109 | 1125 |
1110 TypeId· | 1126 TypeId· |
1111 TypeId::AddTraceSource (std::string name, | 1127 TypeId::AddTraceSource (std::string name, |
1112 std::string help, | 1128 std::string help, |
1113 Ptr<const TraceSourceAccessor> accessor, | 1129 Ptr<const TraceSourceAccessor> accessor, |
1114 std::string callback, | 1130 std::string callback, |
1115 SupportLevel supportLevel, | 1131 SupportLevel supportLevel, |
1116 const std::string &supportMsg) | 1132 const std::string &supportMsg, |
| 1133 bool canBeDuplicate) |
1117 { | 1134 { |
1118 NS_LOG_FUNCTION (this << name << help | 1135 NS_LOG_FUNCTION (this << name << help |
1119 << accessor << callback | 1136 << accessor << callback |
1120 << supportLevel << supportMsg); | 1137 << supportLevel << supportMsg); |
1121 IidManager::Get ()->AddTraceSource (m_tid, name, help, | 1138 IidManager::Get ()->AddTraceSource (m_tid, name, help, |
1122 accessor, callback, | 1139 accessor, callback, |
1123 supportLevel, supportMsg); | 1140 supportLevel, supportMsg, |
| 1141 canBeDuplicate); |
1124 return *this; | 1142 return *this; |
1125 } | 1143 } |
1126 | 1144 |
1127 TypeId· | 1145 TypeId· |
1128 TypeId::HideFromDocumentation (void) | 1146 TypeId::HideFromDocumentation (void) |
1129 { | 1147 { |
1130 NS_LOG_FUNCTION (this); | 1148 NS_LOG_FUNCTION (this); |
1131 IidManager::Get ()->HideFromDocumentation (m_tid); | 1149 IidManager::Get ()->HideFromDocumentation (m_tid); |
1132 return *this; | 1150 return *this; |
1133 } | 1151 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 is >> tidString; | 1233 is >> tidString; |
1216 bool ok = TypeId::LookupByNameFailSafe (tidString, &tid); | 1234 bool ok = TypeId::LookupByNameFailSafe (tidString, &tid); |
1217 if (!ok) | 1235 if (!ok) |
1218 { | 1236 { |
1219 is.setstate (std::ios_base::badbit); | 1237 is.setstate (std::ios_base::badbit); |
1220 } | 1238 } |
1221 return is; | 1239 return is; |
1222 } | 1240 } |
1223 | 1241 |
1224 | 1242 |
1225 ATTRIBUTE_HELPER_CPP (TypeId); | 1243 ATTRIBUTE_HELPER_CPP_LIB (TypeId, NS3_EXPORT); |
1226 | 1244 |
1227 bool operator < (TypeId a, TypeId b) | 1245 bool operator < (TypeId a, TypeId b) |
1228 { | 1246 { |
1229 return a.m_tid < b.m_tid; | 1247 return a.m_tid < b.m_tid; |
1230 } | 1248 } |
1231 | 1249 |
1232 } // namespace ns3 | 1250 } // namespace ns3 |
OLD | NEW |