Click here to Skip to main content
15,896,063 members
Articles / Programming Languages / C#

Integration: Mechanics + Hydraulics + Navigation

Rate me:
Please Sign up or sign in to vote.
5.00/5 (46 votes)
3 Feb 2011CPOL21 min read 61.8K   6.1K   88  
Sample of integration of branches of engineering.
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;

using BaseTypes.Interfaces;

using FormulaEditor.Interfaces;

namespace FormulaEditor
{
    /// <summary>
    /// Creator of elementary functions
    /// </summary>
    public class ElementaryFunctionsCreator : IFormulaObjectCreator
    {
        /// <summary>
        /// Singleton
        /// </summary>
        public static readonly ElementaryFunctionsCreator Object = new ElementaryFunctionsCreator(true);

        /// <summary>
        /// Detectors of unary operations
        /// </summary>
        protected ArrayList unaryDetectors = new ArrayList();
        
        /// <summary>
        /// Detyectors of binary operations
        /// </summary>
        protected IBinaryDetector[] detectors;

        const Double a = 0;

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

        /// <summary>
        /// Default constructor
        /// </summary>
        protected ElementaryFunctionsCreator()
            : this(true)
        {
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="init">Initialization sign</param>
        protected ElementaryFunctionsCreator(bool init)
        {
            if (!init)
            {
                return;
            }
            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 virtual IObjectOperation GetPowerOperation(object valType, object powType)
        {
            if (valType.Equals(a) & powType.Equals(a))
            {
                return new ElementaryPowerOperation(valType, powType);
            }
            return null;
        }
    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


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