introduced object_state enum in object_proxy

This commit is contained in:
Sascha Kühl 2026-02-16 11:28:49 +01:00
parent f38be4c6d9
commit a2a6448e03
1 changed files with 15 additions and 0 deletions

View File

@ -11,6 +11,13 @@
#include <mutex>
namespace matador::object {
enum class object_state : uint8_t {
Transient,
Persistent,
Detached,
Removed
};
template<class Type>
class object_proxy final {
public:
@ -49,6 +56,13 @@ public:
[[nodiscard]] const utils::identifier &primary_key() const { return pk_; }
void primary_key(const utils::identifier &pk) { pk_ = pk; }
bool is_persistent() const { return state_ == object_state::Persistent; }
bool is_transient() const { return state_ == object_state::Transient; }
bool is_detached() const { return state_ == object_state::Detached; }
bool is_removed() const { return state_ == object_state::Removed; }
void change_state(const object_state state) {
state_ = state;
}
private:
Type* resolve() const {
if (obj_) {
@ -72,6 +86,7 @@ private:
std::shared_ptr<Type> obj_{};
std::weak_ptr<object_resolver<Type>> resolver_{};
utils::identifier pk_{};
object_state state_{object_state::Transient};
mutable std::mutex mutex_{};
};
}