20#ifndef ATTRIBUTE_CONTAINER_H
21#define ATTRIBUTE_CONTAINER_H
23#include <ns3/attribute-helper.h>
24#include <ns3/string.h>
37class AttributeChecker;
51template <
class A,
char Sep =
',',
template <
class...>
class C = std::list>
64 typedef typename container_type::iterator
iterator;
66 typedef typename container_type::size_type
size_type;
72 typedef typename std::invoke_result_t<
decltype(&A::Get), A>
item_type;
86 template <
class CONTAINER>
121 void Set(
const T& c);
130 template <
typename T>
188 template <
class ITER>
217template <
class A,
char Sep,
template <
class...>
class C>
229template <
class A,
char Sep =
',',
template <
class...>
class C = std::list>
239template <
class A,
char Sep =
',',
template <
class...>
class C = std::list>
253template <
typename A,
char Sep =
',',
template <
typename...>
class C = std::list,
typename T1>
272 template <
typename...>
class C = std::list,
295template <
class A,
char Sep,
template <
class...>
class C>
312template <
class A,
char Sep,
template <
class...>
class C>
314 : m_itemchecker(nullptr)
318template <
class A,
char Sep,
template <
class...>
class C>
321 : m_itemchecker(itemchecker)
325template <
class A,
char Sep,
template <
class...>
class C>
329 m_itemchecker = itemchecker;
332template <
class A,
char Sep,
template <
class...>
class C>
336 return m_itemchecker;
341template <
class A,
char Sep,
template <
class...>
class C>
345 return MakeAttributeContainerChecker<A, Sep, C>();
348template <
class A,
char Sep,
template <
class...>
class C>
349Ptr<const AttributeChecker>
352 auto checker = MakeAttributeContainerChecker<A, Sep, C>();
353 auto acchecker = DynamicCast<AttributeContainerChecker>(checker);
354 acchecker->SetItemChecker(itemchecker);
358template <
class A,
char Sep,
template <
class...>
class C>
362 std::string containerType;
363 std::string underlyingType;
366 std::ostringstream oss;
367 oss <<
"ns3::AttributeContainerValue<" <<
typeid(
typename T::attribute_type).name() <<
", "
368 <<
typeid(
typename T::container_type).name() <<
">";
369 containerType = oss.str();
373 std::ostringstream oss;
374 oss <<
"ns3::Ptr<" <<
typeid(
typename T::attribute_type).name() <<
">";
375 underlyingType = oss.str();
378 return MakeSimpleAttributeChecker<T, internal::AttributeContainerChecker<A, Sep, C>>(
383template <
class A,
char Sep,
template <
class...>
class C>
388template <
class A,
char Sep,
template <
class...>
class C>
389template <
class CONTAINER>
395template <
class A,
char Sep,
template <
class...>
class C>
403template <
class A,
char Sep,
template <
class...>
class C>
409template <
class A,
char Sep,
template <
class...>
class C>
413 auto c = Create<AttributeContainerValue<A, Sep, C>>();
414 c->m_container = m_container;
418template <
class A,
char Sep,
template <
class...>
class C>
423 auto acchecker = DynamicCast<const AttributeContainerChecker>(checker);
429 std::istringstream iss(value);
430 while (std::getline(iss, value, Sep))
432 auto avalue = acchecker->GetItemChecker()->CreateValidValue(
StringValue(value));
438 auto attr = DynamicCast<A>(avalue);
445 m_container.push_back(attr);
450template <
class A,
char Sep,
template <
class...>
class C>
454 std::ostringstream oss;
456 for (
auto attr : *
this)
462 oss << attr->SerializeToString(checker);
468template <
class A,
char Sep,
template <
class...>
class C>
475 c.insert(c.end(), a->Get());
480template <
class A,
char Sep,
template <
class...>
class C>
487 std::copy(src.begin(), src.end(), std::inserter(value, value.end()));
491template <
class A,
char Sep,
template <
class...>
class C>
497 CopyFrom(c.begin(), c.end());
500template <
class A,
char Sep,
template <
class...>
class C>
507template <
class A,
char Sep,
template <
class...>
class C>
514template <
class A,
char Sep,
template <
class...>
class C>
521template <
class A,
char Sep,
template <
class...>
class C>
525 return m_container.size();
528template <
class A,
char Sep,
template <
class...>
class C>
532 return m_container.begin();
535template <
class A,
char Sep,
template <
class...>
class C>
539 return m_container.end();
542template <
class A,
char Sep,
template <
class...>
class C>
546 return m_container.cbegin();
549template <
class A,
char Sep,
template <
class...>
class C>
553 return m_container.cend();
556template <
class A,
char Sep,
template <
class...>
class C>
561 for (ITER iter = begin; iter != end; ++iter)
563 m_container.push_back(Create<A>(*iter));
568template <
typename A,
char Sep,
template <
typename...>
class C,
typename T1>
572 return MakeAccessorHelper<AttributeContainerValue<A, Sep, C>>(a1);
575template <
typename A,
char Sep,
template <
typename...>
class C,
typename T1,
typename T2>
576Ptr<const AttributeAccessor>
579 return MakeAccessorHelper<AttributeContainerValue<A, Sep, C>>(a1, a2);
Represent the type of an attribute.
AttributeChecker implementation for AttributeContainerValue.
virtual Ptr< const AttributeChecker > GetItemChecker() 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.
AttributeContainerValue::const_iterator Iterator
NS3 style iterator type.
container_type::size_type size_type
Size type for container.
container_type::iterator iterator
stl-style Non-const iterator type.
std::list< value_type > container_type
Internal container type.
bool GetAccessor(T &value) const
Set the given variable to the values stored by this TupleValue object.
Iterator End()
NS3-style ending of container.
size_type GetN() const
NS3-style Number of items.
Ptr< AttributeContainerValue< A, Sep, C > > CopyFrom(const ITER begin, const ITER end)
Copy items from begin to end.
iterator end()
STL-style end of container.
container_type::const_iterator const_iterator
stl-style Const iterator type.
Ptr< A > value_type
Type actually stored within the container.
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
C< item_type > result_type
Type of container returned.
container_type m_container
Internal container.
AttributeContainerValue()
Default constructor.
result_type Get() const
Return a container of items.
A attribute_type
AttributeValue (element) type.
void Set(const T &c)
Copy items from container c.
Iterator Begin()
NS3-style beginning of container.
Ptr< AttributeValue > Copy() const override
std::invoke_result_t< decltype(&A::Get), A > item_type
Item type of container returned by Get.
size_type size() const
STL-style number of items in container.
iterator begin()
STL-style beginning of container.
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
~AttributeContainerValue() override
Destructor.
Hold a value for an Attribute.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
Ptr< const AttributeChecker > GetItemChecker() const override
Get the item checker.
AttributeContainerChecker()
Ptr< const AttributeChecker > m_itemchecker
The AttributeChecker.
void SetItemChecker(Ptr< const AttributeChecker > itemchecker) override
Set the item checker.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< AttributeChecker > MakeAttributeContainerChecker()
Make uninitialized AttributeContainerChecker using explicit types.
Ptr< const AttributeAccessor > MakeAttributeContainerAccessor(T1 a1)
Make AttributeContainerAccessor using explicit types.