mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa ContentTypeSerializer_T
This commit is contained in:
parent
35cf5d54f9
commit
a2b6351de5
@ -105,7 +105,7 @@ namespace xna {
|
|||||||
|
|
||||||
//Provides properties describing the origin of the game asset, such as the original source file and creation tool.
|
//Provides properties describing the origin of the game asset, such as the original source file and creation tool.
|
||||||
//This information is used for error reporting, and by processors that need to determine from what directory the asset was originally loaded.
|
//This information is used for error reporting, and by processors that need to determine from what directory the asset was originally loaded.
|
||||||
struct ContentIdentity {
|
struct ContentIdentity : public ISerialization {
|
||||||
constexpr ContentIdentity() = default;
|
constexpr ContentIdentity() = default;
|
||||||
constexpr ContentIdentity(std::string sourceFilename) :
|
constexpr ContentIdentity(std::string sourceFilename) :
|
||||||
SourceFilename(sourceFilename) {}
|
SourceFilename(sourceFilename) {}
|
||||||
@ -123,6 +123,8 @@ namespace xna {
|
|||||||
//Gets or sets the specific location of the content item within the larger source file.
|
//Gets or sets the specific location of the content item within the larger source file.
|
||||||
//Optional = true
|
//Optional = true
|
||||||
std::string FragmentIdentifier;
|
std::string FragmentIdentifier;
|
||||||
|
|
||||||
|
void Serialize(ContentTypeSerializer& serializer, bool serializeOptional) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Provides properties that define opaque data for a game asset.
|
//Provides properties that define opaque data for a game asset.
|
||||||
|
@ -2,16 +2,14 @@
|
|||||||
#define XNA_PIPELINE_SERIALIZER_HPP
|
#define XNA_PIPELINE_SERIALIZER_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <any>
|
||||||
#include "xna/csharp/xml.hpp"
|
#include "xna/csharp/xml.hpp"
|
||||||
|
#include "xna/content/serializer.hpp"
|
||||||
|
#include "xna/helpers.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
class ContentTypeSerializer {
|
class IntermediateWriter;
|
||||||
|
class IntermediateReader;
|
||||||
};
|
|
||||||
|
|
||||||
struct ISerialization {
|
|
||||||
virtual void Serialize(ContentTypeSerializer& serializer) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class IntermediateSerializer {
|
class IntermediateSerializer {
|
||||||
public:
|
public:
|
||||||
@ -20,6 +18,73 @@ namespace xna {
|
|||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Provides methods for serializing and deserializing a specific managed type.
|
||||||
|
class ContentTypeSerializer {
|
||||||
|
public:
|
||||||
|
//Retrieves and caches any nested type serializers and allows reflection over the target data type.
|
||||||
|
virtual void Initialize(IntermediateSerializer serializer) {};
|
||||||
|
//Serializes an object to intermediate XML format.
|
||||||
|
virtual void Serialize(IntermediateWriter output, std::any const& value, ContentSerializerAttribute& format);
|
||||||
|
//Serializes an object to intermediate XML format.
|
||||||
|
virtual std::any Deserialize(IntermediateWriter input, ContentSerializerAttribute& format, std::any const& existingInstance);
|
||||||
|
|
||||||
|
//Gets a value indicating whether this component may load data into an existing object or if it must it construct a new instance of the object before loading the data.
|
||||||
|
virtual bool CanDeserializeIntoExistingObject() const { return false; }
|
||||||
|
//Queries whether an object contains data to be serialized.
|
||||||
|
virtual bool ObjectIsEmpty(std::any const& value) const { return false; }
|
||||||
|
//Gets a short-form XML name for the target type, or null if there is none.
|
||||||
|
constexpr std::string XmlTypeName() const { return xmlTypeName; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ContentTypeSerializer() {}
|
||||||
|
ContentTypeSerializer(std::string const& xmlTypeName) : xmlTypeName(xmlTypeName) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string xmlTypeName;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ISerialization {
|
||||||
|
virtual void Serialize(ContentTypeSerializer& serializer, bool serializeOptional = true) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class ContentTypeSerializer_T : public ContentTypeSerializer {
|
||||||
|
public:
|
||||||
|
virtual void Serialize(IntermediateWriter output, T const& value, ContentSerializerAttribute& format) = 0;
|
||||||
|
|
||||||
|
void Serialize(IntermediateWriter output, std::any const& value, ContentSerializerAttribute& format) override {
|
||||||
|
Serializer<T>(output, CastType(value), format);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual T Deserialize(IntermediateWriter input, ContentSerializerAttribute& format, T& existingInstance) = 0;
|
||||||
|
|
||||||
|
std::any Deserialize(IntermediateWriter input, ContentSerializerAttribute& format, std::any const& existingInstance) override {
|
||||||
|
|
||||||
|
if constexpr (XnaHelper::IsSmartPoint<T>() && !existingInstance.has_value())
|
||||||
|
return T();
|
||||||
|
|
||||||
|
T existingInstance1 = CastType(existingInstance);
|
||||||
|
|
||||||
|
std::any obj = Deserialize<T>(input, format, existingInstance1);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ContentTypeSerializer_T() {}
|
||||||
|
ContentTypeSerializer_T(std::string const& xmlTypeName) : ContentTypeSerializer(xmlTypeName){}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static T CastType(std::any const& value) {
|
||||||
|
try {
|
||||||
|
return std::any_cast<T>(value);
|
||||||
|
}
|
||||||
|
catch (std::exception& ex) {
|
||||||
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -6,7 +6,7 @@
|
|||||||
add_library (Xn65Pipeline STATIC
|
add_library (Xn65Pipeline STATIC
|
||||||
"writer.cpp"
|
"writer.cpp"
|
||||||
"compiler.cpp"
|
"compiler.cpp"
|
||||||
"importer.cpp" "graphics.cpp")
|
"importer.cpp" "graphics.cpp" "pipeline.cpp")
|
||||||
|
|
||||||
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||||
set_property(TARGET Xn65Pipeline PROPERTY CXX_STANDARD 20)
|
set_property(TARGET Xn65Pipeline PROPERTY CXX_STANDARD 20)
|
||||||
|
7
sources/pipeline/pipeline.cpp
Normal file
7
sources/pipeline/pipeline.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "pipeline/pipeline.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
void ContentIdentity::Serialize(ContentTypeSerializer& serializer, bool serializeOptional) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user