Skip to content

Commit 4033293

Browse files
authored
refactor (#33)
- build: set cpp_std to c++11 - fix: -Wzero-as-null-pointer-constant - fix: -Wlogical-not-parentheses - fix: modernize-redundant-void-arg - fix: -Wwritable-strings - refactor: performance-type-promotion-in-math-fn - refactor: readability-avoid-const-params-in-decls --------- Co-authored-by: Eisuke Kawashima <[email protected]>
1 parent c0eb2d1 commit 4033293

25 files changed

+131
-130
lines changed

include/damping/dftd_atm.h

+15-15
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ namespace dftd4 {
3030
extern int get_atm_dispersion(
3131
const TMolecule &mol,
3232
const TMatrix<double> &dist,
33-
const double cutoff,
34-
const double s9,
35-
const double a1,
36-
const double a2,
37-
const double alp,
33+
double cutoff,
34+
double s9,
35+
double a1,
36+
double a2,
37+
double alp,
3838
const TMatrix<double> &c6,
3939
const TMatrix<double> &dc6dcn,
4040
const TMatrix<double> &dc6dq,
@@ -48,23 +48,23 @@ extern int get_atm_dispersion(
4848
extern int get_atm_dispersion_energy(
4949
const TMolecule &mol,
5050
const TMatrix<double> &dist,
51-
const double cutoff,
52-
const double s9,
53-
const double a1,
54-
const double a2,
55-
const double alp,
51+
double cutoff,
52+
double s9,
53+
double a1,
54+
double a2,
55+
double alp,
5656
const TMatrix<double> &c6,
5757
TVector<double> &energy
5858
);
5959

6060
extern int get_atm_dispersion_derivs(
6161
const TMolecule &mol,
6262
const TMatrix<double> &dist,
63-
const double cutoff,
64-
const double s9,
65-
const double a1,
66-
const double a2,
67-
const double alp,
63+
double cutoff,
64+
double s9,
65+
double a1,
66+
double a2,
67+
double alp,
6868
const TMatrix<double> &c6,
6969
const TMatrix<double> &dc6dcn,
7070
const TMatrix<double> &dc6dq,

include/damping/dftd_rational.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
namespace dftd4 {
2626

27-
extern inline double fdmpr_bj(const int n, const double r, const double c);
28-
extern inline double fdmprdr_bj(const int n, const double r, const double c);
27+
extern inline double fdmpr_bj(int n, double r, double c);
28+
extern inline double fdmprdr_bj(int n, double r, double c);
2929

3030
// Generic wrappers for two- and three-body dispersion
3131

3232
extern int get_dispersion2(
3333
const TMolecule &mol,
3434
const TMatrix<double> &dist,
35-
const double cutoff,
35+
double cutoff,
3636
const dparam &par,
3737
const TMatrix<double> &c6,
3838
const TMatrix<double> &dc6dcn,
@@ -47,7 +47,7 @@ extern int get_dispersion2(
4747
extern int get_dispersion3(
4848
const TMolecule &mol,
4949
const TMatrix<double> &dist,
50-
const double cutoff,
50+
double cutoff,
5151
const dparam &par,
5252
const TMatrix<double> &c6,
5353
const TMatrix<double> &dc6dcn,
@@ -64,7 +64,7 @@ extern int get_dispersion3(
6464
extern int get_dispersion2_energy(
6565
const TMolecule &mol,
6666
const TMatrix<double> &dist,
67-
const double cutoff,
67+
double cutoff,
6868
const dparam &par,
6969
const TMatrix<double> &c6,
7070
TVector<double> &energy
@@ -73,7 +73,7 @@ extern int get_dispersion2_energy(
7373
extern int get_dispersion2_derivs(
7474
const TMolecule &mol,
7575
const TMatrix<double> &dist,
76-
const double cutoff,
76+
double cutoff,
7777
const dparam &par,
7878
const TMatrix<double> &c6,
7979
const TMatrix<double> &dc6dcn,

include/dftd_damping.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ namespace dftd4 {
3737
* @returns Exit status.
3838
*/
3939
extern int
40-
d4par(const std::string func, dftd4::dparam &par, const bool latm = true);
40+
d4par(const std::string func, dftd4::dparam &par, bool latm = true);
4141

4242
} // namespace dftd4

include/dftd_dispersion.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ class dparam {
5252
*/
5353
extern int get_dispersion(
5454
const TMolecule &mol,
55-
const int charge,
55+
int charge,
5656
const TD4Model &d4,
5757
const dparam &par,
58-
const TCutoff cutoff,
58+
TCutoff cutoff,
5959
double &energy,
6060
double *GRAD
6161
);

include/dftd_eeq.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ namespace dftd4 {
3030
extern int get_charges(
3131
const TMolecule &mol,
3232
const TMatrix<double> &dist,
33-
const int charge,
34-
const double cutoff,
33+
int charge,
34+
double cutoff,
3535
TVector<double> &q,
3636
TMatrix<double> &dqdr,
3737
bool lgrad

include/dftd_geometry.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class TMolecule {
3838
at.New(NAtoms);
3939
}
4040

41-
void FreeMemory(void) {
41+
void FreeMemory() {
4242
xyz.Delete();
4343
at.Delete();
4444
}

include/dftd_matrix.h

+20-20
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ template <class T> class TVector {
3333

3434
TVector() {
3535
N = 0;
36-
p = 0;
36+
p = nullptr;
3737
ElementSize = sizeof(T);
3838
}
3939
~TVector() {
40-
if (p != 0) Delete();
40+
if (p != nullptr) Delete();
4141
}
4242
void NewVector(int VectorLength) {
4343
if (VectorLength < 0) { std::exit(EXIT_FAILURE); }
44-
if (p != 0 && N == VectorLength) {
44+
if (p != nullptr && N == VectorLength) {
4545
Init();
4646
} else {
4747
Delete();
@@ -58,9 +58,9 @@ template <class T> class TVector {
5858
void New(int VectorLength) { return NewVector(VectorLength); }
5959
void NewVec(int VectorLength) { return NewVector(VectorLength); }
6060

61-
void Delete(void) {
62-
if (p != 0 && N != 0) { delete[] p; }
63-
p = 0;
61+
void Delete() {
62+
if (p != nullptr && N != 0) { delete[] p; }
63+
p = nullptr;
6464
N = 0;
6565
}
6666
void CopyVec(const TVector &v) {
@@ -73,8 +73,8 @@ template <class T> class TVector {
7373
mem = (long int)N * ElementSize;
7474
std::memcpy(p, v.p, mem);
7575
}
76-
void Init(void) {
77-
if (p != 0) {
76+
void Init() {
77+
if (p != nullptr) {
7878
long int mem = (long int)N * ElementSize;
7979
std::memset(p, 0, mem);
8080
}
@@ -104,20 +104,20 @@ template <class T> class TMatrix {
104104
TMatrix() {
105105
cols = 0;
106106
rows = 0;
107-
p = 0;
107+
p = nullptr;
108108
ElementSize = sizeof(T);
109109
}
110110
~TMatrix() {
111-
if (p != 0) Delete();
111+
if (p != nullptr) Delete();
112112
}
113113

114114
void NewMatrix(int r, int c) {
115115
if (r < 0 || c < 0) std::exit(EXIT_FAILURE);
116-
if (p != 0 && r == rows && c == cols) {
116+
if (p != nullptr && r == rows && c == cols) {
117117
Init();
118118
} else {
119119
long int mem = (long int)r * (long int)c;
120-
if (p != 0) Delete(); // Eventually delete old matrix
120+
if (p != nullptr) Delete(); // Eventually delete old matrix
121121

122122
if (mem == 0) return; // don't touch pointer if no memory is allocated
123123

@@ -136,26 +136,26 @@ template <class T> class TMatrix {
136136
void New(int r, int c) { return NewMatrix(r, c); }
137137
void NewMat(int r, int c) { return NewMatrix(r, c); }
138138

139-
void Delete(void) {
140-
if (p != 0 && rows * cols != 0) { delete[] p; }
139+
void Delete() {
140+
if (p != nullptr && rows * cols != 0) { delete[] p; }
141141
rows = 0;
142142
cols = 0;
143-
p = 0;
143+
p = nullptr;
144144
}
145145

146-
void Init(void) {
146+
void Init() {
147147
long int mem;
148-
if (p != 0) {
148+
if (p != nullptr) {
149149
mem = (long int)cols * (long int)rows * ElementSize;
150150
std::memset(p, 0, mem);
151151
}
152152
}
153153

154-
void Transpose(void) {
154+
void Transpose() {
155155
T x;
156156
int i, j;
157157

158-
if (p != 0) {
158+
if (p != nullptr) {
159159
if (rows == cols) {
160160
for (i = 0; i < rows; i++) {
161161
for (j = 0; j < i; j++) {
@@ -191,7 +191,7 @@ template <class T> class TMatrix {
191191
std::memcpy(p, m.p, mem);
192192
}
193193

194-
void Print(char name[] = "unknown") {
194+
void Print(const char name[] = "unknown") {
195195
printf("Matrix printed: %s (%d, %d)\n", name, rows, cols);
196196
for (int i = 0; i < rows; i++) {
197197
for (int j = 0; j < cols; j++) {

include/dftd_model.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ class TD4Model {
7777
extern inline double trapzd(const double a[23], const double b[23]);
7878

7979
extern inline double
80-
weight_cn(const double wf, const double cn, const double cnref);
80+
weight_cn(double wf, double cn, double cnref);
8181

8282
extern inline double
83-
zeta(const double a, const double c, const double qref, const double qmod);
83+
zeta(double a, double c, double qref, double qmod);
8484
extern inline double
85-
dzeta(const double a, const double c, const double qref, const double qmod);
85+
dzeta(double a, double c, double qref, double qmod);
8686

8787
extern int get_max_ref(const TMolecule &mol, int &mref);
8888

include/dftd_ncoord.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern int calc_distances(const TMolecule &mol, TMatrix<double> &dist);
5151
extern int get_ncoord_erf(
5252
const TMolecule &mol,
5353
const TMatrix<double> &dist,
54-
const double cutoff,
54+
double cutoff,
5555
TVector<double> &cn,
5656
TMatrix<double> &dcndr,
5757
bool lgrad = false
@@ -69,7 +69,7 @@ extern int get_ncoord_erf(
6969
extern int ncoord_erf(
7070
const TMolecule &mol,
7171
const TMatrix<double> &dist,
72-
const double cutoff,
72+
double cutoff,
7373
TVector<double> &cn
7474
);
7575

@@ -87,7 +87,7 @@ extern int ncoord_erf(
8787
extern int dncoord_erf(
8888
const TMolecule &mol,
8989
const TMatrix<double> &dist,
90-
const double cutoff,
90+
double cutoff,
9191
TVector<double> &cn,
9292
TMatrix<double> &dcndr
9393
);
@@ -104,7 +104,7 @@ extern int dncoord_erf(
104104
extern int get_ncoord_d4(
105105
const TMolecule &mol,
106106
const TMatrix<double> &dist,
107-
const double cutoff,
107+
double cutoff,
108108
TVector<double> &cn,
109109
TMatrix<double> &dcndr,
110110
bool lgrad = false
@@ -122,7 +122,7 @@ extern int get_ncoord_d4(
122122
extern int ncoord_d4(
123123
const TMolecule &mol,
124124
const TMatrix<double> &dist,
125-
const double cutoff,
125+
double cutoff,
126126
TVector<double> &cn
127127
);
128128

@@ -140,7 +140,7 @@ extern int ncoord_d4(
140140
extern int dncoord_d4(
141141
const TMolecule &mol,
142142
const TMatrix<double> &dist,
143-
const double cutoff,
143+
double cutoff,
144144
TVector<double> &cn,
145145
TMatrix<double> &dcndr
146146
);
@@ -173,14 +173,14 @@ extern double derf_count(double k, double rr);
173173
* @param lgrad Flag for gradient.
174174
*/
175175
extern int cut_coordination_number(
176-
const double cn_max,
176+
double cn_max,
177177
TVector<double> &cn,
178178
TMatrix<double> &dcndr,
179179
bool lgrad
180180
);
181181

182-
extern inline double log_cn_cut(const double cn_max, const double cn);
182+
extern inline double log_cn_cut(double cn_max, double cn);
183183

184-
extern inline double dlog_cn_cut(const double cn_max, const double cn);
184+
extern inline double dlog_cn_cut(double cn_max, double cn);
185185

186186
}; // namespace dftd4

meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ project(
2222
license: 'LGPL3-or-later',
2323
meson_version: '>=0.51',
2424
default_options: [
25+
'cpp_std=c++11',
2526
'default_library=both',
2627
'warning_level=3',
2728
],

0 commit comments

Comments
 (0)