fork download
  1.  
  2. template <typename ItemType>
  3. class IRtosStaticQueue
  4. {
  5. private:
  6. // Constants
  7. static constexpr size_t item_size_ = sizeof(ItemType);
  8. uint8_t* const buffer_;
  9. const size_t size_;
  10.  
  11. // Fields
  12. bool is_initialized_ = false;
  13. QueueHandle_t handle_;
  14. StaticQueue_t data_;
  15.  
  16. // Methods
  17. public:
  18. /// Constructor & destructor
  19. ///
  20. IRtosStaticQueue(uint8_t* const buffer, const size_t size)
  21. : buffer_(buffer)
  22. , size_(size)
  23. {};
  24. ~IRtosStaticQueue() { assert(false); };
  25.  
  26. /// Initialization method
  27. ///
  28. void Init(void)
  29. {
  30. assert(not is_initialized_);
  31. handle_ = xQueueCreateStatic(size_, item_size_, buffer_, &data_);
  32. is_initialized_ = true;
  33. }
  34.  
  35. /// Returns queue handle
  36. ///
  37. QueueHandle_t handle(void){ return handle_; }
  38.  
  39. /// Returns queue event size
  40. ///
  41. size_t size(void){ return size_; }
  42.  
  43. /// Reset method
  44. ///
  45. void Reset(void)
  46. {
  47. assert(is_initialized_);
  48. xQueueReset(handle_);
  49. }
  50.  
  51. /// Try to put in queue
  52. /// @param - Item value
  53. /// @return - BOOL
  54. ///
  55. bool TryPut(ItemType item)
  56. {
  57. assert(is_initialized_);
  58. auto result = xQueueSend(handle_, &item, 0);
  59. if(result != pdPASS) { return false; }
  60. else { return true; }
  61. }
  62.  
  63. /// Get from queue
  64. /// @param - Item reference
  65. /// @return - BOOL
  66. ///
  67. bool TryGet(ItemType& item)
  68. {
  69. assert(is_initialized_);
  70. ItemType item_local;
  71. auto result = xQueueReceive(handle_, item_local, 0);
  72. if(result == pdTRUE) {
  73. item = item_local;
  74. return true;
  75. }
  76. else { return false; }
  77. }
  78.  
  79. /// Get from queue
  80. /// @param - Item reference
  81. /// @param - Blocking time ticks
  82. /// @return - BOOL
  83. ///
  84. bool TryGetBlocking(ItemType& item, TickType_t blocking_time_ticks)
  85. {
  86. assert(is_initialized_);
  87. ItemType item_local;
  88. auto result = xQueueReceive(handle_, item_local, blocking_time_ticks);
  89. if(result == pdTRUE) {
  90. item = item_local;
  91. return true;
  92. }
  93. else { return false; }
  94. }
  95. };
  96.  
  97. template <typename ItemType, size_t size>
  98. class RtosStaticQueue : public IRtosStaticQueue<ItemType>
  99. {
  100. private:
  101. uint8_t buffer_[size * sizeof(ItemType)];
  102.  
  103. public:
  104. RtosStaticQueue() : IRtosStaticQueue<ItemType>(buffer_, size){ }
  105. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:7:19: error: ‘size_t’ does not name a type
  static constexpr size_t item_size_ = sizeof(ItemType);
                   ^~~~~~
prog.cpp:7:19: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
prog.cpp:1:1:
+#include <cstddef>
 
prog.cpp:7:19:
  static constexpr size_t item_size_ = sizeof(ItemType);
                   ^~~~~~
prog.cpp:8:2: error: ‘uint8_t’ does not name a type
  uint8_t* const buffer_;
  ^~~~~~~
prog.cpp:9:8: error: ‘size_t’ does not name a type
  const size_t size_;
        ^~~~~~
prog.cpp:9:8: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
prog.cpp:13:2: error: ‘QueueHandle_t’ does not name a type
  QueueHandle_t handle_;
  ^~~~~~~~~~~~~
prog.cpp:14:2: error: ‘StaticQueue_t’ does not name a type; did you mean ‘static_assert’?
  StaticQueue_t data_;
  ^~~~~~~~~~~~~
  static_assert
prog.cpp:20:26: error: expected ‘)’ before ‘*’ token
  IRtosStaticQueue(uint8_t* const buffer, const size_t size)
                  ~       ^
                          )
prog.cpp:37:2: error: ‘QueueHandle_t’ does not name a type
  QueueHandle_t handle(void){ return handle_; }
  ^~~~~~~~~~~~~
prog.cpp:41:2: error: ‘size_t’ does not name a type
  size_t size(void){ return size_; }
  ^~~~~~
prog.cpp:41:2: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
prog.cpp:84:38: error: ‘TickType_t’ has not been declared
  bool TryGetBlocking(ItemType& item, TickType_t blocking_time_ticks)
                                      ^~~~~~~~~~
