arduino-emulator
Loading...
Searching...
No Matches
ArduinoCore-Linux
cores
arduino
cbuf.h
1
/*
2
cbuf.h - Circular buffer implementation
3
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
4
This file is part of the esp8266 core for Arduino environment.
5
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
10
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
15
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
#ifndef __cbuf_h
22
#define __cbuf_h
23
24
#include <stddef.h>
25
#include <stdint.h>
26
#include <string.h>
27
28
class
cbuf
29
{
30
public
:
31
cbuf
(
size_t
size);
32
~cbuf
();
33
34
size_t
resizeAdd(
size_t
addSize);
35
size_t
resize(
size_t
newSize);
36
size_t
available()
const
;
37
size_t
size();
38
39
size_t
room()
const
;
40
41
inline
bool
empty()
const
42
{
43
return
_begin == _end;
44
}
45
46
inline
bool
full()
const
47
{
48
return
wrap_if_bufend(_end + 1) == _begin;
49
}
50
51
int
peek();
52
size_t
peek(
char
*dst,
size_t
size);
53
54
int
read();
55
size_t
read(
char
* dst,
size_t
size);
56
57
size_t
write(
char
c);
58
size_t
write(
const
char
* src,
size_t
size);
59
60
void
flush();
61
size_t
remove(
size_t
size);
62
63
cbuf
*next;
64
65
protected
:
66
inline
char
* wrap_if_bufend(
char
* ptr)
const
67
{
68
return
(ptr == _bufend) ? _buf : ptr;
69
}
70
71
size_t
_size;
72
char
* _buf;
73
const
char
* _bufend;
74
char
* _begin;
75
char
* _end;
76
77
};
78
79
#endif
//__cbuf_h
cbuf
Definition
cbuf.h:29
Generated by
1.9.8