Skip to content

Commit

Permalink
Better take on the maintenancy thingy
Browse files Browse the repository at this point in the history
  • Loading branch information
Epixu committed Oct 10, 2024
1 parent 52db22d commit 18b0012
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 332 deletions.
88 changes: 44 additions & 44 deletions source/Hierarchy-Seek.inl

Large diffs are not rendered by default.

218 changes: 110 additions & 108 deletions source/Hierarchy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Seek = Seek::HereAndAbove>
NOD() Unit* SeekUnit(DMeta, Index = IndexFirst) = delete;
Expand Down Expand Up @@ -71,124 +72,125 @@ namespace Langulus::Entity
/// The rest of these functions are defined for every SeekInterface
/// They all use static_cast<THIS*>(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<Seek = Seek::HereAndAbove>
NOD() const A::Unit* SeekUnit(DMeta, Index = 0) const;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() Decay<T>* SeekUnit(Index = 0);
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() const Decay<T>* SeekUnit(Index = 0) const;

template<Seek = Seek::HereAndAbove>
NOD() const A::Unit* SeekUnitAux(const Neat&, DMeta, Index = 0) const;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() Decay<T>* SeekUnitAux(const Neat&, Index = 0);
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() const Decay<T>* SeekUnitAux(const Neat&, Index = 0) const;

template<Seek = Seek::HereAndAbove>
NOD() const A::Unit* SeekUnitExt(DMeta, const Neat&, Index = 0) const;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() Decay<T>* SeekUnitExt(const Neat&, Index = 0);
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() const Decay<T>* SeekUnitExt(const Neat&, Index = 0) const;

template<Seek = Seek::HereAndAbove>
NOD() const A::Unit* SeekUnitAuxExt(DMeta, const Neat&, const Neat&, Index = 0) const;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() Decay<T>* SeekUnitAuxExt(const Neat&, const Neat&, Index = 0);
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() const Decay<T>* SeekUnitAuxExt(const Neat&, const Neat&, Index = 0) const;

template<Seek = Seek::HereAndAbove>
NOD() Trait SeekTrait(TMeta, Index = 0) const;
template<CT::Trait = Trait, Seek = Seek::HereAndAbove>
NOD() Trait SeekTrait(Index = 0);
template<CT::Trait = Trait, Seek = Seek::HereAndAbove>
NOD() Trait SeekTrait(Index = 0) const;

template<Seek = Seek::HereAndAbove>
NOD() Trait SeekTraitAux(const Neat&, TMeta, Index = 0) const;
template<CT::Trait = Trait, Seek = Seek::HereAndAbove>
NOD() Trait SeekTraitAux(const Neat&, Index = 0);
template<CT::Trait = Trait, Seek = Seek::HereAndAbove>
NOD() Trait SeekTraitAux(const Neat&, Index = 0) const;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnit(DMeta, Index = 0) const -> const A::Unit*;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto SeekUnit(Index = 0) -> Decay<T>*;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto SeekUnit(Index = 0) const -> const Decay<T>*;

template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnitAux(const Many&, DMeta, Index = 0) const -> const A::Unit*;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto SeekUnitAux(const Many&, Index = 0) -> Decay<T>*;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto SeekUnitAux(const Many&, Index = 0) const -> const Decay<T>*;

template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnitExt(DMeta, const Many&, Index = 0) const -> const A::Unit*;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto SeekUnitExt(const Many&, Index = 0) -> Decay<T>*;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto SeekUnitExt(const Many&, Index = 0) const -> const Decay<T>*;

template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnitAuxExt(DMeta, const Many&, const Many&, Index = 0) const -> const A::Unit*;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto SeekUnitAuxExt(const Many&, const Many&, Index = 0) -> Decay<T>*;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto SeekUnitAuxExt(const Many&, const Many&, Index = 0) const -> const Decay<T>*;

template<Seek = Seek::HereAndAbove> NOD()
auto SeekTrait(TMeta, Index = 0) const -> Trait;
template<CT::Trait = Trait, Seek = Seek::HereAndAbove> NOD()
auto SeekTrait(Index = 0) -> Trait;
template<CT::Trait = Trait, Seek = Seek::HereAndAbove> NOD()
auto SeekTrait(Index = 0) const -> Trait;

template<Seek = Seek::HereAndAbove> NOD()
auto SeekTraitAux(const Many&, TMeta, Index = 0) const -> Trait;
template<CT::Trait = Trait, Seek = Seek::HereAndAbove> NOD()
auto SeekTraitAux(const Many&, Index = 0) -> Trait;
template<CT::Trait = Trait, Seek = Seek::HereAndAbove> NOD()
auto SeekTraitAux(const Many&, Index = 0) const -> Trait;


