Generate ConcreteCast

This commit is contained in:
ousttrue
2019-02-01 21:52:50 +09:00
parent ec9a8da1ce
commit 0a55f6fb29
5 changed files with 713 additions and 1 deletions

View File

@@ -0,0 +1,71 @@
using System;
using System.IO;
using System.Text;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UniJSON
{
public static partial class ConcreteCast
{
#if UNITY_EDITOR
static Type[] s_castTypes = new Type[]
{
typeof(byte),
typeof(ushort),
typeof(uint),
typeof(ulong),
typeof(sbyte),
typeof(short),
typeof(int),
typeof(long),
typeof(float),
typeof(double),
};
[MenuItem(UniGLTF.UniGLTFVersion.MENU + "/Generate ConcreteCast")]
public static void GenerateGenericCast()
{
var s = new StringBuilder();
using (var w = new StringWriter(s))
{
w.WriteLine(@"
using System;
namespace UniJSON {
public static partial class ConcreteCast
{
");
foreach (var x in s_castTypes)
{
foreach (var y in s_castTypes)
{
w.WriteLine(@"
public static $1 Cast$0To$1($0 src)
{
return ($1)src;
}
".Replace("$0", x.Name).Replace("$1", y.Name));
}
}
w.WriteLine(@"
}
}
");
}
var path = Application.dataPath + SOURCE;
Debug.LogFormat("{0}", path);
File.WriteAllText(path, s.ToString().Replace("\r\n", "\n"), new UTF8Encoding(false));
AssetDatabase.ImportAsset("Assets" + SOURCE);
}
const string SOURCE = "/VRM/UniJSON/Scripts/ConcreteCast.g.cs";
#endif
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7c7697929e4510048a5238dd9d227b2e
timeCreated: 1549025672
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,611 @@
using System;
namespace UniJSON {
public static partial class ConcreteCast
{
public static Byte CastByteToByte(Byte src)
{
return (Byte)src;
}
public static UInt16 CastByteToUInt16(Byte src)
{
return (UInt16)src;
}
public static UInt32 CastByteToUInt32(Byte src)
{
return (UInt32)src;
}
public static UInt64 CastByteToUInt64(Byte src)
{
return (UInt64)src;
}
public static SByte CastByteToSByte(Byte src)
{
return (SByte)src;
}
public static Int16 CastByteToInt16(Byte src)
{
return (Int16)src;
}
public static Int32 CastByteToInt32(Byte src)
{
return (Int32)src;
}
public static Int64 CastByteToInt64(Byte src)
{
return (Int64)src;
}
public static Single CastByteToSingle(Byte src)
{
return (Single)src;
}
public static Double CastByteToDouble(Byte src)
{
return (Double)src;
}
public static Byte CastUInt16ToByte(UInt16 src)
{
return (Byte)src;
}
public static UInt16 CastUInt16ToUInt16(UInt16 src)
{
return (UInt16)src;
}
public static UInt32 CastUInt16ToUInt32(UInt16 src)
{
return (UInt32)src;
}
public static UInt64 CastUInt16ToUInt64(UInt16 src)
{
return (UInt64)src;
}
public static SByte CastUInt16ToSByte(UInt16 src)
{
return (SByte)src;
}
public static Int16 CastUInt16ToInt16(UInt16 src)
{
return (Int16)src;
}
public static Int32 CastUInt16ToInt32(UInt16 src)
{
return (Int32)src;
}
public static Int64 CastUInt16ToInt64(UInt16 src)
{
return (Int64)src;
}
public static Single CastUInt16ToSingle(UInt16 src)
{
return (Single)src;
}
public static Double CastUInt16ToDouble(UInt16 src)
{
return (Double)src;
}
public static Byte CastUInt32ToByte(UInt32 src)
{
return (Byte)src;
}
public static UInt16 CastUInt32ToUInt16(UInt32 src)
{
return (UInt16)src;
}
public static UInt32 CastUInt32ToUInt32(UInt32 src)
{
return (UInt32)src;
}
public static UInt64 CastUInt32ToUInt64(UInt32 src)
{
return (UInt64)src;
}
public static SByte CastUInt32ToSByte(UInt32 src)
{
return (SByte)src;
}
public static Int16 CastUInt32ToInt16(UInt32 src)
{
return (Int16)src;
}
public static Int32 CastUInt32ToInt32(UInt32 src)
{
return (Int32)src;
}
public static Int64 CastUInt32ToInt64(UInt32 src)
{
return (Int64)src;
}
public static Single CastUInt32ToSingle(UInt32 src)
{
return (Single)src;
}
public static Double CastUInt32ToDouble(UInt32 src)
{
return (Double)src;
}
public static Byte CastUInt64ToByte(UInt64 src)
{
return (Byte)src;
}
public static UInt16 CastUInt64ToUInt16(UInt64 src)
{
return (UInt16)src;
}
public static UInt32 CastUInt64ToUInt32(UInt64 src)
{
return (UInt32)src;
}
public static UInt64 CastUInt64ToUInt64(UInt64 src)
{
return (UInt64)src;
}
public static SByte CastUInt64ToSByte(UInt64 src)
{
return (SByte)src;
}
public static Int16 CastUInt64ToInt16(UInt64 src)
{
return (Int16)src;
}
public static Int32 CastUInt64ToInt32(UInt64 src)
{
return (Int32)src;
}
public static Int64 CastUInt64ToInt64(UInt64 src)
{
return (Int64)src;
}
public static Single CastUInt64ToSingle(UInt64 src)
{
return (Single)src;
}
public static Double CastUInt64ToDouble(UInt64 src)
{
return (Double)src;
}
public static Byte CastSByteToByte(SByte src)
{
return (Byte)src;
}
public static UInt16 CastSByteToUInt16(SByte src)
{
return (UInt16)src;
}
public static UInt32 CastSByteToUInt32(SByte src)
{
return (UInt32)src;
}
public static UInt64 CastSByteToUInt64(SByte src)
{
return (UInt64)src;
}
public static SByte CastSByteToSByte(SByte src)
{
return (SByte)src;
}
public static Int16 CastSByteToInt16(SByte src)
{
return (Int16)src;
}
public static Int32 CastSByteToInt32(SByte src)
{
return (Int32)src;
}
public static Int64 CastSByteToInt64(SByte src)
{
return (Int64)src;
}
public static Single CastSByteToSingle(SByte src)
{
return (Single)src;
}
public static Double CastSByteToDouble(SByte src)
{
return (Double)src;
}
public static Byte CastInt16ToByte(Int16 src)
{
return (Byte)src;
}
public static UInt16 CastInt16ToUInt16(Int16 src)
{
return (UInt16)src;
}
public static UInt32 CastInt16ToUInt32(Int16 src)
{
return (UInt32)src;
}
public static UInt64 CastInt16ToUInt64(Int16 src)
{
return (UInt64)src;
}
public static SByte CastInt16ToSByte(Int16 src)
{
return (SByte)src;
}
public static Int16 CastInt16ToInt16(Int16 src)
{
return (Int16)src;
}
public static Int32 CastInt16ToInt32(Int16 src)
{
return (Int32)src;
}
public static Int64 CastInt16ToInt64(Int16 src)
{
return (Int64)src;
}
public static Single CastInt16ToSingle(Int16 src)
{
return (Single)src;
}
public static Double CastInt16ToDouble(Int16 src)
{
return (Double)src;
}
public static Byte CastInt32ToByte(Int32 src)
{
return (Byte)src;
}
public static UInt16 CastInt32ToUInt16(Int32 src)
{
return (UInt16)src;
}
public static UInt32 CastInt32ToUInt32(Int32 src)
{
return (UInt32)src;
}
public static UInt64 CastInt32ToUInt64(Int32 src)
{
return (UInt64)src;
}
public static SByte CastInt32ToSByte(Int32 src)
{
return (SByte)src;
}
public static Int16 CastInt32ToInt16(Int32 src)
{
return (Int16)src;
}
public static Int32 CastInt32ToInt32(Int32 src)
{
return (Int32)src;
}
public static Int64 CastInt32ToInt64(Int32 src)
{
return (Int64)src;
}
public static Single CastInt32ToSingle(Int32 src)
{
return (Single)src;
}
public static Double CastInt32ToDouble(Int32 src)
{
return (Double)src;
}
public static Byte CastInt64ToByte(Int64 src)
{
return (Byte)src;
}
public static UInt16 CastInt64ToUInt16(Int64 src)
{
return (UInt16)src;
}
public static UInt32 CastInt64ToUInt32(Int64 src)
{
return (UInt32)src;
}
public static UInt64 CastInt64ToUInt64(Int64 src)
{
return (UInt64)src;
}
public static SByte CastInt64ToSByte(Int64 src)
{
return (SByte)src;
}
public static Int16 CastInt64ToInt16(Int64 src)
{
return (Int16)src;
}
public static Int32 CastInt64ToInt32(Int64 src)
{
return (Int32)src;
}
public static Int64 CastInt64ToInt64(Int64 src)
{
return (Int64)src;
}
public static Single CastInt64ToSingle(Int64 src)
{
return (Single)src;
}
public static Double CastInt64ToDouble(Int64 src)
{
return (Double)src;
}
public static Byte CastSingleToByte(Single src)
{
return (Byte)src;
}
public static UInt16 CastSingleToUInt16(Single src)
{
return (UInt16)src;
}
public static UInt32 CastSingleToUInt32(Single src)
{
return (UInt32)src;
}
public static UInt64 CastSingleToUInt64(Single src)
{
return (UInt64)src;
}
public static SByte CastSingleToSByte(Single src)
{
return (SByte)src;
}
public static Int16 CastSingleToInt16(Single src)
{
return (Int16)src;
}
public static Int32 CastSingleToInt32(Single src)
{
return (Int32)src;
}
public static Int64 CastSingleToInt64(Single src)
{
return (Int64)src;
}
public static Single CastSingleToSingle(Single src)
{
return (Single)src;
}
public static Double CastSingleToDouble(Single src)
{
return (Double)src;
}
public static Byte CastDoubleToByte(Double src)
{
return (Byte)src;
}
public static UInt16 CastDoubleToUInt16(Double src)
{
return (UInt16)src;
}
public static UInt32 CastDoubleToUInt32(Double src)
{
return (UInt32)src;
}
public static UInt64 CastDoubleToUInt64(Double src)
{
return (UInt64)src;
}
public static SByte CastDoubleToSByte(Double src)
{
return (SByte)src;
}
public static Int16 CastDoubleToInt16(Double src)
{
return (Int16)src;
}
public static Int32 CastDoubleToInt32(Double src)
{
return (Int32)src;
}
public static Int64 CastDoubleToInt64(Double src)
{
return (Int64)src;
}
public static Single CastDoubleToSingle(Double src)
{
return (Single)src;
}
public static Double CastDoubleToDouble(Double src)
{
return (Double)src;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d15ce8227d1aec64ab3fd82c4b271747
timeCreated: 1549025426
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,5 +1,11 @@
using System;
using System.IO;
using System.Linq.Expressions;
using System.Text;
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
#endif
namespace UniJSON
@@ -43,7 +49,7 @@ namespace UniJSON
}
}
static class GenericCast
static partial class GenericCast
{
public static Func<S, T> CreateCast<S, T>()
{