Skip to content

Commit 01f839b

Browse files
committed
Fixed readme
1 parent d2d646a commit 01f839b

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

README.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ I needed a way to buffer sensor events for a group engineering IOT project that
77

88
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.
99

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+
1030
## Use Cases
1131

1232
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
2949

3050
## API
3151

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.
35-
36-
```
37-
// If you want to use C...
38-
39-
RingBuf *buf = RingBuf_new(sizeof(char*), 100);
40-
buf->add(buf, "I like C.");
41-
```
42-
43-
```
44-
// If you want to use the C++ wrapper
45-
46-
RingBufC buf(sizeof(char*), 100);
47-
buf.add("C++ has pretty object.method() syntax");
48-
```
49-
50-
5152

5253
### Constructor
5354

0 commit comments

Comments
 (0)