template<CT::Trait = Trait, Seek = Seek::HereAndAbove>
bool SeekValue(CT::NotTagged auto&, Index = IndexFirst) const;
template<CT::Trait = Trait, Seek = Seek::HereAndAbove>
bool SeekValueAux(const Neat&, CT::NotTagged auto&, Index = 0) const;
bool SeekValueAux(const Many&, CT::NotTagged auto&, Index = 0) const;

template<Seek = Seek::HereAndAbove>
bool SeekValue(CT::Tagged auto&, Index = IndexFirst) const;
template<Seek = Seek::HereAndAbove>
bool SeekValueAux(const Neat&, CT::Tagged auto&, Index = 0) const;
bool SeekValueAux(const Many&, CT::Tagged auto&, Index = 0) const;


template<Seek = Seek::HereAndAbove>
NOD() TMany<const A::Unit*> GatherUnits(DMeta) const;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() TMany<T*> GatherUnits();
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() TMany<const T*> GatherUnits() const;
template<Seek = Seek::HereAndAbove> NOD()
auto GatherUnits(DMeta) const -> TMany<const A::Unit*> ;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto GatherUnits() -> TMany<T*>;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto GatherUnits() const -> TMany<const T*>;

template<Seek = Seek::HereAndAbove>
NOD() TMany<const A::Unit*> GatherUnitsExt(DMeta, const Neat&) const;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() TMany<T*> GatherUnitsExt(const Neat&);
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove>
NOD() TMany<const T*> GatherUnitsExt(const Neat&) const;
template<Seek = Seek::HereAndAbove> NOD()
auto GatherUnitsExt(DMeta, const Many&) const -> TMany<const A::Unit*>;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto GatherUnitsExt(const Many&) -> TMany<T*>;
template<CT::Data T = A::Unit, Seek = Seek::HereAndAbove> NOD()
auto GatherUnitsExt(const Many&) const -> TMany<const T*>;


template<Seek = Seek::HereAndAbove>
NOD() TraitList GatherTraits(TMeta) const;
template<CT::Trait = Trait, Seek = Seek::HereAndAbove>
NOD() TraitList GatherTraits();
template<CT::Trait = Trait, Seek = Seek::HereAndAbove>
NOD() TraitList GatherTraits() const;
template<Seek = Seek::HereAndAbove> NOD()
auto GatherTraits(TMeta) const -> TraitList;
template<CT::Trait = Trait, Seek = Seek::HereAndAbove> NOD()
auto GatherTraits() -> TraitList;
template<CT::Trait = Trait, Seek = Seek::HereAndAbove> NOD()
auto GatherTraits() const -> TraitList;


#if LANGULUS_FEATURE(MANAGED_REFLECTION)
///
/// Token based interface
/// Available only when managed reflection is enabled
///
template<Seek = Seek::HereAndAbove>
NOD() A::Unit* SeekUnit(const Token&, Index = 0);
template<Seek = Seek::HereAndAbove>
NOD() const A::Unit* SeekUnit(const Token&, Index = 0) const;

template<Seek = Seek::HereAndAbove>
NOD() A::Unit* SeekUnitAux(const Neat&, const Token&, Index = 0);
template<Seek = Seek::HereAndAbove>
NOD() const A::Unit* SeekUnitAux(const Neat&, const Token&, Index = 0) const;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnit(const Token&, Index = 0) -> A::Unit*;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnit(const Token&, Index = 0) const -> const A::Unit*;

template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnitAux(const Many&, const Token&, Index = 0) -> A::Unit*;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnitAux(const Many&, const Token&, Index = 0) const -> const A::Unit*;

template<Seek = Seek::HereAndAbove>
NOD() Trait SeekTrait(const Token&, Index = 0);
template<Seek = Seek::HereAndAbove>
NOD() Trait SeekTrait(const Token&, Index = 0) const;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekTrait(const Token&, Index = 0) -> Trait;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekTrait(const Token&, Index = 0) const -> Trait;

template<Seek = Seek::HereAndAbove>
NOD() Trait SeekTraitAux(const Neat&, const Token&, Index = 0);
template<Seek = Seek::HereAndAbove>
NOD() Trait SeekTraitAux(const Neat&, const Token&, Index = 0) const;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekTraitAux(const Many&, const Token&, Index = 0) -> Trait;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekTraitAux(const Many&, const Token&, Index = 0) const -> Trait;

template<Seek = Seek::HereAndAbove>
bool SeekValue(const Token&, CT::Data auto&, Index = 0) const;
template<Seek = Seek::HereAndAbove>
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<Seek = Seek::HereAndAbove>
NOD() TMany<A::Unit*> GatherUnits(const Token&);
template<Seek = Seek::HereAndAbove>
NOD() TMany<const A::Unit*> GatherUnits(const Token&) const;
template<Seek = Seek::HereAndAbove> NOD()
auto GatherUnits(const Token&) -> TMany<A::Unit*>;
template<Seek = Seek::HereAndAbove> NOD()
auto GatherUnits(const Token&) const -> TMany<const A::Unit*>;

