summaryrefslogtreecommitdiffhomepage
path: root/src/script.inl
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-05-03 18:42:09 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-05-05 03:16:22 +0200
commite5a80257216d76f5033b4120f348f309ca7764f1 (patch)
tree6544f3ada808214beb7915704f317aba98966e88 /src/script.inl
parentba91cb1393274072721e1c31db0c7f73dc9c9db7 (diff)
a wip
Diffstat (limited to 'src/script.inl')
-rw-r--r--src/script.inl25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/script.inl b/src/script.inl
index a6c93588..afa84e65 100644
--- a/src/script.inl
+++ b/src/script.inl
@@ -33,7 +33,7 @@ void concept_check() {}
namespace floormat {
-#define FM_ASSERT_SCRIPT_STATE(new_state) (Script<S, Obj>::_assert_state((new_state), __FILE__, __LINE__))
+#define FM_ASSERT_SCRIPT_STATE(new_state) (base_script::_assert_state(_state, (new_state), __FILE__, __LINE__))
template <typename S, typename Obj> Script<S, Obj>::~Script() noexcept
{
@@ -60,16 +60,6 @@ Script<S, Obj>::Script(): ptr{nullptr}, _state{script_lifecycle::no_init}
detail_Script::concept_check<S, Obj>();
}
-template <typename S, typename Obj>
-void Script<S, Obj>::_assert_state(script_lifecycle s, const char* file, int line)
-{
- if (_state != s) [[unlikely]]
- fm_emit_abort(file, line,
- "invalid state transition from '%s' to '%s'",
- base_script::state_name(_state).data(),
- base_script::state_name(s).data());
-}
-
template <typename S, typename Obj> script_lifecycle Script<S, Obj>::state() const { return _state; }
template <typename S, typename Obj>
@@ -111,7 +101,8 @@ void Script<S, Obj>::do_initialize(const std::shared_ptr<Obj>& obj)
template <typename S, typename Obj>
void Script<S, Obj>::do_reassign(S* p, const std::shared_ptr<Obj>& obj)
{
- fm_assert(p);
+ if (!p) [[unlikely]]
+ return do_clear(obj);
FM_ASSERT_SCRIPT_STATE(script_lifecycle::created);
fm_debug_assert(ptr);
ptr->on_destroy(obj, script_destroy_reason::unassign);
@@ -121,6 +112,16 @@ void Script<S, Obj>::do_reassign(S* p, const std::shared_ptr<Obj>& obj)
}
template <typename S, typename Obj>
+void Script<S, Obj>::do_clear(const std::shared_ptr<Obj>& obj)
+{
+ FM_ASSERT_SCRIPT_STATE(script_lifecycle::created);
+ fm_debug_assert(ptr);
+ ptr->on_destroy(obj, script_destroy_reason::unassign);
+ ptr->delete_self();
+ ptr = make_empty();
+}
+
+template <typename S, typename Obj>
void Script<S, Obj>::do_destroy_pre(const std::shared_ptr<Obj>& obj, script_destroy_reason r)
{
FM_ASSERT_SCRIPT_STATE(script_lifecycle::created);