summaryrefslogtreecommitdiff
path: root/Runtime/Serialize/SerializeConversion.h
blob: 782ea5bb142a49c0d674ec0b3aab7fabd70a2b28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef SERIALIZECONVERSION_H
#define SERIALIZECONVERSION_H

#if SUPPORT_SERIALIZED_TYPETREES
#include "Runtime/Serialize/TransferFunctions/SerializeTransfer.h"
#include "SerializeTraits.h"

// Trys to convert from an old type to a new one
template<class OldFormat, class NewFormat>
bool StdTemplateConversionFunction (void* inData, SafeBinaryRead& transfer)
{
	NewFormat& data = *reinterpret_cast<NewFormat*> (inData);
	const TypeTree& oldTypeTree = transfer.GetActiveOldTypeTree ();
	AssertIf (SerializeTraits<OldFormat>::GetTypeString (NULL) != oldTypeTree.m_Type);
	OldFormat oldData;
	
	SafeBinaryRead safeRead;
	CachedReader& temp = safeRead.Init (transfer);
	
	safeRead.Transfer (oldData, oldTypeTree.m_Name.c_str ());
	
	temp.End ();
	
	data = oldData;

	return true;
}

#define REGISTER_CONVERTER(from, to)	\
SafeBinaryRead::RegisterConverter (SerializeTraits<from>::GetTypeString (NULL), SerializeTraits<to>::GetTypeString (NULL),				\
										StdTemplateConversionFunction<from, to>)

#endif
#endif