Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#@ template debug="true" hostspecific="false" language="C#" #>
- <#@ assembly name="System.Core" #>
- <#@ import namespace="System.Linq" #>
- <#@ import namespace="System.Text" #>
- <#@ import namespace="System.Collections.Generic" #>
- <#@ output extension=".cs" #>
- <#
- Dictionary<string, TypeInfo> types = new Dictionary<string, TypeInfo>()
- {
- { "Decimal", new TypeInfo() { Type = typeof(decimal), TypeName = "Decimal", Name = "Decimal", Signed = true, Decimal = true, MateName = null, BitCount = 128, ConvertTo = new Dictionary<string, string>(), ConvertFrom = new Dictionary<string, string>() } },
- { "Double", new TypeInfo() { Type = typeof(double), TypeName = "Double", Name = "Double", Signed = true, Decimal = true, MateName = null, BitCount = 64, ConvertTo = new Dictionary<string, string>(), ConvertFrom = new Dictionary<string, string>() } },
- { "Float", new TypeInfo() { Type = typeof(Single), TypeName = "Single", Name = "Float", Signed = true, Decimal = true, MateName = null, BitCount = 32, ConvertTo = new Dictionary<string, string>(), ConvertFrom = new Dictionary<string, string>() } },
- { "Byte", new TypeInfo() { Type = typeof(byte), TypeName = "Byte", Name = "Byte", Signed = false, Decimal = false, MateName = "SByte", BitCount = 8, ConvertTo = new Dictionary<string, string>(), ConvertFrom = new Dictionary<string, string>() } },
- { "SByte", new TypeInfo() { Type = typeof(sbyte), TypeName = "SByte", Name = "SByte", Signed = true, Decimal = false, MateName = "Byte", BitCount = 8, ConvertTo = new Dictionary<string, string>(), ConvertFrom = new Dictionary<string, string>() } },
- { "Short", new TypeInfo() { Type = typeof(Int16), TypeName = "Int16", Name = "Short", Signed = true, Decimal = false, MateName = "UShort", BitCount = 16, ConvertTo = new Dictionary<string, string>(), ConvertFrom = new Dictionary<string, string>() } },
- { "UShort", new TypeInfo() { Type = typeof(UInt16), TypeName = "UInt16", Name = "UShort", Signed = false, Decimal = false, MateName = "Short", BitCount = 16, ConvertTo = new Dictionary<string, string>(), ConvertFrom = new Dictionary<string, string>() } },
- { "Int", new TypeInfo() { Type = typeof(Int32), TypeName = "Int32", Name = "Int", Signed = true, Decimal = false, MateName = "UInt", BitCount = 32, ConvertTo = new Dictionary<string, string>(), ConvertFrom = new Dictionary<string, string>() } },
- { "UInt", new TypeInfo() { Type = typeof(UInt32), TypeName = "UInt32", Name = "UInt", Signed = false, Decimal = false, MateName = "Int", BitCount = 32, ConvertTo = new Dictionary<string, string>(), ConvertFrom = new Dictionary<string, string>() } },
- { "Long", new TypeInfo() { Type = typeof(Int64), TypeName = "Int64", Name = "Long", Signed = true, Decimal = false, MateName = "ULong", BitCount = 64, ConvertTo = new Dictionary<string, string>(), ConvertFrom = new Dictionary<string, string>() } },
- { "ULong", new TypeInfo() { Type = typeof(UInt64), TypeName = "UInt64", Name = "ULong", Signed = false, Decimal = false, MateName = "Long", BitCount = 64, ConvertTo = new Dictionary<string, string>(), ConvertFrom = new Dictionary<string, string>() } }
- };
- #>
- using System;
- //using XGEFCore;
- using test;
- //****************************
- //****************************
- //
- // THE BELOW CODE IS AUTOGENERATED. Please do not bother editing it, instead please see the template that it was generated from.
- //
- //****************************
- //****************************
- namespace Stats
- {
- <# foreach(var pair in types) {
- string T = pair.Value.Type.Name;
- string Class = pair.Key + "Stat"; #>
- public class <#= Class #> : NumericStat<<#= T #>>
- {
- public override <#= T #> MaxValue { get { return Math.Min(<#= T #>.MaxValue, MaxLimit); } }
- public override <#= T #> MinValue { get { return Math.Max(<#= T #>.MinValue, MinLimit); } }
- #region IComparable
- public override int CompareTo(object obj)
- {
- if (obj == null)
- return 1;
- if(obj is IData)
- {
- return Value.CompareTo(((IData)obj).Data);
- }
- return Value.CompareTo(obj);
- }
- #endregion
- #region IConvertible
- public override TypeCode GetTypeCode()
- {
- return TypeCode.<#= pair.Value.TypeName #>;
- }
- public override bool ToBoolean(IFormatProvider provider)
- {
- if(Value == 0)
- return false;
- return true;
- }
- public override char ToChar(IFormatProvider provider)
- {
- return Convert.ToChar(Value);
- }
- public override sbyte ToSByte(IFormatProvider provider)
- {
- return Convert.ToSByte(Value);
- }
- public override byte ToByte(IFormatProvider provider)
- {
- return Convert.ToByte(Value);
- }
- public override short ToInt16(IFormatProvider provider)
- {
- return Convert.ToInt16(Value);
- }
- public override ushort ToUInt16(IFormatProvider provider)
- {
- return Convert.ToUInt16(Value);
- }
- public override int ToInt32(IFormatProvider provider)
- {
- return Convert.ToInt32(Value);
- }
- public override uint ToUInt32(IFormatProvider provider)
- {
- return Convert.ToUInt32(Value);
- }
- public override long ToInt64(IFormatProvider provider)
- {
- return Convert.ToInt64(Value);
- }
- public override ulong ToUInt64(IFormatProvider provider)
- {
- return Convert.ToUInt64(Value);
- }
- public override float ToSingle(IFormatProvider provider)
- {
- return Convert.ToSingle(Value);
- }
- public override double ToDouble(IFormatProvider provider)
- {
- return Convert.ToDouble(Value);
- }
- public override decimal ToDecimal(IFormatProvider provider)
- {
- return Convert.ToDecimal(Value);
- }
- public override string ToString(IFormatProvider provider)
- {
- return Convert.ToString(Value);
- }
- public override object ToType(Type conversionType, IFormatProvider provider)
- {
- return Convert.ChangeType(Value, conversionType);
- }
- #endregion
- #region Type Casting
- <# foreach(var typePair in types) {
- string typeName = typePair.Value.Type.Name;
- string otherStat = typePair.Value.Name + "Stat";
- string castingTypeTo = "explicit";
- string castingTypeFrom = "explicit";
- //this class is a container for the casting type
- if(typeName == T)
- {
- castingTypeTo = "implicit";
- castingTypeFrom = "implicit";
- }
- //this class is an integer
- else if(!pair.Value.Decimal)
- {
- //integers only cast to the target if it's the same sign and big enough to fit (or it's a real type)
- if(typePair.Value.Decimal || typePair.Value.Signed == pair.Value.Signed && pair.Value.BitCount <= typePair.Value.BitCount)
- castingTypeTo = "implicit";
- //target can only cast to integer if target is also an integer and the signing matches and this integer is big enough to fit target
- if(!typePair.Value.Decimal && typePair.Value.Signed == pair.Value.Signed && pair.Value.BitCount >= typePair.Value.BitCount)
- castingTypeFrom = "implicit";
- }
- //this class is a real type
- else if(typePair.Value.Decimal)
- {
- //floats can cast to doubles, but not the other way around, so detect that accordingly
- if(T == "Single" && typeName == "Double")
- castingTypeTo = "implicit";
- if(typeName == "Single" && T == "Double")
- castingTypeFrom = "implicit";
- }
- pair.Value.ConvertFrom[typeName] = castingTypeFrom;
- pair.Value.ConvertTo[typeName] = castingTypeTo; #>
- public static <#= castingTypeTo #> operator <#= typeName #>(<#= Class #> stat)
- {
- return Convert.To<#= typeName #>(stat.Value);
- }
- <# if(otherStat != Class) { #>
- public static <#= castingTypeFrom #> operator <#= Class #>(<#= otherStat #> stat)
- {
- return new <#= Class #>(stat.Name, (<#= T #>)stat.Value, (<#= T #>)stat.MinValue, (<#= T #>)stat.MaxValue, stat.Description, stat.Notes);
- }<# } #>
- public static <#= castingTypeFrom #> operator <#= Class #>(<#= typeName #> num)
- {
- <#= Class #> stat = new <#= Class #>();
- <# if(castingTypeFrom == "explicit") { #>
- if((<#= T #>)num > stat.MaxLimit)
- stat.Set(stat.MaxLimit);
- else if((<#= T #>)num < stat.MinLimit)
- stat.Set(stat.MinLimit);
- else <# } #>
- stat.Set((<#= T #>)num);
- return stat;
- }
- <# } #>
- #endregion
- #region Operator Overloading
- <# foreach(var typePair in types) {
- string otherT = typePair.Value.Type.Name;
- string otherClass = typePair.Value.Name + "Stat";#>
- public static <#= Class #> operator +(<#= Class #> lhs, <#= otherT #> rhs)
- {
- <#= Class #> result = lhs.Copy();
- result.Set((<#= T #>)(lhs.Value + (<#= T #>)rhs));
- return result;
- }
- public static <#= Class #> operator -(<#= Class #> lhs, <#= otherT #> rhs)
- {
- <#= Class #> result = lhs.Copy();
- result.Set((<#= T #>)(lhs.Value - (<#= T #>)rhs));
- return result;
- }
- public static <#= Class #> operator *(<#= Class #> lhs, <#= otherT #> rhs)
- {
- <#= Class #> result = lhs.Copy();
- result.Set((<#= T #>)(lhs.Value * (<#= T #>)rhs));
- return result;
- }
- public static <#= Class #> operator /(<#= Class #> lhs, <#= otherT #> rhs)
- {
- <#= Class #> result = lhs.Copy();
- result.Set((<#= T #>)(lhs.Value / (<#= T #>)rhs));
- return result;
- }
- public static <#= Class #> operator %(<#= Class #> lhs, <#= otherT #> rhs)
- {
- <#= Class #> result = lhs.Copy();
- result.Set((<#= T #>)(lhs.Value % (<#= T #>)rhs));
- return result;
- }
- public static <#= Class #> operator ^(<#= Class #> lhs, <#= otherT #> rhs)
- {
- <#= Class #> result = lhs.Copy();
- result.Set((<#= T #>)Math.Pow((double)lhs.Value, (double)rhs));
- return result;
- }
- public static bool operator >(<#= Class #> lhs, <#= otherT #> rhs)
- {
- return lhs.CompareTo(rhs) > 0;
- }
- public static bool operator <(<#= Class #> lhs, <#= otherT #> rhs)
- {
- return lhs.CompareTo(rhs) < 0;
- }
- <# } #>
- #endregion
- public <#= Class #> Copy()
- {
- return new <#= Class #>(Name, Value, MinLimit, MaxLimit, Description, Notes);
- }
- public <#= Class #>() : this("UnnamedStat", 0, <#= T #>.MinValue, <#= T #>.MaxValue, null, null) { }
- public <#= Class #>(string name) : this(name, 0, <#= T #>.MinValue, <#= T #>.MaxValue, null, null) { }
- public <#= Class #>(string name, <#= T #> value) : this(name, value, <#= T #>.MinValue, <#= T #>.MaxValue, null, null) { }
- public <#= Class #>(string name, <#= T #> value, <#= T #> min, <#= T #> max) : this(name, value, min, max, null, null) { }
- public <#= Class #>(string name, <#= T #> value, <#= T #> min, <#= T #> max, string desc, string notes) : base(name, value, min, max, desc, notes) { }
- public override string ToString() { return Value.ToString(); }
- }
- <# } #>
- }
- <#+
- public struct TypeInfo
- {
- public Type Type { get; set; }
- public string Name { get; set; }
- public string TypeName { get; set; }
- public bool Signed { get; set; }
- public bool Decimal { get; set; }
- public string MateName { get; set; }
- public int BitCount { get; set; }
- public Dictionary<string, string> ConvertTo { get; set; }
- public Dictionary<string, string> ConvertFrom{ get; set; }
- }
- #>
Advertisement
Add Comment
Please, Sign In to add comment