prog.cpp: In destructor ‘IRtosStaticQueue<ItemType>::~IRtosStaticQueue()’:
prog.cpp:24:24: error: there are no arguments to ‘assert’ that depend on a template parameter, so a declaration of ‘assert’ must be available [-fpermissive]
  ~IRtosStaticQueue() { assert(false); };
                        ^~~~~~
prog.cpp:24:24: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
prog.cpp: In member function ‘void IRtosStaticQueue<ItemType>::Init()’:
prog.cpp:30:3: error: there are no arguments to ‘assert’ that depend on a template parameter, so a declaration of ‘assert’ must be available [-fpermissive]
   assert(not is_initialized_);
   ^~~~~~
prog.cpp:31:3: error: ‘handle_’ was not declared in this scope
   handle_ = xQueueCreateStatic(size_, item_size_, buffer_, &data_);
   ^~~~~~~
prog.cpp:31:32: error: ‘size_’ was not declared in this scope
   handle_ = xQueueCreateStatic(size_, item_size_, buffer_, &data_);
                                ^~~~~
prog.cpp:31:32: note: suggested alternative: ‘signed’
   handle_ = xQueueCreateStatic(size_, item_size_, buffer_, &data_);
                                ^~~~~
                                signed
prog.cpp:31:39: error: ‘item_size_’ was not declared in this scope
   handle_ = xQueueCreateStatic(size_, item_size_, buffer_, &data_);
                                       ^~~~~~~~~~
prog.cpp:31:51: error: ‘buffer_’ was not declared in this scope
   handle_ = xQueueCreateStatic(size_, item_size_, buffer_, &data_);
                                                   ^~~~~~~
prog.cpp:31:61: error: ‘data_’ was not declared in this scope
   handle_ = xQueueCreateStatic(size_, item_size_, buffer_, &data_);
                                                             ^~~~~
prog.cpp:31:13: error: there are no arguments to ‘xQueueCreateStatic’ that depend on a template parameter, so a declaration of ‘xQueueCreateStatic’ must be available [-fpermissive]
   handle_ = xQueueCreateStatic(size_, item_size_, buffer_, &data_);
             ^~~~~~~~~~~~~~~~~~
prog.cpp: In member function ‘void IRtosStaticQueue<ItemType>::Reset()’:
prog.cpp:47:3: error: there are no arguments to ‘assert’ that depend on a template parameter, so a declaration of ‘assert’ must be available [-fpermissive]
   assert(is_initialized_);
   ^~~~~~
prog.cpp:48:15: error: ‘handle_’ was not declared in this scope
   xQueueReset(handle_);
               ^~~~~~~
prog.cpp:48:3: error: there are no arguments to ‘xQueueReset’ that depend on a template parameter, so a declaration of ‘xQueueReset’ must be available [-fpermissive]
   xQueueReset(handle_);
   ^~~~~~~~~~~
prog.cpp: In member function ‘bool IRtosStaticQueue<ItemType>::TryPut(ItemType)’:
prog.cpp:57:3: error: there are no arguments to ‘assert’ that depend on a template parameter, so a declaration of ‘assert’ must be available [-fpermissive]
   assert(is_initialized_);
   ^~~~~~
prog.cpp:58:28: error: ‘handle_’ was not declared in this scope
   auto result = xQueueSend(handle_, &item, 0);
                            ^~~~~~~
prog.cpp:59:16: error: ‘pdPASS’ was not declared in this scope
   if(result != pdPASS) { return false; }
                ^~~~~~
prog.cpp: In member function ‘bool IRtosStaticQueue<ItemType>::TryGet(ItemType&)’:
prog.cpp:69:3: error: there are no arguments to ‘assert’ that depend on a template parameter, so a declaration of ‘assert’ must be available [-fpermissive]
   assert(is_initialized_);
   ^~~~~~
prog.cpp:71:31: error: ‘handle_’ was not declared in this scope
   auto result = xQueueReceive(handle_, item_local, 0);
                               ^~~~~~~
prog.cpp:72:16: error: ‘pdTRUE’ was not declared in this scope
   if(result == pdTRUE) {
                ^~~~~~
prog.cpp: In member function ‘bool IRtosStaticQueue<ItemType>::TryGetBlocking(ItemType&, int)’:
prog.cpp:86:3: error: there are no arguments to ‘assert’ that depend on a template parameter, so a declaration of ‘assert’ must be available [-fpermissive]
   assert(is_initialized_);
   ^~~~~~
prog.cpp:88:31: error: ‘handle_’ was not declared in this scope
   auto result = xQueueReceive(handle_, item_local, blocking_time_ticks);
                               ^~~~~~~
prog.cpp:89:16: error: ‘pdTRUE’ was not declared in this scope
   if(result == pdTRUE) {
                ^~~~~~
prog.cpp: At global scope:
prog.cpp:97:30: error: ‘size_t’ has not been declared
 template <typename ItemType, size_t size>
                              ^~~~~~
prog.cpp:101:2: error: ‘uint8_t’ does not name a type
  uint8_t buffer_[size * sizeof(ItemType)];
  ^~~~~~~
stdout
Standard output is empty