Skip to content

Commit da66bde

Browse files
Mohit242-bitcvvergara
authored andcommitted
clang-tidy: fix cppcoreguidelines-special-member-functions
- Modernize Pgr_ksp to use std::unique_ptr instead of raw pointer - Complete Rule of Five for Pgr_ksp, Visitor, Pg_points_graph, PgrDirectedChPPGraph, Solution, and Line_vertex classes - Update turnRestrictedPath to use std::make_unique
1 parent 38f3750 commit da66bde

7 files changed

Lines changed: 38 additions & 11 deletions

File tree

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Checks: >
2525
-cppcoreguidelines-pro-type-union-access,
2626
-cppcoreguidelines-pro-type-vararg,
2727
-cppcoreguidelines-slicing,
28-
-cppcoreguidelines-special-member-functions,
2928
-cppcoreguidelines-use-default-member-init
3029
3130
CheckOptions:

include/chinese/chinesePostman.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class PgrDirectedChPPGraph {
6262

6363
~PgrDirectedChPPGraph();
6464

65+
PgrDirectedChPPGraph(const PgrDirectedChPPGraph&) = delete;
66+
PgrDirectedChPPGraph& operator=(const PgrDirectedChPPGraph&) = delete;
67+
PgrDirectedChPPGraph(PgrDirectedChPPGraph&&) = delete;
68+
PgrDirectedChPPGraph& operator=(PgrDirectedChPPGraph&&) = delete;
6569

6670
private:
6771
bool EulerCircuitDFS(int64_t p);

include/cpp_common/line_vertex.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class Line_vertex {
6262
target(v.target),
6363
cost(v.cost) {}
6464

65+
Line_vertex& operator=(const Line_vertex&) = default;
66+
Line_vertex(Line_vertex&&) = default;
67+
Line_vertex& operator=(Line_vertex&&) = default;
68+
~Line_vertex() = default;
69+
6570
void cp_members(const Line_vertex &other) {
6671
this->id = other.id;
6772
this->vertex_id = other.vertex_id;

include/vrp/solution.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ class Solution {
7373

7474
/* @brief copy assignment */
7575
Solution& operator = (const Solution& sol) {
76-
EPSILON = 0.0001,
76+
EPSILON = 0.0001;
7777
fleet = sol.fleet;
7878
trucks = sol.trucks;
7979
return *this;
80-
};
80+
}
81+
82+
/* @brief destructor */
83+
~Solution() = default;
8184

8285

8386
Initials_code get_kind() const;

include/withPoints/withPoints.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class Pg_points_graph : public Pgr_messages {
5050
public:
5151
Pg_points_graph() = delete;
5252
Pg_points_graph(const Pg_points_graph &) = delete;
53+
Pg_points_graph& operator=(const Pg_points_graph&) = delete;
54+
Pg_points_graph(Pg_points_graph&&) = delete;
55+
Pg_points_graph& operator=(Pg_points_graph&&) = delete;
56+
~Pg_points_graph() = default;
57+
5358
Pg_points_graph(
5459
std::vector<Point_on_edge_t> p_points,
5560
std::vector<Edge_t> p_edges_to_modify,

include/yen/ksp.hpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3535
#pragma once
3636

3737
#include <map>
38+
#include <memory>
3839
#include <sstream>
3940
#include <deque>
4041
#include <vector>
@@ -63,11 +64,15 @@ class Pgr_ksp : public Pgr_messages {
6364
m_end(0),
6465
m_K(0),
6566
m_heap_paths(false),
66-
m_vis(new Visitor) {
67+
m_vis(std::make_unique<Visitor>()) {
6768
}
68-
~Pgr_ksp() {
69-
delete m_vis;
70-
}
69+
70+
~Pgr_ksp() = default;
71+
72+
Pgr_ksp(const Pgr_ksp&) = delete;
73+
Pgr_ksp& operator=(const Pgr_ksp&) = delete;
74+
Pgr_ksp(Pgr_ksp&&) = delete;
75+
Pgr_ksp& operator=(Pgr_ksp&&) = delete;
7176

7277
std::deque<Path> Yen(
7378
G &graph,
@@ -121,7 +126,13 @@ class Pgr_ksp : public Pgr_messages {
121126

122127
class Visitor {
123128
public:
124-
virtual ~Visitor() {}
129+
virtual ~Visitor() = default;
130+
131+
Visitor() = default;
132+
Visitor(const Visitor&) = delete;
133+
Visitor& operator=(const Visitor&) = delete;
134+
Visitor(Visitor&&) = delete;
135+
Visitor& operator=(Visitor&&) = delete;
125136

126137
virtual void on_insert_first_solution(const Path) const {
127138
/* noop */
@@ -239,7 +250,7 @@ class Pgr_ksp : public Pgr_messages {
239250
pSet m_ResultSet; //!< ordered set of shortest paths
240251
pSet m_Heap; //!< the heap
241252

242-
Visitor *m_vis;
253+
std::unique_ptr<Visitor> m_vis;
243254
};
244255

245256

include/yen/turnRestrictedPath.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3636
#include <set>
3737
#include <limits>
3838
#include <cstdint>
39+
#include <memory>
3940

4041
#include "yen/ksp.hpp"
4142
#include "cpp_common/assert.hpp"
@@ -161,8 +162,7 @@ class Pgr_turnRestrictedPath : public Pgr_ksp< G > {
161162
this->m_end = end_vertex;
162163
this->m_K = K;
163164
Pgr_ksp<G>::m_heap_paths = true;
164-
delete this->m_vis;
165-
this->m_vis = new Myvisitor(
165+
this->m_vis = std::make_unique<Myvisitor>(
166166
m_solutions,
167167
m_restrictions,
168168
m_stop_on_first);

0 commit comments

Comments
 (0)