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

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

Go to the documentation of this file.
00001 #ifndef VIENNAMATH_COMPILETIME_CT_UNARY_EXPR_HPP
00002 #define VIENNAMATH_COMPILETIME_CT_UNARY_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/unary_op_tags.hpp"
00023 
00028 namespace viennamath
00029 {
00030   
00031   //A compile time expression
00037   template <typename LHS,
00038             typename OP>
00039   class ct_unary_expr
00040   {
00041       typedef typename expression_traits<LHS>::const_reference_type    internal_lhs_type;
00042     public:
00043       typedef typename OP::numeric_type            numeric_type;
00044       
00045       typedef LHS    lhs_type;
00046       typedef OP     op_type;
00047       
00048       explicit ct_unary_expr() : lhs_(LHS()) {} 
00049       
00050       explicit ct_unary_expr(internal_lhs_type lhs) : lhs_(lhs){}
00051      
00053       internal_lhs_type lhs() const { return lhs_; }
00054       
00055       template <typename VectorType>
00056       numeric_type operator()(VectorType const & v) const
00057       {
00058         //std::cout << "ct_expr::operator()" << std::endl;
00059         return OP::apply(static_cast<numeric_type>(lhs_(v)), static_cast<numeric_type>(rhs_(v)));
00060       }
00061       
00062     private:
00063       internal_lhs_type lhs_;
00064   };
00065   
00066   
00067   //stream operator for output:
00069   template <typename LHS, typename OP>
00070   std::ostream& operator<<(std::ostream & stream, ct_unary_expr<LHS, OP> const & other)
00071   {
00072     stream << "[" << other.lhs() << OP().str() << "]";
00073     return stream;
00074   }
00075 
00076   
00077 }
00078 
00079 #endif

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