Skip to content

Commit 18f9507

Browse files
committed
fix some clang-tidy warnings
1 parent 4c34a25 commit 18f9507

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1179
-409
lines changed

.clang-tidy

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
Checks:
2-
- "-*"
3-
- "bugprone-*"
4-
- "readability-braces-around-statements"
5-
- "readability-else-after-return"
6-
- "cppcoreguidelines-interfaces-global-init"
7-
- "cppcoreguidelines-pro-type-member-init"
8-
- "cppcoreguidelines-pro-type-static-cast-downcast"
9-
- "cppcoreguidelines-pro-type-union-access"
10-
- "cppcoreguidelines-slicing"
11-
- "cppcoreguidelines-special-member-functions"
1+
Checks: >
2+
-*,
3+
bugprone-*,
4+
readability-braces-around-statements,
5+
readability-else-after-return,
6+
cppcoreguidelines-interfaces-global-init,
7+
cppcoreguidelines-pro-type-member-init,
8+
cppcoreguidelines-pro-type-static-cast-downcast,
9+
cppcoreguidelines-pro-type-union-access,
10+
cppcoreguidelines-slicing,
11+
cppcoreguidelines-special-member-functions
1212
WarningsAsErrors: ''
1313
HeaderFilterRegex: '.*'
1414
FormatStyle: file

modules/mrpt_containers/include/mrpt/containers/CDynamicGrid.h

+76-19
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ class CDynamicGrid
112112
*/
113113
inline void fill(const T& value)
114114
{
115-
for (auto it = m_map.begin(); it != m_map.end(); ++it) *it = value;
115+
for (auto it = m_map.begin(); it != m_map.end(); ++it)
116+
{
117+
*it = value;
118+
}
116119
}
117120

118121
/** Changes the size of the grid, maintaining previous contents.
@@ -133,30 +136,62 @@ class CDynamicGrid
133136
return;
134137
}
135138

136-
if (new_x_min > m_x_min) new_x_min = m_x_min;
137-
if (new_x_max < m_x_max) new_x_max = m_x_max;
138-
if (new_y_min > m_y_min) new_y_min = m_y_min;
139-
if (new_y_max < m_y_max) new_y_max = m_y_max;
139+
if (new_x_min > m_x_min)
140+
{
141+
new_x_min = m_x_min;
142+
}
143+
if (new_x_max < m_x_max)
144+
{
145+
new_x_max = m_x_max;
146+
}
147+
if (new_y_min > m_y_min)
148+
{
149+
new_y_min = m_y_min;
150+
}
151+
if (new_y_max < m_y_max)
152+
{
153+
new_y_max = m_y_max;
154+
}
140155

141156
// Additional margin:
142157
if (additionalMarginMeters > 0)
143158
{
144-
if (new_x_min < m_x_min) new_x_min = floor(new_x_min - additionalMarginMeters);
145-
if (new_x_max > m_x_max) new_x_max = ceil(new_x_max + additionalMarginMeters);
146-
if (new_y_min < m_y_min) new_y_min = floor(new_y_min - additionalMarginMeters);
147-
if (new_y_max > m_y_max) new_y_max = ceil(new_y_max + additionalMarginMeters);
159+
if (new_x_min < m_x_min)
160+
{
161+
new_x_min = floor(new_x_min - additionalMarginMeters);
162+
}
163+
if (new_x_max > m_x_max)
164+
{
165+
new_x_max = ceil(new_x_max + additionalMarginMeters);
166+
}
167+
if (new_y_min < m_y_min)
168+
{
169+
new_y_min = floor(new_y_min - additionalMarginMeters);
170+
}
171+
if (new_y_max > m_y_max)
172+
{
173+
new_y_max = ceil(new_y_max + additionalMarginMeters);
174+
}
148175
}
149176

150177
// Adjust sizes to adapt them to full sized cells according to the
151178
// resolution:
152179
if (fabs(new_x_min / m_resolution - round(new_x_min / m_resolution)) > 0.05)
180+
{
153181
new_x_min = m_resolution * round(new_x_min / m_resolution);
182+
}
154183
if (fabs(new_y_min / m_resolution - round(new_y_min / m_resolution)) > 0.05)
184+
{
155185
new_y_min = m_resolution * round(new_y_min / m_resolution);
186+
}
156187
if (fabs(new_x_max / m_resolution - round(new_x_max / m_resolution)) > 0.05)
188+
{
157189
new_x_max = m_resolution * round(new_x_max / m_resolution);
190+
}
158191
if (fabs(new_y_max / m_resolution - round(new_y_max / m_resolution)) > 0.05)
192+
{
159193
new_y_max = m_resolution * round(new_y_max / m_resolution);
194+
}
160195

161196
// Change the map size: Extensions at each side:
162197
const auto extra_x_left = static_cast<std::size_t>(round((m_x_min - new_x_min) / m_resolution));
@@ -205,17 +240,29 @@ class CDynamicGrid
205240
{
206241
const int cx = x2idx(x);
207242
const int cy = y2idx(y);
208-
if (cx < 0 || cx >= static_cast<int>(m_size_x)) return nullptr;
209-
if (cy < 0 || cy >= static_cast<int>(m_size_y)) return nullptr;
243+
if (cx < 0 || cx >= static_cast<int>(m_size_x))
244+
{
245+
return nullptr;
246+
}
247+
if (cy < 0 || cy >= static_cast<int>(m_size_y))
248+
{
249+
return nullptr;
250+
}
210251
return &m_map[static_cast<size_t>(cx) + static_cast<size_t>(cy) * m_size_x];
211252
}
212253
/** \overload */
213254
inline const T* cellByPos(double x, double y) const
214255
{
215256
const int cx = x2idx(x);
216257
const int cy = y2idx(y);
217-
if (cx < 0 || cx >= static_cast<int>(m_size_x)) return nullptr;
218-
if (cy < 0 || cy >= static_cast<int>(m_size_y)) return nullptr;
258+
if (cx < 0 || cx >= static_cast<int>(m_size_x))
259+
{
260+
return nullptr;
261+
}
262+
if (cy < 0 || cy >= static_cast<int>(m_size_y))
263+
{
264+
return nullptr;
265+
}
219266
return &m_map[static_cast<size_t>(cx) + static_cast<size_t>(cy) * m_size_x];
220267
}
221268

