Skip to content

Commit 309933f

Browse files
Use std::unique_ptr in LinearSolver
1 parent 4674cec commit 309933f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

g2o/core/linear_solver.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class LinearSolver {
8181
*/
8282
virtual bool solvePattern(
8383
SparseBlockMatrix<MatrixX>& spinv,
84-
const std::vector<std::pair<int, int> >& blockIndices,
84+
const std::vector<std::pair<int, int>>& blockIndices,
8585
const SparseBlockMatrix<MatrixType>& A) {
8686
(void)spinv;
8787
(void)blockIndices;
@@ -150,7 +150,7 @@ template <typename MatrixType>
150150
class LinearSolverCCS : public LinearSolver<MatrixType> {
151151
public:
152152
LinearSolverCCS() : LinearSolver<MatrixType>(), ccsMatrix_(nullptr) {}
153-
~LinearSolverCCS() override { delete ccsMatrix_; }
153+
~LinearSolverCCS() override = default;
154154

155155
bool solveBlocks(double**& blocks,
156156
const SparseBlockMatrix<MatrixType>& A) override {
@@ -162,7 +162,7 @@ class LinearSolverCCS : public LinearSolver<MatrixType> {
162162
}
163163

164164
bool solvePattern(SparseBlockMatrix<MatrixX>& spinv,
165-
const std::vector<std::pair<int, int> >& blockIndices,
165+
const std::vector<std::pair<int, int>>& blockIndices,
166166
const SparseBlockMatrix<MatrixType>& A) override {
167167
auto compute = [&](MarginalCovarianceCholesky& mcc) {
168168
mcc.computeCovariance(spinv, A.rowBlockIndices(), blockIndices);
@@ -175,13 +175,12 @@ class LinearSolverCCS : public LinearSolver<MatrixType> {
175175
void setBlockOrdering(bool blockOrdering) { blockOrdering_ = blockOrdering; }
176176

177177
protected:
178-
SparseBlockMatrixCCS<MatrixType>* ccsMatrix_;
178+
std::unique_ptr<SparseBlockMatrixCCS<MatrixType>> ccsMatrix_;
179179
bool blockOrdering_{true};
180180

181181
void initMatrixStructure(const SparseBlockMatrix<MatrixType>& A) {
182-
delete ccsMatrix_;
183-
ccsMatrix_ = new SparseBlockMatrixCCS<MatrixType>(A.rowBlockIndices(),
184-
A.colBlockIndices());
182+
ccsMatrix_ = std::make_unique<SparseBlockMatrixCCS<MatrixType>>(
183+
A.rowBlockIndices(), A.colBlockIndices());
185184
A.fillSparseBlockMatrixCCS(*ccsMatrix_);
186185
}
187186

0 commit comments

Comments
 (0)