using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;

namespace FormulaEditor
{
    /// <summary>
    /// Creator of elementary functions
    /// </summary>
    public class ElementaryObjectsCreator : ElementaryFunctionsCreator
    {


        /// <summary>
        /// Detector
        /// </summary>
        private IOperationDetector detector;

        /// <summary>
        /// Additional binary detectors
        /// </summary>
        private ArrayList binary = new ArrayList();

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="table">Table of variables</param>
        public ElementaryObjectsCreator(Hashtable table)
        {
            detector = new ElementaryObjectDetector(table);
        }

        /// <summary>
        /// Gets i - th operation detector
        /// </summary>
        /// <param name="i">Detector number</param>
        /// <returns>The i - th detector</returns>
        public override IOperationDetector GetDetector(int i)
        {
            if (i == 0)
            {
                return detector;
            }
            return unaryDetectors[i - 1] as IOperationDetector;
        }

        /// <summary>
        /// Adds binary detector
        /// </summary>
        /// <param name="detector">Detector to add</param>
        public void AddBinaryDetector(IBinaryDetector detector)
        {
            binary.Add(detector);
        }

        /// <summary>
        /// Count of binary operations
        /// </summary>
        public override int BinaryCount
        {
            get
            {
                return base.BinaryCount + binary.Count;
            }
        }
        /// <summary>
        /// Gets i - th binary detector
        /// </summary>
        /// <param name="i">Detector number</param>
        /// <returns>The i - th detector</returns>
        public override IBinaryDetector GetBinaryDetector(int i)
        {
            if (i < base.BinaryCount)
            {
                return base.GetBinaryDetector(i);
            }
            int n = i - base.BinaryCount;
            return binary[n] as IBinaryDetector;
        }

    }

}
