ReturnByValue.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_RETURNBYVALUE_H
00012 #define EIGEN_RETURNBYVALUE_H
00013 
00014 namespace Eigen {
00015 
00021 namespace internal {
00022 
00023 template<typename Derived>
00024 struct traits<ReturnByValue<Derived> >
00025   : public traits<typename traits<Derived>::ReturnType>
00026 {
00027   enum {
00028     // We're disabling the DirectAccess because e.g. the constructor of
00029     // the Block-with-DirectAccess expression requires to have a coeffRef method.
00030     // Also, we don't want to have to implement the stride stuff.
00031     Flags = (traits<typename traits<Derived>::ReturnType>::Flags
00032              | EvalBeforeNestingBit) & ~DirectAccessBit
00033   };
00034 };
00035 
00036 /* The ReturnByValue object doesn't even have a coeff() method.
00037  * So the only way that nesting it in an expression can work, is by evaluating it into a plain matrix.
00038  * So internal::nested always gives the plain return matrix type.
00039  *
00040  * FIXME: I don't understand why we need this specialization: isn't this taken care of by the EvalBeforeNestingBit ??
00041  */
00042 template<typename Derived,int n,typename PlainObject>
00043 struct nested<ReturnByValue<Derived>, n, PlainObject>
00044 {
00045   typedef typename traits<Derived>::ReturnType type;
00046 };
00047 
00048 } // end namespace internal
00049 
00050 template<typename Derived> class ReturnByValue
00051   : internal::no_assignment_operator, public internal::dense_xpr_base< ReturnByValue<Derived> >::type
00052 {
00053   public:
00054     typedef typename internal::traits<Derived>::ReturnType ReturnType;
00055 
00056     typedef typename internal::dense_xpr_base<ReturnByValue>::type Base;
00057     EIGEN_DENSE_PUBLIC_INTERFACE(ReturnByValue)
00058 
00059     template<typename Dest>
00060     inline void evalTo(Dest& dst) const
00061     { static_cast<const Derived*>(this)->evalTo(dst); }
00062     inline Index rows() const { return static_cast<const Derived*>(this)->rows(); }
00063     inline Index cols() const { return static_cast<const Derived*>(this)->cols(); }
00064 
00065 #ifndef EIGEN_PARSED_BY_DOXYGEN
00066 #define Unusable YOU_ARE_TRYING_TO_ACCESS_A_SINGLE_COEFFICIENT_IN_A_SPECIAL_EXPRESSION_WHERE_THAT_IS_NOT_ALLOWED_BECAUSE_THAT_WOULD_BE_INEFFICIENT
00067     class Unusable{
00068       Unusable(const Unusable&) {}
00069       Unusable& operator=(const Unusable&) {return *this;}
00070     };
00071     const Unusable& coeff(Index) const { return *reinterpret_cast<const Unusable*>(this); }
00072     const Unusable& coeff(Index,Index) const { return *reinterpret_cast<const Unusable*>(this); }
00073     Unusable& coeffRef(Index) { return *reinterpret_cast<Unusable*>(this); }
00074     Unusable& coeffRef(Index,Index) { return *reinterpret_cast<Unusable*>(this); }
00075 #endif
00076 };
00077 
00078 template<typename Derived>
00079 template<typename OtherDerived>
00080 Derived& DenseBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other)
00081 {
00082   other.evalTo(derived());
00083   return derived();
00084 }
00085 
00086 } // end namespace Eigen
00087 
00088 #endif // EIGEN_RETURNBYVALUE_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:59:54