• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List

/export/development/ViennaMath/viennamath/compiletime/ct_binary_expr.hpp

Go to the documentation of this file.
00001 #ifndef VIENNAMATH_COMPILETIME_CT_BINARY_EXPR_HPP
00002 #define VIENNAMATH_COMPILETIME_CT_BINARY_EXPR_HPP
00003 
00004 /* =======================================================================
00005    Copyright (c) 2012, Institute for Microelectronics,
00006                        Institute for Analysis and Scientific Computing,
00007                        TU Wien.
00008                              -----------------
00009                ViennaMath - Symbolic and Numerical Math in C++
00010                              -----------------
00011 
00012    Author:     Karl Rupp                          rupp@iue.tuwien.ac.at
00013 
00014    License:    MIT (X11), see file LICENSE in the ViennaMath base directory
00015 ======================================================================= */
00016 
00017 
00018 
00019 
00020 #include <ostream>
00021 #include "viennamath/forwards.h"
00022 #include "viennamath/compiletime/binary_op_tags.hpp"
00023 
00028 namespace viennamath
00029 {
00030   
00037   template <typename LHS,
00038             typename OP,
00039             typename RHS>
00040   class ct_binary_expr
00041   {
00042       typedef typename expression_traits<LHS>::const_reference_type    internal_lhs_type;
00043       typedef typename expression_traits<RHS>::const_reference_type    internal_rhs_type;
00044     public:
00045       typedef typename OP::numeric_type            numeric_type;
00046       
00047       typedef LHS    lhs_type;
00048       typedef OP     op_type;
00049       typedef RHS    rhs_type;
00050       
00051       explicit ct_binary_expr() : lhs_(LHS()), rhs_(RHS()) {} 
00052       
00053       explicit ct_binary_expr(internal_lhs_type lhs,
00054                               internal_rhs_type rhs) : lhs_(lhs), rhs_(rhs) {}
00055                           
00056       internal_lhs_type lhs() const { return lhs_; }
00057       internal_rhs_type rhs() const { return rhs_; }
00058       
00059       numeric_type operator()() const
00060       {
00061         return OP::apply(static_cast<numeric_type>(lhs_), static_cast<numeric_type>(rhs_));
00062       }
00063       
00064       template <typename VectorType>
00065       numeric_type operator()(VectorType const & v) const
00066       {
00067         //std::cout << "ct_expr::operator()" << std::endl;
00068         return OP::apply(static_cast<numeric_type>(lhs_(v)), static_cast<numeric_type>(rhs_(v)));
00069       }
00070 
00071     private:
00072       internal_lhs_type lhs_;
00073       internal_rhs_type rhs_;
00074   };
00075   
00076   
00077   //stream operator for output:
00079   template <typename LHS, typename OP, typename RHS>
00080   std::ostream& operator<<(std::ostream & stream, ct_binary_expr<LHS, OP, RHS> const & other)
00081   {
00082     stream << "[" << other.lhs() << OP().str() << other.rhs() << "]";
00083     return stream;
00084   }
00085 
00086   
00087 }
00088 
00089 #endif

Generated on Wed Feb 29 2012 21:50:43 for ViennaMath by  doxygen 1.7.1