Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
Olympe::FileWatcher Class Reference

Polls a single file for modification-time changes. More...

#include <FileWatcher.h>

Public Member Functions

 FileWatcher ()
 Constructs a FileWatcher that is not yet watching any file.
 
 FileWatcher (const std::string &path)
 Constructs a FileWatcher and immediately begins watching path.
 
void Watch (const std::string &path)
 Starts watching path, recording the current modification time.
 
bool HasChanged ()
 Returns true if the file's modification time has changed since the last Watch() or Reset() call.
 
void Reset ()
 Resets the baseline modification timestamp to the current file time.
 
const std::string & GetPath () const
 Returns the path currently being watched.
 
bool IsWatching () const
 Returns true if a path has been set via Watch() or the path constructor.
 

Static Private Member Functions

static time_t GetFileModTime (const std::string &path)
 Platform-portable wrapper around stat() / _stat().
 

Private Attributes

std::string m_Path
 
time_t m_LastModified
 
bool m_IsWatching
 

Detailed Description

Polls a single file for modification-time changes.

Typical usage:

FileWatcher watcher("data/graph.json");
// ... later, every frame or on timer ...
if (watcher.HasChanged())
{
watcher.Reset();
}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Polls a single file for modification-time changes.
Definition FileWatcher.h:43

Definition at line 43 of file FileWatcher.h.

Constructor & Destructor Documentation

◆ FileWatcher() [1/2]

Olympe::FileWatcher::FileWatcher ( )

Constructs a FileWatcher that is not yet watching any file.

Definition at line 23 of file FileWatcher.cpp.

◆ FileWatcher() [2/2]

Olympe::FileWatcher::FileWatcher ( const std::string &  path)
explicit

Constructs a FileWatcher and immediately begins watching path.

Definition at line 29 of file FileWatcher.cpp.

References Watch().

+ Here is the call graph for this function:

Member Function Documentation

◆ GetFileModTime()

time_t Olympe::FileWatcher::GetFileModTime ( const std::string &  path)
staticprivate

Platform-portable wrapper around stat() / _stat().

Returns
Modification time, or 0 on error.

Definition at line 80 of file FileWatcher.cpp.

References GetComponentTypeID_Static().

Referenced by HasChanged(), Reset(), and Watch().

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

◆ GetPath()

const std::string & Olympe::FileWatcher::GetPath ( ) const

Returns the path currently being watched.

Definition at line 66 of file FileWatcher.cpp.

References m_Path.

◆ HasChanged()

bool Olympe::FileWatcher::HasChanged ( )

Returns true if the file's modification time has changed since the last Watch() or Reset() call.

Definition at line 47 of file FileWatcher.cpp.

References GetComponentTypeID_Static(), GetFileModTime(), m_IsWatching, m_LastModified, and m_Path.

+ Here is the call graph for this function:

◆ IsWatching()

bool Olympe::FileWatcher::IsWatching ( ) const

Returns true if a path has been set via Watch() or the path constructor.

Definition at line 71 of file FileWatcher.cpp.

References m_IsWatching.

◆ Reset()

void Olympe::FileWatcher::Reset ( )

Resets the baseline modification timestamp to the current file time.

Definition at line 56 of file FileWatcher.cpp.

References GetFileModTime(), m_IsWatching, m_LastModified, and m_Path.

+ Here is the call graph for this function:

◆ Watch()

void Olympe::FileWatcher::Watch ( const std::string &  path)

Starts watching path, recording the current modification time.

Definition at line 40 of file FileWatcher.cpp.

References GetFileModTime(), m_IsWatching, m_LastModified, and m_Path.

Referenced by FileWatcher().

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

Member Data Documentation

◆ m_IsWatching

bool Olympe::FileWatcher::m_IsWatching
private

Definition at line 100 of file FileWatcher.h.

Referenced by HasChanged(), IsWatching(), Reset(), and Watch().

◆ m_LastModified

time_t Olympe::FileWatcher::m_LastModified
private

Definition at line 99 of file FileWatcher.h.

Referenced by HasChanged(), Reset(), and Watch().

◆ m_Path

std::string Olympe::FileWatcher::m_Path
private

Definition at line 98 of file FileWatcher.h.

Referenced by GetPath(), HasChanged(), Reset(), and Watch().


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