bug #54 - The big Map const-correctness changes

This commit is contained in:
Benoit Jacob
2010-12-10 02:09:58 -05:00
parent e736df3edd
commit 74cc42b22f
19 changed files with 311 additions and 113 deletions

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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

View File

@@ -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
{