24 #include <ns3/attribute-helper.h>
25 #include <ns3/string.h>
29 #include <type_traits>
42 template <
class A,
class B>
44 operator << (std::ostream &os,
const std::pair<A, B> &p)
46 os <<
"(" << p.first <<
"," << p.second <<
")";
54 template <
class A,
class B>
61 typedef typename std::invoke_result_t<decltype(&A::Get), A>
first_type;
63 typedef typename std::invoke_result_t<decltype(&B::Get), B>
second_type;
65 typedef typename std::pair<first_type, second_type>
result_type;
129 template <
class A,
class B>
143 template <
class A,
class B>
152 template <
class A,
class B>
155 template <
typename A,
typename B,
typename T1>
175 template <
class A,
class B>
197 template <
class A,
class B>
199 : m_firstchecker (0),
203 template <
class A,
class B>
205 : m_firstchecker (firstchecker),
206 m_secondchecker (secondchecker)
209 template <
class A,
class B>
213 m_firstchecker = firstchecker;
214 m_secondchecker = secondchecker;
217 template <
class A,
class B>
221 return std::make_pair (m_firstchecker, m_secondchecker);
226 template <
class A,
class B>
230 return MakePairChecker <A, B> ();
233 template <
class A,
class B>
234 Ptr<const AttributeChecker>
237 auto checker = MakePairChecker <A, B> ();
238 auto acchecker = DynamicCast<PairChecker> (checker);
239 acchecker->SetCheckers (firstchecker, secondchecker);
243 template <
class A,
class B>
244 Ptr<AttributeChecker>
247 std::string pairName;
248 std::string underlyingType;
250 std::string first_type_name =
typeid (
typename T::value_type::first_type).name ();
251 std::string second_type_name =
typeid (
typename T::value_type::second_type).name ();
253 std::ostringstream oss;
254 oss <<
"ns3::PairValue<" << first_type_name <<
", " << second_type_name <<
">";
255 pairName = oss.str ();
259 std::ostringstream oss;
260 oss <<
typeid (
typename T::value_type).name ();
261 underlyingType = oss.str ();
264 return MakeSimpleAttributeChecker<T, internal::PairChecker<A, B> > (pairName, underlyingType);
267 template <
class A,
class B>
269 : m_value (std::make_pair (
Create <A> (),
Create <B> ()))
272 template <
class A,
class B>
278 template <
class A,
class B>
282 auto p = Create <PairValue <A, B> > ();
285 p->m_value = std::make_pair (DynamicCast<A> (m_value.first->Copy ()),
286 DynamicCast<B> (m_value.second->Copy ()));
290 template <
class A,
class B>
294 auto pchecker = DynamicCast<const PairChecker> (checker);
295 if (!pchecker)
return false;
297 std::istringstream iss (value);
299 auto first = pchecker->GetCheckers ().first->CreateValidValue (
StringValue (value));
300 if (!
first)
return false;
302 auto firstattr = DynamicCast <A> (
first);
303 if (!firstattr)
return false;
306 auto second = pchecker->GetCheckers ().second->CreateValidValue (
StringValue (value));
307 if (!
second)
return false;
309 auto secondattr = DynamicCast <B> (
second);
310 if (!secondattr)
return false;
312 m_value = std::make_pair (firstattr, secondattr);
316 template <
class A,
class B>
320 std::ostringstream oss;
321 oss << m_value.first->SerializeToString (checker);
323 oss << m_value.second->SerializeToString (checker);
328 template <
class A,
class B>
332 return std::make_pair (m_value.first->Get (), m_value.second->Get ());
335 template <
class A,
class B>
339 m_value = std::make_pair (Create <A> (value.first), Create <B> (value.second));
342 template <
class A,
class B>
343 template <
typename T>
359 template <
typename A,
typename B,
typename T1>
362 return MakeAccessorHelper<PairValue<A, B> > (a1);
Represent the type of an attribute.
Hold a value for an Attribute.
AttributeChecker implementation for PairValue.
virtual void SetCheckers(Ptr< const AttributeChecker > firstchecker, Ptr< const AttributeChecker > secondchecker)=0
Set the individual AttributeChecker for each pair entry.
std::pair< Ptr< const AttributeChecker >, Ptr< const AttributeChecker > > checker_pair_type
Type holding an AttributeChecker for each member of a pair.
virtual checker_pair_type GetCheckers(void) const =0
Get the pair of checkers for each pair entry.
Hold objects of type std::pair<A, B>.
PairValue(const result_type &value)
Construct this PairValue from a std::pair.
std::pair< first_type, second_type > result_type
Type returned by Get or passed in Set.
bool GetAccessor(T &value) const
Access the Pair value as type T.
std::invoke_result_t< decltype(&A::Get), A > first_type
Type of abscissa (first entry of pair).
std::pair< Ptr< A >, Ptr< B > > value_type
Type of value stored in the PairValue.
void Set(const result_type &value)
Set the value.
value_type m_value
The stored Pair instance.
result_type Get(void) const
Get the stored value as a std::pair.
std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Ptr< AttributeValue > Copy(void) const
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
std::invoke_result_t< decltype(&B::Get), B > second_type
Type of ordinal (second entry of pair).
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
Internal checker class templated to each AttributeChecker for each entry in the pair.
ns3::PairChecker::checker_pair_type GetCheckers(void) const
Get the pair of checkers for each pair entry.
Ptr< const AttributeChecker > m_secondchecker
The second checker.
Ptr< const AttributeChecker > m_firstchecker
The first checker.
PairChecker(void)
Default c'tor.
void SetCheckers(Ptr< const AttributeChecker > firstchecker, Ptr< const AttributeChecker > secondchecker)
Set the individual AttributeChecker for each pair entry.
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 AttributeAccessor > MakePairAccessor(T1 a1)
Create an AttributeAccessor for std::pair<>.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Ptr< AttributeChecker > MakePairChecker(const PairValue< A, B > &value)
Make a PairChecker from a PairValue.