[Serialization] add support of filesystem path and Flags
This commit is contained in:
parent
e9f95d4d0f
commit
a0a4f63847
|
|
@ -76,6 +76,7 @@ namespace Nz
|
||||||
|
|
||||||
inline bool Serialize(SerializationContext& context, std::string_view name, const bool& value, TypeTag<bool>);
|
inline bool Serialize(SerializationContext& context, std::string_view name, const bool& value, TypeTag<bool>);
|
||||||
inline bool Serialize(SerializationContext& context, std::string_view name, const std::string& value, TypeTag<std::string>);
|
inline bool Serialize(SerializationContext& context, std::string_view name, const std::string& value, TypeTag<std::string>);
|
||||||
|
inline bool Serialize(SerializationContext& context, std::string_view name, const std::filesystem::path& value, TypeTag<std::filesystem::path>);
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
bool Serialize(SerializationContext& context, std::string_view name, const T (&values)[N]);
|
bool Serialize(SerializationContext& context, std::string_view name, const T (&values)[N]);
|
||||||
|
|
@ -95,6 +96,9 @@ namespace Nz
|
||||||
template<Enum T>
|
template<Enum T>
|
||||||
inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag<T>);
|
inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag<T>);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool Serialize(SerializationContext& context, std::string_view name, const Flags<T>& flags, TypeTag<Flags<T>>);
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline bool Unserialize(SerializationContext&, T*, TypeTag<T>) { return false; }
|
inline bool Unserialize(SerializationContext&, T*, TypeTag<T>) { return false; }
|
||||||
|
|
@ -105,11 +109,9 @@ namespace Nz
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>);
|
bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>);
|
||||||
|
|
||||||
template <>
|
|
||||||
inline bool Unserialize(SerializationContext& context, std::string_view name, bool* value, TypeTag<bool>);
|
inline bool Unserialize(SerializationContext& context, std::string_view name, bool* value, TypeTag<bool>);
|
||||||
|
|
||||||
template <>
|
|
||||||
inline bool Unserialize(SerializationContext& context, std::string_view name, std::string* value, TypeTag<std::string>);
|
inline bool Unserialize(SerializationContext& context, std::string_view name, std::string* value, TypeTag<std::string>);
|
||||||
|
inline bool Unserialize(SerializationContext& context, std::string_view name, std::filesystem::path* value, TypeTag<std::filesystem::path>);
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
bool Unserialize(SerializationContext& context, std::string_view name, T (*values)[N]);
|
bool Unserialize(SerializationContext& context, std::string_view name, T (*values)[N]);
|
||||||
|
|
@ -128,6 +130,9 @@ namespace Nz
|
||||||
|
|
||||||
template<Enum T>
|
template<Enum T>
|
||||||
bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>);
|
bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline bool Unserialize(SerializationContext& context, std::string_view name, Flags<T>* flags, TypeTag<Flags<T>>);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Core/Serialization.inl>
|
#include <Nazara/Core/Serialization.inl>
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,12 @@ namespace Nz
|
||||||
return context.Write(name, value);
|
return context.Write(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool Serialize(SerializationContext& context, std::string_view name, const std::filesystem::path& value, TypeTag<std::filesystem::path>)
|
||||||
|
{
|
||||||
|
std::string str = value.string();
|
||||||
|
return context.Write(name, str);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
bool Serialize(SerializationContext& context, std::string_view name, const T(&values)[N])
|
bool Serialize(SerializationContext& context, std::string_view name, const T(&values)[N])
|
||||||
{
|
{
|
||||||
|
|
@ -187,6 +193,16 @@ namespace Nz
|
||||||
return context.Read(name, string);
|
return context.Read(name, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool Unserialize(SerializationContext& context, std::string_view name, std::filesystem::path* value, TypeTag<std::filesystem::path>)
|
||||||
|
{
|
||||||
|
std::string str;
|
||||||
|
if (!context.Read(name, &str))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*value = str;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
bool Unserialize(SerializationContext& context, std::string_view name, T(*values)[N])
|
bool Unserialize(SerializationContext& context, std::string_view name, T(*values)[N])
|
||||||
{
|
{
|
||||||
|
|
@ -292,5 +308,19 @@ namespace Nz
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool Serialize(SerializationContext& context, std::string_view name, const Flags<T>& flags, TypeTag<Flags<T>>)
|
||||||
|
{
|
||||||
|
return Serialize(context, name, static_cast<typename Flags<T>::BitField>(flags), TypeTag<std::decay_t<typename Flags<T>::BitField>>());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool Unserialize(SerializationContext& context, std::string_view name, Flags<T>* flags, TypeTag<Flags<T>>)
|
||||||
|
{
|
||||||
|
typename Flags<T>::BitField v;
|
||||||
|
if (Unserialize(context, name, &v, TypeTag<std::decay_t<typename Flags<T>::BitField>>()))
|
||||||
|
*flags = v;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue