24 #include <ns3/attribute-helper.h>
25 #include <ns3/string.h>
28 #include <type_traits>
47 template <
class... Args>
49 operator << (std::ostream &os,
const std::tuple<Args...> &t)
51 std::apply ([&os](
auto&&... args)
54 ((os << args << (++n !=
sizeof...(Args) ?
", " :
"")), ...);
68 template <
class... Args>
75 typedef std::tuple<std::invoke_result_t<decltype(&Args::Get),Args>...>
result_type;
116 template <
typename T>
128 template <std::size_t... Is>
149 template <
class T1,
class T2>
164 virtual const std::vector<Ptr<const AttributeChecker>>&
GetCheckers (
void)
const = 0;
176 template <
class... Args,
class... Ts>
191 template <
class... Args,
class T1>
206 template <
class... Args,
class T1,
class T2>
218 template <
class... Args>
220 : m_value (std::make_tuple (Args ()...))
224 template <
class... Args>
230 template <
class... Args>
237 template <
class... Args>
238 template <std::size_t... Is>
242 auto valueTuple = std::make_tuple (DynamicCast<Args> (values[Is])...);
244 bool ok = ((std::get<Is> (valueTuple) !=
nullptr) && ...);
248 m_value = std::make_tuple (Args (*std::get<Is> (valueTuple))...);
253 template <
class... Args>
257 auto tupleChecker = DynamicCast<const TupleChecker> (checker);
258 if (tupleChecker ==
nullptr)
263 auto count = tupleChecker->GetCheckers ().size ();
264 if (count !=
sizeof...(Args))
269 if (value.empty () || value.front () !=
'{' || value.back () !=
'}')
274 value.erase (value.begin ());
276 std::replace (value.data (), value.data () + value.size (),
',',
' ');
278 std::istringstream iss (value);
279 std::vector<Ptr<AttributeValue>> values;
288 values.push_back (tupleChecker->GetCheckers ().at (i++)->CreateValidValue (
StringValue (value)));
289 if (values.back () ==
nullptr)
300 return SetValueImpl (std::index_sequence_for<Args...>{}, values);
303 template <
class... Args>
307 std::ostringstream oss;
308 oss <<
"{" << Get () <<
"}";
312 template <
class... Args>
316 return std::apply ([](Args... values)
318 return std::make_tuple (values.Get ()...);
323 template <
class... Args>
327 m_value = std::apply ([](
auto&&... args)
329 return std::make_tuple (Args (args)...);
334 template <
class... Args>
341 template <
class... Args>
342 template <
typename T>
362 template <
class... Args>
371 template <
class... Ts>
376 const std::vector<Ptr<const AttributeChecker>>&
GetCheckers (
void)
const override
387 return std::apply ([
this](Args... values)
396 return "ns3::TupleValue";
414 if (src == 0 || dst == 0)
431 template <
class... Args>
437 template <
class... Ts>
453 template <
class T1,
class T2>
466 template <
class... Args>
479 template <
class... Ts>
495 template <
class T1,
class T2>
506 template <
class T1,
class T2>
512 template <
class... Args,
class... Ts>
518 template <
class... Args,
class T1>
524 template <
class... Args,
class T1,
class T2>
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(void) 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(void) const
Get the stored values as a std::tuple.
Ptr< AttributeValue > Copy(void) 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.
value_type GetValue(void) const
Get the attribute values as a tuple.
std::tuple< std::invoke_result_t< decltype(&Args::Get), Args >... > result_type
Type returned by Get or passed in Set.
value_type m_value
Tuple of attribute values.
Internal checker class templated to each AttributeChecker for each entry in the tuple.
std::string GetValueTypeName(void) const override
Ptr< AttributeValue > Create(void) const override
bool HasUnderlyingTypeInformation(void) const override
const std::vector< Ptr< const AttributeChecker > > & GetCheckers(void) 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
std::string GetUnderlyingTypeInformation(void) 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)
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.