1 /******************************************************************************
2 Copyright (c) 2007 netAllied GmbH, Tettnang
3 
4 Permission is hereby granted, free of charge, to any person
5 obtaining a copy of this software and associated documentation
6 files (the "Software"), to deal in the Software without
7 restriction, including without limitation the rights to use,
8 copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following
11 conditions:
12 
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
24 ******************************************************************************/
25 
26 #ifndef __MATHML_AST_LOGIC_EXPRESSION_H___
27 #define __MATHML_AST_LOGIC_EXPRESSION_H___
28 
29 #include "MathMLSolverPrerequisites.h"
30 #include "MathMLASTNode.h"
31 
32 namespace MathML
33 {
34 
35     namespace AST
36     {
37         /** String representation for enum Operator::AND. */
38         static const String OPERATOR_LOGIC_AND = "&&";
39         /** String representation for enum Operator::OR. */
40         static const String OPERATOR_LOGIC_OR = "||";
41         /** String representation for enum Operator::XOR. */
42         static const String OPERATOR_LOGIC_XOR = "^";
43         /** String representation for invalid operator. */
44         static const String OPERATOR_LOGIC_ILLEGAL = "ILLEGAL";
45 
46         /** Specialized logic node implementing INode. */
47 
48         class _MATHML_SOLVER_EXPORT LogicExpression : public INode
49         {
50 
51         public:
52             /** Enumeration of the logic operators. */
53             enum Operator
54             {
55                 AND,
56                 OR,
57                 XOR
58 
59                 //NOT is represented in unary expression.
60             };
61 
62         private:
63             /** The operand list for the same type of logic operation. */
64             NodeList mOperands;
65 
66             /** The operator of the logic expression. */
67             Operator mOperator;
68 
69             /** Disable copy construction to avoid expensive deep copies of big trees.
70             */
71             LogicExpression( const LogicExpression& );
72             LogicExpression& operator=( const LogicExpression& );
73 
74         public:
75             /** C-tor. */
76             LogicExpression();
77 
78             /** D-tor. */
79             ~LogicExpression();
80 
81             // see INode::accept(IVisitor* )
82             virtual void accept( IVisitor* visitor ) const;
83 
84 			// see INode::getType()
getNodeType()85 			virtual NodeType getNodeType() const { return LOGICAL; }
86 
87             /** @return a copy of this node. */
88             virtual INode* clone(CloneFlags cloneFlags) const;
89 
90             /** Getter for the operator of the logic expression.
91             @return The operator of the expression.
92             */
93             virtual Operator getOperator() const;
94 
95             /** Setter for the operator of the logic expression.
96             @param op The operator to set.
97             */
98             virtual void setOperator( Operator op );
99 
100             /** Getter for the operator of the expression.
101             @return The operator of the expression as string.
102             */
103             virtual String getOperatorString() const;
104 
105             /** Setter for the operator of the expression.
106             @param op The operator to set as string.
107             */
108             virtual void setOperator( const String& op );
109 
110 			/** Getter for the operands of the logic expression.
111 			@return The list of operands.
112 			*/
113 			virtual const NodeList& getOperands() const;
114 
115 			/** Getter for the operands of the logic expression.
116 			@return The list of operands.
117 			*/
118 			virtual NodeList& getOperands();
119 
120             /** Adds an operand to the logic expression.
121             @param operand The operand to add to the list of operands.
122             */
123             virtual void addOperand( INode* operand );
124 
125             /** Returns a string representation of passed operator. */
126             static String operatorString( Operator op );
127         };
128 
129     } //namespace AST
130 
131 } //namespace MathML
132 
133 #endif //__MATHML_AST_LOGIC_EXPRESSION_H___
134