Skip to content

Commit

Permalink
Added Tag support in hierarchy interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Epixu committed Feb 19, 2024
1 parent 2008f05 commit d0ed509
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 22 deletions.
33 changes: 26 additions & 7 deletions source/Hierarchy-Seek.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#pragma once
#include "Hierarchy.hpp"

#define TEMPLATE() template<class THIS>
#define TME() SeekInterface<THIS>
#define TEMPLATE() template<class THIS>
#define TME() SeekInterface<THIS>


namespace Langulus::Entity
Expand Down Expand Up @@ -164,17 +164,35 @@ namespace Langulus::Entity


TEMPLATE() template<CT::Trait T, Seek SEEK> LANGULUS(INLINED)
bool TME()::SeekValue(CT::Data auto& output, Index offset) const {
bool TME()::SeekValue(CT::NotTagged auto& output, Index offset) const {
return static_cast<const THIS*>(this)
->template SeekValue<SEEK>(MetaTraitOf<T>(), output, offset);
}

TEMPLATE() template<CT::Trait T, Seek SEEK> LANGULUS(INLINED)
bool TME()::SeekValueAux(const Neat& aux, CT::Data auto& output, Index offset) const {
bool TME()::SeekValueAux(const Neat& aux, CT::NotTagged auto& output, Index offset) const {
return static_cast<const THIS*>(this)
->template SeekValueAux<SEEK>(MetaTraitOf<T>(), aux, output, offset);
}



TEMPLATE() template<Seek SEEK> LANGULUS(INLINED)
bool TME()::SeekValue(CT::Tagged auto& output, Index offset) const {
using T = Deref<decltype(output)>;
return static_cast<const THIS*>(this)->template
SeekValue<SEEK>(MetaTraitOf<typename T::TagType>(), output.mData, offset);
}

TEMPLATE() template<Seek SEEK> LANGULUS(INLINED)
bool TME()::SeekValueAux(const Neat& aux, CT::Tagged auto& output, Index offset) const {
using T = Deref<decltype(output)>;
return static_cast<const THIS*>(this)->template
SeekValueAux<SEEK>(MetaTraitOf<typename T::TagType>(), aux, output.mData, offset);
}



#if LANGULUS_FEATURE(MANAGED_REFLECTION)
///
/// Token based interface
Expand Down Expand Up @@ -240,6 +258,7 @@ namespace Langulus::Entity
#undef TEMPLATE
#undef TME


namespace Langulus::Entity
{

Expand Down Expand Up @@ -371,7 +390,7 @@ namespace Langulus::Entity
// Scan descriptor
Trait result;
aux.ForEachDeep([&](const Trait& trait) {
if (trait.TraitIs(meta)) {
if (trait.IsTrait(meta)) {
if (offset == 0) {
// Match found
result = trait;
Expand Down Expand Up @@ -446,7 +465,7 @@ namespace Langulus::Entity
bool done = false;
if (meta) {
aux.ForEachDeep([&](const Trait& trait) -> LoopControl {
if (trait.TraitIs(meta)) {
if (trait.IsTrait(meta)) {
// Found match
try {
if constexpr (CT::DescriptorMakable<D>)
Expand Down Expand Up @@ -483,7 +502,7 @@ namespace Langulus::Entity
--offset;
return not done;
}
catch(...) { }
catch (...) { }

return Loop::Continue;
});
Expand Down
10 changes: 8 additions & 2 deletions source/Hierarchy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,16 @@ namespace Langulus::Entity
template<CT::Trait = Trait, Seek = Seek::HereAndAbove>
NOD() Trait SeekTraitAux(const Neat&, Index = 0) const;


template<CT::Trait = Trait, Seek = Seek::HereAndAbove>
bool SeekValue(CT::Data auto&, Index = IndexFirst) const;
bool SeekValue(CT::NotTagged auto&, Index = IndexFirst) const;
template<CT::Trait = Trait, Seek = Seek::HereAndAbove>
bool SeekValueAux(const Neat&, CT::Data auto&, Index = 0) const;
bool SeekValueAux(const Neat&, 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;


template<Seek = Seek::HereAndAbove>
Expand Down
2 changes: 1 addition & 1 deletion source/Module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Langulus
/// with the currently set RTTI boundary. These types will
/// be unloaded when shared library is unloaded. Unload
/// will be forbidden, if they're still in use.
template<class... T>
template<class...T>
void RegisterTypeList(Entity::MetaList& list) {
// Merge to avoid duplications
(list << ... << MetaOf<T>());
Expand Down
8 changes: 3 additions & 5 deletions source/Pin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Langulus
concept NotPinnable = ((not Pinnable<T>) and ...);

} // namespace Langulus::CT

} // namespace Langulus


Expand All @@ -59,16 +60,13 @@ namespace Langulus::Entity
T mValue;

// Is the pinnable value pinned?
bool mLocked = false;
Traits::State::Tag<bool> mLocked = false;

public:
LANGULUS(ABSTRACT) false;
LANGULUS(TYPED) T;
LANGULUS_BASES(A::Pinnable);

LANGULUS_PROPERTIES_START(Pin)
LANGULUS_PROPERTY_TRAIT(mLocked, State),
LANGULUS_PROPERTIES_END();
LANGULUS_MEMBERS(&Pin::mValue, &Pin::mLocked);

///
/// Construction
Expand Down
2 changes: 1 addition & 1 deletion source/Runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace Langulus::Entity
NOD() bool UnloadSharedLibrary(const SharedLibrary&);

public:
LANGULUS_CONVERSIONS(Text);
LANGULUS_CONVERTS_TO(Text);

Runtime() = delete;
Runtime(Runtime&&) noexcept = default;
Expand Down
4 changes: 2 additions & 2 deletions source/Thing-Seek.inl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ namespace Langulus::Entity
// Scan descriptor
Trait result;
aux.ForEachDeep([&](const Trait& trait) {
if (trait.TraitIs(meta)) {
if (trait.IsTrait(meta)) {
// Found match
result = trait;
return Loop::Break;
Expand Down Expand Up @@ -312,7 +312,7 @@ namespace Langulus::Entity
bool done = false;
if (meta) {
aux.ForEachDeep([&](const Trait& trait) {
if (trait.TraitIs(meta)) {
if (trait.IsTrait(meta)) {
// Found match
try {
if constexpr (CT::Pinnable<D>)
Expand Down
8 changes: 4 additions & 4 deletions source/Thing-Traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,25 @@ namespace Langulus::Entity
Trait Thing::GetTrait(const Trait& id, Index index) {
if (id.GetTrait()) {
// Handle some predefined traits here
if (id.template TraitIs<Traits::Unit>()) {
if (id.template IsTrait<Traits::Unit>()) {
// Get a component
auto unit = GetUnitMeta(DMeta {}, index);
if (unit)
return Traits::Unit {unit};
return {};
}
else if (id.template TraitIs<Traits::Child>()) {
else if (id.template IsTrait<Traits::Child>()) {
// Get a child entity
auto child = GetChild(index);
if (child)
return Traits::Child {child};
return {};
}
else if (id.template TraitIs<Traits::Runtime>()) {
else if (id.template IsTrait<Traits::Runtime>()) {
// Get the nearest runtime
return Traits::Runtime {mRuntime->Get()};
}
else if (id.template TraitIs<Traits::Parent>()) {
else if (id.template IsTrait<Traits::Parent>()) {
// Get the parent
return Traits::Parent {mOwner.Get()};
}
Expand Down
4 changes: 4 additions & 0 deletions source/Thing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ namespace Langulus::Entity
/// It is a placeholder type, that can be extended by external modules
struct Lingua : Text {
LANGULUS(ABSTRACT) true;
LANGULUS_CONVERTS_FROM();

private:
using Text::SerializationRules;
};


Expand Down

0 comments on commit d0ed509

Please sign in to comment.