PropWare  3.0.0.224
C++ objects and CMake build system for Parallax Propeller
Public Types | Public Member Functions | Static Public Attributes | List of all members
PropWare::FatFileWriter Class Reference

Concrete class for writing or modifying a FAT 16/32 file. More...

#include <PropWare/filesystem/fat/fatfilewriter.h>

+ Inheritance diagram for PropWare::FatFileWriter:
+ Collaboration diagram for PropWare::FatFileWriter:

Public Types

enum  ErrorCode {
  NO_ERROR = 0,
  BEG_ERROR = Filesystem::END_ERROR + 1,
  ENTRY_NOT_FILE = BEG_ERROR,
  FILENAME_NOT_FOUND,
  END_ERROR = FILENAME_NOT_FOUND
}
 
enum  SeekDir {
  SeekDir::BEG,
  SeekDir::CUR,
  SeekDir::END
}
 

Public Member Functions

 FatFileWriter (FatFS &fs, const char name[], BlockStorage::Buffer &buffer=SHARED_BUFFER, const Printer &logger=pwOut)
 Standard constructor. More...
 
virtual ~FatFileWriter ()
 All content will be saved to the physical device and the file will be safely closed.
 
PropWare::ErrorCode open ()
 Open the file. More...
 
PropWare::ErrorCode remove ()
 Mark a file as delete and free its clusters in the FAT. File content will not be cleared unless overwritten by another file. File does not have to be opened prior to deleting.
 
PropWare::ErrorCode flush ()
 Flush any modified data back to the SD card. More...
 
PropWare::ErrorCode safe_put_char (const char c)
 Write a character to the file. More...
 
void print_status (const bool printBlocks=false) const
 
const char * get_name () const
 Determine the name of a file. More...
 
bool exists () const
 Determine if a file exists (file does not have to be open) More...
 
bool exists (PropWare::ErrorCode &err) const
 
virtual PropWare::ErrorCode close ()
 Close a file - a required step in any workflow that includes opening a file. More...
 
int32_t get_length () const
 Return the number of bytes (characters) in the file.
 
int32_t tell () const
 Obtain the value of the file position indicator. More...
 
PropWare::ErrorCode seek (const int32_t offset, const SeekDir way)
 Sets the position of the next character to be read or written. More...
 
PropWare::ErrorCode seek (const int32_t position)
 
void put_char (const char c)
 Write a character to the file. More...
 
virtual PropWare::ErrorCode safe_puts (const char string[])
 Write a character array to the file. More...
 
void puts (const char string[])
 Write a character array to the file. More...
 
void print_status (const bool printBlocks=false, const bool printParentStatus=true) const
 

Static Public Attributes

static const unsigned int MAX_FILENAME_LENGTH = 32
 

Detailed Description

Concrete class for writing or modifying a FAT 16/32 file.

Examples
FileWriter_Demo.cpp.

Definition at line 38 of file fatfilewriter.h.

Member Enumeration Documentation

◆ ErrorCode

Enumerator
ENTRY_NOT_FILE 

FatFile Error 0

FILENAME_NOT_FOUND 

FatFile Error 1

Definition at line 38 of file fatfile.h.

◆ SeekDir

enum PropWare::File::SeekDir
stronginherited
Enumerator
BEG 

beginning of the stream

CUR 

current position in the stream

END 

end of the stream

Definition at line 47 of file file.h.

Constructor & Destructor Documentation

◆ FatFileWriter()

PropWare::FatFileWriter::FatFileWriter ( FatFS fs,
const char  name[],
BlockStorage::Buffer buffer = SHARED_BUFFER,
const Printer logger = pwOut 
)

Standard constructor.

Parameters
[in]fsA mounted FAT 16/32 filesystem
[in]name[]Character array with the file name
[in]*bufferIf you don't want to use the globally shared buffer, a different buffer address can be provided here
[in]loggerThis is only used for printing debug statements. Use of the logger is limited such that all references will be optimized out in normal application code

Definition at line 51 of file fatfilewriter.h.

Member Function Documentation

◆ close()

virtual PropWare::ErrorCode PropWare::File::close ( )
virtualinherited

Close a file - a required step in any workflow that includes opening a file.

Returns
0 upon success, error code otherwise

Definition at line 74 of file file.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exists() [1/2]

bool PropWare::FatFile::exists ( ) const
inherited

Determine if a file exists (file does not have to be open)

Returns
True if the file exists, false otherwise

Definition at line 62 of file fatfile.h.

+ Here is the call graph for this function:

◆ exists() [2/2]

bool PropWare::FatFile::exists ( PropWare::ErrorCode &  err) const
inherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[out]errIt is possible for an error to occur

Definition at line 72 of file fatfile.h.

+ Here is the call graph for this function:

◆ flush()

PropWare::ErrorCode PropWare::FatFileWriter::flush ( )
virtual

Flush any modified data back to the SD card.

Returns
0 upon success, error code otherwise

Implements PropWare::File.

Definition at line 118 of file fatfilewriter.h.

◆ get_name()

const char* PropWare::FatFile::get_name ( ) const
inherited

Determine the name of a file.

Returns
Character array containing the file - DO NOT modify the array, it will modify the internals of the file instance

Definition at line 53 of file fatfile.h.

+ Here is the caller graph for this function:

◆ open()

PropWare::ErrorCode PropWare::FatFileWriter::open ( )
virtual

Open the file.

Returns
0 upon success, error code otherwise

Implements PropWare::File.

Definition at line 65 of file fatfilewriter.h.

+ Here is the call graph for this function:

◆ put_char()

void PropWare::FileWriter::put_char ( const char  c)
virtualinherited

Write a character to the file.

Parameters
[in]cCharacter that should be written

Implements PropWare::PrintCapable.

Definition at line 57 of file filewriter.h.

+ Here is the call graph for this function:

◆ puts()

void PropWare::FileWriter::puts ( const char  string[])
virtualinherited

Write a character array to the file.

Parameters
[in]stringNull-terminated character array that should be written

Implements PropWare::PrintCapable.

Definition at line 85 of file filewriter.h.

+ Here is the call graph for this function:

◆ safe_put_char()

PropWare::ErrorCode PropWare::FatFileWriter::safe_put_char ( const char  c)
virtual

Write a character to the file.

Parameters
[in]cCharacter that should be written
Returns
0 upon success, error code otherwise

Implements PropWare::FileWriter.

Definition at line 142 of file fatfilewriter.h.

◆ safe_puts()

virtual PropWare::ErrorCode PropWare::FileWriter::safe_puts ( const char  string[])
virtualinherited

Write a character array to the file.

Parameters
[in]stringNull-terminated character array that should be written
Returns
0 upon success, error code otherwise

Definition at line 68 of file filewriter.h.

+ Here is the caller graph for this function:

◆ seek() [1/2]

PropWare::ErrorCode PropWare::File::seek ( const int32_t  offset,
const SeekDir  way 
)
inherited

Sets the position of the next character to be read or written.

Parameters
[in]offsetOffset value, relative to the way parameter
[in]wayStarting position for the movement and direction of movement
Returns
0 upon success, error code otherwise

Definition at line 112 of file file.h.

+ Here is the caller graph for this function:

◆ seek() [2/2]

PropWare::ErrorCode PropWare::File::seek ( const int32_t  position)
inherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[in]positionAbsolute position to move the file position indicator

Definition at line 147 of file file.h.

+ Here is the call graph for this function:

◆ tell()

int32_t PropWare::File::tell ( ) const
inherited

Obtain the value of the file position indicator.

Postcondition
The next byte to be read from the file

Definition at line 100 of file file.h.


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