You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-19Lines changed: 20 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,26 @@ I needed a way to buffer sensor events for a group engineering IOT project that
7
7
8
8
I decided to give object oriented programming a shot using only C (no C++) with this library, of course, it still compiles with C++ compilers such as in the Arduino IDE. Using C structs and function pointers, the library creates RingBuf objects that are complete with their own methods and attributes. Note that every method (except constructor), takes a `RingBuf *self` pointer. This is the equivalent of the `this` pointer in C++, but the C++ compiler automatically passes it behind the scenes. For this library, you must manually pass a the `RingBuf *self` pointer as the first argument.
9
9
10
+
11
+
## But I like C++'s object syntax... :(
12
+
13
+
Fine. I reluctantly wrapped the C in a C++ class called `RingBufC`. All the methods are the same, except you no longer have to pass the this/self pointer. You can use either.
14
+
15
+
```
16
+
// If you want to use C...
17
+
18
+
RingBuf *buf = RingBuf_new(sizeof(char*), 100);
19
+
buf->add(buf, "I like C.");
20
+
```
21
+
22
+
```
23
+
// If you want to use the C++ wrapper
24
+
25
+
RingBufC buf(sizeof(char*), 100);
26
+
buf.add("C++ has pretty object.method() syntax");
27
+
```
28
+
29
+
10
30
## Use Cases
11
31
12
32
A ring buffer is used when passing asynchronous io between two threads. In the case of the Arduino, it is very useful for buffering data in an interrupt routine that is later processed in your `void loop()`.
@@ -29,25 +49,6 @@ Feel free to improve this library. Fork it, make your changes, then submit a pul
29
49
30
50
## API
31
51
32
-
## But I like C++'s object syntax... :(
33
-
34
-
Fine. I reluctantly wrapped the C in a C++ class called `RingBufC`. All the methods are the same, except you no longer have to pass the this/self pointer. You can use either.
0 commit comments