SdFat
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
fstream Class Reference

SD file input/output stream. More...

#include <SdStream.h>

Inheritance diagram for fstream:
Inheritance graph
[legend]
Collaboration diagram for fstream:
Collaboration graph
[legend]

List of all members.

Public Types

typedef unsigned int fmtflags
typedef unsigned char iostate
typedef int32_t off_type
typedef uint8_t openmode
typedef uint32_t pos_type
enum  seekdir { beg, cur, end }
typedef uint32_t streamsize

Public Member Functions

bool bad () const
void clear (iostate state=goodbit)
void close ()
bool eof () const
bool fail () const
char fill ()
char fill (char c)
fmtflags flags () const
fmtflags flags (fmtflags fl)
ostream & flush ()
 fstream (const char *path, openmode mode=in|out)
 fstream ()
streamsize gcount () const
int get ()
istream & get (char &ch)
istream & get (char *str, streamsize n, char delim= '\n')
istream & getline (char *str, streamsize count, char delim= '\n')
bool good () const
istream & ignore (streamsize n=1, int delim=-1)
bool is_open ()
void open (const char *path, openmode mode=in|out)
 operator const void * () const
bool operator! () const
ostream & operator<< (const char *arg)
ostream & operator<< (unsigned char arg)
ostream & operator<< (double arg)
ostream & operator<< (float arg)
ostream & operator<< (unsigned short arg)
ostream & operator<< (int arg)
ostream & operator<< (unsigned int arg)
ostream & operator<< (unsigned long arg)
ostream & operator<< (const void *arg)
ostream & operator<< (pgm arg)
ostream & operator<< (long arg)
ostream & operator<< (const __FlashStringHelper *arg)
ostream & operator<< (char arg)
ostream & operator<< (signed char arg)
ostream & operator<< (ostream &(*pf)(ostream &str))
ostream & operator<< (ios_base &(*pf)(ios_base &str))
ostream & operator<< (bool arg)
ostream & operator<< (const signed char *arg)
ostream & operator<< (const unsigned char *arg)
ostream & operator<< (short arg)
istream & operator>> (istream &(*pf)(istream &str))
istream & operator>> (ios_base &(*pf)(ios_base &str))
istream & operator>> (unsigned char &ch)
istream & operator>> (unsigned char *str)
istream & operator>> (unsigned short &arg)
istream & operator>> (float &arg)
istream & operator>> (unsigned int &arg)
istream & operator>> (char *str)
istream & operator>> (long &arg)
istream & operator>> (char &ch)
istream & operator>> (unsigned long &arg)
istream & operator>> (int &arg)
istream & operator>> (signed char &ch)
istream & operator>> (void *&arg)
istream & operator>> (double &arg)
istream & operator>> (ios &(*pf)(ios &str))
istream & operator>> (signed char *str)
istream & operator>> (short &arg)
istream & operator>> (bool &arg)
int peek ()
int precision (unsigned int n)
int precision () const
ostream & put (char ch)
iostate rdstate () const
istream & seekg (pos_type pos)
istream & seekg (off_type off, seekdir way)
ostream & seekp (pos_type pos)
ostream & seekp (off_type off, seekdir way)
fmtflags setf (fmtflags fl, fmtflags mask)
fmtflags setf (fmtflags fl)
void setstate (iostate state)
void skipWhite ()
pos_type tellg ()
pos_type tellp ()
void unsetf (fmtflags fl)
unsigned width (unsigned n)
unsigned width ()

Static Public Attributes

static const fmtflags adjustfield = left | right | internal
static const openmode app = 0X4
static const openmode ate = 0X8
static const iostate badbit = 0X01
static const fmtflags basefield = dec | hex | oct
static const openmode binary = 0X10
static const fmtflags boolalpha = 0x0100
static const fmtflags dec = 0x0008
static const iostate eofbit = 0x02
static const iostate failbit = 0X04
static const iostate goodbit = 0x00
static const fmtflags hex = 0x0010
static const openmode in = 0X20
static const fmtflags internal = 0x0004
static const fmtflags left = 0x0001
static const fmtflags oct = 0x0020
static const openmode out = 0X40
static const fmtflags right = 0x0002
static const fmtflags showbase = 0x0200
static const fmtflags showpoint = 0x0400
static const fmtflags showpos = 0x0800
static const fmtflags skipws = 0x1000
static const openmode trunc = 0X80
static const fmtflags uppercase = 0x4000

