Skip to content

Commit 70ee2d3

Browse files
committed
v1.6: Added sizeOf inline
1 parent 0cc2761 commit 70ee2d3

File tree

8 files changed

+41
-23
lines changed

8 files changed

+41
-23
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ language: c
22
sudo: false
33

44
addons:
5-
apt:
6-
packages:
7-
- graphviz
5+
apt:
6+
packages:
7+
- graphviz
88

99
# Blacklist
1010
branches:

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ WARN_FORMAT = "$file:$line: $text"
768768
# messages should be written. If left blank the output is written to standard
769769
# error (stderr).
770770

771-
WARN_LOGFILE = doxy.log
771+
WARN_LOGFILE = workdir/doxy.log
772772

773773
#---------------------------------------------------------------------------
774774
# Configuration options related to the input files

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This library was designed for Arduino, yet may be compiled without change with g
2727
- `q.IsInitialized()`: `true` if initialized properly, `false` otherwise
2828
- `q.isEmpty()`: `true` if full, `false` otherwise
2929
- `q.isFull()`: `true` if empty, `false` otherwise
30+
- `q.sizeOf()`: queue size in bytes (returns 0 in case queue allocation failed)
3031
- `q.getCount()` or `q.nbRecs()`: number of records in the queue
3132
- `q.clean()` or `q.flush()`: remove all items in the queue
3233

ReleaseNotes.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ Queue handling library (designed on Arduino)
33

44
Feel free to share your thoughts @ [email protected] about:
55
- issues encountered
6-
- optimisations
6+
- optimizations
77
- improvements & new functionalities
88

99
------------
1010

1111
** Actual:
1212

