A Discrete-Event Network Simulator
API
Attribute Helper

All these macros can be used to generate automatically the code for subclasses of AttributeValue, AttributeAccessor, and, AttributeChecker, which can be used to give attribute powers to a normal class. More...

+ Collaboration diagram for Attribute Helper:

Modules

 Attribute Implementation
 These are the internal implementation functions for the Attribute system.
 

Files

file  attribute-helper.h
 Attribute helper (ATTRIBUTE_ )macros definition.
 

Macros

#define ATTRIBUTE_ACCESSOR_DEFINE(type)
 Define the attribute accessor functions MakeTypeAccessor for class type. More...
 
#define ATTRIBUTE_CHECKER_DEFINE(type)
 Declare the AttributeChecker class typeChecker and the MaketypeChecker function for class type. More...
 
#define ATTRIBUTE_CHECKER_IMPLEMENT(type)
 Define the MaketypeChecker function for class type. More...
 
#define ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME(type, name)
 Define the MaketypeChecker function for class type. More...
 
#define ATTRIBUTE_CONVERTER_DEFINE(type)
 Define the conversion operators class type and Attribute instances. More...
 
#define ATTRIBUTE_HELPER_CPP(type)
 Define the attribute value, accessor and checkers for class type. More...
 
#define ATTRIBUTE_HELPER_HEADER(type)
 Declare the attribute value, accessor and checkers for class type. More...
 
#define ATTRIBUTE_VALUE_DEFINE(name)   ATTRIBUTE_VALUE_DEFINE_WITH_NAME (name,name)
 Declare the attribute value class nameValue for the class name. More...
 
#define ATTRIBUTE_VALUE_DEFINE_WITH_NAME(type, name)
 Declare the attribute value class nameValue for underlying class type. More...
 
#define ATTRIBUTE_VALUE_IMPLEMENT(type)   ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (type,type)
 Define the class methods belonging to attribute value class typeValue for class type. More...
 
#define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type, name)
 Define the class methods belonging to the attribute value class nameValue of the underlying class type. More...
 

Detailed Description

All these macros can be used to generate automatically the code for subclasses of AttributeValue, AttributeAccessor, and, AttributeChecker, which can be used to give attribute powers to a normal class.

i.e., the user class can then effectively be made an attribute.

There are two kinds of helper macros:

  1. The simple macros.
  2. The more complex macros.

The simple macros are implemented in terms of the complex macros and should generally be preferred over the complex macros.

Note
Because these macros generate class and function definitions, it's difficult to document the results directly. Instead, we use a set of functions in print-introspected-doxygen.cc to generate most of the APi documentation. When using these macros, please add the required function calls to print-introspected-doxygen.cc so your new API is documented.

Macro Definition Documentation

◆ ATTRIBUTE_ACCESSOR_DEFINE

#define ATTRIBUTE_ACCESSOR_DEFINE (   type)
Value:
template <typename T1> \
Ptr<const AttributeAccessor> Make ## type ## Accessor (T1 a1) \
{ \
return MakeAccessorHelper<type ## Value> (a1); \
} \
template <typename T1, typename T2> \
Ptr<const AttributeAccessor> Make ## type ## Accessor (T1 a1, T2 a2) \
{ \
return MakeAccessorHelper<type ## Value> (a1, a2); \
}

Define the attribute accessor functions MakeTypeAccessor for class type.

Parameters
[in]typeThe name of the class

This macro defines and generates the code for the implementation of the MakeTypeAccessor template functions. This macro is typically invoked in a class header to allow users of this class to view and use the template functions defined here. This macro is implemented through the helper templates functions ns3::MakeAccessorHelper<>.

Definition at line 155 of file attribute-helper.h.

◆ ATTRIBUTE_CHECKER_DEFINE

#define ATTRIBUTE_CHECKER_DEFINE (   type)
Value:
class type ## Checker : public AttributeChecker {}; \
Ptr<const AttributeChecker> Make ## type ## Checker (void)

Declare the AttributeChecker class typeChecker and the MaketypeChecker function for class type.

Parameters
[in]typeThe name of the class

This macro declares the typeChecker class and the associated MaketypeChecker function.

(Note that the typeChecker class needs no implementation since it just inherits all its implementation from AttributeChecker.)

Typically invoked in the class header file.

Definition at line 256 of file attribute-helper.h.

◆ ATTRIBUTE_CHECKER_IMPLEMENT

#define ATTRIBUTE_CHECKER_IMPLEMENT (   type)
Value:
Ptr<const AttributeChecker> Make ## type ## Checker (void) { \
return MakeSimpleAttributeChecker<type ## Value,type ## Checker> \
(# type "Value", # type); \
} \

Define the MaketypeChecker function for class type.

Parameters
[in]typeThe name of the class

This macro implements the MaketypeChecker function.

Typically invoked in the source file..

Definition at line 338 of file attribute-helper.h.

◆ ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME

#define ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME (   type,
  name 
)
Value:
Ptr<const AttributeChecker> Make ## type ## Checker (void) { \
return MakeSimpleAttributeChecker<type ## Value,type ## Checker> \
(# type "Value", name); \
} \

Define the MaketypeChecker function for class type.

Parameters
[in]typeThe name of the class.
[in]nameThe string name of the underlying type.

This macro implements the MaketypeChecker function for class type.

