Ejemplo n.º 1
0
        /// <summary>
        /// 获取一个数据对象,数据类型必须为DataType中任意一种
        /// </summary>
        /// <param name="index">元素索引</param>
        /// <param name="offset">子元素偏移</param>
        /// <returns></returns>
        public unsafe object GetData(int index, int offset)
        {
            int    o = (index * m_size + offset) * 4;
            Int32 *a = (Int32 *)(ip + o);

            return(buffer.GetData(*a));
        }
Ejemplo n.º 2
0
        public unsafe T GetData <T>(int index) where T : class
        {
            if (index < 0)
            {
                return(null);
            }
            if (index >= element)
            {
                return(null);
            }
            int    o = index * 4;
            Int32 *a = (Int32 *)(ip + o);

            return(buffer.GetData(*a) as T);
        }
Ejemplo n.º 3
0
        public unsafe object GetData(int index)
        {
            int    o = index * 4;
            Int32 *a = (Int32 *)(ip + o);

            return(buffer.GetData(*a));
        }
Ejemplo n.º 4
0
 object ReadObjectList(DataFieldInfo info, DataBuffer buffer, Object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             var   con  = info.Construction();
             IList list = con as IList;
             for (int i = 0; i < addr16.Length; i++)
             {
                 var fs = buffer.GetData(addr16[i]) as FakeStruct;
                 if (fs != null)
                 {
                     list.Add(ReadObject(info.typeInfo, fs, addr16[i]));
                 }
                 else
                 {
                     list.Add(null);
                 }
             }
             return(con);
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool  isStruct = info.typeInfo.isStruct;
                 var   con      = info.Construction();
                 IList list     = con as IList;
                 for (int i = 0; i < addr32.Length; i++)
                 {
                     int a     = addr32[i];
                     int index = a & 0xffff;
                     var fs    = buffer.GetData(index) as FakeStruct;
                     if (fs != null)
                     {
                         if (isStruct)//结构体无法使用继承
                         {
                             list.Add(ReadObject(info.typeInfo, fs, index));
                         }
                         else
                         {
                             var dt = oldTypes[a >> 16].NewType; //使用继承类型
                             if (dt == null)                     //没有找到继承类型则使用默认类型
                             {
                                 list.Add(null);
                             }
                             else
                             {
                                 list.Add(ReadObject(dt, fs, index));
                             }
                         }
                     }
                     else
                     {
                         list.Add(null);
                     }
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var   con  = info.Construction();
                     IList list = con as IList;
                     for (int i = 0; i < fsa.Length; i++)
                     {
                         unsafe { fs.SetPoint(fsa[i]); }
                         list.Add(ReadStruct(info.typeInfo, fs, 0));
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }
Ejemplo n.º 5
0
 object ReadObjectArray(DataFieldInfo info, DataBuffer buffer, Object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             var   con  = info.ArrayConstruction(addr16.Length);
             Array arry = con as Array;
             if (arry != null)
             {
                 for (int i = 0; i < addr16.Length; i++)
                 {
                     var fs = buffer.GetData(addr16[i]) as FakeStruct;
                     if (fs != null)
                     {
                         arry.SetValue(ReadObject(info.typeInfo, fs, addr16[i]), i);
                     }
                 }
             }
             return(con);
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool  isStruct = info.typeInfo.isStruct;
                 var   con      = info.ArrayConstruction(addr32.Length);
                 Array arry     = con as Array;
                 if (arry == null)
                 {
                     for (int i = 0; i < addr32.Length; i++)
                     {
                         int a     = addr32[i];
                         int index = a & 0xffff;
                         var fs    = buffer.GetData(index) as FakeStruct;
                         if (fs != null)
                         {
                             if (isStruct)//结构体无法使用继承
                             {
                                 arry.SetValue(ReadObject(info.typeInfo, fs, index), i);
                             }
                             else
                             {
                                 var dt = oldTypes[a >> 16].NewType;//使用继承类型
                                 if (dt == null)
                                 {
                                     dt = info.typeInfo;
                                 }
                                 arry.SetValue(ReadObject(dt, fs, index), i);
                             }
                         }
                     }
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var   con  = info.ArrayConstruction(fsa.Length);
                     Array arry = con as Array;
                     if (arry != null)
                     {
                         for (int i = 0; i < fsa.Length; i++)
                         {
                             unsafe { fs.SetPoint(fsa[i]); }
                             arry.SetValue(ReadStruct(info.typeInfo, fs, 0), i);
                         }
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }
Ejemplo n.º 6
0
 object ReadStructList(DataFieldInfo info, DataBuffer buffer, object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             var    con  = info.Construction();
             IList  list = con as IList;
             var    tmp  = info.typeInfo.Construction();
             IntPtr ptr  = UnsafeOperation.GetStructAddr(tmp);
             for (int i = 0; i < addr16.Length; i++)
             {
                 unsafe
                 {
                     byte *bp = (byte *)ptr;
                     for (int j = 0; j < info.typeInfo.DataLength; j++)
                     {
                         bp[j] = 0;
                     }
                 }
                 var fs = buffer.GetData(addr16[i]) as FakeStruct;
                 if (fs != null)
                 {
                     ReadStruct(info.typeInfo, fs, 0, ptr);
                 }
                 list.Add(tmp);
             }
             return(con);
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool   isStruct = info.typeInfo.isStruct;
                 var    con      = info.Construction();
                 IList  list     = con as IList;
                 var    tmp      = info.typeInfo.Construction();
                 IntPtr ptr      = UnsafeOperation.GetStructAddr(tmp);
                 for (int i = 0; i < addr32.Length; i++)
                 {
                     unsafe
                     {
                         byte *bp = (byte *)ptr;
                         for (int j = 0; j < info.typeInfo.DataLength; j++)
                         {
                             bp[j] = 0;
                         }
                     }
                     int a     = addr32[i];
                     int index = a & 0xffff;
                     var fs    = buffer.GetData(index) as FakeStruct;
                     if (fs != null)
                     {
                         ReadStruct(info.typeInfo, fs, 0, ptr);
                     }
                     list.Add(tmp);
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var    con  = info.Construction();
                     IList  list = con as IList;
                     var    tmp  = info.typeInfo.Construction();
                     IntPtr ptr  = UnsafeOperation.GetStructAddr(tmp);
                     for (int i = 0; i < fsa.Length; i++)
                     {
                         unsafe
                         {
                             byte *bp = (byte *)ptr;
                             for (int j = 0; j < info.typeInfo.DataLength; j++)
                             {
                                 bp[j] = 0;
                             }
                         }
                         unsafe { fs.SetPoint(fsa[i]); }
                         ReadStruct(info.typeInfo, fs, 0, ptr);
                         list.Add(tmp);
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }
Ejemplo n.º 7
0
 object ReadStructArray(DataFieldInfo info, DataBuffer buffer, object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             if (addr16.Length > 0)
             {
                 var   con  = info.ArrayConstruction(addr16.Length);
                 Array arry = con as Array;
                 if (arry != null)
                 {
                     IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arry, 0);
                     for (int i = 0; i < addr16.Length; i++)
                     {
                         var fs = buffer.GetData(addr16[i]) as FakeStruct;
                         if (fs != null)
                         {
                             ReadStruct(info.typeInfo, fs, 0, ptr);
                         }
                         ptr += info.DataLength;
                     }
                 }
                 return(con);
             }
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool  isStruct = info.typeInfo.isStruct;
                 var   con      = info.ArrayConstruction(addr32.Length);
                 Array arry     = con as Array;
                 if (arry == null)
                 {
                     IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arry, 0);
                     for (int i = 0; i < addr32.Length; i++)
                     {
                         int a     = addr32[i];
                         int index = a & 0xffff;
                         var fs    = buffer.GetData(index) as FakeStruct;
                         if (fs != null)
                         {
                             ReadStruct(info.typeInfo, fs, 0, ptr);
                         }
                         ptr += info.DataLength;
                     }
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var   con  = info.ArrayConstruction(fsa.Length);
                     Array arry = con as Array;
                     if (arry != null)
                     {
                         IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arry, 0);
                         for (int i = 0; i < fsa.Length; i++)
                         {
                             unsafe { fs.SetPoint(fsa[i]); }
                             ReadStruct(info.typeInfo, fs, 0, ptr);
                             ptr += info.DataLength;
                         }
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }