diff options
author | 2010-12-10 02:09:58 -0500 | |
---|---|---|
committer | 2010-12-10 02:09:58 -0500 | |
commit | 74cc42b22fbe1c05dcbedefb65ceabdec20da146 (patch) | |
tree | 08cbb408c2c75ae3af2950eca494e03dbe5966d1 /Eigen/src/Core/util | |
parent | e736df3eddf0f2b8623653a66b8654f7770f03c8 (diff) |
bug #54 - The big Map const-correctness changes
Diffstat (limited to 'Eigen/src/Core/util')
-rw-r--r-- | Eigen/src/Core/util/Constants.h | 18 | ||||
-rw-r--r-- | Eigen/src/Core/util/ForwardDeclarations.h | 19 | ||||
-rw-r--r-- | Eigen/src/Core/util/StaticAssert.h | 6 | ||||
-rw-r--r-- | Eigen/src/Core/util/XprHelper.h | 5 |
4 files changed, 31 insertions, 17 deletions
diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h index 99b4f3319..03cadc107 100644 --- a/Eigen/src/Core/util/Constants.h +++ b/Eigen/src/Core/util/Constants.h @@ -128,8 +128,10 @@ const unsigned int LinearAccessBit = 0x10; * Means the expression has a coeffRef() method, i.e. is writable as its individual coefficients are directly addressable. * This rules out read-only expressions. * - * Note that DirectAccessBit implies LvalueBit, but the converse is false: LvalueBit doesn't imply DirectAccessBit because - * DirectAccessBit means that the whole memory layout is a plain strided array. + * Note that DirectAccessBit and LvalueBit are mutually orthogonal, as there are examples of expression having one but note + * the other: + * \li writable expressions that don't have a very simple memory layout as a strided array, have LvalueBit but not DirectAccessBit + * \li Map-to-const expressions, for example Map<const Matrix>, have DirectAccessBit but not LvalueBit * * Expressions having LvalueBit also have their coeff() method returning a const reference instead of returning a new value. */ @@ -137,14 +139,12 @@ const unsigned int LvalueBit = 0x20; /** \ingroup flags * - * Means that the underlying array of coefficients can be directly accessed. This means two things. - * - * First, this means LvalueBit, i.e. this means that the expression has a coeffRef() method, i.e. is writable as its - * individual coefficients are directly addressable. This rules out read-only expressions. - * - * Second, the memory layout of the array of coefficients must be exactly the natural one suggested by rows(), cols(), + * Means that the underlying array of coefficients can be directly accessed as a plain strided array. The memory layout + * of the array of coefficients must be exactly the natural one suggested by rows(), cols(), * outerStride(), innerStride(), and the RowMajorBit. This rules out expressions such as Diagonal, whose coefficients, * though referencable, do not have such a regular memory layout. + * + * See the comment on LvalueBit for an explanation of how LvalueBit and DirectAccessBit are mutually orthogonal. */ const unsigned int DirectAccessBit = 0x40; @@ -242,7 +242,7 @@ enum { }; enum AccessorLevels { - ReadOnlyAccessors, WriteAccessors, DirectAccessors + ReadOnlyAccessors, WriteAccessors, DirectAccessors, DirectWriteAccessors }; enum DecompositionOptions { diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 0d0b905ea..c84401fa8 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -33,16 +33,26 @@ template<typename Derived> struct has_direct_access { enum { ret = (traits<Derived>::Flags & DirectAccessBit) ? 1 : 0 }; }; + +template<typename Derived> struct accessors_level +{ + enum { has_direct_access = (traits<Derived>::Flags & DirectAccessBit) ? 1 : 0, + has_write_access = (traits<Derived>::Flags & LvalueBit) ? 1 : 0, + value = has_direct_access ? (has_write_access ? DirectWriteAccessors : DirectAccessors) + : (has_write_access ? WriteAccessors : ReadOnlyAccessors) + }; +}; + } // end namespace internal template<typename T> struct NumTraits; template<typename Derived> struct EigenBase; template<typename Derived> class DenseBase; + + template<typename Derived, - AccessorLevels Level = (internal::traits<Derived>::Flags & DirectAccessBit) ? DirectAccessors - : (internal::traits<Derived>::Flags & LvalueBit) ? WriteAccessors - : ReadOnlyAccessors> + int Level = internal::accessors_level<Derived>::value > class DenseCoeffsBase; template<typename _Scalar, int _Rows, int _Cols, @@ -86,6 +96,9 @@ template<typename MatrixType, int Index> class Diagonal; template<int SizeAtCompileTime, int MaxSizeAtCompileTime = SizeAtCompileTime> class PermutationMatrix; template<int SizeAtCompileTime, int MaxSizeAtCompileTime = SizeAtCompileTime> class Transpositions; +template<typename Derived, + int Level = internal::accessors_level<Derived>::has_write_access ? WriteAccessors : ReadOnlyAccessors +> class MapBase; template<int InnerStrideAtCompileTime, int OuterStrideAtCompileTime> class Stride; template<typename MatrixType, int MapOptions=Unaligned, typename StrideType = Stride<0,0> > class Map; diff --git a/Eigen/src/Core/util/StaticAssert.h b/Eigen/src/Core/util/StaticAssert.h index dbdf8b209..3637b7c0a 100644 --- a/Eigen/src/Core/util/StaticAssert.h +++ b/Eigen/src/Core/util/StaticAssert.h @@ -93,6 +93,8 @@ THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS, YOU_CANNOT_MIX_ARRAYS_AND_MATRICES, YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION, + YOU_ARE_TRYING_TO_WRITE_INTO_A_READ_ONLY_EXPRESSION, + YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT, THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS }; }; @@ -183,4 +185,8 @@ (TYPE::ColsAtCompileTime == 1 || TYPE::ColsAtCompileTime == Dynamic), \ THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS) +#define EIGEN_STATIC_ASSERT_LVALUE(Derived) \ + EIGEN_STATIC_ASSERT(int(internal::traits<Derived>::Flags) & LvalueBit, \ + YOU_ARE_TRYING_TO_WRITE_INTO_A_READ_ONLY_EXPRESSION) + #endif // EIGEN_STATIC_ASSERT_H diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index ea43aa91e..46ade2ba1 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -333,11 +333,6 @@ template<typename T, int n=1, typename PlainObject = typename eval<T>::type> str >::type type; }; -template<unsigned int Flags> struct are_flags_consistent -{ - enum { ret = EIGEN_IMPLIES(bool(Flags&DirectAccessBit), bool(Flags&LvalueBit)) }; -}; - template<typename Derived, typename XprKind = typename traits<Derived>::XprKind> struct dense_xpr_base { |