Skip to content

Instantly share code, notes, and snippets.

@jsonzilla
Last active March 7, 2023 20:59
Show Gist options
  • Save jsonzilla/5a0ef78526c8b898bfde507908c1810e to your computer and use it in GitHub Desktop.
Save jsonzilla/5a0ef78526c8b898bfde507908c1810e to your computer and use it in GitHub Desktop.
Check the lask modified, if changed return true;
#include <chrono>
#include <sys/types.h>
#include <sys/stat.h>
std::chrono::time_point<std::chrono::system_clock> lastChangedFileTime;
bool SomeClass::NeedReload
{
struct stat result;
if (stat(filePath.c_str(), &result) == 0) {
auto mod_time = result.st_mtime;
auto newTime = std::chrono::system_clock::from_time_t(mod_time);
if (newTime != lastChangedFileTime) {
lastChangedFileTime = newTime;
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment