コード例 #1
0
 public STRUCT(STRUCT source)
 {
     _fields       = new List <FIELD>();
     size          = 0;
     _objAlignment = source.objAlignment;
     Clone(source, false);
 }
コード例 #2
0
 public FIELD(int index, int offset, string name, STRUCT child)
 {
     this.index   = index;
     this.offset  = offset;
     this.name    = name;
     this.type    = TYPE.STRUCT;
     this.count   = 1;
     this.objSize = child.size;
     size         = objSize;
     this.child   = child;
 }
コード例 #3
0
        public void Clone(STRUCT source, bool copyValue)
        {
            _objAlignment = source.objAlignment;
            int count = source._fields.Count;

            // For safety, search index instead of foreach to make sure fields are added in sequent
            for (int index = 0; index < count; index++)
            {
                FIELD fSource = source._fields.Find(x => x.index == index);
                if (fSource == null)
                {
                    throw new Exception(string.Format("STRUCT::clone - missinge field with index {0}", index));
                }
                FIELD fNew = new FIELD(_objAlignment, index, size, fSource.name, fSource.type, fSource.count);
                if (copyValue)
                {
                    Array.Copy(fSource.dataBuffer, fNew.dataBuffer, fNew.size);
                }
                _fields.Add(fNew);
                size = fNew.offset + fNew.size;
            }
        }
コード例 #4
0
        public bool Copy(STRUCT source, bool allowMissing)
        {
            Clear();
            bool success = true;

            foreach (FIELD f in _fields)
            {
                if (f.name != "")
                {
                    if (source.Exists(f.name))
                    {
                        FIELD fs = source.GetField(f.name);
                        if ((f.type == TYPE.CHAR) && (fs.type == TYPE.CHAR))
                        {
                            f.SetString(fs.GetString());
                        }
                        else if (((f.type == TYPE.BOOL) && (fs.type == TYPE.BOOL)) ||
                                 (f.IsNumeric() && fs.IsNumeric()))
                        {
                            try
                            {
                                int maxCount = Math.Min(f.count, fs.count);
                                for (int i = 0; i < maxCount; i++)
                                {
                                    if (f.type == TYPE.BOOL)
                                    {
                                        f.SetBool(fs.GetBool(i), i);
                                    }
                                    else if (fs.type == TYPE.UINT64)
                                    {
                                        // have to use UInt64 to handle UINT64, otherwise can use INT64 for all other cases
                                        f.SetNumeric(fs.GetNumeric <UInt64>(i), i);
                                    }
                                    else
                                    {
                                        f.SetNumeric(fs.GetNumeric <Int64>(i), i);
                                    }
                                }
                            } catch (Exception)
                            {
                                success = false;
                                break;
                            }
                        }
                        else
                        {
                            success = false;
                            break;
                        }
                    }
                    else
                    {
                        if (!allowMissing)
                        {
                            success = false;
                            break;
                        }
                    }
                }
            }
            if (!success)
            {
                Clear();
            }
            return(success);
        }