Last active
August 29, 2015 14:27
-
-
Save MartinBspheroid/b6f601b53c6f056f1df7 to your computer and use it in GitHub Desktop.
minimal autoreloading in Cinder it's called BullDog, LOL!!!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// minimal autoreloading in cinder | |
/// it's called BullDog, LOL!!!! | |
struct wFile | |
{ | |
time_t time; | |
fs::path path; | |
std::function<void()> callback; | |
wFile(time_t t, fs::path p, std::function<void()> c) { | |
time = t; | |
path = p; | |
callback = c; | |
} | |
}; | |
class BullDog | |
{ | |
public: | |
BullDog(){}; | |
~BullDog(){}; | |
void watch(fs::path p, std::function<void()> callback) { | |
if(fs::exists(p))list.emplace_back(last_write_time(p), p, callback); | |
} | |
void check(){ | |
list.erase(remove_if(list.begin(), list.end(), [&](wFile w){ return !fs::exists(w.path);}), list.end()); | |
for (auto &item : list){ | |
auto lw = last_write_time(item.path); | |
if (lw > 0 && lw != item.time){ | |
item.callback(); | |
item.time = lw; | |
} | |
} | |
} | |
private: | |
vector<wFile> list; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment