24 #include <ns3/attribute-helper.h> 25 #include <ns3/string.h> 29 #include <type_traits> 34 template <
class A,
class B>
36 operator << (std::ostream &os, const std::pair<A, B> &p)
38 os <<
"(" << p.first <<
"," << p.second <<
")";
46 template <
class A,
class B>
53 typedef typename std::result_of<decltype(&A::Get)(A)>::type
first_type;
55 typedef typename std::result_of<decltype(&B::Get)(B)>::type
second_type;
57 typedef typename std::pair<first_type, second_type>
result_type;
123 template <
class A,
class B>
137 template <
class A,
class B>
146 template <
class A,
class B>
149 template <
typename A,
typename B,
typename T1>
169 template <
class A,
class B>
183 template <
class A,
class B>
185 : m_firstchecker (0),
189 template <
class A,
class B>
191 : m_firstchecker (firstchecker),
192 m_secondchecker (secondchecker)
195 template <
class A,
class B>
199 m_firstchecker = firstchecker;
200 m_secondchecker = secondchecker;
203 template <
class A,
class B>
207 return std::make_pair (m_firstchecker, m_secondchecker);
212 template <
class A,
class B>
216 return MakePairChecker <A, B> ();
219 template <
class A,
class B>
220 Ptr<const AttributeChecker>
223 auto checker = MakePairChecker <A, B> ();
224 auto acchecker = DynamicCast<PairChecker> (checker);
225 acchecker->SetCheckers (firstchecker, secondchecker);
229 template <
class A,
class B>
230 Ptr<AttributeChecker>
233 std::string pairName;
234 std::string underlyingType;
236 std::string first_type_name =
typeid (
typename T::value_type::first_type).name ();
237 std::string second_type_name =
typeid (
typename T::value_type::second_type).name ();
239 std::ostringstream oss;
240 oss <<
"ns3::PairValue<" << first_type_name <<
", " << second_type_name <<
">";
241 pairName = oss.str ();
245 std::ostringstream oss;
246 oss <<
typeid (
typename T::value_type).name ();
247 underlyingType = oss.str ();
250 return MakeSimpleAttributeChecker<T, internal::PairChecker<A, B> > (pairName, underlyingType);
253 template <
class A,
class B>
258 template <
class A,
class B>
264 template <
class A,
class B>
268 auto p = Create <PairValue <A, B> > ();
271 p->m_value = std::make_pair (DynamicCast<A> (m_value.first->Copy ()),
272 DynamicCast<B> (m_value.second->Copy ()));
276 template <
class A,
class B>
280 auto pchecker = DynamicCast<const PairChecker> (checker);
281 if (!pchecker)
return false;
283 std::istringstream iss (value);
285 auto first = pchecker->GetCheckers ().first->CreateValidValue (
StringValue (value));
286 if (!
first)
return false;
288 auto firstattr = DynamicCast <A> (
first);
289 if (!firstattr)
return false;
292 auto second = pchecker->GetCheckers ().second->CreateValidValue (
StringValue (value));
293 if (!
second)
return false;
295 auto secondattr = DynamicCast <B> (
second);
296 if (!secondattr)
return false;
298 m_value = std::make_pair (firstattr, secondattr);
302 template <
class A,
class B>
306 std::ostringstream oss;
307 oss << m_value.first->SerializeToString (checker);
309 oss << m_value.second->SerializeToString (checker);
314 template <
class A,
class B>
318 return std::make_pair (m_value.first->Get (), m_value.second->Get ());
321 template <
class A,
class B>
325 m_value = std::make_pair (Create <A> (value.first), Create <B> (value.second));
328 template <
class A,
class B>
329 template <
typename T>
337 template <
typename A,
typename B,
typename T1>
340 return MakeAccessorHelper<PairValue<A, B> > (a1);
std::result_of< decltype(&B::Get)(B)>::type second_type
Type of ordinal (second entry of pair).
Represent the type of an attribute.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
void Set(std::string path, const AttributeValue &value)
Hold a value for an Attribute.
std::result_of< decltype(&A::Get)(A)>::type first_type
Type of abscissa (first entry of pair).
Ptr< const AttributeChecker > m_firstchecker
void Set(const result_type &value)
Set the stored value.
value_type m_value
The stored Pair instance.
std::pair< Ptr< const AttributeChecker >, Ptr< const AttributeChecker > > checker_pair_type
virtual void SetCheckers(Ptr< const AttributeChecker > firstchecker, Ptr< const AttributeChecker > secondchecker)=0
Set the individual AttributeChecker for each pair entry.
std::pair< first_type, second_type > result_type
Type returned by Get or passed in Set.
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.
AttributeChecker implementation for PairValue.
std::pair< Ptr< A >, Ptr< B > > value_type
Type of value stored in the PairValue.
void SetCheckers(Ptr< const AttributeChecker > firstchecker, Ptr< const AttributeChecker > secondchecker)
Set the individual AttributeChecker for each pair entry.
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
virtual checker_pair_type GetCheckers(void) const =0
Get the pair of checkers for each pair entry.
Ptr< const AttributeChecker > m_secondchecker
ns3::PairChecker::checker_pair_type GetCheckers(void) const
Get the pair of checkers for each pair entry.
bool GetAccessor(T &value) const
Access the Pair value as type T.
Ptr< AttributeValue > Copy(void) const
result_type Get(void) const
Get the stored value as a std::pair.
Internal checker class templated to each AttributeChecker for each entry in the pair.
Hold objects of type std::pair<A, B>.
Ptr< const AttributeAccessor > MakePairAccessor(T1 a1)
std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Ptr< AttributeChecker > MakePairChecker(const PairValue< A, B > &value)
Make a PairChecker from a PairValue.