Typically invoked in the source file..

Definition at line 357 of file attribute-helper.h.

◆ ATTRIBUTE_CONVERTER_DEFINE

#define ATTRIBUTE_CONVERTER_DEFINE (   type)

Define the conversion operators class type and Attribute instances.

Parameters
[in]typeThe name of the class

This macro defines the conversion operators for class type to and from instances of typeAttribute. Typically invoked in the class header file.

Internal:
This appears to be unused in the current code base.

Definition at line 238 of file attribute-helper.h.

◆ ATTRIBUTE_HELPER_CPP

#define ATTRIBUTE_HELPER_CPP (   type)
Value:
ATTRIBUTE_VALUE_IMPLEMENT (type)
#define ATTRIBUTE_CHECKER_IMPLEMENT(type)
Define the MaketypeChecker function for class type.

Define the attribute value, accessor and checkers for class type.

Parameters
[in]typeThe name of the class

This macro implements

  • The typeValue class methods,
  • The MaketypeChecker function,

for class type.

This macro should be invoked from the class implementation file.

Definition at line 406 of file attribute-helper.h.

◆ ATTRIBUTE_HELPER_HEADER

#define ATTRIBUTE_HELPER_HEADER (   type)
Value:
ATTRIBUTE_ACCESSOR_DEFINE (type); \
ATTRIBUTE_CHECKER_DEFINE (type)
#define ATTRIBUTE_VALUE_DEFINE(name)
Declare the attribute value class nameValue for the class name.

Declare the attribute value, accessor and checkers for class type.

Parameters
[in]typeThe name of the class

This macro declares:

  • The attribute value class typeValue,
  • The attribute accessor functions MaketypeAccessor,
  • The AttributeChecker class typeChecker and the MaketypeChecker function,

for class type.

This macro should be invoked outside of the class declaration in its public header.

Definition at line 384 of file attribute-helper.h.

◆ ATTRIBUTE_VALUE_DEFINE

#define ATTRIBUTE_VALUE_DEFINE (   name)    ATTRIBUTE_VALUE_DEFINE_WITH_NAME (name,name)

Declare the attribute value class nameValue for the class name.

Parameters
[in]nameThe name of the class.

This macro declares the class nameValue associated to class name. This macro is typically invoked in the class header file.

Definition at line 219 of file attribute-helper.h.

◆ ATTRIBUTE_VALUE_DEFINE_WITH_NAME

#define ATTRIBUTE_VALUE_DEFINE_WITH_NAME (   type,
  name 
)
Value:
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 GetAccessor (T &value) const { \
value = T (m_value); \
return true; \
} \
virtual Ptr<AttributeValue> Copy (void) const; \
virtual std::string \
SerializeToString (Ptr<const AttributeChecker> checker) const; \
virtual bool \
DeserializeFromString (std::string value, \
Ptr<const AttributeChecker> checker); \
private: \
type m_value; \
}
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:805
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition: ptr.h:688

Declare the attribute value class nameValue for underlying class type.

Parameters
[in]typeThe underlying type name token
[in]nameThe token to use in defining the accessor name.

This macro declares the class typeValue associated with class type. This macro is typically invoked in the class header file.

This can be used directly for things like plain old data, such as std::string, to create the attribute value class StringValue, as in ATTRIBUTE_VALUE_DEFINE_WITH_NAME(std::string, String);

Definition at line 184 of file attribute-helper.h.

◆ ATTRIBUTE_VALUE_IMPLEMENT

#define ATTRIBUTE_VALUE_IMPLEMENT (   type)    ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (type,type)

Define the class methods belonging to attribute value class typeValue for class type.

Parameters
[in]typeThe name of the class.

This macro implements the typeValue class methods (including the typeValue::SerializeToString and typeValue::DeserializeFromString methods).

Typically invoked in the source file.

Definition at line 323 of file attribute-helper.h.

◆ ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME

#define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (   type,
  name 
)
Value:
name ## Value::name ## Value () \
: m_value () {} \
name ## Value::name ## Value (const type &value) \
: m_value (value) {} \
void name ## Value::Set (const type &v) { \
m_value = v; \
} \
type name ## Value::Get (void) const { \
return m_value; \
} \
Ptr<AttributeValue> \
name ## Value::Copy (void) const { \
return ns3::Create<name ## Value> (*this); \
} \
std::string name ## Value::SerializeToString \
(Ptr<const AttributeChecker> checker) const { \
std::ostringstream oss; \
oss << m_value; \
return oss.str (); \
} \
bool name ## Value::DeserializeFromString \
(std::string value, Ptr<const AttributeChecker> checker) { \
std::istringstream iss; \
iss.str (value); \
iss >> m_value; \
NS_ABORT_MSG_UNLESS (iss.eof (), \
"Attribute value " << "\"" << value << "\"" \
<< " is not properly formatted"); \
return !iss.bad () && !iss.fail (); \
}
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:805
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
Definition: ptr.h:688

Define the class methods belonging to the attribute value class nameValue of the underlying class type.

Parameters
[in]typeThe underlying type name
[in]nameThe token to use in defining the accessor name.

This macro implements the typeValue class methods (including the typeValue::SerializeToString and typeValue::DeserializeFromString methods).

Typically invoked in the source file

Definition at line 277 of file attribute-helper.h.