aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Hauke Heibel <hauke.heibel@gmail.com>2009-06-03 16:47:38 +0200
committerGravatar Hauke Heibel <hauke.heibel@gmail.com>2009-06-03 16:47:38 +0200
commit71e5cbcbc4299ab218da327d2080af0b49bdae23 (patch)
tree74b56c1cdfece5177507de22b69e92913bcd10a0
parentf292d2352e0ac9be8a9c5b0d931dc9a2c6da1aa0 (diff)
Added specializations for DontAlign when using Dynamic matrices.
This allows users to store Matrices in smart pointers without the need for a specialized allocator/de-allocator.
-rw-r--r--Eigen/src/Core/MatrixStorage.h112
1 files changed, 103 insertions, 9 deletions
diff --git a/Eigen/src/Core/MatrixStorage.h b/Eigen/src/Core/MatrixStorage.h
index 3c6a6117c..002df076c 100644
--- a/Eigen/src/Core/MatrixStorage.h
+++ b/Eigen/src/Core/MatrixStorage.h
@@ -66,10 +66,10 @@ template <typename T, int Size, int MatrixOptions> struct ei_matrix_array<T,Size
*
* \sa Matrix
*/
-template<typename T, int Size, int _Rows, int _Cols, int _Options> class ei_matrix_storage;
+template<typename T, int Size, int _Rows, int _Cols, int _Options, bool Align = ((_Options&DontAlign)==0)> class ei_matrix_storage;
// purely fixed-size matrix
-template<typename T, int Size, int _Rows, int _Cols, int _Options> class ei_matrix_storage
+template<typename T, int Size, int _Rows, int _Cols, int _Options, bool Align> class ei_matrix_storage
{
ei_matrix_array<T,Size,_Options> m_data;
public:
@@ -86,7 +86,7 @@ template<typename T, int Size, int _Rows, int _Cols, int _Options> class ei_matr
};
// null matrix
-template<typename T, int _Rows, int _Cols, int _Options> class ei_matrix_storage<T, 0, _Rows, _Cols, _Options>
+template<typename T, int _Rows, int _Cols, int _Options, bool Align> class ei_matrix_storage<T, 0, _Rows, _Cols, _Options, Align>
{
public:
inline explicit ei_matrix_storage() {}
@@ -101,7 +101,7 @@ template<typename T, int _Rows, int _Cols, int _Options> class ei_matrix_storage
};
// dynamic-size matrix with fixed-size storage
-template<typename T, int Size, int _Options> class ei_matrix_storage<T, Size, Dynamic, Dynamic, _Options>
+template<typename T, int Size, int _Options, bool Align> class ei_matrix_storage<T, Size, Dynamic, Dynamic, _Options, Align>
{
ei_matrix_array<T,Size,_Options> m_data;
int m_rows;
@@ -126,7 +126,7 @@ template<typename T, int Size, int _Options> class ei_matrix_storage<T, Size, Dy
};
// dynamic-size matrix with fixed-size storage and fixed width
-template<typename T, int Size, int _Cols, int _Options> class ei_matrix_storage<T, Size, Dynamic, _Cols, _Options>
+template<typename T, int Size, int _Cols, int _Options, bool Align> class ei_matrix_storage<T, Size, Dynamic, _Cols, _Options, Align>
{
ei_matrix_array<T,Size,_Options> m_data;
int m_rows;
@@ -148,7 +148,7 @@ template<typename T, int Size, int _Cols, int _Options> class ei_matrix_storage<
};
// dynamic-size matrix with fixed-size storage and fixed height
-template<typename T, int Size, int _Rows, int _Options> class ei_matrix_storage<T, Size, _Rows, Dynamic, _Options>
+template<typename T, int Size, int _Rows, int _Options, bool Align> class ei_matrix_storage<T, Size, _Rows, Dynamic, _Options, Align>
{
ei_matrix_array<T,Size,_Options> m_data;
int m_cols;
@@ -170,7 +170,7 @@ template<typename T, int Size, int _Rows, int _Options> class ei_matrix_storage<
};
// purely dynamic matrix.
-template<typename T, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, Dynamic, _Options>
+template<typename T, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, Dynamic, _Options, true>
{
T *m_data;
int m_rows;
@@ -203,8 +203,42 @@ template<typename T, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic,
inline T *data() { return m_data; }
};
+// purely dynamic matrix with Align flag being set to false.
+template<typename T, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, Dynamic, _Options, false>
+{
+ T *m_data;
+ int m_rows;
+ int m_cols;
+public:
+ inline explicit ei_matrix_storage() : m_data(0), m_rows(0), m_cols(0) {}
+ inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert)
+ : m_data(0), m_rows(0), m_cols(0) {}
+ inline ei_matrix_storage(int size, int rows, int cols)
+ : m_data(new T[size]), m_rows(rows), m_cols(cols) {}
+ inline ~ei_matrix_storage() { delete [] m_data; }
+ inline void swap(ei_matrix_storage& other)
+ { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
+ inline int rows(void) const {return m_rows;}
+ inline int cols(void) const {return m_cols;}
+ void resize(int size, int rows, int cols)
+ {
+ if(size != m_rows*m_cols)
+ {
+ delete [] m_data;
+ if (size)
+ m_data = new T[size];
+ else
+ m_data = 0;
+ }
+ m_rows = rows;
+ m_cols = cols;
+ }
+ inline const T *data() const { return m_data; }
+ inline T *data() { return m_data; }
+};
+
// matrix with dynamic width and fixed height (so that matrix has dynamic size).
-template<typename T, int _Rows, int _Options> class ei_matrix_storage<T, Dynamic, _Rows, Dynamic, _Options>
+template<typename T, int _Rows, int _Options> class ei_matrix_storage<T, Dynamic, _Rows, Dynamic, _Options, true>
{
T *m_data;
int m_cols;
@@ -232,8 +266,38 @@ template<typename T, int _Rows, int _Options> class ei_matrix_storage<T, Dynamic
inline T *data() { return m_data; }
};
+// matrix with dynamic width and fixed height (so that matrix has dynamic size)
+// with Align flag being set to false.
+template<typename T, int _Rows, int _Options> class ei_matrix_storage<T, Dynamic, _Rows, Dynamic, _Options, false>
+{
+ T *m_data;
+ int m_cols;
+ public:
+ inline explicit ei_matrix_storage() : m_data(0), m_cols(0) {}
+ inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
+ inline ei_matrix_storage(int size, int, int cols) : m_data(new T[size]), m_cols(cols) {}
+ inline ~ei_matrix_storage() { delete [] m_data; }
+ inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
+ inline static int rows(void) {return _Rows;}
+ inline int cols(void) const {return m_cols;}
+ void resize(int size, int, int cols)
+ {
+ if(size != _Rows*m_cols)
+ {
+ delete [] m_data;
+ if (size)
+ m_data = new T[size];
+ else
+ m_data = 0;
+ }
+ m_cols = cols;
+ }
+ inline const T *data() const { return m_data; }
+ inline T *data() { return m_data; }
+};
+
// matrix with dynamic height and fixed width (so that matrix has dynamic size).
-template<typename T, int _Cols, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, _Cols, _Options>
+template<typename T, int _Cols, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, _Cols, _Options, true>
{
T *m_data;
int m_rows;
@@ -261,4 +325,34 @@ template<typename T, int _Cols, int _Options> class ei_matrix_storage<T, Dynamic
inline T *data() { return m_data; }
};
+// matrix with dynamic height and fixed width (so that matrix has dynamic size)
+// with Align flag being set to false.
+template<typename T, int _Cols, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, _Cols, _Options, false>
+{
+ T *m_data;
+ int m_rows;
+ public:
+ inline explicit ei_matrix_storage() : m_data(0), m_rows(0) {}
+ inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
+ inline ei_matrix_storage(int size, int rows, int) : m_data(new T[size]), m_rows(rows) {}
+ inline ~ei_matrix_storage() { delete [] m_data; }
+ inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
+ inline int rows(void) const {return m_rows;}
+ inline static int cols(void) {return _Cols;}
+ void resize(int size, int rows, int)
+ {
+ if(size != m_rows*_Cols)
+ {
+ delete [] m_data;
+ if (size)
+ m_data = new T[size];
+ else
+ m_data = 0;
+ }
+ m_rows = rows;
+ }
+ inline const T *data() const { return m_data; }
+ inline T *data() { return m_data; }
+};
+
#endif // EIGEN_MATRIX_H