bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
|
126.1.1
by Gustav Hartvigsson
* Using |
1 |
#pragma once
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
2 |
|
3 |
#include "defs.h" |
|
4 |
#include "Func.h" |
|
5 |
||
|
110
by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub. |
6 |
S_BEGIN_DECLS
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
7 |
|
8 |
||
9 |
/**
|
|
10 |
* @file
|
|
11 |
* @defgroup SRingBuffer SRingBuffer
|
|
12 |
* @addtogroup SRingBuffer
|
|
13 |
* @{
|
|
14 |
* An SRingBuffer is a special data structure that is circular in nature.
|
|
15 |
* It only holds bytes and as such is useful when dealing with strings and
|
|
16 |
* other eight-bit data.
|
|
17 |
*
|
|
18 |
* If you are looking for a circular array, this is not
|
|
19 |
* such a structure.
|
|
20 |
*
|
|
21 |
* @section Theory
|
|
22 |
* The theory behind a circular structure is simple: Never have to deal with
|
|
23 |
* empty slots in an array, only permit indirect, non-indexed access.
|
|
24 |
*
|
|
25 |
<pre>
|
|
|
99
by Gustav Hartvigsson
* Working on RingBuffer and Stream. |
26 |
[b|b|b|b|b|b|b|b|b|b| | | | ]
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
27 |
^ ^
|
28 |
start end
|
|
|
99
by Gustav Hartvigsson
* Working on RingBuffer and Stream. |
29 |
front back
|
30 |
||
31 |
||
32 |
||
33 |
[ | | | | | |b|b|b|b| | | | ]
|
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
34 |
^ ^
|
35 |
start end
|
|
|
99
by Gustav Hartvigsson
* Working on RingBuffer and Stream. |
36 |
front back
|
37 |
||
38 |
||
39 |
||
40 |
[b|b| | | | | | | |b|b|b|b|b]
|
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
41 |
^ ^
|
42 |
end start
|
|
|
99
by Gustav Hartvigsson
* Working on RingBuffer and Stream. |
43 |
back front
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
44 |
</pre>
|
45 |
*/
|
|
46 |
||
47 |
/**
|
|
48 |
* The SRingBuffer is an opaque data structure that represent an array that
|
|
49 |
* is circular in nature.
|
|
50 |
*/
|
|
51 |
typedef struct SRingBuffer SRingBuffer; |
|
52 |
||
53 |
/**
|
|
54 |
* Create a new SRingBuffer objects.
|
|
55 |
*
|
|
56 |
* @param len The number of items to
|
|
57 |
*/
|
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
58 |
S_EXPORTED
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
59 |
SRingBuffer * |
60 |
s_ring_buffer_new (size_t len); |
|
61 |
||
62 |
/**
|
|
63 |
* Free an SRingBuffer.
|
|
64 |
*
|
|
65 |
* @param self The SRingBuffer to free.
|
|
66 |
*/
|
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
67 |
S_EXPORTED
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
68 |
void
|
69 |
s_ring_buffer_free (SRingBuffer * self); |
|
70 |
||
71 |
/**
|
|
|
99
by Gustav Hartvigsson
* Working on RingBuffer and Stream. |
72 |
* determine
|
73 |
*/
|
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
74 |
S_EXPORTED
|
|
99
by Gustav Hartvigsson
* Working on RingBuffer and Stream. |
75 |
sboolean
|
76 |
s_ring_buffer_is_empty (SRingBuffer * self); |
|
77 |
||
78 |
/**
|
|
79 |
* Add data to the front of the ringbuffer.
|
|
80 |
*
|
|
81 |
*/
|
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
82 |
S_EXPORTED
|
|
99
by Gustav Hartvigsson
* Working on RingBuffer and Stream. |
83 |
void
|
84 |
s_ring_buffer_push (SRingBuffer * self, |
|
85 |
sbyte data); |
|
86 |
||
87 |
/**
|
|
88 |
* add an item to the back of the ringbuffer.
|
|
89 |
*/
|
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
90 |
S_EXPORTED
|
|
99
by Gustav Hartvigsson
* Working on RingBuffer and Stream. |
91 |
void
|
92 |
s_ring_buffer_push_back (SRingBuffer * self, |
|
93 |
sbyte data); |
|
94 |
||
95 |
/**
|
|
96 |
* Pop an item from the front of the array.
|
|
97 |
*/
|
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
98 |
S_EXPORTED
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
99 |
sbyte
|
100 |
s_ring_buffer_pop (SRingBuffer * self); |
|
101 |
||
102 |
/**
|
|
|
99
by Gustav Hartvigsson
* Working on RingBuffer and Stream. |
103 |
* Pop the back of the array.
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
104 |
*/
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
105 |
S_EXPORTED
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
106 |
sbyte
|
|
99
by Gustav Hartvigsson
* Working on RingBuffer and Stream. |
107 |
s_ring_buffer_pop_back (SRingBuffer * self); |
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
108 |
|
109 |
/**
|
|
110 |
* Reallocate an SRingBuffer to a now size for the internal array.
|
|
111 |
*
|
|
112 |
* @param self The SRingBuffer to reallocate.
|
|
113 |
* @param len The new length.
|
|
114 |
*/
|
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
115 |
S_EXPORTED
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
116 |
void
|
|
99
by Gustav Hartvigsson
* Working on RingBuffer and Stream. |
117 |
s_ring_buffer_realloc (SRingBuffer * self, |
118 |
size_t len); |
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
119 |
|
120 |
/**
|
|
121 |
* Get the current length of the ring buffer.
|
|
122 |
*/
|
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
123 |
S_EXPORTED
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
124 |
size_t
|
125 |
s_ring_buffer_len (SRingBuffer * self); |
|
126 |
||
127 |
/**
|
|
128 |
* Get the total size of the internal array.
|
|
129 |
*/
|
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
130 |
S_EXPORTED
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
131 |
size_t
|
132 |
s_ring_buffer_size (SRingBuffer * self); |
|
133 |
||
134 |
/**
|
|
135 |
* Iterate over the bytes in the SRingBuffer.
|
|
136 |
*
|
|
137 |
* This is the only valid way to iterate over the bytes in an SRingBuffer.
|
|
138 |
*
|
|
139 |
* @param self The SRingBuffer to iterate over.
|
|
140 |
* @param func Pointer to a function that is run on each byte.
|
|
141 |
* @param user_data Data that is provided to the function when doing the
|
|
142 |
* iteration.
|
|
143 |
*
|
|
144 |
* @note
|
|
145 |
* This does not use pop or push operations, and is thus the only way to keep
|
|
146 |
* the data and still be able to iterate over it.
|
|
147 |
*
|
|
148 |
* The signature of the function provided should be as follows
|
|
149 |
@code{C}
|
|
150 |
void
|
|
151 |
my_for_each_func (SRingBuffer * buffer,
|
|
152 |
sbyte item,
|
|
153 |
spointer user_data) {
|
|
154 |
// code here
|
|
155 |
}
|
|
156 |
@endcode
|
|
157 |
*
|
|
158 |
* To prevent warnings cast the function using the @c FOREACHFUNC() macro.
|
|
159 |
*/
|
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
160 |
S_EXPORTED
|
|
98
by Gustav Hartvigsson
* Started work on SRingBuffer to be used in SStream. |
161 |
void
|
162 |
s_ring_buffer_for_each (SRingBuffer * self, |
|
163 |
ForEachFunc func, |
|
164 |
spointer user_data); |
|
165 |
||
166 |
/**
|
|
167 |
* @}
|
|
168 |
*/
|
|
169 |
||
|
110
by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub. |
170 |
S_END_DECLS
|