00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef EIGEN_MATRIXSTORAGE_H
00028 #define EIGEN_MATRIXSTORAGE_H
00029
00030 #ifdef EIGEN_DEBUG_MATRIX_CTOR
00031 #define EIGEN_INT_DEBUG_MATRIX_CTOR EIGEN_DEBUG_MATRIX_CTOR;
00032 #else
00033 #define EIGEN_INT_DEBUG_MATRIX_CTOR
00034 #endif
00035
00036 struct ei_constructor_without_unaligned_array_assert {};
00037
00042 template <typename T, int Size, int MatrixOptions,
00043 int Alignment = (MatrixOptions&DontAlign) ? 0
00044 : (((Size*sizeof(T))%16)==0) ? 16
00045 : 0 >
00046 struct ei_matrix_array
00047 {
00048 T array[Size];
00049 ei_matrix_array() {}
00050 ei_matrix_array(ei_constructor_without_unaligned_array_assert) {}
00051 };
00052
00053 #ifdef EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
00054 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
00055 #else
00056 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
00057 ei_assert((reinterpret_cast<size_t>(array) & sizemask) == 0 \
00058 && "this assertion is explained here: " \
00059 "http://eigen.tuxfamily.org/dox/UnalignedArrayAssert.html" \
00060 " **** READ THIS WEB PAGE !!! ****");
00061 #endif
00062
00063 template <typename T, int Size, int MatrixOptions>
00064 struct ei_matrix_array<T, Size, MatrixOptions, 16>
00065 {
00066 EIGEN_ALIGN16 T array[Size];
00067 ei_matrix_array() { EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(0xf) }
00068 ei_matrix_array(ei_constructor_without_unaligned_array_assert) {}
00069 };
00070
00071 template <typename T, int MatrixOptions, int Alignment>
00072 struct ei_matrix_array<T, 0, MatrixOptions, Alignment>
00073 {
00074 EIGEN_ALIGN16 T array[1];
00075 ei_matrix_array() {}
00076 ei_matrix_array(ei_constructor_without_unaligned_array_assert) {}
00077 };
00078
00091 template<typename T, int Size, int _Rows, int _Cols, int _Options> class ei_matrix_storage;
00092
00093
00094 template<typename T, int Size, int _Rows, int _Cols, int _Options> class ei_matrix_storage
00095 {
00096 ei_matrix_array<T,Size,_Options> m_data;
00097 public:
00098 inline explicit ei_matrix_storage() {}
00099 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
00100 : m_data(ei_constructor_without_unaligned_array_assert()) {}
00101 inline ei_matrix_storage(DenseIndex,DenseIndex,DenseIndex) {}
00102 inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); }
00103 inline static DenseIndex rows(void) {return _Rows;}
00104 inline static DenseIndex cols(void) {return _Cols;}
00105 inline void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
00106 inline void resize(DenseIndex,DenseIndex,DenseIndex) {}
00107 inline const T *data() const { return m_data.array; }
00108 inline T *data() { return m_data.array; }
00109 };
00110
00111
00112 template<typename T, int _Rows, int _Cols, int _Options> class ei_matrix_storage<T, 0, _Rows, _Cols, _Options>
00113 {
00114 public:
00115 inline explicit ei_matrix_storage() {}
00116 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) {}
00117 inline ei_matrix_storage(DenseIndex,DenseIndex,DenseIndex) {}
00118 inline void swap(ei_matrix_storage& ) {}
00119 inline static DenseIndex rows(void) {return _Rows;}
00120 inline static DenseIndex cols(void) {return _Cols;}
00121 inline void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
00122 inline void resize(DenseIndex,DenseIndex,DenseIndex) {}
00123 inline const T *data() const { return 0; }
00124 inline T *data() { return 0; }
00125 };
00126
00127
00128 template<typename T, int Size, int _Options> class ei_matrix_storage<T, Size, Dynamic, Dynamic, _Options>
00129 {
00130 ei_matrix_array<T,Size,_Options> m_data;
00131 DenseIndex m_rows;
00132 DenseIndex m_cols;
00133 public:
00134 inline explicit ei_matrix_storage() : m_rows(0), m_cols(0) {}
00135 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
00136 : m_data(ei_constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
00137 inline ei_matrix_storage(DenseIndex, DenseIndex rows, DenseIndex cols) : m_rows(rows), m_cols(cols) {}
00138 inline void swap(ei_matrix_storage& other)
00139 { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
00140 inline DenseIndex rows(void) const {return m_rows;}
00141 inline DenseIndex cols(void) const {return m_cols;}
00142 inline void conservativeResize(DenseIndex, DenseIndex rows, DenseIndex cols) { m_rows = rows; m_cols = cols; }
00143 inline void resize(DenseIndex, DenseIndex rows, DenseIndex cols) { m_rows = rows; m_cols = cols; }
00144 inline const T *data() const { return m_data.array; }
00145 inline T *data() { return m_data.array; }
00146 };
00147
00148
00149 template<typename T, int Size, int _Cols, int _Options> class ei_matrix_storage<T, Size, Dynamic, _Cols, _Options>
00150 {
00151 ei_matrix_array<T,Size,_Options> m_data;
00152 DenseIndex m_rows;
00153 public:
00154 inline explicit ei_matrix_storage() : m_rows(0) {}
00155 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
00156 : m_data(ei_constructor_without_unaligned_array_assert()), m_rows(0) {}
00157 inline ei_matrix_storage(DenseIndex, DenseIndex rows, DenseIndex) : m_rows(rows) {}
00158 inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
00159 inline DenseIndex rows(void) const {return m_rows;}
00160 inline DenseIndex cols(void) const {return _Cols;}
00161 inline void conservativeResize(DenseIndex, DenseIndex rows, DenseIndex) { m_rows = rows; }
00162 inline void resize(DenseIndex, DenseIndex rows, DenseIndex) { m_rows = rows; }
00163 inline const T *data() const { return m_data.array; }
00164 inline T *data() { return m_data.array; }
00165 };
00166
00167
00168 template<typename T, int Size, int _Rows, int _Options> class ei_matrix_storage<T, Size, _Rows, Dynamic, _Options>
00169 {
00170 ei_matrix_array<T,Size,_Options> m_data;
00171 DenseIndex m_cols;
00172 public:
00173 inline explicit ei_matrix_storage() : m_cols(0) {}
00174 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
00175 : m_data(ei_constructor_without_unaligned_array_assert()), m_cols(0) {}
00176 inline ei_matrix_storage(DenseIndex, DenseIndex, DenseIndex cols) : m_cols(cols) {}
00177 inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
00178 inline DenseIndex rows(void) const {return _Rows;}
00179 inline DenseIndex cols(void) const {return m_cols;}
00180 inline void conservativeResize(DenseIndex, DenseIndex, DenseIndex cols) { m_cols = cols; }
00181 inline void resize(DenseIndex, DenseIndex, DenseIndex cols) { m_cols = cols; }
00182 inline const T *data() const { return m_data.array; }
00183 inline T *data() { return m_data.array; }
00184 };
00185
00186
00187 template<typename T, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, Dynamic, _Options>
00188 {
00189 T *m_data;
00190 DenseIndex m_rows;
00191 DenseIndex m_cols;
00192 public:
00193 inline explicit ei_matrix_storage() : m_data(0), m_rows(0), m_cols(0) {}
00194 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
00195 : m_data(0), m_rows(0), m_cols(0) {}
00196 inline ei_matrix_storage(DenseIndex size, DenseIndex rows, DenseIndex cols)
00197 : m_data(ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols)
00198 { EIGEN_INT_DEBUG_MATRIX_CTOR }
00199 inline ~ei_matrix_storage() { ei_conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
00200 inline void swap(ei_matrix_storage& other)
00201 { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
00202 inline DenseIndex rows(void) const {return m_rows;}
00203 inline DenseIndex cols(void) const {return m_cols;}
00204 inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex cols)
00205 {
00206 m_data = ei_conditional_aligned_realloc_new<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
00207 m_rows = rows;
00208 m_cols = cols;
00209 }
00210 void resize(DenseIndex size, DenseIndex rows, DenseIndex cols)
00211 {
00212 if(size != m_rows*m_cols)
00213 {
00214 ei_conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
00215 if (size)
00216 m_data = ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size);
00217 else
00218 m_data = 0;
00219 EIGEN_INT_DEBUG_MATRIX_CTOR
00220 }
00221 m_rows = rows;
00222 m_cols = cols;
00223 }
00224 inline const T *data() const { return m_data; }
00225 inline T *data() { return m_data; }
00226 };
00227
00228
00229 template<typename T, int _Rows, int _Options> class ei_matrix_storage<T, Dynamic, _Rows, Dynamic, _Options>
00230 {
00231 T *m_data;
00232 DenseIndex m_cols;
00233 public:
00234 inline explicit ei_matrix_storage() : m_data(0), m_cols(0) {}
00235 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
00236 inline ei_matrix_storage(DenseIndex size, DenseIndex, DenseIndex cols) : m_data(ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_cols(cols)
00237 { EIGEN_INT_DEBUG_MATRIX_CTOR }
00238 inline ~ei_matrix_storage() { ei_conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
00239 inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
00240 inline static DenseIndex rows(void) {return _Rows;}
00241 inline DenseIndex cols(void) const {return m_cols;}
00242 inline void conservativeResize(DenseIndex size, DenseIndex, DenseIndex cols)
00243 {
00244 m_data = ei_conditional_aligned_realloc_new<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
00245 m_cols = cols;
00246 }
00247 EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex, DenseIndex cols)
00248 {
00249 if(size != _Rows*m_cols)
00250 {
00251 ei_conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
00252 if (size)
00253 m_data = ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size);
00254 else
00255 m_data = 0;
00256 EIGEN_INT_DEBUG_MATRIX_CTOR
00257 }
00258 m_cols = cols;
00259 }
00260 inline const T *data() const { return m_data; }
00261 inline T *data() { return m_data; }
00262 };
00263
00264
00265 template<typename T, int _Cols, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, _Cols, _Options>
00266 {
00267 T *m_data;
00268 DenseIndex m_rows;
00269 public:
00270 inline explicit ei_matrix_storage() : m_data(0), m_rows(0) {}
00271 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
00272 inline ei_matrix_storage(DenseIndex size, DenseIndex rows, DenseIndex) : m_data(ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_rows(rows)
00273 { EIGEN_INT_DEBUG_MATRIX_CTOR }
00274 inline ~ei_matrix_storage() { ei_conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
00275 inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
00276 inline DenseIndex rows(void) const {return m_rows;}
00277 inline static DenseIndex cols(void) {return _Cols;}
00278 inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex)
00279 {
00280 m_data = ei_conditional_aligned_realloc_new<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
00281 m_rows = rows;
00282 }
00283 EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex rows, DenseIndex)
00284 {
00285 if(size != m_rows*_Cols)
00286 {
00287 ei_conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
00288 if (size)
00289 m_data = ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size);
00290 else
00291 m_data = 0;
00292 EIGEN_INT_DEBUG_MATRIX_CTOR
00293 }
00294 m_rows = rows;
00295 }
00296 inline const T *data() const { return m_data; }
00297 inline T *data() { return m_data; }
00298 };
00299
00300 #endif // EIGEN_MATRIX_H