23#include <ns3/attribute-helper.h>
24#include <ns3/string.h>
47template <
class... Args>
49operator<<(std::ostream& os,
const std::tuple<Args...>& t)
52 [&os](
auto&&... args) {
54 ((os << args << (++n !=
sizeof...(Args) ?
", " :
"")), ...);
67template <
class... Args>
74 typedef std::tuple<std::invoke_result_t<
decltype(&Args::Get), Args>...>
result_type;
115 template <
typename T>
127 template <std::size_t... Is>
148template <
class T1,
class T2>
162 virtual const std::vector<Ptr<const AttributeChecker>>&
GetCheckers()
const = 0;
173template <
class... Args,
class... Ts>
187template <
class... Args,
class T1>
202template <
class... Args,
class T1,
class T2>
214template <
class... Args>
216 : m_value(
std::make_tuple(Args()...))
220template <
class... Args>
226template <
class... Args>
233template <
class... Args>
234template <std::size_t... Is>
239 auto valueTuple = std::make_tuple(DynamicCast<Args>(values[Is])...);
241 bool ok = ((std::get<Is>(valueTuple) !=
nullptr) && ...);
245 m_value = std::make_tuple(Args(*std::get<Is>(valueTuple))...);
250template <
class... Args>
254 auto tupleChecker = DynamicCast<const TupleChecker>(checker);
260 auto count = tupleChecker->GetCheckers().size();
261 if (count !=
sizeof...(Args))
266 if (value.empty() || value.front() !=
'{' || value.back() !=
'}')
271 value.erase(value.begin());
273 std::replace(value.data(), value.data() + value.size(),
',',
' ');
275 std::istringstream iss(value);
276 std::vector<Ptr<AttributeValue>> values;
285 values.push_back(tupleChecker->GetCheckers().at(i++)->CreateValidValue(
StringValue(value)));
297 return SetValueImpl(std::index_sequence_for<Args...>{}, values);
300template <
class... Args>
304 std::ostringstream oss;
305 oss <<
"{" << Get() <<
"}";
309template <
class... Args>
313 return std::apply([](Args... values) { return std::make_tuple(values.Get()...); }, m_value);
316template <
class... Args>
320 m_value = std::apply([](
auto&&... args) {
return std::make_tuple(Args(args)...); }, value);
323template <
class... Args>
330template <
class... Args>
349template <
class... Args>
358 template <
class... Ts>
364 const std::vector<Ptr<const AttributeChecker>>&
GetCheckers()
const override
377 [
this](Args... values) {
386 return "ns3::TupleValue";
408 if (src ==
nullptr || dst ==
nullptr)
425template <
class... Args>
431 template <
class... Ts>
449 template <
class T1,
class T2>
462template <
class... Args>
476 template <
class... Ts>
494 template <
class T1,
class T2>
503template <
class T1,
class T2>
510template <
class... Args,
class... Ts>
511Ptr<const AttributeChecker>
517template <
class... Args,
class T1>
518Ptr<const AttributeAccessor>
524template <
class... Args,
class T1,
class T2>
525Ptr<const AttributeAccessor>
Represent the type of an attribute.
Hold a value for an Attribute.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
Checker for attribute values storing tuples.
virtual const std::vector< Ptr< const AttributeChecker > > & GetCheckers() const =0
Get the checkers for all tuple elements.
Hold objects of type std::tuple<Args...>.
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
result_type Get() const
Get the stored values as a std::tuple.
void Set(const result_type &value)
Set the stored values.
bool GetAccessor(T &value) const
Set the given variable to the values stored by this TupleValue object.
std::tuple< Args... > value_type
Type of value stored in the TupleValue.
value_type m_value
Tuple of attribute values.
Ptr< AttributeValue > Copy() const override
bool SetValueImpl(std::index_sequence< Is... >, const std::vector< Ptr< AttributeValue > > &values)
Set the attribute values starting from the given values.
std::tuple< std::invoke_result_t< decltype(&Args::Get), Args >... > result_type
Type returned by Get or passed in Set.
value_type GetValue() const
Get the attribute values as a tuple.
Internal checker class templated to each AttributeChecker for each entry in the tuple.
std::string GetUnderlyingTypeInformation() const override
bool HasUnderlyingTypeInformation() const override
std::string GetValueTypeName() const override
std::vector< Ptr< const AttributeChecker > > m_checkers
attribute checkers
TupleChecker(Ts... checkers)
Constructor.
const std::vector< Ptr< const AttributeChecker > > & GetCheckers() const override
Get the checkers for all tuple elements.
bool Check(const AttributeValue &value) const override
Ptr< AttributeValue > Create() const override
bool Copy(const AttributeValue &source, AttributeValue &destination) const override
Copy the source to the destination.
Ptr< const AttributeAccessor > MakeAccessorHelper(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTupleChecker(Ts... checkers)
Create a TupleChecker from AttributeCheckers associated with TupleValue elements.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Ptr< const AttributeAccessor > MakeTupleAccessor(T1 a1)
Create an AttributeAccessor for a class data member of type tuple, or a lone class get functor or set...
auto MakeTupleValue(T2 t)
Create a TupleValue object.
static Ptr< const AttributeChecker > MakeTupleChecker(Ts... checkers)
Create a TupleChecker from AttributeCheckers associated with TupleValue elements.
static Ptr< const AttributeAccessor > MakeTupleAccessor(T1 a1)
Create an AttributeAccessor for a class data member of type tuple, or a lone class get functor or set...
static Ptr< const AttributeAccessor > MakeTupleAccessor(T1 a1, T2 a2)
Create an AttributeAccessor using a pair of get functor and set methods from a class.
static TupleValue< Args... > MakeTupleValue(const typename TupleValue< Args... >::result_type &t)
Create a TupleValue object.
Helper class defining static methods for MakeTupleChecker and MakeTupleAccessor that are called when ...
static Ptr< const AttributeChecker > MakeTupleChecker(Ts... checkers)
Create a TupleChecker from AttributeCheckers associated with TupleValue elements.
static Ptr< const AttributeAccessor > MakeTupleAccessor(T1 a1)
Create an AttributeAccessor for a class data member of type tuple, or a lone class get functor or set...
static Ptr< const AttributeAccessor > MakeTupleAccessor(T1 a1, T2 a2)
Create an AttributeAccessor using a pair of get functor and set methods from a class.