@@ -225,9 +272,10 @@ class CDynamicGrid
225272
inline T* cellByIndex(unsigned int cx, unsigned int cy)
226273
{
227274
if (cx >= m_size_x || cy >= m_size_y)
275+
{
228276
return nullptr;
229-
else
230-
return &m_map[cx + cy * m_size_x];
277+
}
278+
return &m_map[cx + cy * m_size_x];
231279
}
232280

233281
/** Returns a pointer to the contents of a cell given by its cell indexes,
@@ -236,9 +284,10 @@ class CDynamicGrid
236284
inline const T* cellByIndex(unsigned int cx, unsigned int cy) const
237285
{
238286
if (cx >= m_size_x || cy >= m_size_y)
287+
{
239288
return nullptr;
240-
else
241-
return &m_map[cx + cy * m_size_x];
289+
}
290+
return &m_map[cx + cy * m_size_x];
242291
}
243292

244293
/** Returns the horizontal size of grid map in cells count */
@@ -287,10 +336,18 @@ class CDynamicGrid
287336
void getAsMatrix(MAT& m) const
288337
{
289338
m.setSize(m_size_y, m_size_x);
290-
if (m_map.empty()) return;
339+
if (m_map.empty())
340+
{
341+
return;
342+
}
291343
const T* c = &m_map[0];
292344
for (size_t cy = 0; cy < m_size_y; cy++)
293-
for (size_t cx = 0; cx < m_size_x; cx++) m(cy, cx) = *c++;
345+
{
346+
for (size_t cx = 0; cx < m_size_x; cx++)
347+
{
348+
m(cy, cx) = *c++;
349+
}
350+
}
294351
}
295352

296353
/** The user must implement this in order to provide "saveToTextFile" a way

modules/mrpt_containers/include/mrpt/containers/bimap.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ class bimap
9494

9595
if (!keyExists && valueExists) THROW_EXCEPTION("Duplicated `value` with different `key`");
9696

97-
if (keyExists && valueExists && itKey->second == v) return; // Ok
97+
if (keyExists && valueExists && itKey->second == v)
98+
{
99+
return; // Ok
100+
}
98101

99102
// New:
100103
m_k2v[k] = v;
@@ -109,7 +112,10 @@ class bimap
109112
bool direct(const KEY& k, VALUE& out_v) const
110113
{
111114
const_iterator i = m_k2v.find(k);
112-
if (i == m_k2v.end()) return false;
115+
if (i == m_k2v.end())
116+
{
117+
return false;
118+
}
113119
out_v = i->second;
114120
return true;
115121
}
@@ -142,7 +148,10 @@ class bimap
142148
bool inverse(const VALUE& v, KEY& out_k) const
143149
{
144150
const_iterator_inverse i = m_v2k.find(v);
145-
if (i == m_v2k.end()) return false;
151+
if (i == m_v2k.end())
152+
{
153+
return false;
154+
}
146155
out_k = i->second;
147156
return true;
148157
}

modules/mrpt_containers/include/mrpt/containers/circular_buffer.h

+63-17
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ class circular_buffer
3030
public:
3131
circular_buffer(size_t size) : m_data(size), m_size(size), m_next_read(0), m_next_write(0)
3232
{
33-
if (m_size <= 2) throw std::invalid_argument("size must be >2");
33+
if (m_size <= 2)
34+
{
35+
throw std::invalid_argument("size must be >2");
36+
}
3437
}
3538

3639
/** Insert a copy of the given element in the buffer.
@@ -39,8 +42,14 @@ class circular_buffer
3942
void push(T d)
4043
{
4144
auto new_idx = m_next_write + 1;
42-
if (new_idx == m_size) new_idx = 0;
43-
if (new_idx == m_next_read) throw std::out_of_range("push: circular_buffer is full");
45+
if (new_idx == m_size)
46+
{
47+
new_idx = 0;
48+
}
49+
if (new_idx == m_next_read)
50+
{
51+
throw std::out_of_range("push: circular_buffer is full");
52+
}
4453
m_data[m_next_write] = d;
4554
m_next_write = new_idx;
4655
}
@@ -51,28 +60,43 @@ class circular_buffer
5160
void push_ref(const T& d)
5261
{
5362
m_data[m_next_write++] = d;
54-
if (m_next_write == m_size) m_next_write = 0;
63+
if (m_next_write == m_size)
64+
{
65+
m_next_write = 0;
66+
}
5567

56-
if (m_next_write == m_next_read) throw std::out_of_range("push: circular_buffer is full");
68+
if (m_next_write == m_next_read)
69+
{
70+
throw std::out_of_range("push: circular_buffer is full");
71+
}
5772
}
5873

5974
/** Insert an array of elements in the buffer.
6075
* \exception std::out_of_range If the buffer run out of space.
6176
*/
6277
void push_many(T* array_elements, size_t count)
6378
{
64-
while (count--) push(*array_elements++);
79+
while (count--)
80+
{
81+
push(*array_elements++);
82+
}
6583
}
6684

