Click here to Skip to main content
15,892,746 members
Articles / Programming Languages / C#

Universal Framework for Science and Engineering - Part 4: Space elevator

Rate me:
Please Sign up or sign in to vote.
4.56/5 (6 votes)
14 Aug 20066 min read 36.6K   2.2K   37  
An article on framework applications to the space elevator.
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;

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

        public static readonly ElementaryFunctionsCreator Object = new ElementaryFunctionsCreator();

        protected ArrayList unaryDetectors = new ArrayList();
        private readonly IBinaryDetector[] detectors;

        private IMultiOperationDetector[] multiDetectors = new IMultiOperationDetector[]
			{
				OptionalDetector.Object
			};


        protected ElementaryFunctionsCreator()
        {
            ElementaryBinaryDetector plus = new ElementaryBinaryDetector('+');
            plus.Add(StringConcatOperation.Object);
            plus.Add(StringObjectConcatOperation.Object);
            LikeOperation like = new LikeOperation();
            like.Add(LikeObjectOperation.Object);

            detectors = new IBinaryDetector[]
			{
				new LogicalDetector('\u2217'), new LogicalDetector('\u2216'),
				LogicalEqualityDetector.Object,
				new BitDetector('|'), new BitDetector('&'), new BitDetector('^'),
				new BitDetector('\u2266'), new BitDetector('\u2267'),
				ComparationDetector.Object,  like,
				plus, new ElementaryBinaryDetector('-'),
				new ElementaryBinaryDetector('*')
			};
        }

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

        /// <summary>
        /// Checks whether symbol is bra
        /// </summary>
        /// <param name="s">The symbol</param>
        /// <returns>True if symbol is bra and false otherwise</returns>
        public bool IsBra(MathSymbol s)
        {
            return s.Symbol == '(';
        }

        /// <summary>
        /// Checks whether symbol is ket
        /// </summary>
        /// <param name="s">The symbol</param>
        /// <returns>True if symbol is ket and false otherwise</returns>
        public bool IsKet(MathSymbol s)
        {
            return s.Symbol == ')';
        }

        /// <summary>
        /// Count of operations
        /// </summary>
        public virtual int OperationCount
        {
            get
            {
                return unaryDetectors.Count + 1;
            }
        }

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

        /// <summary>
        /// Adds unary operation detector
        /// </summary>
        /// <param name="detector">Detector to add</param>
        public void Add(IOperationDetector detector)
        {
            unaryDetectors.Add(detector);
        }


        /// <summary>
        /// Count of multi operation
        /// </summary>
        public int MultiOperationCount
        {
            get
            {
                return multiDetectors.Length;
            }
        }

        /// <summary>
        /// Gets multi operation detector
        /// </summary>
        /// <param name="n">The detector number</param>
        /// <returns>The n - th detector</returns>
        public IMultiOperationDetector GetMultiOperationDetector(int n)
        {
            return multiDetectors[n];
        }

        /// <summary>
        /// Gets power operation
        /// </summary>
        /// <param name="valType">Type of value</param>
        /// <param name="powType">Type of power</param>
        /// <returns>Operation</returns>
        public IObjectOperation GetPowerOperation(object valType, object powType)
        {
            return new ElementaryPowerOperation(valType, powType);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions