Example #1
0
	void Serialize_Parent_Class(
		Json::Value & classValue,
		const mxClass& parentClass,
		const void* rawMem
		)
	{
		if( ObjectUtil::Serializable_Class( parentClass ) )
		{
			Json::Value	parentClassValue = Serialize_Class( parentClass, rawMem );

			classValue[ BASE_CLASS_TAG ] = parentClassValue;
			//classValue[ parentClass.GetTypeName() ] = parentClassValue;
			//value[ "Super" ] = parentClassValue;

			if( bEnableJsonComments )
			{
				parentClassValue.setComment("// Base class", Json::CommentPlacement::commentBefore);
			}
		}
	}
Example #2
0
	Json::Value Serialize(
		const mxType& typeInfo,	// type of serialized object
		const void* rawMem,	// pointer to the start of the memory block
		const UINT offset	// byte offset within the structure
		)
	{
	#if MX_DEBUG_SERIALIZATION
		if( typeInfo.m_alignment ) {
			Assert(IS_ALIGNED_BY( rawMem, typeInfo.m_alignment ));
		}
	#endif // MX_DEBUG_SERIALIZATION

		Json::Value		returnValue;

		const void* objAddr = (BYTE*)rawMem + offset;

		const ETypeKind typeKind = typeInfo.m_kind;

		switch( typeKind )
		{
		case ETypeKind::Type_Int8 :
			{
				const INT8 intValue = TPODHelper< INT8 >::GetConst( objAddr );
				returnValue = Serialize_Int8( intValue );
			}
			break;

		case ETypeKind::Type_UInt8 :
			{
				const UINT8 uintValue = TPODHelper< UINT8 >::GetConst( objAddr );
				returnValue = Serialize_UInt8( uintValue );
			}
			break;

		case ETypeKind::Type_Int16 :
			{
				const INT16 intValue = TPODHelper< INT16 >::GetConst( objAddr );
				returnValue = Serialize_Int16( intValue );
			}
			break;

		case ETypeKind::Type_UInt16 :
			{
				const UINT16 uintValue = TPODHelper< UINT16 >::GetConst( objAddr );
				returnValue = Serialize_UInt16( uintValue );
			}
			break;

		case ETypeKind::Type_Int32 :
			{
				const INT32 intValue = TPODHelper< INT32 >::GetConst( objAddr );
				returnValue = Serialize_Int32( intValue );
			}
			break;

		case ETypeKind::Type_UInt32 :
			{
				const UINT32 uintValue = TPODHelper< UINT32 >::GetConst( objAddr );
				returnValue = Serialize_UInt32( uintValue );
			}
			break;

		case ETypeKind::Type_Int64 :
			{
				const INT64 intValue = TPODHelper< INT64 >::GetConst( objAddr );
				returnValue = Serialize_Int64( intValue );
			}
			break;

		case ETypeKind::Type_UInt64 :
			{
				const UINT64 uintValue = TPODHelper< UINT64 >::GetConst( objAddr );
				returnValue = Serialize_UInt64( uintValue );
			}
			break;

		case ETypeKind::Type_Float :
			{
				const F4 floatValue = TPODHelper< F4 >::GetConst( objAddr );
				returnValue = Serialize_Float( floatValue );
			}
			break;

		case ETypeKind::Type_Double :
			{
				const F8 doubleValue = TPODHelper< F8 >::GetConst( objAddr );
				returnValue = Serialize_Double( doubleValue );
			}
			break;

		case ETypeKind::Type_Bool :
			{
				const bool booleanValue = TPODHelper< bool >::GetConst( objAddr );
				returnValue = Serialize_Boolean( booleanValue );
			}
			break;

		case ETypeKind::Type_SimdQuad :
			{
				const float4 vectorValue = TPODHelper< float4 >::GetConst( objAddr );
				returnValue = Serialize_Float4( vectorValue );
			}
			break;

		case ETypeKind::Type_Vec2D :
			{
				const Vec2D& vectorValue = TPODHelper< Vec2D >::GetConst( objAddr );
				returnValue = Serialize_Vec2D( vectorValue );
			}
			break;

		case ETypeKind::Type_Vec3D :
			{
				const Vec3D& vectorValue = TPODHelper< Vec3D >::GetConst( objAddr );
				returnValue = Serialize_Vec3D( vectorValue );
			}
			break;

		case ETypeKind::Type_Vec4D :
			{
				const Vec4D& vectorValue = TPODHelper< Vec4D >::GetConst( objAddr );
				returnValue = Serialize_Vec4D( vectorValue );
			}
			break;

		case ETypeKind::Type_Matrix2 :
			{
				const Matrix2& matrixValue = TPODHelper< Matrix2 >::GetConst( objAddr );
				returnValue = Serialize_Matrix2( matrixValue );
			}
			break;

		case ETypeKind::Type_Matrix3 :
			{
				const Matrix3& matrixValue = TPODHelper< Matrix3 >::GetConst( objAddr );
				returnValue = Serialize_Matrix3( matrixValue );
			}
			break;

		case ETypeKind::Type_Matrix4 :
			{
				const Matrix4& matrixValue = TPODHelper< Matrix4 >::GetConst( objAddr );
				returnValue = Serialize_Matrix4( matrixValue );
			}
			break;

		case ETypeKind::Type_ColorRGBA :
			{
				const FColor& colorValue = TPODHelper< FColor >::GetConst( objAddr );
				returnValue = Serialize_ColorRGBA( colorValue );
			}
			break;

		case ETypeKind::Type_String :
			{
				const String& stringValue = TPODHelper< String >::GetConst( objAddr );
				returnValue = Serialize_String( stringValue );
			}
			break;

		case ETypeKind::Type_Enum :
			{
				const mxEnumType& enumInfo = typeInfo.UpCast<mxEnumType>();
				returnValue = Serialize_Enum( enumInfo, objAddr );
			}
			break;

		case ETypeKind::Type_Flags :
			{
				const mxFlagsType& flagsType = typeInfo.UpCast<mxFlagsType>();
				returnValue = Serialize_Flags( flagsType, objAddr );
			}
			break;

		case ETypeKind::Type_Struct :
			{
				const mxStruct& structInfo = typeInfo.UpCast<mxStruct>();
				returnValue = Serialize_Struct( structInfo, objAddr );
			}
			break;

		case ETypeKind::Type_Class :
			{
				const mxClass& classInfo = typeInfo.UpCast<mxClass>();
				returnValue = Serialize_Class( classInfo, objAddr );
			}
			break;

		case ETypeKind::Type_Pointer :
			{
				const mxPointerType& pointerType = typeInfo.UpCast<mxPointerType>();
				returnValue = Serialize_Pointer( pointerType, objAddr );
			}
			break;

		case ETypeKind::Type_AssetRef :
			{
				const mxAssetReferenceType& handleType = typeInfo.UpCast<mxAssetReferenceType>();
				returnValue = Serialize_AssetReference( handleType, objAddr );
			}
			break;

		case ETypeKind::Type_Array :
			{
				const mxArrayType& arrayInfo = typeInfo.UpCast<mxArrayType>();
				returnValue = Serialize_Array( arrayInfo, objAddr );
			}
			break;

		default:
			Unreachable;
		}

		if( bEnableJsonComments )
		{
			String	comment;
			comment.Format("// type: %s, size: %u, offset: %u, align: %u\n",
				typeInfo.m_name, typeInfo.m_instanceSize, offset, typeInfo.m_alignment);

			returnValue.setComment(comment, Json::CommentPlacement::commentBefore);
		}

		return returnValue;
	}//Serialize()