Exemple #1
0
        //Array and Object
        private static IExpressionData ArrayIndex(List <IExpression> parameters)
        {
            List <IObject>  list = new List <IObject>();
            IExpressionData data;

            foreach (var item in parameters)
            {
                data = item.Evaluate();
                if (data is StringType)
                {
                    list.Add(new VariableData(typeof(string), data.GetData()));
                }
                else if (data is BoolType)
                {
                    list.Add(new VariableData(typeof(bool), data.GetData()));
                }
                else if (data is DoubleType)
                {
                    list.Add(new VariableData(typeof(double), data.GetData()));
                }
                else if (data is ObjectType)
                {
                    list.Add((IObject)data.GetData());
                }
            }
            ArrayIndex array = new ArrayIndex(list);

            return(new ObjectType(array));
        }
Exemple #2
0
 public override bool Push(int value, ArrayIndex stackIndex = 0)
 {
     if (value <= Min())
     {
         _StackMinValue.Push(value);
     }
     return(base.Push(value));
 }
Exemple #3
0
        static void Main(string[] args)
        {
            ArrayIndex a = new ArrayIndex(6);

            a.StartIndex = -2;
            a.Initilize();
            a.ShowArray();
            Console.ReadKey();
        }
Exemple #4
0
        public override bool Pop(ArrayIndex stackIndex = 0)
        {
            var value = base.Peek();

            if (value == Min())
            {
                _StackMinValue.Pop();
            }
            return(base.Pop());
        }
Exemple #5
0
 public void TestAI()
 {
     var ai = new ArrayIndex<CodePoint,int>{{'這',1},{'在',2},{'謟',5},{'謟',0},{'A',3}};
     ai.Prep();
     Assert.AreEqual(5,ai.Length);
     int b = 0, e = ai.Length;
     ai.EqualRange('謟',out b,out e);
     Assert.AreNotEqual(b,e);
     Assert.True(e>b);
 }
 public static IObject GetObject(string name, int index)
 {
     if (dictionary.ContainsKey(name) && dictionary[name] is ArrayIndex)
     {
         ArrayIndex array = (ArrayIndex)dictionary[name];
         return(array[index]);
     }
     else
     {
         throw new Exception("Error in calling arrayindex");
     }
 }
Exemple #7
0
        public void Construct(CommonTree syntaxArrayElementReference)
        {
            var syntaxExtendedId = syntaxArrayElementReference.GetChild(0).CastTo <CommonTree>();

            Name = TreeHelper.GetExpression(this, Scope, syntaxExtendedId).CastTo <ExtendedId>();
            Name.Construct(syntaxExtendedId);

            var syntaxArrayIndex = syntaxArrayElementReference.GetChild(1).CastTo <CommonTree>();

            ArrayIndex = TreeHelper.GetExpression(this, Scope, syntaxArrayIndex);
            ArrayIndex.Construct(syntaxArrayIndex);
        }
 public virtual bool Push(T value, ArrayIndex stackIndex = 0)
 {
     if (_TopIndex > _InitialSize - 1)
     {
         throw new Exception("Stack Overflow");
     }
     else
     {
         Nodes[++_TopIndex] = value;
         return(true);
     }
 }
 public virtual bool Pop(ArrayIndex stackIndex = 0)
 {
     if (_TopIndex == -1)
     {
         throw new Exception("Stack is empty");
     }
     else
     {
         Nodes[_TopIndex] = default(T);
         return(true);
     }
 }
Exemple #10
0
 private static void SetValue(Array array, ArrayIndex arrayIndex, int flatIndex, T value)
 {
     if (arrayIndex == null)
     {
         array.SetValue(value, flatIndex);
     }
     else
     {
         arrayIndex.FlatIndex = flatIndex;
         arrayIndex.SetValue <T>(array, value);
     }
 }
Exemple #11
0
 private static T GetValue(Array array, ArrayIndex arrayIndex, int flatIndex)
 {
     if (arrayIndex == null)
     {
         return((T)array.GetValue(flatIndex));
     }
     else
     {
         arrayIndex.FlatIndex = flatIndex;
         return(arrayIndex.GetValue <T>(array));
     }
 }
