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 #ifndef EIGEN_MATRIXSTORAGE_H
00027 #define EIGEN_MATRIXSTORAGE_H
00028
00029 struct ei_constructor_without_unaligned_array_assert {};
00030
00034 template <typename T, int Size, int MatrixOptions,
00035 bool Align = (MatrixOptions&AutoAlign) && (((Size*sizeof(T))&0xf)==0)
00036 > struct ei_matrix_array
00037 {
00038 EIGEN_ALIGN_128 T array[Size];
00039
00040 ei_matrix_array()
00041 {
00042 #ifndef EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
00043 ei_assert((reinterpret_cast<size_t>(array) & 0xf) == 0
00044 && "this assertion is explained here: http://eigen.tuxfamily.org/dox/UnalignedArrayAssert.html **** READ THIS WEB PAGE !!! ****");
00045 #endif
00046 }
00047
00048 ei_matrix_array(ei_constructor_without_unaligned_array_assert) {}
00049 };
00050
00051 template <typename T, int Size, int MatrixOptions> struct ei_matrix_array<T,Size,MatrixOptions,false>
00052 {
00053 T array[Size];
00054 ei_matrix_array() {}
00055 ei_matrix_array(ei_constructor_without_unaligned_array_assert) {}
00056 };
00057
00069 template<typename T, int Size, int _Rows, int _Cols, int _Options> class ei_matrix_storage;
00070
00071
00072 template<typename T, int Size, int _Rows, int _Cols, int _Options> class ei_matrix_storage
00073 {
00074 ei_matrix_array<T,Size,_Options> m_data;
00075 public:
00076 inline explicit ei_matrix_storage() {}
00077 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
00078 : m_data(ei_constructor_without_unaligned_array_assert()) {}
00079 inline ei_matrix_storage(int,int,int) {}
00080 inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); }
00081 inline static int rows(void) {return _Rows;}
00082 inline static int cols(void) {return _Cols;}
00083 inline void resize(int,int,int) {}
00084 inline const T *data() const { return m_data.array; }
00085 inline T *data() { return m_data.array; }
00086 };
00087
00088
00089 template<typename T, int Size, int _Options> class ei_matrix_storage<T, Size, Dynamic, Dynamic, _Options>
00090 {
00091 ei_matrix_array<T,Size,_Options> m_data;
00092 int m_rows;
00093 int m_cols;
00094 public:
00095 inline explicit ei_matrix_storage() : m_rows(0), m_cols(0) {}
00096 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
00097 : m_data(ei_constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
00098 inline ei_matrix_storage(int, int rows, int cols) : m_rows(rows), m_cols(cols) {}
00099 inline ~ei_matrix_storage() {}
00100 inline void swap(ei_matrix_storage& other)
00101 { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
00102 inline int rows(void) const {return m_rows;}
00103 inline int cols(void) const {return m_cols;}
00104 inline void resize(int, int rows, int cols)
00105 {
00106 m_rows = rows;
00107 m_cols = cols;
00108 }
00109 inline const T *data() const { return m_data.array; }
00110 inline T *data() { return m_data.array; }
00111 };
00112
00113
00114 template<typename T, int Size, int _Cols, int _Options> class ei_matrix_storage<T, Size, Dynamic, _Cols, _Options>
00115 {
00116 ei_matrix_array<T,Size,_Options> m_data;
00117 int m_rows;
00118 public:
00119 inline explicit ei_matrix_storage() : m_rows(0) {}
00120 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
00121 : m_data(ei_constructor_without_unaligned_array_assert()), m_rows(0) {}
00122 inline ei_matrix_storage(int, int rows, int) : m_rows(rows) {}
00123 inline ~ei_matrix_storage() {}
00124 inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
00125 inline int rows(void) const {return m_rows;}
00126 inline int cols(void) const {return _Cols;}
00127 inline void resize(int , int rows, int)
00128 {
00129 m_rows = rows;
00130 }
00131 inline const T *data() const { return m_data.array; }
00132 inline T *data() { return m_data.array; }
00133 };
00134
00135
00136 template<typename T, int Size, int _Rows, int _Options> class ei_matrix_storage<T, Size, _Rows, Dynamic, _Options>
00137 {
00138 ei_matrix_array<T,Size,_Options> m_data;
00139 int m_cols;
00140 public:
00141 inline explicit ei_matrix_storage() : m_cols(0) {}
00142 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
00143 : m_data(ei_constructor_without_unaligned_array_assert()), m_cols(0) {}
00144 inline ei_matrix_storage(int, int, int cols) : m_cols(cols) {}
00145 inline ~ei_matrix_storage() {}
00146 inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
00147 inline int rows(void) const {return _Rows;}
00148 inline int cols(void) const {return m_cols;}
00149 inline void resize(int, int, int cols)
00150 {
00151 m_cols = cols;
00152 }
00153 inline const T *data() const { return m_data.array; }
00154 inline T *data() { return m_data.array; }
00155 };
00156
00157
00158 template<typename T, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, Dynamic, _Options>
00159 {
00160 T *m_data;
00161 int m_rows;
00162 int m_cols;
00163 public:
00164 inline explicit ei_matrix_storage() : m_data(0), m_rows(0), m_cols(0) {}
00165 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
00166 : m_data(0), m_rows(0), m_cols(0) {}
00167 inline ei_matrix_storage(int size, int rows, int cols)
00168 : m_data(ei_aligned_new<T>(size)), m_rows(rows), m_cols(cols) {}
00169 inline ~ei_matrix_storage() { ei_aligned_delete(m_data, m_rows*m_cols); }
00170 inline void swap(ei_matrix_storage& other)
00171 { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
00172 inline int rows(void) const {return m_rows;}
00173 inline int cols(void) const {return m_cols;}
00174 void resize(int size, int rows, int cols)
00175 {
00176 if(size != m_rows*m_cols)
00177 {
00178 ei_aligned_delete(m_data, m_rows*m_cols);
00179 if (size)
00180 m_data = ei_aligned_new<T>(size);
00181 else
00182 m_data = 0;
00183 }
00184 m_rows = rows;
00185 m_cols = cols;
00186 }
00187 inline const T *data() const { return m_data; }
00188 inline T *data() { return m_data; }
00189 };
00190
00191
00192 template<typename T, int _Rows, int _Options> class ei_matrix_storage<T, Dynamic, _Rows, Dynamic, _Options>
00193 {
00194 T *m_data;
00195 int m_cols;
00196 public:
00197 inline explicit ei_matrix_storage() : m_data(0), m_cols(0) {}
00198 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
00199 inline ei_matrix_storage(int size, int, int cols) : m_data(ei_aligned_new<T>(size)), m_cols(cols) {}
00200 inline ~ei_matrix_storage() { ei_aligned_delete(m_data, _Rows*m_cols); }
00201 inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
00202 inline static int rows(void) {return _Rows;}
00203 inline int cols(void) const {return m_cols;}
00204 void resize(int size, int, int cols)
00205 {
00206 if(size != _Rows*m_cols)
00207 {
00208 ei_aligned_delete(m_data, _Rows*m_cols);
00209 if (size)
00210 m_data = ei_aligned_new<T>(size);
00211 else
00212 m_data = 0;
00213 }
00214 m_cols = cols;
00215 }
00216 inline const T *data() const { return m_data; }
00217 inline T *data() { return m_data; }
00218 };
00219
00220
00221 template<typename T, int _Cols, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, _Cols, _Options>
00222 {
00223 T *m_data;
00224 int m_rows;
00225 public:
00226 inline explicit ei_matrix_storage() : m_data(0), m_rows(0) {}
00227 inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
00228 inline ei_matrix_storage(int size, int rows, int) : m_data(ei_aligned_new<T>(size)), m_rows(rows) {}
00229 inline ~ei_matrix_storage() { ei_aligned_delete(m_data, _Cols*m_rows); }
00230 inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
00231 inline int rows(void) const {return m_rows;}
00232 inline static int cols(void) {return _Cols;}
00233 void resize(int size, int rows, int)
00234 {
00235 if(size != m_rows*_Cols)
00236 {
00237 ei_aligned_delete(m_data, _Cols*m_rows);
00238 if (size)
00239 m_data = ei_aligned_new<T>(size);
00240 else
00241 m_data = 0;
00242 }
00243 m_rows = rows;
00244 }
00245 inline const T *data() const { return m_data; }
00246 inline T *data() { return m_data; }
00247 };
00248
00249 #endif // EIGEN_MATRIX_H