Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
FileWatcher.cpp
Go to the documentation of this file.
1/**
2 * @file FileWatcher.cpp
3 * @brief Poll-based file change detection implementation (Phase 7).
4 * @author Olympe Engine
5 * @date 2026-03-10
6 */
7
8#include "FileWatcher.h"
9
10#ifdef _WIN32
11# include <sys/stat.h>
12// Use _stat on Windows
13#else
14# include <sys/stat.h>
15#endif
16
17namespace Olympe {
18
19// ============================================================================
20// Construction
21// ============================================================================
22
24 : m_LastModified(0)
25 , m_IsWatching(false)
26{
27}
28
29FileWatcher::FileWatcher(const std::string& path)
30 : m_LastModified(0)
31 , m_IsWatching(false)
32{
33 Watch(path);
34}
35
36// ============================================================================
37// Control
38// ============================================================================
39
40void FileWatcher::Watch(const std::string& path)
41{
42 m_Path = path;
43 m_IsWatching = !path.empty();
45}
46
48{
49 if (!m_IsWatching)
50 return false;
51
53 return current > m_LastModified;
54}
55
61
62// ============================================================================
63// Accessors
64// ============================================================================
65
66const std::string& FileWatcher::GetPath() const
67{
68 return m_Path;
69}
70
72{
73 return m_IsWatching;
74}
75
76// ============================================================================
77// GetFileModTime
78// ============================================================================
79
80time_t FileWatcher::GetFileModTime(const std::string& path)
81{
82 if (path.empty())
83 return 0;
84
85#ifdef _WIN32
86 struct _stat st;
87 if (_stat(path.c_str(), &st) != 0)
88 return 0;
89 return static_cast<time_t>(st.st_mtime);
90#else
91 struct stat st;
92 if (stat(path.c_str(), &st) != 0)
93 return 0;
94 return st.st_mtime;
95#endif
96}
97
98} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Poll-based file change detection (Phase 7).
void Reset()
Resets the baseline modification timestamp to the current file time.
std::string m_Path
Definition FileWatcher.h:98
bool HasChanged()
Returns true if the file's modification time has changed since the last Watch() or Reset() call.
void Watch(const std::string &path)
Starts watching path, recording the current modification time.
FileWatcher()
Constructs a FileWatcher that is not yet watching any file.
bool IsWatching() const
Returns true if a path has been set via Watch() or the path constructor.
const std::string & GetPath() const
Returns the path currently being watched.
static time_t GetFileModTime(const std::string &path)
Platform-portable wrapper around stat() / _stat().
< Provides AssetID and INVALID_ASSET_ID