6785
/** Retrieve an element from the buffer.
6886
* \exception std::out_of_range If the buffer is empty.
6987
*/
7088
T pop()
7189
{
72-
if (m_next_read == m_next_write) throw std::out_of_range("pop: circular_buffer is empty");
90+
if (m_next_read == m_next_write)
91+
{
92+
throw std::out_of_range("pop: circular_buffer is empty");
93+
}
7394

7495
const size_t i = m_next_read++;
75-
if (m_next_read == m_size) m_next_read = 0;
96+
if (m_next_read == m_size)
97+
{
98+
m_next_read = 0;
99+
}
76100
return m_data[i];
77101
}
78102

@@ -81,26 +105,38 @@ class circular_buffer
81105
*/
82106
void pop(T& out_val)
83107
{
84-
if (m_next_read == m_next_write) throw std::out_of_range("pop: circular_buffer is empty");
108+
if (m_next_read == m_next_write)
109+
{
110+
throw std::out_of_range("pop: circular_buffer is empty");
111+
}
85112

86113
out_val = m_data[m_next_read++];
87-
if (m_next_read == m_size) m_next_read = 0;
114+
if (m_next_read == m_size)
115+
{
116+
m_next_read = 0;
117+
}
88118
}
89119

90120
/** Pop a number of elements into a user-provided array.
91121
* \exception std::out_of_range If the buffer has less elements than
92122
* requested. */
93123
void pop_many(T* out_array, size_t count)
94124
{
95-
while (count--) pop(*out_array++);
125+
while (count--)
126+
{
127+
pop(*out_array++);
128+
}
96129
}
97130

98131
/** Peek (see without modifying) what is to be read from the buffer if pop()
99132
* was to be called.
100133
* \exception std::out_of_range If the buffer is empty. */
101134
T peek() const
102135
{
103-
if (m_next_read == m_next_write) throw std::out_of_range("peek: circular_buffer is empty");
136+
if (m_next_read == m_next_write)
137+
{
138+
throw std::out_of_range("peek: circular_buffer is empty");
139+
}
104140
return m_data[m_next_read];
105141
}
106142
/** Like peek(), but seeking ahead in the buffer (index=0 means the
@@ -109,7 +145,10 @@ class circular_buffer
109145
* available elements. */
110146
T peek(size_t index) const
111147
{
112-
if (index >= this->size()) throw std::out_of_range("peek: seek out of range");
148+
if (index >= this->size())
149+
{
150+
throw std::out_of_range("peek: seek out of range");
151+
}
113152
return m_data[(m_next_read + index) % m_size];
114153
}
115154

@@ -122,9 +161,15 @@ class circular_buffer
122161
size_t peek_read = m_next_read;
123162
while (count--)
124163
{
125-
if (peek_read == m_next_write) throw std::out_of_range("peek: circular_buffer is empty");
164+
if (peek_read == m_next_write)
165+
{
166+
throw std::out_of_range("peek: circular_buffer is empty");
167+
}
126168
T val = m_data[peek_read++];
127-
if (peek_read == m_size) peek_read = 0;
169+
if (peek_read == m_size)
170+
{
171+
peek_read = 0;
172+
}
128173
*out_array++ = val;
129174
}
130175
}
@@ -135,9 +180,10 @@ class circular_buffer
135180
size_t size() const
136181
{
137182
if (m_next_write >= m_next_read)
183+
{
138184
return m_next_write - m_next_read;
139-
else
140-
return m_next_write + (m_size - m_next_read);
185+
}
186+
return m_next_write + (m_size - m_next_read);
141187
}
142188

143189
/** Return the maximum capacity of the buffer.

0 commit comments

Comments
 (0)