UESaveFile/Serialisers: make types() return an ArrayView of Strings.

It's the best way to avoid dangling views for now.
This commit is contained in:
Guillaume Jacquemin 2022-03-06 14:29:09 +01:00
parent fdb7567aea
commit 88afaaceec
16 changed files with 27 additions and 30 deletions

View file

@ -238,10 +238,8 @@ auto PropertySerialiser::writeSet(Containers::ArrayView<UnrealPropertyBase::ptr>
} }
auto PropertySerialiser::getSerialiser(Containers::StringView item_type) -> AbstractUnrealPropertySerialiser* { auto PropertySerialiser::getSerialiser(Containers::StringView item_type) -> AbstractUnrealPropertySerialiser* {
!Utility::Debug{};
for(auto& item : _serialisers) { for(auto& item : _serialisers) {
for(auto serialiser_type : item->types()) { for(auto serialiser_type : item->types()) {
Utility::Debug{} << serialiser_type;
if(item_type == serialiser_type) { if(item_type == serialiser_type) {
return item.get(); return item.get();
} }

View file

@ -38,7 +38,7 @@ class AbstractUnrealCollectionPropertySerialiser {
virtual ~AbstractUnrealCollectionPropertySerialiser() = default; virtual ~AbstractUnrealCollectionPropertySerialiser() = default;
virtual auto types() -> Containers::ArrayView<const Containers::StringView> = 0; virtual auto types() -> Containers::ArrayView<const Containers::String> = 0;
virtual auto deserialise(Containers::StringView name, Containers::StringView type, virtual auto deserialise(Containers::StringView name, Containers::StringView type,
UnsignedLong value_length, UnsignedInt count, BinaryReader& reader, UnsignedLong value_length, UnsignedInt count, BinaryReader& reader,

View file

@ -37,7 +37,7 @@ class AbstractUnrealPropertySerialiser {
virtual ~AbstractUnrealPropertySerialiser() = default; virtual ~AbstractUnrealPropertySerialiser() = default;
virtual auto types() -> Containers::ArrayView<const Containers::StringView> = 0; virtual auto types() -> Containers::ArrayView<const Containers::String> = 0;
virtual auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, virtual auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr = 0; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr = 0;

View file

@ -19,9 +19,9 @@
#include "BoolPropertySerialiser.h" #include "BoolPropertySerialiser.h"
auto BoolPropertySerialiser::types() -> Containers::ArrayView<const Containers::StringView> { auto BoolPropertySerialiser::types() -> Containers::ArrayView<const Containers::String> {
using namespace Containers::Literals; using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit, {"BoolProperty"_s}}; static const Containers::Array<Containers::String> types{InPlaceInit, {"BoolProperty"_s}};
return types; return types;
} }

View file

@ -29,7 +29,7 @@ class BoolPropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<BoolPropertySerialiser>; using ptr = Containers::Pointer<BoolPropertySerialiser>;
auto types() -> Containers::ArrayView<const Containers::StringView> override; auto types() -> Containers::ArrayView<const Containers::String> override;
auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;

View file

@ -19,9 +19,9 @@
#include "BytePropertySerialiser.h" #include "BytePropertySerialiser.h"
auto BytePropertySerialiser::types() -> Containers::ArrayView<const Containers::StringView> { auto BytePropertySerialiser::types() -> Containers::ArrayView<const Containers::String> {
using namespace Containers::Literals; using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit, {"ByteProperty"_s}}; static const Containers::Array<Containers::String> types{InPlaceInit, {"ByteProperty"_s}};
return types; return types;
} }

View file

@ -27,7 +27,7 @@ class BytePropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<BytePropertySerialiser>; using ptr = Containers::Pointer<BytePropertySerialiser>;
auto types() -> Containers::ArrayView<const Containers::StringView> override; auto types() -> Containers::ArrayView<const Containers::String> override;
auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;

View file

@ -19,9 +19,9 @@
#include "EnumPropertySerialiser.h" #include "EnumPropertySerialiser.h"
auto EnumPropertySerialiser::types() -> Containers::ArrayView<const Containers::StringView> { auto EnumPropertySerialiser::types() -> Containers::ArrayView<const Containers::String> {
using namespace Containers::Literals; using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit, {"EnumProperty"_s}}; static const Containers::Array<Containers::String> types{InPlaceInit, {"EnumProperty"_s}};
return types; return types;
} }

View file

@ -27,7 +27,7 @@ class EnumPropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<EnumPropertySerialiser>; using ptr = Containers::Pointer<EnumPropertySerialiser>;
auto types() -> Containers::ArrayView<const Containers::StringView> override; auto types() -> Containers::ArrayView<const Containers::String> override;
auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;

View file

@ -19,10 +19,9 @@
#include "FloatPropertySerialiser.h" #include "FloatPropertySerialiser.h"
auto FloatPropertySerialiser::types() -> Containers::ArrayView<const Containers::String> {
auto FloatPropertySerialiser::types() -> Containers::ArrayView<const Containers::StringView> {
using namespace Containers::Literals; using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit, {"FloatProperty"_s}}; static const Containers::Array<Containers::String> types{InPlaceInit, {"FloatProperty"_s}};
return types; return types;
} }

View file

@ -27,7 +27,7 @@ class FloatPropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<FloatPropertySerialiser>; using ptr = Containers::Pointer<FloatPropertySerialiser>;
auto types() -> Containers::ArrayView<const Containers::StringView> override; auto types() -> Containers::ArrayView<const Containers::String> override;
auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;

View file

@ -19,11 +19,11 @@
#include "StringPropertySerialiser.h" #include "StringPropertySerialiser.h"
auto StringPropertySerialiser::types() -> Containers::ArrayView<const Containers::StringView> { auto StringPropertySerialiser::types() -> Containers::ArrayView<const Containers::String> {
using namespace Containers::Literals; using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit, static const Containers::Array<Containers::String> types{InPlaceInit,
{"NameProperty"_s, "StrProperty"_s, {"NameProperty"_s, "StrProperty"_s,
"SoftObjectProperty"_s, "ObjectProperty"_s}}; "SoftObjectProperty"_s, "ObjectProperty"_s}};
return types; return types;
} }

View file

@ -27,7 +27,7 @@ class StringPropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<StringPropertySerialiser>; using ptr = Containers::Pointer<StringPropertySerialiser>;
auto types() -> Containers::ArrayView<const Containers::StringView> override; auto types() -> Containers::ArrayView<const Containers::String> override;
auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;

View file

@ -25,9 +25,9 @@
#include "StructSerialiser.h" #include "StructSerialiser.h"
auto StructSerialiser::types() -> Containers::ArrayView<const Containers::StringView> { auto StructSerialiser::types() -> Containers::ArrayView<const Containers::String> {
using namespace Containers::Literals; using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit, {"StructProperty"_s}}; static const Containers::Array<Containers::String> types{InPlaceInit, {"StructProperty"_s}};
return types; return types;
} }

View file

@ -29,7 +29,7 @@ class StructSerialiser : public AbstractUnrealPropertySerialiser, public Abstrac
public: public:
using ptr = Containers::Pointer<StructSerialiser>; using ptr = Containers::Pointer<StructSerialiser>;
auto types() -> Containers::ArrayView<const Containers::StringView> override; auto types() -> Containers::ArrayView<const Containers::String> override;
auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
UnsignedInt count, BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array<UnrealPropertyBase::ptr> override; UnsignedInt count, BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array<UnrealPropertyBase::ptr> override;

View file

@ -32,15 +32,15 @@ class UnrealPropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<UnrealPropertySerialiser<T>>; using ptr = Containers::Pointer<UnrealPropertySerialiser<T>>;
auto types() -> Containers::ArrayView<const Containers::StringView> override { auto types() -> Containers::ArrayView<const Containers::String> override {
static const Containers::Array<Containers::StringView> types = []{ static const Containers::Array<Containers::String> types = []{
Containers::Array<Containers::StringView> array; Containers::Array<Containers::String> array;
Containers::Pointer<T> p(new T); Containers::Pointer<T> p(new T);
if(std::is_base_of<StructProperty, T>::value) { if(std::is_base_of<StructProperty, T>::value) {
array = Containers::Array<Containers::StringView>{InPlaceInit, {dynamic_cast<StructProperty*>(p.get())->structType}}; array = Containers::Array<Containers::String>{InPlaceInit, {dynamic_cast<StructProperty*>(p.get())->structType}};
} }
else { else {
array = Containers::Array<Containers::StringView>{InPlaceInit, {p->propertyType}}; array = Containers::Array<Containers::String>{InPlaceInit, {p->propertyType}};
} }
return array; return array;
}(); }();