Protected Member Functions

uint8_t flagsToBase ()

Private Member Functions

uint32_t available ()
void clearWriteError ()
bool contiguousRange (uint32_t *bgnBlock, uint32_t *endBlock)
bool createContiguous (SdBaseFile *dirFile, const char *path, uint32_t size)
uint32_t curCluster () const
uint32_t curPosition () const
bool dirEntry (dir_t *dir)
bool exists (const char *name)
int16_t fgets (char *str, int16_t num, char *delim=0)
uint32_t fileSize () const
uint32_t firstCluster () const
bool getFilename (char *name)
void getpos (FatPos_t *pos)
bool getWriteError ()
bool isDir () const
bool isFile () const
bool isOpen () const
bool isRoot () const
bool isSubDir () const
void ls (Print *pr, uint8_t flags=0, uint8_t indent=0)
void ls (uint8_t flags=0)
bool mkdir (SdBaseFile *dir, const char *path, bool pFlag=true)
bool open (SdBaseFile *dirFile, uint16_t index, uint8_t oflag)
bool open (SdBaseFile *dirFile, const char *path, uint8_t oflag)
bool openNext (SdBaseFile *dirFile, uint8_t oflag)
bool openRoot (SdVolume *vol)
int peek ()
bool printCreateDateTime (Print *pr)
int printField (int32_t value, char term)
int printField (uint32_t value, char term)
int printField (uint16_t value, char term)
int printField (int16_t value, char term)
bool printModifyDateTime (Print *pr)
bool printName (Print *pr)
bool printName ()
int16_t read ()
int read (void *buf, size_t nbyte)
int8_t readDir (dir_t *dir)
bool remove ()
bool rename (SdBaseFile *dirFile, const char *newPath)
void rewind ()
bool rmdir ()
bool rmRfStar ()
bool seekCur (int32_t offset)
bool seekEnd (int32_t offset=0)
bool seekSet (uint32_t pos)
void setpos (FatPos_t *pos)
bool sync ()
bool timestamp (SdBaseFile *file)
bool timestamp (uint8_t flag, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
bool truncate (uint32_t size)
uint8_t type () const
SdVolume * volume () const
int write (const void *buf, size_t nbyte)

Static Private Member Functions

static SdBaseFile * cwd ()
static void dateTimeCallback (void(*dateTime)(uint16_t *date, uint16_t *time))
static void dateTimeCallbackCancel ()
static void dirName (const dir_t &dir, char *name)
static void printFatDate (uint16_t fatDate)
static void printFatDate (Print *pr, uint16_t fatDate)
static void printFatTime (Print *pr, uint16_t fatTime)
static void printFatTime (uint16_t fatTime)
static bool remove (SdBaseFile *dirFile, const char *path)

Private Attributes

bool writeError

Detailed Description

SD file input/output stream.


Member Typedef Documentation

typedef unsigned int ios_base::fmtflags [inherited]

type for format flags

typedef unsigned char ios_base::iostate [inherited]

typedef for iostate bitmask

typedef int32_t ios_base::off_type [inherited]

type for relative seek offset

typedef uint8_t ios_base::openmode [inherited]

typedef for iostream open mode

typedef uint32_t ios_base::pos_type [inherited]

type for absolute seek position

typedef uint32_t ios_base::streamsize [inherited]

unsigned size that can represent maximum file size. (violates spec - should be signed)


Member Enumeration Documentation

enum ios_base::seekdir [inherited]

enumerated type for the direction of relative seeks

Enumerator:
beg 

seek relative to the beginning of the stream

cur 

seek relative to the current stream position

end 

seek relative to the end of the stream


Constructor & Destructor Documentation

fstream::fstream ( ) [inline]
fstream::fstream ( const char *  path,
openmode  mode = in | out 
) [inline, explicit]

Constructor with open

Parameters:
[in]pathpath to open
[in]modeopen mode

Member Function Documentation

bool ios::bad ( ) const [inline, inherited]
Returns:
true if bad bit is set else false.
void fstream::clear ( iostate  state = goodbit) [inline]

Clear state and writeError

Parameters:
[in]statenew state for stream

Reimplemented from ios.

void fstream::close ( ) [inline]

Close a file and force cached data and directory information to be written to the storage device.

Reimplemented from SdBaseFile.

bool ios::eof ( ) const [inline, inherited]
Returns:
true if end of file has been reached else false.

Warning: An empty file returns false before the first read.

Moral: eof() is only useful in combination with fail(), to find out whether EOF was the cause for failure

bool ios::fail ( ) const [inline, inherited]
Returns:
true if any iostate bit other than eof are set else false.
char ios_base::fill ( ) [inline, inherited]
Returns:
fill character
char ios_base::fill ( char  c) [inline, inherited]

Set fill character

Parameters:
[in]cnew fill character
Returns:
old fill character
fmtflags ios_base::flags ( ) const [inline, inherited]
Returns:
format flags
fmtflags ios_base::flags ( fmtflags  fl) [inline, inherited]

set format flags

Parameters:
[in]flnew flag
Returns:
old flags
uint8_t ios_base::flagsToBase ( ) [inline, protected, inherited]
Returns:
current number base
ostream& ostream::flush ( ) [inline, inherited]

Flushes the buffer associated with this stream. The flush function calls the sync function of the associated file.

Returns:
A reference to the ostream object.
streamsize istream::gcount ( ) const [inline, inherited]
Returns:
The number of characters extracted by the last unformatted input function.
int istream::get ( ) [inherited]

Extract a character if one is available.

Returns:
The character or -1 if a failure occurs. A failure is indicated by the stream state.
istream & istream::get ( char &  c) [inherited]

Extract a character if one is available.

Parameters:
[out]clocation to receive the extracted character.
Returns:
always returns *this. A failure is indicated by the stream state.
istream & istream::get ( char *  str,
streamsize  n,
char  delim = '\n' 
) [inherited]

Extract characters.

Parameters:
[out]strLocation to receive extracted characters.
[in]nSize of str.
[in]delimDelimiter

Characters are extracted until extraction fails, n is less than 1, n-1 characters are extracted, or the next character equals delim (delim is not extracted). If no characters are extracted failbit is set. If end-of-file occurs the eofbit is set.

Returns:
always returns *this. A failure is indicated by the stream state.
istream & istream::getline ( char *  str,
streamsize  n,
char  delim = '\n' 
) [inherited]

Extract characters

Parameters:
[out]strLocation to receive extracted characters.
[in]nSize of str.
[in]delimDelimiter

Characters are extracted until extraction fails, the next character equals delim (delim is extracted), or n-1 characters are extracted.

The failbit is set if no characters are extracted or n-1 characters are extracted. If end-of-file occurs the eofbit is set.

Returns:
always returns *this. A failure is indicated by the stream state.
bool ios::good ( ) const [inline, inherited]
Returns:
True if no iostate flags are set else false.
istream & istream::ignore ( streamsize  n = 1,
int  delim = -1 
) [inherited]

Extract characters and discard them.

Parameters:
[in]nmaximum number of characters to ignore.
[in]delimDelimiter.

Characters are extracted until extraction fails, n characters are extracted, or the next input character equals delim (the delimiter is extracted). If end-of-file occurs the eofbit is set.

Failures are indicated by the state of the stream.

Returns:
*this
bool fstream::is_open ( ) [inline]
Returns:
True if stream is open else false.
void fstream::open ( const char *  path,
openmode  mode = in | out 
) [inline]

Open a fstream

Parameters:
[in]pathfile to open
[in]modeopen mode

Valid open modes are (at end, ios::ate, and/or ios::binary may be added):

ios::in - Open file for reading.

ios::out or ios::out | ios::trunc - Truncate to 0 length, if existent, or create a file for writing only.

ios::app or ios::out | ios::app - Append; open or create file for writing at end-of-file.

ios::in | ios::out - Open file for update (reading and writing).

ios::in | ios::out | ios::trunc - Truncate to zero length, if existent, or create file for update.

ios::in | ios::app or ios::in | ios::out | ios::app - Append; open or create text file for update, writing at end of file.

Reimplemented from SdBaseFile.

ios::operator const void * ( ) const [inline, inherited]
Returns:
null pointer if fail() is true.
bool ios::operator! ( ) const [inline, inherited]
Returns:
true if fail() else false.
ostream& ostream::operator<< ( const signed char *  arg) [inline, inherited]

Output string

Parameters:
[in]argstring to output
Returns:
the stream
ostream& ostream::operator<< ( double  arg) [inline, inherited]

Output double

Parameters:
[in]argvalue to output
Returns:
the stream
ostream& ostream::operator<< ( float  arg) [inline, inherited]

Output float

Parameters:
[in]argvalue to output
Returns:
the stream
ostream& ostream::operator<< ( short  arg) [inline, inherited]

Output signed short

Parameters:
[in]argvalue to output
Returns:
the stream
ostream& ostream::operator<< ( int  arg) [inline, inherited]

Output signed int

Parameters:
[in]argvalue to output
Returns:
the stream
ostream& ostream::operator<< ( unsigned int  arg) [inline, inherited]

Output unsigned int

Parameters:
[in]argvalue to output
Returns:
the stream
ostream& ostream::operator<< ( long  arg) [inline, inherited]

Output signed long

Parameters:
[in]argvalue to output
Returns:
the stream
ostream& ostream::operator<< ( const void *  arg) [inline, inherited]

Output pointer

Parameters:
[in]argvalue to output
Returns:
the stream
ostream& ostream::operator<< ( pgm  arg) [inline, inherited]

Output a string from flash using the pstr() macro

Parameters:
[in]argpgm struct pointing to string
Returns:
the stream
ostream& ostream::operator<< ( const __FlashStringHelper *  arg) [inline, inherited]

Output a string from flash using the Arduino F() macro.

Parameters:
[in]argpointing to flash string
Returns:
the stream
ostream& ostream::operator<< ( unsigned char  arg) [inline, inherited]

Output character

Parameters:
[in]argcharacter to output
Returns:
the stream
ostream& ostream::operator<< ( unsigned short  arg) [inline, inherited]

Output unsigned short

Parameters:
[in]argvalue to output
Returns:
the stream
ostream& ostream::operator<< ( unsigned long  arg) [inline, inherited]

Output unsigned long

Parameters:
[in]argvalue to output
Returns:
the stream
ostream& ostream::operator<< ( ostream &(*)(ostream &str)  pf) [inline, inherited]

call manipulator

Parameters:
[in]pffunction to call
Returns:
the stream
ostream& ostream::operator<< ( ios_base &(*)(ios_base &str)  pf) [inline, inherited]

call manipulator

Parameters:
[in]pffunction to call
Returns:
the stream
ostream& ostream::operator<< ( bool  arg) [inline, inherited]

Output bool

Parameters:
[in]argvalue to output
Returns:
the stream
ostream& ostream::operator<< ( const char *  arg) [inline, inherited]

Output string

Parameters:
[in]argstring to output
Returns:
the stream
ostream& ostream::operator<< ( const unsigned char *  arg) [inline, inherited]

Output string

Parameters:
[in]argstring to output
Returns:
the stream
ostream& ostream::operator<< ( char  arg) [inline, inherited]

Output character

Parameters:
[in]argcharacter to output
Returns:
the stream
ostream& ostream::operator<< ( signed char  arg) [inline, inherited]

Output character

Parameters:
[in]argcharacter to output
Returns:
the stream
istream& istream::operator>> ( char *  str) [inline, inherited]

Extract a character string

Parameters:
[out]strlocation to store the string.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( ios &(*)(ios &str)  pf) [inline, inherited]

call manipulator

Parameters:
[in]pffunction to call
Returns:
the stream
istream& istream::operator>> ( bool &  arg) [inline, inherited]

Extract a value of type bool.

Parameters:
[out]arglocation to store the value.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( int &  arg) [inline, inherited]

Extract a value of type int.

Parameters:
[out]arglocation to store the value.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( long &  arg) [inline, inherited]

Extract a value of type long.

Parameters:
[out]arglocation to store the value.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( char &  ch) [inline, inherited]

Extract a character

Parameters:
[out]chlocation to store the character.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( istream &(*)(istream &str)  pf) [inline, inherited]

call manipulator

Parameters:
[in]pffunction to call
Returns:
the stream
istream& istream::operator>> ( unsigned long &  arg) [inline, inherited]

Extract a value of type unsigned long.

Parameters:
[out]arglocation to store the value.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( double &  arg) [inline, inherited]

Extract a value of type double.

Parameters:
[out]arglocation to store the value.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( float &  arg) [inline, inherited]

Extract a value of type float.

Parameters:
[out]arglocation to store the value.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( signed char &  ch) [inline, inherited]

Extract a character

Parameters:
[out]chlocation to store the character.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( void *&  arg) [inline, inherited]

Extract a value of type void*.

Parameters:
[out]arglocation to store the value.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( unsigned int &  arg) [inline, inherited]

Extract a value of type unsigned int.

Parameters:
[out]arglocation to store the value.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( short &  arg) [inline, inherited]

Extract a value of type short.

Parameters:
[out]arglocation to store the value.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( unsigned char *  str) [inline, inherited]

Extract a character string

Parameters:
[out]strlocation to store the string.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( ios_base &(*)(ios_base &str)  pf) [inline, inherited]

call manipulator

Parameters:
[in]pffunction to call
Returns:
the stream
istream& istream::operator>> ( unsigned char &  ch) [inline, inherited]

Extract a character

Parameters:
[out]chlocation to store the character.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( unsigned short &  arg) [inline, inherited]

Extract a value of type unsigned short.

Parameters:
[out]arglocation to store the value.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::operator>> ( signed char *  str) [inline, inherited]

Extract a character string

Parameters:
[out]strlocation to store the string.
Returns:
Is always *this. Failure is indicated by the state of *this.
int istream::peek ( ) [inherited]

Return the next available character without consuming it.

Returns:
The character if the stream state is good else -1;
int ios_base::precision ( unsigned int  n) [inline, inherited]

set precision

Parameters:
[in]nnew precision
Returns:
old precision
int ios_base::precision ( ) const [inline, inherited]
Returns:
precision
ostream& ostream::put ( char  ch) [inline, inherited]

Puts a character in a stream.

The unformatted output function inserts the element ch. It returns *this.

Parameters:
[in]chThe character
Returns:
A reference to the ostream object.
iostate ios::rdstate ( ) const [inline, inherited]
Returns:
The iostate flags for this file.
istream& istream::seekg ( pos_type  pos) [inline, inherited]

Set the stream position

Parameters:
[in]posThe absolute position in which to move the read pointer.
Returns:
Is always *this. Failure is indicated by the state of *this.
istream& istream::seekg ( off_type  off,
seekdir  way 
) [inline, inherited]

Set the stream position.

Parameters:
[in]offAn offset to move the read pointer relative to way. off is a signed 32-bit int so the offset is limited to +- 2GB.
[in]wayOne of ios::beg, ios::cur, or ios::end.
Returns:
Is always *this. Failure is indicated by the state of *this.
ostream& ostream::seekp ( pos_type  pos) [inline, inherited]

Set the stream position

Parameters:
[in]posThe absolute position in which to move the write pointer.
Returns:
Is always *this. Failure is indicated by the state of *this.
ostream& ostream::seekp ( off_type  off,
seekdir  way 
) [inline, inherited]

Set the stream position.

Parameters:
[in]offAn offset to move the write pointer relative to way. off is a signed 32-bit int so the offset is limited to +- 2GB.
[in]wayOne of ios::beg, ios::cur, or ios::end.
Returns:
Is always *this. Failure is indicated by the state of *this.
fmtflags ios_base::setf ( fmtflags  fl,
fmtflags  mask 
) [inline, inherited]

modify format flags

Parameters:
[in]maskflags to be removed
[in]flflags to be set after mask bits have been cleared
Returns:
old flags
fmtflags ios_base::setf ( fmtflags  fl) [inline, inherited]

set format flags

Parameters:
[in]flnew flags to be or'ed in
Returns:
old flags
void ios::setstate ( iostate  state) [inline, inherited]

Set iostate bits.

Parameters:
[in]stateBitts to set.
void istream::skipWhite ( ) [inherited]

used to implement ws()

pos_type istream::tellg ( ) [inline, inherited]
Returns:
the stream position
pos_type ostream::tellp ( ) [inline, inherited]
Returns:
the stream position
void ios_base::unsetf ( fmtflags  fl) [inline, inherited]

clear format flags

Parameters:
[in]flflags to be cleared
Returns:
old flags
unsigned ios_base::width ( unsigned  n) [inline, inherited]

set width

Parameters:
[in]nnew width
Returns:
old width
unsigned ios_base::width ( ) [inline, inherited]
Returns:
width

Member Data Documentation

const fmtflags ios_base::adjustfield = left | right | internal [static, inherited]

mask for adjustfield

const openmode ios_base::app = 0X4 [static, inherited]

seek to end before each write

const openmode ios_base::ate = 0X8 [static, inherited]

open and seek to end immediately after opening

const iostate ios_base::badbit = 0X01 [static, inherited]

iostate bad bit for a nonrecoverable error.

const fmtflags ios_base::basefield = dec | hex | oct [static, inherited]

mask for basefield

const openmode ios_base::binary = 0X10 [static, inherited]

perform input and output in binary mode (as opposed to text mode)

const fmtflags ios_base::boolalpha = 0x0100 [static, inherited]

use strings true/false for bool

const fmtflags ios_base::dec = 0x0008 [static, inherited]

base 10 flag

const iostate ios_base::eofbit = 0x02 [static, inherited]

iostate bit for end of file reached

const iostate ios_base::failbit = 0X04 [static, inherited]

iostate fail bit for nonfatal error

const iostate ios_base::goodbit = 0x00 [static, inherited]

iostate for no flags

const fmtflags ios_base::hex = 0x0010 [static, inherited]

base 16 flag

const openmode ios_base::in = 0X20 [static, inherited]

open for input

const fmtflags ios_base::internal = 0x0004 [static, inherited]

fill between sign/base prefix and number

const fmtflags ios_base::left = 0x0001 [static, inherited]

left adjust fields

const fmtflags ios_base::oct = 0x0020 [static, inherited]

base 8 flag

const openmode ios_base::out = 0X40 [static, inherited]

open for output

const fmtflags ios_base::right = 0x0002 [static, inherited]

right adjust fields

const fmtflags ios_base::showbase = 0x0200 [static, inherited]

use prefix 0X for hex and 0 for oct

const fmtflags ios_base::showpoint = 0x0400 [static, inherited]

always show '.' for floating numbers

const fmtflags ios_base::showpos = 0x0800 [static, inherited]

show + sign for nonnegative numbers

const fmtflags ios_base::skipws = 0x1000 [static, inherited]

skip initial white space

const openmode ios_base::trunc = 0X80 [static, inherited]

truncate an existing stream when opening

const fmtflags ios_base::uppercase = 0x4000 [static, inherited]

use uppercase letters in number representations


The documentation for this class was generated from the following file: