From 49faa1829b28275db200a96573e1a7c94c7f24cb Mon Sep 17 00:00:00 2001
From: Jesper Andersson <jesper@fmrib.ox.ac.uk>
Date: Tue, 15 Feb 2011 15:45:08 +0000
Subject: [PATCH] Added copy-constructor and assignment operator to SpMat

---
 SpMat.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/SpMat.h b/SpMat.h
index 00ebdff..32c844c 100644
--- a/SpMat.h
+++ b/SpMat.h
@@ -94,6 +94,7 @@ public:
   SpMat(unsigned int m, unsigned int n, const unsigned int *irp, const unsigned int *jcp, const double *sp);
   SpMat(const NEWMAT::GeneralMatrix& M);
   SpMat(const std::string& fname);
+  SpMat(const SpMat<T>& s) : _m(s._m), _n(s._n), _nz(s._nz), _ri(s._ri), _val(s._val), _pw(s._pw), _ei(*this,true) {}
   ~SpMat() {}
 
   unsigned int Nrows() const {return(_m);}
@@ -121,6 +122,12 @@ public:
   void SetColumn(unsigned int c, const NEWMAT::ColumnVector& col, double eps=0.0);  // Set a whole column (obliterating what was there before) 
   void AddTo(unsigned int r, unsigned int c, const T& v) {here(r,c) += v;}          // Add value to a single (possibly existing) value
 
+  SpMat<T>& operator=(const SpMat& M)
+  {
+    if (this == &M) return(*this);
+    _m=M._m; _n=M._n; _nz=M._nz; _ri=M._ri; _val=M._val; _pw=M._pw; _ei=M._ei;
+    return(*this);
+  }
   SpMat<T>& operator+=(const SpMat& M) 
   {
     if (same_sparsity(M)) return(add_same_sparsity_mat_to_me(M,1));
@@ -182,10 +189,11 @@ public:
       if (_j == _mat._n) _oob = true;
     }
     ~Iterator() {}
+    Iterator& operator=(const Iterator& I) { _i=I._i; _j=I._j; _oob=I._oob; return(*this); } // _mat deliberately not assigned
     bool operator==(const Iterator& other) { return(&_mat==&other._mat && ((_oob && other._oob) || (_i==other._i && _j==other._j))); }
     bool operator!=(const Iterator& other) { return(!(*this==other)); }
     T& operator*() { return((_mat._val[_j])[_i]); }
-    Iterator& operator++() 
+    Iterator& operator++() // Prefix operator
     {
       if (++_i < _mat._ri[_j].size()) return(*this);
       else {
-- 
GitLab