Пример #1
0
        public BlendTypeRepository()
        {
            int capacity = 1024;

            m_tables   = new Dictionary <string, IBlendType>(capacity);
            m_sdnaList = new List <BlendStructureType>(capacity);

            // add all primitive type
            foreach (var type in BlendPrimitiveType.AllTypes())
            {
                Add(type);
            }
        }
Пример #2
0
        public static IEnumerable <object> GetAllRawValue(BlendValueCapsule value)
        {
            Debug.Assert(value.Type.GetType() == typeof(BlendArrayType), "tyep unmatched");
            var type = (BlendArrayType)value.Type;

            if (type.ArrayDimension == 1)
            {
                if (type.BaseType.Equals(BlendPrimitiveType.Char()))
                {
                    // Parse as string
                    var objs = value.GetRawValue <BlendValueCapsule[]>();
                    yield return(ConvertUtil.CharArray2String(objs.Select(o => o.GetRawValue())));
                }
                else
                {
                    // Parse as 1 dimension array
                    var objs = value.GetRawValue <BlendValueCapsule[]>();
                    foreach (var obj in objs.SelectMany(v => v.GetAllValue()))
                    {
                        yield return(obj);
                    }
                }
            }
            else if (type.ArrayDimension == 2)
            {
                // Parse as 2 dimension array
                var objs1 = value.GetRawValue <object[]>();
                foreach (BlendValueCapsule[] objs2 in objs1)
                {
                    foreach (var obj in objs2.SelectMany(v => v.GetAllValue()))
                    {
                        yield return(obj);
                    }
                }
            }
            else
            {
                Debug.Assert(false, "logic error");
            }
        }
Пример #3
0
        public System.Collections.IEnumerable GetChildren(Aga.Controls.Tree.TreePath treePath)
        {
            _NodeModel node = null;

            if (treePath.IsEmpty())
            {
                if (m_rootNode != null)
                {
                    node = m_rootNode;
                }
            }
            else
            {
                node = (_NodeModel)treePath.LastNode;
            }

            if (node != null)
            {
                if (node.IsStructure)
                {
                    // scan members
                    var type = (BlendStructureType)node.m_value.Type;
                    foreach (var decl in type.MemberDecls)
                    {
                        var value     = node.m_value.GetMember(decl.Name);
                        var childNode = new _NodeModel(decl.Name, value);
                        yield return(childNode);
                    }
                }
                else if (node.IsPointer)
                {
                    // dereference
                    var address     = node.m_value.GetRawValue <BlendAddress>();
                    var pointerType = (BlendPointerType)node.m_value.Type;
                    var baseType    = pointerType.BaseType;
                    if (address.CanDereference(baseType))
                    {
                        List <BlendValueCapsule> result = null;
                        try
                        {
                            if (baseType.Equals(BlendPrimitiveType.Void()))
                            {
                                // void pointer
                                result = address.DereferenceAll();
                            }
                            else
                            {
                                result = address.DereferenceAll(baseType);
                            }
                        }
                        catch (BlenderException e)
                        {
                            Dialog.ShowError(e);
                            yield break;
                        }

                        if (result.Count == 1)
                        {
                            var childNode = new _NodeModel("*" + node.Name, result[0]);
                            yield return(childNode);
                        }
                        else
                        {
                            // If the number of dereferenced objects is over 1, we show it as an array.
                            for (int i = 0; i < result.Count; ++i)
                            {
                                var value     = result[i];
                                var childNode = new _NodeModel(node.Name + "[" + i + "]", value);
                                yield return(childNode);
                            }
                        }
                    }
                }
                else if (node.IsArray)
                {
                    var arrayType  = (BlendArrayType)node.m_value.Type;
                    int arrayCount = arrayType.ArrayDimension;
                    switch (arrayCount)
                    {
                    case 1:
                        for (int i = 0; i < arrayType.GetLength(0); ++i)
                        {
                            var value     = node.m_value.GetAt(i);
                            var childNode = new _NodeModel(node.Name + "[" + i + "]", value);
                            yield return(childNode);
                        }
                        break;


                    case 2:
                        for (int i = 0; i < arrayType.GetLength(0); ++i)
                        {
                            for (int j = 0; j < arrayType.GetLength(1); ++j)
                            {
                                var value     = node.m_value.GetAt(i, j);
                                var childNode = new _NodeModel(node.Name + "[" + i + "]" + "[" + j + "]", value);
                                yield return(childNode);
                            }
                        }
                        break;
                    }
                }
            }

            yield break;
        }