NS3中,每个类都包含了一个typeid。一个类的typeid主要用来记录与这个类相关的属性,trace源,继承树之类的信息。
一 内部类型
在TypeId类中,定义了三个内部类型:
1.1 AttributeFlag : 属性标志,用来表面TypeId类 内部所含属性 的性质,如可读/可写/可在构造时赋值/以上三中都有,具体定义如下
enum AttributeFlag {
ATTR_GET = 1<<0, /**< The attribute can be read */
ATTR_SET = 1<<1, /**< The attribute can be written */
ATTR_CONSTRUCT = 1<<2, /**< The attribute can be written at construction-time */
ATTR_SGC = ATTR_GET | ATTR_SET | ATTR_CONSTRUCT, /**< The attribute can be read, and written at any time */
};
1.2 AttributeInformation: 属性信息,TypeId中保存的任何一个属性都有一个对应的该类型结构体
struct AttributeInformation {
std::string name;
std::string help;
uint32_t flags;
Ptr<const AttributeValue> originalInitialValue;
Ptr<const AttributeValue> initialValue;
Ptr<const AttributeAccessor> accessor;
Ptr<const AttributeChecker> checker;
};
1.3 TraceSourceInformation: 这个主要是与TraceSource相关的信息结构体,不知怎么翻译-_-||
二 内部方法
2.1 构造函数
TypeId::TypeId (const char *name)
{
NS_LOG_FUNCTION (this << name);
uint16_t uid = Singleton<IidManager>::Get ()->AllocateUid (name);
NS_ASSERT (uid != 0);
m_tid = uid;
}
TypeId::TypeId (uint16_t tid)
: m_tid (tid)
{
NS_LOG_FUNCTION (this << tid);
}
两个构造函数重点都在m_tid变量的初始化上面。每个typeid类都保存有一个唯一的m_tid,这是一个16bit整数。针对第一个构造函数,参数是一个name字符串,内部通过调用IidManager类的AllocateUid来获得其m_tid。
IidManager 这个类的作用是一个帮助