// @(#)root/smatrix:$Name: $:$Id: Expression.h,v 1.5 2006/02/08 16:52:38 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_Expression #define ROOT_Math_Expression // ******************************************************************** // // source: // // type: source code // // created: 19. Mar 2001 // // author: Thorsten Glebe // HERA-B Collaboration // Max-Planck-Institut fuer Kernphysik // Saupfercheckweg 1 // 69117 Heidelberg // Germany // E-mail: T.Glebe@mpi-hd.mpg.de // // Description: Expression Template Elements for SVector // // changes: // 19 Mar 2001 (TG) creation // 20 Mar 2001 (TG) added rows(), cols() to Expr // 21 Mar 2001 (TG) added Expr::value_type // 11 Apr 2001 (TG) rows(), cols() replaced by rows, cols // 10 Okt 2001 (TG) added print() and operator<<() for Expr class // // ******************************************************************** /** Expr. An Expression wrapper class. @memo Expr. @author T. Glebe */ //============================================================================== // Expr: class representing SVector expressions //============================================================================= // originally references where used as data members of operation wrappers // problem appear on Windows because original ref goes out of scope use then by value by default (like in tvmet) //#define SMATRIX_USE_REFERENCES #include namespace ROOT { namespace Math { // template class MatRepStd; template class VecExpr { public: typedef T value_type; /// VecExpr(const ExprType& rhs) : rhs_(rhs) {} /// ~VecExpr() {} /// inline T apply(unsigned int i) const { return rhs_.apply(i); } #ifdef OLD_IMPL /// static const unsigned int rows = D; /// ///static const unsigned int cols = D2; #else // use enumerations enum { kRows = D }; #endif /// used by operator<<() std::ostream& print(std::ostream& os) const { os.setf(std::ios::right,std::ios::adjustfield); unsigned int i=0; os << "[ "; for(; i class MatRepStd; template > class Expr { public: typedef T value_type; /// Expr(const ExprType& rhs) : rhs_(rhs) {} /// ~Expr() {} /// inline T apply(unsigned int i) const { return rhs_.apply(i); } #ifdef OLD_IMPL /// static const unsigned int rows = D; /// static const unsigned int cols = D2; #else // use enumerations enum { /// kRows = D, /// kCols = D2 }; #endif /// used by operator<<() std::ostream& print(std::ostream& os) const { os.setf(std::ios::right,std::ios::adjustfield); if(D2 == 1 || D2 ==0 ) { unsigned int i=0; for(; i inline std::ostream& operator<<(std::ostream& os, const VecExpr& rhs) { return rhs.print(os); } template inline std::ostream& operator<<(std::ostream& os, const Expr& rhs) { return rhs.print(os); } /** BinaryOp. A class representing binary operators in the parse tree. @memo BinaryOp @author T. Glebe */ //============================================================================== // BinaryOp //============================================================================== template class BinaryOp { public: /// BinaryOp( Operator /* op */, const LHS& lhs, const RHS& rhs) : lhs_(lhs), rhs_(rhs) {} /// ~BinaryOp() {} /// inline T apply(unsigned int i) const { return Operator::apply(lhs_.apply(i), rhs_.apply(i)); } protected: #ifdef SMATRIX_USE_REFERENCES const LHS& lhs_; const RHS& rhs_; #else const LHS lhs_; const RHS rhs_; #endif }; /** UnaryOp. A class representing unary operators in the parse tree. @memo UnaryOp @author T. Glebe */ //============================================================================== // UnaryOp //============================================================================== template class UnaryOp { public: /// UnaryOp( Operator /* op */ , const RHS& rhs) : rhs_(rhs) {} /// ~UnaryOp() {} /// inline T apply(unsigned int i) const { return Operator::apply(rhs_.apply(i)); } protected: #ifdef SMATRIX_USE_REFERENCES const RHS& rhs_; #else const RHS rhs_; #endif }; /** Constant. A class representing constant expressions (literals) in the parse tree. @memo Constant @author T. Glebe */ //============================================================================== // Constant //============================================================================== template class Constant { public: /// Constant( const T& rhs ) : rhs_(rhs) {} /// ~Constant() {} /// inline T apply(unsigned int /*i */ ) const { return rhs_; } protected: #ifdef SMATRIX_USE_REFERENCES const T& rhs_; #else const T rhs_; #endif }; } // namespace Math } // namespace ROOT #endif /* ROOT_Math_Expression */