TypeId information manager. More...
Classes | |
struct | IidInformation |
The information record about a single type id. More... | |
Public Member Functions | |
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, TypeId::SupportLevel supportLevel=TypeId::SUPPORTED, const std::string &supportMsg="") |
Record a new attribute in a type id. | |
void | AddConstructor (uint16_t uid, Callback< ObjectBase * > callback) |
Add a constructor Callback to this type id. | |
void | AddDeprecatedName (uint16_t uid, const std::string &name) |
Add a deprecated name for the type id. | |
void | AddTraceSource (uint16_t uid, std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor, std::string callback, TypeId::SupportLevel supportLevel=TypeId::SUPPORTED, const std::string &supportMsg="") |
Record a new TraceSource. | |
uint16_t | AllocateUid (std::string name) |
Create a new unique type id. | |
TypeId::AttributeInformation | GetAttribute (uint16_t uid, std::size_t i) const |
Get Attribute information by index. | |
std::size_t | GetAttributeN (uint16_t uid) const |
Get the number of attributes. | |
Callback< ObjectBase * > | GetConstructor (uint16_t uid) const |
Get the constructor Callback of a type id. | |
std::string | GetDeprecatedName (uint16_t uid) const |
Get the deprecated name of a type id. | |
std::string | GetGroupName (uint16_t uid) const |
Get the group name of a type id. | |
TypeId::hash_t | GetHash (uint16_t uid) const |
Get the hash of a type id. | |
std::string | GetName (uint16_t uid) const |
Get the name of a type id. | |
uint16_t | GetParent (uint16_t uid) const |
Get the parent of a type id. | |
uint16_t | GetRegistered (uint16_t i) const |
Get a type id by index. | |
uint16_t | GetRegisteredN () const |
Get the total number of type ids. | |
std::size_t | GetSize (uint16_t uid) const |
Get the size of a type id. | |
TypeId::TraceSourceInformation | GetTraceSource (uint16_t uid, std::size_t i) const |
Get the trace source by index. | |
std::size_t | GetTraceSourceN (uint16_t uid) const |
Get the number of Trace sources. | |
uint16_t | GetUid (std::string name) const |
Get a type id by name. | |
uint16_t | GetUid (TypeId::hash_t hash) const |
Get a type id by hash value. | |
bool | HasConstructor (uint16_t uid) const |
Check if a type id has a constructor Callback. | |
void | HideFromDocumentation (uint16_t uid) |
Mark this type id to be excluded from documentation. | |
bool | MustHideFromDocumentation (uint16_t uid) const |
Check if this TypeId should not be listed in documentation. | |
void | SetAttributeInitialValue (uint16_t uid, std::size_t i, Ptr< const AttributeValue > initialValue) |
Set the initial value of an Attribute. | |
void | SetGroupName (uint16_t uid, std::string groupName) |
Set the group name of a type id. | |
void | SetParent (uint16_t uid, uint16_t parent) |
Set the parent of a type id. | |
void | SetSize (uint16_t uid, std::size_t size) |
Set the size of the object class referred to by this id. | |
Public Member Functions inherited from ns3::Singleton< IidManager > | |
Singleton (const Singleton< IidManager > &)=delete | |
Singleton & | operator= (const Singleton< IidManager > &)=delete |
Private Types | |
enum | { HashChainFlag = 0x80000000 } |
IidManager constants. More... | |
typedef std::map< TypeId::hash_t, uint16_t > | hashmap_t |
Type of the by-hash index. | |
typedef std::vector< IidInformation >::const_iterator | Iterator |
Iterator type. | |
typedef std::map< std::string, uint16_t > | namemap_t |
Type of the by-name index. | |
Private Member Functions | |
bool | HasAttribute (uint16_t uid, std::string name) |
Check if a type id has a given Attribute. | |
bool | HasTraceSource (uint16_t uid, std::string name) |
Check if a type id has a given TraceSource. | |
IidManager::IidInformation * | LookupInformation (uint16_t uid) const |
Retrieve the information record for a type. | |
Static Private Member Functions | |
static TypeId::hash_t | Hasher (const std::string name) |
Hashing function. | |
Private Attributes | |
hashmap_t | m_hashmap |
The by-hash index. | |
std::vector< IidInformation > | m_information |
The container of all type id records. | |
namemap_t | m_namemap |
The by-name index. | |
Additional Inherited Members | |
Static Public Member Functions inherited from ns3::Singleton< IidManager > | |
static IidManager * | Get () |
Get a pointer to the singleton instance. | |
Protected Member Functions inherited from ns3::Singleton< IidManager > | |
Singleton () | |
Constructor. | |
virtual | ~Singleton () |
Destructor. | |
TypeId information manager.
Information records are stored in a vector. Name and hash lookup are performed by maps to the vector index.
We require all types to produce distinct hashes. What if we encounter two types that produce the same hash value? As we move to a federated distribution model (the App store), it becomes increasingly likely that the core ns3 team won't discover this in test builds. Therefore, we need to handle this case explicitly.
Note, we expect this to be extremely rare. As of this writing we have ~400 < 2^9 types, so the probability of getting a collision when we introduce a new type is ~2^9/2^31 = 2^-22, assuming we reserve 31 bits for the hash, and one bit for chaining. Even with double the number of types the probability of having a collision is only 2 x 10^-4. The probability for a three-fold collision is 1 x 10^-10.
Therefore, we'll handle one collision explicitly by reserving the high order bit of the hash value, and assert on higher level collisions. The three-fold collision probability should be an acceptablly small error rate.
Definition at line 67 of file type-id.cc.
|
private |
Type of the by-hash index.
Definition at line 347 of file type-id.cc.
|
private |
Iterator type.
Definition at line 329 of file type-id.cc.
|
private |
Type of the by-name index.
Definition at line 342 of file type-id.cc.
|
private |
IidManager constants.
Enumerator | |
---|---|
HashChainFlag | Hash chaining flag. To handle the first collision, we reserve the high bit as a chain flag. |
Definition at line 352 of file type-id.cc.
void ns3::IidManager::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, | ||
TypeId::SupportLevel | supportLevel = TypeId::SUPPORTED, | ||
const std::string & | supportMsg = "" ) |
Record a new attribute in a type id.
[in] | uid | The id. |
[in] | name | The name of the new attribute |
[in] | help | Some help text which describes the purpose of this attribute. |
[in] | flags | Flags which describe how this attribute can be read and/or written. |
[in] | initialValue | The initial value for this attribute. |
[in] | accessor | An instance of the associated AttributeAccessor subclass. |
[in] | checker | An instance of the associated AttributeChecker subclass. |
[in] | supportLevel | The support/deprecation status for this attribute. |
[in] | supportMsg | Upgrade hint if this attribute is no longer supported. |
Definition at line 681 of file type-id.cc.
References ns3::TypeId::AttributeInformation::accessor, ns3::IidManager::IidInformation::attributes, ns3::TypeId::AttributeInformation::checker, ns3::TypeId::AttributeInformation::flags, HasAttribute(), ns3::TypeId::AttributeInformation::help, IID, IIDL, ns3::TypeId::AttributeInformation::initialValue, LookupInformation(), ns3::IidManager::IidInformation::name, ns3::TypeId::AttributeInformation::name, NS_FATAL_ERROR, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::TypeId::AttributeInformation::originalInitialValue, ns3::TypeId::AttributeInformation::supportLevel, and ns3::TypeId::AttributeInformation::supportMsg.
Referenced by ns3::TypeId::AddAttribute(), and ns3::TypeId::AddAttribute().
void ns3::IidManager::AddConstructor | ( | uint16_t | uid, |
Callback< ObjectBase * > | callback ) |
Add a constructor Callback to this type id.
[in] | uid | The id. |
[in] | callback | The Callback for the constructor. |
Definition at line 517 of file type-id.cc.
References ns3::IidManager::IidInformation::constructor, ns3::IidManager::IidInformation::hasConstructor, IID, LookupInformation(), ns3::IidManager::IidInformation::name, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
Referenced by ns3::TypeId::DoAddConstructor().
void ns3::IidManager::AddDeprecatedName | ( | uint16_t | uid, |
const std::string & | name ) |
Add a deprecated name for the type id.
Use of this name raises a runtime warning, and only one deprecated name is supported.
[in] | uid | The id. |
[in] | name | The deprecated name. |
Definition at line 471 of file type-id.cc.
References ns3::IidManager::IidInformation::deprecatedName, IID, LookupInformation(), m_namemap, NS_ASSERT_MSG, and NS_LOG_FUNCTION.
Referenced by ns3::TypeId::AddDeprecatedName().
void ns3::IidManager::AddTraceSource | ( | uint16_t | uid, |
std::string | name, | ||
std::string | help, | ||
Ptr< const TraceSourceAccessor > | accessor, | ||
std::string | callback, | ||
TypeId::SupportLevel | supportLevel = TypeId::SUPPORTED, | ||
const std::string & | supportMsg = "" ) |
Record a new TraceSource.
[in] | uid | The id. |
[in] | name | The name of the new trace source |
[in] | help | Some help text which describes the purpose of this trace source. |
[in] | accessor | A pointer to a TraceSourceAccessor which can be used to connect/disconnect sinks to this trace source. |
[in] | callback | Fully qualified typedef name for the callback signature. Generally this should begin with the "ns3::" namespace qualifier. |
[in] | supportLevel | The support/deprecation status for this attribute. |
[in] | supportMsg | Upgrade hint if this attribute is no longer supported. |
Definition at line 780 of file type-id.cc.
References ns3::TypeId::TraceSourceInformation::accessor, ns3::TypeId::TraceSourceInformation::callback, HasTraceSource(), ns3::TypeId::TraceSourceInformation::help, IID, IIDL, LookupInformation(), ns3::IidManager::IidInformation::name, ns3::TypeId::TraceSourceInformation::name, NS_FATAL_ERROR, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::TypeId::TraceSourceInformation::supportLevel, ns3::TypeId::TraceSourceInformation::supportMsg, and ns3::IidManager::IidInformation::traceSources.
Referenced by ns3::TypeId::AddTraceSource().
uint16_t ns3::IidManager::AllocateUid | ( | std::string | name | ) |
Create a new unique type id.
[in] | name | The name of this type id. |
Definition at line 386 of file type-id.cc.
References GetUid(), ns3::IidManager::IidInformation::groupName, ns3::IidManager::IidInformation::hasConstructor, ns3::IidManager::IidInformation::hash, HashChainFlag, Hasher(), IID, IIDL, LookupInformation(), m_hashmap, m_information, m_namemap, ns3::IidManager::IidInformation::mustHideFromDocumentation, ns3::IidManager::IidInformation::name, NS_ABORT_MSG_UNLESS, NS_ASSERT, NS_ASSERT_MSG, NS_LOG_ERROR, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::IidManager::IidInformation::parent, ns3::IidManager::IidInformation::size, ns3::TypeId::SUPPORTED, and ns3::IidManager::IidInformation::supportLevel.
Referenced by ns3::TypeId::TypeId().
TypeId::AttributeInformation ns3::IidManager::GetAttribute | ( | uint16_t | uid, |
std::size_t | i ) const |
Get Attribute information by index.
[in] | uid | The id. |
[in] | i | Index into attribute array |
Definition at line 741 of file type-id.cc.
References ns3::IidManager::IidInformation::attributes, IID, IIDL, LookupInformation(), ns3::IidManager::IidInformation::name, NS_ASSERT, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
Referenced by ns3::TypeId::GetAttribute().
std::size_t ns3::IidManager::GetAttributeN | ( | uint16_t | uid | ) | const |
Get the number of attributes.
[in] | uid | The id. |
Definition at line 731 of file type-id.cc.
References ns3::IidManager::IidInformation::attributes, IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.
Referenced by ns3::TypeId::GetAttributeN().
Callback< ObjectBase * > ns3::IidManager::GetConstructor | ( | uint16_t | uid | ) | const |
Get the constructor Callback of a type id.
[in] | uid | The id. |
Definition at line 615 of file type-id.cc.
References ns3::IidManager::IidInformation::constructor, ns3::IidManager::IidInformation::hasConstructor, IID, LookupInformation(), ns3::IidManager::IidInformation::name, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
Referenced by ns3::TypeId::GetConstructor().
std::string ns3::IidManager::GetDeprecatedName | ( | uint16_t | uid | ) | const |
Get the deprecated name of a type id.
[in] | uid | The id. |
Definition at line 567 of file type-id.cc.
References ns3::IidManager::IidInformation::deprecatedName, IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.
std::string ns3::IidManager::GetGroupName | ( | uint16_t | uid | ) | const |
Get the group name of a type id.
[in] | uid | The id. |
Definition at line 596 of file type-id.cc.
References ns3::IidManager::IidInformation::groupName, IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.
Referenced by ns3::TypeId::GetGroupName().
TypeId::hash_t ns3::IidManager::GetHash | ( | uint16_t | uid | ) | const |
Get the hash of a type id.
[in] | uid | The id. |
Definition at line 576 of file type-id.cc.
References ns3::IidManager::IidInformation::hash, IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.
Referenced by ns3::TypeId::GetHash().
std::string ns3::IidManager::GetName | ( | uint16_t | uid | ) | const |
Get the name of a type id.
[in] | uid | The id. |
Definition at line 558 of file type-id.cc.
References IID, IIDL, LookupInformation(), ns3::IidManager::IidInformation::name, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
Referenced by ns3::TypeId::GetName(), ns3::TypeId::LookupByName(), and ns3::TypeId::LookupByNameFailSafe().
uint16_t ns3::IidManager::GetParent | ( | uint16_t | uid | ) | const |
Get the parent of a type id.
[in] | uid | The id. |
Definition at line 586 of file type-id.cc.
References IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::IidManager::IidInformation::parent.
Referenced by ns3::TypeId::GetParent(), and ns3::TypeId::HasParent().
uint16_t ns3::IidManager::GetRegistered | ( | uint16_t | i | ) | const |
Get a type id by index.
The type id value 0 indicates not registered, so there is an offset of 1 between the index and the type id value. This function converts from an index to the type id value.
[in] | i | The index. |
Definition at line 645 of file type-id.cc.
References IID, and NS_LOG_FUNCTION.
uint16_t ns3::IidManager::GetRegisteredN | ( | ) | const |
Get the total number of type ids.
Definition at line 638 of file type-id.cc.
References IID, m_information, and NS_LOG_FUNCTION.
Referenced by ns3::TypeId::GetRegisteredN().
std::size_t ns3::IidManager::GetSize | ( | uint16_t | uid | ) | const |
Get the size of a type id.
[in] | uid | The id. |
Definition at line 605 of file type-id.cc.
References IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::IidManager::IidInformation::size.
Referenced by ns3::TypeId::GetSize().
TypeId::TraceSourceInformation ns3::IidManager::GetTraceSource | ( | uint16_t | uid, |
std::size_t | i ) const |
Get the trace source by index.
[in] | uid | The id. |
[in] | i | Index into trace source array. |
Definition at line 818 of file type-id.cc.
References IID, IIDL, LookupInformation(), ns3::IidManager::IidInformation::name, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::IidManager::IidInformation::traceSources.
Referenced by ns3::TypeId::GetTraceSource().
std::size_t ns3::IidManager::GetTraceSourceN | ( | uint16_t | uid | ) | const |
Get the number of Trace sources.
[in] | uid | The id. |
Definition at line 808 of file type-id.cc.
References IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::IidManager::IidInformation::traceSources.
Referenced by ns3::TypeId::GetTraceSourceN().
uint16_t ns3::IidManager::GetUid | ( | std::string | name | ) | const |
Get a type id by name.
[in] | name | The type id to find. |
Definition at line 530 of file type-id.cc.
References IID, IIDL, m_namemap, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
Referenced by AllocateUid(), ns3::TypeId::LookupByHash(), ns3::TypeId::LookupByHashFailSafe(), ns3::TypeId::LookupByName(), and ns3::TypeId::LookupByNameFailSafe().
uint16_t ns3::IidManager::GetUid | ( | TypeId::hash_t | hash | ) | const |
Get a type id by hash value.
[in] | hash | The type id to find. |
Definition at line 544 of file type-id.cc.
References IID, IIDL, m_hashmap, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
|
private |
Check if a type id has a given Attribute.
[in] | uid | The id. |
[in] | name | The Attribute name. |
true
if uid has the Attribute name . Definition at line 652 of file type-id.cc.
References ns3::IidManager::IidInformation::attributes, IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::IidManager::IidInformation::parent.
Referenced by AddAttribute().
bool ns3::IidManager::HasConstructor | ( | uint16_t | uid | ) | const |
Check if a type id has a constructor Callback.
[in] | uid | The id. |
true
if the type id has a constructor Callback. Definition at line 628 of file type-id.cc.
References ns3::IidManager::IidInformation::hasConstructor, IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.
Referenced by ns3::TypeId::HasConstructor().
|
staticprivate |
Hashing function.
[in] | name | The type id name. |
Definition at line 366 of file type-id.cc.
References ns3::Hasher::clear(), ns3::Create(), and ns3::Hasher::GetHash32().
Referenced by AllocateUid().
|
private |
Check if a type id has a given TraceSource.
[in] | uid | The id. |
[in] | name | The TraceSource name. |
true
if uid has the TraceSource name . Definition at line 751 of file type-id.cc.
References IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::IidManager::IidInformation::parent, and ns3::IidManager::IidInformation::traceSources.
Referenced by AddTraceSource().
void ns3::IidManager::HideFromDocumentation | ( | uint16_t | uid | ) |
Mark this type id to be excluded from documentation.
[in] | uid | The id. |
Definition at line 509 of file type-id.cc.
References IID, LookupInformation(), ns3::IidManager::IidInformation::mustHideFromDocumentation, and NS_LOG_FUNCTION.
Referenced by ns3::TypeId::HideFromDocumentation().
|
private |
Retrieve the information record for a type.
[in] | uid | The id. |
Definition at line 461 of file type-id.cc.
References IID, IIDL, m_information, NS_ASSERT_MSG, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
Referenced by AddAttribute(), AddConstructor(), AddDeprecatedName(), AddTraceSource(), AllocateUid(), GetAttribute(), GetAttributeN(), GetConstructor(), GetDeprecatedName(), GetGroupName(), GetHash(), GetName(), GetParent(), GetSize(), GetTraceSource(), GetTraceSourceN(), HasAttribute(), HasConstructor(), HasTraceSource(), HideFromDocumentation(), MustHideFromDocumentation(), SetAttributeInitialValue(), SetGroupName(), SetParent(), and SetSize().
bool ns3::IidManager::MustHideFromDocumentation | ( | uint16_t | uid | ) | const |
Check if this TypeId should not be listed in documentation.
[in] | uid | The id. |
true
if this TypeId should be hidden from the user. Definition at line 828 of file type-id.cc.
References IID, IIDL, LookupInformation(), ns3::IidManager::IidInformation::mustHideFromDocumentation, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
Referenced by ns3::TypeId::MustHideFromDocumentation().
void ns3::IidManager::SetAttributeInitialValue | ( | uint16_t | uid, |
std::size_t | i, | ||
Ptr< const AttributeValue > | initialValue ) |
Set the initial value of an Attribute.
[in] | uid | The id. |
[in] | i | The attribute to manipulate |
[in] | initialValue | The new initial value to use for this attribute. |
Definition at line 720 of file type-id.cc.
References ns3::IidManager::IidInformation::attributes, IID, LookupInformation(), NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by ns3::TypeId::SetAttributeInitialValue().
void ns3::IidManager::SetGroupName | ( | uint16_t | uid, |
std::string | groupName ) |
Set the group name of a type id.
[in] | uid | The id. |
[in] | groupName | The group name. |
Definition at line 493 of file type-id.cc.
References ns3::IidManager::IidInformation::groupName, IID, LookupInformation(), and NS_LOG_FUNCTION.
Referenced by ns3::TypeId::SetGroupName().
void ns3::IidManager::SetParent | ( | uint16_t | uid, |
uint16_t | parent ) |
Set the parent of a type id.
[in] | uid | The id. |
[in] | parent | The id of the parent. |
Definition at line 484 of file type-id.cc.
References IID, LookupInformation(), m_information, NS_ASSERT, NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::parent.
Referenced by ns3::TypeId::SetParent().
void ns3::IidManager::SetSize | ( | uint16_t | uid, |
std::size_t | size ) |
Set the size of the object class referred to by this id.
[in] | uid | The id. |
[in] | size | The object size. |
Definition at line 501 of file type-id.cc.
References IID, LookupInformation(), NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::size.
Referenced by ns3::TypeId::SetSize().
|
private |
The by-hash index.
Definition at line 349 of file type-id.cc.
Referenced by AllocateUid(), and GetUid().
|
private |
The container of all type id records.
Definition at line 339 of file type-id.cc.
Referenced by AllocateUid(), GetRegisteredN(), LookupInformation(), and SetParent().
|
private |
The by-name index.
Definition at line 344 of file type-id.cc.
Referenced by AddDeprecatedName(), AllocateUid(), and GetUid().