Skip to content

Commit 11a1a16

Browse files
committed
v1.6: added getRemainingCount inline & eaxmple sketch
1 parent 9ece8df commit 11a1a16

File tree

8 files changed

+72
-22
lines changed

8 files changed

+72
-22
lines changed

Clean.bat

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ This library was designed for Arduino, yet may be compiled without change with g
2828
- `q.isEmpty()`: `true` if full, `false` otherwise
2929
- `q.isFull()`: `true` if empty, `false` otherwise
3030
- `q.sizeOf()`: queue size in bytes (returns 0 in case queue allocation failed)
31-
- `q.getCount()` or `q.nbRecs()`: number of records in the queue
31+
- `q.getCount()` or `q.nbRecs()`: number of records stored in the queue
32+
- `q.getRemainingCount()`: number of records left in the queue
3233
- `q.clean()` or `q.flush()`: remove all items in the queue
3334

3435
## Examples included
3536

3637
- [SimpleQueue.ino](examples/SimpleQueue/SimpleQueue.ino): Simple queue example (both LIFO FIFO implementations can be tested)
38+
- [PointersQueue.ino](examples/PointersQueue/PointersQueue.ino): Queue of string pointers for string processing
3739
- [RolloverTest.ino](examples/RolloverTest/RolloverTest.ino): Simple test to test queue rollover (for lib testing purposes mainly)
3840
- [LibTst.ino](examples/LibTst/LibTst.ino): flexible test (for lib testing purposes mainly)
3941

ReleaseNotes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ Feel free to share your thoughts @ [email protected] about:
1010

1111
** Actual:
1212

13-
v1.6 21 May 2018:
13+
v1.6 26 May 2018:
1414
- Constructor does not check anymore if class instance is already allocated (as it supposedly isn't)
15+
- Added getRemainingCount inline returning how much records are left in the queue
1516
- Added sizeOf inline to check full queue size in byte (may also be used to check if queue has been allocated properly)
1617
- Adding support for unit tests and doxygen documentation generation with Travis CI (using travis-ci-arduino from adafruit before custom bash files needed)
1718
- Travis bash scripts found in SMFSW travis-ci-arduino forked repository
1819
- Removed Doxygen anchor with version in source headers
1920
- Updated README.md
21+
- Added more example sketches & updated LibTst example using latest inlines additions
2022

2123
v1.5 14 March 2018:
2224
- Added isInitialized inline to be able to check after init if queue has been properly allocated

examples/LibTst/LibTst.ino

Lines changed: 3 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 21 May 2018
9+
modified 26 May 2018
1010
by SMFSW
1111
*/
1212

@@ -57,6 +57,8 @@ void loop() {
5757
Serial.print(rec.entry2, HEX);
5858
Serial.print(" Count ");
5959
Serial.print(q.getCount());
60+
Serial.print(" Remaining ");
61+
Serial.print(q.getRemainingCount());
6062
Serial.print(" Full? ");
6163
Serial.println(q.isFull());
6264
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Pointers Queue
3+
Pointers queue demonstration
4+
5+
This example code is in the public domain.
6+
7+
created 25 May 2018
8+
by SMFSW
9+
*/
10+
11+
#include <cppQueue.h>
12+
13+
14+
const char * str[3] = {
15+
">>> This example demonstrates how to strip quotes",
16+
">>> from strings using a queue of pointers",
17+
">>> to access methods from the string class."
18+
};
19+
20+
Queue q(sizeof(String *), 3, FIFO); // Instantiate queue
21+
22+
23+
// the setup function runs once when you press reset or power the board
24+
void setup() {
25+
Serial.begin(115200);
26+
}
27+
28+
// the loop function runs over and over again forever
29+
void loop() {
30+
String strings[3];
31+
String * pStr;
32+
33+
Serial.println("Original text:");
34+
for (unsigned int i = 0 ; i < 3 ; i++)
35+
{
36+
strings[i] = str[i];
37+
pStr = &strings[i];
38+
q.push(&pStr);
39+
Serial.println(strings[i]);
40+
}
41+
42+
Serial.println("");
43+
Serial.println("Processed text:");
44+
for (unsigned int i = 0 ; i < 3 ; i++)
45+
{
46+
q.pop(&pStr);
47+
pStr->remove(0, 4);
48+
Serial.println(*pStr);
49+
}
50+
51+
while(1);
52+
}

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ isFull KEYWORD2
2020
sizeOf KEYWORD2
2121
getCount KEYWORD2
2222
nbRecs KEYWORD2
23+
getRemainingCount KEYWORD2
2324
push KEYWORD2
2425
pop KEYWORD2
2526
pull KEYWORD2

src/cppQueue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!\file cppQueue.cpp
22
** \author SMFSW
3-
** \date 2018/05/21
3+
** \date 2018/05/26
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)

src/cppQueue.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!\file cppQueue.h
22
** \author SMFSW
3-
** \date 2018/05/21
3+
** \date 2018/05/26
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)
@@ -99,18 +99,24 @@ class Queue
9999
return queue_sz; }
100100

101101
/*! \brief get number of records in the queue
102-
** \return Number of records left in the queue
102+
** \return Number of records stored in the queue
103103
**/
104104
inline uint16_t getCount(void) __attribute__((always_inline)) {
105105
return cnt; }
106106

107107
/*! \brief get number of records in the queue (same as getCount)
108108
** \deprecated nbRecs was already used in Queue lib, alias is made to keep compatibility with earlier versions
109-
** \return Number of records left in the queue
109+
** \return Number of records stored in the queue
110110
**/
111111
inline uint16_t nbRecs(void) __attribute__((always_inline)) {
112112
return getCount(); }
113113

114+
/*! \brief get number of records left in the queue
115+
** \return Number of records left in the queue
116+
**/
117+
inline uint16_t getRemainingCount(void) __attribute__((always_inline)) {
118+
return rec_nb - cnt; }
119+
114120
/*! \brief Push record to queue
115121
** \param [in] record - pointer to record to be pushed into queue
116122
** \return Push status

0 commit comments

Comments
 (0)