Пример #1
0
        private static void FillArray(PlTerm[] terms, Type elementType, Array al)
        {
            int termsLength = terms.Length;
            var idxIter     = new ArrayIndexEnumerator(al);

            for (int i = 0; i < termsLength; i++)
            {
                idxIter.MoveNext();
                PlTerm term = terms[i];
                al.SetValue(CastTerm(term, elementType), idxIter.Current);
            }
        }
Пример #2
0
        public static bool cliArrayFill(PlTerm arrayValue, PlTerm valueIn)
        {
            object getInstance;
            Type   c;

            if (!GetInstanceAndType(arrayValue, out getInstance, out c))
            {
                return(false);
            }
            Array al        = (Array)getInstance;
            var   initValue = CastTerm(valueIn, c.GetElementType());
            var   idxIter   = new ArrayIndexEnumerator(al);

            while (idxIter.MoveNext())
            {
                al.SetValue(initValue, idxIter.Current);
            }
            return(true);
        }
Пример #3
0
        public static bool unifyArrayToTerm(Array value, PlTerm valueOut)
        {
            int  len       = value.Length;
            Type arrayType = value.GetType();
            var  termv     = NewPlTermV(len);
            int  rank      = arrayType.GetArrayRank();

            if (rank != 1)
            {
                var indexesv = new PlTermV(rank);
                for (int i = 0; i < rank; i++)
                {
                    indexesv[i].Put(value.GetLength(i));
                }
                var idxIter = new ArrayIndexEnumerator(value);
                int putAt   = 0;
                while (idxIter.MoveNext())
                {
                    bool pf = termv[putAt++].FromObject((value.GetValue(idxIter.Current)));
                    if (!pf)
                    {
                        return(false);
                    }
                }
                return /// array/3
                       (valueOut.Unify(PlC("array", typeToSpec(arrayType), PlC("indexes", indexesv), PlC("values", termv))));
            }
            else
            {
                for (int i = 0; i < len; i++)
                {
                    bool pf = termv[i].FromObject((value.GetValue(i)));
                    if (!pf)
                    {
                        return(false);
                    }
                }
                return(valueOut.Unify(PlC("array", typeToSpec(arrayType.GetElementType()), PlC("values", termv))));
            }
        }