forked from Archive/PX4-Autopilot
uORB::Publication*: template parameter automatically obtains the queue size according to the type
This commit is contained in:
parent
948bed6b5c
commit
90c366f369
|
@ -48,6 +48,24 @@
|
|||
namespace uORB
|
||||
{
|
||||
|
||||
template <typename U> class DefaultQueueSize
|
||||
{
|
||||
private:
|
||||
template <typename T>
|
||||
static constexpr uint8_t get_queue_size(decltype(T::ORB_QUEUE_LENGTH) *)
|
||||
{
|
||||
return T::ORB_QUEUE_LENGTH;
|
||||
}
|
||||
|
||||
template <typename T> static constexpr uint8_t get_queue_size(...)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public:
|
||||
static constexpr unsigned value = get_queue_size<U>(nullptr);
|
||||
};
|
||||
|
||||
class PublicationBase
|
||||
{
|
||||
public:
|
||||
|
@ -79,7 +97,7 @@ protected:
|
|||
/**
|
||||
* uORB publication wrapper class
|
||||
*/
|
||||
template<typename T, uint8_t ORB_QSIZE = 1>
|
||||
template<typename T, uint8_t ORB_QSIZE = DefaultQueueSize<T>::value>
|
||||
class Publication : public PublicationBase
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace uORB
|
|||
/**
|
||||
* Base publication multi wrapper class
|
||||
*/
|
||||
template<typename T, uint8_t QSIZE = 1>
|
||||
template<typename T, uint8_t QSIZE = DefaultQueueSize<T>::value>
|
||||
class PublicationMulti : public PublicationBase
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue