在NS3中,每个类都有与之相关的属性,这些属性可以看作是对基本类型的封装,这些属性存储在与类相关的TypeId类中。下面来介绍一下attribute的相关实现:
与属性相关的文件主要位于src/core/model文件夹下面文件名中带有attribute关键字的文件
最基本的类有三个:AttributeValue ,AttributeAccessor和 AttributeChecker 另外还有一个特殊的EmptyAttributeValue
在NS3中,任何属性,都有三个相关量,即属性值,属性访问器,属性检查器。
如果要定义自己的类型,则需要分别创建相应的AttributeValue ,AttributeAccessor和 AttributeChecker。为了方便创建,NS3为我们定义了一些宏,位于文件attribute-helper中。
现在,以integer.h文件中对integer类型的定义为例进行学习:
首先,文件中使用了两个宏,如下所示:
ATTRIBUTE_VALUE_DEFINE_WITH_NAME (int64_t, Integer);
ATTRIBUTE_ACCESSOR_DEFINE (Integer);
从attribute-helper.h中可以找到宏的定义:
#define ATTRIBUTE_VALUE_DEFINE_WITH_NAME(type,name) \
class name ## Value : public AttributeValue \
{ \
public: \
name ## Value (); \
name ## Value (const type &value); \
void Set (const type &value); \
type Get (void) const; \
template <typename T> \
bool