Dear all,
What do you guys think about having assignment operators in
DenseSubVector and DenseSubMatrix? Actually, I would like to have
them since that would enable me to use a std::vector<DenseSubVector>.
This requires the DenseSubVector::parent member to be a pointer rather
than a reference, but that shouldn't cause any problems, right?
Actually, I just implemented this, so if you like it, just check it
in.
Best Regards,
Tim
--
Dr. Tim Kroeger
[email protected] Phone +49-421-218-7710
[email protected] Fax +49-421-218-4236
Fraunhofer MEVIS, Institute for Medical Image Computing
Universitaetsallee 29, 28359 Bremen, Germany
Index: include/numerics/dense_subvector.h
===================================================================
--- include/numerics/dense_subvector.h (Revision 3305)
+++ include/numerics/dense_subvector.h (Arbeitskopie)
@@ -56,15 +56,25 @@
const unsigned int n=0);
/**
+ * Copy constructor.
+ */
+ DenseSubVector(const DenseSubVector<T>& other);
+
+ /**
* Destructor. Does nothing.
*/
virtual ~DenseSubVector() {}
/**
+ * Assignment operator.
+ */
+ DenseSubVector<T>& operator= (const DenseSubVector<T>& other);
+
+ /**
* @returns a reference to the parent vector.
*/
- DenseVector<T>& parent () { return _parent_vector; }
+ DenseVector<T>& parent () { return *_parent_vector; }
/**
* Set every element in the subvector to 0.
@@ -113,7 +123,7 @@
/**
* The parent vector that contains this subvector.
*/
- DenseVector<T>& _parent_vector;
+ DenseVector<T>* _parent_vector;
/**
* The length of this subvector.
@@ -135,7 +145,7 @@
DenseSubVector<T>::DenseSubVector(DenseVector<T>& parent,
const unsigned int ioff,
const unsigned int n) :
- _parent_vector(parent)
+ _parent_vector(&parent)
{
reposition (ioff, n);
}
@@ -144,6 +154,30 @@
template<typename T>
inline
+DenseSubVector<T>::DenseSubVector(const DenseSubVector<T>& other) :
+ DenseVectorBase<T>(other),
+ _parent_vector(other._parent_vector),
+ _n(other._n),
+ _i_off(other._i_off)
+{
+}
+
+
+
+template<typename T>
+inline
+DenseSubVector<T>& DenseSubVector<T>::operator= (const DenseSubVector<T>&
other)
+{
+ _parent_vector = other._parent_vector;
+ _n = other._n;
+ _i_off = other._i_off;
+ return *this;
+}
+
+
+
+template<typename T>
+inline
void DenseSubVector<T>::reposition(const unsigned int ioff,
const unsigned int n)
{
@@ -151,7 +185,8 @@
_n = n;
// Make sure we still fit in the parent vector.
- libmesh_assert ((this->i_off() + this->size()) <= _parent_vector.size());
+ libmesh_assert (_parent_vector!=NULL);
+ libmesh_assert ((this->i_off() + this->size()) <= _parent_vector->size());
}
@@ -160,8 +195,9 @@
inline
void DenseSubVector<T>::zero()
{
+ libmesh_assert (_parent_vector!=NULL);
for (unsigned int i=0; i<this->size(); i++)
- _parent_vector (i + this->i_off()) = 0.;
+ (*_parent_vector) (i + this->i_off()) = 0.;
}
@@ -170,10 +206,11 @@
inline
T DenseSubVector<T>::operator () (const unsigned int i) const
{
+ libmesh_assert (_parent_vector!=NULL);
libmesh_assert (i < this->size());
- libmesh_assert (i + this->i_off() < _parent_vector.size());
+ libmesh_assert (i + this->i_off() < _parent_vector->size());
- return _parent_vector (i + this->i_off());
+ return (*_parent_vector) (i + this->i_off());
}
@@ -181,10 +218,11 @@
inline
T & DenseSubVector<T>::operator () (const unsigned int i)
{
+ libmesh_assert (_parent_vector!=NULL);
libmesh_assert (i < this->size());
- libmesh_assert (i + this->i_off() < _parent_vector.size());
+ libmesh_assert (i + this->i_off() < _parent_vector->size());
- return _parent_vector (i + this->i_off());
+ return (*_parent_vector) (i + this->i_off());
}
Index: include/numerics/dense_submatrix.h
===================================================================
--- include/numerics/dense_submatrix.h (Revision 3305)
+++ include/numerics/dense_submatrix.h (Arbeitskopie)
@@ -65,6 +65,11 @@
DenseSubMatrix (const DenseSubMatrix<T>& other_matrix);
/**
+ * Assignment operator.
+ */
+ DenseSubMatrix<T>& operator= (const DenseSubMatrix<T>& other);
+
+ /**
* Destructor. Empty.
*/
virtual ~DenseSubMatrix() {};
@@ -73,7 +78,7 @@
/**
* @returns a reference to the parent matrix.
*/
- DenseMatrix<T>& parent () { return _parent_matrix; }
+ DenseMatrix<T>& parent () { return *_parent_matrix; }
/**
* Set every element in the submatrix to 0.
@@ -153,7 +158,7 @@
/**
* The parent matrix that contains this submatrix.
*/
- DenseMatrix<T>& _parent_matrix;
+ DenseMatrix<T>* _parent_matrix;
/**
* The row offset into the parent matrix.
@@ -177,7 +182,7 @@
const unsigned int m,
const unsigned int n)
: DenseMatrixBase<T>(m,n),
- _parent_matrix(parent)
+ _parent_matrix(&parent)
{
this->reposition (ioff, joff, m, n);
}
@@ -197,6 +202,18 @@
template<typename T>
inline
+DenseSubMatrix<T>& DenseSubMatrix<T>::operator= (const DenseSubMatrix<T>&
other)
+{
+ DenseMatrixBase<T>::operator=(other);
+ _parent_matrix = other._parent_matrix;
+ _i_off = other._i_off;
+ _j_off = other._j_off;
+ return *this;
+}
+
+
+template<typename T>
+inline
void DenseSubMatrix<T>::reposition(const unsigned int ioff,
const unsigned int joff,
const unsigned int m,
@@ -208,8 +225,9 @@
this->_n = n;
// Make sure we still fit in the parent matrix.
- libmesh_assert ((this->i_off() + this->m()) <= _parent_matrix.m());
- libmesh_assert ((this->j_off() + this->n()) <= _parent_matrix.n());
+ libmesh_assert (_parent_matrix!=NULL);
+ libmesh_assert ((this->i_off() + this->m()) <= _parent_matrix->m());
+ libmesh_assert ((this->j_off() + this->n()) <= _parent_matrix->n());
}
@@ -218,10 +236,11 @@
inline
void DenseSubMatrix<T>::zero()
{
+ libmesh_assert (_parent_matrix!=NULL);
for (unsigned int i=0; i<this->m(); i++)
for (unsigned int j=0; j<this->n(); j++)
- _parent_matrix(i + this->i_off(),
- j + this->j_off()) = 0.;
+ (*_parent_matrix)(i + this->i_off(),
+ j + this->j_off()) = 0.;
}
@@ -231,13 +250,14 @@
T DenseSubMatrix<T>::operator () (const unsigned int i,
const unsigned int j) const
{
+ libmesh_assert (_parent_matrix!=NULL);
libmesh_assert (i < this->m());
libmesh_assert (j < this->n());
- libmesh_assert (i + this->i_off() < _parent_matrix.m());
- libmesh_assert (j + this->j_off() < _parent_matrix.n());
+ libmesh_assert (i + this->i_off() < _parent_matrix->m());
+ libmesh_assert (j + this->j_off() < _parent_matrix->n());
- return _parent_matrix (i + this->i_off(),
- j + this->j_off());
+ return (*_parent_matrix) (i + this->i_off(),
+ j + this->j_off());
}
@@ -246,13 +266,14 @@
T & DenseSubMatrix<T>::operator () (const unsigned int i,
const unsigned int j)
{
+ libmesh_assert (_parent_matrix!=NULL);
libmesh_assert (i < this->m());
libmesh_assert (j < this->n());
- libmesh_assert (i + this->i_off() < _parent_matrix.m());
- libmesh_assert (j + this->j_off() < _parent_matrix.n());
+ libmesh_assert (i + this->i_off() < _parent_matrix->m());
+ libmesh_assert (j + this->j_off() < _parent_matrix->n());
- return _parent_matrix (i + this->i_off(),
- j + this->j_off());
+ return (*_parent_matrix) (i + this->i_off(),
+ j + this->j_off());
}
Index: include/numerics/dense_matrix_base.h
===================================================================
--- include/numerics/dense_matrix_base.h (Revision 3305)
+++ include/numerics/dense_matrix_base.h (Arbeitskopie)
@@ -53,6 +53,16 @@
DenseMatrixBase(const unsigned int m=0,
const unsigned int n=0) : _m(m), _n(n) {};
+ /**
+ * Copy constructor.
+ */
+ DenseMatrixBase(const DenseMatrixBase<T>& other) : _m(other._n),
_n(other._n) {};
+
+ /**
+ * Assignment operator.
+ */
+ DenseMatrixBase<T>& operator= (const DenseMatrixBase<T>& other);
+
public:
/**
* Destructor. Empty.
@@ -176,6 +186,17 @@
template<typename T>
+inline
+DenseMatrixBase<T>& DenseMatrixBase<T>::operator= (const DenseMatrixBase<T>&
other)
+{
+ _m = other._m;
+ _n = other._n;
+ return *this;
+}
+
+
+
+template<typename T>
template<typename T2, typename T3>
inline
typename boostcopy::enable_if_c<
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Libmesh-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-devel