/// <summary>
        /// The recursive method which implements the variable number of for-loops together with processing callbacks to the outerProductProcessor.
        /// </summary>
        /// <param name="dimensionIndex"></param>
        /// <param name="outerProductProcessor"></param>
        private void ProcessOuterProductRecursive(int dimensionIndex, IOuterProductProcessor outerProductProcessor)
        {
            if (dimensionIndex >= _numberElementsPerDimension.Length)
            {
                return;
            }

            var processingState = new OuterProductProcessingState(this, dimensionIndex);


            for (int currentDimensionIndex = 0; currentDimensionIndex < _numberElementsPerDimension[dimensionIndex]; ++currentDimensionIndex)
            {
                DimensionIndices[dimensionIndex] = currentDimensionIndex;

                outerProductProcessor.SetProcessingState(processingState);
                bool continueProcessingBeforeLoop = outerProductProcessor.DoBeforeLoop();
                if (!continueProcessingBeforeLoop)
                {
                    break;
                }

                ProcessOuterProductRecursive(dimensionIndex + 1, outerProductProcessor);

                outerProductProcessor.SetProcessingState(processingState);
                bool continueProcessingAfterLoop = outerProductProcessor.DoAfterLoop();
                if (!continueProcessingAfterLoop)
                {
                    break;
                }

                ++_numberElementsProcessed;
            }
        }
예제 #2
0
 /// <summary>
 /// Internal use only: Used by OuterProductIndexGenerator class to set the current <see cref="ProcessingState"/> before invoking a callback.
 /// </summary>
 /// <param name="processingState"></param>
 public void SetProcessingState(OuterProductProcessingState processingState)
 {
     _processingState = processingState;
 }