29 #include <type_traits>
47 template <
class... Args>
49 operator<<(std::ostream& os,
const std::tuple<Args...>& t)
52 [&os](
auto&&...
args) {
54 ((os <<
args << (++n !=
sizeof...(Args) ?
", " :
"")), ...);
67 template <
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>
148 template <
class T1,
class T2>
162 virtual const std::vector<Ptr<const AttributeChecker>>&
GetCheckers()
const = 0;
173 template <
class... Args,
class... Ts>
187 template <
class... Args,
class T1>
202 template <
class... Args,
class T1,
class T2>
214 template <
class... Args>
216 : m_value(std::make_tuple(Args()...))
220 template <
class... Args>
226 template <
class... Args>
233 template <
class... Args>
234 template <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))...);
250 template <
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);
300 template <
class... Args>
304 std::ostringstream oss;
305 oss <<
"{" << Get() <<
"}";
309 template <
class... Args>
313 return std::apply([](Args... values) { return std::make_tuple(values.Get()...); }, m_value);
316 template <
class... Args>
320 m_value = std::apply([](
auto&&...
args) {
return std::make_tuple(Args(
args)...); }, value);
323 template <
class... Args>
330 template <
class... Args>
331 template <
typename T>
349 template <
class... Args>
358 template <
class... Ts>
364 const std::vector<Ptr<const AttributeChecker>>&
GetCheckers()
const override
371 const auto v =
dynamic_cast<const TupleValue<Args...
>*>(&value);
377 [
this](Args... values) {
386 return "ns3::TupleValue";
406 const auto src =
dynamic_cast<const TupleValue<Args...
>*>(&source);
407 auto dst =
dynamic_cast<TupleValue<Args...
>*>(&destination);
408 if (src ==
nullptr || dst ==
nullptr)
425 template <
class... Args>
431 template <
class... Ts>
449 template <
class T1,
class T2>
462 template <
class... Args>
476 template <
class... Ts>
494 template <
class T1,
class T2>
503 template <
class T1,
class T2>
510 template <
class... Args,
class... Ts>
511 Ptr<const AttributeChecker>
517 template <
class... Args,
class T1>
518 Ptr<const AttributeAccessor>
524 template <
class... Args,
class T1,
class T2>
525 Ptr<const AttributeAccessor>
Attribute helper (ATTRIBUTE_ )macros definition.
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
bool SetValueImpl(std::index_sequence< Is... >, const std::vector< Ptr< AttributeValue >> &values)
Set the attribute values starting from the given values.
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.
result_type Get() const
Get the stored values as a std::tuple.
Ptr< AttributeValue > Copy() const override
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.
value_type m_value
Tuple of attribute values.
Internal checker class templated to each AttributeChecker for each entry in the tuple.
std::string GetUnderlyingTypeInformation() const override
Ptr< AttributeValue > Create() const override
bool HasUnderlyingTypeInformation() const override
std::string GetValueTypeName() const override
const std::vector< Ptr< const AttributeChecker > > & GetCheckers() const override
Get the checkers for all tuple elements.
std::vector< Ptr< const AttributeChecker > > m_checkers
attribute checkers
TupleChecker(Ts... checkers)
Constructor.
bool Check(const AttributeValue &value) 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.
void Set(std::string path, const AttributeValue &value)
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.
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...
Ptr< const AttributeAccessor > MakeTupleAccessor(T1 a1, T2 a2)
Create an AttributeAccessor using a pair of get functor and set methods from a class.
auto MakeTupleValue(T2 t)
Create a TupleValue object.
std::ostream & operator<<(std::ostream &os, const Angles &a)
ns3::StringValue attribute value declarations.
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 AttributeChecker > MakeTupleChecker(Ts... checkers)
Create a TupleChecker from AttributeCheckers associated with TupleValue elements.
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.