Inheritance: XmlObjectNode, IFormulaTree
コード例 #1
0
 public static XmlFormulaTree CreateRoundNode(XmlFormulaTree child)
 {
     return(new XmlFormulaTree
     {
         VariableType = "FUNCTION",
         VariableValue = "ROUND",
         LeftChild = child,
         RightChild = null
     });
 }
コード例 #2
0
 public static XmlFormulaTree CreateRandomNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return(new XmlFormulaTree
     {
         VariableType = "FUNCTION",
         VariableValue = "RAND",
         LeftChild = leftChild,
         RightChild = rightChild
     });
 }
コード例 #3
0
 public static XmlFormulaTree CreateSubtractNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return(new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "MINUS",
         LeftChild = leftChild,
         RightChild = rightChild
     });
 }
コード例 #4
0
 public static XmlFormulaTree CreateArctanNode(XmlFormulaTree child)
 {
     return(new XmlFormulaTree
     {
         VariableType = "FUNCTION",
         VariableValue = "ARCTAN",
         LeftChild = child,
         RightChild = null
     });
 }
コード例 #5
0
 public static XmlFormulaTree CreateGreaterEqualNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return(new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "GREATER_OR_EQUAL",
         LeftChild = leftChild,
         RightChild = rightChild
     });
 }
コード例 #6
0
 public static XmlFormulaTree CreateOrNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return(new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "LOGICAL_OR",
         LeftChild = leftChild,
         RightChild = rightChild
     });
 }
コード例 #7
0
 public static XmlFormulaTree CreateLessNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return(new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "SMALLER_THAN",
         LeftChild = leftChild,
         RightChild = rightChild
     });
 }
コード例 #8
0
 public static XmlFormulaTree CreateNegativeSignNode(XmlFormulaTree child)
 {
     return(new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "MINUS",
         LeftChild = null,
         RightChild = child
     });
 }
コード例 #9
0
 public static XmlFormulaTree CreateDivideNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return(new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "DIVIDE",
         LeftChild = leftChild,
         RightChild = rightChild
     });
 }
コード例 #10
0
 public static XmlFormulaTree CreateNotEqualsNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return(new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "NOT_EQUAL",
         LeftChild = leftChild,
         RightChild = rightChild
     });
 }
コード例 #11
0
 public static XmlFormulaTree CreateMultiplyNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return(new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "MULT",
         LeftChild = leftChild,
         RightChild = rightChild
     });
 }
コード例 #12
0
 public static XmlFormulaTree CreateSubtractNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "MINUS",
         LeftChild = leftChild,
         RightChild = rightChild
     };
 }
コード例 #13
0
 public static XmlFormulaTree CreateParenthesesNode(XmlFormulaTree child)
 {
     return(new XmlFormulaTree
     {
         VariableType = "BRACKET",
         VariableValue = null,
         LeftChild = null,
         RightChild = child
     });
 }
コード例 #14
0
 public static XmlFormulaTree CreateNotNode(XmlFormulaTree child)
 {
     return(new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "LOGICAL_NOT",
         LeftChild = null,
         RightChild = child
     });
 }
コード例 #15
0
        public override bool Equals(System.Object obj)
        {
            XmlFormulaTree t = obj as XmlFormulaTree;

            if ((object)t == null)
            {
                return(false);
            }

            return(this.Equals(t));
        }
コード例 #16
0
        internal override void LoadFromXml(XElement xRoot)
        {
            if(xRoot.Element(XmlConstants.LeftChild) != null)
                LeftChild = new XmlFormulaTree(xRoot.Element(XmlConstants.LeftChild));
            if (xRoot.Element(XmlConstants.RightChild) != null)
                RightChild = new XmlFormulaTree(xRoot.Element(XmlConstants.RightChild));

            if (xRoot.Element(XmlConstants.Type) != null)
            VariableType = xRoot.Element(XmlConstants.Type).Value;
            if (xRoot.Element(XmlConstants.Value) != null)
            VariableValue = xRoot.Element(XmlConstants.Value).Value;
        }
コード例 #17
0
        internal override void LoadFromXml(XElement xRoot)
        {
            //TODO: notwendig? oder doch nur  if (xRoot.Element(XmlConstants.Formula) != null)

            //if (xRoot.Element(XmlConstants.Formula) != null)
            if (xRoot != null)
            {
                if (xRoot.Name.LocalName == XmlConstants.Formula)
                {
                    FormulaTree = new XmlFormulaTree(xRoot);//.Element(XmlConstants.Formula));
                }
            }
        }
コード例 #18
0
        internal override void LoadFromXml(XElement xRoot)
        {
            //TODO: notwendig? oder doch nur  if (xRoot.Element(XmlConstants.Formula) != null)
            
            //if (xRoot.Element(XmlConstants.Formula) != null)
            if (xRoot != null)
            {
                if (xRoot.Name.LocalName == XmlConstants.Formula)
            {
                    FormulaTree = new XmlFormulaTree(xRoot);//.Element(XmlConstants.Formula));
                }
            }

        }
コード例 #19
0
        public bool Equals(XmlFormulaTree t)
        {
            bool type = this.VariableType.Equals(t.VariableType);
            bool value = this.VariableValue.Equals(t.VariableValue);
            bool left = false;
            if ((this.LeftChild == null) && (t.LeftChild == null))
                left = true;
            else if ((this.LeftChild != null) && (t.LeftChild != null))
                left = this.LeftChild.Equals(t.LeftChild);
            else left = false;

            bool right = false;
            if ((this.RightChild == null) && (t.RightChild == null))
                right = true;
            else if ((this.RightChild != null) && (t.RightChild != null))
                right = this.RightChild.Equals(t.RightChild);
            else right = false;

            return type && value && left && right;
        }
コード例 #20
0
 public static XmlFormulaTree CreateNumberNode(double value)
 {
     if (value >= 0)
     {
         return new XmlFormulaTree
             {
                 VariableType = "NUMBER",
                 VariableValue = value.ToString(CultureInfo.InvariantCulture)
             };
     }
     else
     {
         XmlFormulaTree child = new XmlFormulaTree
     {
             VariableType = "NUMBER",
             VariableValue = Math.Abs(value).ToString(CultureInfo.InvariantCulture)
         };
         return CreateNegativeSignNode(child);
     }
 }
コード例 #21
0
        internal override void LoadFromXml(XElement xRoot)
        {
            if (xRoot.Element(XmlConstants.LeftChild) != null)
            {
                LeftChild = new XmlFormulaTree(xRoot.Element(XmlConstants.LeftChild));
            }
            if (xRoot.Element(XmlConstants.RightChild) != null)
            {
                RightChild = new XmlFormulaTree(xRoot.Element(XmlConstants.RightChild));
            }

            if (xRoot.Element(XmlConstants.Type) != null)
            {
                VariableType = xRoot.Element(XmlConstants.Type).Value;
            }
            if (xRoot.Element(XmlConstants.Value) != null)
            {
                VariableValue = xRoot.Element(XmlConstants.Value).Value;
            }
        }
コード例 #22
0
 public static XmlFormulaTree CreateNumberNode(double value)
 {
     if (value >= 0)
     {
         return(new XmlFormulaTree
         {
             VariableType = "NUMBER",
             VariableValue = value.ToString(CultureInfo.InvariantCulture)
         });
     }
     else
     {
         XmlFormulaTree child = new XmlFormulaTree
         {
             VariableType  = "NUMBER",
             VariableValue = Math.Abs(value).ToString(CultureInfo.InvariantCulture)
         };
         return(CreateNegativeSignNode(child));
     }
 }
コード例 #23
0
        public bool Equals(XmlFormulaTree t)
        {
            bool type  = this.VariableType.Equals(t.VariableType);
            bool value = this.VariableValue.Equals(t.VariableValue);
            bool left  = false;

            if ((this.LeftChild == null) && (t.LeftChild == null))
            {
                left = true;
            }
            else if ((this.LeftChild != null) && (t.LeftChild != null))
            {
                left = this.LeftChild.Equals(t.LeftChild);
            }
            else
            {
                left = false;
            }

            bool right = false;

            if ((this.RightChild == null) && (t.RightChild == null))
            {
                right = true;
            }
            else if ((this.RightChild != null) && (t.RightChild != null))
            {
                right = this.RightChild.Equals(t.RightChild);
            }
            else
            {
                right = false;
            }

            return(type && value && left && right);
        }
コード例 #24
0
 public static XmlFormulaTree CreateArctanNode(XmlFormulaTree child)
 {
     return new XmlFormulaTree
     {
         VariableType = "FUNCTION",
         VariableValue = "ARCTAN",
         LeftChild = child,
         RightChild = null
     };
 }
コード例 #25
0
 public static XmlFormulaTree CreateRoundNode(XmlFormulaTree child)
 {
     return new XmlFormulaTree
     {
         VariableType = "FUNCTION",
         VariableValue = "ROUND",
         LeftChild = child,
         RightChild = null
     };
 }
コード例 #26
0
 public static XmlFormulaTree CreateOrNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "LOGICAL_OR",
         LeftChild = leftChild,
         RightChild = rightChild
     };
 }
コード例 #27
0
 public static XmlFormulaTree CreateNotNode(XmlFormulaTree child)
 {
     return new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "LOGICAL_NOT",
         LeftChild = null,
         RightChild = child
     };
 }
コード例 #28
0
 public static XmlFormulaTree CreateGreaterEqualNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "GREATER_OR_EQUAL",
         LeftChild = leftChild,
         RightChild = rightChild
     };
 }
コード例 #29
0
 protected override XmlFormulaTree ToXml(XmlFormulaTree child)
 {
     return XmlFormulaTreeFactory.CreateNegativeSignNode(child);
 }
コード例 #30
0
 public static XmlFormulaTree CreateNotEqualsNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "NOT_EQUAL",
         LeftChild = leftChild,
         RightChild = rightChild
     };
 }
コード例 #31
0
 protected override XmlFormulaTree ToXml(XmlFormulaTree firstChild, XmlFormulaTree secondChild)
 {
     return XmlFormulaTreeFactory.CreateRandomNode(firstChild, secondChild);
 }
コード例 #32
0
 public static XmlFormulaTree CreateMultiplyNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "MULT",
         LeftChild = leftChild,
         RightChild = rightChild
     };
 }
コード例 #33
0
 public static XmlFormulaTree CreateDivideNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "DIVIDE",
         LeftChild = leftChild,
         RightChild = rightChild
     };
 }
コード例 #34
0
 protected abstract XmlFormulaTree ToXml(XmlFormulaTree child);
コード例 #35
0
 protected abstract XmlFormulaTree ToXml(XmlFormulaTree firstChild, XmlFormulaTree secondChild);
コード例 #36
0
 protected override XmlFormulaTree ToXml(XmlFormulaTree child)
 {
     return XmlFormulaTreeFactory.CreateSqrtNode(child);
 }
コード例 #37
0
 public static XmlFormulaTree CreateRandomNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return new XmlFormulaTree
     {
         VariableType = "FUNCTION",
         VariableValue = "RAND",
         LeftChild = leftChild,
         RightChild = rightChild
     };
 }
コード例 #38
0
 public static XmlFormulaTree CreateLessNode(XmlFormulaTree leftChild, XmlFormulaTree rightChild)
 {
     return new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "SMALLER_THAN",
         LeftChild = leftChild,
         RightChild = rightChild
     };
 }
コード例 #39
0
 public static XmlFormulaTree CreateParenthesesNode(XmlFormulaTree child)
 {
     return new XmlFormulaTree
     {
         VariableType = "BRACKET",
         VariableValue = null, 
         LeftChild = null,
         RightChild = child
     };
 }
