From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XUtliPoolLib/CVSReader.cs | 389 ++++++++++++++++++++++++ 1 file changed, 389 insertions(+) create mode 100644 Client/Assets/Scripts/XUtliPoolLib/CVSReader.cs (limited to 'Client/Assets/Scripts/XUtliPoolLib/CVSReader.cs') diff --git a/Client/Assets/Scripts/XUtliPoolLib/CVSReader.cs b/Client/Assets/Scripts/XUtliPoolLib/CVSReader.cs new file mode 100644 index 00000000..573afd35 --- /dev/null +++ b/Client/Assets/Scripts/XUtliPoolLib/CVSReader.cs @@ -0,0 +1,389 @@ +using System; +using System.IO; + +namespace XUtliPoolLib +{ + public abstract class CVSReader + { + public string error + { + get + { + return " line: " + this.lineno.ToString() + " column: " + this.columnno.ToString(); + } + } + + protected static CVSReader.FloatParse floatParse = new CVSReader.FloatParse(); + + protected static CVSReader.DoubleParse doubleParse = new CVSReader.DoubleParse(); + + protected static CVSReader.UIntParse uintParse = new CVSReader.UIntParse(); + + protected static CVSReader.IntParse intParse = new CVSReader.IntParse(); + + protected static CVSReader.LongParse longParse = new CVSReader.LongParse(); + + protected static CVSReader.StringParse stringParse = new CVSReader.StringParse(); + + protected static CVSReader.BoolParse boolParse = new CVSReader.BoolParse(); + + protected static CVSReader.ByteParse byteParse = new CVSReader.ByteParse(); + + protected static CVSReader.ShortParse shortParse = new CVSReader.ShortParse(); + + public int lineno = -1; + + public int columnno = -1; + + protected DataHandler m_DataHandler = null; + + public abstract class ValueParse + { + public abstract T[] GetBuffer(DataHandler dh); + + public abstract void Read(XBinaryReader stream, ref T t, CVSReader reader); + } + + public sealed class UIntParse : CVSReader.ValueParse + { + public override uint[] GetBuffer(DataHandler dh) + { + return dh.uintBuffer; + } + + public override void Read(XBinaryReader stream, ref uint t, CVSReader reader) + { + t = stream.ReadUInt32(); + } + } + + public sealed class IntParse : CVSReader.ValueParse + { + public override int[] GetBuffer(DataHandler dh) + { + return dh.intBuffer; + } + + public override void Read(XBinaryReader stream, ref int t, CVSReader reader) + { + t = stream.ReadInt32(); + } + } + + public sealed class LongParse : CVSReader.ValueParse + { + public override long[] GetBuffer(DataHandler dh) + { + return dh.longBuffer; + } + + public override void Read(XBinaryReader stream, ref long t, CVSReader reader) + { + t = stream.ReadInt64(); + } + } + + public sealed class FloatParse : CVSReader.ValueParse + { + public override float[] GetBuffer(DataHandler dh) + { + return dh.floatBuffer; + } + + public override void Read(XBinaryReader stream, ref float t, CVSReader reader) + { + t = stream.ReadSingle(); + } + } + + public sealed class DoubleParse : CVSReader.ValueParse + { + public override double[] GetBuffer(DataHandler dh) + { + return dh.doubleBuffer; + } + + public override void Read(XBinaryReader stream, ref double t, CVSReader reader) + { + t = stream.ReadDouble(); + } + } + + public sealed class StringParse : CVSReader.ValueParse + { + public override string[] GetBuffer(DataHandler dh) + { + return dh.stringBuffer; + } + + public override void Read(XBinaryReader stream, ref string t, CVSReader reader) + { + bool flag = reader.m_DataHandler != null; + if (flag) + { + t = reader.m_DataHandler.ReadString(stream); + } + else + { + t = string.Intern(stream.ReadString(-1)); + } + } + } + + public sealed class BoolParse : CVSReader.ValueParse + { + public override bool[] GetBuffer(DataHandler dh) + { + return null; + } + + public override void Read(XBinaryReader stream, ref bool t, CVSReader reader) + { + t = stream.ReadBoolean(); + } + } + + public sealed class ByteParse : CVSReader.ValueParse + { + public override byte[] GetBuffer(DataHandler dh) + { + return null; + } + + public override void Read(XBinaryReader stream, ref byte t, CVSReader reader) + { + t = stream.ReadByte(); + } + } + + public sealed class ShortParse : CVSReader.ValueParse + { + public short[] buffer = null; + + public override short[] GetBuffer(DataHandler dh) + { + return null; + } + + public override void Read(XBinaryReader stream, ref short t, CVSReader reader) + { + t = stream.ReadInt16(); + } + } + + public delegate int RowDataCompare(Trowdata rowData, Ttype key); + + public static void Init() + { + SeqRef.parser = CVSReader.stringParse; + SeqRef.parser = CVSReader.intParse; + SeqRef.parser = CVSReader.uintParse; + SeqRef.parser = CVSReader.longParse; + SeqRef.parser = CVSReader.floatParse; + SeqRef.parser = CVSReader.doubleParse; + SeqListRef.parser = CVSReader.stringParse; + SeqListRef.parser = CVSReader.intParse; + SeqListRef.parser = CVSReader.uintParse; + SeqListRef.parser = CVSReader.longParse; + SeqListRef.parser = CVSReader.floatParse; + SeqListRef.parser = CVSReader.doubleParse; + } + + public CVSReader() + { + this.lineno = 1; + } + + public bool ReadFile(XBinaryReader reader) + { + this.lineno = 0; + this.columnno = -1; + int num = reader.ReadInt32(); + int num2 = reader.ReadInt32(); + this.OnClear(num2); + this.m_DataHandler = new DataHandler(); + this.m_DataHandler.Init(reader); + byte b = reader.ReadByte(); + for (int i = 0; i < (int)b; i++) + { + byte b2 = reader.ReadByte(); + byte b3 = reader.ReadByte(); + } + for (int j = 0; j < num2; j++) + { + int num3 = reader.ReadInt32(); + int position = reader.GetPosition(); + this.ReadLine(reader); + int position2 = reader.GetPosition(); + int num4 = position2 - position; + bool flag = num3 > num4; + if (flag) + { + reader.Seek(num3 - num4, SeekOrigin.Current); + } + else + { + bool flag2 = num3 < num4; + if (flag2) + { + XSingleton.singleton.AddErrorLog2("read table error:{0} line:{1} column:{2}", new object[] + { + base.GetType().Name, + this.lineno + 1, + this.columnno + }); + break; + } + } + this.lineno++; + bool flag3 = this.columnno > 0; + if (flag3) + { + break; + } + } + int position3 = reader.GetPosition(); + bool flag4 = position3 != num; + if (flag4) + { + XSingleton.singleton.AddErrorLog2("read table error:{0} size:{1} read size:{2}", new object[] + { + base.GetType().Name, + num, + position3 + }); + } + this.m_DataHandler.UnInit(false); + return this.columnno == -1; + } + + public void Clear() + { + this.OnClear(0); + } + + protected bool Read(XBinaryReader stream, ref T v, CVSReader.ValueParse parse) + { + parse.Read(stream, ref v, this); + return true; + } + + protected bool ReadArray(XBinaryReader stream, ref T[] v, CVSReader.ValueParse parse) + { + byte b = stream.ReadByte(); + bool flag = b > 0; + if (flag) + { + v = new T[(int)b]; + for (byte b2 = 0; b2 < b; b2 += 1) + { + parse.Read(stream, ref v[(int)b2], this); + } + } + else + { + v = null; + } + return true; + } + + protected abstract void OnClear(int lineCount); + + protected virtual void ReadLine(XBinaryReader reader) + { + } + + public static void GetRowDataListByField(Trowdata[] table, Ttype field, out int startIndex, out int endIndex, CVSReader.RowDataCompare comp) where Ttype : IComparable + { + startIndex = -1; + endIndex = -1; + int num = 0; + int num2 = table.Length - 1; + int num3 = -1; + int num4; + for (;;) + { + Trowdata rowData = table[num]; + bool flag = comp(rowData, field) == 0; + if (flag) + { + break; + } + Trowdata rowData2 = table[num2]; + bool flag2 = comp(rowData2, field) == 0; + if (flag2) + { + goto Block_2; + } + bool flag3 = num2 - num <= 1; + if (flag3) + { + goto Block_3; + } + num4 = num + (num2 - num) / 2; + Trowdata rowData3 = table[num4]; + bool flag4 = comp(rowData3, field) < 0; + if (flag4) + { + num2 = num4; + } + else + { + bool flag5 = comp(rowData3, field) > 0; + if (!flag5) + { + goto IL_AE; + } + num = num4; + } + if (num >= num2) + { + goto IL_C2; + } + } + num3 = num; + goto IL_C2; + Block_2: + num3 = num2; + Block_3: + goto IL_C2; + IL_AE: + num3 = num4; + IL_C2: + bool flag6 = num3 >= 0; + if (flag6) + { + startIndex = num3; + endIndex = num3; + bool flag7 = num3 > 0; + if (flag7) + { + for (int i = num3 - 1; i >= 0; i--) + { + Trowdata rowData4 = table[i]; + bool flag8 = comp(rowData4, field) != 0; + if (flag8) + { + break; + } + startIndex = i; + } + } + bool flag9 = num3 < table.Length - 1; + if (flag9) + { + for (int j = num3 + 1; j < table.Length; j++) + { + Trowdata rowData5 = table[j]; + bool flag10 = comp(rowData5, field) != 0; + if (flag10) + { + break; + } + endIndex = j; + } + } + } + } + } +} -- cgit v1.1-26-g67d0