// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Export.hpp #pragma once #ifndef NAZARA_CORE_SERIALIZATION_HPP #define NAZARA_CORE_SERIALIZATION_HPP #include #include #include #include #include #include #include #include #include namespace Nz { template concept Numeric = std::is_arithmetic::value; enum class EnumSerializationMode { Binary, String, }; struct NAZARA_CORE_API SerializationContext { public: virtual EnumSerializationMode GetEnumSerializationMode() const = 0; virtual bool PushObject(std::string_view name) = 0; virtual bool PopObject() = 0; virtual bool PushArray(std::string_view name) = 0; virtual bool PopArray() = 0; virtual bool Write(std::string_view name, bool value) = 0; virtual bool Write(std::string_view name, Nz::Int8 value) = 0; virtual bool Write(std::string_view name, Nz::Int16 value) = 0; virtual bool Write(std::string_view name, Nz::Int32 value) = 0; virtual bool Write(std::string_view name, Nz::Int64 value) = 0; virtual bool Write(std::string_view name, Nz::UInt8 value) = 0; virtual bool Write(std::string_view name, Nz::UInt16 value) = 0; virtual bool Write(std::string_view name, Nz::UInt32 value) = 0; virtual bool Write(std::string_view name, Nz::UInt64 value) = 0; virtual bool Write(std::string_view name, float value) = 0; virtual bool Write(std::string_view name, double value) = 0; virtual bool Write(std::string_view name, const std::string& value) = 0; virtual bool Read(std::string_view name, bool* value) = 0; virtual bool Read(std::string_view name, Nz::Int8* value) = 0; virtual bool Read(std::string_view name, Nz::Int16* value) = 0; virtual bool Read(std::string_view name, Nz::Int32* value) = 0; virtual bool Read(std::string_view name, Nz::Int64* value) = 0; virtual bool Read(std::string_view name, Nz::UInt8* value) = 0; virtual bool Read(std::string_view name, Nz::UInt16* value) = 0; virtual bool Read(std::string_view name, Nz::UInt32* value) = 0; virtual bool Read(std::string_view name, Nz::UInt64* value) = 0; virtual bool Read(std::string_view name, float* value) = 0; virtual bool Read(std::string_view name, double* value) = 0; virtual bool Read(std::string_view name, std::string* value) = 0; }; template inline bool Serialize(SerializationContext&, T, TypeTag) { return false; } template bool Serialize(SerializationContext& context, std::string_view name, const T& value); template inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag); inline bool Serialize(SerializationContext& context, std::string_view name, const bool& value, TypeTag); inline bool Serialize(SerializationContext& context, std::string_view name, const std::string& value, TypeTag); template bool Serialize(SerializationContext& context, std::string_view name, const T (&values)[N]); template bool Serialize(SerializationContext& context, std::string_view name, const std::array& values); template bool Serialize(SerializationContext& context, std::string_view name, const std::vector& values); template bool Serialize(SerializationContext& context, std::string_view name, const Nz::EnumArray& values); template inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag); template inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag); template inline bool Unserialize(SerializationContext&, T*, TypeTag) { return false; } template inline bool Unserialize(SerializationContext& context, std::string_view name, T* value); template bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag); template <> inline bool Unserialize(SerializationContext& context, std::string_view name, bool* value, TypeTag); template <> inline bool Unserialize(SerializationContext& context, std::string_view name, std::string* value, TypeTag); template bool Unserialize(SerializationContext& context, std::string_view name, T (*values)[N]); template bool Unserialize(SerializationContext& context, std::string_view name, std::array* values); template bool Unserialize(SerializationContext& context, std::string_view name, std::vector* values); template bool Unserialize(SerializationContext& context, std::string_view name, Nz::EnumArray* values); template inline bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag); template bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag); } #include #endif // NAZARA_CORE_SERIALIZATION_HPP