Click here to Skip to main content
15,886,840 members
Articles / Programming Languages / C#

Grandiose Projects 3. Compatibility with Simulink

Rate me:
Please Sign up or sign in to vote.
4.27/5 (11 votes)
8 Feb 2010CPOL23 min read 47.7K   5.9K   38  
Import of Simulink files
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;


using CategoryTheory;


namespace DataPerformer
{
    [Serializable()]
    public class SwitchLink : ICategoryArrow, ISerializable, IRemovableObject
    {
        private FormulaDataConsumer target;
        private ISwitched source;
        //private bool isUpdatable = false;
        /// <summary>
        /// Linked object
        /// </summary>
        protected object obj;
        int a;
        public SwitchLink()
        {
            a = 0;
        }

        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        public SwitchLink(SerializationInfo info, StreamingContext context)
        {
            a = (int)info.GetValue("A", typeof(int));
        }
        /// <summary>
        /// ISerializable interface implementation
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("A", a);
        }

        /// <summary>
        /// Creates correspond xml
        /// </summary>
        /// <param name="doc">document to create element</param>
        /// <returns>The created element</returns>
        /*public XmlElement CreateXml(XmlDocument doc)
        {
            XmlElement el = doc.CreateElement("SwitchLink");
            return el;
        }*/



        /// <summary>
        /// Composes this arrow "f" with next arrow "g" 
        /// </summary>
        /// <param name="category"> The category of arrow</param>
        /// <param name="next"> The next arrow "g" </param>
        /// <returns>Composition "fg" </returns>
        public ICategoryArrow Compose(ICategory category, ICategoryArrow next)
        {
            return null;
        }

        /// <summary>
        /// The category of this object
        /// </summary>
        public ICategory Category
        {
            get
            {
                return null;
            }
        }

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


        /// <summary>
        /// The post remove operation
        /// </summary>
        public void RemoveObject()
        {
            source.RemoveSwitch(this);
        }



        /// <summary>
        /// The source of this arrow
        /// </summary>
        public ICategoryObject Source
        {
            get
            {
                return source as ICategoryObject;
            }
            set
            {
                if (!(value is ISwitched))
                {
                    CategoryException.ThrowIllegalSourceException();
                }
                source = value as ISwitched;
            }
        }

        /// <summary>
        /// The target of this arrow
        /// </summary>
        public ICategoryObject Target
        {
            get
            {
                return target;
            }
            set
            {
                if (source == null)
                {
                    throw new Exception("Source object is missing");
                }
                if (source == value)
                {
                    throw new Exception("Target of switch link should not concide with source");
                }
                if (!(value is FormulaDataConsumer))
                {
                    CategoryException.ThrowIllegalTargetException();
                }
                target = value as FormulaDataConsumer;
                source.AddSwitch(this);
            }
        }

        public bool IsMonomorphism
        {
            get
            {
                return false;
            }
        }

        public bool IsEpimorphism
        {
            get
            {
                return false;
            }
        }

        public bool IsIsomorphism
        {
            get
            {
                return false;
            }
        }

    }

    /// <summary>
    /// Switched object
    /// </summary>
    public interface ISwitched
    {
        /// <summary>
        /// Adds switch link
        /// </summary>
        /// <param name="link">Link to add</param>
        void AddSwitch(SwitchLink link);

        /// <summary>
        /// Removes switch link
        /// </summary>
        /// <param name="link">Link to remove</param>
        void RemoveSwitch(SwitchLink link);
    }


}

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