1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_MISC_SOLVE_H
11 #define EIGEN_MISC_SOLVE_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 /** \class solve_retval_base
18   *
19   */
20 template<typename DecompositionType, typename Rhs>
21 struct traits<solve_retval_base<DecompositionType, Rhs> >
22 {
23   typedef typename DecompositionType::MatrixType MatrixType;
24   typedef Matrix<typename Rhs::Scalar,
25                  MatrixType::ColsAtCompileTime,
26                  Rhs::ColsAtCompileTime,
27                  Rhs::PlainObject::Options,
28                  MatrixType::MaxColsAtCompileTime,
29                  Rhs::MaxColsAtCompileTime> ReturnType;
30 };
31 
32 template<typename _DecompositionType, typename Rhs> struct solve_retval_base
33  : public ReturnByValue<solve_retval_base<_DecompositionType, Rhs> >
34 {
35   typedef typename remove_all<typename Rhs::Nested>::type RhsNestedCleaned;
36   typedef _DecompositionType DecompositionType;
37   typedef ReturnByValue<solve_retval_base> Base;
38   typedef typename Base::Index Index;
39 
40   solve_retval_base(const DecompositionType& dec, const Rhs& rhs)
41     : m_dec(dec), m_rhs(rhs)
42   {}
43 
44   inline Index rows() const { return m_dec.cols(); }
45   inline Index cols() const { return m_rhs.cols(); }
46   inline const DecompositionType& dec() const { return m_dec; }
47   inline const RhsNestedCleaned& rhs() const { return m_rhs; }
48 
49   template<typename Dest> inline void evalTo(Dest& dst) const
50   {
51     static_cast<const solve_retval<DecompositionType,Rhs>*>(this)->evalTo(dst);
52   }
53 
54   protected:
55     const DecompositionType& m_dec;
56     typename Rhs::Nested m_rhs;
57 };
58 
59 } // end namespace internal
60 
61 #define EIGEN_MAKE_SOLVE_HELPERS(DecompositionType,Rhs) \
62   typedef typename DecompositionType::MatrixType MatrixType; \
63   typedef typename MatrixType::Scalar Scalar; \
64   typedef typename MatrixType::RealScalar RealScalar; \
65   typedef typename MatrixType::Index Index; \
66   typedef Eigen::internal::solve_retval_base<DecompositionType,Rhs> Base; \
67   using Base::dec; \
68   using Base::rhs; \
69   using Base::rows; \
70   using Base::cols; \
71   solve_retval(const DecompositionType& dec, const Rhs& rhs) \
72     : Base(dec, rhs) {}
73 
74 } // end namespace Eigen
75 
76 #endif // EIGEN_MISC_SOLVE_H
77