Beispiel #1
0
			static void ReadObject(void* object, void* source, const ObjectType& type, const DataNode& node)
			{
				for (auto baseType : type.GetBaseTypes())
				{
					const ObjectType* baseObjectType = dynamic_cast<const ObjectType*>(baseType.type);
					if (!baseObjectType)
						continue;

					void* baseObject = (*baseType.dynamicCastUpFunc)(object);
					void* baseSourceObject = (*baseType.dynamicCastUpFunc)(source);
					ReadObject(baseObject, baseSourceObject, *baseObjectType, node);
				}

				for (auto field : type.GetFields())
				{
					if (!field->GetAttribute<SerializableAttribute>())
						continue;

					auto fldNode = node.GetNode(field->GetName());
					if (fldNode)
					{
						if (field->GetType()->IsBasedOn(TypeOf(IObject)))
						{
							bool usedConverter = false;
							for (auto conv : mDataConverters)
							{
								if (conv->IsConvertsType(field->GetType()))
								{
									conv->FromData(field->GetValuePtr(object), node);
									usedConverter = true;
									break;
								}
							}

							if (usedConverter)
								continue;

							fldNode->GetValueDelta(*(IObject*)field->GetValuePtr(object),
												   *(IObject*)field->GetValuePtr(source));
						}
						else field->DeserializeFromObject(object, *fldNode);
					}
					else field->CopyValue(object, source);
				}
			}
Beispiel #2
0
			static void WriteObject(void* object, const ObjectType& type, DataNode& node)
			{
				for (auto baseType : type.GetBaseTypes())
				{
					const ObjectType* baseObjectType = dynamic_cast<const ObjectType*>(baseType.type);
					if (!baseObjectType)
						continue;

					void* baseObject = (*baseType.dynamicCastUpFunc)(object);
					WriteObject(baseObject, *baseObjectType, node);
				}

				for (auto field : type.GetFields())
				{
					auto srlzAttribute = field->GetAttribute<SerializableAttribute>();
					if (srlzAttribute)
						field->SerializeFromObject(object, *node.AddNode(field->GetName()));
				}
			}
Beispiel #3
0
			static void WriteObject(void* object, void* source, const ObjectType& type, DataNode& node)
			{
				for (auto baseType : type.GetBaseTypes())
				{
					const ObjectType* baseObjectType = dynamic_cast<const ObjectType*>(baseType.type);
					if (!baseObjectType)
						continue;

					void* baseObject = (*baseType.dynamicCastUpFunc)(object);
					void* baseSourceObject = (*baseType.dynamicCastUpFunc)(source);
					WriteObject(baseObject, baseSourceObject, *baseObjectType, node);
				}

				for (auto field : type.GetFields())
				{
					if (!field->GetAttribute<SerializableAttribute>())
						continue;

					if (field->GetType()->IsBasedOn(TypeOf(IObject)))
					{
						bool usedConverter = false;
						for (auto conv : mDataConverters)
						{
							if (conv->IsConvertsType(&type))
							{
								if (!field->IsValueEquals(object, source))
									conv->ToData(&object, *node.AddNode(field->GetName()));

								usedConverter = true;

								break;
							}
						}

						if (usedConverter)
							continue;

						DataNode* newFieldNode = mnew DataNode();
						newFieldNode->SetName(field->GetName());

						newFieldNode->SetValueDelta(*(IObject*)field->GetValuePtr(object),
													*(IObject*)field->GetValuePtr(source));

						if (!newFieldNode->IsEmpty())
							node.AddNode(newFieldNode);
						else
							delete newFieldNode;

						continue;
					}

					if (!field->IsValueEquals(object, source))
					{
						DataNode* newFieldNode = mnew DataNode();
						newFieldNode->SetName(field->GetName());

						field->SerializeFromObject(object, *newFieldNode);

						if (!newFieldNode->IsEmpty())
							node.AddNode(newFieldNode);
						else
							delete newFieldNode;
					}
				}
			}