11/* !\file cppQueue.cpp
22** \author SMFSW
3- ** \copyright BSD 3-Clause License (c) 2017-2025 , SMFSW
3+ ** \copyright BSD 3-Clause License (c) 2017-2026 , SMFSW
44** \brief cppQueue handling library (designed on Arduino)
55** \details cppQueue handling library (designed on Arduino)
66** This library was designed for Arduino, yet may be compiled without change with gcc for other purposes/targets
77**/
88/* ***************************************************************/
9- #include < string.h >
10- #include < stdlib.h >
9+ #include < cstring >
10+ #include < cstdlib >
1111
1212#include " cppQueue.h"
1313/* ***************************************************************/
2525** \param [in] end - counter upper limit value
2626** \param [in] start - counter lower limit value
2727**/
28- static inline void __attribute__ ((nonnull, always_inline )) _inc_idx (uint16_t * const pIdx, const uint16_t end, const uint16_t start)
28+ static inline void __attribute__ ((nonnull)) cppq_inc_idx (uint16_t * const pIdx, const uint16_t end, const uint16_t start)
2929{
3030 if (*pIdx < (end - 1U )) { (*pIdx)++; }
3131 else { *pIdx = start; }
@@ -37,7 +37,7 @@ static inline void __attribute__((nonnull, always_inline)) _inc_idx(uint16_t * c
3737** \param [in] end - counter upper limit value
3838** \param [in] start - counter lower limit value
3939**/
40- static inline void __attribute__ ((nonnull, always_inline )) _dec_idx (uint16_t * const pIdx, const uint16_t end, const uint16_t start)
40+ static inline void __attribute__ ((nonnull)) cppq_dec_idx (uint16_t * const pIdx, const uint16_t end, const uint16_t start)
4141{
4242 if (*pIdx > start) { (*pIdx)--; }
4343 else { *pIdx = end - 1U ; }
@@ -49,30 +49,30 @@ static inline void __attribute__((nonnull, always_inline)) _dec_idx(uint16_t * c
4949** \retval true if queue is allocated
5050** \retval false is queue is not allocated
5151**/
52- inline bool __attribute__ ((always_inline)) cppQueue::_isInitialized(void ) {
53- return (init == QUEUE_INITIALIZED) ? true : false ; }
52+ inline const bool __attribute__ ((always_inline)) cppQueue::_isInitialized(void ) {
53+ return (init == QUEUE_INITIALIZED); }
5454
5555/* ! \brief get emptiness state of the queue
5656** \return cppQueue emptiness status
5757** \retval true if queue is empty
5858** \retval false is not empty
5959**/
60- inline bool __attribute__ ((always_inline)) cppQueue::_isEmpty(void ) {
61- return (cnt == 0U ) ? true : false ; }
60+ inline const bool __attribute__ ((always_inline)) cppQueue::_isEmpty(void ) {
61+ return (cnt == 0U ); }
6262
6363/* ! \brief get fullness state of the queue
6464** \return cppQueue fullness status
6565** \retval true if queue is full
6666** \retval false is not full
6767**/
68- inline bool __attribute__ ((always_inline)) cppQueue::_isFull(void ) {
69- return (cnt == rec_nb) ? true : false ; }
68+ inline const bool __attribute__ ((always_inline)) cppQueue::_isFull(void ) {
69+ return (cnt == rec_nb); }
7070
7171
7272/* ! \brief get number of records in the queue
7373** \return Number of records stored in the queue
7474**/
75- inline uint16_t __attribute__ ((always_inline)) cppQueue::_getCount(void ) {
75+ inline const uint16_t __attribute__ ((always_inline)) cppQueue::_getCount(void ) {
7676 return cnt; }
7777
7878
@@ -82,16 +82,16 @@ inline uint16_t __attribute__((always_inline)) cppQueue::_getCount(void) {
8282cppQueue::cppQueue (const size_t size_rec, const uint16_t nb_recs, const cppQueueType type, const bool overwrite, void * const pQDat, const size_t lenQDat)
8383{
8484 init = 0 ;
85- rec_nb = 0 ; // rec_nb needs to be 0 to ensure proper push behavior when queue is not allocated
86- ovw = 0 ; // ovw needs to be 0 to ensure proper push behavior when queue is not allocated
87- flush (); // other variables needs to be 0 to ensure proper functions behavior when queue is not allocated
85+ rec_nb = 0 ; // rec_nb needs to be 0 to ensure proper push behavior when queue is not allocated
86+ ovw = false ; // ovw needs to be false to ensure proper push behavior when queue is not allocated
87+ flush (); // other variables needs to be 0 to ensure proper functions behavior when queue is not allocated
8888
8989 const size_t size = nb_recs * size_rec;
9090
91- dynamic = (pQDat == NULL ) ? true : false ;
91+ dynamic = (pQDat == NULL );
9292
93- if (dynamic) { queue = ( uint8_t *) malloc (size); }
94- else if (lenQDat >= size) { queue = ( uint8_t *) pQDat; }
93+ if (dynamic) { queue = static_cast < uint8_t *>( malloc (size) ); }
94+ else if (lenQDat >= size) { queue = static_cast < uint8_t *>( pQDat) ; }
9595 else { queue = NULL ; }
9696
9797 if (queue != NULL )
@@ -130,7 +130,7 @@ bool __attribute__((nonnull)) cppQueue::push(const void * const record)
130130 {
131131 if (impl == FIFO)
132132 {
133- _inc_idx (&out, rec_nb, 0 ); // as oldest record is overwritten, increment out
133+ cppq_inc_idx (&out, rec_nb, 0 ); // as oldest record is overwritten, increment out
134134 }
135135 // else if (impl == LIFO) {} // Nothing to do in this case
136136 }
@@ -148,7 +148,7 @@ bool __attribute__((nonnull)) cppQueue::push(const void * const record)
148148 {
149149 uint8_t * const pStart = queue + (rec_sz * in);
150150 memcpy (pStart, record, rec_sz);
151- _inc_idx (&in, rec_nb, 0 );
151+ cppq_inc_idx (&in, rec_nb, 0 );
152152 }
153153
154154 return ret;
@@ -169,11 +169,11 @@ bool __attribute__((nonnull)) cppQueue::pop(void * const record)
169169 if (impl == FIFO)
170170 {
171171 pStart = queue + (rec_sz * out);
172- _inc_idx (&out, rec_nb, 0 );
172+ cppq_inc_idx (&out, rec_nb, 0 );
173173 }
174174 else /* if (impl == LIFO) */
175175 {
176- _dec_idx (&in, rec_nb, 0 );
176+ cppq_dec_idx (&in, rec_nb, 0 );
177177 pStart = queue + (rec_sz * in);
178178 }
179179
@@ -205,7 +205,7 @@ bool __attribute__((nonnull)) cppQueue::peek(void * const record)
205205 else /* if (impl == LIFO)*/
206206 {
207207 uint16_t rec = in; // Temporary var for peek (no change on in with dec_idx)
208- _dec_idx (&rec, rec_nb, 0 );
208+ cppq_dec_idx (&rec, rec_nb, 0 );
209209 pStart = queue + (rec_sz * rec);
210210 }
211211
@@ -228,11 +228,11 @@ bool cppQueue::drop(void)
228228 {
229229 if (impl == FIFO)
230230 {
231- _inc_idx (&out, rec_nb, 0 );
231+ cppq_inc_idx (&out, rec_nb, 0 );
232232 }
233233 else /* if (impl == LIFO)*/
234234 {
235- _dec_idx (&in, rec_nb, 0 );
235+ cppq_dec_idx (&in, rec_nb, 0 );
236236 }
237237
238238 cnt--; // Decrease records count
@@ -280,21 +280,21 @@ bool __attribute__((nonnull)) cppQueue::peekPrevious(void * const record)
280280/* *********************/
281281/* ** PUBLIC GETTERS ***/
282282/* *********************/
283- bool cppQueue::isInitialized (void ) {
283+ const bool cppQueue::isInitialized (void ) {
284284 return _isInitialized (); }
285285
286- bool cppQueue::isEmpty (void ) {
286+ const bool cppQueue::isEmpty (void ) {
287287 return _isEmpty (); }
288288
289- bool cppQueue::isFull (void ) {
289+ const bool cppQueue::isFull (void ) {
290290 return _isFull (); }
291291
292- uint32_t cppQueue::sizeOf (void ) {
292+ const uint32_t cppQueue::sizeOf (void ) {
293293 return queue_sz; }
294294
295- uint16_t cppQueue::getCount (void ) {
295+ const uint16_t cppQueue::getCount (void ) {
296296 return _getCount (); }
297297
298- uint16_t cppQueue::getRemainingCount (void ) {
298+ const uint16_t cppQueue::getRemainingCount (void ) {
299299 return rec_nb - cnt; }
300300
0 commit comments