19 #ifndef ATTRIBUTE_HELPER_H
20 #define ATTRIBUTE_HELPER_H
97 template <
typename T,
typename BASE>
105 struct SimpleAttributeChecker :
public BASE
109 return dynamic_cast<const T*
>(&value) !=
nullptr;
112 std::string GetValueTypeName()
const override
114 if (m_type.rfind(
"ns3::", 0) == 0)
119 return "ns3::" + m_type;
122 bool HasUnderlyingTypeInformation()
const override
127 std::string GetUnderlyingTypeInformation()
const override
134 return ns3::Create<T>();
139 const T* src =
dynamic_cast<const T*
>(&source);
140 T* dst =
dynamic_cast<T*
>(&destination);
141 if (src ==
nullptr || dst ==
nullptr)
150 std::string m_underlying;
151 }* checker =
new SimpleAttributeChecker();
153 checker->m_type = name;
154 checker->m_underlying = underlying;
174 #define ATTRIBUTE_ACCESSOR_DEFINE(type) \
175 template <typename T1> \
176 Ptr<const AttributeAccessor> Make##type##Accessor(T1 a1) \
178 return MakeAccessorHelper<type##Value>(a1); \
180 template <typename T1, typename T2> \
181 Ptr<const AttributeAccessor> Make##type##Accessor(T1 a1, T2 a2) \
183 return MakeAccessorHelper<type##Value>(a1, a2); \
203 #define ATTRIBUTE_VALUE_DEFINE_WITH_NAME(type, name) \
204 class name##Value : public AttributeValue \
208 name##Value(const type& value); \
209 void Set(const type& value); \
211 template <typename T> \
212 bool GetAccessor(T& value) const \
214 value = T(m_value); \
217 Ptr<AttributeValue> Copy() const override; \
218 std::string SerializeToString(Ptr<const AttributeChecker> checker) const override; \
219 bool DeserializeFromString(std::string value, \
220 Ptr<const AttributeChecker> checker) override; \
237 #define ATTRIBUTE_VALUE_DEFINE(name) ATTRIBUTE_VALUE_DEFINE_WITH_NAME(name, name)
254 #define ATTRIBUTE_CONVERTER_DEFINE(type)
272 #define ATTRIBUTE_CHECKER_DEFINE(type) \
273 class type##Checker : public AttributeChecker \
276 Ptr<const AttributeChecker> Make##type##Checker()
294 #define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type, name) \
295 name##Value::name##Value() \
299 name##Value::name##Value(const type& value) \
303 void name##Value::Set(const type& v) \
307 type name##Value::Get() const \
311 Ptr<AttributeValue> name##Value::Copy() const \
313 return ns3::Create<name##Value>(*this); \
315 std::string name##Value::SerializeToString(Ptr<const AttributeChecker> checker) const \
317 std::ostringstream oss; \
321 bool name##Value::DeserializeFromString(std::string value, \
322 Ptr<const AttributeChecker> checker) \
324 std::istringstream iss; \
327 NS_ABORT_MSG_UNLESS(iss.eof(), \
329 << "\"" << value << "\"" \
330 << " is not properly formatted"); \
331 return !iss.bad() && !iss.fail(); \
348 #define ATTRIBUTE_VALUE_IMPLEMENT(type) ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type, type)
361 #define ATTRIBUTE_CHECKER_IMPLEMENT(type) \
362 Ptr<const AttributeChecker> Make##type##Checker() \
364 return MakeSimpleAttributeChecker<type##Value, type##Checker>(#type "Value", #type); \
380 #define ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME(type, name) \
381 Ptr<const AttributeChecker> Make##type##Checker() \
383 return MakeSimpleAttributeChecker<type##Value, type##Checker>(#type "Value", name); \
407 #define ATTRIBUTE_HELPER_HEADER(type) \
408 ATTRIBUTE_VALUE_DEFINE(type); \
409 ATTRIBUTE_ACCESSOR_DEFINE(type); \
410 ATTRIBUTE_CHECKER_DEFINE(type)
429 #define ATTRIBUTE_HELPER_CPP(type) \
430 ATTRIBUTE_CHECKER_IMPLEMENT(type); \
431 ATTRIBUTE_VALUE_IMPLEMENT(type)
NS_ABORT_x macro definitions.
ns3::MakeAccessorHelper declarations and template implementations.
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Hold a value for an Attribute.
Smart pointer class similar to boost::intrusive_ptr.
Ptr< AttributeChecker > MakeSimpleAttributeChecker(std::string name, std::string underlying)
A simple string-based attribute checker.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.