From 20ea33f3321738e7c1b4cad7bdcaedcdb54dd0f0 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 11 Apr 2023 10:18:18 -0400 Subject: Artifact simplification (#2781) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP simplifying artifact interface. * Use ContainedKind. * Remove LazyCastableList. Use ContainedKind for find. * Remove ICastableList. * Remove need for ICastableList. * Remove IArtifactContainer. * Small fixes. * Small improvements around Artifact. * Make explicit find is for *representations* that can cast. Fix bug in handling casting in lookup. * Made associated items artifacts too. * Small fixes. * Small improvements around writing a container. --- source/core/slang-castable-list-impl.cpp | 136 ------------------------------- 1 file changed, 136 deletions(-) delete mode 100644 source/core/slang-castable-list-impl.cpp (limited to 'source/core/slang-castable-list-impl.cpp') diff --git a/source/core/slang-castable-list-impl.cpp b/source/core/slang-castable-list-impl.cpp deleted file mode 100644 index 4f4b07790..000000000 --- a/source/core/slang-castable-list-impl.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// slang-castable-list-impl.cpp -#include "slang-castable-list-impl.h" - -#include "slang-castable-util.h" - -namespace Slang { - -/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CastableList !!!!!!!!!!!!!!!!!!!!!!!!!!! */ - -CastableList::~CastableList() -{ - for (auto castable : m_list) - { - castable->release(); - } -} - -void* CastableList::castAs(const Guid& guid) -{ - if (auto intf = getInterface(guid)) - { - return intf; - } - return getObject(guid); -} - -void* CastableList::getInterface(const Guid& guid) -{ - if (guid == ISlangUnknown::getTypeGuid() || - guid == ICastable::getTypeGuid() || - guid == ICastableList::getTypeGuid()) - { - return static_cast(this); - } - return nullptr; -} - -void* CastableList::getObject(const Guid& guid) -{ - SLANG_UNUSED(guid); - return nullptr; -} - -void* CastableList::find(const Guid& guid) -{ - for (ICastable* castable : m_list) - { - if (auto ptr = castable->castAs(guid)) - { - return ptr; - } - } - return nullptr; -} - -ICastable* SLANG_MCALL CastableList::findWithPredicate(FindFunc func, void* data) -{ - for (ICastable* castable : m_list) - { - if (func(castable, data)) - { - return castable; - } - } - return nullptr; -} - -Index CastableList::indexOf(ICastable* castable) -{ - const Count count = m_list.getCount(); - for (Index i = 0; i < count; ++i) - { - ICastable* cur = m_list[i]; - if (cur == castable) - { - return i; - } - } - return -1; -} - -void CastableList::add(ICastable* castable) -{ - SLANG_ASSERT(castable); - castable->addRef(); - m_list.add(castable); -} - -void CastableList::removeAt(Index i) -{ - auto castable = m_list[i]; - m_list.removeAt(i); - castable->release(); -} - -void CastableList::clear() -{ - for (auto castable : m_list) - { - castable->release(); - } - m_list.clear(); -} - -void CastableList::addUnknown(ISlangUnknown* unk) -{ - add(CastableUtil::getCastable(unk)); -} - -Index CastableList::indexOfUnknown(ISlangUnknown* unk) -{ - SLANG_ASSERT(unk); - // If it has a castable interface we can just look for that - { - ComPtr castable; - if (SLANG_SUCCEEDED(unk->queryInterface(SLANG_IID_PPV_ARGS(castable.writeRef()))) && castable) - { - return indexOf(castable); - } - } - - // It's not derived from ICastable, so can only be in list via an adapter - const Count count = m_list.getCount(); - for (Index i = 0; i < count; ++i) - { - auto adapter = as(m_list[i]); - if (adapter && adapter->getContained() == unk) - { - return i; - } - } - - return -1; -} - -} // namespace Slang -- cgit v1.2.3