NS3 仿真器 之 typeid 类知识学习

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 这个类的作用是一个帮助

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值