TypeId information manager. More...
Classes | |
struct | IidInformation |
Public Member Functions | |
IidManager () | |
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) |
void | AddConstructor (uint16_t uid, Callback< ObjectBase * > callback) |
void | AddTraceSource (uint16_t uid, std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor, std::string callback) |
uint16_t | AllocateUid (std::string name) |
struct TypeId::AttributeInformation | GetAttribute (uint16_t uid, uint32_t i) const |
uint32_t | GetAttributeN (uint16_t uid) const |
Callback< ObjectBase * > | GetConstructor (uint16_t uid) const |
std::string | GetGroupName (uint16_t uid) const |
TypeId::hash_t | GetHash (uint16_t uid) const |
std::string | GetName (uint16_t uid) const |
uint16_t | GetParent (uint16_t uid) const |
uint16_t | GetRegistered (uint32_t i) const |
uint32_t | GetRegisteredN (void) const |
std::size_t | GetSize (uint16_t uid) const |
struct TypeId::TraceSourceInformation | GetTraceSource (uint16_t uid, uint32_t i) const |
uint32_t | GetTraceSourceN (uint16_t uid) const |
uint16_t | GetUid (std::string name) const |
uint16_t | GetUid (TypeId::hash_t hash) const |
bool | HasConstructor (uint16_t uid) const |
void | HideFromDocumentation (uint16_t uid) |
bool | MustHideFromDocumentation (uint16_t uid) const |
void | SetAttributeInitialValue (uint16_t uid, uint32_t i, Ptr< const AttributeValue > initialValue) |
void | SetGroupName (uint16_t uid, std::string groupName) |
void | SetParent (uint16_t uid, uint16_t parent) |
void | SetSize (uint16_t uid, std::size_t size) |
Private Types | |
enum | { HashChainFlag = 0x80000000 } |
typedef std::map< TypeId::hash_t, uint16_t > | hashmap_t |
typedef std::vector< struct IidInformation >::const_iterator | Iterator |
typedef std::map< std::string, uint16_t > | namemap_t |
Private Member Functions | |
bool | HasAttribute (uint16_t uid, std::string name) |
bool | HasTraceSource (uint16_t uid, std::string name) |
struct IidManager::IidInformation * | LookupInformation (uint16_t uid) const |
Static Private Member Functions | |
static TypeId::hash_t | Hasher (const std::string name) |
Private Attributes | |
hashmap_t | m_hashmap |
std::vector< struct IidInformation > | m_information |
namemap_t | m_namemap |
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 70 of file type-id.cc.
|
private |
Definition at line 138 of file type-id.cc.
|
private |
Definition at line 129 of file type-id.cc.
|
private |
Definition at line 135 of file type-id.cc.
|
private |
Enumerator | |
---|---|
HashChainFlag |
Definition at line 144 of file type-id.cc.
ns3::IidManager::IidManager | ( | ) |
Definition at line 147 of file type-id.cc.
References NS_LOG_FUNCTION.
void ns3::IidManager::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 at line 407 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, ns3::TypeId::AttributeInformation::initialValue, LookupInformation(), ns3::TypeId::AttributeInformation::name, ns3::IidManager::IidInformation::name, NS_FATAL_ERROR, NS_LOG_FUNCTION, and ns3::TypeId::AttributeInformation::originalInitialValue.
void ns3::IidManager::AddConstructor | ( | uint16_t | uid, |
Callback< ObjectBase * > | callback | ||
) |
Definition at line 270 of file type-id.cc.
References ns3::IidManager::IidInformation::constructor, ns3::IidManager::IidInformation::hasConstructor, LookupInformation(), ns3::IidManager::IidInformation::name, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
void ns3::IidManager::AddTraceSource | ( | uint16_t | uid, |
std::string | name, | ||
std::string | help, | ||
Ptr< const TraceSourceAccessor > | accessor, | ||
std::string | callback | ||
) |
Definition at line 490 of file type-id.cc.
References ns3::TypeId::TraceSourceInformation::accessor, ns3::TypeId::TraceSourceInformation::callback, HasTraceSource(), ns3::TypeId::TraceSourceInformation::help, LookupInformation(), ns3::TypeId::TraceSourceInformation::name, ns3::IidManager::IidInformation::name, NS_FATAL_ERROR, NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::traceSources.
uint16_t ns3::IidManager::AllocateUid | ( | std::string | name | ) |
Definition at line 161 of file type-id.cc.
References GetUid(), ns3::IidManager::IidInformation::groupName, ns3::IidManager::IidInformation::hasConstructor, ns3::IidManager::IidInformation::hash, HashChainFlag, Hasher(), LookupInformation(), m_hashmap, m_information, m_namemap, ns3::IidManager::IidInformation::mustHideFromDocumentation, ns3::IidManager::IidInformation::name, NS_ASSERT, NS_ASSERT_MSG, NS_LOG_ERROR, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::IidManager::IidInformation::parent, and ns3::IidManager::IidInformation::size.
struct TypeId::AttributeInformation ns3::IidManager::GetAttribute | ( | uint16_t | uid, |
uint32_t | i | ||
) | const |
Definition at line 453 of file type-id.cc.
References ns3::IidManager::IidInformation::attributes, NS_ASSERT, and NS_LOG_FUNCTION.
uint32_t ns3::IidManager::GetAttributeN | ( | uint16_t | uid | ) | const |
Definition at line 446 of file type-id.cc.
References ns3::IidManager::IidInformation::attributes, LookupInformation(), and NS_LOG_FUNCTION.
Callback< ObjectBase * > ns3::IidManager::GetConstructor | ( | uint16_t | uid | ) | const |
Definition at line 346 of file type-id.cc.
References ns3::IidManager::IidInformation::constructor, ns3::IidManager::IidInformation::hasConstructor, LookupInformation(), ns3::IidManager::IidInformation::name, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
std::string ns3::IidManager::GetGroupName | ( | uint16_t | uid | ) | const |
Definition at line 331 of file type-id.cc.
References ns3::IidManager::IidInformation::groupName, LookupInformation(), and NS_LOG_FUNCTION.
TypeId::hash_t ns3::IidManager::GetHash | ( | uint16_t | uid | ) | const |
Definition at line 317 of file type-id.cc.
References ns3::IidManager::IidInformation::hash, LookupInformation(), and NS_LOG_FUNCTION.
std::string ns3::IidManager::GetName | ( | uint16_t | uid | ) | const |
Definition at line 310 of file type-id.cc.
References LookupInformation(), ns3::IidManager::IidInformation::name, and NS_LOG_FUNCTION.
uint16_t ns3::IidManager::GetParent | ( | uint16_t | uid | ) | const |
Definition at line 324 of file type-id.cc.
References LookupInformation(), NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::parent.
uint16_t ns3::IidManager::GetRegistered | ( | uint32_t | i | ) | const |
Definition at line 372 of file type-id.cc.
References NS_LOG_FUNCTION.
uint32_t ns3::IidManager::GetRegisteredN | ( | void | ) | const |
Definition at line 366 of file type-id.cc.
References m_information, and NS_LOG_FUNCTION.
std::size_t ns3::IidManager::GetSize | ( | uint16_t | uid | ) | const |
Definition at line 338 of file type-id.cc.
References LookupInformation(), NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::size.
struct TypeId::TraceSourceInformation ns3::IidManager::GetTraceSource | ( | uint16_t | uid, |
uint32_t | i | ||
) | const |
Definition at line 518 of file type-id.cc.
References NS_ASSERT, NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::traceSources.
uint32_t ns3::IidManager::GetTraceSourceN | ( | uint16_t | uid | ) | const |
Definition at line 511 of file type-id.cc.
References LookupInformation(), NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::traceSources.
uint16_t ns3::IidManager::GetUid | ( | std::string | name | ) | const |
Definition at line 283 of file type-id.cc.
References m_namemap, and NS_LOG_FUNCTION.
Referenced by AllocateUid().
uint16_t ns3::IidManager::GetUid | ( | TypeId::hash_t | hash | ) | const |
Definition at line 297 of file type-id.cc.
References m_hashmap.
|
private |
Definition at line 379 of file type-id.cc.
References ns3::IidManager::IidInformation::attributes, LookupInformation(), NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::parent.
Referenced by AddAttribute().
bool ns3::IidManager::HasConstructor | ( | uint16_t | uid | ) | const |
Definition at line 358 of file type-id.cc.
References ns3::IidManager::IidInformation::hasConstructor, LookupInformation(), and NS_LOG_FUNCTION.
|
staticprivate |
Definition at line 154 of file type-id.cc.
References ns3::Hasher::clear(), and ns3::Hasher::GetHash32().
Referenced by AllocateUid().
|
private |
Definition at line 462 of file type-id.cc.
References LookupInformation(), NS_LOG_FUNCTION, ns3::IidManager::IidInformation::parent, and ns3::IidManager::IidInformation::traceSources.
Referenced by AddTraceSource().
void ns3::IidManager::HideFromDocumentation | ( | uint16_t | uid | ) |
Definition at line 262 of file type-id.cc.
References LookupInformation(), ns3::IidManager::IidInformation::mustHideFromDocumentation, and NS_LOG_FUNCTION.
|
private |
Definition at line 232 of file type-id.cc.
References m_information, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by AddAttribute(), AddConstructor(), AddTraceSource(), AllocateUid(), GetAttributeN(), GetConstructor(), GetGroupName(), GetHash(), GetName(), GetParent(), GetSize(), GetTraceSourceN(), HasAttribute(), HasConstructor(), HasTraceSource(), HideFromDocumentation(), MustHideFromDocumentation(), SetAttributeInitialValue(), SetGroupName(), SetParent(), and SetSize().
bool ns3::IidManager::MustHideFromDocumentation | ( | uint16_t | uid | ) | const |
Definition at line 526 of file type-id.cc.
References LookupInformation(), ns3::IidManager::IidInformation::mustHideFromDocumentation, and NS_LOG_FUNCTION.
void ns3::IidManager::SetAttributeInitialValue | ( | uint16_t | uid, |
uint32_t | i, | ||
Ptr< const AttributeValue > | initialValue | ||
) |
Definition at line 433 of file type-id.cc.
References ns3::IidManager::IidInformation::attributes, LookupInformation(), NS_ASSERT, and NS_LOG_FUNCTION.
void ns3::IidManager::SetGroupName | ( | uint16_t | uid, |
std::string | groupName | ||
) |
Definition at line 248 of file type-id.cc.
References ns3::IidManager::IidInformation::groupName, LookupInformation(), and NS_LOG_FUNCTION.
void ns3::IidManager::SetParent | ( | uint16_t | uid, |
uint16_t | parent | ||
) |
Definition at line 240 of file type-id.cc.
References LookupInformation(), m_information, NS_ASSERT, NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::parent.
void ns3::IidManager::SetSize | ( | uint16_t | uid, |
std::size_t | size | ||
) |
Definition at line 255 of file type-id.cc.
References LookupInformation(), NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::size.
|
private |
Definition at line 139 of file type-id.cc.
Referenced by AllocateUid(), and GetUid().
|
private |
Definition at line 133 of file type-id.cc.
Referenced by AllocateUid(), GetRegisteredN(), LookupInformation(), and SetParent().
|
private |
Definition at line 136 of file type-id.cc.
Referenced by AllocateUid(), and GetUid().