20 #ifndef ATTRIBUTE_CONTAINER_H
21 #define ATTRIBUTE_CONTAINER_H
23 #include <ns3/attribute-helper.h>
24 #include <ns3/string.h>
30 #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);
130 template <
typename T>
188 template <
class ITER>
217 template <
class A,
template <
class...>
class C>
227 template <
class A,
template <
class...>
class C =
std::list>
236 template <
class A,
template <
class...>
class C =
std::list>
249 template <
typename A,
template <
typename...>
class C =
std::list,
typename T1>
265 template <
typename A,
template <
typename...>
class C =
std::list,
typename T1,
typename T2>
286 template <
class A,
template <
class...>
class C>
303 template <
class A,
template <
class...>
class C>
305 : m_itemchecker(nullptr)
309 template <
class A,
template <
class...>
class C>
311 : m_itemchecker(itemchecker)
315 template <
class A,
template <
class...>
class C>
319 m_itemchecker = itemchecker;
322 template <
class A,
template <
class...>
class C>
326 return m_itemchecker;
331 template <
class A,
template <
class...>
class C>
335 return MakeAttributeContainerChecker<A, C>();
338 template <
class A,
template <
class...>
class C>
339 Ptr<const AttributeChecker>
342 auto checker = MakeAttributeContainerChecker<A, C>();
343 auto acchecker = DynamicCast<AttributeContainerChecker>(checker);
344 acchecker->SetItemChecker(itemchecker);
348 template <
class A,
template <
class...>
class C>
349 Ptr<AttributeChecker>
352 std::string containerType;
353 std::string underlyingType;
356 std::ostringstream oss;
357 oss <<
"ns3::AttributeContainerValue<" <<
typeid(
typename T::attribute_type).name() <<
", "
358 <<
typeid(
typename T::container_type).name() <<
">";
359 containerType = oss.str();
363 std::ostringstream oss;
364 oss <<
"ns3::Ptr<" <<
typeid(
typename T::attribute_type).name() <<
">";
365 underlyingType = oss.str();
368 return MakeSimpleAttributeChecker<T, internal::AttributeContainerChecker<A, C>>(containerType,
372 template <
class A,
template <
class...>
class C>
378 template <
class A,
template <
class...>
class C>
379 template <
class CONTAINER>
385 template <
class A,
template <
class...>
class C>
386 template <
class ITER>
393 template <
class A,
template <
class...>
class C>
399 template <
class A,
template <
class...>
class C>
403 auto c = Create<AttributeContainerValue<A, C>>();
405 c->m_container = m_container;
409 template <
class A,
template <
class...>
class C>
414 auto acchecker = DynamicCast<const AttributeContainerChecker>(checker);
420 std::istringstream iss(
value);
421 while (std::getline(iss,
value, m_sep))
423 auto avalue = acchecker->GetItemChecker()->CreateValidValue(
StringValue(
value));
429 auto attr = DynamicCast<A>(avalue);
436 m_container.push_back(attr);
441 template <
class A,
template <
class...>
class C>
445 std::ostringstream oss;
447 for (
auto attr : *
this)
453 oss << attr->SerializeToString(checker);
459 template <
class A,
template <
class...>
class C>
466 c.insert(c.end(), a->Get());
471 template <
class A,
template <
class...>
class C>
472 template <
typename T>
478 std::copy(src.begin(), src.end(), std::inserter(
value,
value.end()));
482 template <
class A,
template <
class...>
class C>
488 CopyFrom(c.begin(), c.end());
491 template <
class A,
template <
class...>
class C>
498 template <
class A,
template <
class...>
class C>
505 template <
class A,
template <
class...>
class C>
512 template <
class A,
template <
class...>
class C>
516 return m_container.size();
519 template <
class A,
template <
class...>
class C>
523 return m_container.begin();
526 template <
class A,
template <
class...>
class C>
530 return m_container.end();
533 template <
class A,
template <
class...>
class C>
537 return m_container.cbegin();
540 template <
class A,
template <
class...>
class C>
544 return m_container.cend();
547 template <
class A,
template <
class...>
class C>
548 template <
class ITER>
552 for (ITER iter = begin; iter != end; ++iter)
554 m_container.push_back(Create<A>(*iter));
559 template <
typename A,
template <
typename...>
class C,
typename T1>
563 return MakeAccessorHelper<AttributeContainerValue<A, C>>(a1);
566 template <
typename A,
template <
typename...>
class C,
typename T1,
typename T2>
567 Ptr<const AttributeAccessor>
570 return MakeAccessorHelper<AttributeContainerValue<A, 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.
result_type Get() const
Return a container of items.
Ptr< A > value_type
Type actually stored within the container.
void Set(const T &c)
Copy items from container c.
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.
container_type m_container
Internal container.
container_type::iterator iterator
stl-style Non-const iterator type.
~AttributeContainerValue() override
Destructor.
Iterator Begin()
NS3-style beginning of container.
char m_sep
Item separator.
iterator end()
STL-style end of container.
A attribute_type
AttributeValue (element) type.
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
AttributeContainerValue(char sep=',')
Default constructor.
C< item_type > result_type
Type of container returned.
bool GetAccessor(T &value) const
Set the given variable to the values stored by this TupleValue object.
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.
size_type GetN() const
NS3-style Number of items.
iterator begin()
STL-style beginning of container.
AttributeContainerValue::const_iterator Iterator
NS3 style iterator type.
Ptr< AttributeValue > Copy() const override
Iterator End()
NS3-style ending of container.
size_type size() const
STL-style number of items in container.
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 SetItemChecker(Ptr< const AttributeChecker > itemchecker) override
Set the item checker.
Ptr< const AttributeChecker > GetItemChecker() const override
Get 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.