13-
v1.6 3 May 2018:
13+
v1.6 21 May 2018:
1414
- Constructor does not check anymore if class instance is already allocated (as it supposedly isn't)
15+
- Added sizeOf inline to check full queue size in byte (may also be used to check if queue has been allocated properly)
1516
- Adding support for unit tests and doxygen documentation generation with Travis CI (using travis-ci-arduino from adafruit before custom bash files needed)
1617
- Travis bash scripts found in SMFSW travis-ci-arduino forked repository
1718
- Removed Doxygen anchor with version in source headers
@@ -27,7 +28,7 @@ v1.4 21 November 2017:
2728
- Added const qualifier for function parameters
2829

2930
v1.3 12 July 2017:
30-
- #2 fix for esp8266: reanamed cpp/h files : header name already used in compiler sys includes
31+
- #2 fix for esp8266: renamed cpp/h files : header name already used in compiler sys includes
3132
- examples updated with new header file name (cppQueue.h)
3233
- comply with Arduino v1.5+ IDE source located in src subfolder
3334

examples/LibTst/LibTst.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
This example code is in the public domain.
77
88
created 22 March 2017
9-
modified 22 March 2018
9+
modified 21 May 2018
1010
by SMFSW
1111
*/
1212

@@ -38,6 +38,10 @@ Queue q(sizeof(Rec), 10, IMPLEMENTATION, OVERWRITE); // Instantiate queue
3838
// the setup function runs once when you press reset or power the board
3939
void setup() {
4040
Serial.begin(115200);
41+
42+
Serial.print("Queue is ");
43+
Serial.print(q.sizeOf());
44+
Serial.println(" bytes long.");
4145
}
4246

4347
// the loop function runs over and over again forever

keywords.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ flush KEYWORD2
1717
isInitialized KEYWORD2
1818
isEmpty KEYWORD2
1919
isFull KEYWORD2
20-
nbRecs KEYWORD2
20+
sizeOf KEYWORD2
2121
getCount KEYWORD2
22+
nbRecs KEYWORD2
2223
push KEYWORD2
2324
pop KEYWORD2
2425
pull KEYWORD2

src/cppQueue.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
/*!\file cppQueue.cpp
22
** \author SMFSW
3-
** \date 2018/03/14
3+
** \date 2018/05/21
44
** \copyright BSD 3-Clause License (c) 2017-2018, SMFSW
55
** \brief Queue handling library (designed on Arduino)
66
** \details Queue handling library (designed on Arduino)
7-
** This library was designed for Arduino, yet may be compiled without change with gcc for other purporses/targets
7+
** This library was designed for Arduino, yet may be compiled without change with gcc for other purposes/targets
88
**/
9-
10-
11-
extern "C"
12-
{
9+
/****************************************************************/
10+
extern "C" {
1311
#include <string.h>
1412
#include <stdlib.h>
1513
}
1614

1715
#include "cppQueue.h"
16+
/****************************************************************/
1817

1918

2019
#define INC_IDX(ctr, end, start) if (ctr < (end-1)) { ctr++; } \
@@ -26,6 +25,8 @@ extern "C"
2625

2726
Queue::Queue(const uint16_t size_rec, const uint16_t nb_recs, const QueueType type, const bool overwrite)
2827
{
28+
uint32_t size = nb_recs * size_rec;
29+
2930
rec_nb = nb_recs;
3031
rec_sz = size_rec;
3132
impl = type;
@@ -34,9 +35,10 @@ Queue::Queue(const uint16_t size_rec, const uint16_t nb_recs, const QueueType ty
3435
init = 0;
3536

3637
//if (queue) { free(queue); } // Free existing data (if any)
37-
queue = (uint8_t *) malloc(nb_recs * size_rec);
38+
queue = (uint8_t *) malloc(size);
3839

39-
if (queue == NULL) { return; } // Return here if Queue not allocated
40+
if (queue == NULL) { queue_sz = 0; return; } // Return here if Queue not allocated
41+
else { queue_sz = size; }
4042

4143
init = QUEUE_INITIALIZED;
4244
flush();

src/cppQueue.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/*!\file cppQueue.h
22
** \author SMFSW
3-
** \date 2018/03/14
3+
** \date 2018/05/21
44
** \copyright BSD 3-Clause License (c) 2017-2018, SMFSW
55
** \brief Queue handling library (designed on Arduino)
66
** \details Queue handling library (designed on Arduino)
7-
** This library was designed for Arduino, yet may be compiled without change with gcc for other purporses/targets
7+
** This library was designed for Arduino, yet may be compiled without change with gcc for other purposes/targets
88
**/
9-
10-
#ifndef __CPPQUEUE_H__
11-
#define __CPPQUEUE_H__
9+
/****************************************************************/
10+
#ifndef __CPPQUEUE_H
11+
#define __CPPQUEUE_H
1212

1313
#include <inttypes.h>
14+
/****************************************************************/
1415

1516

1617
#define QUEUE_INITIALIZED 0x5AA5 //!< Queue initialized control value
@@ -35,6 +36,7 @@ class Queue
3536
bool ovw; //!< Overwrite previous records when queue is full allowed
3637
uint16_t rec_nb; //!< number of records in the queue
3738
uint16_t rec_sz; //!< Size of a record
39+
uint32_t queue_sz; //!< Size of the full queue
3840
uint8_t * queue; //!< Queue start pointer (when allocated)
3941

4042
uint16_t in; //!< number of records pushed into the queue
@@ -89,6 +91,13 @@ class Queue
8991
inline bool isFull(void) __attribute__((always_inline)) {
9092
return (cnt == rec_nb) ? true : false; }
9193

94+
/*! \brief get size of queue
95+
** \remark Size in bytes (like sizeof)
96+
** \return Size of queue in bytes
97+
**/
98+
inline uint32_t sizeOf(void) __attribute__((always_inline)) {
99+
return queue_sz; }
100+
92101
/*! \brief get number of records in the queue
93102
** \return Number of records left in the queue
94103
**/
@@ -152,4 +161,4 @@ class Queue
152161
bool drop(void);
153162
};
154163

155-
#endif /* __CPPQUEUE_H__ */
164+
#endif /* __CPPQUEUE_H */

0 commit comments

Comments
 (0)