public FieldDefine GetDefine(int index) { FieldDefine temp = null; m_Define_IndexMap.TryGetValue(index, out temp); return(temp); }
public FieldDefine GetDefine(string name) { FieldDefine temp = null; m_Define_NameMap.TryGetValue(name, out temp); return(temp); }
/// <summary> /// Generate the .cs file. /// </summary> /// <param name="schema">schema</param> /// <param name="path">folder path</param> public void Generate(Schema schema, string path) { StringBuilder builder = new StringBuilder(); builder.Append("using TD;\r\n"); builder.Append("namespace TDStruct\r\n"); builder.Append("{\r\n"); builder.Append("public class " + schema.ClassName + " : ITDStruct\r\n"); builder.Append("\t{\r\n"); for (int i = 0; i < schema.Count; i++) { FieldDefine fd = schema.GetDefine(i); string fd_type_str = "int"; switch (fd.FieldType) { case FIELD_TYPE.T_FLOAT: fd_type_str = "float"; break; case FIELD_TYPE.T_STRING: fd_type_str = "string"; break; } builder.Append("\t\tpublic " + fd_type_str + " " + fd.FieldName + ";\r\n"); } builder.Append("\t\tpublic void Init(Row row)\r\n"); builder.Append("\t\t{\r\n"); for (int i = 0; i < schema.Count; i++) { FieldDefine fd = schema.GetDefine(i); string fd_get_value_str = ".GetInt()"; switch (fd.FieldType) { case FIELD_TYPE.T_FLOAT: fd_get_value_str = ".GetFloat()"; break; case FIELD_TYPE.T_STRING: fd_get_value_str = ".GetString()"; break; } builder.Append("\t\t\t" + fd.FieldName + " = row.GetField(" + fd.Index.ToString() + ")" + fd_get_value_str + ";\r\n"); } builder.Append("\t\t}\r\n"); builder.Append("\t}\r\n"); builder.Append("}\r\n"); //output file File.WriteAllText(path + "TD_" + schema.ClassName + ".cs", builder.ToString(), Encoding.UTF8); }
//load Data To Reader. void LoadData() { if (m_Schema == null) { return; } for (int i = 0; i < m_recordsNumber; ++i) { Row tempRow = new Row(m_Schema); for (int j = 0; j < m_Schema.Count; ++j) { FieldDefine tempDefine = m_Schema.GetDefine(j); Field tempField = null; switch (tempDefine.FieldType) { case FIELD_TYPE.T_INT: int tempInt = m_Reader.ReadInt32(); tempField = new Field(tempInt); break; case FIELD_TYPE.T_FLOAT: float tempFloat = m_Reader.ReadSingle(); tempField = new Field(tempFloat); break; case FIELD_TYPE.T_STRING: string tempString = m_Reader.ReadString(); tempField = new Field(tempString); break; default: tempField = new Field(0); //Debug.Log("Undefined Field Type"); break; } tempRow.m_Fields.Add(tempField); } mRowList.Add(tempRow); } }
bool WriteData(Row[] a_rows, Schema a_schema) { if (!InitWriter()) { return(false); } foreach (Row row in a_rows) { for (int i = 0; i < a_schema.Count; ++i) { FieldDefine define = a_schema.GetDefine(i); switch (define.FieldType) { case FIELD_TYPE.T_INT: m_Writer.Write((int)row.GetField(i).m_Value); break; case FIELD_TYPE.T_FLOAT: m_Writer.Write((float)row.GetField(i).m_Value); break; case FIELD_TYPE.T_STRING: m_Writer.Write(row.GetField(i).m_Value.ToString()); break; case FIELD_TYPE.T_INVALID: //Debug.LogError("Wrong Field Type."); break; default: break; } } } return(true); }
void LoadSchema() { if (m_Schema == null) { m_Schema = new Schema(); m_Schema.ClassName = m_FileName; int identity = m_Reader.ReadInt32(); if (m_Identity != identity) { return; } //read record number m_recordsNumber = m_Reader.ReadInt32(); //read column number int columnNumber = m_Reader.ReadInt32(); //create field define and fill field name. for (int i = 0; i < columnNumber; ++i) { FieldDefine define = new FieldDefine(); define.FieldName = m_Reader.ReadString(); define.Index = i; m_Schema.AddDefine(define); } //read field type. for (int i = 0; i < columnNumber; ++i) { FieldDefine define = m_Schema.GetDefine(i); define.FieldType = (FIELD_TYPE)m_Reader.ReadInt32(); } } }
void LoadSchema() { if (m_Schema == null) { m_Schema = new Schema(); m_Schema.ClassName = m_FileName; int identity = m_Reader.ReadInt32(); if (m_Identity != identity) { return; } //read record number m_recordsNumber = m_Reader.ReadInt32(); //read column number int columnNumber = m_Reader.ReadInt32(); //create field define and fill field name. for (int i = 0; i < columnNumber; ++i) { FieldDefine define = new FieldDefine(); define.FieldName = m_Reader.ReadString(); define.Index = i; m_Schema.AddDefine(define); } //read field type. for (int i = 0; i < columnNumber; ++i) { FieldDefine define = m_Schema.GetDefine(i); define.FieldType = (FIELD_TYPE)m_Reader.ReadInt32(); } } }
public Field GetField(string fieldName) { FieldDefine define = m_Schema.GetDefine(fieldName); return(GetField(define.Index)); }
public FieldDefine AddDefine(FieldDefine a_FieldDefine) { m_Define_IndexMap.Add(a_FieldDefine.Index, a_FieldDefine); m_Define_NameMap.Add(a_FieldDefine.FieldName, a_FieldDefine); return(a_FieldDefine); }
public FieldDefine AddDefine(FieldDefine a_FieldDefine) { m_Define_IndexMap.Add(a_FieldDefine.Index, a_FieldDefine); m_Define_NameMap.Add(a_FieldDefine.FieldName, a_FieldDefine); return a_FieldDefine; }