Exemple #12
0
 private FlatArrayAccessor(Array array, ArrayIndex arrayIndex, bool readOnly)
     : base(array != null ? index => GetValue(array, arrayIndex, index) : (Func <int, T>)null,
            array != null && !array.IsReadOnly ? (index, value) => SetValue(array, arrayIndex, index, value) : (Action <int, T>)null)
 {
     if (array == null)
     {
         throw new ArgumentNullException("array");
     }
     if (!typeof(T).IsAssignableFrom(array.GetType().GetElementType()))
     {
         throw new ArgumentException("Invalid array element type");
     }
 }
Exemple #13
0
        public void TestAI()
        {
            var ai = new ArrayIndex <CodePoint, int> {
                { '這', 1 }, { '在', 2 }, { '謟', 5 }, { '謟', 0 }, { 'A', 3 }
            };

            ai.Prep();
            Assert.AreEqual(5, ai.Length);
            int b = 0, e = ai.Length;

            ai.EqualRange('謟', out b, out e);
            Assert.AreNotEqual(b, e);
            Assert.True(e > b);
        }
        public JaggedArrayEnumerator(Array array, bool zeroBased, Func <int> getStamp)
        {
            if (array == null)
            {
                throw new ArgumentNullException();
            }
            //
            _arrayIndex = new ArrayIndex(new JaggedArrayInfo(array))
            {
                ZeroBased = zeroBased
            };
            _array    = array;
            _getStamp = getStamp;
            _stamp    = getStamp != null?getStamp() : 0;

            _current = default(T);
        }
        public bool Push(T value, ArrayIndex stackIndex)
        {
            var result = false;

            if (topIndex[0] < stack1Size || topIndex[1] < stack2Size || topIndex[2] < stack3Size)
            {
                result = true;
                input[topIndex[(int)stackIndex] + 1] = value;
                topIndex[(int)stackIndex]++;
            }
            else
            {
                throw new Exception("Stack is full cannot insert values");
            }

            return(result);
        }
Exemple #16
0
        public RegularArrayEnumerator(Array array, bool zeroBased, Func <int> getStamp)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            //
            _arrayIndex = new ArrayIndex(new RegularArrayInfo(array.GetRegularArrayDimensions()))
            {
                ZeroBased = zeroBased
            };
            _array    = array;
            _getStamp = getStamp;
            _stamp    = getStamp != null?getStamp() : 0;

            _current = default(T);
        }
        public bool Pop(ArrayIndex stackIndex)
        {
            bool result = false;

            if (topIndex[0] > 0 || topIndex[1] > 0 || topIndex[2] > 0)
            {
                input[topIndex[(int)stackIndex]] = default(T);
                topIndex[(int)stackIndex]--;
                result = true;
            }

            else
            {
                result = true;
                throw new Exception("All stacks are empty");
            }
            return(result);
        }
Exemple #18
0
        public override Type visitIndex(ArrayIndex index, Environment env)
        {
            Type arrayType = analyzeExpr(index.indexBase, env);
            Type indexType = analyzeExpr(index.index, env);

            if (!indexType.IsError && (!indexType.IsIntegral || indexType.Tag > TypeTag.INT))
            {
                log.error(index.index.Pos, messages.indexNotInteger);
            }

            if (arrayType.IsError)
            {
                return(symtab.errorType);
            }

            if (!arrayType.IsArray)
            {
                log.error(index.Pos, messages.indexNotArray);
                return(symtab.errorType);
            }

            return(((ArrayType)arrayType).elemType);
        }
Exemple #19
0
        public byte[] GetBytes()
        {
            ArrayList res = new ArrayList();

            res.Add((byte)((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST | (1 << 1)));
            res.Add((byte)84);

            res.Add((byte)InvokeId);
            res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY);

            //Object ID
            BacNetTag objectTag = new BacNetTag {
                Class = true, Length = 4, Number = 0
            };

            res.AddRange(objectTag.GetBytes());
            res.AddRange(ObjectId.GetObjectBytes());

            //Property ID
            BacNetTag propertyIdTag = new BacNetTag {
                Class = true, Length = (byte)PropertyId.GetLength(), Number = 1
            };

            res.AddRange(propertyIdTag.GetBytes());
            res.AddRange(PropertyId.GetBytes());

            if (ArrayIndex != null)
            {
                BacNetTag arrayIndexTag = new BacNetTag {
                    Class = true, Length = (byte)ArrayIndex.GetLength(), Number = 2
                };
                res.AddRange(arrayIndexTag.GetBytes());
                res.AddRange(ArrayIndex.GetBytes());
            }

            return((byte[])res.ToArray(typeof(byte)));
        }