コード例 #40
0
        public void XmlFormulaTreeTest()
        {
            TextReader sr = new StringReader("<formula category=\"IF_CONDITION\"> <leftChild> <leftChild> <leftChild> <leftChild> <leftChild> <type>USER_VARIABLE</type> <value>x speed</value> </leftChild> <rightChild> <type>USER_VARIABLE</type> <value>x speed</value> </rightChild> <type>OPERATOR</type> <value>MULT</value> </leftChild> <rightChild> <leftChild> <type>USER_VARIABLE</type> <value>y speed</value> </leftChild> <rightChild> <type>USER_VARIABLE</type> <value>y speed</value> </rightChild> <type>OPERATOR</type> <value>MULT</value> </rightChild> <type>OPERATOR</type> <value>PLUS</value> </leftChild> <type>FUNCTION</type> <value>SQRT</value> </leftChild> <rightChild> <type>NUMBER</type> <value>2</value> </rightChild> <type>OPERATOR</type> <value>GREATER_THAN</value> </leftChild> <rightChild> <leftChild> <type>SENSOR</type> <value>OBJECT_X</value> </leftChild> <rightChild> <type>NUMBER</type> <value>55</value> </rightChild> <type>OPERATOR</type> <value>SMALLER_THAN</value> </rightChild> <type>OPERATOR</type> <value>LOGICAL_AND</value> </formula>");
            var xRoot = XElement.Load(sr);

            var testObject = new XmlFormulaTree(xRoot);

            var referenceObject = new XmlFormulaTree()
            {
                VariableType = "OPERATOR",
                VariableValue = "LOGICAL_AND",
                LeftChild = new XmlFormulaTree()
                {
                    VariableType = "OPERATOR",
                    VariableValue = "GREATER_THAN",
                    LeftChild = new XmlFormulaTree()
                    {
                        VariableType = "FUNCTION",
                        VariableValue = "SQRT",
                        LeftChild = new XmlFormulaTree()
                        {
                            VariableType = "OPERATOR",
                            VariableValue = "PLUS",
                            LeftChild = new XmlFormulaTree()
                            {
                                VariableType = "OPERATOR",
                                VariableValue = "MULT",
                                LeftChild = new XmlFormulaTree()
                                {
                                    VariableType = "USER_VARIABLE",
                                    VariableValue = "x speed",
                                },
                                RightChild = new XmlFormulaTree()
                                {
                                    VariableType = "USER_VARIABLE",
                                    VariableValue = "x speed",
                                }
                            },
                            RightChild = new XmlFormulaTree()
                            {
                                VariableType = "OPERATOR",
                                VariableValue = "MULT",
                                LeftChild = new XmlFormulaTree()
                                {
                                    VariableType = "USER_VARIABLE",
                                    VariableValue = "y speed",
                                },
                                RightChild = new XmlFormulaTree()
                                {
                                    VariableType = "USER_VARIABLE",
                                    VariableValue = "y speed",
                                }
                            }
                        }
                        // SQRT no RightChild
                    },
                    RightChild = new XmlFormulaTree()
                    {
                        VariableType = "NUMBER",
                        VariableValue = "2",
                    }
                },
                RightChild = new XmlFormulaTree()
                {
                    VariableType = "OPERATOR",
                    VariableValue = "SMALLER_THAN",
                    LeftChild = new XmlFormulaTree()
                    {
                        VariableType = "SENSOR",
                        VariableValue = "OBJECT_X",
                    },
                    RightChild = new XmlFormulaTree()
                    {
                        VariableType = "NUMBER",
                        VariableValue = "55",
                    }
                }
            };

            Assert.AreEqual(referenceObject, testObject);
        }
コード例 #41
0
 public static XmlFormulaTree CreateNegativeSignNode(XmlFormulaTree child)
 {
     return new XmlFormulaTree
     {
         VariableType = "OPERATOR",
         VariableValue = "MINUS",
         LeftChild = null,
         RightChild = child
     };
 }
コード例 #42
0
 protected override XmlFormulaTree ToXml(XmlFormulaTree child)
 {
     return XmlFormulaTreeFactory.CreateParenthesesNode(child);
 }