I just made C++ God and it's scary
This commit is contained in:
49
src/dawn/state/StateProperty.hpp
Normal file
49
src/dawn/state/StateProperty.hpp
Normal 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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user