public void Load(TableRowBuffer buffer) { m_Id = TableExtracter.ExtractNumeric <int>(buffer, "Id", 0); m_Name = TableExtracter.ExtractString(buffer, "Name", ""); m_Type = TableExtracter.ExtractNumeric <int>(buffer, "Type", 0); OnLoadConfig(); }
public static string[] ExtractStringArray(TableRowBuffer node, string nodeName, string[] defaultVal) { List <string> list = ExtractStringList(node, nodeName, defaultVal); if (null != list) { return(list.ToArray()); } else { return(null); } }
public static T[] ExtractNumericArray <T>(TableRowBuffer node, string nodeName, T[] defaultVal) { List <T> list = ExtractNumericList <T>(node, nodeName, defaultVal); if (null != list) { return(list.ToArray()); } else { return(null); } }
public string GetData(int rowIdx, int colIdx) { if (rowIdx < 0 || rowIdx >= _rowCnt || colIdx < 0 || colIdx >= _colCnt) { return(string.Empty); } TableRowBuffer dbRow = GetRowBuffer(rowIdx); if (dbRow != null) { return(dbRow.GetDataByIdx(colIdx)); } return(string.Empty); }
public static string ExtractString(TableRowBuffer node, string nodeName, string defaultVal) { string result = defaultVal; if (node == null || !node.HasFields || node.GetDataByName(nodeName) == null) { return(result); } string nodeText = node.GetDataByName(nodeName); if (!string.IsNullOrEmpty(nodeText)) { result = nodeText; } return(result); }
public static List <T> ExtractNumericList <T>(TableRowBuffer node, string nodeName, T defaultVal, bool isMust) { List <T> result = new List <T>(); if (node == null || !node.HasFields || node.GetDataByName(nodeName) == null) { return(result); } string nodeText = node.GetDataByName(nodeName); if (!string.IsNullOrEmpty(nodeText)) { result = Converter.ConvertNumericList <T>(nodeText); } return(result); }
public void Load(string path) { TableBuffer document = new TableBuffer(path); document.Load(); for (int index = 0; index < document.RowCnt; index++) { TableRowBuffer node = document.GetRowBuffer(index); try { TData data = new TData(); data.Load(node); Add(data); } catch (System.Exception ex) { GameLog.Error("ITable load file({0}) row(1) failed.Exception:{2}\n{3}", path, node.Idx, ex.Message, ex.StackTrace); } } OnLoadTable(); GameLog.Info("ITable load file({0}) done.", path); }
public static List <string> ExtractStringList(TableRowBuffer node, string nodeName, string[] defaultVal) { List <string> result = new List <string>(); if (node == null || !node.HasFields) { return(result); } string nodeText = node.GetDataByName(nodeName); if (!string.IsNullOrEmpty(nodeText)) { result = Converter.ConvertStringList(nodeText); } else if (null != defaultVal) { result.AddRange(defaultVal); } return(result); }
public static T ExtractNumeric <T>(TableRowBuffer node, string nodeName, T defaultVal) { T result = defaultVal; if (node == null || !node.HasFields || node.GetDataByName(nodeName) == null) { return(result); } string nodeText = node.GetDataByName(nodeName); if (!string.IsNullOrEmpty(nodeText)) { try { result = (T)Convert.ChangeType(nodeText, typeof(T)); } catch (System.Exception ex) { GameLog.Error("ExtractNumeric {0} {1} Exception:{2}/{3}", nodeName, nodeText, ex.Message, ex.StackTrace); throw; } } return(result); }
public static bool ExtractBool(TableRowBuffer node, string nodeName, bool defaultVal) { bool result = defaultVal; if (node == null || !node.HasFields || node.GetDataByName(nodeName) == null) { return(result); } string nodeText = node.GetDataByName(nodeName); if (!string.IsNullOrEmpty(nodeText)) { if (nodeText.Trim().ToLower() == "true" || nodeText.Trim().ToLower() == "1") { result = true; } if (nodeText.Trim().ToLower() == "false" || nodeText.Trim().ToLower() == "0") { result = false; } } return(result); }
public virtual void Load(TableRowBuffer row) { }
public static T ExtractEnum <T>(TableRowBuffer node, string nodeName, T defaultVal) { return((T)(object)(ExtractNumeric <int>(node, nodeName, (int)(object)(defaultVal)))); }
public static T ExtractNumeric <T>(TableRowBuffer node, string nodeName, T defaultVal, bool isMust) { return(ExtractNumeric <T>(node, nodeName, defaultVal)); }
public static bool ExtractBool(TableRowBuffer node, string nodeName, bool defaultVal, bool isMust) { return(ExtractBool(node, nodeName, defaultVal)); }
public static string ExtractString(TableRowBuffer node, string nodeName, string defaultVal, bool isMust) { return(ExtractString(node, nodeName, defaultVal)); }
private void ParseStream(StreamReader sr) { //-------------------------------------------------------------- //临时变量 string[] dataArray = null; string strLine = ""; //读第一行,标题行 strLine = sr.ReadLine(); //读取失败,即认为读取结束 if (strLine == null) { throw new Exception("TableBuffer Field null."); } dataArray = strLine.Split(_split, StringSplitOptions.None); if (dataArray == null || dataArray.Length == 0) { throw new Exception("TableBuffer Field split failed."); } this._fileds = new List <string>(dataArray); //-------------------------------------------------------------- //初始化 int rowIdx = 0; int fieldCnt = dataArray.Length; //-------------------------------------------------------------- //开始读取 TableRowBuffer rowBuffer = null; List <string> dataList = null; do { rowBuffer = null; //读取一行 strLine = sr.ReadLine(); //读取失败,即认为读取结束 if (strLine == null) { break; } //是否是注释行 if (strLine.Trim().StartsWith("#")) { continue; } if (strLine.Trim().StartsWith("\"#")) { continue; } //分解 dataArray = strLine.Split(_split, StringSplitOptions.None); //第一列不能为空 if (string.IsNullOrEmpty(dataArray[0])) { continue; } //列数不对 if (dataArray == null || dataArray.Length == 0) { continue; } dataList = new List <string>(dataArray); if (dataArray.Length != fieldCnt) { //补上空格 if (dataArray.Length < fieldCnt) { int nSubNum = fieldCnt - dataArray.Length; for (int i = 0; i < nSubNum; i++) { dataList.Add(""); } } } rowBuffer = new TableRowBuffer(this, rowIdx); rowBuffer.Data = dataList; _data.Add(rowBuffer); rowIdx++; } while (true); //-------------------------------------------------------- //生成正式数据库 _colCnt = fieldCnt; _rowCnt = rowIdx; //创建索引 CreateIndex(); }