Refactor folder item management and move NotifyValue to a new utility header

This commit is contained in:
scawful
2025-01-22 13:32:45 -05:00
parent 50c9223a53
commit a5b94ab173
6 changed files with 75 additions and 78 deletions

55
src/util/notify.h Normal file
View File

@@ -0,0 +1,55 @@
#ifndef YAZE_UTIL_NOTIFY_H
#define YAZE_UTIL_NOTIFY_H
namespace yaze {
namespace util {
/**
* @class NotifyValue
* @brief A class to manage a value that can be modified and notify when it
* changes.
*/
template <typename T>
class NotifyValue {
public:
NotifyValue() : value_(), modified_(false), temp_value_() {}
NotifyValue(const T &value)
: value_(value), modified_(false), temp_value_() {}
void set(const T &value) {
value_ = value;
modified_ = true;
}
const T &get() {
modified_ = false;
return value_;
}
T &mutable_get() {
modified_ = false;
temp_value_ = value_;
return temp_value_;
}
void apply_changes() {
if (temp_value_ != value_) {
value_ = temp_value_;
modified_ = true;
}
}
void operator=(const T &value) { set(value); }
operator T() { return get(); }
bool modified() const { return modified_; }
private:
T value_;
bool modified_;
T temp_value_;
};
} // namespace util
} // namespace yaze
#endif