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
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,15 +17,15 @@ I decided to give object oriented programming a shot using only C (no C++) with
17
17
18
18
Fine. I reluctantly wrapped the C stuff 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.
19
19
20
-
```
20
+
```c++
21
21
// If you want to use C...
22
22
char *mystr = "I like C";
23
23
24
24
RingBuf *buf = RingBuf_new(sizeof(char*), 100);
25
25
buf->add(buf, &mystr);
26
26
```
27
27
28
-
```
28
+
```c++
29
29
// If you want to use the C++ wrapper
30
30
char *mystr = "C++ has pretty object.method() syntax";
31
31
@@ -64,7 +64,7 @@ Feel free to improve this library. Fork it, make your changes, then submit a pul
64
64
65
65
### Constructor
66
66
67
-
```
67
+
```c++
68
68
RingBuf *RingBuf_new(int size, int len);
69
69
```
70
70
@@ -73,7 +73,7 @@ This would be the equivalent of `new RingBuf(int size, int len)` in C++.
73
73
74
74
### Deconstructor
75
75
76
-
```
76
+
```c++
77
77
int RingBuf_delete(RingBuf *self);
78
78
```
79
79
@@ -84,38 +84,38 @@ Deletes the RingBuf, and frees up all the memory associated with it.
84
84
85
85
### add()
86
86
87
-
```
87
+
```c++
88
88
intadd(RingBuf *self, void *object);
89
89
```
90
90
91
91
Append an element to the buffer, where object is a pointer to object you wish to append. Returns -1 on a full buffer. On success, returns the position (index) in the buffer where the element was added.
92
92
93
93
### peek()
94
94
95
-
```
95
+
```c++
96
96
void *peek(RingBuf *self, unsigned int num);
97
97
```
98
98
99
99
Peek at the num'th element in the buffer. Returns a void pointer to the location of the num'th element. If num is out of bounds or the num'th element is empty, a NULL pointer is returned. Cast the result of this call into a pointer of whatever type you are storing in the buffer. Note that this gives you direct memory access to the location of the num'th element in the buffer, allowing you to directly edit elements in the buffer. Note that while all of RingBuf's public methods are thread safe (including this one), directly using the pointer returned from this method is not thread safe. If there is a possibility an interrupt could fire and remove/modify the item pointed to by the returned pointer, disable interrupts first with `noInterrupts()`, do whatever you need to do with the pointer, then you can reenable interrupts by calling `interrupts()`.
100
100
101
101
### pull()
102
102
103
-
```
103
+
```c++
104
104
void *pull(RingBuf *self, void *object);
105
105
```
106
106
107
107
Pull the first element out of the buffer. The first element is copied into the location pointed to by object. Returns a NULL pointer if the buffer is empty, otherwise returns object.
108
108
109
109
110
110
### numElements()
111
-
```
111
+
```c++
112
112
unsigned int numElements(RingBuf *self);
113
113
```
114
114
115
115
Returns number of elements in buffer.
116
116
117
117
### isFull()
118
-
```
118
+
```c++
119
119
boolisFull(RingBuf *self);
120
120
```
121
121
@@ -124,7 +124,7 @@ Returns true if buffer is full, otherwise false.
0 commit comments