diff options
Diffstat (limited to 'hwpfilter/source')
-rw-r--r-- | hwpfilter/source/cspline.cxx | 4 | ||||
-rw-r--r-- | hwpfilter/source/solver.cxx | 28 | ||||
-rw-r--r-- | hwpfilter/source/solver.h | 5 |
3 files changed, 8 insertions, 29 deletions
diff --git a/hwpfilter/source/cspline.cxx b/hwpfilter/source/cspline.cxx index 32041163e00b..a61104f5e9ac 100644 --- a/hwpfilter/source/cspline.cxx +++ b/hwpfilter/source/cspline.cxx @@ -119,7 +119,7 @@ void PeriodicSpline (int N, const double* x, const double* a, double*& b, double for (i = 0; i < N; i++) h[i] = x[i+1]-x[i]; - double** mat = mgcLinearSystemD::NewMatrix(N+1); // guaranteed to be zeroed memory + std::unique_ptr<std::unique_ptr<double[]>[]> mat = mgcLinearSystemD::NewMatrix(N+1); // guaranteed to be zeroed memory c = mgcLinearSystemD::NewVector(N+1); // guaranteed to be zeroed memory // c[0] - c[N] = 0 @@ -155,8 +155,6 @@ void PeriodicSpline (int N, const double* x, const double* a, double*& b, double b[i] = (a[i+1]-a[i])/h[i] - oneThird*(c[i+1]+2.0f*c[i])*h[i]; d[i] = oneThird*(c[i+1]-c[i])/h[i]; } - - mgcLinearSystemD::DeleteMatrix(N+1,mat); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/solver.cxx b/hwpfilter/source/solver.cxx index d1c76b8cd916..323eaa2af068 100644 --- a/hwpfilter/source/solver.cxx +++ b/hwpfilter/source/solver.cxx @@ -22,35 +22,19 @@ #include "solver.h" -double** mgcLinearSystemD::NewMatrix (int N) +std::unique_ptr<std::unique_ptr<double[]>[]> mgcLinearSystemD::NewMatrix (int N) { - double** A = new double*[N]; - if ( !A ) - return nullptr; + std::unique_ptr<std::unique_ptr<double[]>[]> A(new std::unique_ptr<double[]>); for (int row = 0; row < N; row++) { - A[row] = new double[N]; - if ( !A[row] ) - { - for (int i = 0; i < row; i++) - delete[] A[i]; - delete[] A; - return nullptr; - } + A[row].reset(new double[N]); for (int col = 0; col < N; col++) A[row][col] = 0; } return A; } -void mgcLinearSystemD::DeleteMatrix (int N, double** A) -{ - for (int row = 0; row < N; row++) - delete[] A[row]; - delete[] A; -} - double* mgcLinearSystemD::NewVector (int N) { double* B = new double[N]; @@ -62,7 +46,7 @@ double* mgcLinearSystemD::NewVector (int N) return B; } -bool mgcLinearSystemD::Solve (int n, double** a, double* b) +bool mgcLinearSystemD::Solve (int n, std::unique_ptr<std::unique_ptr<double[]>[]>& a, double* b) { std::unique_ptr<int[]> indxc( new int[n] ); if ( !indxc ) @@ -113,9 +97,7 @@ bool mgcLinearSystemD::Solve (int n, double** a, double* b) if ( irow != icol ) { - double* rowptr = a[irow]; - a[irow] = a[icol]; - a[icol] = rowptr; + std::swap(a[irow], a[icol]); save = b[irow]; b[irow] = b[icol]; diff --git a/hwpfilter/source/solver.h b/hwpfilter/source/solver.h index ea3295bad9d4..0da10ac72ae8 100644 --- a/hwpfilter/source/solver.h +++ b/hwpfilter/source/solver.h @@ -23,11 +23,10 @@ class mgcLinearSystemD { public: - static double** NewMatrix (int N); - static void DeleteMatrix (int N, double** A); + static std::unique_ptr<std::unique_ptr<double[]>[]> NewMatrix (int N); static double* NewVector (int N); - static bool Solve (int N, double** A, double* b); + static bool Solve (int N, std::unique_ptr<std::unique_ptr<double[]>[]>& A, double* b); // Input: // A[N][N] coefficient matrix, entries are A[row][col] // b[N] vector, entries are b[row] |