20 #ifndef ATTRIBUTE_CONTAINER_H
21 #define ATTRIBUTE_CONTAINER_H
30 #include <type_traits>
37 class AttributeChecker;
51 template <
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>
217 template <
class A,
char Sep,
template <
class...>
class C>
229 template <
class A,
char Sep =
',',
template <
class...>
class C =
std::list>
239 template <
class A,
char Sep =
',',
template <
class...>
class C =
std::list>
253 template <
typename A,
char Sep =
',',
template <
typename...>
class C =
std::list,
typename T1>
270 template <
typename A,
272 template <
typename...>
class C =
std::list,
295 template <
class A,
char Sep,
template <
class...>
class C>
312 template <
class A,
char Sep,
template <
class...>
class C>
314 : m_itemchecker(nullptr)
318 template <
class A,
char Sep,
template <
class...>
class C>
321 : m_itemchecker(itemchecker)
325 template <
class A,
char Sep,
template <
class...>
class C>
329 m_itemchecker = itemchecker;
332 template <
class A,
char Sep,
template <
class...>
class C>
336 return m_itemchecker;
341 template <
class A,
char Sep,
template <
class...>
class C>
345 return MakeAttributeContainerChecker<A, Sep, C>();
348 template <
class A,
char Sep,
template <
class...>
class C>
349 Ptr<const AttributeChecker>
352 auto checker = MakeAttributeContainerChecker<A, Sep, C>();
353 auto acchecker = DynamicCast<AttributeContainerChecker>(checker);
354 acchecker->SetItemChecker(itemchecker);
358 template <
class A,
char Sep,
template <
class...>
class C>
359 Ptr<AttributeChecker>
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>>(
383 template <
class A,
char Sep,
template <
class...>
class C>
388 template <
class A,
char Sep,
template <
class...>
class C>
389 template <
class CONTAINER>
395 template <
class A,
char Sep,
template <
class...>
class C>
396 template <
class ITER>
403 template <
class A,
char Sep,
template <
class...>
class C>
409 template <
class A,
char Sep,
template <
class...>
class C>
413 auto c = Create<AttributeContainerValue<A, Sep, C>>();
414 c->m_container = m_container;
418 template <
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);
450 template <
class A,
char Sep,
template <
class...>
class C>
454 std::ostringstream oss;
456 for (
auto attr : *
this)
462 oss << attr->SerializeToString(checker);
468 template <
class A,
char Sep,
template <
class...>
class C>
475 c.insert(c.end(), a->Get());
480 template <
class A,
char Sep,
template <
class...>
class C>
481 template <
typename T>
487 std::copy(src.begin(), src.end(), std::inserter(value, value.end()));
491 template <
class A,
char Sep,
template <
class...>
class C>
497 CopyFrom(c.begin(), c.end());
500 template <
class A,
char Sep,
template <
class...>
class C>
507 template <
class A,
char Sep,
template <
class...>
class C>
514 template <
class A,
char Sep,
template <
class...>
class C>
521 template <
class A,
char Sep,
template <
class...>
class C>
525 return m_container.size();
528 template <
class A,
char Sep,
template <
class...>
class C>
532 return m_container.begin();
535 template <
class A,
char Sep,
template <
class...>
class C>
539 return m_container.end();
542 template <
class A,
char Sep,
template <
class...>
class C>
546 return m_container.cbegin();
549 template <
class A,
char Sep,
template <
class...>
class C>
553 return m_container.cend();
556 template <
class A,
char Sep,
template <
class...>
class C>
557 template <
class ITER>
561 for (ITER iter = begin; iter != end; ++iter)
563 m_container.push_back(Create<A>(*iter));
568 template <
typename A,
char Sep,
template <
typename...>
class C,
typename T1>
572 return MakeAccessorHelper<AttributeContainerValue<A, Sep, C>>(a1);
575 template <
typename A,
char Sep,
template <
typename...>
class C,
typename T1,
typename T2>
576 Ptr<const AttributeAccessor>
579 return MakeAccessorHelper<AttributeContainerValue<A, Sep, C>>(a1, a2);
Attribute helper (ATTRIBUTE_ )macros definition.
Represent the type of an attribute.
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(const AttributeContainerValue< A, Sep, C > &value)
Make AttributeContainerChecker from AttributeContainerValue.
Ptr< const AttributeAccessor > MakeAttributeContainerAccessor(T1 a1)
Make AttributeContainerAccessor using explicit types.
ns3::StringValue attribute value declarations.