diff options
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-castable-list-impl.cpp | 80 | ||||
| -rw-r--r-- | source/core/slang-castable-list-impl.h | 47 | ||||
| -rw-r--r-- | source/core/slang-castable-util.cpp | 70 | ||||
| -rw-r--r-- | source/core/slang-castable-util.h | 58 | ||||
| -rw-r--r-- | source/core/slang-platform.h | 4 | ||||
| -rw-r--r-- | source/core/slang-semantic-version.cpp | 10 | ||||
| -rw-r--r-- | source/core/slang-semantic-version.h | 21 |
7 files changed, 155 insertions, 135 deletions
diff --git a/source/core/slang-castable-list-impl.cpp b/source/core/slang-castable-list-impl.cpp index dcc58e37b..1cc5dc2d4 100644 --- a/source/core/slang-castable-list-impl.cpp +++ b/source/core/slang-castable-list-impl.cpp @@ -1,71 +1,9 @@ // slang-castable-list-impl.cpp #include "slang-castable-list-impl.h" -namespace Slang { - -/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CastableUtil !!!!!!!!!!!!!!!!!!!!!!!!!!! */ +#include "slang-castable-util.h" -/* static */ComPtr<ICastable> CastableUtil::getCastable(ISlangUnknown* unk) -{ - SLANG_ASSERT(unk); - ComPtr<ICastable> castable; - if (SLANG_SUCCEEDED(unk->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef()))) - { - SLANG_ASSERT(castable); - } - else - { - castable = new UnknownCastableAdapter(unk); - } - return castable; -} - -/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UnknownCastableAdapter !!!!!!!!!!!!!!!!!!!!!!!!!!! */ - -void* UnknownCastableAdapter::castAs(const Guid& guid) -{ - if (auto intf = getInterface(guid)) - { - return intf; - } - if (auto obj = getObject(guid)) - { - return obj; - } - - if (m_found && guid == m_foundGuid) - { - return m_found; - } - - ComPtr<ISlangUnknown> cast; - if (SLANG_SUCCEEDED(m_contained->queryInterface(guid, (void**)cast.writeRef())) && cast) - { - // Save the interface in the cache - m_found = cast; - m_foundGuid = guid; - - return cast; - } - return nullptr; -} - -void* UnknownCastableAdapter::getInterface(const Guid& guid) -{ - if (guid == ISlangUnknown::getTypeGuid() || - guid == ICastable::getTypeGuid() || - guid == IUnknownCastableAdapter::getTypeGuid()) - { - return static_cast<IUnknownCastableAdapter*>(this); - } - return nullptr; -} - -void* UnknownCastableAdapter::getObject(const Guid& guid) -{ - SLANG_UNUSED(guid); - return nullptr; -} +namespace Slang { /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CastableList !!!!!!!!!!!!!!!!!!!!!!!!!!! */ @@ -166,18 +104,7 @@ void CastableList::clear() void CastableList::addUnknown(ISlangUnknown* unk) { - // If it has ICastable interface we can just add as that - { - ComPtr<ICastable> castable; - if (SLANG_SUCCEEDED(unk->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef())) && castable) - { - return add(castable); - } - } - - // Wrap it in an adapter - IUnknownCastableAdapter* adapter = new UnknownCastableAdapter(unk); - add(adapter); + add(CastableUtil::getCastable(unk)); } Index CastableList::indexOfUnknown(ISlangUnknown* unk) @@ -202,6 +129,7 @@ Index CastableList::indexOfUnknown(ISlangUnknown* unk) return i; } } + return -1; } diff --git a/source/core/slang-castable-list-impl.h b/source/core/slang-castable-list-impl.h index 2ce124ce7..7a7f98a6a 100644 --- a/source/core/slang-castable-list-impl.h +++ b/source/core/slang-castable-list-impl.h @@ -1,4 +1,4 @@ -// slang-castable-list.h +// slang-castable-list-impl.h #ifndef SLANG_CASTABLE_LIST_IMPL_H #define SLANG_CASTABLE_LIST_IMPL_H @@ -12,42 +12,8 @@ namespace Slang { -/* An adapter such that types which aren't derived from ICastable, can be used as such. - -With the following caveats. -* the interfaces/objects of the adapter are checked *first*, so IUnknown will always be for the adapter -* assumes when doing a queryInterface on the contained item, it will remain in scope when released (this is *not* strict COM) -*/ -class UnknownCastableAdapter : public ComBaseObject, public IUnknownCastableAdapter -{ -public: - SLANG_COM_BASE_IUNKNOWN_ALL - - // ICastable - SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE; - - // IUnknownCastableAdapter - virtual SLANG_NO_THROW ISlangUnknown* SLANG_MCALL getContained() SLANG_OVERRIDE { return m_contained; } - - UnknownCastableAdapter(ISlangUnknown* unk): - m_contained(unk) - { - SLANG_ASSERT(unk); - } - -protected: - void* getInterface(const Guid& guid); - void* getObject(const Guid& guid); - - ComPtr<ISlangUnknown> m_contained; - - // We hold a cache for a single lookup to make things a little faster - void* m_found = nullptr; - Guid m_foundGuid; -}; - /* Implementation of the ICastableList interface. -Is atomic reference counted*/ +Is atomic reference counted */ class CastableList : public ComBaseObject, public ICastableList { public: @@ -72,17 +38,12 @@ public: /// Dtor virtual ~CastableList(); -protected: void* getInterface(const Guid& guid); void* getObject(const Guid& guid); - List<ICastable*> m_list; -}; +protected: -struct CastableUtil -{ - /// Given an unk return as an unk - static ComPtr<ICastable> getCastable(ISlangUnknown* unk); + List<ICastable*> m_list; }; } // namespace Slang diff --git a/source/core/slang-castable-util.cpp b/source/core/slang-castable-util.cpp new file mode 100644 index 000000000..408e36cb3 --- /dev/null +++ b/source/core/slang-castable-util.cpp @@ -0,0 +1,70 @@ +// slang-castable-util.cpp +#include "slang-castable-util.h" + +namespace Slang { + +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CastableUtil !!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +/* static */ComPtr<ICastable> CastableUtil::getCastable(ISlangUnknown* unk) +{ + SLANG_ASSERT(unk); + ComPtr<ICastable> castable; + if (SLANG_SUCCEEDED(unk->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef()))) + { + SLANG_ASSERT(castable); + } + else + { + castable = new UnknownCastableAdapter(unk); + } + return castable; +} + +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UnknownCastableAdapter !!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +void* UnknownCastableAdapter::castAs(const Guid& guid) +{ + if (auto intf = getInterface(guid)) + { + return intf; + } + if (auto obj = getObject(guid)) + { + return obj; + } + + if (m_found && guid == m_foundGuid) + { + return m_found; + } + + ComPtr<ISlangUnknown> cast; + if (SLANG_SUCCEEDED(m_contained->queryInterface(guid, (void**)cast.writeRef())) && cast) + { + // Save the interface in the cache + m_found = cast; + m_foundGuid = guid; + + return cast; + } + return nullptr; +} + +void* UnknownCastableAdapter::getInterface(const Guid& guid) +{ + if (guid == ISlangUnknown::getTypeGuid() || + guid == ICastable::getTypeGuid() || + guid == IUnknownCastableAdapter::getTypeGuid()) + { + return static_cast<IUnknownCastableAdapter*>(this); + } + return nullptr; +} + +void* UnknownCastableAdapter::getObject(const Guid& guid) +{ + SLANG_UNUSED(guid); + return nullptr; +} + +} // namespace Slang diff --git a/source/core/slang-castable-util.h b/source/core/slang-castable-util.h new file mode 100644 index 000000000..4d3c3900c --- /dev/null +++ b/source/core/slang-castable-util.h @@ -0,0 +1,58 @@ +// slang-castable-util.h +#ifndef SLANG_CASTABLE_UTIL_H +#define SLANG_CASTABLE_UTIL_H + +#include "slang-castable-list.h" + +#include "../../slang-com-helper.h" +#include "../../slang-com-ptr.h" + +#include "../core/slang-com-object.h" + +namespace Slang +{ + +/* An adapter such that types which aren't derived from ICastable, can be used as such. + +With the following caveats. +* the interfaces/objects of the adapter are checked *first*, so IUnknown will always be for the adapter +* assumes when doing a queryInterface on the contained item, it will remain in scope when released (this is *not* strict COM) +*/ +class UnknownCastableAdapter : public ComBaseObject, public IUnknownCastableAdapter +{ +public: + SLANG_COM_BASE_IUNKNOWN_ALL + + // ICastable + SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE; + + // IUnknownCastableAdapter + virtual SLANG_NO_THROW ISlangUnknown* SLANG_MCALL getContained() SLANG_OVERRIDE { return m_contained; } + + UnknownCastableAdapter(ISlangUnknown* unk): + m_contained(unk) + { + SLANG_ASSERT(unk); + } + +protected: + void* getInterface(const Guid& guid); + void* getObject(const Guid& guid); + + ComPtr<ISlangUnknown> m_contained; + + // We hold a cache for a single lookup to make things a little faster + void* m_found = nullptr; + Guid m_foundGuid; +}; + +struct CastableUtil +{ + /// Given an ISlangUnkown return as a castable interface. + /// Can use UnknownCastableAdapter if can't queryInterface unk to ICastable + static ComPtr<ICastable> getCastable(ISlangUnknown* unk); +}; + +} // namespace Slang + +#endif diff --git a/source/core/slang-platform.h b/source/core/slang-platform.h index ff7f1ccd9..c8bea747f 100644 --- a/source/core/slang-platform.h +++ b/source/core/slang-platform.h @@ -7,7 +7,7 @@ namespace Slang { - enum class PlatformKind + enum class PlatformKind : uint8_t { Unknown, WinRT, @@ -48,7 +48,7 @@ namespace Slang }; }; - enum class PlatformFamily + enum class PlatformFamily : uint8_t { Unknown, Windows, diff --git a/source/core/slang-semantic-version.cpp b/source/core/slang-semantic-version.cpp index cc631d292..550ea993b 100644 --- a/source/core/slang-semantic-version.cpp +++ b/source/core/slang-semantic-version.cpp @@ -26,16 +26,16 @@ SlangResult SemanticVersion::parse(const UnownedStringSlice& value, char separat { SLANG_RETURN_ON_FAIL(StringUtil::parseInt(slices[i], ints[i])); - const Int max = (i == 0) ? 0x7fffffff : 0xffff; + const Int max = (i == 2) ? 0x7fffffff : 0xffff; if (ints[i] < 0 || ints[i] > max) { return SLANG_FAIL; } } - outVersion.m_major = uint32_t(ints[0]); + outVersion.m_major = uint16_t(ints[0]); outVersion.m_minor = uint16_t(ints[1]); - outVersion.m_patch = uint16_t(ints[2]); + outVersion.m_patch = uint32_t(ints[2]); return SLANG_OK; } @@ -50,7 +50,7 @@ void SemanticVersion::append(StringBuilder& buf) const buf << Int32(m_major) << "." << Int32(m_minor); if (m_patch != 0) { - buf << "." << Int32(m_patch); + buf << "." << UInt32(m_patch); } } @@ -90,8 +90,6 @@ void SemanticVersion::append(StringBuilder& buf) const return bestVersion; } - - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MatchSemanticVersion !!!!!!!!!!!!!!!!!!!!!!!!!!!!! /* static */SemanticVersion MatchSemanticVersion::findAnyBest(const SemanticVersion* versions, Count count, const ThisType& matchVersion) diff --git a/source/core/slang-semantic-version.h b/source/core/slang-semantic-version.h index 4d64627c2..e7f10eeed 100644 --- a/source/core/slang-semantic-version.h +++ b/source/core/slang-semantic-version.h @@ -3,6 +3,7 @@ #define SLANG_SEMANTIC_VERSION_H #include "../core/slang-basic.h" +#include "../core/slang-hash.h" namespace Slang { @@ -14,10 +15,11 @@ struct SemanticVersion typedef uint64_t IntegerType; SemanticVersion():m_major(0), m_minor(0), m_patch(0) {} + SemanticVersion(int inMajor, int inMinor = 0, int inPatch = 0): - m_major(uint32_t(inMajor)), + m_major(uint16_t(inMajor)), m_minor(uint16_t(inMinor)), - m_patch(uint16_t(inPatch)) + m_patch(uint32_t(inPatch)) {} void reset() @@ -30,20 +32,23 @@ struct SemanticVersion /// All zeros means nothing is set bool isSet() const { return m_major || m_minor || m_patch; } - IntegerType toInteger() const { return (IntegerType(m_major) << 32) | (uint32_t(m_minor) << 16) | m_patch; } + IntegerType toInteger() const { return (IntegerType(m_major) << 48) | (IntegerType(m_minor) << 32) | m_patch; } void setFromInteger(IntegerType v) { - set(int(v >> 32), int((v >> 16) & 0xffff), int(v & 0xffff)); + set(int(v >> 48), int((v >> 32) & 0xffff), int(v & 0xffffffff)); } void set(int major, int minor, int patch = 0) { SLANG_ASSERT(major >= 0 && minor >=0 && patch >= 0); - m_major = uint32_t(major); + m_major = uint16_t(major); m_minor = uint16_t(minor); - m_patch = uint16_t(patch); + m_patch = uint32_t(patch); } + /// Get hash value + HashCode getHashCode() const { return Slang::getHashCode(toInteger()); } + static SlangResult parse(const UnownedStringSlice& value, SemanticVersion& outVersion); static SlangResult parse(const UnownedStringSlice& value, char separatorChar, SemanticVersion& outVersion); @@ -61,9 +66,9 @@ struct SemanticVersion bool operator==(const ThisType& rhs) const { return toInteger() == rhs.toInteger(); } bool operator!=(const ThisType& rhs) const { return toInteger() != rhs.toInteger(); } - uint32_t m_major; + uint16_t m_major; uint16_t m_minor; - uint16_t m_patch; + uint32_t m_patch; ///< Patch number. Can actually be quite large for some code bases. }; /* Adds to the semantic versioning information for an incomplete version that can be matched */ |
