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::invoke_result_t<decltype(&A::Get), A>
item_type;
86 template <
class CONTAINER>
121 void Set (
const T &c);
178 template <
class ITER>
207 template <
class A,
template <
class...>
class C>
218 template <
class A,
template <
class...>
class C=
std::list>
228 template <
class A,
template <
class...>
class C=
std::list>
238 template <
typename A,
template <
typename...>
class C=
std::list,
typename T1>
257 template <
class A,
template <
class...>
class C>
274 template <
class A,
template <
class...>
class C>
279 template <
class A,
template <
class...>
class C>
281 : m_itemchecker (itemchecker)
284 template <
class A,
template <
class...>
class C>
288 m_itemchecker = itemchecker;
291 template <
class A,
template <
class...>
class C>
295 return m_itemchecker;
300 template <
class A,
template <
class...>
class C>
304 return MakeAttributeContainerChecker <A, C> ();
307 template <
class A,
template <
class...>
class C>
308 Ptr<const AttributeChecker>
311 auto checker = MakeAttributeContainerChecker <A, C> ();
312 auto acchecker = DynamicCast<AttributeContainerChecker> (checker);
313 acchecker->SetItemChecker (itemchecker);
317 template <
class A,
template <
class...>
class C>
318 Ptr<AttributeChecker>
321 std::string containerType;
322 std::string underlyingType;
325 std::ostringstream oss;
326 oss <<
"ns3::AttributeContainerValue<" <<
typeid (
typename T::attribute_type).name ()
327 <<
", " <<
typeid (
typename T::container_type).name () <<
">";
328 containerType = oss.str ();
332 std::ostringstream oss;
333 oss <<
"ns3::Ptr<" <<
typeid (
typename T::attribute_type).name () <<
">";
334 underlyingType = oss.str ();
337 return MakeSimpleAttributeChecker<T, internal::AttributeContainerChecker<A, C> > (containerType, underlyingType);
340 template <
class A,
template <
class...>
class C>
347 template <
class A,
template <
class...>
class C>
348 template <
class CONTAINER>
355 template <
class A,
template <
class...>
class C>
356 template <
class ITER>
363 template <
class A,
template <
class...>
class C>
366 m_container.clear ();
369 template <
class A,
template <
class...>
class C>
373 auto c = Create<AttributeContainerValue<A, C> > ();
375 c->m_container = m_container;
379 template <
class A,
template <
class...>
class C>
383 auto acchecker = DynamicCast<const AttributeContainerChecker> (checker);
384 if (!acchecker)
return false;
386 std::istringstream iss (value);
387 while (std::getline (iss, value, m_sep))
389 auto avalue = acchecker->GetItemChecker ()->CreateValidValue (
StringValue (value));
390 if (!avalue)
return false;
392 auto attr = DynamicCast <A> (avalue);
393 if (!attr)
return false;
396 m_container.push_back (attr);
401 template <
class A,
template <
class...>
class C>
405 std::ostringstream oss;
407 for (
auto attr: *
this)
409 if (!
first) oss << m_sep;
410 oss << attr->SerializeToString (checker);
416 template <
class A,
template <
class...>
class C>
422 c.insert (c.end (), a->Get ());
426 template <
class A,
template <
class...>
class C>
431 m_container.clear ();
432 CopyFrom (c.begin (), c.end ());
435 template <
class A,
template <
class...>
class C>
442 template <
class A,
template <
class...>
class C>
449 template <
class A,
template <
class...>
class C>
456 template <
class A,
template <
class...>
class C>
460 return m_container.size ();
463 template <
class A,
template <
class...>
class C>
467 return m_container.begin ();
470 template <
class A,
template <
class...>
class C>
474 return m_container.end ();
477 template <
class A,
template <
class...>
class C>
481 return m_container.cbegin ();
484 template <
class A,
template <
class...>
class C>
488 return m_container.cend ();
491 template <
class A,
template <
class...>
class C>
492 template <
class ITER>
496 for (ITER iter = begin; iter != end; ++iter)
498 m_container.push_back (Create<A> (*iter));
503 template <
typename A,
template <
typename...>
class C,
typename T1>
506 return MakeAccessorHelper<AttributeContainerValue<A, C> > (a1);
Represent the type of an attribute.
AttributeChecker implementation for AttributeContainerValue.
virtual Ptr< const AttributeChecker > GetItemChecker(void) const =0
Get the item checker.
virtual void SetItemChecker(Ptr< const AttributeChecker > itemchecker)=0
Set the item checker.
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::invoke_result_t< decltype(&A::Get), A > item_type
Item type of container returned by Get.
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.
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
The AttributeChecker.
AttributeContainerChecker(void)
Ptr< const AttributeChecker > GetItemChecker(void) const
Get the item checker.
void SetItemChecker(Ptr< const AttributeChecker > itemchecker)
Set the item checker.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeAttributeContainerAccessor(T1 a1)
Make AttributeContainerAccessor using explicit types.
Ptr< AttributeChecker > MakeAttributeContainerChecker(const AttributeContainerValue< A, C > &value)
Make AttributeContainerChecker from AttributeContainerValue.