Skip to content

Commit

Permalink
Serialize Name Keys as Strings for maps
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 committed Nov 13, 2023
1 parent a04f909 commit a770d28
Showing 1 changed file with 64 additions and 19 deletions.
83 changes: 64 additions & 19 deletions src/common/scripting/core/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2541,19 +2541,40 @@ static void PMapValueWriter(FSerializer &ar, const M *map, const PMap *m)
{
TMapConstIterator<typename M::KeyType, typename M::ValueType> it(*map);
const typename M::Pair * p;
while(it.NextPair(p))
if(m->KeyType == TypeName)
{
if constexpr(std::is_same_v<typename M::KeyType,FString>)
while(it.NextPair(p))
{
m->ValueType->WriteValue(ar,p->Key.GetChars(),static_cast<const void *>(&p->Value));
if constexpr(std::is_same_v<typename M::KeyType,uint32_t>)
{
m->ValueType->WriteValue(ar,FName(ENamedName(p->Key)).GetChars(),static_cast<const void *>(&p->Value));
}
else
{
#ifdef __GNUC__
__builtin_unreachable();
#elif defined(_MSC_VER)
__assume(0);
#endif
}
}
else if constexpr(std::is_same_v<typename M::KeyType,uint32_t>)
}
else
{
while(it.NextPair(p))
{
FString key;
key.Format("%u",p->Key);
m->ValueType->WriteValue(ar,key.GetChars(),static_cast<const void *>(&p->Value));
if constexpr(std::is_same_v<typename M::KeyType,FString>)
{
m->ValueType->WriteValue(ar,p->Key.GetChars(),static_cast<const void *>(&p->Value));
}
else if constexpr(std::is_same_v<typename M::KeyType,uint32_t>)
{
FString key;
key.Format("%u",p->Key);
m->ValueType->WriteValue(ar,key.GetChars(),static_cast<const void *>(&p->Value));
}
//else unknown key type
}
//else unknown key type
}
}

Expand Down Expand Up @@ -2582,29 +2603,53 @@ template<typename M>
static bool PMapValueReader(FSerializer &ar, M *map, const PMap *m)
{
const char * k;
while((k = ar.GetKey()))
if(m->KeyType == TypeName)
{
typename M::ValueType * val;
if constexpr(std::is_same_v<typename M::KeyType,FString>)
if constexpr(std::is_same_v<typename M::KeyType,uint32_t>)
{
val = &map->InsertNew(k);
val = &map->InsertNew(FName(k).GetIndex());

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Debug

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Debug

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Debug

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Debug

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Debug

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Debug

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Debug

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2022 | Debug

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2019 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2019 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2019 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2019 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2019 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2019 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2019 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]

Check warning on line 2611 in src/common/scripting/core/types.cpp

View workflow job for this annotation

GitHub Actions / Visual Studio 2019 | Release

uninitialized local variable 'k' used [D:\a\gzdoom\gzdoom\build\src\zdoom.vcxproj]
}
else if constexpr(std::is_same_v<typename M::KeyType,uint32_t>)
else
{
FString s(k);
if(!s.IsInt())
{
ar.EndObject();
return false;
}
val = &map->InsertNew(static_cast<uint32_t>(s.ToULong()));
#ifdef __GNUC__
__builtin_unreachable();
#elif defined(_MSC_VER)
__assume(0);
#endif
}
if (!m->ValueType->ReadValue(ar,nullptr,static_cast<void*>(val)))
{
ar.EndObject();
return false;
}
}
else
{
while((k = ar.GetKey()))
{
typename M::ValueType * val;
if constexpr(std::is_same_v<typename M::KeyType,FString>)
{
val = &map->InsertNew(k);
}
else if constexpr(std::is_same_v<typename M::KeyType,uint32_t>)
{
FString s(k);
if(!s.IsInt())
{
ar.EndObject();
return false;
}
val = &map->InsertNew(static_cast<uint32_t>(s.ToULong()));
}
if (!m->ValueType->ReadValue(ar,nullptr,static_cast<void*>(val)))
{
ar.EndObject();
return false;
}
}
}
ar.EndObject();
return true;
}
Expand Down

0 comments on commit a770d28

Please sign in to comment.