/// <summary>
        /// Compiles the <see cref="Tabulator{T}"/> object
        /// for evaluating the specified <paramref name="expression"/>
        /// in some ranges of arguments.</summary>
        /// <param name="expression">Expression to compile.</param>
        /// <exception cref="SyntaxException">
        /// <paramref name="expression"/> contains syntax error(s)
        /// and can't be compiled.</exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="expression"/> is null.</exception>
        /// <exception cref="ArgumentException">
        /// Current expression's arguments <see cref="Arguments">count</see>
        /// is not supported (only 1 or 2 arguments supported by now).</exception>
        /// <remarks>Not available in the .NET CF versions.</remarks>
        /// <returns><see cref="Tabulator{T}"/> object
        /// for evaluating expression.</returns>
        public Tabulator <T> CreateTabulator(string expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }
            if (ArgsCount == 0)
            {
                throw new ArgumentException(Resource.errTabulatorWrongArgs);
            }

            var compiler = new TabulatorCompiler <T>(ArgsCount, OverflowCheck);

            ParseOptimized(expression, compiler);

            var del = compiler.CreateDelegate();

            if (ArgsCount > 2)
            {
                var alloc = TabulatorCompiler <T> .GetAllocator(ArgsCount);

                return(new Tabulator <T>(expression, del, ArgsCount, alloc));
            }

            return(new Tabulator <T>(expression, del, ArgsCount));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allocates the array with lengths, that needed
        /// to tabulate some expression in the specified
        /// argument <paramref name="ranges"/>.</summary>
        /// <param name="ranges">Argument ranges.</param>
        /// <typeparam name="T">Array elements type.</typeparam>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="ranges"/> is null.</exception>
        /// <exception cref="InvalidRangeException">
        /// Some instance of <paramref name="ranges"/>
        /// is not valid for iteration over it.</exception>
        /// <returns>Allocated <paramref name="ranges"/>-dimensional
        /// jagged array casted to <see cref="Array"/> type.</returns>
        public static Array Allocate <T>(params ValueRange <T>[] ranges)
        {
            if (ranges == null)
            {
                throw new ArgumentNullException("ranges");
            }

            if (ranges.Length == 1)
            {
                return(new double[ranges[0].ValidCount]);
            }
            if (ranges.Length == 2)
            {
                return(Allocate(ranges[0], ranges[1]));
            }

            var sizes = new int[ranges.Length];

            for (int i = 0; i < ranges.Length; i++)
            {
                sizes[i] = ranges[i].ValidCount;
            }

            var alloc = TabulatorCompiler <T> .GetAllocator(ranges.Length);

            return(alloc(sizes));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Allocates the array with lengths, that needed to tabulate
        /// some expression in the three specified argument ranges.</summary>
        /// <param name="range1">First argument range.</param>
        /// <param name="range2">Second argument range.</param>
        /// <param name="range3">Third argument range.</param>
        /// <typeparam name="T">Array elements type.</typeparam>
        /// <exception cref="InvalidRangeException"><paramref name="range1"/>,
        /// <paramref name="range2"/> or <paramref name="range3"/>
        /// is not valid for iteration over it.</exception>
        /// <returns>Allocated three-dimensional jagged array
        /// casted to <see cref="Array"/> type.</returns>
        public static Array Allocate <T>(
            ValueRange <T> range1,
            ValueRange <T> range2,
            ValueRange <T> range3)
        {
            var alloc = TabulatorCompiler <T> .GetAllocator(3);

            return(alloc(
                       range1.ValidCount,
                       range2.ValidCount,
                       range3.ValidCount));
        }