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

namespace FormulaEditor
{
    /// <summary>
    /// Symbol linked with object
    /// </summary>
    public class ObjectedSymbol : MathSymbol, INullArityOperation, IOperationAcceptor
    {

        /// <summary>
        /// Associated object
        /// </summary>
        protected object obj;


        private static readonly Guid guid = new Guid();




        /// <summary>
        /// ICloneable interface implementation
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            ObjectedSymbol s = new ObjectedSymbol();
            s.obj = obj;
            return s;
        }

        /// <summary>
        /// The associated object
        /// </summary>
        public object Object
        {
            get
            {
                return obj;
            }
            set
            {
                obj = value;
            }
        }

        /// <summary>
        /// Index of subscript
        /// </summary>
        public int SubscriptIndex
        {
            get
            {
                MathFormula f = this[0];
                string s = "";
                for (int i = 0; i < f.Count; i++)
                {
                    s += f[i].Symbol;
                }
                return Int32.Parse(s);
            }
        }

        /// <summary>
        /// Arity of this operation
        /// </summary>
        public int Arity
        {
            get
            {
                return 0;
            }
        }

        /// <summary>
        /// Return type
        /// </summary>
        public object ReturnType
        {
            get
            {
                if (obj is Guid)
                {
                    return guid;
                }
                return obj;
            }
        }


        /// <summary>
        /// Calculates result of this operation
        /// </summary>
        public object this[object[] o]
        {
            get
            {
                return obj;
            }
        }

        /// <summary>
        /// The "is powered" sign
        /// </summary>
        public bool IsPowered
        {
            get
            {
                return false;
            }
        }

        #region IOperationAcceptor Members

        public IObjectOperation Accept(object type)
        {
            return this;
        }

        #endregion

    }
}
