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 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_STATIC_ASSERT_H
00027 #define EIGEN_STATIC_ASSERT_H
00028 
00029 /* Some notes on Eigen's static assertion mechanism:
00030  *
00031  *  - in EIGEN_STATIC_ASSERT(CONDITION,MSG) the parameter CONDITION must be a compile time boolean
00032  *    expression, and MSG an enum listed in struct internal::static_assertion<true>
00033  *
00034  *  - define EIGEN_NO_STATIC_ASSERT to disable them (and save compilation time)
00035  *    in that case, the static assertion is converted to the following runtime assert:
00036  *      eigen_assert(CONDITION && "MSG")
00037  *
00038  *  - currently EIGEN_STATIC_ASSERT can only be used in function scope
00039  *
00040  */
00041 
00042 #ifndef EIGEN_NO_STATIC_ASSERT
00043 
00044   #if defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(_MSC_VER) && (_MSC_VER >= 1600))
00045 
00046     // if native static_assert is enabled, let's use it
00047     #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
00048 
00049   #else // not CXX0X
00050 
00051     namespace internal {
00052 
00053     template<bool condition>
00054     struct static_assertion {};
00055 
00056     template<>
00057     struct static_assertion<true>
00058     {
00059       enum {
00060         YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX,
00061         YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES,
00062         YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES,
00063         THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE,
00064         THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE,
00065         THIS_METHOD_IS_ONLY_FOR_OBJECTS_OF_A_SPECIFIC_SIZE,
00066         YOU_MADE_A_PROGRAMMING_MISTAKE,
00067         EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT,
00068         EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE,
00069         YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR,
00070         YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR,
00071         UNALIGNED_LOAD_AND_STORE_OPERATIONS_UNIMPLEMENTED_ON_ALTIVEC,
00072         THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES,
00073         NUMERIC_TYPE_MUST_BE_REAL,
00074         COEFFICIENT_WRITE_ACCESS_TO_SELFADJOINT_NOT_SUPPORTED,
00075         WRITING_TO_TRIANGULAR_PART_WITH_UNIT_DIAGONAL_IS_NOT_SUPPORTED,
00076         THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE,
00077         INVALID_MATRIX_PRODUCT,
00078         INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS,
00079         INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION,
00080         YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY,
00081         THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES,
00082         THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES,
00083         INVALID_MATRIX_TEMPLATE_PARAMETERS,
00084         INVALID_MATRIXBASE_TEMPLATE_PARAMETERS,
00085         BOTH_MATRICES_MUST_HAVE_THE_SAME_STORAGE_ORDER,
00086         THIS_METHOD_IS_ONLY_FOR_DIAGONAL_MATRIX,
00087         THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE,
00088         THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES,
00089         YOU_ALREADY_SPECIFIED_THIS_STRIDE,
00090         INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION,
00091         THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD,
00092         PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1,
00093         THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS,
00094         YOU_CANNOT_MIX_ARRAYS_AND_MATRICES,
00095         YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION,
00096         THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY,
00097         YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT,
00098         THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS
00099       };
00100     };
00101 
00102     } // end namespace internal
00103 
00104     // Specialized implementation for MSVC to avoid "conditional
00105     // expression is constant" warnings.  This implementation doesn't
00106     // appear to work under GCC, hence the multiple implementations.
00107     #ifdef _MSC_VER
00108 
00109       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
00110         {Eigen::internal::static_assertion<bool(CONDITION)>::MSG;}
00111 
00112     #else
00113 
00114       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
00115         if (Eigen::internal::static_assertion<bool(CONDITION)>::MSG) {}
00116 
00117     #endif
00118 
00119   #endif // not CXX0X
00120 
00121 #else // EIGEN_NO_STATIC_ASSERT
00122 
00123   #define EIGEN_STATIC_ASSERT(CONDITION,MSG) eigen_assert((CONDITION) && #MSG);
00124 
00125 #endif // EIGEN_NO_STATIC_ASSERT
00126 
00127 
00128 // static assertion failing if the type \a TYPE is not a vector type
00129 #define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE) \
00130   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime, \
00131                       YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX)
00132 
00133 // static assertion failing if the type \a TYPE is not fixed-size
00134 #define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE) \
00135   EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime!=Eigen::Dynamic, \
00136                       YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR)
00137 
00138 // static assertion failing if the type \a TYPE is not dynamic-size
00139 #define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE) \
00140   EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime==Eigen::Dynamic, \
00141                       YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR)
00142 
00143 // static assertion failing if the type \a TYPE is not a vector type of the given size
00144 #define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE) \
00145   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime && TYPE::SizeAtCompileTime==SIZE, \
00146                       THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE)
00147 
00148 // static assertion failing if the type \a TYPE is not a vector type of the given size
00149 #define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS) \
00150   EIGEN_STATIC_ASSERT(TYPE::RowsAtCompileTime==ROWS && TYPE::ColsAtCompileTime==COLS, \
00151                       THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
00152 
00153 // static assertion failing if the two vector expression types are not compatible (same fixed-size or dynamic size)
00154 #define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0,TYPE1) \
00155   EIGEN_STATIC_ASSERT( \
00156       (int(TYPE0::SizeAtCompileTime)==Eigen::Dynamic \
00157     || int(TYPE1::SizeAtCompileTime)==Eigen::Dynamic \
00158     || int(TYPE0::SizeAtCompileTime)==int(TYPE1::SizeAtCompileTime)),\
00159     YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES)
00160 
00161 #define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
00162      ( \
00163         (int(TYPE0::SizeAtCompileTime)==0 && int(TYPE1::SizeAtCompileTime)==0) \
00164     || (\
00165           (int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \
00166         || int(TYPE1::RowsAtCompileTime)==Eigen::Dynamic \
00167         || int(TYPE0::RowsAtCompileTime)==int(TYPE1::RowsAtCompileTime)) \
00168       &&  (int(TYPE0::ColsAtCompileTime)==Eigen::Dynamic \
00169         || int(TYPE1::ColsAtCompileTime)==Eigen::Dynamic \
00170         || int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime))\
00171        ) \
00172      )
00173 
00174 #ifdef EIGEN2_SUPPORT
00175   #define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
00176     eigen_assert(!NumTraits<Scalar>::IsInteger);
00177 #else
00178   #define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
00179     EIGEN_STATIC_ASSERT(!NumTraits<TYPE>::IsInteger, THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES)
00180 #endif
00181 
00182 
00183 // static assertion failing if it is guaranteed at compile-time that the two matrix expression types have different sizes
00184 #define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
00185   EIGEN_STATIC_ASSERT( \
00186      EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\
00187     YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES)
00188 
00189 #define EIGEN_STATIC_ASSERT_SIZE_1x1(TYPE) \
00190       EIGEN_STATIC_ASSERT((TYPE::RowsAtCompileTime == 1 || TYPE::RowsAtCompileTime == Dynamic) && \
00191                           (TYPE::ColsAtCompileTime == 1 || TYPE::ColsAtCompileTime == Dynamic), \
00192                           THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS)
00193 
00194 #define EIGEN_STATIC_ASSERT_LVALUE(Derived) \
00195       EIGEN_STATIC_ASSERT(internal::is_lvalue<Derived>::value, \
00196                           THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY)
00197 
00198 #endif // EIGEN_STATIC_ASSERT_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:59