OpenEnroth 73e68f7
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Protected Member Functions | Friends | List of all members
FileSystem Class Referenceabstract

#include <FileSystem.h>

Inheritance diagram for FileSystem:
DirectoryFileSystem LowercaseFileSystem MemoryFileSystem MountingFileSystem ProxyFileSystem ReadOnlyFileSystem MaskingFileSystem EmbeddedFileSystem MergingFileSystem NullFileSystem

Public Member Functions

 FileSystem ()=default
 
virtual ~FileSystem ()=default
 
bool exists (std::string_view path) const
 
bool exists (FileSystemPathView path) const
 
FileStat stat (std::string_view path) const
 
FileStat stat (FileSystemPathView path) const
 
std::vector< DirectoryEntryls (std::string_view path) const
 
std::vector< DirectoryEntryls (FileSystemPathView path) const
 
void ls (std::string_view path, std::vector< DirectoryEntry > *entries) const
 
void ls (FileSystemPathView path, std::vector< DirectoryEntry > *entries) const
 
Blob read (std::string_view path) const
 
Blob read (FileSystemPathView path) const
 
void write (std::string_view path, const Blob &data)
 
void write (FileSystemPathView path, const Blob &data)
 
std::unique_ptr< InputStreamopenForReading (std::string_view path) const
 
std::unique_ptr< InputStreamopenForReading (FileSystemPathView path) const
 
std::unique_ptr< OutputStreamopenForWriting (std::string_view path)
 
std::unique_ptr< OutputStreamopenForWriting (FileSystemPathView path)
 
void rename (std::string_view srcPath, std::string_view dstPath)
 
void rename (FileSystemPathView srcPath, FileSystemPathView dstPath)
 
bool remove (std::string_view path)
 
bool remove (FileSystemPathView path)
 
std::string displayPath (std::string_view path) const
 
std::string displayPath (FileSystemPathView path) const
 

Protected Types

template<class T >
using FileSystemTrieNode = detail::FileSystemTrieNode< T >
 
template<class T >
using FileSystemTrie = detail::FileSystemTrie< T >
 

Protected Member Functions

virtual bool _exists (FileSystemPathView path) const =0
 
virtual FileStat _stat (FileSystemPathView path) const =0
 
virtual void _ls (FileSystemPathView path, std::vector< DirectoryEntry > *entries) const =0
 
virtual Blob _read (FileSystemPathView path) const =0
 
virtual void _write (FileSystemPathView path, const Blob &data)=0
 
virtual std::unique_ptr< InputStream_openForReading (FileSystemPathView path) const =0
 
virtual std::unique_ptr< OutputStream_openForWriting (FileSystemPathView path)=0
 
virtual void _rename (FileSystemPathView srcPath, FileSystemPathView dstPath)
 
virtual bool _remove (FileSystemPathView path)=0
 
virtual std::string _displayPath (FileSystemPathView path) const =0
 

Friends

class ProxyFileSystem
 

Detailed Description

File system interface.

All user-facing methods take paths as UTF8-encoded std::string_views, and users are expected to just use std::strings to store paths.

Paths are normalized internally, and then processed by the implementation in a derived class. Both ".." and "." special dirs are supported, but peeking outside the root directory is not - passing paths that try to do this will throw, exists will return false, and stat will return FILE_INVALID.

Unlike a real file system, this interface doesn't have a concept of a "current directory." All methods take root-relative paths, so "foo/bar" and "/foo/bar" are equivalent.

Root folder of the file system always exists. Thus, exists("") always returns true, stat("") always returns FILE_DIRECTORY, ls("") never throws, remove("") and rename("", "foo") always throw.

See also
ReadOnlyFileSystem

Member Typedef Documentation

◆ FileSystemTrie

template<class T >
using FileSystem::FileSystemTrie = detail::FileSystemTrie<T>
protected

◆ FileSystemTrieNode

template<class T >
using FileSystem::FileSystemTrieNode = detail::FileSystemTrieNode<T>
protected

Constructor & Destructor Documentation

◆ FileSystem()

FileSystem::FileSystem ( )
default

◆ ~FileSystem()

virtual FileSystem::~FileSystem ( )
virtualdefault

Member Function Documentation

◆ _displayPath()

virtual std::string FileSystem::_displayPath ( FileSystemPathView  path) const
protectedpure virtual

◆ _exists()

virtual bool FileSystem::_exists ( FileSystemPathView  path) const
protectedpure virtual

◆ _ls()

virtual void FileSystem::_ls ( FileSystemPathView  path,
std::vector< DirectoryEntry > *  entries 
) const
protectedpure virtual

◆ _openForReading()

virtual std::unique_ptr< InputStream > FileSystem::_openForReading ( FileSystemPathView  path) const
protectedpure virtual

◆ _openForWriting()

virtual std::unique_ptr< OutputStream > FileSystem::_openForWriting ( FileSystemPathView  path)
protectedpure virtual

◆ _read()

virtual Blob FileSystem::_read ( FileSystemPathView  path) const
protectedpure virtual

◆ _remove()

virtual bool FileSystem::_remove ( FileSystemPathView  path)
protectedpure virtual

◆ _rename()

void FileSystem::_rename ( FileSystemPathView  srcPath,
FileSystemPathView  dstPath 
)
protectedvirtual

