fork download
  1.  
  2. template <typename ItemType, size_t size>
  3. class RtosStaticQueueUPTR
  4. {
  5. private:
  6. // Constants
  7. static constexpr size_t item_size_ = sizeof(ItemType*);
  8.  
  9. // Fields
  10. bool is_initialized_ = false;
  11. QueueHandle_t handle_;
  12. StaticQueue_t data_;
  13. uint8_t buffer_[size * item_size_];
  14.  
  15. public:
  16.  
  17. // Methods
  18. /// Constructor & destructor
  19. ///
  20. RtosStaticQueueUPTR() {};
  21. ~RtosStaticQueueUPTR() { assert(false); };
  22.  
  23. /// Initialization method
  24. ///
  25. void Init(void)
  26. {
  27. assert(not is_initialized_);
  28. handle_ = xQueueCreateStatic(size, item_size_, buffer_, &data_);
  29. is_initialized_ = true;
  30. }
  31.  
  32. /// Reset method
  33. ///
  34. void Reset(void)
  35. {
  36. assert(is_initialized_);
  37.  
  38. ItemType* object = nullptr;
  39. while(true) {
  40. xQueueReceive(handle_, &object, 0);
  41. if(object == nullptr) { break; }
  42. else { delete object; }
  43. }
  44. }
  45.  
  46. /// Try to put in queue
  47. /// @param - Item
  48. /// @return - Item, null if sent
  49. ///
  50. unique_ptr<ItemType> TryPut(unique_ptr<ItemType> item_uptr)
  51. {
  52. assert(is_initialized_);
  53.  
  54. if(not item_uptr) { return nullptr; }
  55. ItemType* item_ptr = item_uptr.get();
  56. auto result = xQueueSend(handle_, &item_ptr, 0);
  57.  
  58. if(result != pdPASS) { return item_uptr; }
  59. else {
  60. item_uptr.release();
  61. return nullptr;
  62. }
  63. }
  64.  
  65. /// Get from queue
  66. /// @return - Item pointer
  67. ///
  68. unique_ptr<ItemType> TryGet(void)
  69. {
  70. assert(is_initialized_);
  71.  
  72. ItemType* item_ptr = nullptr;
  73. auto result = xQueueReceive(handle_, &item_ptr, 0);
  74. if((result == pdTRUE) and (item_ptr)) {
  75. return unique_ptr<ItemType>(item_ptr);
  76. }
  77. else { return nullptr; }
  78. }
  79.  
  80. /// Get from queue
  81. /// @param - Blocking time ticks
  82. /// @return - Item pointer
  83. ///
  84. unique_ptr<ItemType> TryGetBlocking(TickType_t blocking_time_ticks)
  85. {
  86. assert(is_initialized_);
  87.  
  88. ItemType* item_ptr = nullptr;
  89. auto result = xQueueReceive(handle_, &item_ptr, blocking_time_ticks);
  90. if((result == pdTRUE) and (item_ptr)) {
  91. return unique_ptr<ItemType>(item_ptr);
  92. }
  93. else { return nullptr; }
  94. }
  95. };
  96.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:30: error: ‘size_t’ has not been declared
 template <typename ItemType, size_t size>
                              ^~~~~~
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:11:2: error: ‘QueueHandle_t’ does not name a type
  QueueHandle_t handle_;
  ^~~~~~~~~~~~~
prog.cpp:12:2: error: ‘StaticQueue_t’ does not name a type; did you mean ‘static_assert’?
  StaticQueue_t data_;
  ^~~~~~~~~~~~~
  static_assert
prog.cpp:13:2: error: ‘uint8_t’ does not name a type
  uint8_t   buffer_[size * item_size_];
  ^~~~~~~
prog.cpp:50:2: error: ‘unique_ptr’ does not name a type
  unique_ptr<ItemType> TryPut(unique_ptr<ItemType> item_uptr)
  ^~~~~~~~~~
prog.cpp:68:2: error: ‘unique_ptr’ does not name a type
  unique_ptr<ItemType> TryGet(void)
  ^~~~~~~~~~
prog.cpp:84:2: error: ‘unique_ptr’ does not name a type
  unique_ptr<ItemType> TryGetBlocking(TickType_t blocking_time_ticks)
  ^~~~~~~~~~
stdout
Standard output is empty