diff options
Diffstat (limited to 'source/core/slang-rtti-info.cpp')
| -rw-r--r-- | source/core/slang-rtti-info.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/source/core/slang-rtti-info.cpp b/source/core/slang-rtti-info.cpp index 043e6490a..c35444d03 100644 --- a/source/core/slang-rtti-info.cpp +++ b/source/core/slang-rtti-info.cpp @@ -2,6 +2,8 @@ #include "../../slang-com-helper.h" +#include "slang-rtti-util.h" + #include <mutex> namespace Slang { @@ -191,4 +193,35 @@ StructRttiInfo StructRttiBuilder::make() return m_rttiInfo; } +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RttiTypeFuncsMap !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +RttiTypeFuncs RttiTypeFuncsMap::getFuncsForType(const RttiInfo* rttiInfo) +{ + if (auto funcsPtr = m_map.TryGetValue(rttiInfo)) + { + return *funcsPtr; + } + + // Try to get the default impl + // NOTE! funcs could be invalid if there is no default impl. + const auto funcs = RttiUtil::getDefaultTypeFuncs(rttiInfo); + + // Add to the map + m_map.Add(rttiInfo, funcs); + return funcs; +} + +void RttiTypeFuncsMap::add(const RttiInfo* rttiInfo, const RttiTypeFuncs& funcs) +{ + if (auto funcsPtr = m_map.TryGetValueOrAdd(rttiInfo, funcs)) + { + // If there are funcs set, they aren't valid otherwise this would be + // replacing, so assert on that scenario. + SLANG_ASSERT(!funcsPtr->isValid()); + + // Replace the funcs + *funcsPtr = funcs; + } +} + } // namespace Slang |
