Skip to content

Commit

Permalink
Some detachment reordering; Further Neat substitutions; Testing Neat/…
Browse files Browse the repository at this point in the history
…Many descriptors for Things
  • Loading branch information
Epixu committed Oct 10, 2024
1 parent 09561c3 commit 0d72d9b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 28 deletions.
4 changes: 2 additions & 2 deletions source/Module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<m, ::Langulus::A::Module>, \
"Langulus module class interface " \
#m " doesn't inherit ::Langulus::A::Module"); \
Expand Down
4 changes: 2 additions & 2 deletions source/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions source/Runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 17 additions & 14 deletions source/Thing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -121,9 +121,9 @@ namespace Langulus::Entity
/// @param other - clone that entity
Thing::Thing(Abandoned<Thing>&& 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)}
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions source/Thing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ref<Runtime>> mRuntime;
// Temporal flow
Pin<Ref<Temporal>> mFlow;
// Hierarchy
Hierarchy mChildren;
// Units indexed by all their relevant reflected bases
UnitMap mUnitsAmbiguous;
// Units indexed by concrete type, in order of addition
Expand Down
2 changes: 1 addition & 1 deletion source/Thing.inl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace Langulus::Entity
ENTITY_VERBOSE_SELF_TAB(
"Producing child (at ", Reference(0), " references): ");
Ref<Thing> newThing;
newThing.New(this, Neat {Forward<T>(arguments)...});
newThing.New(this, Many {Forward<T>(arguments)...});
return Abandon(newThing);
}

Expand Down
9 changes: 6 additions & 3 deletions test/TestThing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity::Hierarchy>,
"Hierarchy must be reflected as deep");
Expand Down Expand Up @@ -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<Runtime>(),
Construct::From<Temporal>(),
Expand Down Expand Up @@ -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<Runtime>(),
Construct::From<Temporal>(),
Expand Down

0 comments on commit 0d72d9b

Please sign in to comment.