◆ _stat()

virtual FileStat FileSystem::_stat ( FileSystemPathView  path) const
protectedpure virtual

◆ _write()

virtual void FileSystem::_write ( FileSystemPathView  path,
const Blob data 
)
protectedpure virtual

◆ displayPath() [1/2]

std::string FileSystem::displayPath ( FileSystemPathView  path) const

◆ displayPath() [2/2]

std::string FileSystem::displayPath ( std::string_view  path) const
Parameters
pathPath inside this file system. The passed path is not required to exist.
Returns
A path string that's suitable to be displayed to the user. E.g. an absolute path on the underlying OS file system.

◆ exists() [1/2]

bool FileSystem::exists ( FileSystemPathView  path) const

◆ exists() [2/2]

bool FileSystem::exists ( std::string_view  path) const
Parameters
pathPath to check.
Returns
Whether the given path exists.
Exceptions
std::runtime_errorOn error, e.g. if the current user doesn't have the necessary permissions.

◆ ls() [1/4]

std::vector< DirectoryEntry > FileSystem::ls ( FileSystemPathView  path) const

◆ ls() [2/4]

void FileSystem::ls ( FileSystemPathView  path,
std::vector< DirectoryEntry > *  entries 
) const

◆ ls() [3/4]

std::vector< DirectoryEntry > FileSystem::ls ( std::string_view  path) const
Parameters
pathPath to an existing directory to list.
Returns
List of directory entries.
Exceptions
std::runtime_errorIf path doesn't exist, or on any other error.

◆ ls() [4/4]

void FileSystem::ls ( std::string_view  path,
std::vector< DirectoryEntry > *  entries 
) const

◆ openForReading() [1/2]

std::unique_ptr< InputStream > FileSystem::openForReading ( FileSystemPathView  path) const

◆ openForReading() [2/2]

std::unique_ptr< InputStream > FileSystem::openForReading ( std::string_view  path) const
Parameters
pathPath to an existing file to open for reading.
Returns
Input stream for reading from a file.
Exceptions
std::runtime_errorIf path doesn't exist, or on any other error.

◆ openForWriting() [1/2]

std::unique_ptr< OutputStream > FileSystem::openForWriting ( FileSystemPathView  path)

◆ openForWriting() [2/2]

std::unique_ptr< OutputStream > FileSystem::openForWriting ( std::string_view  path)
Parameters
pathPath to a file to write. If parent directory doesn't exist, it will be created. If a file with the provided name exists, it will be overwritten.
Returns
Output stream for writing into a file.
Exceptions
std::runtime_errorOn error, e.g. if the current user doesn't have the necessary permissions.

◆ read() [1/2]

Blob FileSystem::read ( FileSystemPathView  path) const

◆ read() [2/2]

Blob FileSystem::read ( std::string_view  path) const
Parameters
pathPath to an existing file to read or map into memory.
Returns
File contents. Implementations are encouraged to use memory mapping.
Exceptions
std::runtime_errorIf path doesn't exist, or on any other error.

◆ remove() [1/2]

bool FileSystem::remove ( FileSystemPathView  path)

◆ remove() [2/2]

bool FileSystem::remove ( std::string_view  path)
Parameters
pathPath to a file or a directory to remove. A directory will be removed even if it is not empty. Must not be root.
Returns
true if the file or folder was deleted, false if it did not exist.
Exceptions
std::runtime_errorOn error, e.g. if the current user doesn't have the necessary permissions.

◆ rename() [1/2]

void FileSystem::rename ( FileSystemPathView  srcPath,
FileSystemPathView  dstPath 
)

◆ rename() [2/2]

void FileSystem::rename ( std::string_view  srcPath,
std::string_view  dstPath 
)

Renames a file or a folder.

Default implementation removes dstPath first, then copies the srcPath over, then removes srcPath.

Derived classes working on top of an actual file system might implement this using POSIX rename.

Parameters
srcPathSource path for renaming. Path must exist and must not be root.
dstPathTarget path for renaming. If source path is a directory, then target path must not exist. If source path is a file, then target path must either not exist, or be a file. If parent directory of dstPath doesn't exist, it will be created.
Exceptions
std::runtime_errorOn error, e.g. if the current user doesn't have the necessary permissions.

◆ stat() [1/2]

FileStat FileSystem::stat ( FileSystemPathView  path) const

◆ stat() [2/2]

FileStat FileSystem::stat ( std::string_view  path) const
Parameters
pathPath to a file of a folder to get information for.
Returns
Information for a file or directory at path. FileStat::type will be set to FILE_INVALID if path doesn't exist.
Exceptions
std::runtime_errorOn error, e.g. if the current user doesn't have the necessary permissions.

◆ write() [1/2]

void FileSystem::write ( FileSystemPathView  path,
const Blob data 
)

◆ write() [2/2]

void FileSystem::write ( std::string_view  path,
const Blob data 
)
Parameters
pathPath to a file to write. If parent directory doesn't exist, it will be created. If a file with the provided name exists, it will be overwritten.
dataFile contents to write.
Exceptions
std::runtime_errorOn error, e.g. if the current user doesn't have the necessary permissions.

Friends And Related Function Documentation

◆ ProxyFileSystem

friend class ProxyFileSystem
friend

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