SundanceBinaryExpr.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #ifndef SUNDANCE_BINARYEXPR_H
00032 #define SUNDANCE_BINARYEXPR_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceExprWithChildren.hpp"
00036 #include "SundanceExpr.hpp"
00037 
00038 namespace Sundance
00039 {
00040 using namespace Teuchos;
00041 
00042 /** 
00043  * BinaryExpr is a base class for binary expressions, e.g., sums
00044  * and products. It provides a number of helper methods.
00045  */
00046 class BinaryExpr : public ExprWithChildren
00047 {
00048 public:
00049   /** construct with left and right operands */
00050   BinaryExpr(const RCP<ScalarExpr>& left,
00051     const RCP<ScalarExpr>& right, int sign);
00052 
00053   /** virtual dtor */
00054   virtual ~BinaryExpr() {;}
00055 
00056   /** */
00057   virtual std::ostream& toText(std::ostream& os, bool paren) const ;
00058 
00059   /** */
00060   virtual XMLObject toXML() const ;
00061 
00062   /** */
00063   Expr left() const {return child(0);}
00064 
00065   /** */
00066   Expr right() const {return child(1);}
00067 
00068   /** */
00069   int sign() const {return sign_;}
00070 
00071   /** Downcast the left expr to an evaluatable expr */
00072   const EvaluatableExpr* leftEvaluatable() const 
00073     {return evaluatableChild(0);}
00074 
00075   /** Downcast the right expr to an evaluatable expr */
00076   const EvaluatableExpr* rightEvaluatable() const 
00077     {return evaluatableChild(1);}
00078 
00079   /** Downcast the left expr to a scalar expr */
00080   const ScalarExpr* leftScalar() const {return scalarChild(0);}
00081 
00082   /** Downcast the right expr to a scalar expr */
00083   const ScalarExpr* rightScalar() const {return scalarChild(1);}
00084 
00085   /** Ordering operator for use in transforming exprs to standard form */
00086   virtual bool lessThan(const ScalarExpr* other) const ;
00087 
00088 protected:
00089 
00090           
00091 
00092   /** */
00093   virtual bool parenthesizeSelf() const = 0 ;
00094   /** */
00095   virtual bool parenthesizeOperands() const = 0 ;
00096   /** */
00097   virtual const std::string& xmlTag() const = 0 ;
00098   /** */
00099   virtual const std::string& opChar() const = 0 ;
00100 
00101 
00102 
00103 private:
00104           
00105 
00106   int sign_;
00107 };
00108 }
00109 
00110 #endif

Site Contact