template<Seek = Seek::HereAndAbove>
NOD() TraitList GatherTraits(const Token&);
template<Seek = Seek::HereAndAbove>
NOD() TraitList GatherTraits(const Token&) const;
template<Seek = Seek::HereAndAbove> NOD()
auto GatherTraits(const Token&) -> TraitList;
template<Seek = Seek::HereAndAbove> NOD()
auto GatherTraits(const Token&) const -> TraitList;
#endif
};

Expand Down Expand Up @@ -219,24 +221,24 @@ namespace Langulus::Entity
using SeekInterface::SeekValue;
using SeekInterface::SeekValueAux;

template<Seek = Seek::HereAndAbove>
NOD() A::Unit* SeekUnit(DMeta, Index = 0);
template<Seek = Seek::HereAndAbove>
NOD() A::Unit* SeekUnitAux(const Neat&, DMeta, Index = 0);
template<Seek = Seek::HereAndAbove>
NOD() A::Unit* SeekUnitExt(DMeta, const Neat&, Index = 0);
template<Seek = Seek::HereAndAbove>
NOD() A::Unit* SeekUnitAuxExt(DMeta, const Neat&, const Neat&, Index = 0);
template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnit(DMeta, Index = 0) -> A::Unit*;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnitAux(const Many&, DMeta, Index = 0) -> A::Unit*;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnitExt(DMeta, const Many&, Index = 0) -> A::Unit*;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekUnitAuxExt(DMeta, const Many&, const Many&, Index = 0) -> A::Unit*;

template<Seek = Seek::HereAndAbove>
NOD() Trait SeekTrait(TMeta, Index = 0);
template<Seek = Seek::HereAndAbove>
NOD() Trait SeekTraitAux(const Neat&, TMeta, Index = 0);
template<Seek = Seek::HereAndAbove> NOD()
auto SeekTrait(TMeta, Index = 0) -> Trait;
template<Seek = Seek::HereAndAbove> NOD()
auto SeekTraitAux(const Many&, TMeta, Index = 0) -> Trait;

template<Seek = Seek::HereAndAbove>
bool SeekValue(TMeta, CT::Data auto&, Index = 0) const;
template<Seek = Seek::HereAndAbove>
bool SeekValueAux(TMeta, const Neat&, CT::Data auto&, Index = 0) const;
bool SeekValueAux(TMeta, const Many&, CT::Data auto&, Index = 0) const;

///
/// Gather
Expand All @@ -245,16 +247,16 @@ namespace Langulus::Entity
using SeekInterface::GatherUnitsExt;
using SeekInterface::GatherTraits;

template<Seek = Seek::HereAndAbove>
NOD() TMany<A::Unit*> GatherUnitsExt(DMeta, const Neat&);
template<Seek = Seek::HereAndAbove>
NOD() TMany<A::Unit*> GatherUnits(DMeta);
template<Seek = Seek::HereAndAbove> NOD()
auto GatherUnitsExt(DMeta, const Many&) -> TMany<A::Unit*>;
template<Seek = Seek::HereAndAbove> NOD()
auto GatherUnits(DMeta) -> TMany<A::Unit*>;

template<Seek = Seek::HereAndAbove>
NOD() TraitList GatherTraits(TMeta);
template<Seek = Seek::HereAndAbove> NOD()
auto GatherTraits(TMeta) -> TraitList;

template<CT::Data D, Seek = Seek::HereAndAbove>
NOD() TMany<D> GatherValues() const;
template<CT::Data D, Seek = Seek::HereAndAbove> NOD()
auto GatherValues() const -> TMany<D>;
};

} // namespace Langulus::Entity
24 changes: 10 additions & 14 deletions source/Thing-Seek.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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<Seek SEEK>
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
Expand Down Expand Up @@ -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<Seek SEEK> 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)) {
Expand Down Expand Up @@ -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<Seek SEEK> 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
Expand Down Expand Up @@ -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<Seek SEEK> 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) {
Expand Down Expand Up @@ -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<Seek SEEK>
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);
Expand Down Expand Up @@ -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<Seek SEEK> 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) {
Expand Down Expand Up @@ -264,10 +264,6 @@ namespace Langulus::Entity
else
output = temp.template AsCast<D>();

/*if constexpr (CT::Pinnable<D>)
output = temp.template AsCast<TypeOf<D>>();
else
output = temp.template AsCast<D>();*/
return true;
}
catch (...) { }
Expand Down Expand Up @@ -305,7 +301,7 @@ namespace Langulus::Entity
/// @return true if value has been found and rewritten
template<Seek SEEK> 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<decltype(output)>;

Expand All @@ -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 (...) {}
}
Expand All @@ -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;
});
Expand Down
Loading

0 comments on commit 18b0012

Please sign in to comment.