CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::FileWatcher Class Referencefinal

Watcher that reports on changes of files or directories. More...

#include <CeresEngine/Foundation/IO/FileWatcher.hpp>

Public Types

using ImplementationType = SPtr< IFileWatcher >
 
using EventFunc = std::function< void(const FileHandle &, FileEvent)>
 Callback function for file system events.
 

Public Member Functions

 FileWatcher (ExecutionContext &executionContext, const FileHandle &directory, const FileEvent &events=FileEvent::Default, bool recursive=true)
 Creates a new watcher for the given directory.
 
 FileWatcher (ImplementationType &&implementation)
 Creates a new FileWatcher from a concrete implementation.
 
 FileWatcher (const FileWatcher &fileWatcher)=delete
 
FileWatcheroperator= (const FileWatcher &fileWatcher)=delete
 
FileWatcheroperator= (FileWatcher &&other) noexcept
 
 FileWatcher (FileWatcher &&other) noexcept
 
 ~FileWatcher () noexcept
 
IFileSystemgetFileSystem () const
 Gets file system that this watcher watches for.
 
void start ()
 Starts the file watching operation.
 
void stop ()
 Stops the file watching operation.
 
void addHandler (FileEventHandler &eventHandler)
 Adds an event handler.
 
void addHandler (EventFunc &&funcFileEvent)
 Adds a callback function as event handler.
 
void removeHandler (const FileEventHandler &eventHandler)
 Remove an event handler.
 

Protected Member Functions

void onFileEvent (const FileHandle &handle, FileEvent event)
 Called on file event.
 

Private Attributes

ImplementationType mImplementation
 The file handle implementation.
 
Vector< FileEventHandler * > mEventHandlers
 List of registered file event handlers.
 
Vector< UPtr< FunctionalFileEventHandler > > mOwnEventHandlers
 Functional event handlers that are owned by the file watcher.
 

Friends

class IFileWatcher
 

Detailed Description

Watcher that reports on changes of files or directories.

Member Typedef Documentation

◆ EventFunc

Callback function for file system events.

◆ ImplementationType

Constructor & Destructor Documentation

◆ FileWatcher() [1/4]

CeresEngine::FileWatcher::FileWatcher ( ExecutionContext executionContext,
const FileHandle directory,
const FileEvent events = FileEvent::Default,
bool  recursive = true 
)
explicit

Creates a new watcher for the given directory.

◆ FileWatcher() [2/4]

CeresEngine::FileWatcher::FileWatcher ( ImplementationType &&  implementation)

Creates a new FileWatcher from a concrete implementation.

◆ FileWatcher() [3/4]

CeresEngine::FileWatcher::FileWatcher ( const FileWatcher fileWatcher)
delete

◆ FileWatcher() [4/4]

CeresEngine::FileWatcher::FileWatcher ( FileWatcher &&  other)
noexcept

◆ ~FileWatcher()

CeresEngine::FileWatcher::~FileWatcher ( )
noexcept

Member Function Documentation

◆ addHandler() [1/2]

void CeresEngine::FileWatcher::addHandler ( EventFunc &&  funcFileEvent)

Adds a callback function as event handler.

Parameters
funcFileEventThe function that is call on each file system event.

◆ addHandler() [2/2]

void CeresEngine::FileWatcher::addHandler ( FileEventHandler eventHandler)

Adds an event handler.

Parameters
eventHandlerThe File event handler.

◆ getFileSystem()

IFileSystem * CeresEngine::FileWatcher::getFileSystem ( ) const

Gets file system that this watcher watches for.

Returns
The watched file system (can be null).

◆ onFileEvent()

void CeresEngine::FileWatcher::onFileEvent ( const FileHandle handle,
FileEvent  event 
)
protected

Called on file event.

Parameters
handleThe file handle that received the event.
eventThe type of event that has occurred.

◆ operator=() [1/2]

FileWatcher & CeresEngine::FileWatcher::operator= ( const FileWatcher fileWatcher)
delete

◆ operator=() [2/2]

FileWatcher & CeresEngine::FileWatcher::operator= ( FileWatcher &&  other)
noexcept

◆ removeHandler()

void CeresEngine::FileWatcher::removeHandler ( const FileEventHandler eventHandler)

Remove an event handler.

Parameters
eventHandlerThe file event handler.

◆ start()

void CeresEngine::FileWatcher::start ( )

Starts the file watching operation.

Note
This function begins to watch the file system on a background thread. On every event, onFileEvent() is called using the watcher execution context with the typeof the event and a file handle to the file or directory. To stop listening, call stop().

◆ stop()

void CeresEngine::FileWatcher::stop ( )

Stops the file watching operation.

Friends And Related Symbol Documentation

◆ IFileWatcher

Member Data Documentation

◆ mEventHandlers

Vector<FileEventHandler*> CeresEngine::FileWatcher::mEventHandlers
private

List of registered file event handlers.

◆ mImplementation

ImplementationType CeresEngine::FileWatcher::mImplementation
private

The file handle implementation.

◆ mOwnEventHandlers

Vector<UPtr<FunctionalFileEventHandler> > CeresEngine::FileWatcher::mOwnEventHandlers
private

Functional event handlers that are owned by the file watcher.


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