LittleFileSystem
Loading...
Searching...
No Matches
ntdv::VirtualFile Class Reference

VirtualFile class provides an interface for file operations in a virtual file system. More...

#include <VirtualFile.h>

Inheritance diagram for ntdv::VirtualFile:
ntdv::IFile

Public Member Functions

 VirtualFile (VirtualFileSystem *fs, const char *path, const char *mode)
 
 ~VirtualFile () override
 Destructor.
 
size_t Write (const uint8_t *buf, size_t size) override
 
size_t Read (uint8_t *buf, size_t size) override
 
void Flush () override
 Flush the file buffer.
 
bool Seek (uint32_t pos, SeekMode mode) override
 
size_t Position () const override
 
size_t Size () const override
 
bool SetBufferSize (size_t size) override
 
void Close () override
 Close the file.
 
time_t GetLastWrite () override
 
const char * Path () const override
 
const char * Name () const override
 
boolean IsDirectory () override
 
FilePtr OpenNextFile (const char *mode) override
 
boolean SeekDir (long position) override
 
String GetNextFileName () override
 
String GetNextFileName (bool *isDir) override
 
void RewindDirectory () override
 Go to the begining of the directory.
 
 operator bool () override
 
- Public Member Functions inherited from ntdv::IFile
virtual ~IFile ()=default
 Virtual destructor.
 

Protected Member Functions

void getStat () const
 Get the file status information.
 

Protected Attributes

VirtualFileSystem_fs
 Pointer to the virtual file system.
 
FILE * _file
 Pointer to the file.
 
DIR * _dir
 Pointer to the directory.
 
char * _path
 Path of the file.
 
bool _isDirectory
 Whether the file is a directory.
 
struct stat _stat
 File status information.
 
bool _written
 Whether the file has been written to.
 

Detailed Description

VirtualFile class provides an interface for file operations in a virtual file system.

Constructor & Destructor Documentation

◆ VirtualFile()

VirtualFile::VirtualFile ( VirtualFileSystem * fs,
const char * path,
const char * mode )

Constructor

Parameters
fs- pointer to the virtual file system
path- path of the file
mode- mode to open the file in

◆ ~VirtualFile()

VirtualFile::~VirtualFile ( )
override

Destructor.

Member Function Documentation

◆ Close()

void VirtualFile::Close ( )
overridevirtual

Close the file.

Implements ntdv::IFile.

◆ Flush()

void VirtualFile::Flush ( )
overridevirtual

Flush the file buffer.

Implements ntdv::IFile.

◆ GetLastWrite()

time_t VirtualFile::GetLastWrite ( )
overridevirtual

Get the last write time of the file

Returns
the last write time

Implements ntdv::IFile.

◆ GetNextFileName() [1/2]

String VirtualFile::GetNextFileName ( )
overridevirtual

Get the name of the next file in the directory

Returns
the name of the next file

Implements ntdv::IFile.

◆ GetNextFileName() [2/2]

String VirtualFile::GetNextFileName ( bool * isDir)
overridevirtual

Get the name of the next file in the directory and whether it is a directory

Parameters
isDir- pointer to a boolean to store whether the file is a directory
Returns
the name of the next file

Implements ntdv::IFile.

◆ getStat()

void VirtualFile::getStat ( ) const
protected

Get the file status information.

◆ IsDirectory()

boolean VirtualFile::IsDirectory ( )
overridevirtual

Check if the file is a directory

Returns
true if the file is a directory, false otherwise

Implements ntdv::IFile.

◆ Name()

const char * VirtualFile::Name ( ) const
overridevirtual

Get the name of the file

Returns
the file name

Implements ntdv::IFile.

◆ OpenNextFile()

FilePtr VirtualFile::OpenNextFile ( const char * mode)
overridevirtual

Open the next file in the directory

Parameters
mode- mode to open the file in
Returns
a shared pointer to the opened file

Implements ntdv::IFile.

◆ operator bool()

VirtualFile::operator bool ( )
overridevirtual

Check if the file is valid

Returns
true if the file is valid, false otherwise

Implements ntdv::IFile.

◆ Path()

const char * VirtualFile::Path ( ) const
overridevirtual

Get the path of the file

Returns
the file path

Implements ntdv::IFile.

◆ Position()

size_t VirtualFile::Position ( ) const
overridevirtual

Get the current position in the file

Returns
the current position

Implements ntdv::IFile.

◆ Read()

size_t VirtualFile::Read ( uint8_t * buf,
size_t size )
overridevirtual

Read data from the file

Parameters
buf- buffer to store the data
size- size of the data to read
Returns
the number of bytes read

Implements ntdv::IFile.

◆ RewindDirectory()

void VirtualFile::RewindDirectory ( )
overridevirtual

Go to the begining of the directory.

Implements ntdv::IFile.

◆ Seek()

bool VirtualFile::Seek ( uint32_t pos,
SeekMode mode )
overridevirtual

Seek to a position in the file

Parameters
pos- position to seek to
mode- mode of seeking
Returns
true if successful, false otherwise

Implements ntdv::IFile.

◆ SeekDir()

boolean VirtualFile::SeekDir ( long position)
overridevirtual

Seek to a position in the directory

Parameters
position- position to seek to
Returns
true if successful, false otherwise

Implements ntdv::IFile.

◆ SetBufferSize()

bool VirtualFile::SetBufferSize ( size_t size)
overridevirtual

Set the buffer size for the file

Parameters
size- size of the buffer
Returns
true if successful, false otherwise

Implements ntdv::IFile.

◆ Size()

size_t VirtualFile::Size ( ) const
overridevirtual

Get the size of the file

Returns
the size of the file

Implements ntdv::IFile.

◆ Write()

size_t VirtualFile::Write ( const uint8_t * buf,
size_t size )
overridevirtual

Write data to the file

Parameters
buf- buffer containing the data
size- size of the data
Returns
the number of bytes written

Implements ntdv::IFile.

Member Data Documentation

◆ _dir

DIR* ntdv::VirtualFile::_dir
protected

Pointer to the directory.

◆ _file

FILE* ntdv::VirtualFile::_file
protected

Pointer to the file.

◆ _fs

VirtualFileSystem* ntdv::VirtualFile::_fs
protected

Pointer to the virtual file system.

◆ _isDirectory

bool ntdv::VirtualFile::_isDirectory
protected

Whether the file is a directory.

◆ _path

char* ntdv::VirtualFile::_path
protected

Path of the file.

◆ _stat

struct stat ntdv::VirtualFile::_stat
protected

File status information.

◆ _written

bool ntdv::VirtualFile::_written
mutableprotected

Whether the file has been written to.


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