StaticAssert.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) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2008 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_STATIC_ASSERT_H
00012 #define EIGEN_STATIC_ASSERT_H
00013 
00014 /* Some notes on Eigen's static assertion mechanism:
00015  *
00016  *  - in EIGEN_STATIC_ASSERT(CONDITION,MSG) the parameter CONDITION must be a compile time boolean
00017  *    expression, and MSG an enum listed in struct internal::static_assertion<true>
00018  *
00019  *  - define EIGEN_NO_STATIC_ASSERT to disable them (and save compilation time)
00020  *    in that case, the static assertion is converted to the following runtime assert:
00021  *      eigen_assert(CONDITION && "MSG")
00022  *
00023  *  - currently EIGEN_STATIC_ASSERT can only be used in function scope
00024  *
00025  */
00026 
00027 #ifndef EIGEN_NO_STATIC_ASSERT
00028 
00029   #if defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(_MSC_VER) && (_MSC_VER >= 1600))
00030 
00031     // if native static_assert is enabled, let's use it
00032     #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
00033 
00034   #else // not CXX0X
00035 
00036     namespace Eigen {
00037 
00038     namespace internal {
00039 
00040     template<bool condition>
00041     struct static_assertion {};
00042 
00043     template<>
00044     struct static_assertion<true>
00045     {
00046       enum {
00047         YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX,
00048         YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES,
00049         YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES,
00050         THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE,
00051         THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE,
00052         THIS_METHOD_IS_ONLY_FOR_OBJECTS_OF_A_SPECIFIC_SIZE,
00053         YOU_MADE_A_PROGRAMMING_MISTAKE,
00054         EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT,
00055         EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE,
00056         YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR,
00057         YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR,
00058         UNALIGNED_LOAD_AND_STORE_OPERATIONS_UNIMPLEMENTED_ON_ALTIVEC,
00059         THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES,
00060         FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED,
00061         NUMERIC_TYPE_MUST_BE_REAL,
00062         COEFFICIENT_WRITE_ACCESS_TO_SELFADJOINT_NOT_SUPPORTED,
00063         WRITING_TO_TRIANGULAR_PART_WITH_UNIT_DIAGONAL_IS_NOT_SUPPORTED,
00064         THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE,
00065         INVALID_MATRIX_PRODUCT,
00066         INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS,
00067         INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION,
00068         YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY,
00069         THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES,
00070         THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES,
00071         INVALID_MATRIX_TEMPLATE_PARAMETERS,
00072         INVALID_MATRIXBASE_TEMPLATE_PARAMETERS,
00073         BOTH_MATRICES_MUST_HAVE_THE_SAME_STORAGE_ORDER,
00074         THIS_METHOD_IS_ONLY_FOR_DIAGONAL_MATRIX,
00075         THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE,
00076         THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES,
00077         YOU_ALREADY_SPECIFIED_THIS_STRIDE,
00078         INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION,
00079         THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD,
00080         PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1,
00081         THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS,
00082         YOU_CANNOT_MIX_ARRAYS_AND_MATRICES,
00083         YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION,
00084         THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY,
00085         YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT,
00086         THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS,
00087         THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL,
00088         THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES,
00089         YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED,
00090         YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED,
00091         THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE,
00092         THE_STORAGE_ORDER_OF_BOTH_SIDES_MUST_MATCH,
00093         OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG,
00094         IMPLICIT_CONVERSION_TO_SCALAR_IS_FOR_INNER_PRODUCT_ONLY,
00095         STORAGE_LAYOUT_DOES_NOT_MATCH
00096       };
00097     };
00098 
00099     } // end namespace internal
00100 
00101     } // end namespace Eigen
00102 
00103     // Specialized implementation for MSVC to avoid "conditional
00104     // expression is constant" warnings.  This implementation doesn't
00105     // appear to work under GCC, hence the multiple implementations.
00106     #ifdef _MSC_VER
00107 
00108       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
00109         {Eigen::internal::static_assertion<bool(CONDITION)>::MSG;}
00110 
00111     #else
00112 
00113       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
00114         if (Eigen::internal::static_assertion<bool(CONDITION)>::MSG) {}
00115 
00116     #endif
00117 
00118   #endif // not CXX0X
00119 
00120 #else // EIGEN_NO_STATIC_ASSERT
00121 
00122   #define EIGEN_STATIC_ASSERT(CONDITION,MSG) eigen_assert((CONDITION) && #MSG);
00123 
00124 #endif // EIGEN_NO_STATIC_ASSERT
00125 
00126 
00127 // static assertion failing if the type \a TYPE is not a vector type
00128 #define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE) \
00129   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime, \
00130                       YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX)
00131 
00132 // static assertion failing if the type \a TYPE is not fixed-size
00133 #define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE) \
00134   EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime!=Eigen::Dynamic, \
00135                       YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR)
00136 
00137 // static assertion failing if the type \a TYPE is not dynamic-size
00138 #define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE) \
00139   EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime==Eigen::Dynamic, \
00140                       YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR)
00141 
00142 // static assertion failing if the type \a TYPE is not a vector type of the given size
00143 #define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE) \
00144   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime && TYPE::SizeAtCompileTime==SIZE, \
00145                       THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE)
00146 
00147 // static assertion failing if the type \a TYPE is not a vector type of the given size
00148 #define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS) \
00149   EIGEN_STATIC_ASSERT(TYPE::RowsAtCompileTime==ROWS && TYPE::ColsAtCompileTime==COLS, \
00150                       THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
00151 
00152 // static assertion failing if the two vector expression types are not compatible (same fixed-size or dynamic size)
00153 #define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0,TYPE1) \
00154   EIGEN_STATIC_ASSERT( \
00155       (int(TYPE0::SizeAtCompileTime)==Eigen::Dynamic \
00156     || int(TYPE1::SizeAtCompileTime)==Eigen::Dynamic \
00157     || int(TYPE0::SizeAtCompileTime)==int(TYPE1::SizeAtCompileTime)),\
00158     YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES)
00159 
00160 #define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
00161      ( \
00162         (int(TYPE0::SizeAtCompileTime)==0 && int(TYPE1::SizeAtCompileTime)==0) \
00163     || (\
00164           (int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \
00165         || int(TYPE1::RowsAtCompileTime)==Eigen::Dynamic \
00166         || int(TYPE0::RowsAtCompileTime)==int(TYPE1::RowsAtCompileTime)) \
00167       &&  (int(TYPE0::ColsAtCompileTime)==Eigen::Dynamic \
00168         || int(TYPE1::ColsAtCompileTime)==Eigen::Dynamic \
00169         || int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime))\
00170        ) \
00171      )
00172 
00173 #ifdef EIGEN2_SUPPORT
00174   #define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
00175     eigen_assert(!NumTraits<Scalar>::IsInteger);
00176 #else
00177   #define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
00178     EIGEN_STATIC_ASSERT(!NumTraits<TYPE>::IsInteger, THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES)
00179 #endif
00180 
00181 
00182 // static assertion failing if it is guaranteed at compile-time that the two matrix expression types have different sizes
00183 #define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
00184   EIGEN_STATIC_ASSERT( \
00185      EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\
00186     YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES)
00187 
00188 #define EIGEN_STATIC_ASSERT_SIZE_1x1(TYPE) \
00189       EIGEN_STATIC_ASSERT((TYPE::RowsAtCompileTime == 1 || TYPE::RowsAtCompileTime == Dynamic) && \
00190                           (TYPE::ColsAtCompileTime == 1 || TYPE::ColsAtCompileTime == Dynamic), \
00191                           THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS)
00192 
00193 #define EIGEN_STATIC_ASSERT_LVALUE(Derived) \
00194       EIGEN_STATIC_ASSERT(internal::is_lvalue<Derived>::value, \
00195                           THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY)
00196 
00197 #define EIGEN_STATIC_ASSERT_ARRAYXPR(Derived) \
00198       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Derived>::XprKind, ArrayXpr>::value), \
00199                           THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES)
00200 
00201 #define EIGEN_STATIC_ASSERT_SAME_XPR_KIND(Derived1, Derived2) \
00202       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Derived1>::XprKind, \
00203                                              typename internal::traits<Derived2>::XprKind \
00204                                             >::value), \
00205                           YOU_CANNOT_MIX_ARRAYS_AND_MATRICES)
00206 
00207 
00208 #endif // EIGEN_STATIC_ASSERT_H


turtlebot_exploration_3d
Author(s): Bona , Shawn
autogenerated on Thu Jun 6 2019 21:00:11