1 #ifndef __EXPRESSION_HH
2 #define __EXPRESSION_HH
39 #include "Riostream.h"
42 template <
class ExprType,
class T,
unsigned int D,
unsigned int D2 = 0>
48 Expr(
const ExprType& rhs) :
55 inline T
apply(
unsigned int i)
const {
60 static const unsigned int rows = D;
62 static const unsigned int cols = D2;
65 std::ostream&
print(std::ostream& os)
const {
66 os.setf(ios::right, ios::adjustfield) ;
71 os << apply(i) <<
", ";
76 for (
unsigned int i=0; i < D; ++i) {
77 for (
unsigned int j=0; j < D2; ++j) {
78 os << setw(12) << apply(i*D2+j);
79 if ((!((j+1)%12)) && (j < D2-1))
98 template <
class A,
class T,
unsigned int D1,
unsigned int D2>
100 return rhs.
print(os);
112 template <
class Operator,
class LHS,
class RHS,
class T>
116 BinaryOp( Operator op,
const LHS& lhs,
const RHS& rhs) :
117 lhs_(lhs), rhs_(rhs) {}
123 inline T
apply(
unsigned int i)
const {
124 return Operator::apply(lhs_.apply(i), rhs_.apply(i));
142 template <
class Operator,
class RHS,
class T>
153 inline T
apply(
unsigned int i)
const {
154 return Operator::apply(rhs_.apply(i));
182 inline T
apply(
unsigned int i)
const {
return rhs_; }
std::ostream & operator<<(std::ostream &os, const Expr< A, T, D1, D2 > &rhs)
Definition: Expression.hh:99
Definition: Expression.hh:113
const RHS & rhs_
Definition: Expression.hh:129
T apply(unsigned int i) const
Definition: Expression.hh:123
const LHS & lhs_
Definition: Expression.hh:128
BinaryOp(Operator op, const LHS &lhs, const RHS &rhs)
Definition: Expression.hh:116
~BinaryOp()
Definition: Expression.hh:120
Definition: Expression.hh:172
const T & rhs_
Definition: Expression.hh:185
Constant(const T &rhs)
Definition: Expression.hh:175
T apply(unsigned int i) const
Definition: Expression.hh:182
~Constant()
Definition: Expression.hh:179
Definition: Expression.hh:43
T value_type
Definition: Expression.hh:45
T apply(unsigned int i) const
Definition: Expression.hh:55
ExprType rhs_
Definition: Expression.hh:92
std::ostream & print(std::ostream &os) const
used by operator<<()
Definition: Expression.hh:65
~Expr()
Definition: Expression.hh:52
Expr(const ExprType &rhs)
Definition: Expression.hh:48
Definition: Expression.hh:143
T apply(unsigned int i) const
Definition: Expression.hh:153
UnaryOp(Operator op, const RHS &rhs)
Definition: Expression.hh:146
const RHS & rhs_
Definition: Expression.hh:158
~UnaryOp()
Definition: Expression.hh:150