Exemple #20
0
 public override Exit visitIndex(ArrayIndex index, Environment env)
 {
     analyzeExpr(index.indexBase, env);
     return(0);
 }
 public MyArray()
 {
     array = new int[1, 1];
     index = new ArrayIndex(0, 0);
 }
Exemple #22
0
 public T Peek(ArrayIndex stackIndex = 0)
 {
     return(Nodes[_TopIndex]);
 }
 public MyArray(int row, int column)
 {
     array = new int[row, column];
     index = new ArrayIndex(row, column);
 }
 public MyArray(int[,] item)
 {
     array = item;
     index = new ArrayIndex(item.GetLength(0), item.GetLength(1));
 }
Exemple #25
0
        private static void GenerateWeldLists(GameObject[] arrGOtoWeld, Material interiorMaterial, out List <GameObject> listParentGO, out List <Mesh> listParentMesh_un,
                                              out List <Material> listMaterial, out List <ArrayIndex> listMaterialInfo, out int interiorMaterialIdx)
        {
            listParentGO      = new List <GameObject>();
            listParentMesh_un = new List <UnityEngine.Mesh>();

            listMaterial     = new List <Material>();
            listMaterialInfo = new List <ArrayIndex>();

            interiorMaterialIdx = -1;

            for (int i = 0; i < arrGOtoWeld.Length; i++)
            {
                GameObject       go      = arrGOtoWeld[i];
                UnityEngine.Mesh un_mesh = go.GetMesh();
                if (un_mesh != null)
                {
                    listParentMesh_un.Add(un_mesh);
                    listParentGO.Add(go);

                    int        submeshCount     = un_mesh.subMeshCount;
                    ArrayIndex meshMaterialInfo = new ArrayIndex();
                    meshMaterialInfo.arrIdx_ = new uint[submeshCount];

                    Renderer renderer = go.GetComponent <Renderer>();
                    if (renderer != null)
                    {
                        Material[] arrMaterials = renderer.sharedMaterials;
                        int        nMaterials   = arrMaterials.Length;

                        for (int j = 0; j < submeshCount || j < nMaterials; j++)
                        {
                            Material material = arrMaterials[j];
                            if (material != null)
                            {
                                if (!listMaterial.Contains(material))
                                {
                                    if (interiorMaterial != null && material == interiorMaterial)
                                    {
                                        interiorMaterialIdx = listMaterial.Count;
                                    }
                                    listMaterial.Add(material);
                                }

                                int indexMaterial = listMaterial.IndexOf(material);
                                meshMaterialInfo.arrIdx_[j] = (uint)indexMaterial;
                            }
                            else
                            {
                                meshMaterialInfo.arrIdx_[j] = uint.MaxValue;
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < submeshCount; j++)
                        {
                            meshMaterialInfo.arrIdx_[j] = uint.MaxValue;
                        }
                    }
                    listMaterialInfo.Add(meshMaterialInfo);
                }
            }
        }
Exemple #26
0
        private static void CreateMeshCollapsedUnity(string name, MeshComplex mesh_COLLAPSED_car, ArrayIndex mesh_COLLAPSED_info, GameObject boundsObject,
                                                     List <Material> listMaterial, out GameObject[] arrGameObject, out Mesh[] arrMesh)
        {
            UnityEngine.Mesh[]  arrMesh_COLLAPSED_un;
            Tuple2 <int, int>[] arrSubmeshRange;

            CRGeometryUtils.CreateMeshesFromComplex(mesh_COLLAPSED_car, out arrMesh_COLLAPSED_un, out arrSubmeshRange);

            int nMeshUnity = arrMesh_COLLAPSED_un.Length;

            List <GameObject> listGameObject = new List <GameObject>();
            List <Mesh>       listMesh       = new List <Mesh>();

            for (int i = 0; i < nMeshUnity; i++)
            {
                Mesh mesh_COLLAPSED_un = arrMesh_COLLAPSED_un[i];
                mesh_COLLAPSED_un.name = name + "_" + i;
                listMesh.Add(mesh_COLLAPSED_un);

                GameObject go = Object.Instantiate(boundsObject);
                go.name = name + "_" + i;
                go.AddMesh(mesh_COLLAPSED_un);
                listGameObject.Add(go);

                Tuple2 <int, int> submeshRange = arrSubmeshRange[i];

                List <Material> collapsedMaterials = new List <Material>();
                uint[]          arrMaterialIdx     = mesh_COLLAPSED_info.arrIdx_;

                for (int j = submeshRange.First; j <= submeshRange.Second; j++)
                {
                    uint materialIdx = arrMaterialIdx[j];
                    if (materialIdx != uint.MaxValue)
                    {
                        Material mat = listMaterial[(int)materialIdx];
                        collapsedMaterials.Add(mat);
                    }
                    else
                    {
                        collapsedMaterials.Add(null);
                    }
                }

                Renderer renderer = go.GetComponent <Renderer>();
                renderer.sharedMaterials = collapsedMaterials.ToArray();
            }

            arrGameObject = listGameObject.ToArray();
            arrMesh       = listMesh.ToArray();
        }
Exemple #27
0
    /// <summary>
    /// Return the value (using Reflection) of the specified property on the specified object.
    /// Returns null if not found. Examples of Names that can be found.
    ///     Pod
    ///     Environment.MeanT
    ///     Organs[]
    ///     Organs[AboveGround].Live
    ///     Organs[AboveGround].Live.Wt
    ///     Leaf.Leaves[Leaf.CurrentRank].CoverAbove
    ///  Can return an Instance, an Entity or an object[] when an array specifier is present.
    /// </summary>
    public static object GetVariable(string NamePath, object RelativeTo)
    {
        Component My = null;

        if (RelativeTo is Component)
        {
            My = RelativeTo as Component;
            if ((My != null) && !NamePath.Contains("["))
            {
                object v;
                My.GetObject(NamePath, out v);
                return(v);
            }
        }

        if (VarParts == null)
        {
            VarParts = new Dictionary <string, List <string> >();
        }

        string[] Bits;
        //cache the list of names that are parsed here
        List <String> Parts;

        if (VarParts.TryGetValue(NamePath, out Parts))
        {
            Bits = Parts.ToArray();
        }
        else
        {
            Bits = StringManip.SplitStringHonouringBrackets(NamePath, '.', '[', ']');
            VarParts.Add(NamePath, Bits.ToList());
        }

        for (int i = 0; i < Bits.Length; i++)
        {
            string ArraySpecifier = "";
            bool   ArrayFound     = Bits[i].Contains("[");
            if (ArrayFound)
            {
                ArraySpecifier = StringManip.SplitOffBracketedValue(ref Bits[i], '[', ']');
            }

            object MatchingChild;
            if (RelativeTo is Component)
            {
                MatchingChild = (RelativeTo as Component).LinkByName(Bits[i]);      // Try for a model name first. e.g. Root
                if (MatchingChild == null)
                {
                    (RelativeTo as Component).GetObject(Bits[i], out MatchingChild);      // may be a variable. e.g. Organs
                }
            }
            else
            {
                MatchingChild = Utility.GetValueOfFieldOrProperty(Bits[i], RelativeTo);
            }

            if (MatchingChild == null)
            {
                throw new Exception("Cannot find variable: " + NamePath);
            }

            // Look for array spec
            if (ArrayFound)
            {
                if (!(MatchingChild is IList))
                {
                    throw new Exception("Cannot specify an array on a non array variable. Name: " + NamePath);
                }
                IList Array = MatchingChild as IList;

                // First try and treat the ArraySpecifier as an integer index.
                // If that's not possible, then assume it is a reference to an integer variable
                // somewhere in the system.
                // If that's not possible then assume it is a type name e.g. AboveGround.
                int ArrayIndex;

                bool ok = int.TryParse(ArraySpecifier, out ArrayIndex);

                if (ArraySpecifier != "" && !ok && My != null)
                {
                    object ArraySpec;
                    ok = My.GetObject(ArraySpecifier, out ArraySpec);      // Assume it is a simulation variable.
                    if (ok && (ArraySpec is Int32 || ArraySpec is Double))
                    {
                        ArrayIndex = Convert.ToInt32(ArraySpec);
                    }
                    else
                    {
                        ok = false;
                    }
                }

                if (ok)
                {
                    if (ArrayIndex < 0 || ArrayIndex >= Array.Count)
                    {
                        throw new Exception("Invalid index of " + ArrayIndex.ToString() + " found while indexing into variable: " + NamePath);
                    }
                    MatchingChild = Array[ArrayIndex];
                }
                else
                {
                    // Must be a type name. Go collect an array of objects of that type.
                    List <object> ArrayOfType = new List <object>();

                    // Construct a name remainder.
                    string RestOfName = null;
                    for (int j = i + 1; j < Bits.Length; j++)
                    {
                        if (RestOfName != null)
                        {
                            RestOfName += ".";
                        }
                        RestOfName += Bits[j];
                    }

                    foreach (object o in Array)
                    {
                        if (ArraySpecifier == "" || Utility.IsOfType(o.GetType(), ArraySpecifier))
                        {
                            if (RestOfName == null)
                            {
                                ArrayOfType.Add(o);
                            }
                            else
                            {
                                object ChildObject = GetVariable(RestOfName, o);      // recursion
                                if (ChildObject != null)
                                {
                                    ArrayOfType.Add(ChildObject);
                                }
                            }
                        }
                    }
                    return(ArrayOfType.ToArray());
                }
            }

            RelativeTo = MatchingChild;
        }

        // If we get this far then we've found a match.
        return(RelativeTo);
    }
Exemple #28
0
 public int GetLength(ArrayIndex i)
 {
     return(_valueArray.GetLength((int)i));
 }
Exemple #29
0
 public virtual T visitIndex(ArrayIndex index, A arg) => visit(index, arg);
        public T Peek(ArrayIndex stackIndex)
        {
            int index = (int)stackIndex * stack1Size + topIndex[(int)stackIndex];

            return(input[index]);
        }
Exemple #31
0
        public byte[] GetBytes()
        {
            ArrayList res = new ArrayList();

            res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST);
            res.Add((byte)3);

            res.Add((byte)InvokeId);
            res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_WRITE_PROPERTY);

            //Object ID
            BacNetTag objectTag = new BacNetTag {
                Class = true, Length = 4, Number = 0
            };

            res.AddRange(objectTag.GetBytes());
            res.AddRange(ObjectId.GetObjectBytes());

            //Property ID
            BacNetTag propertyIdTag = new BacNetTag {
                Class = true, Length = (byte)PropertyId.GetLength(), Number = 1
            };

            res.AddRange(propertyIdTag.GetBytes());
            res.AddRange(PropertyId.GetBytes());

            if (ArrayIndex != null)
            {
                BacNetTag arrayIndexTag = new BacNetTag {
                    Class = true, Length = (byte)ArrayIndex.GetLength(), Number = 2
                };
                res.AddRange(arrayIndexTag.GetBytes());
                res.AddRange(ArrayIndex.GetBytes());
            }

            //Opening Tag
            BacNetTag openingTag = new BacNetTag {
                Class = true, Length = 6, Number = 3
            };

            res.AddRange(openingTag.GetBytes());

            BacNetTag metaTag = new BacNetTag();

            foreach (var value in ValueList)
            {
                int    type;
                byte[] valueBytes = ByteConverter.GetPropertyValueBytes(value, out type);
                if (type != 0)
                {
                    metaTag = new BacNetTag {
                        Class = false, Length = (byte)valueBytes.Length, Number = (byte)type
                    };
                    res.AddRange(metaTag.GetBytes());
                }
                res.AddRange(valueBytes);
            }

            //Closing Tag
            BacNetTag closingTag = new BacNetTag {
                Class = true, Length = 7, Number = 3
            };

            res.AddRange(closingTag.GetBytes());

            BacNetTag priorityTag = new BacNetTag {
                Class = true, Number = 4, Length = 1
            };

            res.AddRange(priorityTag.GetBytes());
            res.Add((byte)0xA);


            return((byte[])res.ToArray(typeof(byte)));
        }