/// <summary> /// Creates a new instance of the <see cref="CalculationEngine"/> class. /// </summary> /// <param name="options">The <see cref="JaceOptions"/> to configure the behaviour of the engine.</param> public CalculationEngine(JaceOptions options) { this.executionFormulaCache = new MemoryCache <string, Func <IDictionary <string, double>, double> >(options.CacheMaximumSize, options.CacheReductionSize); this.FunctionRegistry = new FunctionRegistry(false); this.ConstantRegistry = new ConstantRegistry(false); this.cultureInfo = options.CultureInfo; this.cacheEnabled = options.CacheEnabled; this.optimizerEnabled = options.OptimizerEnabled; this.caseSensitive = options.CaseSensitive; this.random = new Random(); if (options.ExecutionMode == ExecutionMode.Interpreted) { executor = new Interpreter(caseSensitive); } else if (options.ExecutionMode == ExecutionMode.Compiled) { executor = new DynamicCompiler(caseSensitive); } else { throw new ArgumentException(string.Format("Unsupported execution mode \"{0}\".", options.ExecutionMode), "executionMode"); } optimizer = new Optimizer(new Interpreter()); // We run the optimizer with the interpreter // Register the default constants of Jace.NET into the constant registry if (options.DefaultConstants) { RegisterDefaultConstants(); } // Register the default functions of Jace.NET into the function registry if (options.DefaultFunctions) { RegisterDefaultFunctions(); } }
/// <summary> /// Creates a new instance of the <see cref="CalculationEngine"/> class. /// </summary> /// <param name="options">The <see cref="JaceOptions"/> to configure the behaviour of the engine.</param> public CalculationEngine(JaceOptions options) : this(options.CultureInfo, options.ExecutionMode, options.CacheEnabled, options.OptimizerEnabled, options.AdjustVariableCase, options.DefaultFunctions, options.DefaultConstants) { }