OpenEnroth 73e68f7
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
MountingFileSystem Class Reference

#include <MountingFileSystem.h>

Inheritance diagram for MountingFileSystem:
FileSystem

Public Member Functions

 MountingFileSystem (std::string_view displayName)
 
virtual ~MountingFileSystem ()
 
void mount (std::string_view path, FileSystem *fileSystem)
 
void mount (FileSystemPathView path, FileSystem *fileSystem)
 
bool unmount (std::string_view path)
 
bool unmount (FileSystemPathView path)
 
void clearMounts ()
 
- Public Member Functions inherited from FileSystem
 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
 

Private Types

using Node = FileSystemTrieNode< FileSystem * >
 
using WalkResult = std::tuple< Node *, FileSystem *, FileSystemPathView >
 
using ConstWalkResult = std::tuple< const Node *, const FileSystem *, FileSystemPathView >
 

Private Member Functions

virtual bool _exists (FileSystemPathView path) const override
 
virtual FileStat _stat (FileSystemPathView path) const override
 
virtual void _ls (FileSystemPathView path, std::vector< DirectoryEntry > *entries) const override
 
virtual Blob _read (FileSystemPathView path) const override
 
virtual void _write (FileSystemPathView path, const Blob &data) override
 
virtual std::unique_ptr< InputStream_openForReading (FileSystemPathView path) const override
 
virtual std::unique_ptr< OutputStream_openForWriting (FileSystemPathView path) override
 
virtual void _rename (FileSystemPathView srcPath, FileSystemPathView dstPath) override
 
virtual bool _remove (FileSystemPathView path) override
 
virtual std::string _displayPath (FileSystemPathView path) const override
 
WalkResult walk (FileSystemPathView path)
 
ConstWalkResult walk (FileSystemPathView path) const
 
std::pair< const FileSystem *, FileSystemPathViewwalkForReading (FileSystemPathView path) const
 
std::pair< FileSystem *, FileSystemPathViewwalkForWriting (FileSystemPathView path)
 

Private Attributes

std::string _displayName
 
FileSystemTrie< FileSystem * > _trie
 

Additional Inherited Members

- Protected Types inherited from FileSystem
template<class T >
using FileSystemTrieNode = detail::FileSystemTrieNode< T >
 
template<class T >
using FileSystemTrie = detail::FileSystemTrie< T >
 
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
 

Detailed Description

File system that makes it possible to mount other file systems at different points of the file tree.

This can be handy if, for example, you need to override one of the folders of some other file system:

SomeFileSystem fs1;
fs.mount("", &fs1);
fs.mount("data/images", &fs2); // Now "data/images" is pointing into `fs2`, whatever was there in `fs1` is ignored.
Definition: MemoryFileSystem.h:33
Definition: MountingFileSystem.h:31
void mount(std::string_view path, FileSystem *fileSystem)
Definition: MountingFileSystem.cpp:17

In the example above, repeated calls to mount create a hierarchy of virtual directories. These virtual directories override everything with the same name that existed in the underlying file systems.

Note that rename and remove only work on regular files, and will fail on virtual directories. If you want to tweak the virtual directory tree, use mount and unmount.

Member Typedef Documentation

◆ ConstWalkResult

using MountingFileSystem::ConstWalkResult = std::tuple<const Node *, const FileSystem *, FileSystemPathView>
private

◆ Node

◆ WalkResult

Constructor & Destructor Documentation

◆ MountingFileSystem()

MountingFileSystem::MountingFileSystem ( std::string_view  displayName)
explicit

◆ ~MountingFileSystem()

MountingFileSystem::~MountingFileSystem ( )
virtualdefault

Member Function Documentation

◆ _displayPath()

std::string MountingFileSystem::_displayPath ( FileSystemPathView  path) const
overrideprivatevirtual

Implements FileSystem.

◆ _exists()

bool MountingFileSystem::_exists ( FileSystemPathView  path) const
overrideprivatevirtual

Implements FileSystem.

◆ _ls()

void MountingFileSystem::_ls ( FileSystemPathView  path,
std::vector< DirectoryEntry > *  entries 
) const
overrideprivatevirtual

Implements FileSystem.

◆ _openForReading()

std::unique_ptr< InputStream > MountingFileSystem::_openForReading ( FileSystemPathView  path) const
overrideprivatevirtual

Implements FileSystem.

◆ _openForWriting()

std::unique_ptr< OutputStream > MountingFileSystem::_openForWriting ( FileSystemPathView  path)
overrideprivatevirtual

Implements FileSystem.

◆ _read()

Blob MountingFileSystem::_read ( FileSystemPathView  path) const
overrideprivatevirtual

Implements FileSystem.

◆ _remove()

bool MountingFileSystem::_remove ( FileSystemPathView  path)
overrideprivatevirtual

Implements FileSystem.

◆ _rename()

void MountingFileSystem::_rename ( FileSystemPathView  srcPath,
FileSystemPathView  dstPath 
)
overrideprivatevirtual

Reimplemented from FileSystem.

◆ _stat()

FileStat MountingFileSystem::_stat ( FileSystemPathView  path) const
overrideprivatevirtual

Implements FileSystem.

◆ _write()

void MountingFileSystem::_write ( FileSystemPathView  path,
const Blob data 
)
overrideprivatevirtual

Implements FileSystem.

◆ clearMounts()

void MountingFileSystem::clearMounts ( )

◆ mount() [1/2]

void MountingFileSystem::mount ( FileSystemPathView  path,
FileSystem fileSystem 
)

◆ mount() [2/2]

void MountingFileSystem::mount ( std::string_view  path,
FileSystem fileSystem 
)

◆ unmount() [1/2]

bool MountingFileSystem::unmount ( FileSystemPathView  path)

◆ unmount() [2/2]

bool MountingFileSystem::unmount ( std::string_view  path)

◆ walk() [1/2]

MountingFileSystem::WalkResult MountingFileSystem::walk ( FileSystemPathView  path)
private

◆ walk() [2/2]

MountingFileSystem::ConstWalkResult MountingFileSystem::walk ( FileSystemPathView  path) const
private

◆ walkForReading()

std::pair< const FileSystem *, FileSystemPathView > MountingFileSystem::walkForReading ( FileSystemPathView  path) const
private

◆ walkForWriting()

std::pair< FileSystem *, FileSystemPathView > MountingFileSystem::walkForWriting ( FileSystemPathView  path)
private

Member Data Documentation

◆ _displayName

std::string MountingFileSystem::_displayName
private

◆ _trie

FileSystemTrie<FileSystem *> MountingFileSystem::_trie
private

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