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. More... | |
void | AddConstructor (uint16_t uid, Callback< ObjectBase * > callback) |
Add a constructor Callback to this type id. More... | |
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. More... | |
uint16_t | AllocateUid (std::string name) |
Create a new unique type id. More... | |
TypeId::AttributeInformation | GetAttribute (uint16_t uid, std::size_t i) const |
Get Attribute information by index. More... | |
std::size_t | GetAttributeN (uint16_t uid) const |
Get the number of attributes. More... | |
Callback< ObjectBase * > | GetConstructor (uint16_t uid) const |
Get the constructor Callback of a type id. More... | |
std::string | GetGroupName (uint16_t uid) const |
Get the group name of a type id. More... | |
TypeId::hash_t | GetHash (uint16_t uid) const |
Get the hash of a type id. More... | |
std::string | GetName (uint16_t uid) const |
Get the name of a type id. More... | |
uint16_t | GetParent (uint16_t uid) const |
Get the parent of a type id. More... | |
uint16_t | GetRegistered (uint16_t i) const |
Get a type id by index. More... | |
uint16_t | GetRegisteredN () const |
Get the total number of type ids. More... | |
std::size_t | GetSize (uint16_t uid) const |
Get the size of a type id. More... | |
TypeId::TraceSourceInformation | GetTraceSource (uint16_t uid, std::size_t i) const |
Get the trace source by index. More... | |
std::size_t | GetTraceSourceN (uint16_t uid) const |
Get the number of Trace sources. More... | |
uint16_t | GetUid (std::string name) const |
Get a type id by name. More... | |
uint16_t | GetUid (TypeId::hash_t hash) const |
Get a type id by hash value. More... | |
bool | HasConstructor (uint16_t uid) const |
Check if a type id has a constructor Callback. More... | |
void | HideFromDocumentation (uint16_t uid) |
Mark this type id to be excluded from documentation. More... | |
bool | MustHideFromDocumentation (uint16_t uid) const |
Check if this TypeId should not be listed in documentation. More... | |
void | SetAttributeInitialValue (uint16_t uid, std::size_t i, Ptr< const AttributeValue > initialValue) |
Set the initial value of an Attribute. More... | |
void | SetGroupName (uint16_t uid, std::string groupName) |
Set the group name of a type id. More... | |
void | SetParent (uint16_t uid, uint16_t parent) |
Set the parent of a type id. More... | |
void | SetSize (uint16_t uid, std::size_t size) |
Set the size of the object class referred to by this id. More... | |
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. More... | |
typedef std::vector< IidInformation >::const_iterator | Iterator |
Iterator type. More... | |
typedef std::map< std::string, uint16_t > | namemap_t |
Type of the by-name index. More... | |
Private Member Functions | |
bool | HasAttribute (uint16_t uid, std::string name) |
Check if a type id has a given Attribute. More... | |
bool | HasTraceSource (uint16_t uid, std::string name) |
Check if a type id has a given TraceSource. More... | |
IidManager::IidInformation * | LookupInformation (uint16_t uid) const |
Retrieve the information record for a type. More... | |
Static Private Member Functions | |
static TypeId::hash_t | Hasher (const std::string name) |
Hashing function. More... | |
Private Attributes | |
hashmap_t | m_hashmap |
The by-hash index. More... | |
std::vector< IidInformation > | m_information |
The container of all type id records. More... | |
namemap_t | m_namemap |
The by-name index. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from ns3::Singleton< IidManager > | |
static IidManager * | Get () |
Get a pointer to the singleton instance. More... | |
Protected Member Functions inherited from ns3::Singleton< IidManager > | |
Singleton () | |
Constructor. More... | |
virtual | ~Singleton () |
Destructor. More... | |
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 78 of file type-id.cc.
|
private |
Type of the by-hash index.
Definition at line 343 of file type-id.cc.
|
private |
Iterator type.
Definition at line 325 of file type-id.cc.
|
private |
Type of the by-name index.
Definition at line 338 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 348 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 654 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, check-style-clang-format::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().
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 499 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::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 753 of file type-id.cc.
References ns3::TypeId::TraceSourceInformation::accessor, ns3::TypeId::TraceSourceInformation::callback, HasTraceSource(), ns3::TypeId::TraceSourceInformation::help, check-style-clang-format::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 382 of file type-id.cc.
References GetUid(), ns3::IidManager::IidInformation::groupName, ns3::IidManager::IidInformation::hasConstructor, nlohmann::detail::hash(), 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 714 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 704 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 588 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::GetGroupName | ( | uint16_t | uid | ) | const |
Get the group name of a type id.
[in] | uid | The id. |
Definition at line 569 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 549 of file type-id.cc.
References nlohmann::detail::hash(), 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 540 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().
uint16_t ns3::IidManager::GetParent | ( | uint16_t | uid | ) | const |
Get the parent of a type id.
[in] | uid | The id. |
Definition at line 559 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 618 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 611 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 578 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 791 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 781 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 512 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 526 of file type-id.cc.
References nlohmann::detail::hash(), 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 625 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 601 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 362 of file type-id.cc.
References ns3::Hasher::clear(), 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 724 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 491 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 457 of file type-id.cc.
References IID, IIDL, m_information, NS_ASSERT, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
Referenced by AddAttribute(), AddConstructor(), AddTraceSource(), AllocateUid(), GetAttribute(), GetAttributeN(), GetConstructor(), 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 801 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 693 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 475 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 466 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 483 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 345 of file type-id.cc.
Referenced by AllocateUid(), and GetUid().
|
private |
The container of all type id records.
Definition at line 335 of file type-id.cc.
Referenced by AllocateUid(), GetRegisteredN(), LookupInformation(), and SetParent().
|
private |
The by-name index.
Definition at line 340 of file type-id.cc.
Referenced by AllocateUid(), and GetUid().