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) |
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 |
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) |
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 134 of file type-id.cc.
|
private |
Definition at line 125 of file type-id.cc.
|
private |
Definition at line 131 of file type-id.cc.
|
private |
Definition at line 140 of file type-id.cc.
ns3::IidManager::IidManager | ( | ) |
Definition at line 143 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 388 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 258 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 | ||
) |
Definition at line 471 of file type-id.cc.
References ns3::TypeId::TraceSourceInformation::accessor, 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 157 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, and ns3::IidManager::IidInformation::parent.
|
read |
Definition at line 434 of file type-id.cc.
References NS_ASSERT, and NS_LOG_FUNCTION.
uint32_t ns3::IidManager::GetAttributeN | ( | uint16_t | uid | ) | const |
Definition at line 427 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 327 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 319 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 305 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 298 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 312 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 353 of file type-id.cc.
References NS_LOG_FUNCTION.
uint32_t ns3::IidManager::GetRegisteredN | ( | void | ) | const |
Definition at line 347 of file type-id.cc.
References m_information, and NS_LOG_FUNCTION.
|
read |
Definition at line 497 of file type-id.cc.
References NS_ASSERT, and NS_LOG_FUNCTION.
uint32_t ns3::IidManager::GetTraceSourceN | ( | uint16_t | uid | ) | const |
Definition at line 490 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 271 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 285 of file type-id.cc.
References m_hashmap.
|
private |
Definition at line 360 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 339 of file type-id.cc.
References ns3::IidManager::IidInformation::hasConstructor, LookupInformation(), and NS_LOG_FUNCTION.
|
staticprivate |
Definition at line 150 of file type-id.cc.
References ns3::Hasher::clear(), and ns3::Hasher::GetHash32().
Referenced by AllocateUid().
|
private |
Definition at line 443 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 250 of file type-id.cc.
References LookupInformation(), ns3::IidManager::IidInformation::mustHideFromDocumentation, and NS_LOG_FUNCTION.
|
readprivate |
Definition at line 227 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(), GetTraceSourceN(), HasAttribute(), HasConstructor(), HasTraceSource(), HideFromDocumentation(), MustHideFromDocumentation(), SetAttributeInitialValue(), SetGroupName(), and SetParent().
bool ns3::IidManager::MustHideFromDocumentation | ( | uint16_t | uid | ) | const |
Definition at line 505 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 414 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 243 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 235 of file type-id.cc.
References LookupInformation(), m_information, NS_ASSERT, NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::parent.
|
private |
Definition at line 135 of file type-id.cc.
Referenced by AllocateUid(), and GetUid().
|
private |
Definition at line 129 of file type-id.cc.
Referenced by AllocateUid(), GetRegisteredN(), LookupInformation(), and SetParent().
|
private |
Definition at line 132 of file type-id.cc.
Referenced by AllocateUid(), and GetUid().