27 #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;
130 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>
177 template <
class A,
class B>
201 template <
class A,
class B>
203 : m_firstchecker(nullptr),
204 m_secondchecker(nullptr)
208 template <
class A,
class B>
211 : m_firstchecker(firstchecker),
212 m_secondchecker(secondchecker)
216 template <
class A,
class B>
221 m_firstchecker = firstchecker;
222 m_secondchecker = secondchecker;
225 template <
class A,
class B>
229 return std::make_pair(m_firstchecker, m_secondchecker);
234 template <
class A,
class B>
238 return MakePairChecker<A, B>();
241 template <
class A,
class B>
242 Ptr<const AttributeChecker>
245 auto checker = MakePairChecker<A, B>();
246 auto acchecker = DynamicCast<PairChecker>(checker);
247 acchecker->SetCheckers(firstchecker, secondchecker);
251 template <
class A,
class B>
252 Ptr<AttributeChecker>
255 std::string pairName;
256 std::string underlyingType;
258 std::string first_type_name =
typeid(
typename T::value_type::first_type).name();
259 std::string second_type_name =
typeid(
typename T::value_type::second_type).name();
261 std::ostringstream oss;
262 oss <<
"ns3::PairValue<" << first_type_name <<
", " << second_type_name <<
">";
263 pairName = oss.str();
267 std::ostringstream oss;
268 oss <<
typeid(
typename T::value_type).name();
269 underlyingType = oss.str();
272 return MakeSimpleAttributeChecker<T, internal::PairChecker<A, B>>(pairName, underlyingType);
275 template <
class A,
class B>
281 template <
class A,
class B>
287 template <
class A,
class B>
291 auto p = Create<PairValue<A, B>>();
295 p->m_value = std::make_pair(DynamicCast<A>(m_value.first->Copy()),
296 DynamicCast<B>(m_value.second->Copy()));
301 template <
class A,
class B>
305 auto pchecker = DynamicCast<const PairChecker>(checker);
311 std::istringstream iss(value);
313 auto first = pchecker->GetCheckers().first->CreateValidValue(
StringValue(value));
319 auto firstattr = DynamicCast<A>(
first);
326 auto second = pchecker->GetCheckers().second->CreateValidValue(
StringValue(value));
332 auto secondattr = DynamicCast<B>(
second);
338 m_value = std::make_pair(firstattr, secondattr);
342 template <
class A,
class B>
346 std::ostringstream oss;
347 oss << m_value.first->SerializeToString(checker);
349 oss << m_value.second->SerializeToString(checker);
354 template <
class A,
class B>
358 return std::make_pair(m_value.first->Get(), m_value.second->Get());
361 template <
class A,
class B>
365 m_value = std::make_pair(Create<A>(value.first), Create<B>(value.second));
368 template <
class A,
class B>
369 template <
typename T>
385 template <
typename A,
typename B,
typename T1>
389 return MakeAccessorHelper<PairValue<A, B>>(a1);
Attribute helper (ATTRIBUTE_ )macros definition.
Represent the type of an attribute.
Hold a value for an Attribute.
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() 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.
result_type Get() const
Get the stored value as a std::pair.
bool GetAccessor(T &value) const
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.
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
void Set(const result_type &value)
std::invoke_result_t< decltype(&B::Get), B > second_type
Type of ordinal (second entry of pair).
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
Ptr< AttributeValue > Copy() const override
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.
Ptr< const AttributeChecker > m_secondchecker
The second checker.
Ptr< const AttributeChecker > m_firstchecker
The first checker.
void SetCheckers(Ptr< const AttributeChecker > firstchecker, Ptr< const AttributeChecker > secondchecker) override
Set the individual AttributeChecker for each pair entry.
ns3::PairChecker::checker_pair_type GetCheckers() const override
Get the pair of checkers for each pair entry.
PairChecker()
Default c'tor.
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.
ns3::StringValue attribute value declarations.