From 0d72d9bf733686cd39ad6a7d413f2aa49d985b38 Mon Sep 17 00:00:00 2001 From: Epixu Date: Thu, 10 Oct 2024 18:25:57 +0300 Subject: [PATCH] Some detachment reordering; Further Neat substitutions; Testing Neat/Many descriptors for Things --- source/Module.hpp | 4 ++-- source/Runtime.cpp | 4 ++-- source/Runtime.hpp | 4 ++-- source/Thing.cpp | 31 +++++++++++++++++-------------- source/Thing.hpp | 7 +++---- source/Thing.inl | 2 +- test/TestThing.cpp | 9 ++++++--- 7 files changed, 33 insertions(+), 28 deletions(-) diff --git a/source/Module.hpp b/source/Module.hpp index 73394fc..75227b3 100644 --- a/source/Module.hpp +++ b/source/Module.hpp @@ -93,7 +93,7 @@ namespace Langulus::A }; using EntryFunction = void(*)(DMeta&, MetaList&); - using CreateFunction = Module*(*)(Entity::Runtime*, const Neat&); + using CreateFunction = Module*(*)(Entity::Runtime*, const Many&); using InfoFunction = const Info*(*)(); NOD() Entity::Runtime* GetRuntime() const noexcept { @@ -150,7 +150,7 @@ namespace Langulus::CT \ LANGULUS_EXPORT() \ ::Langulus::A::Module* LANGULUS_MODULE_CREATE() ( \ - ::Langulus::Entity::Runtime* rt, const ::Langulus::Anyness::Neat& desc) { \ + ::Langulus::Entity::Runtime* rt, const ::Langulus::Anyness::Many& desc) { \ static_assert(::Langulus::CT::DerivedFrom, \ "Langulus module class interface " \ #m " doesn't inherit ::Langulus::A::Module"); \ diff --git a/source/Runtime.cpp b/source/Runtime.cpp index 78a2c7d..a178e1f 100644 --- a/source/Runtime.cpp +++ b/source/Runtime.cpp @@ -195,7 +195,7 @@ namespace Langulus::Entity /// @param name - module name /// @param descriptor - module initialization descriptor /// @return the new module instance - A::Module* Runtime::InstantiateModule(const Token& name, const Neat& descriptor) { + A::Module* Runtime::InstantiateModule(const Token& name, const Many& descriptor) { // Load the library if not loaded yet const auto library = LoadSharedLibrary(name); @@ -267,7 +267,7 @@ namespace Langulus::Entity /// @param library - the library handle /// @param descriptor - module initialization descriptor /// @return the new module instance - A::Module* Runtime::InstantiateModule(const SharedLibrary& library, const Neat& descriptor) { + A::Module* Runtime::InstantiateModule(const SharedLibrary& library, const Many& descriptor) { if (not library.IsValid()) return nullptr; diff --git a/source/Runtime.hpp b/source/Runtime.hpp index d6b354b..368ffca 100644 --- a/source/Runtime.hpp +++ b/source/Runtime.hpp @@ -113,10 +113,10 @@ namespace Langulus::Entity NOD() auto GetOwner() const noexcept { return mOwner; } NOD() LANGULUS_API(ENTITY) - A::Module* InstantiateModule(const Token&, const Neat& = {}); + A::Module* InstantiateModule(const Token&, const Many& = {}); NOD() LANGULUS_API(ENTITY) - A::Module* InstantiateModule(const SharedLibrary&, const Neat& = {}); + A::Module* InstantiateModule(const SharedLibrary&, const Many& = {}); NOD() LANGULUS_API(ENTITY) SharedLibrary GetDependency(DMeta) const noexcept; diff --git a/source/Thing.cpp b/source/Thing.cpp index 73e52b3..0ac7e4b 100644 --- a/source/Thing.cpp +++ b/source/Thing.cpp @@ -91,9 +91,9 @@ namespace Langulus::Entity /// @param other - move that entity Thing::Thing(Thing&& other) noexcept : Resolvable {this} - , mChildren {Move(other.mChildren)} , mRuntime {Move(other.mRuntime)} , mFlow {Move(other.mFlow)} + , mChildren {Move(other.mChildren)} , mUnitsAmbiguous {Move(other.mUnitsAmbiguous)} , mUnitsList {Move(other.mUnitsList)} , mTraits {Move(other.mTraits)} @@ -121,9 +121,9 @@ namespace Langulus::Entity /// @param other - clone that entity Thing::Thing(Abandoned&& other) : Resolvable {this} - , mChildren {Abandon(other->mChildren)} , mRuntime {Abandon(other->mRuntime)} , mFlow {Abandon(other->mFlow)} + , mChildren {Abandon(other->mChildren)} , mUnitsAmbiguous {Abandon(other->mUnitsAmbiguous)} , mUnitsList {Abandon(other->mUnitsList)} , mTraits {Abandon(other->mTraits)} @@ -169,13 +169,21 @@ namespace Langulus::Entity void Thing::Detach() { ENTITY_VERBOSE_SELF_TAB("Destroying (", Reference(0), " uses):"); - if (not mRuntime.IsLocked()) - mRuntime.Reset(); + mTraits.Reset(); + + // Decouple all units from this owner + for (auto& unit : mUnitsList) { + ENTITY_VERBOSE_SELF("Decoupling unit: ", unit); + unit->mOwners.Reset(); + ENTITY_VERBOSE_SELF("...", Reference(0), " uses remain"); + } + + mUnitsList.Reset(); + mUnitsAmbiguous.Reset(); + if (not mFlow.IsLocked()) mFlow.Reset(); - mTraits.Reset(); - // Decouple all children from this for (auto& child : mChildren) { if (child->mOwner) { @@ -188,15 +196,10 @@ namespace Langulus::Entity } } - // Decouple all units from this owner - for (auto& unit : mUnitsList) { - ENTITY_VERBOSE_SELF("Decoupling unit: ", unit); - unit->mOwners.Reset(); - ENTITY_VERBOSE_SELF("...", Reference(0), " uses remain"); - } + mChildren.Reset(); - mUnitsAmbiguous.Reset(); - mUnitsList.Reset(); + if (not mRuntime.IsLocked()) + mRuntime.Reset(); } /// Compare two entities diff --git a/source/Thing.hpp b/source/Thing.hpp index 11706eb..605038e 100644 --- a/source/Thing.hpp +++ b/source/Thing.hpp @@ -50,13 +50,12 @@ namespace Langulus::Entity LANGULUS_API(ENTITY) void ResetFlow(Temporal*); // The order of members is critical! - // Hierarchy should be destroyed last, hence it is the first - // member - Hierarchy mChildren; - // Runtime + // Runtime should be destroyed last, hence it is the first member Pin> mRuntime; // Temporal flow Pin> mFlow; + // Hierarchy + Hierarchy mChildren; // Units indexed by all their relevant reflected bases UnitMap mUnitsAmbiguous; // Units indexed by concrete type, in order of addition diff --git a/source/Thing.inl b/source/Thing.inl index 0000687..0d8ed1c 100644 --- a/source/Thing.inl +++ b/source/Thing.inl @@ -53,7 +53,7 @@ namespace Langulus::Entity ENTITY_VERBOSE_SELF_TAB( "Producing child (at ", Reference(0), " references): "); Ref newThing; - newThing.New(this, Neat {Forward(arguments)...}); + newThing.New(this, Many {Forward(arguments)...}); return Abandon(newThing); } diff --git a/test/TestThing.cpp b/test/TestThing.cpp index 5711a93..242b1b1 100644 --- a/test/TestThing.cpp +++ b/test/TestThing.cpp @@ -8,7 +8,10 @@ #include "Common.hpp" -SCENARIO("Testing Thing", "[thing]") { +TEMPLATE_TEST_CASE("Testing Thing with different kidns of descriptors", + "[thing]", + Many, Neat +) { static Allocator::State memoryState; static_assert(CT::Deep, "Hierarchy must be reflected as deep"); @@ -216,7 +219,7 @@ SCENARIO("Testing Thing", "[thing]") { for (int repeat = 0; repeat != 10; ++repeat) { WHEN(std::string("Creating a Thing by descriptor #") + std::to_string(repeat)) { Logger::Special("Start: Creating a Thing by descriptor"); - Neat descriptor { + TestType descriptor { Traits::Name {"Root"}, Construct::From(), Construct::From(), @@ -312,7 +315,7 @@ SCENARIO("Testing Thing", "[thing]") { } GIVEN("A complex hierarchy with runtime, flow, units, and traits") { - Neat descriptor { + TestType descriptor { Traits::Name {"Root"}, Construct::From(), Construct::From(),