20 #ifndef ATTRIBUTE_HELPER_H
21 #define ATTRIBUTE_HELPER_H
96 template <
typename T,
typename BASE>
104 struct SimpleAttributeChecker :
public BASE
108 return dynamic_cast<const T *
> (&value) != 0;
110 virtual std::string GetValueTypeName (
void)
const
114 virtual bool HasUnderlyingTypeInformation (
void)
const
118 virtual std::string GetUnderlyingTypeInformation (
void)
const
124 return ns3::Create<T> ();
128 const T *src =
dynamic_cast<const T *
> (&source);
129 T *dst =
dynamic_cast<T *
> (&destination);
130 if (src == 0 || dst == 0)
138 std::string m_underlying;
139 } *checker =
new SimpleAttributeChecker ();
140 checker->m_type = name;
141 checker->m_underlying = underlying;
161 #define ATTRIBUTE_ACCESSOR_DEFINE(type) \
162 template <typename T1> \
163 Ptr<const AttributeAccessor> Make ## type ## Accessor (T1 a1) \
165 return MakeAccessorHelper<type ## Value> (a1); \
167 template <typename T1, typename T2> \
168 Ptr<const AttributeAccessor> Make ## type ## Accessor (T1 a1, T2 a2) \
170 return MakeAccessorHelper<type ## Value> (a1, a2); \
190 #define ATTRIBUTE_VALUE_DEFINE_WITH_NAME(type,name) \
191 class name ## Value : public AttributeValue \
195 name ## Value (const type &value); \
196 void Set (const type &value); \
197 type Get (void) const; \
198 template <typename T> \
199 bool GetAccessor (T & value) const { \
200 value = T (m_value); \
203 virtual Ptr<AttributeValue> Copy (void) const; \
204 virtual std::string \
205 SerializeToString (Ptr<const AttributeChecker> checker) const; \
207 DeserializeFromString (std::string value, \
208 Ptr<const AttributeChecker> checker); \
225 #define ATTRIBUTE_VALUE_DEFINE(name) \
226 ATTRIBUTE_VALUE_DEFINE_WITH_NAME (name,name)
244 #define ATTRIBUTE_CONVERTER_DEFINE(type)
262 #define ATTRIBUTE_CHECKER_DEFINE(type) \
263 class type ## Checker : public AttributeChecker {}; \
264 Ptr<const AttributeChecker> Make ## type ## Checker (void)
283 #define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type,name) \
284 name ## Value::name ## Value () \
286 name ## Value::name ## Value (const type &value) \
287 : m_value (value) {} \
288 void name ## Value::Set (const type &v) { \
291 type name ## Value::Get (void) const { \
294 Ptr<AttributeValue> \
295 name ## Value::Copy (void) const { \
296 return ns3::Create<name ## Value> (*this); \
298 std::string name ## Value::SerializeToString \
299 (Ptr<const AttributeChecker> checker) const { \
300 std::ostringstream oss; \
304 bool name ## Value::DeserializeFromString \
305 (std::string value, Ptr<const AttributeChecker> checker) { \
306 std::istringstream iss; \
309 NS_ABORT_MSG_UNLESS (iss.eof (), \
310 "Attribute value " << "\"" << value << "\"" << \
311 " is not properly formatted"); \
312 return !iss.bad () && !iss.fail (); \
329 #define ATTRIBUTE_VALUE_IMPLEMENT(type) \
330 ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (type,type)
344 #define ATTRIBUTE_CHECKER_IMPLEMENT(type) \
345 Ptr<const AttributeChecker> Make ## type ## Checker (void) { \
346 return MakeSimpleAttributeChecker<type ## Value,type ## Checker> \
347 (# type "Value", # type); \
363 #define ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME(type,name) \
364 Ptr<const AttributeChecker> Make ## type ## Checker (void) { \
365 return MakeSimpleAttributeChecker<type ## Value,type ## Checker> \
366 (# type "Value", name); \
390 #define ATTRIBUTE_HELPER_HEADER(type) \
391 ATTRIBUTE_VALUE_DEFINE (type); \
392 ATTRIBUTE_ACCESSOR_DEFINE (type); \
393 ATTRIBUTE_CHECKER_DEFINE (type)
412 #define ATTRIBUTE_HELPER_CPP(type) \
413 ATTRIBUTE_CHECKER_IMPLEMENT (type); \
414 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.