Sleeping Wombat Common Library  0.50.0
swCommonLibrary
SerializationCore.h
1 #pragma once
2 
10 #include "swCommonLib/Common/RTTR.h"
11 #include "swCommonLib/Serialization/Serializer.h"
13 
14 #include "swCommonLib/Serialization/PropertySerialization/SerializationContext.h"
15 #include <DirectXMath.h>
16 #include <string>
17 
18 
19 
20 
21 namespace sw
22 {
23 
24 
31 {
32 public:
33 
34  static std::vector< rttr::property >& GetTypeFilteredProperties ( rttr::type objType, SerializationContext* context );
35 
36 
37  static bool ShouldSave ( const rttr::property& prop, MetaDataType saveFlag );
38  static bool IsPolymorphicType ( TypeID type );
39 
40  static void DefaultSerialize ( ISerializer& ser, const EngineObject* object );
41  static void DefaultDeserialize ( const IDeserializer& deser, EngineObject* object );
42 
43  static void DefaultSerializeImpl ( ISerializer& ser, const rttr::instance& object, rttr::type dynamicType );
44  static void DefaultDeserializeImpl ( const IDeserializer& deser, const rttr::instance& object, rttr::type dynamicType );
45 
48 
50  static bool SerializeBasicTypes ( ISerializer& ser, const rttr::instance& object, rttr::property& prop );
51  static bool SerializeVectorTypes ( ISerializer& ser, const rttr::instance& object, rttr::property& prop );
52  static bool SerializeStringTypes ( ISerializer& ser, const rttr::instance& object, rttr::property& prop );
53  static bool SerializeEnumTypes ( ISerializer& ser, const rttr::instance& object, rttr::property& prop );
54  static bool SerializeArrayTypes ( ISerializer& ser, const rttr::instance& object, rttr::property& prop );
55  static bool SerializeObjectTypes ( ISerializer& ser, const rttr::instance& object, rttr::property& prop );
56 
57  static bool SerializeBasicTypes ( ISerializer& ser, rttr::string_view name, const rttr::variant& propertyValue );
59 
60  static void SerializePolymorphic ( ISerializer& ser, const rttr::instance& object, rttr::property& prop );
61  static void SerializePropertiesVec ( ISerializer& ser, const rttr::instance& object, std::vector< rttr::property >& properties );
62 
65 
67  static bool DeserializeBasicTypes ( const IDeserializer& deser, const rttr::instance& object, rttr::property& prop );
68  static bool DeserializeVectorTypes ( const IDeserializer& deser, const rttr::instance& object, rttr::property& prop );
69  static bool DeserializeStringTypes ( const IDeserializer& deser, const rttr::instance& object, rttr::property& prop );
70  static bool DeserializeEnumTypes ( const IDeserializer& deser, const rttr::instance& object, rttr::property& prop );
71  static bool DeserializeArrayTypes ( const IDeserializer& deser, const rttr::instance& object, rttr::property& prop );
72  static bool DeserializeObjectTypes ( const IDeserializer& deser, const rttr::instance& object, rttr::property& prop );
73 
75 
76  static void DeserializePolymorphic ( const IDeserializer& deser, const rttr::instance& object, rttr::property& prop );
77  static void DeserializeNotPolymorphic ( const IDeserializer& deser, const rttr::instance& object, rttr::property& prop );
78 
79  static rttr::variant CreateAndSetObjectProperty ( const IDeserializer& deser, const rttr::instance& object, rttr::property& prop, TypeID dynamicType );
80  static rttr::variant CreateInstance ( TypeID type );
81 
82 
83  static std::string WstringToUTF ( const std::wstring& str );
84  static std::wstring UTFToWstring ( const std::string& str );
85 
86  template< typename PropertyType >
87  static PropertyType GetPropertyValue ( rttr::property prop, const rttr::instance& object );
88 
89  template< typename PropertyType >
90  static void SerializeProperty ( ISerializer& ser, rttr::property prop, const rttr::instance& object );
91 
92  template< typename PropertyType >
93  static void SerializeProperty ( ISerializer& ser, rttr::string_view name, const rttr::variant& propertyValue );
94 
95 
96  template<> static void SerializeProperty< EngineObject* > ( ISerializer& ser, rttr::property prop, const rttr::instance& object );
97  template<> static void SerializeProperty< void* > ( ISerializer& ser, rttr::property prop, const rttr::instance& object );
98  template<> static void SerializeProperty< DirectX::XMFLOAT2* > ( ISerializer& ser, rttr::property prop, const rttr::instance& object );
99  template<> static void SerializeProperty< DirectX::XMFLOAT3* > ( ISerializer& ser, rttr::property prop, const rttr::instance& object );
100  template<> static void SerializeProperty< DirectX::XMFLOAT4* > ( ISerializer& ser, rttr::property prop, const rttr::instance& object );
101  template<> static void SerializeProperty< std::wstring > ( ISerializer& ser, rttr::property prop, const rttr::instance& object );
102  template<> static void SerializeProperty< char > ( ISerializer& ser, rttr::property prop, const rttr::instance& object );
103 
104  template<> static void SerializeProperty< char > ( ISerializer& ser, rttr::string_view name, const rttr::variant& propertyValue );
105 
106 
107  template< typename PropertyType >
108  static void SetPropertyValue ( rttr::property prop, const rttr::instance& object, PropertyType value );
109 
110  template< typename PropertyType >
111  static void DeserializeProperty ( const IDeserializer& deser, rttr::property prop, const rttr::instance& object );
112 
113 
114  template<> static void DeserializeProperty< EngineObject* > ( const IDeserializer& deser, rttr::property prop, const rttr::instance& object );
115  template<> static void DeserializeProperty< void* > ( const IDeserializer& deser, rttr::property prop, const rttr::instance& object );
116  template<> static void DeserializeProperty< DirectX::XMFLOAT2* > ( const IDeserializer& deser, rttr::property prop, const rttr::instance& object );
117  template<> static void DeserializeProperty< DirectX::XMFLOAT3* > ( const IDeserializer& deser, rttr::property prop, const rttr::instance& object );
118  template<> static void DeserializeProperty< DirectX::XMFLOAT4* > ( const IDeserializer& deser, rttr::property prop, const rttr::instance& object );
119  template<> static void DeserializeProperty< std::wstring > ( const IDeserializer& deser, rttr::property prop, const rttr::instance& object );
120  template<> static void DeserializeProperty< char > ( const IDeserializer& deser, rttr::property prop, const rttr::instance& object );
121 
123  static TypeID GetRealType ( const rttr::instance& object );
124 
126  static TypeID GetWrappedType ( TypeID type );
127 
129  static TypeID GetRawWrappedType ( TypeID type );
130 
132  static SerializationContext* Context ( const IDeserializer& deser );
133 
135  static void DestroyObject ( rttr::variant& object );
136 };
137 
138 
139 } // sw
140 
141 
142 #include "SerializationCore.inl"
static void SerializeProperty(ISerializer &ser, rttr::property prop, const rttr::instance &object)
Serializuje właściwość podanego typu.
Definition: SerializationCore.inl:63
Serialization context for automatic serialization.
Definition: SerializationContext.h:30
static bool DeserializeArrayTypes(const IDeserializer &deser, const rttr::instance &object, rttr::property &prop)
Deserializes arrays.
Definition: SerializationCore.cpp:433
static void SetPropertyValue(rttr::property prop, const rttr::instance &object, PropertyType value)
Ustawia wartość podanej właściwości.
Definition: SerializationCore.inl:79
Interface for deserializers.
Definition: Deserializer.h:39
static void DestroyObject(rttr::variant &object)
Destroy object in variant.
Definition: SerializationCore.inl:125
Definition: Exception.h:11
static rttr::variant CreateAndSetObjectProperty(const IDeserializer &deser, const rttr::instance &object, rttr::property &prop, TypeID dynamicType)
Definition: SerializationCore.cpp:664
Deklaracja klasy deserializatora.
static bool DeserializeStringTypes(const IDeserializer &deser, const rttr::instance &object, rttr::property &prop)
Deserializuje std::string i std::wstring.
Definition: SerializationCore.cpp:393
Serializers interface.
Definition: Serializer.h:31
Base class for serializable objects.
Definition: EngineObject.h:24
static PropertyType GetPropertyValue(rttr::property prop, const rttr::instance &object)
Returns typed property value.
Definition: SerializationCore.inl:52
static void DeserializeNotPolymorphic(const IDeserializer &deser, const rttr::instance &object, rttr::property &prop)
Definition: SerializationCore.cpp:633
static bool DeserializeVectorTypes(const IDeserializer &deser, const rttr::instance &object, rttr::property &prop)
Deserializuje typy DirectXMath.
Definition: SerializationCore.cpp:374
Core serialization/deserialization functions.
Definition: SerializationCore.h:30
static bool DeserializeBasicTypes(const IDeserializer &deser, const rttr::instance &object, rttr::property &prop)
Deserialize basic arithemtic types and bool.
Definition: SerializationCore.cpp:334
static SerializationContext * Context(const IDeserializer &deser)
Returns SerialziationContext from deserializer.
Definition: SerializationCore.inl:118
static void DeserializeProperty(const IDeserializer &deser, rttr::property prop, const rttr::instance &object)
Deserializuje właściwość podanego typu.
Definition: SerializationCore.inl:88
static bool DeserializeEnumTypes(const IDeserializer &deser, const rttr::instance &object, rttr::property &prop)
Deserializes enum properties from string.
Definition: SerializationCore.cpp:410
static TypeID GetRealType(const rttr::instance &object)
Gets real type of the object that means most derived and wrapped type.
Definition: SerializationCore.inl:96
static bool DeserializeObjectTypes(const IDeserializer &deser, const rttr::instance &object, rttr::property &prop)
Deserializes structures and generic objects.
Definition: SerializationCore.cpp:522
static bool SerializeEnumTypes(ISerializer &ser, const rttr::instance &object, rttr::property &prop)
Definition: SerializationCore.cpp:208
static bool IsPolymorphicType(TypeID type)
We support only polymorphic types derived from EngineObject.
Definition: SerializationCore.cpp:68
static TypeID GetRawWrappedType(TypeID type)
First extracts wrapped type and then returns raw type.
Definition: SerializationCore.inl:111
static void DeserializePolymorphic(const IDeserializer &deser, const rttr::instance &object, rttr::property &prop)
Definition: SerializationCore.cpp:563
static TypeID GetWrappedType(TypeID type)
Gets wrapped type. If type isn't wrapper it returns it unmodified.
Definition: SerializationCore.inl:104
static bool SerializeBasicTypes(ISerializer &ser, const rttr::instance &object, rttr::property &prop)
Serialize basic arithemtic types and bool.
Definition: SerializationCore.cpp:128