Soldered SD Card Arduino Library
1.0.0
Easily read and write files to and form the SD card breakout! A fork of the original SDFat library by Bill Greiman.
Toggle main menu visibility
Loading...
Searching...
No Matches
bufstream.h
Go to the documentation of this file.
1
25
#ifndef bufstream_h
26
#define bufstream_h
31
#include "
iostream.h
"
32
#include <string.h>
33
//==============================================================================
38
class
ibufstream
:
public
istream
39
{
40
public
:
42
ibufstream
()
43
{
44
}
45
49
explicit
ibufstream
(
const
char
*str)
50
{
51
init
(str);
52
}
53
57
void
init
(
const
char
*str)
58
{
59
m_buf
= str;
60
m_len
= strlen(
m_buf
);
61
m_pos
= 0;
62
clear
();
63
}
64
65
protected
:
67
int16_t getch()
68
{
69
if
(
m_pos
<
m_len
)
70
{
71
return
m_buf
[
m_pos
++];
72
}
73
setstate
(
eofbit
);
74
return
-1;
75
}
76
void
getpos(
pos_t
*pos)
77
{
78
pos->
position
=
m_pos
;
79
}
80
bool
seekoff(
off_type
off,
seekdir
way)
81
{
82
(void)off;
83
(void)way;
84
return
false
;
85
}
86
bool
seekpos(
pos_type
pos)
87
{
88
if
(pos <
m_len
)
89
{
90
m_pos
= pos;
91
return
true
;
92
}
93
return
false
;
94
}
95
void
setpos(
pos_t
*pos)
96
{
97
m_pos
= pos->
position
;
98
}
99
pos_type
tellpos()
100
{
101
return
m_pos
;
102
}
104
private
:
105
const
char
*
m_buf
=
nullptr
;
106
size_t
m_len
= 0;
107
size_t
m_pos
;
108
};
109
//==============================================================================
114
class
obufstream
:
public
ostream
115
{
116
public
:
118
obufstream
()
119
{
120
}
121
125
obufstream
(
char
*
buf
,
size_t
size)
126
{
127
init
(
buf
, size);
128
}
129
133
void
init
(
char
*
buf
,
size_t
size)
134
{
135
m_buf
=
buf
;
136
buf
[0] =
'\0'
;
137
m_size
= size;
138
m_in
= 0;
139
}
140
141
char
*
buf
()
142
{
143
return
m_buf
;
144
}
145
146
size_t
length
()
147
{
148
return
m_in
;
149
}
150
151
protected
:
153
void
putch(
char
c)
154
{
155
if
((
m_in
+ 1) >=
m_size
)
156
{
157
setstate
(
badbit
);
158
return
;
159
}
160
m_buf
[
m_in
++] = c;
161
m_buf
[
m_in
] =
'\0'
;
162
}
163
void
putstr(
const
char
*str)
164
{
165
while
(*str)
166
{
167
putch(*str++);
168
}
169
}
170
bool
seekoff(
off_type
off,
seekdir
way)
171
{
172
(void)off;
173
(void)way;
174
return
false
;
175
}
176
bool
seekpos(
pos_type
pos)
177
{
178
if
(pos >
m_in
)
179
{
180
return
false
;
181
}
182
m_in
= pos;
183
m_buf
[
m_in
] =
'\0'
;
184
return
true
;
185
}
186
bool
sync()
187
{
188
return
true
;
189
}
190
pos_type
tellpos()
191
{
192
return
m_in
;
193
}
195
private
:
196
char
*
m_buf
=
nullptr
;
197
size_t
m_size
= 0;
198
size_t
m_in
= 0;
199
};
200
#endif
// bufstream_h
ibufstream::m_len
size_t m_len
Definition
bufstream.h:106
ibufstream::init
void init(const char *str)
Definition
bufstream.h:57
ibufstream::ibufstream
ibufstream(const char *str)
Definition
bufstream.h:49
ibufstream::m_buf
const char * m_buf
Definition
bufstream.h:105
ibufstream::m_pos
size_t m_pos
Definition
bufstream.h:107
ibufstream::ibufstream
ibufstream()
Definition
bufstream.h:42
ios_base::off_type
int32_t off_type
Definition
ios.h:73
ios_base::seekdir
seekdir
Definition
ios.h:87
ios_base::pos_type
uint32_t pos_type
Definition
ios.h:71
ios_base::badbit
static const iostate badbit
Definition
ios.h:59
ios_base::eofbit
static const iostate eofbit
Definition
ios.h:61
ios::clear
void clear(iostate state=goodbit)
Definition
ios.h:480
ios::setstate
void setstate(iostate state)
Definition
ios.h:488
istream::istream
istream()
Definition
istream.h:40
obufstream::m_buf
char * m_buf
Definition
bufstream.h:196
obufstream::m_in
size_t m_in
Definition
bufstream.h:198
obufstream::obufstream
obufstream()
Definition
bufstream.h:118
obufstream::obufstream
obufstream(char *buf, size_t size)
Definition
bufstream.h:125
obufstream::init
void init(char *buf, size_t size)
Definition
bufstream.h:133
obufstream::buf
char * buf()
Definition
bufstream.h:141
obufstream::length
size_t length()
Definition
bufstream.h:146
obufstream::m_size
size_t m_size
Definition
bufstream.h:197
ostream::ostream
ostream()
Definition
ostream.h:40
pos_t
fspos_t pos_t
Definition
ios.h:34
iostream.h
iostream class
fspos_t::position
uint64_t position
Definition
FsStructs.h:134
src
iostream
bufstream.h
Generated on
for Soldered SD Card Arduino Library by
1.17.0. Dark theme by
Tilen Majerle
. All rights reserved. Copyright:
Soldered