mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 08:43:33 +08:00
ParameterType<> template
This commit is contained in:
@@ -58,12 +58,6 @@ class UAVCAN_EXPORT LazyConstructor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U> struct ParamType { typedef const U& Type; };
|
|
||||||
template <typename U> struct ParamType<U&> { typedef U& Type; };
|
|
||||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
|
||||||
template <typename U> struct ParamType<U&&> { typedef U&& Type; };
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LazyConstructor()
|
LazyConstructor()
|
||||||
: ptr_(NULL)
|
: ptr_(NULL)
|
||||||
@@ -130,50 +124,53 @@ public:
|
|||||||
// for nargs in range(1, MAX_ARGS + 1):
|
// for nargs in range(1, MAX_ARGS + 1):
|
||||||
// nums = [(x + 1) for x in range(nargs)]
|
// nums = [(x + 1) for x in range(nargs)]
|
||||||
// l1 = ['typename P%d' % x for x in nums]
|
// l1 = ['typename P%d' % x for x in nums]
|
||||||
// l2 = ['typename ParamType<P%d>::Type p%d' % (x, x) for x in nums]
|
// l2 = ['typename ParameterType<P%d>::Type p%d' % (x, x) for x in nums]
|
||||||
// l3 = ['p%d' % x for x in nums]
|
// l3 = ['p%d' % x for x in nums]
|
||||||
// print(TEMPLATE % (', '.join(l1), ', '.join(l2), ', '.join(l3)))
|
// print(TEMPLATE % (', '.join(l1), ', '.join(l2), ', '.join(l3)))
|
||||||
|
|
||||||
template <typename P1>
|
template <typename P1>
|
||||||
void construct(typename ParamType<P1>::Type p1)
|
void construct(typename ParameterType<P1>::Type p1)
|
||||||
{
|
{
|
||||||
ensureNotConstructed();
|
ensureNotConstructed();
|
||||||
ptr_ = new (static_cast<void*>(data_.pool)) T(p1);
|
ptr_ = new (static_cast<void*>(data_.pool)) T(p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename P1, typename P2>
|
template<typename P1, typename P2>
|
||||||
void construct(typename ParamType<P1>::Type p1, typename ParamType<P2>::Type p2)
|
void construct(typename ParameterType<P1>::Type p1, typename ParameterType<P2>::Type p2)
|
||||||
{
|
{
|
||||||
ensureNotConstructed();
|
ensureNotConstructed();
|
||||||
ptr_ = new (static_cast<void*>(data_.pool)) T(p1, p2);
|
ptr_ = new (static_cast<void*>(data_.pool)) T(p1, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename P1, typename P2, typename P3>
|
template<typename P1, typename P2, typename P3>
|
||||||
void construct(typename ParamType<P1>::Type p1, typename ParamType<P2>::Type p2, typename ParamType<P3>::Type p3)
|
void construct(typename ParameterType<P1>::Type p1, typename ParameterType<P2>::Type p2,
|
||||||
|
typename ParameterType<P3>::Type p3)
|
||||||
{
|
{
|
||||||
ensureNotConstructed();
|
ensureNotConstructed();
|
||||||
ptr_ = new (static_cast<void*>(data_.pool)) T(p1, p2, p3);
|
ptr_ = new (static_cast<void*>(data_.pool)) T(p1, p2, p3);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename P1, typename P2, typename P3, typename P4>
|
template<typename P1, typename P2, typename P3, typename P4>
|
||||||
void construct(typename ParamType<P1>::Type p1, typename ParamType<P2>::Type p2, typename ParamType<P3>::Type p3,
|
void construct(typename ParameterType<P1>::Type p1, typename ParameterType<P2>::Type p2,
|
||||||
typename ParamType<P4>::Type p4)
|
typename ParameterType<P3>::Type p3, typename ParameterType<P4>::Type p4)
|
||||||
{
|
{
|
||||||
ensureNotConstructed();
|
ensureNotConstructed();
|
||||||
ptr_ = new (static_cast<void*>(data_.pool)) T(p1, p2, p3, p4);
|
ptr_ = new (static_cast<void*>(data_.pool)) T(p1, p2, p3, p4);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename P1, typename P2, typename P3, typename P4, typename P5>
|
template<typename P1, typename P2, typename P3, typename P4, typename P5>
|
||||||
void construct(typename ParamType<P1>::Type p1, typename ParamType<P2>::Type p2, typename ParamType<P3>::Type p3,
|
void construct(typename ParameterType<P1>::Type p1, typename ParameterType<P2>::Type p2,
|
||||||
typename ParamType<P4>::Type p4, typename ParamType<P5>::Type p5)
|
typename ParameterType<P3>::Type p3, typename ParameterType<P4>::Type p4,
|
||||||
|
typename ParameterType<P5>::Type p5)
|
||||||
{
|
{
|
||||||
ensureNotConstructed();
|
ensureNotConstructed();
|
||||||
ptr_ = new (static_cast<void*>(data_.pool)) T(p1, p2, p3, p4, p5);
|
ptr_ = new (static_cast<void*>(data_.pool)) T(p1, p2, p3, p4, p5);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
|
template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
|
||||||
void construct(typename ParamType<P1>::Type p1, typename ParamType<P2>::Type p2, typename ParamType<P3>::Type p3,
|
void construct(typename ParameterType<P1>::Type p1, typename ParameterType<P2>::Type p2,
|
||||||
typename ParamType<P4>::Type p4, typename ParamType<P5>::Type p5, typename ParamType<P6>::Type p6)
|
typename ParameterType<P3>::Type p3, typename ParameterType<P4>::Type p4,
|
||||||
|
typename ParameterType<P5>::Type p5, typename ParameterType<P6>::Type p6)
|
||||||
{
|
{
|
||||||
ensureNotConstructed();
|
ensureNotConstructed();
|
||||||
ptr_ = new (static_cast<void*>(data_.pool)) T(p1, p2, p3, p4, p5, p6);
|
ptr_ = new (static_cast<void*>(data_.pool)) T(p1, p2, p3, p4, p5, p6);
|
||||||
|
|||||||
@@ -100,6 +100,15 @@ template <typename T> struct RemoveReference<T&> { typedef T Type; };
|
|||||||
template <typename T> struct RemoveReference<T&&> { typedef T Type; };
|
template <typename T> struct RemoveReference<T&&> { typedef T Type; };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameter types
|
||||||
|
*/
|
||||||
|
template <typename U> struct ParameterType { typedef const U& Type; };
|
||||||
|
template <typename U> struct ParameterType<U&> { typedef U& Type; };
|
||||||
|
#if UAVCAN_CPP_VERSION > UAVCAN_CPP03
|
||||||
|
template <typename U> struct ParameterType<U&&> { typedef U&& Type; };
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Value types
|
* Value types
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user