cheshirekow  v0.1.0
lvalue.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of fiber.
5  *
6  * fiber is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * fiber is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with fiber. If not, see <http://www.gnu.org/licenses/>.
18  */
25 #ifndef FIBER_LVALUE_H_
26 #define FIBER_LVALUE_H_
27 
28 
29 namespace fiber {
30 
32 template <typename Scalar, class Exp>
33 class _LValue {
34  public:
36 
37  Size size() const { return static_cast<Exp const&>(*this).size(); }
38  Size rows() const { return static_cast<Exp const&>(*this).rows(); }
39  Size cols() const { return static_cast<Exp const&>(*this).cols(); }
40 
41  Scalar& operator[](Size i) { return static_cast<Exp&>(*this)[i]; }
42 
43  Scalar const& operator[](Size i) const {
44  return static_cast<Exp const&>(*this)[i];
45  }
46 
47  Scalar& operator()(Size i, Size j) {
48  return static_cast<Exp&>(*this)(i, j);
49  }
50 
51  Scalar const& operator()(Size i, Size j) const {
52  return static_cast<Exp const&>(*this)(i, j);
53  }
54 
57  StreamAssign stream(*this);
58  return stream << x;
59  }
60 
61  template <class Exp2>
63  assert(rows() == B.rows());
64  assert(cols() == B.cols());
65  for (int i = 0; i < rows(); i++) {
66  for (int j = 0; j < cols(); j++) {
67  (*this)(i, j) = B(i, j);
68  }
69  }
70  return *this;
71  }
72 };
73 
76 template <typename Scalar, class Exp>
78  return exp;
79 }
80 
81 } // namespace fiber
82 
83 
84 #endif // FIBER_LVALUE_H_
Scalar & operator[](Size i)
Definition: lvalue.h:41
Size cols() const
Definition: lvalue.h:39
StreamAssign operator<<(Scalar x)
returns a stream for assignment
Definition: lvalue.h:56
expression template for rvalues
Definition: rvalue.h:33
Size cols() const
Definition: rvalue.h:37
unsigned int Size
Definition: fiber.h:32
Size rows() const
Definition: lvalue.h:38
Size rows() const
Definition: rvalue.h:36
StreamAssignment< _LValue< Scalar, Exp > > StreamAssign
Definition: lvalue.h:35
Scalar const & operator()(Size i, Size j) const
Definition: lvalue.h:51
_LValue< Scalar, Exp > & operator=(_RValue< Scalar, Exp2 > const &B)
Definition: lvalue.h:62
Size size() const
Definition: lvalue.h:37
Scalar const & operator[](Size i) const
Definition: lvalue.h:43
expression template for rvalues
Definition: lvalue.h:33
Scalar & operator()(Size i, Size j)
Definition: lvalue.h:47
_LValue< Scalar, Exp > & LValue(_LValue< Scalar, Exp > &exp)
Explicitly expose _LValue of an expressions, can be used to help the compiler disambiguate overloads...
Definition: lvalue.h:77