Download src/core/state.cpp from fava21/hf_repo4: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/datasets/fava21/hf_repo4/resolve/main/src/core/state.cpp
- Command line
-
hf download hf://datasets/fava21/hf_repo4/src/core/state.cpp
-
curl -L -o state.cpp https://huggingface.co/datasets/fava21/hf_repo4/resolve/main/src/core/state.cpp
1.36 kB
| // FCS Glass - src/core/state.cpp | |
| // | |
| // Implements: C2, C3. See src/core/state.h. | |
| namespace fcs { | |
| namespace core { | |
| // REQ C2 / C3 - one roll per frame. Swap rather than copy: it is O(1) instead | |
| // of O(widgets), and it makes "previous" exactly the map that was current a | |
| // moment ago, with no chance of the two drifting apart. | |
| void StateStore::BeginFrame() { | |
| prev_.swap(cur_); | |
| cur_.clear(); | |
| ++frame_; | |
| } | |
| // REQ C2 - created on first sight, default-initialised. operator[] does the | |
| // insert; the map is the single owner of the state, so a widget cannot hold a | |
| // copy that outlives its key. | |
| WidgetState& StateStore::Get(Id id) { return cur_[id]; } | |
| // REQ C3 - the previous frame's copy. An id that did not exist last frame reads | |
| // as a default-constructed WidgetState, which is the honest answer: it was not | |
| // hovered, because it was not there to be hovered. | |
| const WidgetState& StateStore::prev(Id id) const { | |
| const auto it = prev_.find(id); | |
| return (it == prev_.end()) ? unknown_ : it->second; | |
| } | |
| // REQ T6 - surface rebuild. Deliberately wipes BOTH maps: keeping `prev_` would | |
| // leave widgets reporting hover against a surface that no longer exists. | |
| void StateStore::Clear() { | |
| cur_.clear(); | |
| prev_.clear(); | |
| unknown_ = WidgetState{}; | |
| } | |
| } // namespace core | |
| } // namespace fcs | |