uORB::Publication*: template parameter automatically obtains the queue size according to the type

This commit is contained in:
FengShun 2020-10-26 17:29:00 +08:00 committed by Beat Küng
parent 948bed6b5c
commit 90c366f369
2 changed files with 20 additions and 2 deletions

View File

@ -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:

View File

@ -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: