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.
Loading...
Searching...
No Matches
ios.h
Go to the documentation of this file.
1
25#ifndef ios_h
26#define ios_h
27#include "../FsLib/FsLib.h"
32//==============================================================================
34typedef fspos_t pos_t;
35//==============================================================================
36#if SDFAT_FILE_TYPE == 1
39#elif SDFAT_FILE_TYPE == 2
41#elif SDFAT_FILE_TYPE == 3
43#else // SDFAT_FILE_TYPE
44#error Invalid SDFAT_FILE_TYPE
45#endif // SDFAT_FILE_TYPE
50class ios_base
51{
52 public:
54 typedef unsigned char iostate;
55 // State flags.
57 static const iostate goodbit = 0x00;
59 static const iostate badbit = 0X01;
61 static const iostate eofbit = 0x02;
63 static const iostate failbit = 0X04;
64#if SDFAT_FILE_TYPE == 1
69 typedef uint32_t streamsize;
71 typedef uint32_t pos_type;
73 typedef int32_t off_type;
74#else // SDFAT_FILE_TYPE
79 typedef uint64_t streamsize;
81 typedef uint64_t pos_type;
83 typedef int64_t off_type;
84#endif // SDFAT_FILE_TYPE
86 enum seekdir
87 {
93 end
94 };
96 typedef unsigned int fmtflags;
98 static const fmtflags left = 0x0001;
100 static const fmtflags right = 0x0002;
102 static const fmtflags internal = 0x0004;
104 static const fmtflags dec = 0x0008;
106 static const fmtflags hex = 0x0010;
108 static const fmtflags oct = 0x0020;
109 // static const fmtflags fixed = 0x0040;
110 // static const fmtflags scientific = 0x0080;
112 static const fmtflags boolalpha = 0x0100;
114 static const fmtflags showbase = 0x0200;
116 static const fmtflags showpoint = 0x0400;
118 static const fmtflags showpos = 0x0800;
120 static const fmtflags skipws = 0x1000;
121 // static const fmtflags unitbuf = 0x2000;
123 static const fmtflags uppercase = 0x4000;
125 static const fmtflags adjustfield = left | right | internal;
127 static const fmtflags basefield = dec | hex | oct;
128 // static const fmtflags floatfield = scientific | fixed;
129 //----------------------------------------------------------------------------
131 typedef uint8_t openmode;
132
133 // Openmode flags.
135 static const openmode app = 0X4;
137 static const openmode ate = 0X8;
139 static const openmode binary = 0X10;
141 static const openmode in = 0X20;
143 static const openmode out = 0X40;
145 static const openmode trunc = 0X80;
146 //----------------------------------------------------------------------------
147 ios_base() : m_fill(' '), m_fmtflags(dec | right | skipws), m_precision(2), m_width(0)
148 {
149 }
151 char fill()
152 {
153 return m_fill;
154 }
159 char fill(char c)
160 {
161 char r = m_fill;
162 m_fill = c;
163 return r;
164 }
167 {
168 return m_fmtflags;
169 }
175 {
176 fmtflags tmp = m_fmtflags;
177 m_fmtflags = fl;
178 return tmp;
179 }
181 int precision() const
182 {
183 return m_precision;
184 }
189 int precision(unsigned int n)
190 {
191 int r = m_precision;
192 m_precision = n;
193 return r;
194 }
200 {
201 fmtflags r = m_fmtflags;
202 m_fmtflags |= fl;
203 return r;
204 }
211 {
212 fmtflags r = m_fmtflags;
213 m_fmtflags &= ~mask;
214 m_fmtflags |= fl;
215 return r;
216 }
221 {
222 m_fmtflags &= ~fl;
223 }
225 unsigned width()
226 {
227 return m_width;
228 }
233 unsigned width(unsigned n)
234 {
235 unsigned r = m_width;
236 m_width = n;
237 return r;
238 }
239
240 protected:
242 uint8_t flagsToBase()
243 {
244 uint8_t f = flags() & basefield;
245 return f == oct ? 8 : f != hex ? 10 : 16;
246 }
247
248 private:
249 char m_fill;
251 unsigned char m_precision;
252 unsigned int m_width;
253};
254//------------------------------------------------------------------------------
260{
262 return str;
263}
268inline ios_base &dec(ios_base &str)
269{
271 return str;
272}
277inline ios_base &hex(ios_base &str)
278{
280 return str;
281}
287{
289 return str;
290}
295inline ios_base &left(ios_base &str)
296{
298 return str;
299}
305{
307 return str;
308}
314{
316 return str;
317}
323{
325 return str;
326}
332{
334 return str;
335}
341{
343 return str;
344}
350{
352 return str;
353}
358inline ios_base &oct(ios_base &str)
359{
361 return str;
362}
368{
370 return str;
371}
377{
379 return str;
380}
386{
388 return str;
389}
395{
397 return str;
398}
404{
406 return str;
407}
413{
415 return str;
416}
417//==============================================================================
422class ios : public ios_base
423{
424 public:
427 {
428 }
429
431 operator const void *() const
432 {
433 return !fail() ? reinterpret_cast<const void *>(this) : nullptr;
434 }
436 bool operator!() const
437 {
438 return fail();
439 }
441 explicit operator bool() const
442 {
443 return !fail();
444 }
447 {
448 return m_iostate;
449 }
451 bool good() const
452 {
453 return m_iostate == goodbit;
454 }
462 bool eof() const
463 {
464 return m_iostate & eofbit;
465 }
467 bool fail() const
468 {
469 return m_iostate & (failbit | badbit);
470 }
472 bool bad() const
473 {
474 return m_iostate & badbit;
475 }
480 void clear(iostate state = goodbit)
481 {
482 m_iostate = state;
483 }
488 void setstate(iostate state)
489 {
490 m_iostate |= state;
491 }
492
493 private:
495};
496#endif // ios_h
Basic file class.
Definition ExFatFile.h:95
Basic file class.
Definition FatFile.h:112
FsBaseFile class.
Definition FsFile.h:39
Base class for all streams.
Definition ios.h:51
static const iostate goodbit
Definition ios.h:57
uint8_t flagsToBase()
Definition ios.h:242
uint64_t pos_type
Definition ios.h:81
static const fmtflags dec
Definition ios.h:104
fmtflags flags() const
Definition ios.h:166
unsigned char m_precision
Definition ios.h:251
static const fmtflags hex
Definition ios.h:106
static const iostate failbit
Definition ios.h:63
void unsetf(fmtflags fl)
Definition ios.h:220
static const fmtflags oct
Definition ios.h:108
int32_t off_type
Definition ios.h:73
ios_base()
Definition ios.h:147
int precision(unsigned int n)
Definition ios.h:189
static const fmtflags skipws
Definition ios.h:120
unsigned int m_width
Definition ios.h:252
fmtflags setf(fmtflags fl, fmtflags mask)
Definition ios.h:210
static const fmtflags basefield
Definition ios.h:127
static const fmtflags showpos
Definition ios.h:118
static const fmtflags showbase
Definition ios.h:114
char m_fill
Definition ios.h:249
uint32_t streamsize
Definition ios.h:69
int64_t off_type
Definition ios.h:83
char fill(char c)
Definition ios.h:159
uint8_t openmode
Definition ios.h:131
@ cur
Definition ios.h:91
@ beg
Definition ios.h:89
unsigned width(unsigned n)
Definition ios.h:233
fmtflags setf(fmtflags fl)
Definition ios.h:199
int precision() const
Definition ios.h:181
uint32_t pos_type
Definition ios.h:71
static const iostate badbit
Definition ios.h:59
unsigned int fmtflags
Definition ios.h:96
static const fmtflags showpoint
Definition ios.h:116
static const fmtflags left
Definition ios.h:98
static const fmtflags adjustfield
Definition ios.h:125
static const fmtflags uppercase
Definition ios.h:123
char fill()
Definition ios.h:151
fmtflags flags(fmtflags fl)
Definition ios.h:174
static const fmtflags right
Definition ios.h:100
unsigned char iostate
Definition ios.h:54
fmtflags m_fmtflags
Definition ios.h:250
static const iostate eofbit
Definition ios.h:61
unsigned width()
Definition ios.h:225
static const fmtflags boolalpha
Definition ios.h:112
static const fmtflags internal
Definition ios.h:102
Error and state information for all streams.
Definition ios.h:423
bool good() const
Definition ios.h:451
bool fail() const
Definition ios.h:467
bool bad() const
Definition ios.h:472
bool eof() const
Definition ios.h:462
void clear(iostate state=goodbit)
Definition ios.h:480
iostate m_iostate
Definition ios.h:494
ios()
Definition ios.h:426
bool operator!() const
Definition ios.h:436
void setstate(iostate state)
Definition ios.h:488
iostate rdstate() const
Definition ios.h:446
static uint8_t mask
Definition DigitalPin.h:109
ios_base & noskipws(ios_base &str)
Definition ios.h:340
ios_base & noshowpos(ios_base &str)
Definition ios.h:331
ios_base & internal(ios_base &str)
Definition ios.h:286
ios_base & skipws(ios_base &str)
Definition ios.h:403
ios_base & boolalpha(ios_base &str)
Definition ios.h:259
ios_base & right(ios_base &str)
Definition ios.h:367
ios_base & showpoint(ios_base &str)
Definition ios.h:394
ios_base & noshowpoint(ios_base &str)
Definition ios.h:322
ios_base & noboolalpha(ios_base &str)
Definition ios.h:304
ios_base & hex(ios_base &str)
Definition ios.h:277
ios_base & oct(ios_base &str)
Definition ios.h:358
ios_base & left(ios_base &str)
Definition ios.h:295
ios_base & showbase(ios_base &str)
Definition ios.h:376
ios_base & nouppercase(ios_base &str)
Definition ios.h:349
FatFile StreamBaseFile
Definition ios.h:38
fspos_t pos_t
Definition ios.h:34
ios_base & uppercase(ios_base &str)
Definition ios.h:412
ios_base & showpos(ios_base &str)
Definition ios.h:385
ios_base & dec(ios_base &str)
Definition ios.h:268
ios_base & noshowbase(ios_base &str)
Definition ios.h:313
Definition FsStructs.h:133