Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "SundanceBinaryExpr.hpp"
00043 #include "SundanceExpr.hpp"
00044
00045 using namespace Sundance;
00046 using namespace Sundance;
00047
00048 using namespace Sundance;
00049 using namespace Teuchos;
00050
00051
00052 BinaryExpr::BinaryExpr(const RCP<ScalarExpr>& left,
00053 const RCP<ScalarExpr>& right, int sign)
00054 : ExprWithChildren(tuple(left, right)),
00055 sign_(sign)
00056 {}
00057
00058
00059 bool BinaryExpr::lessThan(const ScalarExpr* other) const
00060 {
00061 const BinaryExpr* b = dynamic_cast<const BinaryExpr*>(other);
00062 TEUCHOS_TEST_FOR_EXCEPTION(b==0, std::logic_error, "cast should never fail at this point");
00063
00064 if (sign_ < b->sign_) return true;
00065 if (sign_ > b->sign_) return false;
00066 return ExprWithChildren::lessThan(other);
00067 }
00068
00069 std::ostream& BinaryExpr:: toText(std::ostream& os, bool paren) const
00070 {
00071 if (Expr::showAllParens() || (paren && parenthesizeSelf())) os << "(";
00072 leftScalar()->toText(os, parenthesizeOperands()) ;
00073 os << opChar();
00074 if (leftScalar()->isHungryDiffOp())
00075 {
00076 rightScalar()->toText(os, true);
00077 }
00078 else
00079 {
00080 rightScalar()->toText(os, parenthesizeOperands() || opChar() == "-");
00081 }
00082 if (Expr::showAllParens() || (paren && parenthesizeSelf())) os << ")";
00083
00084 return os;
00085 }
00086
00087
00088 XMLObject BinaryExpr::toXML() const
00089 {
00090 XMLObject rtn(xmlTag());
00091 rtn.addChild(left().toXML());
00092 rtn.addChild(right().toXML());
00093
00094 return rtn;
00095 }
00096
00097