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
ostream.h
Go to the documentation of this file.
1
25#ifndef ostream_h
26#define ostream_h
31#include "ios.h"
32//==============================================================================
37class ostream : public virtual ios
38{
39 public:
41 {
42 }
43
49 {
50 return pf(*this);
51 }
57 {
58 pf(*this);
59 return *this;
60 }
66 {
67 putBool(arg);
68 return *this;
69 }
74 ostream &operator<<(const char *arg)
75 {
76 putStr(arg);
77 return *this;
78 }
83 ostream &operator<<(const signed char *arg)
84 {
85 putStr((const char *)arg);
86 return *this;
87 }
92 ostream &operator<<(const unsigned char *arg)
93 {
94 putStr((const char *)arg);
95 return *this;
96 }
97#if ENABLE_ARDUINO_STRING
102 ostream &operator<<(const String &arg)
103 {
104 putStr(arg.c_str());
105 return *this;
106 }
107#endif // ENABLE_ARDUINO_STRING
112 ostream &operator<<(char arg)
113 {
114 putChar(arg);
115 return *this;
116 }
121 ostream &operator<<(signed char arg)
122 {
123 putChar(static_cast<char>(arg));
124 return *this;
125 }
130 ostream &operator<<(unsigned char arg)
131 {
132 putChar(static_cast<char>(arg));
133 return *this;
134 }
139 ostream &operator<<(double arg)
140 {
141 putDouble(arg);
142 return *this;
143 }
148 ostream &operator<<(float arg)
149 {
150 putDouble(arg);
151 return *this;
152 }
157 ostream &operator<<(short arg)
158 { // NOLINT
159 putNum((int32_t)arg);
160 return *this;
161 }
166 ostream &operator<<(unsigned short arg)
167 { // NOLINT
168 putNum((uint32_t)arg);
169 return *this;
170 }
176 {
177 putNum((int32_t)arg);
178 return *this;
179 }
184 ostream &operator<<(unsigned int arg)
185 {
186 putNum((uint32_t)arg);
187 return *this;
188 }
194 { // NOLINT
195 putNum((int32_t)arg);
196 return *this;
197 }
202 ostream &operator<<(unsigned long arg)
203 { // NOLINT
204 putNum((uint32_t)arg);
205 return *this;
206 }
211 ostream &operator<<(long long arg)
212 { // NOLINT
213 putNum((int64_t)arg);
214 return *this;
215 }
220 ostream &operator<<(unsigned long long arg)
221 { // NOLINT
222 putNum((uint64_t)arg);
223 return *this;
224 }
229 ostream &operator<<(const void *arg)
230 {
231 putNum(reinterpret_cast<uint32_t>(arg));
232 return *this;
233 }
238 ostream &operator<<(const __FlashStringHelper *arg)
239 {
240 putPgm(reinterpret_cast<const char *>(arg));
241 return *this;
242 }
252 ostream &put(char ch)
253 {
254 putch(ch);
255 return *this;
256 }
257 // ostream& write(char *str, streamsize count);
264 {
265 if (!sync())
266 {
268 }
269 return *this;
270 }
275 {
276 return tellpos();
277 }
284 {
285 if (!seekpos(pos))
286 {
288 }
289 return *this;
290 }
300 {
301 if (!seekoff(off, way))
302 {
304 }
305 return *this;
306 }
307
308 protected:
310
313 virtual void putch(char ch) = 0;
314 virtual void putstr(const char *str) = 0;
315 virtual bool seekoff(off_type pos, seekdir way) = 0;
316 virtual bool seekpos(pos_type pos) = 0;
317 virtual bool sync() = 0;
318 virtual pos_type tellpos() = 0;
320 private:
321 void do_fill(unsigned len);
322 void fill_not_left(unsigned len);
323 void putBool(bool b);
324 void putChar(char c);
325 void putDouble(double n);
326 void putNum(int32_t n);
327 void putNum(int64_t n);
328 void putNum(uint32_t n)
329 {
330 putNum(n, false);
331 }
332 void putNum(uint64_t n)
333 {
334 putNum(n, false);
335 }
336 void putPgm(const char *str);
337 void putStr(const char *str);
338
339 template <typename T> char *fmtNum(T n, char *ptr, uint8_t base)
340 {
341 char a = flags() & uppercase ? 'A' - 10 : 'a' - 10;
342 do
343 {
344 T m = n;
345 n /= base;
346 char c = m - base * n;
347 *--ptr = c < 10 ? c + '0' : c + a;
348 } while (n);
349 return ptr;
350 }
351
352 template <typename T> void putNum(T n, bool neg)
353 {
354 char buf[(8 * sizeof(T) + 2) / 3 + 2];
355 char *ptr = buf + sizeof(buf) - 1;
356 char *num;
357 char *str;
358 uint8_t base = flagsToBase();
359 *ptr = '\0';
360 str = num = fmtNum(n, ptr, base);
361 if (base == 10)
362 {
363 if (neg)
364 {
365 *--str = '-';
366 }
367 else if (flags() & showpos)
368 {
369 *--str = '+';
370 }
371 }
372 else if (flags() & showbase)
373 {
374 if (flags() & hex)
375 {
376 *--str = flags() & uppercase ? 'X' : 'x';
377 }
378 *--str = '0';
379 }
380 uint8_t len = ptr - str;
381 fmtflags adj = flags() & adjustfield;
382 if (adj == internal)
383 {
384 while (str < num)
385 {
386 putch(*str++);
387 }
388 do_fill(len);
389 }
390 else
391 {
392 // do fill for right
393 fill_not_left(len);
394 }
395 putstr(str);
396 do_fill(len);
397 }
398};
399#endif // ostream_h
static const float m[]
Definition FmtNumber.cpp:460
Base class for all streams.
Definition ios.h:51
uint8_t flagsToBase()
Definition ios.h:242
fmtflags flags() const
Definition ios.h:166
static const fmtflags hex
Definition ios.h:106
static const iostate failbit
Definition ios.h:63
int32_t off_type
Definition ios.h:73
static const fmtflags showpos
Definition ios.h:118
static const fmtflags showbase
Definition ios.h:114
seekdir
Definition ios.h:87
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 adjustfield
Definition ios.h:125
static const fmtflags uppercase
Definition ios.h:123
static const fmtflags internal
Definition ios.h:102
Error and state information for all streams.
Definition ios.h:423
void setstate(iostate state)
Definition ios.h:488
Output Stream.
Definition ostream.h:38
void putNum(T n, bool neg)
Definition ostream.h:352
ostream & operator<<(bool arg)
Definition ostream.h:65
ostream & operator<<(const char *arg)
Definition ostream.h:74
ostream & put(char ch)
Definition ostream.h:252
char * fmtNum(T n, char *ptr, uint8_t base)
Definition ostream.h:339
void putNum(uint64_t n)
Definition ostream.h:332
ostream & operator<<(unsigned short arg)
Definition ostream.h:166
void putNum(int32_t n)
Definition ostream.cpp:153
void putChar(char c)
Definition ostream.cpp:67
void putDouble(double n)
Definition ostream.cpp:74
ostream & operator<<(const unsigned char *arg)
Definition ostream.h:92
ostream & operator<<(const __FlashStringHelper *arg)
Definition ostream.h:238
void putStr(const char *str)
Definition ostream.cpp:179
ostream & operator<<(unsigned int arg)
Definition ostream.h:184
ostream & seekp(pos_type pos)
Definition ostream.h:283
ostream & operator<<(unsigned long long arg)
Definition ostream.h:220
ostream & operator<<(long long arg)
Definition ostream.h:211
ostream & operator<<(unsigned long arg)
Definition ostream.h:202
ostream & operator<<(float arg)
Definition ostream.h:148
void putNum(uint32_t n)
Definition ostream.h:328
ostream & operator<<(long arg)
Definition ostream.h:193
ostream & operator<<(int arg)
Definition ostream.h:175
void do_fill(unsigned len)
Definition ostream.cpp:31
ostream & operator<<(const void *arg)
Definition ostream.h:229
pos_type tellp()
Definition ostream.h:274
void putBool(bool b)
Definition ostream.cpp:48
ostream & operator<<(const signed char *arg)
Definition ostream.h:83
void putPgm(const char *str)
Definition ostream.cpp:165
ostream & operator<<(ios_base &(*pf)(ios_base &str))
Definition ostream.h:56
ostream & operator<<(unsigned char arg)
Definition ostream.h:130
ostream()
Definition ostream.h:40
ostream & operator<<(signed char arg)
Definition ostream.h:121
ostream & flush()
Definition ostream.h:263
ostream & operator<<(const String &arg)
Definition ostream.h:102
void fill_not_left(unsigned len)
Definition ostream.cpp:40
ostream & operator<<(ostream &(*pf)(ostream &str))
Definition ostream.h:48
ostream & operator<<(short arg)
Definition ostream.h:157
ostream & seekp(off_type off, seekdir way)
Definition ostream.h:299
ostream & operator<<(double arg)
Definition ostream.h:139
ios_base and ios classes