Beispiel #1
0
        public Row Search_First_Column_Equ(int field, object value)
        {
            foreach (Row item_row in m_DataRows)
            {
                switch (m_Schema.GetDefine(field).FieldType)
                {
                case FIELD_TYPE.T_INT:
                    if ((int)value == (int)item_row.m_Fields[field].m_Value)
                    {
                        return(item_row);
                    }
                    break;

                case FIELD_TYPE.T_FLOAT:
                    if ((float)value == (float)item_row.m_Fields[field].m_Value)
                    {
                        return(item_row);
                    }
                    break;

                case FIELD_TYPE.T_STRING:
                    if ((string)value == (string)item_row.m_Fields[field].m_Value)
                    {
                        return(item_row);
                    }
                    break;
                }
            }
            return(null);
        }
Beispiel #2
0
        bool WriteSchema(Schema a_schema, int a_recordsNumber)
        {
            if (!InitWriter())
            {
                return(false);
            }

            //Write int ----- Identity
            m_Writer.Write(m_Identity);

            //Write int ----- RecordsNumber
            m_Writer.Write(a_recordsNumber);

            //Write int ----- columnsNumber
            m_Writer.Write(a_schema.Count);

            //Write string * columnsNumber ----- FieldName
            for (int i = 0; i < a_schema.Count; ++i)
            {
                m_Writer.Write(a_schema.GetDefine(i).FieldName);
            }

            //Write int * columnsNumber ------ FieldType
            for (int i = 0; i < a_schema.Count; ++i)
            {
                m_Writer.Write((int)a_schema.GetDefine(i).FieldType);
            }

            return(true);
        }
Beispiel #3
0
        /// <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);
            }
        }
Beispiel #5
0
        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();
                }
            }
        }
Beispiel #7
0
        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();
                }
            }
        }
Beispiel #8
0
        bool WriteSchema(Schema a_schema, int a_recordsNumber)
        {
            if (!InitWriter())
            {
                return false;
            }

            //Write int ----- Identity
            m_Writer.Write(m_Identity);

            //Write int ----- RecordsNumber
            m_Writer.Write(a_recordsNumber);

            //Write int ----- columnsNumber
            m_Writer.Write(a_schema.Count);

            //Write string * columnsNumber ----- FieldName
            for (int i = 0; i < a_schema.Count; ++i)
            {
                m_Writer.Write(a_schema.GetDefine(i).FieldName);
            }

            //Write int * columnsNumber ------ FieldType
            for (int i = 0; i < a_schema.Count; ++i)
            {
                m_Writer.Write((int)a_schema.GetDefine(i).FieldType);
            }

            return true;
        }
Beispiel #9
0
        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;
        }
Beispiel #10
0
        public Field GetField(string fieldName)
        {
            FieldDefine define = m_Schema.GetDefine(fieldName);

            return(GetField(define.Index));
        }