I just made C++ God and it's scary

This commit is contained in:
2023-02-26 21:56:39 -08:00
parent e8892b6477
commit 0ae51cd4dd
15 changed files with 221 additions and 96 deletions

View File

@ -0,0 +1,49 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "StateOwner.hpp"
namespace Dawn {
template<class V>
class StateProperty {
private:
StateOwner *owner;
V value;
void setInternal(V val) {
if(val == this->value) return;// TODO: can I omit this? kinda bad tbh.
assertNotNull(this->owner);
auto old = this->value;
this->value = val;
this->owner->onStatePropertyUpdated(this, val, old);
}
public:
const StateProperty& operator += (const V &value) {
this->setInternal(this->value + value);
return *this;
}
const bool_t operator != (const V &value) {
return value != this->value;
}
const bool_t operator == (const V &value) {
return value == this->value;
}
const StateProperty& operator = (const V &val) {
this->setInternal(val);
return *this;
}
operator V() const {
return this->value;
}
friend class StateOwner;
};
}