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
istream.h
Go to the documentation of this file.
1
25#ifndef istream_h
26#define istream_h
31#include "ios.h"
32
37class istream : public virtual ios
38{
39 public:
41 {
42 }
48 {
49 return pf(*this);
50 }
56 {
57 pf(*this);
58 return *this;
59 }
64 istream &operator>>(ios &(*pf)(ios &str))
65 {
66 pf(*this);
67 return *this;
68 }
74 istream &operator>>(char *str)
75 {
76 getStr(str);
77 return *this;
78 }
85 {
86 getChar(&ch);
87 return *this;
88 }
94 istream &operator>>(signed char *str)
95 {
96 getStr(reinterpret_cast<char *>(str));
97 return *this;
98 }
104 istream &operator>>(signed char &ch)
105 {
106 getChar(reinterpret_cast<char *>(&ch));
107 return *this;
108 }
114 istream &operator>>(unsigned char *str)
115 {
116 getStr(reinterpret_cast<char *>(str));
117 return *this;
118 }
124 istream &operator>>(unsigned char &ch)
125 {
126 getChar(reinterpret_cast<char *>(&ch));
127 return *this;
128 }
134 istream &operator>>(bool &arg)
135 {
136 getBool(&arg);
137 return *this;
138 }
144 istream &operator>>(short &arg)
145 { // NOLINT
146 getNumber(&arg);
147 return *this;
148 }
154 istream &operator>>(unsigned short &arg)
155 { // NOLINT
156 getNumber(&arg);
157 return *this;
158 }
165 {
166 getNumber(&arg);
167 return *this;
168 }
174 istream &operator>>(unsigned int &arg)
175 {
176 getNumber(&arg);
177 return *this;
178 }
184 istream &operator>>(long &arg)
185 { // NOLINT
186 getNumber(&arg);
187 return *this;
188 }
194 istream &operator>>(unsigned long &arg)
195 { // NOLINT
196 getNumber(&arg);
197 return *this;
198 }
204 istream &operator>>(double &arg)
205 {
206 getDouble(&arg);
207 return *this;
208 }
214 istream &operator>>(float &arg)
215 {
216 double v;
217 getDouble(&v);
218 arg = v;
219 return *this;
220 }
226 istream &operator>>(void *&arg)
227 {
228 uint32_t val;
229 getNumber(&val);
230 arg = reinterpret_cast<void *>(val);
231 return *this;
232 }
238 {
239 return m_gcount;
240 }
247 int get();
255 istream &get(char &ch);
270 istream &get(char *str, streamsize n, char delim = '\n');
287 istream &getline(char *str, streamsize n, char delim = '\n');
303 istream &ignore(streamsize n = 1, int delim = -1);
310 int peek();
311 // istream& read(char *str, streamsize count);
312 // streamsize readsome(char *str, streamsize count);
317 {
318 return tellpos();
319 }
326 {
327 if (!seekpos(pos))
328 {
330 }
331 return *this;
332 }
342 {
343 if (!seekoff(off, way))
344 {
346 }
347 return *this;
348 }
349 void skipWhite();
350
351 protected:
353
357 virtual int16_t getch() = 0;
363 int16_t getch(pos_t *pos)
364 {
365 getpos(pos);
366 return getch();
367 }
372 virtual void getpos(pos_t *pos) = 0;
377 virtual bool seekoff(off_type off, seekdir way) = 0;
378 virtual bool seekpos(pos_type pos) = 0;
379 virtual void setpos(pos_t *pos) = 0;
380 virtual pos_type tellpos() = 0;
381
383 private:
384 void getBool(bool *b);
385 void getChar(char *ch);
386 bool getDouble(double *value);
387 template <typename T> void getNumber(T *value);
388 bool getNumber(uint32_t posMax, uint32_t negMax, uint32_t *num);
389 void getStr(char *str);
390 int16_t readSkip();
391
392 size_t m_gcount;
393};
394//------------------------------------------------------------------------------
395template <typename T> void istream::getNumber(T *value)
396{
397 uint32_t tmp;
398 if ((T)-1 < 0)
399 {
400 // number is signed, max positive value
401 uint32_t const m = ((uint32_t)-1) >> (33 - sizeof(T) * 8);
402 // max absolute value of negative number is m + 1.
403 if (getNumber(m, m + 1, &tmp))
404 {
405 *value = (T)tmp;
406 }
407 }
408 else
409 {
410 // max unsigned value for T
411 uint32_t const m = (T)-1;
412 if (getNumber(m, m, &tmp))
413 {
414 *value = (T)tmp;
415 }
416 }
417}
418#endif // istream_h
static const float m[]
Definition FmtNumber.cpp:460
Base class for all streams.
Definition ios.h:51
static const iostate failbit
Definition ios.h:63
int32_t off_type
Definition ios.h:73
uint32_t streamsize
Definition ios.h:69
seekdir
Definition ios.h:87
uint32_t pos_type
Definition ios.h:71
Error and state information for all streams.
Definition ios.h:423
void setstate(iostate state)
Definition ios.h:488
Input Stream.
Definition istream.h:38
istream & operator>>(unsigned char &ch)
Definition istream.h:124
istream & operator>>(short &arg)
Definition istream.h:144
void skipWhite()
Definition istream.cpp:476
istream & ignore(streamsize n=1, int delim=-1)
Definition istream.cpp:424
istream & operator>>(unsigned long &arg)
Definition istream.h:194
pos_type tellg()
Definition istream.h:316
istream & operator>>(double &arg)
Definition istream.h:204
istream & operator>>(signed char &ch)
Definition istream.h:104
istream & operator>>(unsigned short &arg)
Definition istream.h:154
istream & seekg(off_type off, seekdir way)
Definition istream.h:341
int get()
Definition istream.cpp:29
int peek()
Definition istream.cpp:444
istream & operator>>(signed char *str)
Definition istream.h:94
istream & operator>>(unsigned int &arg)
Definition istream.h:174
istream & operator>>(char &ch)
Definition istream.h:84
istream & getline(char *str, streamsize n, char delim='\n')
Definition istream.cpp:276
istream & operator>>(char *str)
Definition istream.h:74
void getNumber(T *value)
Definition istream.h:395
void getStr(char *str)
Definition istream.cpp:391
istream & operator>>(int &arg)
Definition istream.h:164
istream & operator>>(void *&arg)
Definition istream.h:226
size_t m_gcount
Definition istream.h:392
void getChar(char *ch)
Definition istream.cpp:134
void getBool(bool *b)
Definition istream.cpp:85
istream & seekg(pos_type pos)
Definition istream.h:325
int16_t readSkip()
Definition istream.cpp:465
istream()
Definition istream.h:40
istream & operator>>(unsigned char *str)
Definition istream.h:114
istream & operator>>(istream &(*pf)(istream &str))
Definition istream.h:47
streamsize gcount() const
Definition istream.h:237
istream & operator>>(bool &arg)
Definition istream.h:134
istream & operator>>(ios_base &(*pf)(ios_base &str))
Definition istream.h:55
istream & operator>>(ios &(*pf)(ios &str))
Definition istream.h:64
bool getDouble(double *value)
Definition istream.cpp:152
istream & operator>>(long &arg)
Definition istream.h:184
istream & operator>>(float &arg)
Definition istream.h:214
static bool value
Definition DigitalPin.h:210
ios_base and ios classes
Definition FsStructs.h:133