blob: 6b7644bf2c68053f6bdd400e96f60ef2899f775c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// slang-castable.cpp
#include "slang-castable.h"
namespace Slang {
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CastableUtil !!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* static */ComPtr<ICastable> CastableUtil::getCastable(ISlangUnknown* unk)
{
SLANG_ASSERT(unk);
ComPtr<ICastable> castable;
if (SLANG_SUCCEEDED(unk->queryInterface(SLANG_IID_PPV_ARGS(castable.writeRef()))))
{
SLANG_ASSERT(castable);
}
else
{
castable = new UnknownCastableAdapter(unk);
}
return castable;
}
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ObjectCastableAdapter !!!!!!!!!!!!!!!!!!!!!!!!!!! */
void* ObjectCastableAdapter::castAs(const Guid& guid)
{
if (auto intf = getInterface(guid))
{
return intf;
}
return getObject(guid);
}
void* ObjectCastableAdapter::getInterface(const Guid& guid)
{
if (guid == ISlangUnknown::getTypeGuid() ||
guid == ICastable::getTypeGuid() ||
guid == IObjectCastableAdapter::getTypeGuid())
{
return static_cast<IObjectCastableAdapter*>(this);
}
return nullptr;
}
void* ObjectCastableAdapter::getObject(const Guid& guid)
{
if (guid == m_containedGuid)
{
return m_contained;
}
return nullptr;
}
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 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
|