00001 #ifndef VIENNAMATH_RUNTIME_EQUATION_HPP
00002 #define VIENNAMATH_RUNTIME_EQUATION_HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <ostream>
00021 #include "viennamath/forwards.h"
00022
00027 namespace viennamath
00028 {
00029
00031 template <typename InterfaceType>
00032 class rt_equation
00033 {
00034
00035 public:
00036 typedef rt_expr<InterfaceType> value_type;
00037 typedef InterfaceType interface_type;
00038
00039 rt_equation() {};
00040
00041
00042 rt_equation(const rt_expr<InterfaceType> & lhs,
00043 const rt_expr<InterfaceType> & rhs) : lhs_(lhs.get()->clone()), rhs_(rhs.get()->clone()) {}
00044
00046 rt_expr<InterfaceType> const & lhs() const { return lhs_; }
00048 rt_expr<InterfaceType> const & rhs() const { return rhs_; }
00049
00050 private:
00051 rt_expr<InterfaceType> lhs_;
00052 rt_expr<InterfaceType> rhs_;
00053 };
00054
00056 template <typename InterfaceType>
00057 std::ostream& operator<<(std::ostream & stream, rt_equation<InterfaceType> const & e)
00058 {
00059 stream << "equation(" << e.lhs() << " = " << e.rhs() << ")";
00060 return stream;
00061 }
00062
00063
00064
00065
00067
00068
00069
00070
00071
00072
00074
00075 template <typename NumericT, typename InterfaceType, typename RHSType>
00076 rt_equation<InterfaceType> make_equation(typename InterfaceType::numeric_type lhs, rt_constant<NumericT, InterfaceType> const & rhs)
00077 {
00078 return rt_equation<InterfaceType>(lhs, rhs);
00079 }
00080
00082 template <typename InterfaceType>
00083 rt_equation<InterfaceType> make_equation(typename InterfaceType::numeric_type lhs, rt_variable<InterfaceType> const & rhs)
00084 {
00085 return rt_equation<InterfaceType>(lhs, rhs);
00086 }
00087
00089 template <id_type id>
00090 rt_equation<> make_equation(default_numeric_type lhs, ct_variable<id> const & rhs)
00091 {
00092 return rt_equation<>(lhs, rhs);
00093 }
00094
00096 template <typename InterfaceType>
00097 rt_equation<InterfaceType> make_equation(typename InterfaceType::numeric_type lhs, rt_unary_expr<InterfaceType> const & rhs)
00098 {
00099 return rt_equation<InterfaceType>(lhs, rhs);
00100 }
00101
00103 template <typename InterfaceType>
00104 rt_equation<InterfaceType> make_equation(typename InterfaceType::numeric_type lhs, rt_binary_expr<InterfaceType> const & rhs)
00105 {
00106 return rt_equation<InterfaceType>(lhs, rhs);
00107 }
00108
00110 template <typename InterfaceType>
00111 rt_equation<InterfaceType> make_equation(typename InterfaceType::numeric_type lhs, rt_expr<InterfaceType> const & rhs)
00112 {
00113 return rt_equation<InterfaceType>(lhs, rhs);
00114 }
00115
00116
00117
00119 template <typename NumericT, typename InterfaceType, typename RHSType>
00120 rt_equation<InterfaceType> make_equation(rt_constant<NumericT, InterfaceType> const & lhs, RHSType const & rhs)
00121 {
00122 return rt_equation<InterfaceType>(lhs, rhs);
00123 }
00124
00125
00127 template <typename InterfaceType, typename RHSType>
00128 rt_equation<InterfaceType> make_equation(rt_variable<InterfaceType> const & lhs, RHSType const & rhs)
00129 {
00130 return rt_equation<InterfaceType>(lhs, rhs);
00131 }
00132
00133
00135 template <typename InterfaceType, typename RHSType>
00136 rt_equation<InterfaceType> make_equation(rt_function_symbol<InterfaceType> const & lhs, RHSType const & rhs)
00137 {
00138 return rt_equation<InterfaceType>(lhs, rhs);
00139 }
00140
00141
00143 template <typename InterfaceType, typename RHSType>
00144 rt_equation<InterfaceType> make_equation(rt_unary_expr<InterfaceType> const & lhs, RHSType const & rhs)
00145 {
00146 return rt_equation<InterfaceType>(lhs, rhs);
00147 }
00148
00149
00150
00152 template <typename InterfaceType, typename RHSType>
00153 rt_equation<InterfaceType> make_equation(rt_binary_expr<InterfaceType> const & lhs, RHSType const & rhs)
00154 {
00155 return rt_equation<InterfaceType>(lhs, rhs);
00156 }
00157
00158
00160 template <typename InterfaceType, typename RHSType>
00161 rt_equation<InterfaceType> make_equation(rt_expr<InterfaceType> const & lhs, RHSType const & rhs)
00162 {
00163 return rt_equation<InterfaceType>(lhs, rhs);
00164 }
00165
00166
00168 template <typename LHS, typename OP, typename RHS, typename RHSType>
00169 rt_equation<> make_equation(ct_binary_expr<LHS, OP, RHS> const & lhs, RHSType const & rhs)
00170 {
00171 return rt_equation<>(lhs, rhs);
00172 }
00173
00175 template <typename LHS, typename OP, typename RHSType>
00176 rt_equation<> make_equation(ct_unary_expr<LHS, OP> const & lhs, RHSType const & rhs)
00177 {
00178 return rt_equation<>(lhs, rhs);
00179 }
00180
00182 template <long val, typename RHSType>
00183 rt_equation<> make_equation(ct_constant<val> const & lhs, RHSType const & rhs)
00184 {
00185 return rt_equation<>(lhs, rhs);
00186 }
00187
00189 template <typename TAG, typename RHSType>
00190 rt_equation<> make_equation(ct_function_symbol<TAG> const & lhs, RHSType const & rhs)
00191 {
00192 return rt_equation<>(lhs, rhs);
00193 }
00194
00196 template <id_type id, typename RHSType>
00197 rt_equation<> make_equation(ct_variable<id> const & lhs, RHSType const & rhs)
00198 {
00199 return rt_equation<>(lhs, rhs);
00200 }
00201
00202 }
00203
00204 #endif