From bfd3771406b236f4fefcd6c6d334705b558cdb2d Mon Sep 17 00:00:00 2001 From: "Sascha Schade (strongly-typed)" Date: Thu, 18 May 2023 12:32:41 +0200 Subject: [PATCH] Use isNotEmpty() instead of !isEmpty() --- src/modm/communication/rpr/interface_impl.hpp | 2 +- src/modm/communication/xpcc/backend/can/connector_impl.hpp | 2 +- src/modm/container/doubly_linked_list.hpp | 3 +++ src/modm/container/dynamic_array.hpp | 6 ++++++ src/modm/container/linked_list.hpp | 3 +++ src/modm/container/linked_list_impl.hpp | 2 +- src/modm/container/stack.hpp | 6 ++++++ src/modm/platform/can/lpc/c_can.cpp.in | 4 ++-- src/modm/platform/i2c/stm32/i2c_master.cpp.in | 2 +- src/modm/platform/uart/at90_tiny_mega/uart_rx.cpp.in | 2 +- src/modm/platform/uart/at90_tiny_mega/uart_tx.cpp.in | 2 +- src/modm/platform/uart/cortex/itm.cpp.in | 4 ++-- src/modm/platform/uart/lpc/uart.cpp.in | 6 +++--- src/modm/platform/uart/rp/uart.cpp.in | 4 ++-- src/modm/platform/uart/stm32/uart.cpp.in | 4 ++-- src/modm/platform/uart/xmega/uart_buffered_rx.cpp.in | 2 +- src/modm/platform/uart/xmega/uart_buffered_tx.cpp.in | 2 +- src/modm/platform/uart/xmega/uart_flow.cpp.in | 6 +++--- src/modm/ui/gui/view.cpp | 2 +- test/modm/architecture/driver/atomic/atomic_queue_test.cpp | 1 + test/modm/communication/xpcc/fake_backend.cpp | 2 +- test/modm/container/bounded_deque_test.cpp | 1 + test/modm/container/bounded_queue_test.cpp | 1 + test/modm/container/bounded_stack_test.cpp | 1 + test/modm/container/doubly_linked_list_test.cpp | 1 + test/modm/container/dynamic_array_test.cpp | 1 + test/modm/container/linked_list_test.cpp | 1 + test/modm/mock/spi_master.cpp | 6 +++--- 28 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/modm/communication/rpr/interface_impl.hpp b/src/modm/communication/rpr/interface_impl.hpp index 6af92dcff0..deff203e9a 100644 --- a/src/modm/communication/rpr/interface_impl.hpp +++ b/src/modm/communication/rpr/interface_impl.hpp @@ -467,7 +467,7 @@ template void modm::rpr::Interface::popMessage(Queue &queue) { - if (!queue.isEmpty()) + if (queue.isNotEmpty()) { // deallocate the external buffer Message message = queue.get(); diff --git a/src/modm/communication/xpcc/backend/can/connector_impl.hpp b/src/modm/communication/xpcc/backend/can/connector_impl.hpp index 937511ee5a..49564321d7 100644 --- a/src/modm/communication/xpcc/backend/can/connector_impl.hpp +++ b/src/modm/communication/xpcc/backend/can/connector_impl.hpp @@ -123,7 +123,7 @@ xpcc::CanConnector::sendWaitingMessages() } else if (canDriver->getBusState() != Driver::BusState::Connected) { // No connection to the CAN bus, drop all messages which should be send - while (!sendList.isEmpty()) { + while (sendList.isNotEmpty()) { sendList.removeFront(); } return; diff --git a/src/modm/container/doubly_linked_list.hpp b/src/modm/container/doubly_linked_list.hpp index ecd73abb61..36c936d089 100644 --- a/src/modm/container/doubly_linked_list.hpp +++ b/src/modm/container/doubly_linked_list.hpp @@ -42,6 +42,9 @@ namespace modm inline bool isEmpty() const; + inline bool + isNotEmpty() const { return (not isEmpty()); } + /** * \brief Get number of items in the list * diff --git a/src/modm/container/dynamic_array.hpp b/src/modm/container/dynamic_array.hpp index 24b1b1a615..3a60aef947 100644 --- a/src/modm/container/dynamic_array.hpp +++ b/src/modm/container/dynamic_array.hpp @@ -104,6 +104,12 @@ namespace modm return (this->size == 0); } + inline bool + isNotEmpty() const + { + return not isEmpty(); + } + /** * \brief Return size * diff --git a/src/modm/container/linked_list.hpp b/src/modm/container/linked_list.hpp index 2cb57e0fa9..9f16ab7e84 100644 --- a/src/modm/container/linked_list.hpp +++ b/src/modm/container/linked_list.hpp @@ -50,6 +50,9 @@ namespace modm inline bool isEmpty() const; + inline bool + isNotEmpty() const { return (not isEmpty()); } + /** * \brief Get number of elements * diff --git a/src/modm/container/linked_list_impl.hpp b/src/modm/container/linked_list_impl.hpp index 7716879fb4..1f78d02f7a 100644 --- a/src/modm/container/linked_list_impl.hpp +++ b/src/modm/container/linked_list_impl.hpp @@ -179,7 +179,7 @@ template void modm::LinkedList::removeAll() { - while (!this->isEmpty()) { + while (this->isNotEmpty()) { this->removeFront(); } } diff --git a/src/modm/container/stack.hpp b/src/modm/container/stack.hpp index 686aee1c6f..951e072114 100644 --- a/src/modm/container/stack.hpp +++ b/src/modm/container/stack.hpp @@ -47,6 +47,12 @@ namespace modm return c.isEmpty(); } + inline bool + isNotEmpty() + { + return not c.isEmpty(); + } + bool isFull() { diff --git a/src/modm/platform/can/lpc/c_can.cpp.in b/src/modm/platform/can/lpc/c_can.cpp.in index 3813e52c33..daca404189 100644 --- a/src/modm/platform/can/lpc/c_can.cpp.in +++ b/src/modm/platform/can/lpc/c_can.cpp.in @@ -162,7 +162,7 @@ modm::platform::Can::CAN_tx(uint8_t /* msg_obj_num */) // All message objects empty. Otherwise the order of messages // is not maintained - while (!txQueue.isEmpty()) + while (txQueue.isNotEmpty()) { // Still messages in the queue. @@ -349,7 +349,7 @@ bool modm::platform::Can::isMessageAvailable() { %% if options["buffer.rx"] > 0 - return !rxQueue.isEmpty(); + return rxQueue.isNotEmpty(); %% else /* Check if new data is available in the Message * Objects 1 to 16. */ diff --git a/src/modm/platform/i2c/stm32/i2c_master.cpp.in b/src/modm/platform/i2c/stm32/i2c_master.cpp.in index 36525857d9..3d3eb3161d 100644 --- a/src/modm/platform/i2c/stm32/i2c_master.cpp.in +++ b/src/modm/platform/i2c/stm32/i2c_master.cpp.in @@ -622,7 +622,7 @@ modm::platform::I2cMaster{{ id }}::reset() if (transaction) transaction->detaching(DetachCause::ErrorCondition); transaction = nullptr; // remove all queued transactions - while(!queue.isEmpty()) + while(queue.isNotEmpty()) { ConfiguredTransaction next = queue.get(); if (next.transaction) next.transaction->detaching(DetachCause::ErrorCondition); diff --git a/src/modm/platform/uart/at90_tiny_mega/uart_rx.cpp.in b/src/modm/platform/uart/at90_tiny_mega/uart_rx.cpp.in index d8f1bab550..2616108b56 100644 --- a/src/modm/platform/uart/at90_tiny_mega/uart_rx.cpp.in +++ b/src/modm/platform/uart/at90_tiny_mega/uart_rx.cpp.in @@ -101,7 +101,7 @@ std::size_t modm::platform::Uart{{ id }}::discardReceiveBuffer() { std::size_t i(0); - while(!rxBuffer.isEmpty()) + while(rxBuffer.isNotEmpty()) { rxBuffer.pop(); ++i; diff --git a/src/modm/platform/uart/at90_tiny_mega/uart_tx.cpp.in b/src/modm/platform/uart/at90_tiny_mega/uart_tx.cpp.in index f56b86fa65..c60051be13 100644 --- a/src/modm/platform/uart/at90_tiny_mega/uart_tx.cpp.in +++ b/src/modm/platform/uart/at90_tiny_mega/uart_tx.cpp.in @@ -126,7 +126,7 @@ modm::platform::Uart{{ id }}::discardTransmitBuffer() } std::size_t i = 0; - while(!txBuffer.isEmpty()) + while(txBuffer.isNotEmpty()) { txBuffer.pop(); ++i; diff --git a/src/modm/platform/uart/cortex/itm.cpp.in b/src/modm/platform/uart/cortex/itm.cpp.in index 084ef22325..f7c2fc0bf5 100644 --- a/src/modm/platform/uart/cortex/itm.cpp.in +++ b/src/modm/platform/uart/cortex/itm.cpp.in @@ -126,7 +126,7 @@ Itm::discardTransmitBuffer() { %% if options["buffer.tx"] std::size_t count = 0; - for(; not txBuffer.isEmpty(); txBuffer.pop()) + for(; txBuffer.isNotEmpty(); txBuffer.pop()) ++count; return count; %% else @@ -180,7 +180,7 @@ Itm::update() static uint32_t buffer{0}; static uint8_t size{0}; - while (not txBuffer.isEmpty() and size < 4) + while (txBuffer.isNotEmpty() and size < 4) { const uint8_t data = txBuffer.get(); txBuffer.pop(); diff --git a/src/modm/platform/uart/lpc/uart.cpp.in b/src/modm/platform/uart/lpc/uart.cpp.in index ef1456269e..3905440719 100644 --- a/src/modm/platform/uart/lpc/uart.cpp.in +++ b/src/modm/platform/uart/lpc/uart.cpp.in @@ -252,7 +252,7 @@ bool modm::platform::Uart1::read(uint8_t& data) { %% if options["buffer.rx"] > 16 - if (not rxBuffer.isEmpty()) + if (rxBuffer.isNotEmpty()) { data = rxBuffer.get(); rxBuffer.pop(); @@ -298,7 +298,7 @@ modm::platform::Uart1::discardReceiveBuffer() { std::size_t count(0); %% if options["buffer.rx"] > 16 - while(!rxBuffer.isEmpty()) + while(rxBuffer.isNotEmpty()) { ++count; rxBuffer.pop(); @@ -346,7 +346,7 @@ MODM_ISR(UART) return; } - while (!txBuffer.isEmpty() and (charsLeft-- > 0)) + while (txBuffer.isNotEmpty() and (charsLeft-- > 0)) { // Write to the hardware buffer LPC_UART->THR = txBuffer.get(); diff --git a/src/modm/platform/uart/rp/uart.cpp.in b/src/modm/platform/uart/rp/uart.cpp.in index 180978fec2..90b4835f6d 100644 --- a/src/modm/platform/uart/rp/uart.cpp.in +++ b/src/modm/platform/uart/rp/uart.cpp.in @@ -229,7 +229,7 @@ modm::platform::Uart{{ id }}::discardReceiveBuffer() { std::size_t count(0); %% if options["buffer.rx"] > fifo_size - while(!rxBuffer.isEmpty()) + while(rxBuffer.isNotEmpty()) { ++count; rxBuffer.pop(); @@ -253,7 +253,7 @@ MODM_ISR(UART{{ id }}_IRQ) %% if options["buffer.tx"] > fifo_size if (IValue & UART_UARTMIS_TXMIS_BITS) { - while (!txBuffer.isEmpty() and !tx_fifo_full()) + while (txBuffer.isNotEmpty() and !tx_fifo_full()) { // Write to the hardware buffer uart{{ id }}_hw->dr = txBuffer.get(); diff --git a/src/modm/platform/uart/stm32/uart.cpp.in b/src/modm/platform/uart/stm32/uart.cpp.in index b51422421c..cd8783f3fa 100644 --- a/src/modm/platform/uart/stm32/uart.cpp.in +++ b/src/modm/platform/uart/stm32/uart.cpp.in @@ -131,7 +131,7 @@ std::size_t std::size_t count = 0; // disable interrupt since buffer will be cleared {{ hal }}::disableInterrupt({{ hal }}::Interrupt::TxEmpty); - while(!txBuffer.isEmpty()) { + while(txBuffer.isNotEmpty()) { ++count; txBuffer.pop(); } @@ -202,7 +202,7 @@ std::size_t { %% if options["buffer.rx"] std::size_t count = 0; - while(!rxBuffer.isEmpty()) { + while(rxBuffer.isNotEmpty()) { ++count; rxBuffer.pop(); } diff --git a/src/modm/platform/uart/xmega/uart_buffered_rx.cpp.in b/src/modm/platform/uart/xmega/uart_buffered_rx.cpp.in index c409e6eb48..fcc99325d2 100644 --- a/src/modm/platform/uart/xmega/uart_buffered_rx.cpp.in +++ b/src/modm/platform/uart/xmega/uart_buffered_rx.cpp.in @@ -83,7 +83,7 @@ std::size_t modm::platform::Uart{{ id }}::discardReceiveBuffer() { std::size_t i(0); - while(!rxBuffer.isEmpty()) + while(rxBuffer.isNotEmpty()) { rxBuffer.pop(); ++i; diff --git a/src/modm/platform/uart/xmega/uart_buffered_tx.cpp.in b/src/modm/platform/uart/xmega/uart_buffered_tx.cpp.in index 12570eab4c..24fd500b6a 100644 --- a/src/modm/platform/uart/xmega/uart_buffered_tx.cpp.in +++ b/src/modm/platform/uart/xmega/uart_buffered_tx.cpp.in @@ -116,7 +116,7 @@ modm::platform::Uart{{ id }}::discardTransmitBuffer() } std::size_t i = 0; - while(!txBuffer.isEmpty()) + while(txBuffer.isNotEmpty()) { txBuffer.pop(); ++i; diff --git a/src/modm/platform/uart/xmega/uart_flow.cpp.in b/src/modm/platform/uart/xmega/uart_flow.cpp.in index 57b24cf6dd..2bacff2870 100644 --- a/src/modm/platform/uart/xmega/uart_flow.cpp.in +++ b/src/modm/platform/uart/xmega/uart_flow.cpp.in @@ -158,7 +158,7 @@ modm::platform::BufferedUartFlow{{ id }}::read(uint8_t& c) // Small hack: When the AVR stopped transmission due to a high RTS signal try to resume // transmission now when RTS is low again and there is something to send. // TODO: can be removed if RTS interrupt is included. - if (!RTS::read() && !txBuffer.isEmpty()) { + if ((not RTS::read()) && txBuffer.isNotEmpty()) { // enable DRE interrupt to resume transmission USART{{ id }}_CTRLA = USART_RXCINTLVL_MED_gc | USART_DREINTLVL_MED_gc; } @@ -219,7 +219,7 @@ uint8_t modm::platform::BufferedUartFlow{{ id }}::flushReceiveBuffer() { uint8_t i = 0; - while(!rxBuffer.isEmpty()) { + while(rxBuffer.isNotEmpty()) { rxBuffer.pop(); ++i; } @@ -236,7 +236,7 @@ modm::platform::BufferedUartFlow{{ id }}::flushReceiveBuffer() //modm::platform::BufferedUartFlow{{ id }}::flushTransmitBuffer() //{ // uint8_t i(0); -// while(!txBuffer.isEmpty()) { +// while(txBuffer.isNotEmpty()) { // txBuffer.pop(); // ++i; // } diff --git a/src/modm/ui/gui/view.cpp b/src/modm/ui/gui/view.cpp index 75c5389d8c..f37673cf6e 100644 --- a/src/modm/ui/gui/view.cpp +++ b/src/modm/ui/gui/view.cpp @@ -40,7 +40,7 @@ modm::gui::View::update() modm::gui::inputQueue* input_queue = this->stack->getInputQueue(); - while(!input_queue->isEmpty()) { + while(input_queue->isNotEmpty()) { // pop input event ev = input_queue->get(); diff --git a/test/modm/architecture/driver/atomic/atomic_queue_test.cpp b/test/modm/architecture/driver/atomic/atomic_queue_test.cpp index fd07aeab5f..ed676d21c5 100644 --- a/test/modm/architecture/driver/atomic/atomic_queue_test.cpp +++ b/test/modm/architecture/driver/atomic/atomic_queue_test.cpp @@ -21,6 +21,7 @@ AtomicQueueTest::testQueue() modm::atomic::Queue queue; TEST_ASSERT_TRUE(queue.isEmpty()); + TEST_ASSERT_FALSE(queue.isNotEmpty()); TEST_ASSERT_EQUALS(queue.getMaxSize(), 3); TEST_ASSERT_TRUE(queue.push(1)); diff --git a/test/modm/communication/xpcc/fake_backend.cpp b/test/modm/communication/xpcc/fake_backend.cpp index 1c04c749e2..9b154ab640 100644 --- a/test/modm/communication/xpcc/fake_backend.cpp +++ b/test/modm/communication/xpcc/fake_backend.cpp @@ -30,7 +30,7 @@ FakeBackend::sendPacket(const xpcc::Header &header, bool FakeBackend::isPacketAvailable() const { - return !this->messagesToReceive.isEmpty(); + return this->messagesToReceive.isNotEmpty(); } const xpcc::Header& diff --git a/test/modm/container/bounded_deque_test.cpp b/test/modm/container/bounded_deque_test.cpp index 81451989ca..76c5e8c8a2 100644 --- a/test/modm/container/bounded_deque_test.cpp +++ b/test/modm/container/bounded_deque_test.cpp @@ -23,6 +23,7 @@ BoundedDequeTest::testForward() modm::BoundedDeque deque; TEST_ASSERT_TRUE(deque.isEmpty()); + TEST_ASSERT_FALSE(deque.isNotEmpty()); TEST_ASSERT_EQUALS(deque.getMaxSize(), 3U); TEST_ASSERT_EQUALS(deque.getSize(), 0U); diff --git a/test/modm/container/bounded_queue_test.cpp b/test/modm/container/bounded_queue_test.cpp index 6870f0b6b7..42187d7977 100644 --- a/test/modm/container/bounded_queue_test.cpp +++ b/test/modm/container/bounded_queue_test.cpp @@ -21,6 +21,7 @@ BoundedQueueTest::testQueue() modm::BoundedQueue queue; TEST_ASSERT_TRUE(queue.isEmpty()); + TEST_ASSERT_FALSE(queue.isNotEmpty()); TEST_ASSERT_EQUALS(queue.getMaxSize(), 5U); diff --git a/test/modm/container/bounded_stack_test.cpp b/test/modm/container/bounded_stack_test.cpp index a92717fbcd..d04bfa60b4 100644 --- a/test/modm/container/bounded_stack_test.cpp +++ b/test/modm/container/bounded_stack_test.cpp @@ -21,6 +21,7 @@ BoundedStackTest::testStack() modm::BoundedStack stack; TEST_ASSERT_TRUE(stack.isEmpty()); + TEST_ASSERT_FALSE(stack.isNotEmpty()); TEST_ASSERT_EQUALS(stack.getMaxSize(), 3U); TEST_ASSERT_TRUE(stack.push(1)); diff --git a/test/modm/container/doubly_linked_list_test.cpp b/test/modm/container/doubly_linked_list_test.cpp index c6cc8ff6ce..0a272e31cf 100644 --- a/test/modm/container/doubly_linked_list_test.cpp +++ b/test/modm/container/doubly_linked_list_test.cpp @@ -30,6 +30,7 @@ DoublyLinkedListTest::testConstructor() modm::DoublyLinkedList< unittest::CountType > list; TEST_ASSERT_TRUE(list.isEmpty()); + TEST_ASSERT_FALSE(list.isNotEmpty()); TEST_ASSERT_EQUALS(unittest::CountType::numberOfDefaultConstructorCalls, 0U); } diff --git a/test/modm/container/dynamic_array_test.cpp b/test/modm/container/dynamic_array_test.cpp index d640d63a82..348fd9bcac 100644 --- a/test/modm/container/dynamic_array_test.cpp +++ b/test/modm/container/dynamic_array_test.cpp @@ -30,6 +30,7 @@ DynamicArrayTest::testDefaultConstrutor() Container array; TEST_ASSERT_TRUE(array.isEmpty()); + TEST_ASSERT_FALSE(array.isNotEmpty()); TEST_ASSERT_EQUALS(array.getSize(), 0U); } diff --git a/test/modm/container/linked_list_test.cpp b/test/modm/container/linked_list_test.cpp index 104c01e44e..90a724c6e6 100644 --- a/test/modm/container/linked_list_test.cpp +++ b/test/modm/container/linked_list_test.cpp @@ -31,6 +31,7 @@ LinkedListTest::testConstructor() modm::LinkedList< unittest::CountType > list; TEST_ASSERT_TRUE(list.isEmpty()); + TEST_ASSERT_FALSE(list.isNotEmpty()); TEST_ASSERT_EQUALS(unittest::CountType::numberOfDefaultConstructorCalls, 0U); } diff --git a/test/modm/mock/spi_master.cpp b/test/modm/mock/spi_master.cpp index ce7fc74d3c..19ede76d1f 100644 --- a/test/modm/mock/spi_master.cpp +++ b/test/modm/mock/spi_master.cpp @@ -49,7 +49,7 @@ modm_test::platform::SpiMaster::transfer(uint8_t data) { txBuffer.append(data); - if(!rxBuffer.isEmpty()) { + if(rxBuffer.isNotEmpty()) { tmp = rxBuffer.getFront(); rxBuffer.removeFront(); } @@ -77,14 +77,14 @@ modm_test::platform::SpiMaster::transfer(uint8_t * tx, uint8_t * rx, std::size_t } if(rx != nullptr) { - if(!rxBuffer.isEmpty()) { + if(rxBuffer.isNotEmpty()) { rx[i] = rxBuffer.getFront(); } else { rx[i] = 0; } } - if(!rxBuffer.isEmpty()) { + if(rxBuffer.isNotEmpty()) { rxBuffer.removeFront(); } }