21 #ifndef ATTRIBUTE_CONTAINER_H
22 #define ATTRIBUTE_CONTAINER_H
24 #include <ns3/attribute-helper.h>
25 #include <ns3/string.h>
32 #include <type_traits>
37 class AttributeChecker;
50 template <
class A,
template<
class...>
class C=
std::list>
63 typedef typename container_type::iterator
iterator;
65 typedef typename container_type::size_type
size_type;
71 typedef typename std::result_of<decltype(&A::Get)(A)>::type
item_type;
86 template <
class CONTAINER>
121 void Set (
const T &c);
178 template <
class ITER>
199 template <
class A,
template <
class...>
class C>
210 template <
class A,
template <
class...>
class C=
std::list>
220 template <
class A,
template <
class...>
class C=
std::list>
223 template <
typename A,
template <
typename...>
class C=
std::list,
typename T1>
240 template <
class A,
template <
class...>
class C>
253 template <
class A,
template <
class...>
class C>
258 template <
class A,
template <
class...>
class C>
260 : m_itemchecker (itemchecker)
263 template <
class A,
template <
class...>
class C>
267 m_itemchecker = itemchecker;
270 template <
class A,
template <
class...>
class C>
274 return m_itemchecker;
279 template <
class A,
template <
class...>
class C>
283 return MakeAttributeContainerChecker <A, C> ();
286 template <
class A,
template <
class...>
class C>
287 Ptr<const AttributeChecker>
290 auto checker = MakeAttributeContainerChecker <A, C> ();
291 auto acchecker = DynamicCast<AttributeContainerChecker> (checker);
292 acchecker->SetItemChecker (itemchecker);
296 template <
class A,
template <
class...>
class C>
297 Ptr<AttributeChecker>
300 std::string containerType;
301 std::string underlyingType;
304 std::ostringstream oss;
305 oss <<
"ns3::AttributeContainerValue<" <<
typeid (
typename T::attribute_type).name ()
306 <<
", " <<
typeid (
typename T::container_type).name () <<
">";
307 containerType = oss.str ();
311 std::ostringstream oss;
312 oss <<
"ns3::Ptr<" <<
typeid (
typename T::attribute_type).name () <<
">";
313 underlyingType = oss.str ();
316 return MakeSimpleAttributeChecker<T, internal::AttributeContainerChecker<A, C> > (containerType, underlyingType);
319 template <
class A,
template <
class...>
class C>
326 template <
class A,
template <
class...>
class C>
327 template <
class CONTAINER>
334 template <
class A,
template <
class...>
class C>
335 template <
class ITER>
342 template <
class A,
template <
class...>
class C>
345 m_container.clear ();
348 template <
class A,
template <
class...>
class C>
352 auto c = Create<AttributeContainerValue<A, C> > ();
354 c->m_container = m_container;
358 template <
class A,
template <
class...>
class C>
362 auto acchecker = DynamicCast<const AttributeContainerChecker> (checker);
363 if (!acchecker)
return false;
365 std::istringstream iss (value);
366 while (std::getline (iss, value, m_sep))
368 auto avalue = acchecker->GetItemChecker ()->CreateValidValue (
StringValue (value));
369 if (!avalue)
return false;
371 auto attr = DynamicCast <A> (avalue);
372 if (!attr)
return false;
375 m_container.push_back (attr);
380 template <
class A,
template <
class...>
class C>
384 std::ostringstream oss;
386 for (
auto attr: *
this)
388 if (!
first) oss << m_sep;
389 oss << attr->SerializeToString (checker);
395 template <
class A,
template <
class...>
class C>
401 c.insert (c.end (), a->Get ());
405 template <
class A,
template <
class...>
class C>
410 m_container.clear ();
411 CopyFrom (c.begin (), c.end ());
414 template <
class A,
template <
class...>
class C>
421 template <
class A,
template <
class...>
class C>
428 template <
class A,
template <
class...>
class C>
435 template <
class A,
template <
class...>
class C>
439 return m_container.size ();
442 template <
class A,
template <
class...>
class C>
446 return m_container.begin ();
449 template <
class A,
template <
class...>
class C>
453 return m_container.end ();
456 template <
class A,
template <
class...>
class C>
460 return m_container.cbegin ();
463 template <
class A,
template <
class...>
class C>
467 return m_container.cend ();
470 template <
class A,
template <
class...>
class C>
471 template <
class ITER>
475 for (ITER iter = begin; iter != end; ++iter)
477 m_container.push_back (Create<A> (*iter));
482 template <
typename A,
template <
typename...>
class C,
typename T1>
485 return MakeAccessorHelper<AttributeContainerValue<A, C> > (a1);
Represent the type of an attribute.
AttributeChecker implementation for AttributeContainerValue.
virtual Ptr< const AttributeChecker > GetItemChecker(void) const =0
virtual void SetItemChecker(Ptr< const AttributeChecker > itemchecker)=0
A container for one type of attribute.
std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Ptr< A > value_type
Type actually stored within the container.
void Set(const T &c)
Copy items from container c.
result_type Get(void) const
Return a container of items.
Iterator End(void)
NS3-style ending of container.
~AttributeContainerValue()
Destructor.
Ptr< AttributeValue > Copy(void) const
container_type::size_type size_type
Size type for container.
std::list< value_type > container_type
Internal container type.
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
container_type m_container
Internal container.
size_type GetN(void) const
NS3-style Number of items.
container_type::iterator iterator
stl-style Non-const iterator type.
char m_sep
Item separator.
std::result_of< decltype(&A::Get)(A)>::type item_type
Item type of container returned by Get.
size_type size(void) const
STL-style number of items in container.
iterator end(void)
STL-style end of container.
A attribute_type
AttributeValue (element) type.
Iterator Begin(void)
NS3-style beginning of container.
AttributeContainerValue(char sep=',')
Default constructor.
C< item_type > result_type
Type of container returned.
container_type::const_iterator const_iterator
stl-style Const iterator type.
Ptr< AttributeContainerValue< A, C > > CopyFrom(const ITER begin, const ITER end)
Copy items from begin to end.
iterator begin(void)
STL-style beginning of container.
AttributeContainerValue::const_iterator Iterator
NS3 style iterator type.
Hold a value for an Attribute.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
Ptr< const AttributeChecker > m_itemchecker
AttributeContainerChecker(void)
Ptr< const AttributeChecker > GetItemChecker(void) const
void SetItemChecker(Ptr< const AttributeChecker > itemchecker)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeAttributeContainerAccessor(T1 a1)
Ptr< AttributeChecker > MakeAttributeContainerChecker(const AttributeContainerValue< A, C > &value)
Make AttributeContainerChecker from AttributeContainerValue.