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 mpblocks.
5  *
6  * mpblocks 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  * mpblocks 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 mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_POLYNOMIAL_LVALUE_H_
28 #define MPBLOCKS_POLYNOMIAL_LVALUE_H_
29 
30 namespace mpblocks {
31 namespace polynomial {
32 
34 template <typename Scalar, class Exp>
35 class LValue
36 {
37  public:
39 
40  typedef unsigned int Size_t;
41 
43  Size_t size() const
44  {
45  return static_cast<Exp const&>(*this).size();
46  }
47 
48  Size_t degree() const
49  {
50  return size()-1;
51  }
52 
54  Scalar& operator[]( Size_t i )
55  {
56  return static_cast<Exp&>(*this)[i];
57  }
58 
60  Stream_t operator<<( Scalar x )
61  {
62  Stream_t stream(*this);
63  return stream << x;
64  }
65 
66  template <class Exp2>
68  {
69  resize(B.size());
70  for( int i=0; i < B.size(); i++)
71  (*this)[i] = B[i];
72  return *this;
73  }
74 
75  void resize( Size_t size )
76  {
77  static_cast<Exp*>(this)->resize( size );
78  }
79 
80 
81  operator RValue<Scalar,Exp>()
82  {
83  return
84  static_cast< RValue<Scalar,Exp>& >(
85  static_cast< Exp& >(*this) );
86  }
87 
88  void fill( Scalar val )
89  {
90  for(int i=0; i < size(); i++)
91  (*this)[i] = val;
92  }
93 };
94 
95 
96 template <typename Scalar, class Exp>
98 {
99  return exp;
100 }
101 
102 
103 
104 
105 
106 
107 } // polynomial
108 } // mpblocks
109 
110 
111 
112 
113 
114 #endif // MATRIXEXPRESSION_H_
expression template for rvalues
Definition: LValue.h:35
Size_t size() const
return the size for a vector
Definition: LValue.h:43
Size_t size() const
return the size for a vector
Definition: RValue.h:41
void resize(Size_t size)
Definition: LValue.h:75
LValue< Scalar, Exp > & lvalue(LValue< Scalar, Exp > &exp)
Definition: LValue.h:97
Stream_t operator<<(Scalar x)
returns a stream for assignment
Definition: LValue.h:60
expression template for rvalues
Definition: RValue.h:35
StreamAssignment< LValue< Scalar, Exp > > Stream_t
Definition: LValue.h:38
void fill(Scalar val)
Definition: LValue.h:88
Size_t degree() const
Definition: LValue.h:48
Scalar & operator[](Size_t i)
return the evaluated i'th element of a vector expression
Definition: LValue.h:54
LValue< Scalar, Exp > & operator=(RValue< Scalar, Exp2 > const &B)
Definition: LValue.h:67