diff options
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-blob.h | 7 | ||||
| -rw-r--r-- | source/core/slang-castable-list-impl.cpp | 17 | ||||
| -rw-r--r-- | source/core/slang-castable-list-impl.h | 1 | ||||
| -rw-r--r-- | source/core/slang-castable-list.h | 13 | ||||
| -rw-r--r-- | source/core/slang-lazy-castable-list.cpp | 14 | ||||
| -rw-r--r-- | source/core/slang-lazy-castable-list.h | 2 | ||||
| -rw-r--r-- | source/core/slang-shared-library.cpp | 14 | ||||
| -rw-r--r-- | source/core/slang-shared-library.h | 18 | ||||
| -rw-r--r-- | source/core/slang-smart-pointer.h | 7 | ||||
| -rw-r--r-- | source/core/slang-string.h | 5 |
10 files changed, 93 insertions, 5 deletions
diff --git a/source/core/slang-blob.h b/source/core/slang-blob.h index b1384bb2c..8a9ab5dea 100644 --- a/source/core/slang-blob.h +++ b/source/core/slang-blob.h @@ -45,11 +45,18 @@ public: SLANG_NO_THROW size_t SLANG_MCALL getBufferSize() SLANG_OVERRIDE { return m_string.getLength(); } static ComPtr<ISlangBlob> create(const String& in) { return ComPtr<ISlangBlob>(new StringBlob(in)); } + static ComPtr<ISlangBlob> moveCreate(String& in) + { + auto blob = new StringBlob; + blob->m_string.swapWith(in); + return ComPtr<ISlangBlob>(blob); + } protected: explicit StringBlob(String const& string) : m_string(string) {} + StringBlob() {} /// Get the contained string SLANG_FORCE_INLINE const String& getString() const { return m_string; } diff --git a/source/core/slang-castable-list-impl.cpp b/source/core/slang-castable-list-impl.cpp index ee10ea995..56f8c7cae 100644 --- a/source/core/slang-castable-list-impl.cpp +++ b/source/core/slang-castable-list-impl.cpp @@ -36,9 +36,10 @@ void* UnknownCastableAdapter::castAs(const Guid& guid) void* UnknownCastableAdapter::getInterface(const Guid& guid) { if (guid == ISlangUnknown::getTypeGuid() || - guid == ICastable::getTypeGuid()) + guid == ICastable::getTypeGuid() || + guid == IUnknownCastableAdapter::getTypeGuid()) { - return static_cast<ICastable*>(this); + return static_cast<IUnknownCastableAdapter*>(this); } return nullptr; } @@ -97,6 +98,18 @@ void* CastableList::find(const Guid& guid) 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(); diff --git a/source/core/slang-castable-list-impl.h b/source/core/slang-castable-list-impl.h index 6c03855f2..b578e8de4 100644 --- a/source/core/slang-castable-list-impl.h +++ b/source/core/slang-castable-list-impl.h @@ -66,6 +66,7 @@ public: virtual Index SLANG_MCALL indexOf(ICastable* castable) SLANG_OVERRIDE; virtual Index SLANG_MCALL indexOfUnknown(ISlangUnknown* unk) SLANG_OVERRIDE; virtual void* SLANG_MCALL find(const Guid& guid) SLANG_OVERRIDE; + virtual ICastable* SLANG_MCALL findWithPredicate(FindFunc func, void* data) SLANG_OVERRIDE; virtual ICastable*const* SLANG_MCALL getBuffer() SLANG_OVERRIDE { return m_list.getBuffer(); } /// Dtor diff --git a/source/core/slang-castable-list.h b/source/core/slang-castable-list.h index 942f53376..b9c98d65a 100644 --- a/source/core/slang-castable-list.h +++ b/source/core/slang-castable-list.h @@ -9,11 +9,14 @@ namespace Slang { + /* A useful interface for handling lists of castable interfaces. Cannot hold nullptr */ class ICastableList : public ICastable { SLANG_COM_INTERFACE(0x335f3d40, 0x934c, 0x40dc, { 0xb5, 0xe1, 0xf7, 0x6e, 0x40, 0x3, 0x62, 0x5 }) - + + typedef bool (*FindFunc)(ICastable* castable, void* data); + /// Get the count of all interfaces held in the list virtual Count SLANG_MCALL getCount() = 0; /// Get the interface at the specified index @@ -32,6 +35,8 @@ class ICastableList : public ICastable virtual Index SLANG_MCALL indexOfUnknown(ISlangUnknown* unk) = 0; /// Find the first item that casts to non null virtual void* SLANG_MCALL find(const Guid& guid) = 0; + /// Find the fast castable that matches the predicate + virtual ICastable* SLANG_MCALL findWithPredicate(FindFunc func, void* data) = 0; /// Access the internal buffer (any mutation can invalidate this value) virtual ICastable*const* SLANG_MCALL getBuffer() = 0; }; @@ -43,6 +48,12 @@ SLANG_FORCE_INLINE T* find(ICastableList* list) return reinterpret_cast<T*>(list->find(T::getTypeGuid())); } +template <typename T> +SLANG_FORCE_INLINE T* find(ICastableList* list, ICastableList::FindFunc func, void* data) +{ + return reinterpret_cast<T*>(list->findWithPredicate(T::getTypeGuid(), func, data)); +} + /* Adapter interface to make a non castable types work as ICastable */ class IUnknownCastableAdapter : public ICastable { diff --git a/source/core/slang-lazy-castable-list.cpp b/source/core/slang-lazy-castable-list.cpp index d9f0090d5..1832a67f4 100644 --- a/source/core/slang-lazy-castable-list.cpp +++ b/source/core/slang-lazy-castable-list.cpp @@ -112,7 +112,19 @@ void* LazyCastableList::find(const Guid& guid) } return nullptr; } - + +ICastable* LazyCastableList::findWithPredicate(ICastableList::FindFunc func, void* data) +{ + for (auto castable : getView()) + { + if (func(castable, data)) + { + return castable; + } + } + return nullptr; +} + ConstArrayView<ICastable*> LazyCastableList::getView() const { switch (m_state) diff --git a/source/core/slang-lazy-castable-list.h b/source/core/slang-lazy-castable-list.h index 4f73ce9ca..84bfd8c6d 100644 --- a/source/core/slang-lazy-castable-list.h +++ b/source/core/slang-lazy-castable-list.h @@ -35,6 +35,8 @@ public: void clearAndDeallocate(); /// Find the first item that castAs(guid) produces a result void* find(const Guid& guid); + /// Find first match using predicate function + ICastable* findWithPredicate(ICastableList::FindFunc func, void* data); /// Get the contents of the list as a view ConstArrayView<ICastable*> getView() const; /// Get the index of castable in the list. Returns -1 if not found diff --git a/source/core/slang-shared-library.cpp b/source/core/slang-shared-library.cpp index 0e4f0ee73..35440ac9e 100644 --- a/source/core/slang-shared-library.cpp +++ b/source/core/slang-shared-library.cpp @@ -33,7 +33,7 @@ SlangResult DefaultSharedLibraryLoader::loadSharedLibrary(const char* path, ISla { *outSharedLibrary = nullptr; // Try loading - SharedLibrary::Handle handle = nullptr; + SharedLibrary::Handle handle; SLANG_RETURN_ON_FAIL(SharedLibrary::load(path, handle)); *outSharedLibrary = ComPtr<ISlangSharedLibrary>(new DefaultSharedLibrary(handle)).detach(); return SLANG_OK; @@ -74,6 +74,18 @@ TemporarySharedLibrary::~TemporarySharedLibrary() } } +/* !!!!!!!!!!!!!!!!!!!!!!!!!! ScopeSharedLibrary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ + +ScopeSharedLibrary::~ScopeSharedLibrary() +{ + if (m_sharedLibraryHandle) + { + // We have to unload if we want to be able to remove + SharedLibrary::unload(m_sharedLibraryHandle); + m_sharedLibraryHandle = nullptr; + } +} + /* !!!!!!!!!!!!!!!!!!!!!!!!!! DefaultSharedLibrary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ DefaultSharedLibrary::~DefaultSharedLibrary() diff --git a/source/core/slang-shared-library.h b/source/core/slang-shared-library.h index c0074bad3..0a63e570e 100644 --- a/source/core/slang-shared-library.h +++ b/source/core/slang-shared-library.h @@ -100,6 +100,24 @@ protected: String m_path; }; +class ScopeSharedLibrary : public DefaultSharedLibrary +{ +public: + typedef DefaultSharedLibrary Super; + + /// Ctor + ScopeSharedLibrary(const SharedLibrary::Handle sharedLibraryHandle, ISlangUnknown* scope) : + Super(sharedLibraryHandle), + m_scope(scope) + { + } + + virtual ~ScopeSharedLibrary(); + +protected: + ComPtr<ISlangUnknown> m_scope; +}; + class SharedLibraryUtils { public: diff --git a/source/core/slang-smart-pointer.h b/source/core/slang-smart-pointer.h index 45083c1eb..75c4398a5 100644 --- a/source/core/slang-smart-pointer.h +++ b/source/core/slang-smart-pointer.h @@ -236,6 +236,13 @@ namespace Slang return rs; } + void swapWith(RefPtr<T>& rhs) + { + auto rhsPtr = rhs.pointer; + rhs.pointer = pointer; + pointer = rhsPtr; + } + SLANG_FORCE_INLINE void setNull() { releaseReference(pointer); diff --git a/source/core/slang-string.h b/source/core/slang-string.h index 69ca7e2c3..028eec3e4 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -765,6 +765,11 @@ namespace Slang return indexOf(str.begin(), 0); } + void swapWith(String& other) + { + m_buffer.swapWith(other.m_buffer); + } + Index indexOf(char ch, Index id) const { const Index length = getLength(); |
