introduced object_state enum in object_proxy
This commit is contained in:
parent
f38be4c6d9
commit
a2a6448e03
|
|
@ -11,6 +11,13 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
|
enum class object_state : uint8_t {
|
||||||
|
Transient,
|
||||||
|
Persistent,
|
||||||
|
Detached,
|
||||||
|
Removed
|
||||||
|
};
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
class object_proxy final {
|
class object_proxy final {
|
||||||
public:
|
public:
|
||||||
|
|
@ -49,6 +56,13 @@ public:
|
||||||
[[nodiscard]] const utils::identifier &primary_key() const { return pk_; }
|
[[nodiscard]] const utils::identifier &primary_key() const { return pk_; }
|
||||||
void primary_key(const utils::identifier &pk) { pk_ = 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:
|
private:
|
||||||
Type* resolve() const {
|
Type* resolve() const {
|
||||||
if (obj_) {
|
if (obj_) {
|
||||||
|
|
@ -72,6 +86,7 @@ private:
|
||||||
std::shared_ptr<Type> obj_{};
|
std::shared_ptr<Type> obj_{};
|
||||||
std::weak_ptr<object_resolver<Type>> resolver_{};
|
std::weak_ptr<object_resolver<Type>> resolver_{};
|
||||||
utils::identifier pk_{};
|
utils::identifier pk_{};
|
||||||
|
object_state state_{object_state::Transient};
|
||||||
mutable std::mutex mutex_{};
|
mutable std::mutex mutex_{};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue