From 18b001252ea9fd13cf95b2a7d74e021ea0a30bcf Mon Sep 17 00:00:00 2001 From: Dimo Markov Date: Thu, 10 Oct 2024 11:27:58 +0300 Subject: [PATCH] Better take on the maintenancy thingy --- source/Hierarchy-Seek.inl | 88 +++++++-------- source/Hierarchy.hpp | 218 +++++++++++++++++++------------------- source/Thing-Seek.inl | 24 ++--- source/Thing-Traits.cpp | 24 ++--- source/Thing.cpp | 76 ++++++------- source/Thing.hpp | 138 +++++++++++------------- source/Thing.inl | 6 +- source/Unit-Seek.inl | 14 +-- source/Unit.cpp | 25 +++-- source/Unit.hpp | 50 ++++----- 10 files changed, 331 insertions(+), 332 deletions(-) diff --git a/source/Hierarchy-Seek.inl b/source/Hierarchy-Seek.inl index 319685a..9581a9d 100644 --- a/source/Hierarchy-Seek.inl +++ b/source/Hierarchy-Seek.inl @@ -24,19 +24,19 @@ namespace Langulus::Entity /// @param offset - the match to return /// @return a pointer to the found unit, or nullptr if not found TEMPLATE() template LANGULUS(INLINED) - const A::Unit* TME()::SeekUnit(DMeta type, Index offset) const { + auto TME()::SeekUnit(DMeta type, Index offset) const -> const A::Unit* { return const_cast(static_cast(this)) ->template SeekUnit(type, offset); } TEMPLATE() template LANGULUS(INLINED) - Decay* TME()::SeekUnit(Index offset) { + auto TME()::SeekUnit(Index offset) -> Decay* { return dynamic_cast*>(static_cast(this) ->template SeekUnit(MetaDataOf>(), offset)); } TEMPLATE() template LANGULUS(INLINED) - const Decay* TME()::SeekUnit(Index offset) const { + auto TME()::SeekUnit(Index offset) const -> const Decay* { return const_cast(this) ->template SeekUnit(offset); } @@ -49,19 +49,19 @@ namespace Langulus::Entity /// @param offset - the match to return /// @return a pointer to the found unit, or nullptr if not found TEMPLATE() template LANGULUS(INLINED) - const A::Unit* TME()::SeekUnitAux(const Neat& aux, DMeta type, Index offset) const { + auto TME()::SeekUnitAux(const Many& aux, DMeta type, Index offset) const -> const A::Unit* { return const_cast(static_cast(this)) ->template SeekUnitAux(aux, type, offset); } TEMPLATE() template LANGULUS(INLINED) - Decay* TME()::SeekUnitAux(const Neat& aux, Index offset) { + auto TME()::SeekUnitAux(const Many& aux, Index offset) -> Decay* { return dynamic_cast*>(static_cast(this) ->template SeekUnitAux(aux, MetaDataOf>(), offset)); } TEMPLATE() template LANGULUS(INLINED) - const Decay* TME()::SeekUnitAux(const Neat& aux, Index offset) const { + auto TME()::SeekUnitAux(const Many& aux, Index offset) const -> const Decay* { return const_cast(this) ->template SeekUnitAux(aux, offset); } @@ -73,19 +73,19 @@ namespace Langulus::Entity /// @param offset - the match to return /// @return a pointer to the found unit, or nullptr if not found TEMPLATE() template LANGULUS(INLINED) - const A::Unit* TME()::SeekUnitExt(DMeta type, const Neat& ext, Index offset) const { + auto TME()::SeekUnitExt(DMeta type, const Many& ext, Index offset) const -> const A::Unit* { return const_cast(static_cast(this)) ->template SeekUnitExt(type, ext, offset); } TEMPLATE() template LANGULUS(INLINED) - Decay* TME()::SeekUnitExt(const Neat& ext, Index offset) { + auto TME()::SeekUnitExt(const Many& ext, Index offset) -> Decay* { return dynamic_cast*>(static_cast(this) ->template SeekUnitExt(MetaDataOf>(), ext, offset)); } TEMPLATE() template LANGULUS(INLINED) - const Decay* TME()::SeekUnitExt(const Neat& ext, Index offset) const { + auto TME()::SeekUnitExt(const Many& ext, Index offset) const -> const Decay* { return const_cast(this) ->template SeekUnitExt(ext, offset); } @@ -99,19 +99,19 @@ namespace Langulus::Entity /// @param offset - the match to return /// @return a pointer to the found unit, or nullptr if not found TEMPLATE() template LANGULUS(INLINED) - const A::Unit* TME()::SeekUnitAuxExt(DMeta type, const Neat& aux, const Neat& ext, Index offset) const { + auto TME()::SeekUnitAuxExt(DMeta type, const Many& aux, const Many& ext, Index offset) const -> const A::Unit* { return const_cast(static_cast(this)) ->template SeekUnitAuxExt(type, aux, ext, offset); } TEMPLATE() template LANGULUS(INLINED) - Decay* TME()::SeekUnitAuxExt(const Neat& aux, const Neat& ext, Index offset) { + auto TME()::SeekUnitAuxExt(const Many& aux, const Many& ext, Index offset) -> Decay* { return dynamic_cast*>(static_cast(this) ->template SeekUnitAuxExt(MetaDataOf>(), aux, ext, offset)); } TEMPLATE() template LANGULUS(INLINED) - const Decay* TME()::SeekUnitAuxExt(const Neat& aux, const Neat& ext, Index offset) const { + auto TME()::SeekUnitAuxExt(const Many& aux, const Many& ext, Index offset) const -> const Decay* { return const_cast(this) ->template SeekUnitAuxExt(aux, ext, offset); } @@ -122,19 +122,19 @@ namespace Langulus::Entity /// @param offset - the match to return /// @return a pointer to the found unit, or nullptr if not found TEMPLATE() template LANGULUS(INLINED) - Trait TME()::SeekTrait(TMeta type, Index offset) const { + auto TME()::SeekTrait(TMeta type, Index offset) const -> Trait { return const_cast(static_cast(this)) ->template SeekTrait(type, offset); } TEMPLATE() template LANGULUS(INLINED) - Trait TME()::SeekTrait(Index offset) { + auto TME()::SeekTrait(Index offset) -> Trait { return static_cast(this) ->template SeekTrait(MetaTraitOf(), offset); } TEMPLATE() template LANGULUS(INLINED) - Trait TME()::SeekTrait(Index offset) const { + auto TME()::SeekTrait(Index offset) const -> Trait { return const_cast(this) ->template SeekTrait(offset); } @@ -146,19 +146,19 @@ namespace Langulus::Entity /// @param offset - the match to return /// @return a pointer to the found unit, or nullptr if not found TEMPLATE() template LANGULUS(INLINED) - Trait TME()::SeekTraitAux(const Neat& aux, TMeta type, Index offset) const { + auto TME()::SeekTraitAux(const Many& aux, TMeta type, Index offset) const -> Trait { return const_cast(static_cast(this)) ->template SeekTraitAux(aux, type, offset); } TEMPLATE() template LANGULUS(INLINED) - Trait TME()::SeekTraitAux(const Neat& aux, Index offset) { + auto TME()::SeekTraitAux(const Many& aux, Index offset) -> Trait { return static_cast(this) ->template SeekTraitAux(aux, MetaTraitOf(), offset); } TEMPLATE() template LANGULUS(INLINED) - Trait TME()::SeekTraitAux(const Neat& aux, Index offset) const { + auto TME()::SeekTraitAux(const Many& aux, Index offset) const -> Trait { return const_cast(this) ->template SeekTraitAux(aux, offset); } @@ -172,7 +172,7 @@ namespace Langulus::Entity } TEMPLATE() template LANGULUS(INLINED) - bool TME()::SeekValueAux(const Neat& aux, CT::NotTagged auto& output, Index offset) const { + bool TME()::SeekValueAux(const Many& aux, CT::NotTagged auto& output, Index offset) const { return static_cast(this) ->template SeekValueAux(MetaTraitOf(), aux, output, offset); } @@ -190,7 +190,7 @@ namespace Langulus::Entity } TEMPLATE() template LANGULUS(INLINED) - bool TME()::SeekValueAux(const Neat& aux, CT::Tagged auto& output, Index offset) const { + bool TME()::SeekValueAux(const Many& aux, CT::Tagged auto& output, Index offset) const { using T = Deref; auto lambda = [&]() { return static_cast(this)->template @@ -207,43 +207,43 @@ namespace Langulus::Entity /// Available only when managed reflection is enabled /// TEMPLATE() template LANGULUS(INLINED) - A::Unit* TME()::SeekUnit(const Token& dataToken, Index offset) { + auto TME()::SeekUnit(const Token& dataToken, Index offset) -> A::Unit* { return static_cast(this) ->template SeekUnit(RTTI::GetMetaData(dataToken), offset); } TEMPLATE() template LANGULUS(INLINED) - const A::Unit* TME()::SeekUnit(const Token& dataToken, Index offset) const { + auto TME()::SeekUnit(const Token& dataToken, Index offset) const -> const A::Unit* { return static_cast(this) ->template SeekUnit(RTTI::GetMetaData(dataToken), offset); } TEMPLATE() template LANGULUS(INLINED) - A::Unit* TME()::SeekUnitAux(const Neat& aux, const Token& dataToken, Index offset) { + auto TME()::SeekUnitAux(const Many& aux, const Token& dataToken, Index offset) -> A::Unit* { return static_cast(this) ->template SeekUnitAux(aux, RTTI::GetMetaData(dataToken), offset); } TEMPLATE() template LANGULUS(INLINED) - const A::Unit* TME()::SeekUnitAux(const Neat& aux, const Token& dataToken, Index offset) const { + auto TME()::SeekUnitAux(const Many& aux, const Token& dataToken, Index offset) const -> const A::Unit* { return static_cast(this) ->template SeekUnitAux(aux, RTTI::GetMetaData(dataToken), offset); } TEMPLATE() template LANGULUS(INLINED) - Trait TME()::SeekTrait(const Token& traitToken, Index offset) { + auto TME()::SeekTrait(const Token& traitToken, Index offset) -> Trait { return static_cast(this) ->template SeekTrait(RTTI::GetMetaTrait(traitToken), offset); } TEMPLATE() template LANGULUS(INLINED) - Trait TME()::SeekTrait(const Token& traitToken, Index offset) const { + auto TME()::SeekTrait(const Token& traitToken, Index offset) const -> Trait { return static_cast(this) ->template SeekTrait(RTTI::GetMetaTrait(traitToken), offset); } TEMPLATE() template LANGULUS(INLINED) - Trait TME()::SeekTraitAux(const Neat& aux, const Token& traitToken, Index offset) const { + auto TME()::SeekTraitAux(const Many& aux, const Token& traitToken, Index offset) const -> Trait { return static_cast(this) ->template SeekTraitAux(aux, RTTI::GetMetaTrait(traitToken), offset); } @@ -255,7 +255,7 @@ namespace Langulus::Entity } TEMPLATE() template LANGULUS(INLINED) - bool TME()::SeekValueAux(const Token& traitToken, const Neat& aux, CT::Data auto& output, Index offset) const { + bool TME()::SeekValueAux(const Token& traitToken, const Many& aux, CT::Data auto& output, Index offset) const { return static_cast(this) ->template SeekValueAux(RTTI::GetMetaTrait(traitToken), aux, output, offset); } @@ -276,7 +276,7 @@ namespace Langulus::Entity /// @param offset - which of the matches to return /// @return the found unit, or nullptr if no such unit was found template LANGULUS(INLINED) - A::Unit* Hierarchy::SeekUnit(DMeta meta, Index offset) { + auto Hierarchy::SeekUnit(DMeta meta, Index offset) -> A::Unit* { for (auto owner : *this) { A::Unit* result = owner->template SeekUnit(meta, offset); if (result) @@ -294,8 +294,8 @@ namespace Langulus::Entity /// @param offset - the index of the unit to return /// @return the unit if found, or nullptr otherwise template LANGULUS(INLINED) - A::Unit* Hierarchy::SeekUnitAux(const Neat& aux, DMeta meta, Index offset) { - const A::Unit* result {}; + auto Hierarchy::SeekUnitAux(const Many& aux, DMeta meta, Index offset) -> A::Unit* { + const A::Unit* result = nullptr; // Scan descriptor even if hierarchy is empty if constexpr (SEEK & Seek::Here) { @@ -320,9 +320,8 @@ namespace Langulus::Entity // If reached, then no unit was found in the descriptor // Let's delve into the hierarchy, by scanning for Traits::Parent // and Traits::Child inside the 'aux' - //return SeekValue(meta, output, offset); if constexpr (SEEK & Seek::Above) { - aux.ForEachTrait([&](const Traits::Parent& trait) -> LoopControl { + aux.ForEachDeep([&](const Traits::Parent& trait) -> LoopControl { trait.ForEach([&](const Thing& parent) { if (nullptr != (result = parent.SeekUnit(meta, offset))) // Value was found @@ -334,7 +333,7 @@ namespace Langulus::Entity } if constexpr (SEEK & Seek::Below) { - aux.ForEachTrait([&](const Traits::Child& trait) -> LoopControl { + aux.ForEachDeep([&](const Traits::Child& trait) -> LoopControl { trait.ForEach([&](const Thing& child) { if (nullptr != (result = child.SeekUnit(meta, offset))) // Value was found @@ -355,7 +354,7 @@ namespace Langulus::Entity /// @param offset - the index of the unit to return /// @return the unit if found, or nullptr otherwise template LANGULUS(INLINED) - A::Unit* Hierarchy::SeekUnitExt(DMeta type, const Neat& ext, Index offset) { + auto Hierarchy::SeekUnitExt(DMeta type, const Many& ext, Index offset) -> A::Unit* { for (auto owner : *this) { A::Unit* result = owner->template SeekUnitExt(type, ext, offset); if (result) @@ -374,9 +373,9 @@ namespace Langulus::Entity /// @param offset - the index of the unit to return /// @return a pointer to the found unit, or nullptr if not found template LANGULUS(INLINED) - A::Unit* Hierarchy::SeekUnitAuxExt(DMeta type, const Neat& aux, const Neat& ext, Index offset) { + auto Hierarchy::SeekUnitAuxExt(DMeta type, const Many& aux, const Many& ext, Index offset) -> A::Unit* { // Scan descriptor even if hierarchy is empty - A::Unit* result {}; + A::Unit* result = nullptr; aux.ForEachDeep([&](const A::Unit* u) { if (u->CastsTo(type)) { //TODO check construct arguments @@ -406,7 +405,7 @@ namespace Langulus::Entity /// @param offset - the offset to apply /// @return the trait, which is not empty, if trait was found template LANGULUS(INLINED) - Trait Hierarchy::SeekTrait(TMeta meta, Index offset) { + auto Hierarchy::SeekTrait(TMeta meta, Index offset) -> Trait { for (auto owner : *this) { auto result = owner->template SeekTrait(meta, offset); if (result) @@ -423,7 +422,7 @@ namespace Langulus::Entity /// @param offset - the number of the matching trait to use /// @return the trait, which is not empty, if trait was found template LANGULUS(INLINED) - Trait Hierarchy::SeekTraitAux(const Neat& aux, TMeta meta, Index offset) { + auto Hierarchy::SeekTraitAux(const Many& aux, TMeta meta, Index offset) -> Trait { // Scan descriptor Trait result; aux.ForEachDeep([&](const Trait& trait) { @@ -489,7 +488,7 @@ namespace Langulus::Entity /// @param offset - the number of the matching trait to use /// @return the trait, which is not empty, if trait was found template LANGULUS(INLINED) - bool Hierarchy::SeekValueAux(TMeta meta, const Neat& aux, CT::Data auto& output, Index offset) const { + bool Hierarchy::SeekValueAux(TMeta meta, const Many& aux, CT::Data auto& output, Index offset) const { using D = Deref; if constexpr (CT::Pinnable) { @@ -502,7 +501,7 @@ namespace Langulus::Entity if constexpr (SEEK & Seek::Here) { bool done = false; if (meta) { - aux.ForEachTrait([&](const Trait& trait) -> LoopControl { + aux.ForEachDeep([&](const Trait& trait) -> LoopControl { if (trait.IsTrait(meta)) { // Found match try { @@ -568,10 +567,9 @@ namespace Langulus::Entity // If reached, then no trait was found in the descriptor // Let's delve into the hierarchy, by scanning for Traits::Parent // and Traits::Child inside the 'aux' - //return SeekValue(meta, output, offset); bool done = false; if constexpr (SEEK & Seek::Above) { - aux.ForEachTrait([&](const Traits::Parent& trait) -> LoopControl { + aux.ForEachDeep([&](const Traits::Parent& trait) -> LoopControl { trait.ForEach([&](const Thing& parent) { if (parent.SeekValue(meta, output, offset)) { // Value was found @@ -580,12 +578,13 @@ namespace Langulus::Entity } return Loop::Continue; }); + return not done; }); } if constexpr (SEEK & Seek::Below) { - aux.ForEachTrait([&](const Traits::Child& trait) -> LoopControl { + aux.ForEachDeep([&](const Traits::Child& trait) -> LoopControl { trait.ForEach([&](const Thing& child) { if (child.SeekValue(meta, output, offset)) { // Value was found @@ -594,6 +593,7 @@ namespace Langulus::Entity } return Loop::Continue; }); + return not done; }); } diff --git a/source/Hierarchy.hpp b/source/Hierarchy.hpp index 00eae87..22d28fe 100644 --- a/source/Hierarchy.hpp +++ b/source/Hierarchy.hpp @@ -34,6 +34,7 @@ namespace Langulus::Entity /// /// Can't use virtuals, because we want these to be template functions, /// so that we retain the most of the static optimizations + /// TODO generalize these when deduce-this has been implemented well /// /*template NOD() Unit* SeekUnit(DMeta, Index = IndexFirst) = delete; @@ -71,82 +72,83 @@ namespace Langulus::Entity /// The rest of these functions are defined for every SeekInterface /// They all use static_cast(this) as execution context for the /// above functions, which should be defined in THIS + /// TODO generalize these when deduce-this has been implemented well /// - template - NOD() const A::Unit* SeekUnit(DMeta, Index = 0) const; - template - NOD() Decay* SeekUnit(Index = 0); - template - NOD() const Decay* SeekUnit(Index = 0) const; - - template - NOD() const A::Unit* SeekUnitAux(const Neat&, DMeta, Index = 0) const; - template - NOD() Decay* SeekUnitAux(const Neat&, Index = 0); - template - NOD() const Decay* SeekUnitAux(const Neat&, Index = 0) const; - - template - NOD() const A::Unit* SeekUnitExt(DMeta, const Neat&, Index = 0) const; - template - NOD() Decay* SeekUnitExt(const Neat&, Index = 0); - template - NOD() const Decay* SeekUnitExt(const Neat&, Index = 0) const; - - template - NOD() const A::Unit* SeekUnitAuxExt(DMeta, const Neat&, const Neat&, Index = 0) const; - template - NOD() Decay* SeekUnitAuxExt(const Neat&, const Neat&, Index = 0); - template - NOD() const Decay* SeekUnitAuxExt(const Neat&, const Neat&, Index = 0) const; - - template - NOD() Trait SeekTrait(TMeta, Index = 0) const; - template - NOD() Trait SeekTrait(Index = 0); - template - NOD() Trait SeekTrait(Index = 0) const; - - template - NOD() Trait SeekTraitAux(const Neat&, TMeta, Index = 0) const; - template - NOD() Trait SeekTraitAux(const Neat&, Index = 0); - template - NOD() Trait SeekTraitAux(const Neat&, Index = 0) const; + template NOD() + auto SeekUnit(DMeta, Index = 0) const -> const A::Unit*; + template NOD() + auto SeekUnit(Index = 0) -> Decay*; + template NOD() + auto SeekUnit(Index = 0) const -> const Decay*; + + template NOD() + auto SeekUnitAux(const Many&, DMeta, Index = 0) const -> const A::Unit*; + template NOD() + auto SeekUnitAux(const Many&, Index = 0) -> Decay*; + template NOD() + auto SeekUnitAux(const Many&, Index = 0) const -> const Decay*; + + template NOD() + auto SeekUnitExt(DMeta, const Many&, Index = 0) const -> const A::Unit*; + template NOD() + auto SeekUnitExt(const Many&, Index = 0) -> Decay*; + template NOD() + auto SeekUnitExt(const Many&, Index = 0) const -> const Decay*; + + template NOD() + auto SeekUnitAuxExt(DMeta, const Many&, const Many&, Index = 0) const -> const A::Unit*; + template NOD() + auto SeekUnitAuxExt(const Many&, const Many&, Index = 0) -> Decay*; + template NOD() + auto SeekUnitAuxExt(const Many&, const Many&, Index = 0) const -> const Decay*; + + template NOD() + auto SeekTrait(TMeta, Index = 0) const -> Trait; + template NOD() + auto SeekTrait(Index = 0) -> Trait; + template NOD() + auto SeekTrait(Index = 0) const -> Trait; + + template NOD() + auto SeekTraitAux(const Many&, TMeta, Index = 0) const -> Trait; + template NOD() + auto SeekTraitAux(const Many&, Index = 0) -> Trait; + template NOD() + auto SeekTraitAux(const Many&, Index = 0) const -> Trait; template bool SeekValue(CT::NotTagged auto&, Index = IndexFirst) const; template - bool SeekValueAux(const Neat&, CT::NotTagged auto&, Index = 0) const; + bool SeekValueAux(const Many&, CT::NotTagged auto&, Index = 0) const; template bool SeekValue(CT::Tagged auto&, Index = IndexFirst) const; template - bool SeekValueAux(const Neat&, CT::Tagged auto&, Index = 0) const; + bool SeekValueAux(const Many&, CT::Tagged auto&, Index = 0) const; - template - NOD() TMany GatherUnits(DMeta) const; - template - NOD() TMany GatherUnits(); - template - NOD() TMany GatherUnits() const; + template NOD() + auto GatherUnits(DMeta) const -> TMany ; + template NOD() + auto GatherUnits() -> TMany; + template NOD() + auto GatherUnits() const -> TMany; - template - NOD() TMany GatherUnitsExt(DMeta, const Neat&) const; - template - NOD() TMany GatherUnitsExt(const Neat&); - template - NOD() TMany GatherUnitsExt(const Neat&) const; + template NOD() + auto GatherUnitsExt(DMeta, const Many&) const -> TMany; + template NOD() + auto GatherUnitsExt(const Many&) -> TMany; + template NOD() + auto GatherUnitsExt(const Many&) const -> TMany; - template - NOD() TraitList GatherTraits(TMeta) const; - template - NOD() TraitList GatherTraits(); - template - NOD() TraitList GatherTraits() const; + template NOD() + auto GatherTraits(TMeta) const -> TraitList; + template NOD() + auto GatherTraits() -> TraitList; + template NOD() + auto GatherTraits() const -> TraitList; #if LANGULUS_FEATURE(MANAGED_REFLECTION) @@ -154,41 +156,41 @@ namespace Langulus::Entity /// Token based interface /// Available only when managed reflection is enabled /// - template - NOD() A::Unit* SeekUnit(const Token&, Index = 0); - template - NOD() const A::Unit* SeekUnit(const Token&, Index = 0) const; - - template - NOD() A::Unit* SeekUnitAux(const Neat&, const Token&, Index = 0); - template - NOD() const A::Unit* SeekUnitAux(const Neat&, const Token&, Index = 0) const; + template NOD() + auto SeekUnit(const Token&, Index = 0) -> A::Unit*; + template NOD() + auto SeekUnit(const Token&, Index = 0) const -> const A::Unit*; + + template NOD() + auto SeekUnitAux(const Many&, const Token&, Index = 0) -> A::Unit*; + template NOD() + auto SeekUnitAux(const Many&, const Token&, Index = 0) const -> const A::Unit*; - template - NOD() Trait SeekTrait(const Token&, Index = 0); - template - NOD() Trait SeekTrait(const Token&, Index = 0) const; + template NOD() + auto SeekTrait(const Token&, Index = 0) -> Trait; + template NOD() + auto SeekTrait(const Token&, Index = 0) const -> Trait; - template - NOD() Trait SeekTraitAux(const Neat&, const Token&, Index = 0); - template - NOD() Trait SeekTraitAux(const Neat&, const Token&, Index = 0) const; + template NOD() + auto SeekTraitAux(const Many&, const Token&, Index = 0) -> Trait; + template NOD() + auto SeekTraitAux(const Many&, const Token&, Index = 0) const -> Trait; template bool SeekValue(const Token&, CT::Data auto&, Index = 0) const; template - bool SeekValueAux(const Token&, const Neat&, CT::Data auto&, Index = 0) const; + bool SeekValueAux(const Token&, const Many&, CT::Data auto&, Index = 0) const; - template - NOD() TMany GatherUnits(const Token&); - template - NOD() TMany GatherUnits(const Token&) const; + template NOD() + auto GatherUnits(const Token&) -> TMany; + template NOD() + auto GatherUnits(const Token&) const -> TMany; - template - NOD() TraitList GatherTraits(const Token&); - template - NOD() TraitList GatherTraits(const Token&) const; + template NOD() + auto GatherTraits(const Token&) -> TraitList; + template NOD() + auto GatherTraits(const Token&) const -> TraitList; #endif }; @@ -219,24 +221,24 @@ namespace Langulus::Entity using SeekInterface::SeekValue; using SeekInterface::SeekValueAux; - template - NOD() A::Unit* SeekUnit(DMeta, Index = 0); - template - NOD() A::Unit* SeekUnitAux(const Neat&, DMeta, Index = 0); - template - NOD() A::Unit* SeekUnitExt(DMeta, const Neat&, Index = 0); - template - NOD() A::Unit* SeekUnitAuxExt(DMeta, const Neat&, const Neat&, Index = 0); + template NOD() + auto SeekUnit(DMeta, Index = 0) -> A::Unit*; + template NOD() + auto SeekUnitAux(const Many&, DMeta, Index = 0) -> A::Unit*; + template NOD() + auto SeekUnitExt(DMeta, const Many&, Index = 0) -> A::Unit*; + template NOD() + auto SeekUnitAuxExt(DMeta, const Many&, const Many&, Index = 0) -> A::Unit*; - template - NOD() Trait SeekTrait(TMeta, Index = 0); - template - NOD() Trait SeekTraitAux(const Neat&, TMeta, Index = 0); + template NOD() + auto SeekTrait(TMeta, Index = 0) -> Trait; + template NOD() + auto SeekTraitAux(const Many&, TMeta, Index = 0) -> Trait; template bool SeekValue(TMeta, CT::Data auto&, Index = 0) const; template - bool SeekValueAux(TMeta, const Neat&, CT::Data auto&, Index = 0) const; + bool SeekValueAux(TMeta, const Many&, CT::Data auto&, Index = 0) const; /// /// Gather @@ -245,16 +247,16 @@ namespace Langulus::Entity using SeekInterface::GatherUnitsExt; using SeekInterface::GatherTraits; - template - NOD() TMany GatherUnitsExt(DMeta, const Neat&); - template - NOD() TMany GatherUnits(DMeta); + template NOD() + auto GatherUnitsExt(DMeta, const Many&) -> TMany; + template NOD() + auto GatherUnits(DMeta) -> TMany; - template - NOD() TraitList GatherTraits(TMeta); + template NOD() + auto GatherTraits(TMeta) -> TraitList; - template - NOD() TMany GatherValues() const; + template NOD() + auto GatherValues() const -> TMany; }; } // namespace Langulus::Entity diff --git a/source/Thing-Seek.inl b/source/Thing-Seek.inl index b155c76..bbe0360 100644 --- a/source/Thing-Seek.inl +++ b/source/Thing-Seek.inl @@ -29,7 +29,7 @@ namespace Langulus::Entity /// @param offset - which of the matches to return /// @return the found unit, or nullptr if no such unit was found template - A::Unit* Thing::SeekUnit(DMeta meta, Index offset) { + auto Thing::SeekUnit(DMeta meta, Index offset) -> A::Unit* { A::Unit* result = nullptr; if constexpr (SEEK & Seek::Here) { // Seek here if requested @@ -69,7 +69,7 @@ namespace Langulus::Entity /// @param offset - the index of the unit to return /// @return the unit if found, or nullptr otherwise template LANGULUS(INLINED) - A::Unit* Thing::SeekUnitAux(const Neat& aux, DMeta meta, Index offset) { + auto Thing::SeekUnitAux(const Many& aux, DMeta meta, Index offset) -> A::Unit* { A::Unit* result {}; aux.ForEachDeep([&](const A::Unit* unit) { if (unit->CastsTo(meta)) { @@ -99,7 +99,7 @@ namespace Langulus::Entity /// @param offset - the index of the unit to return /// @return the unit if found, or nullptr otherwise template LANGULUS(INLINED) - A::Unit* Thing::SeekUnitExt(DMeta type, const Neat& ext, Index offset) { + auto Thing::SeekUnitExt(DMeta type, const Many& ext, Index offset) -> A::Unit* { A::Unit* result = nullptr; if constexpr (SEEK & Seek::Here) { // Seek here if requested @@ -139,7 +139,7 @@ namespace Langulus::Entity /// @param offset - the Nth match to return /// @return a pointer to the found unit, or nullptr if not found template LANGULUS(INLINED) - A::Unit* Thing::SeekUnitAuxExt(DMeta type, const Neat& aux, const Neat& ext, Index offset) { + auto Thing::SeekUnitAuxExt(DMeta type, const Many& aux, const Many& ext, Index offset) -> A::Unit* { // Scan descriptor even if hierarchy is empty A::Unit* result {}; aux.ForEachDeep([&](const A::Unit* unit) { @@ -170,7 +170,7 @@ namespace Langulus::Entity /// @param offset - the offset to apply /// @return the trait, which is not empty, if trait was found template - Trait Thing::SeekTrait(TMeta meta, Index offset) { + auto Thing::SeekTrait(TMeta meta, Index offset) -> Trait { if constexpr (SEEK & Seek::Here) { // Seek here if requested auto output = GetTrait(meta, offset); @@ -209,7 +209,7 @@ namespace Langulus::Entity /// @param offset - the number of the matching trait to use /// @return the trait, which is not empty, if trait was found template LANGULUS(INLINED) - Trait Thing::SeekTraitAux(const Neat& aux, TMeta meta, Index offset) { + auto Thing::SeekTraitAux(const Many& aux, TMeta meta, Index offset) -> Trait { // Scan descriptor Trait result; aux.ForEachDeep([&](const Trait& trait) { @@ -264,10 +264,6 @@ namespace Langulus::Entity else output = temp.template AsCast(); - /*if constexpr (CT::Pinnable) - output = temp.template AsCast>(); - else - output = temp.template AsCast();*/ return true; } catch (...) { } @@ -305,7 +301,7 @@ namespace Langulus::Entity /// @return true if value has been found and rewritten template LANGULUS(INLINED) bool Thing::SeekValueAux( - TMeta meta, const Neat& aux, CT::Data auto& output, Index offset + TMeta meta, const Many& aux, CT::Data auto& output, Index offset ) const { using D = Deref; @@ -330,7 +326,7 @@ namespace Langulus::Entity // Didn't throw, but we're done only if offset matches done = offset == 0; --offset; - return not done; + return done ? Loop::Break : Loop::Continue; } catch (...) {} } @@ -350,9 +346,9 @@ namespace Langulus::Entity // Didn't throw, but we're done only if offset matches done = offset == 0; --offset; - return not done; + return done ? Loop::Break : Loop::Continue; } - catch(...) { } + catch(...) {} return Loop::Continue; }); diff --git a/source/Thing-Traits.cpp b/source/Thing-Traits.cpp index 2b5db03..c8fbd9d 100644 --- a/source/Thing-Traits.cpp +++ b/source/Thing-Traits.cpp @@ -29,7 +29,7 @@ namespace Langulus::Entity /// @param trait - trait id /// @param offset - offset of result to use /// @return a filled trait if fount, empty if not - Trait Thing::GetTrait(TMeta trait, Index offset) const { + auto Thing::GetTrait(TMeta trait, Index offset) const -> Trait { return GetTrait(Trait::FromMeta(trait, nullptr), offset); } @@ -37,7 +37,7 @@ namespace Langulus::Entity /// @param trait - trait id /// @param offset - offset of result to use /// @return a filled trait if fount, empty if not - Trait Thing::GetTrait(TMeta trait, Index offset) { + auto Thing::GetTrait(TMeta trait, Index offset) -> Trait { return GetTrait(Trait::FromMeta(trait, nullptr), offset); } @@ -45,7 +45,7 @@ namespace Langulus::Entity /// @param id - the trait to search for /// @param index - the index of the trait we seek /// @return a pointer to the trait, or nullptr if not found - Trait* Thing::GetLocalTrait(TMeta id, Index index) { + auto Thing::GetLocalTrait(TMeta id, Index index) -> Trait* { if (id) { // Search a typed trait const auto found = mTraits.FindIt(id); @@ -76,7 +76,7 @@ namespace Langulus::Entity /// @param id - the trait to search for /// @param offset - the index of the trait we seek /// @return a pointer to the trait, or nullptr if not found - const Trait* Thing::GetLocalTrait(TMeta id, Index offset) const { + auto Thing::GetLocalTrait(TMeta id, Index offset) const -> const Trait* { return const_cast(*this).GetLocalTrait(id, offset); } @@ -84,7 +84,7 @@ namespace Langulus::Entity /// @param id - trait to match /// @param index - offset of result to use /// @return a non-empty trait, if found - Trait Thing::GetTrait(const Trait& id, Index index) { + auto Thing::GetTrait(const Trait& id, Index index) -> Trait { if (id.GetTrait()) { // Handle some predefined traits here if (id.template IsTrait()) { @@ -124,14 +124,14 @@ namespace Langulus::Entity /// @param id - trait to match /// @param index - offset of result to use /// @return a non-empty trait, if found - Trait Thing::GetTrait(const Trait& id, Index index) const { + auto Thing::GetTrait(const Trait& id, Index index) const -> Trait { return const_cast(this)->GetTrait(id, index); } /// Add a new trait to the thing /// @param trait - trait to shallow copy /// @return the new trait instance - Trait* Thing::AddTrait(Trait trait) { + auto Thing::AddTrait(Trait trait) -> Trait* { const auto tmeta = trait.GetTrait(); auto found = mTraits.FindIt(tmeta); if (found) { @@ -148,7 +148,7 @@ namespace Langulus::Entity /// Remove a trait from the universal entity /// @param trait - type of trait to remove /// @return the number of removed traits - Count Thing::RemoveTrait(TMeta trait) { + auto Thing::RemoveTrait(TMeta trait) -> Count { const auto found = mTraits.FindIt(trait); if (found) { const auto removed = found.GetValue().GetCount(); @@ -164,7 +164,7 @@ namespace Langulus::Entity /// Remove an exact-matching trait from this entity /// @param trait - type and value to remove /// @return the number of removed traits - Count Thing::RemoveTrait(Trait trait) { + auto Thing::RemoveTrait(Trait trait) -> Count { const auto found = mTraits.FindIt(trait.GetTrait()); if (found) { const auto removed = found.GetValue().Remove(trait); @@ -181,7 +181,7 @@ namespace Langulus::Entity /// A fast check whether traits of the given type are inside this entity /// @param trait - type of trait to check /// @return the number of matching traits - Count Thing::HasTraits(TMeta trait) const { + auto Thing::HasTraits(TMeta trait) const -> Count { const auto found = mTraits.FindIt(trait); return found ? found.GetValue().GetCount() : 0; } @@ -189,7 +189,7 @@ namespace Langulus::Entity /// A fast check whether traits of the given type and value are inside /// @param trait - trait to search for /// @return the number of matching traits - Count Thing::HasTraits(const Trait& trait) const { + auto Thing::HasTraits(const Trait& trait) const -> Count { const auto found = mTraits.FindIt(trait.GetTrait()); if (not found) return 0; @@ -205,7 +205,7 @@ namespace Langulus::Entity /// Get traits /// @return the map of traits LANGULUS_API(ENTITY) - const TraitMap& Thing::GetTraits() const noexcept { + auto Thing::GetTraits() const noexcept -> const TraitMap& { return mTraits; } diff --git a/source/Thing.cpp b/source/Thing.cpp index 6cf98f8..73e52b3 100644 --- a/source/Thing.cpp +++ b/source/Thing.cpp @@ -54,9 +54,10 @@ namespace Langulus::Entity /// Construct as a child of another thing /// @param parent - the thing that owns this thing /// @param descriptor - instructions for creating the thing - Thing::Thing(Thing* parent, const Neat& descriptor) + Thing::Thing(Thing* parent, const Many& descriptor) : Resolvable {this} - , mOwner {parent} { + , mOwner {parent} + { if (parent) { parent->AddChild(this); mRuntime = parent->GetRuntime(); @@ -89,14 +90,15 @@ namespace Langulus::Entity /// because 'other' is removed from its children /// @param other - move that entity Thing::Thing(Thing&& other) noexcept - : Resolvable {this} - , mChildren {Move(other.mChildren)} - , mRuntime {Move(other.mRuntime)} - , mFlow {Move(other.mFlow)} + : Resolvable {this} + , mChildren {Move(other.mChildren)} + , mRuntime {Move(other.mRuntime)} + , mFlow {Move(other.mFlow)} , mUnitsAmbiguous {Move(other.mUnitsAmbiguous)} - , mUnitsList {Move(other.mUnitsList)} - , mTraits {Move(other.mTraits)} - , mRefreshRequired {true} { + , mUnitsList {Move(other.mUnitsList)} + , mTraits {Move(other.mTraits)} + , mRefreshRequired{true} + { // Remap children for (auto& child : mChildren) child->mOwner = this; @@ -118,14 +120,15 @@ namespace Langulus::Entity /// because 'other' is duplicated in its children /// @param other - clone that entity Thing::Thing(Abandoned&& other) - : Resolvable {this} - , mChildren {Abandon(other->mChildren)} - , mRuntime {Abandon(other->mRuntime)} - , mFlow {Abandon(other->mFlow)} + : Resolvable {this} + , mChildren {Abandon(other->mChildren)} + , mRuntime {Abandon(other->mRuntime)} + , mFlow {Abandon(other->mFlow)} , mUnitsAmbiguous {Abandon(other->mUnitsAmbiguous)} - , mUnitsList {Abandon(other->mUnitsList)} - , mTraits {Abandon(other->mTraits)} - , mRefreshRequired {true} { + , mUnitsList {Abandon(other->mUnitsList)} + , mTraits {Abandon(other->mTraits)} + , mRefreshRequired{true} + { // Remap children for (auto& child : mChildren) child->mOwner = this; @@ -147,9 +150,10 @@ namespace Langulus::Entity /// because 'other' is duplicated in its children /// @param other - clone that entity Thing::Thing(Cloned&& other) - : Resolvable {this} - , mChildren {Clone(other->mChildren)} - , mRefreshRequired {true} { + : Resolvable {this} + , mChildren {Clone(other->mChildren)} + , mRefreshRequired{true} + { TODO(); //TODO clone flow and runtime if pinned, recreate modules if new runtime, // recreate units and traits, then recreate children @@ -316,7 +320,7 @@ namespace Langulus::Entity /// @param id - the type of the unit /// @param index - the unit index to seek /// @return the unit if found, or nullptr if not - A::Unit* Thing::GetUnitMeta(DMeta id, Index index) { + auto Thing::GetUnitMeta(DMeta id, Index index) -> A::Unit* { if (id) { // Search a typed trait const auto found = mUnitsAmbiguous.FindIt(id); @@ -327,7 +331,7 @@ namespace Langulus::Entity return mUnitsList[index]; } - const A::Unit* Thing::GetUnitMeta(DMeta type, Index offset) const { + auto Thing::GetUnitMeta(DMeta type, Index offset) const -> const A::Unit* { return const_cast(this)->GetUnitMeta(type, offset); } @@ -338,7 +342,7 @@ namespace Langulus::Entity /// @param what - the desired properties of the unit /// @param index - the unit index to seek /// @return the unit if found, or nullptr if not - A::Unit* Thing::GetUnitExt(DMeta meta, const Neat& what, Index index) { + auto Thing::GetUnitExt(DMeta meta, const Many& what, Index index) -> A::Unit* { if (meta) { // Search a typed unit const auto found = mUnitsAmbiguous.FindIt(meta); @@ -371,7 +375,7 @@ namespace Langulus::Entity return nullptr; } - const A::Unit* Thing::GetUnitExt(DMeta meta, const Neat& what, Index index) const { + auto Thing::GetUnitExt(DMeta meta, const Many& what, Index index) const -> const A::Unit* { return const_cast(this)->GetUnitExt(meta, what, index); } @@ -380,31 +384,31 @@ namespace Langulus::Entity /// @param token - the type name of the unit /// @param offset - the unit index /// @return the unit if found, or nullptr if not - A::Unit* Thing::GetUnitMeta(const Token& token, Index offset) { + auto Thing::GetUnitMeta(const Token& token, Index offset) -> A::Unit* { return GetUnitMeta(RTTI::DisambiguateMeta(token), offset); } #endif /// Get the owner /// @return the owner - const Ref& Thing::GetOwner() const noexcept { + auto Thing::GetOwner() const noexcept -> const Ref& { return mOwner; } /// Get children hierarchy /// @return the hierarchy - const Hierarchy& Thing::GetChildren() const noexcept { + auto Thing::GetChildren() const noexcept -> const Hierarchy& { return mChildren; } /// Get a child by index /// @param id - the index to pick /// @return the child entity, or nullptr of none was found - Thing* Thing::GetChild(Index offset) { + auto Thing::GetChild(Index offset) -> Thing* { return mChildren[offset]; } - const Thing* Thing::GetChild(Index offset) const { + auto Thing::GetChild(Index offset) const -> const Thing* { return const_cast(this)->GetChild(offset); } @@ -412,7 +416,7 @@ namespace Langulus::Entity /// @param name - name to seek /// @param offset - offset to seek /// @return the child entity, or nullptr of none was found - Thing* Thing::GetNamedChild(const Token& name, Index offset) { + auto Thing::GetNamedChild(const Token& name, Index offset) -> Thing* { Index matches = 0; for (auto& child : mChildren) { if (child->GetName() == name) { @@ -425,7 +429,7 @@ namespace Langulus::Entity return nullptr; } - const Thing* Thing::GetNamedChild(const Token& name, Index offset) const { + auto Thing::GetNamedChild(const Token& name, Index offset) const -> const Thing* { return const_cast(this)->GetNamedChild(name, offset); } @@ -456,7 +460,7 @@ namespace Langulus::Entity /// Count the number of matching units in this entity /// @param type - the type of units to search for /// @return the number of matching units - Count Thing::HasUnits(DMeta type) const { + auto Thing::HasUnits(DMeta type) const -> Count { const auto found = mUnitsAmbiguous.FindIt(type); return found ? found.GetValue().GetCount() : 0; } @@ -469,19 +473,19 @@ namespace Langulus::Entity /// Get the current runtime /// @return the pointer to the runtime - const Pin>& Thing::GetRuntime() const noexcept { + auto Thing::GetRuntime() const noexcept -> const Pin>& { return mRuntime; } /// Get the current temporal flow /// @return the pointer to the flow - const Pin>& Thing::GetFlow() const noexcept { + auto Thing::GetFlow() const noexcept -> const Pin>& { return mFlow; } /// Create a local runtime for this thing /// @return the new runtime instance, or the old one if already created - Runtime* Thing::CreateRuntime() { + auto Thing::CreateRuntime() -> Runtime* { if (mRuntime.IsLocked()) return &*mRuntime; @@ -498,7 +502,7 @@ namespace Langulus::Entity /// Create a local flow for this thing /// @return the new flow instance, or the old one, if already created - Temporal* Thing::CreateFlow() { + auto Thing::CreateFlow() -> Temporal* { if (mFlow.IsLocked()) return &*mFlow; @@ -519,7 +523,7 @@ namespace Langulus::Entity /// @param module - name of the module /// @param descriptor - instructions for module setup /// @return the instantiated module interface - A::Module* Thing::LoadMod(const Token& module, const Neat& descriptor) { + auto Thing::LoadMod(const Token& module, const Many& descriptor) -> A::Module* { const auto runtime = GetRuntime(); LANGULUS_ASSUME(UserAssumes, runtime, "No runtime available for loading a module"); diff --git a/source/Thing.hpp b/source/Thing.hpp index 006c1ab..11706eb 100644 --- a/source/Thing.hpp +++ b/source/Thing.hpp @@ -77,7 +77,7 @@ namespace Langulus::Entity public: LANGULUS_API(ENTITY) Thing(); LANGULUS_API(ENTITY) Thing(Describe&&); - LANGULUS_API(ENTITY) Thing(Thing*, const Neat& = {}); + LANGULUS_API(ENTITY) Thing(Thing*, const Many& = {}); LANGULUS_API(ENTITY) Thing(Thing&&) noexcept; LANGULUS_API(ENTITY) Thing(Cloned&&); LANGULUS_API(ENTITY) Thing(Abandoned&&); @@ -98,10 +98,10 @@ namespace Langulus::Entity bool RequiresRefresh() const noexcept; NOD() LANGULUS_API(ENTITY) - const Pin>& GetRuntime() const noexcept; + auto GetRuntime() const noexcept -> const Pin>&; NOD() LANGULUS_API(ENTITY) - const Pin>& GetFlow() const noexcept; + auto GetFlow() const noexcept -> const Pin>&; LANGULUS_API(ENTITY) void Do(Verb&); LANGULUS_API(ENTITY) void Select(Verb&); @@ -130,13 +130,13 @@ namespace Langulus::Entity /// Hierarchy management /// LANGULUS_API(ENTITY) - Runtime* CreateRuntime(); + auto CreateRuntime() -> Runtime*; LANGULUS_API(ENTITY) - Temporal* CreateFlow(); + auto CreateFlow() -> Temporal*; template - Ref CreateChild(T&&...); + auto CreateChild(T&&...) -> Ref; template Count AddChild(Thing*); @@ -144,25 +144,25 @@ namespace Langulus::Entity Count RemoveChild(Thing*); LANGULUS_API(ENTITY) - A::Module* LoadMod(const Token&, const Neat& = {}); + auto LoadMod(const Token&, const Many& = {}) -> A::Module*; NOD() LANGULUS_API(ENTITY) - const Ref& GetOwner() const noexcept; + auto GetOwner() const noexcept -> const Ref&; NOD() LANGULUS_API(ENTITY) - const Hierarchy& GetChildren() const noexcept; + auto GetChildren() const noexcept -> const Hierarchy&; NOD() LANGULUS_API(ENTITY) - Thing* GetChild(Index = 0); + auto GetChild(Index = 0) -> Thing*; NOD() LANGULUS_API(ENTITY) - const Thing* GetChild(Index = 0) const; + auto GetChild(Index = 0) const -> const Thing*; NOD() LANGULUS_API(ENTITY) - Thing* GetNamedChild(const Token&, Index = 0); + auto GetNamedChild(const Token&, Index = 0) -> Thing*; NOD() LANGULUS_API(ENTITY) - const Thing* GetNamedChild(const Token&, Index = 0) const; + auto GetNamedChild(const Token&, Index = 0) const -> const Thing*; LANGULUS_API(ENTITY) void DumpHierarchy() const; @@ -176,13 +176,13 @@ namespace Langulus::Entity template Count RemoveUnit(A::Unit*); - template + template Many CreateUnit(A&&...); - template + template Many CreateUnits(); #if LANGULUS_FEATURE(MANAGED_REFLECTION) - template + template Many CreateUnitToken(const Token&, A&&...); #endif @@ -190,40 +190,38 @@ namespace Langulus::Entity Count RemoveUnits(); NOD() LANGULUS_API(ENTITY) - Count HasUnits(DMeta) const; - - template - NOD() Count HasUnits() const; + auto HasUnits(DMeta) const -> Count; + template NOD() + auto HasUnits() const -> Count; NOD() LANGULUS_API(ENTITY) - const UnitList& GetUnits() const noexcept; + auto GetUnits() const noexcept -> const UnitList&; NOD() LANGULUS_API(ENTITY) - const UnitMap& GetUnitsMap() const noexcept; + auto GetUnitsMap() const noexcept -> const UnitMap&; NOD() LANGULUS_API(ENTITY) - A::Unit* GetUnitMeta(DMeta, Index = 0); + auto GetUnitMeta(DMeta, Index = 0) -> A::Unit*; NOD() LANGULUS_API(ENTITY) - const A::Unit* GetUnitMeta(DMeta, Index = 0) const; + auto GetUnitMeta(DMeta, Index = 0) const -> const A::Unit*; NOD() LANGULUS_API(ENTITY) - A::Unit* GetUnitExt(DMeta, const Neat&, Index = 0); + auto GetUnitExt(DMeta, const Many&, Index = 0) -> A::Unit*; NOD() LANGULUS_API(ENTITY) - const A::Unit* GetUnitExt(DMeta, const Neat&, Index = 0) const; + auto GetUnitExt(DMeta, const Many&, Index = 0) const -> const A::Unit*; - template - NOD() Decay* GetUnit(Index = 0); - template - NOD() const Decay* GetUnit(Index = 0) const; + template NOD() + auto GetUnit(Index = 0) -> Decay*; + template NOD() + auto GetUnit(Index = 0) const -> const Decay*; #if LANGULUS_FEATURE(MANAGED_REFLECTION) NOD() LANGULUS_API(ENTITY) - A::Unit const* GetUnitMeta(const Token&, Index = 0) const; - + auto GetUnitMeta(const Token&, Index = 0) const -> A::Unit const*; NOD() LANGULUS_API(ENTITY) - A::Unit* GetUnitMeta(const Token&, Index = 0); + auto GetUnitMeta(const Token&, Index = 0) -> A::Unit*; - template - NOD() Decay* GetUnitAs(const Token&, Index = 0); + template NOD() + auto GetUnitAs(const Token&, Index = 0) -> Decay*; #endif private: @@ -234,45 +232,37 @@ namespace Langulus::Entity /// /// Trait management /// - LANGULUS_API(ENTITY) Trait* AddTrait(Trait); + LANGULUS_API(ENTITY) auto AddTrait(Trait) -> Trait*; LANGULUS_API(ENTITY) Count RemoveTrait(TMeta); LANGULUS_API(ENTITY) Count RemoveTrait(Trait); NOD() LANGULUS_API(ENTITY) Count HasTraits(TMeta) const; - NOD() LANGULUS_API(ENTITY) Count HasTraits(const Trait&) const; NOD() LANGULUS_API(ENTITY) - const TraitMap& GetTraits() const noexcept; - + auto GetTraits() const noexcept -> const TraitMap&; NOD() LANGULUS_API(ENTITY) - Trait GetTrait(TMeta, Index = 0) const; - + auto GetTrait(TMeta, Index = 0) const -> Trait; NOD() LANGULUS_API(ENTITY) - Trait GetTrait(TMeta, Index = 0); - + auto GetTrait(TMeta, Index = 0) -> Trait; NOD() LANGULUS_API(ENTITY) - Trait GetTrait(const Trait&, Index = 0) const; - + auto GetTrait(const Trait&, Index = 0) const -> Trait; NOD() LANGULUS_API(ENTITY) - Trait GetTrait(const Trait&, Index = 0); - - template - NOD() Trait GetTrait(Index = 0); + auto GetTrait(const Trait&, Index = 0) -> Trait; + template NOD() + auto GetTrait(Index = 0) -> Trait; NOD() LANGULUS_API(ENTITY) - const Trait* GetLocalTrait(TMeta, Index = 0) const; - + auto GetLocalTrait(TMeta, Index = 0) const -> const Trait*; NOD() LANGULUS_API(ENTITY) - Trait* GetLocalTrait(TMeta, Index = 0); - - template - NOD() Trait* GetLocalTrait(Index = 0); - template - NOD() Trait const* GetLocalTrait(Index = 0) const; + auto GetLocalTrait(TMeta, Index = 0) -> Trait*; + template NOD() + auto GetLocalTrait(Index = 0) -> Trait*; + template NOD() + auto GetLocalTrait(Index = 0) const -> Trait const*; LANGULUS_API(ENTITY) void SetName(const Text&); @@ -292,24 +282,24 @@ namespace Langulus::Entity using SeekInterface::SeekValue; using SeekInterface::SeekValueAux; - template - NOD() A::Unit* SeekUnit(DMeta, Index = 0); - template - NOD() A::Unit* SeekUnitAux(const Neat&, DMeta, Index = 0); - template - NOD() A::Unit* SeekUnitExt(DMeta, const Neat&, Index = 0); - template - NOD() A::Unit* SeekUnitAuxExt(DMeta, const Neat&, const Neat&, Index = 0); + template NOD() + auto SeekUnit(DMeta, Index = 0) -> A::Unit*; + template NOD() + auto SeekUnitAux(const Many&, DMeta, Index = 0) -> A::Unit*; + template NOD() + auto SeekUnitExt(DMeta, const Many&, Index = 0) -> A::Unit*; + template NOD() + auto SeekUnitAuxExt(DMeta, const Many&, const Many&, Index = 0) -> A::Unit*; - template - NOD() Trait SeekTrait(TMeta, Index = 0); - template - NOD() Trait SeekTraitAux(const Neat&, TMeta, Index = 0); + template NOD() + auto SeekTrait(TMeta, Index = 0) -> Trait; + template NOD() + auto SeekTraitAux(const Many&, TMeta, Index = 0) -> Trait; template bool SeekValue(TMeta, CT::Data auto&, Index = 0) const; template - bool SeekValueAux(TMeta, const Neat&, CT::Data auto&, Index = 0) const; + bool SeekValueAux(TMeta, const Many&, CT::Data auto&, Index = 0) const; /// /// Gather @@ -319,15 +309,15 @@ namespace Langulus::Entity using SeekInterface::GatherTraits; template - NOD() TMany GatherUnits(DMeta); + auto GatherUnits(DMeta) -> TMany; template - NOD() TMany GatherUnitsExt(DMeta, const Neat&); + auto GatherUnitsExt(DMeta, const Many&) -> TMany; template - NOD() TraitList GatherTraits(TMeta); + auto GatherTraits(TMeta) -> TraitList; template - NOD() TMany GatherValues() const; + auto GatherValues() const -> TMany; }; } // namespace Langulus::Entity \ No newline at end of file diff --git a/source/Thing.inl b/source/Thing.inl index f872bf1..e159916 100644 --- a/source/Thing.inl +++ b/source/Thing.inl @@ -581,8 +581,8 @@ namespace Langulus::Entity // Implicitly add a parent trait to descriptor, if one isn't // already added - it will be stripped later, when normalizing // the descriptor when producing the item from a factory - Construct descriptor {construct}; - Traits::Parent parent; + Construct descriptor = construct; + /*Traits::Parent parent; if (not descriptor->ExtractTrait(parent)) { parent = this; parent.MakeMissing(); @@ -592,7 +592,7 @@ namespace Langulus::Entity Reference(0), " references)" ); } - else parent << this; + else parent << this;*/ if (producer) { // Data has a specific producer, we can narrow the required diff --git a/source/Unit-Seek.inl b/source/Unit-Seek.inl index 8383394..56d421a 100644 --- a/source/Unit-Seek.inl +++ b/source/Unit-Seek.inl @@ -19,7 +19,7 @@ namespace Langulus::A /// @param offset - which of the matches to return /// @return the found unit, or nullptr if no such unit was found template LANGULUS(INLINED) - Unit* Unit::SeekUnit(DMeta meta, Index offset) { + auto Unit::SeekUnit(DMeta meta, Index offset) -> Unit* { return mOwners.template SeekUnit(meta, offset); } @@ -30,7 +30,7 @@ namespace Langulus::A /// @param offset - the index of the unit to return /// @return the unit if found, or nullptr otherwise template LANGULUS(INLINED) - Unit* Unit::SeekUnitAux(const Neat& aux, DMeta meta, Index offset) { + auto Unit::SeekUnitAux(const Many& aux, DMeta meta, Index offset) -> Unit* { return mOwners.template SeekUnitAux(aux, meta, offset); } @@ -41,7 +41,7 @@ namespace Langulus::A /// @param offset - the index of the unit to return /// @return the unit if found, or nullptr otherwise template LANGULUS(INLINED) - Unit* Unit::SeekUnitExt(DMeta type, const Neat& ext, Index offset) { + auto Unit::SeekUnitExt(DMeta type, const Many& ext, Index offset) -> Unit* { return mOwners.template SeekUnitExt(type, ext, offset); } @@ -54,7 +54,7 @@ namespace Langulus::A /// @param offset - the index of the unit to return /// @return a pointer to the found unit, or nullptr if not found template LANGULUS(INLINED) - Unit* Unit::SeekUnitAuxExt(DMeta type, const Neat& aux, const Neat& ext, Index offset) { + auto Unit::SeekUnitAuxExt(DMeta type, const Many& aux, const Many& ext, Index offset) -> Unit* { return mOwners.template SeekUnitAuxExt(type, aux, ext, offset); } @@ -64,7 +64,7 @@ namespace Langulus::A /// @param offset - the offset to apply /// @return the trait, which is not empty, if trait was found template LANGULUS(INLINED) - Langulus::Trait Unit::SeekTrait(TMeta meta, Index offset) { + auto Unit::SeekTrait(TMeta meta, Index offset) -> Langulus::Trait { return mOwners.template SeekTrait(meta, offset); } @@ -75,7 +75,7 @@ namespace Langulus::A /// @param offset - the number of the matching trait to use /// @return the trait, which is not empty, if trait was found template LANGULUS(INLINED) - Langulus::Trait Unit::SeekTraitAux(const Neat& aux, TMeta meta, Index offset) { + auto Unit::SeekTraitAux(const Many& aux, TMeta meta, Index offset) -> Langulus::Trait { return mOwners.template SeekTraitAux(aux, meta, offset); } @@ -103,7 +103,7 @@ namespace Langulus::A /// @param offset - the number of the matching trait to use /// @return the trait, which is not empty, if trait was found template LANGULUS(INLINED) - bool Unit::SeekValueAux(TMeta meta, const Neat& aux, CT::Data auto& output, Index offset) const { + bool Unit::SeekValueAux(TMeta meta, const Many& aux, CT::Data auto& output, Index offset) const { return mOwners.template SeekValueAux(meta, aux, output, offset); } diff --git a/source/Unit.cpp b/source/Unit.cpp index 6a7ab7c..42bb3d7 100644 --- a/source/Unit.cpp +++ b/source/Unit.cpp @@ -12,6 +12,8 @@ using namespace Langulus::A; + +/// Unit destructor decouples unit from all owners Unit::~Unit() { for (auto entity : mOwners) Decouple(entity); @@ -27,11 +29,11 @@ void Unit::Select(Flow::Verb& verb) { /// Check if this unit has a given set of properties /// @param descriptor - descriptor with required properties /// @return true if the unit has the given properties -bool Unit::CompareDescriptor(const Neat& descriptor) const { +bool Unit::CompareDescriptor(const Many& descriptor) const { // First we compare traits only, all of them must be present bool mismatch = false; Offset memberOffset = 0; - descriptor.ForEach([&](const Anyness::Trait& trait) { + descriptor.ForEachDeep([&](const Anyness::Trait& trait) { if (not GetMember(trait.GetTrait(), memberOffset) .Compare(static_cast(trait))) { mismatch = true; @@ -42,10 +44,10 @@ bool Unit::CompareDescriptor(const Neat& descriptor) const { return Loop::Continue; }); - // Then we run another check, based on data types, again, all - // of them must be present, either in trait, or in other form + // Then we run another check based on data types, again - all + // of them must be present, either as trait or in other form memberOffset = 0; - descriptor.ForEachTail([&](const Many& anythingElse) { + descriptor.ForEachDeep([&](const Many& anythingElse) { if (not GetMember(TMeta {}, memberOffset).Compare(anythingElse)) { mismatch = true; return Loop::Break; @@ -60,7 +62,7 @@ bool Unit::CompareDescriptor(const Neat& descriptor) const { /// Get the list of unit owners /// @return the owners -const Hierarchy& Unit::GetOwners() const noexcept { +auto Unit::GetOwners() const noexcept -> const Hierarchy& { return mOwners; } @@ -71,7 +73,7 @@ void Unit::Refresh() {} /// @attention assumes units are correctly coupled and coupling to /// different runtimes should be explicitly disallowed /// @return a pointer to the runtime, if available -Runtime* Unit::GetRuntime() const noexcept { +auto Unit::GetRuntime() const noexcept -> Runtime* { if (not mOwners) return nullptr; return &*mOwners[0]->GetRuntime(); @@ -81,14 +83,19 @@ Runtime* Unit::GetRuntime() const noexcept { /// Traits::Parent, if any was defined (always two-sided) /// This will call refresh to all units in that entity on next tick /// @param desc - the descriptor to scan for parents -void Unit::Couple(const Neat& desc) { - // Couple any Thing provided in the descriptor +/// @param fallback - a fallback Thing to couple to (optional) +/// This usually comes from the producer's context. For example, if you +/// don't provide a parent for the renderer, it will be instantiated as +/// a child to the graphics module owner (i.e. the runtime owner) +void Unit::Couple(const Many& desc, const Thing* fallback) { const Thing* owner = nullptr; if (not desc.ExtractTrait(owner)) desc.ExtractData(owner); if (owner and mOwners.Merge(IndexBack, const_cast(owner))) const_cast(owner)->AddUnit(this); + else if (fallback) + const_cast(fallback)->AddUnit(this); } /// Decouple the component from an entity (always two-sided) diff --git a/source/Unit.hpp b/source/Unit.hpp index f06f30b..96a51ed 100644 --- a/source/Unit.hpp +++ b/source/Unit.hpp @@ -63,9 +63,9 @@ namespace Langulus::A virtual void Refresh(); - Runtime* GetRuntime() const noexcept; - const Hierarchy& GetOwners() const noexcept; - bool CompareDescriptor(const Neat&) const; + auto GetRuntime() const noexcept -> Runtime*; + auto GetOwners() const noexcept -> const Hierarchy&; + bool CompareDescriptor(const Many&) const; /// /// Flow @@ -85,24 +85,24 @@ namespace Langulus::A using SeekInterface::SeekValue; using SeekInterface::SeekValueAux; - template - NOD() Unit* SeekUnit(DMeta, Index = 0); - template - NOD() Unit* SeekUnitAux(const Neat&, DMeta, Index = 0); - template - NOD() Unit* SeekUnitExt(DMeta, const Neat&, Index = 0); - template - NOD() Unit* SeekUnitAuxExt(DMeta, const Neat&, const Neat&, Index = 0); + template NOD() + auto SeekUnit(DMeta, Index = 0) -> Unit*; + template NOD() + auto SeekUnitAux(const Many&, DMeta, Index = 0) -> Unit*; + template NOD() + auto SeekUnitExt(DMeta, const Many&, Index = 0) -> Unit*; + template NOD() + auto SeekUnitAuxExt(DMeta, const Many&, const Many&, Index = 0) -> Unit*; - template - NOD() Langulus::Trait SeekTrait(TMeta, Index = 0); - template - NOD() Langulus::Trait SeekTraitAux(const Neat&, TMeta, Index = 0); + template NOD() + auto SeekTrait(TMeta, Index = 0) -> Langulus::Trait; + template NOD() + auto SeekTraitAux(const Many&, TMeta, Index = 0) -> Langulus::Trait; template bool SeekValue(TMeta, CT::Data auto&, Index = 0) const; template - bool SeekValueAux(TMeta, const Neat&, CT::Data auto&, Index = 0) const; + bool SeekValueAux(TMeta, const Many&, CT::Data auto&, Index = 0) const; /// /// Gather @@ -111,19 +111,19 @@ namespace Langulus::A using SeekInterface::GatherUnitsExt; using SeekInterface::GatherTraits; - template - NOD() TMany GatherUnits(DMeta); - template - NOD() TMany GatherUnitsExt(DMeta, const Neat&); + template NOD() + auto GatherUnits(DMeta) -> TMany; + template NOD() + auto GatherUnitsExt(DMeta, const Many&) -> TMany; - template - NOD() TraitList GatherTraits(TMeta); + template NOD() + auto GatherTraits(TMeta) -> TraitList; - template - NOD() TMany GatherValues() const; + template NOD() + auto GatherValues() const -> TMany; protected: - void Couple(const Neat&); + void Couple(const Many&, const Thing* = nullptr); void Decouple(const Thing*); void ReplaceOwner(const Thing*, const Thing*); };