Skip to content

Commit db6688d

Browse files
committed
Apply clang-tidy suggestions
1 parent d4c28ce commit db6688d

24 files changed

+79
-74
lines changed

.clang-tidy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Checks: |
1212
-readability-isolate-declaration,
1313
-readability-function-cognitive-complexity,
1414
bugprone-*,
15-
concurrency-*
15+
-bugprone-easily-swappable-parameters,
16+
concurrency-*,
1617
portability-*
1718
...

src/api_config.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ using namespace lsl;
1414

1515
/// Substitute the "~" character by the full home directory (according to environment variables).
1616
std::string expand_tilde(const std::string &filename) {
17+
// NOLINTBEGIN(concurrency-mt-unsafe)
1718
if (!filename.empty() && filename[0] == '~') {
1819
std::string homedir;
19-
if (getenv("HOME"))
20-
homedir = getenv("HOME");
21-
else if (getenv("USERPROFILE"))
22-
homedir = getenv("USERPROFILE");
20+
if (auto *home = getenv("HOME"))
21+
homedir = home;
22+
else if (auto *home = getenv("USERPROFILE"))
23+
homedir = home;
2324
else if (getenv("HOMEDRIVE") && getenv("HOMEPATH"))
2425
homedir = std::string(getenv("HOMEDRIVE")) + getenv("HOMEPATH");
2526
else {
@@ -30,6 +31,7 @@ std::string expand_tilde(const std::string &filename) {
3031
return homedir + filename.substr(1);
3132
}
3233
return filename;
34+
// NOLINTEND(concurrency-mt-unsafe)
3335
}
3436

3537
/// Parse a set specifier (a string of the form {a, b, c, ...}) into a vector of strings.
@@ -50,8 +52,10 @@ bool file_is_readable(const std::string &filename) {
5052
api_config::api_config() {
5153
// for each config file location under consideration...
5254
std::vector<std::string> filenames;
53-
if (getenv("LSLAPICFG")) {
54-
std::string envcfg(getenv("LSLAPICFG"));
55+
56+
// NOLINTNEXTLINE(concurrency-mt-unsafe)
57+
if (auto cfgpath = getenv("LSLAPICFG")) {
58+
std::string envcfg(cfgpath);
5559
if (!file_is_readable(envcfg))
5660
LOG_F(ERROR, "LSLAPICFG file %s not found", envcfg.c_str());
5761
else

src/api_types.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class stream_outlet_impl;
2121
namespace pugi {
2222
struct xml_node_struct;
2323
}
24-
typedef lsl::resolver_impl *lsl_continuous_resolver;
25-
typedef lsl::stream_info_impl *lsl_streaminfo;
26-
typedef lsl::stream_outlet_impl *lsl_outlet;
27-
typedef lsl::stream_inlet_impl *lsl_inlet;
28-
typedef pugi::xml_node_struct *lsl_xml_ptr;
24+
using lsl_continuous_resolver = lsl::resolver_impl *;
25+
using lsl_streaminfo = lsl::stream_info_impl *;
26+
using lsl_outlet = lsl::stream_outlet_impl *;
27+
using lsl_inlet = lsl::stream_inlet_impl *;
28+
using lsl_xml_ptr = pugi::xml_node_struct *;

src/cancellable_streambuf.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ namespace lsl {
2727
using Protocol = asio::ip::tcp;
2828
using Socket = asio::basic_stream_socket<Protocol, asio::io_context::executor_type>;
2929
/// Iostream streambuf for a socket.
30-
class cancellable_streambuf : public std::streambuf,
31-
private asio::io_context,
32-
private Socket,
33-
public lsl::cancellable_obj {
30+
class cancellable_streambuf final : public std::streambuf,
31+
private asio::io_context,
32+
private Socket,
33+
public lsl::cancellable_obj {
3434
public:
3535
/// Construct a cancellable_streambuf without establishing a connection.
3636
cancellable_streambuf() : io_context(1), Socket(as_context()) { init_buffers(); }
3737

3838
/// Destructor flushes buffered data.
39-
virtual ~cancellable_streambuf() override {
39+
~cancellable_streambuf() override {
4040
// no cancel() can fire after this call
4141
unregister_from_all();
4242
if (pptr() != pbase()) overflow(traits_type::eof());

src/cancellation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class cancellable_obj {
8383
inline void cancellable_registry::cancel_all_registered() {
8484
std::lock_guard<std::recursive_mutex> lock(state_mut_);
8585
std::set<cancellable_obj *> copy(cancellables_);
86-
for (auto obj : copy)
86+
for (auto *obj : copy)
8787
if (cancellables_.find(obj) != cancellables_.end()) obj->cancel();
8888
}
8989

src/data_receiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void data_receiver::data_thread() {
258258

259259
if (data_protocol_version == 100) {
260260
// portable binary archive (parse archive header)
261-
inarch.reset(new eos::portable_iarchive(server_stream));
261+
inarch = std::make_unique<eos::portable_iarchive>(server_stream);
262262
// receive stream_info message from server
263263
std::string infomsg;
264264
*inarch >> infomsg;

src/data_receiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class inlet_connection; // Forward declaration
2424
* The background thread terminates only if the data_receiver is destroyed or the underlying
2525
* connection is lost or shut down.
2626
*/
27-
class data_receiver : public cancellable_registry {
27+
class data_receiver final : public cancellable_registry {
2828
public:
2929
/**
3030
* Construct a new data receiver from an info connection.

src/lsl_inlet_c.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,10 @@ LIBLSL_C_API unsigned long lsl_pull_chunk_str(lsl_inlet in, char **data_buffer,
241241
data_buffer[k][tmp[k].size()] = '\0';
242242
}
243243
return result;
244-
} else
245-
return 0;
246-
} LSL_STORE_EXCEPTION_IN(ec)
244+
}
245+
return 0;
246+
}
247+
LSL_STORE_EXCEPTION_IN(ec)
247248
return 0;
248249
}
249250

@@ -270,9 +271,10 @@ LIBLSL_C_API unsigned long lsl_pull_chunk_buf(lsl_inlet in, char **data_buffer,
270271
data_buffer[k][tmp[k].size()] = '\0';
271272
}
272273
return result;
273-
} else
274-
return 0;
275-
} LSL_STORE_EXCEPTION_IN(ec)
274+
}
275+
return 0;
276+
}
277+
LSL_STORE_EXCEPTION_IN(ec)
276278
return 0;
277279
}
278280

src/portable_archive/portable_archive_exception.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace eos {
3030
const unsigned no_infnan = 64;
3131

3232
// integral type for the archive version
33-
typedef lslboost::archive::library_version_type archive_version_type;
33+
using archive_version_type = lslboost::archive::library_version_type;
3434

3535
// version of the linked lslboost archive library
3636
const archive_version_type archive_version(
@@ -81,8 +81,8 @@ namespace eos {
8181
}
8282

8383
//! override the base class function with our message
84-
const char* what() const noexcept { return msg.c_str(); }
85-
~portable_archive_exception() noexcept {}
84+
const char *what() const noexcept override { return msg.c_str(); }
85+
~portable_archive_exception() noexcept override = default;
8686
};
8787

8888
} // namespace eos

src/portable_archive/portable_iarchive.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ namespace eos {
1818
// forward declaration
1919
class portable_iarchive;
2020

21-
typedef lslboost::archive::basic_binary_iprimitive<
22-
portable_iarchive
23-
, std::istream::char_type
24-
, std::istream::traits_type
25-
> portable_iprimitive;
21+
using portable_iprimitive = lslboost::archive::basic_binary_iprimitive<portable_iarchive,
22+
std::istream::char_type, std::istream::traits_type>;
2623

2724
/**
2825
* \brief Portable binary input archive using little endian format.
@@ -49,7 +46,9 @@ namespace eos {
4946

5047
// workaround for gcc: use a dummy struct
5148
// as additional argument type for overloading
52-
template <int> struct dummy { dummy(int) {}};
49+
template <int> struct dummy {
50+
dummy(int /*unused*/) {}
51+
};
5352

5453
// loads directly from stream
5554
inline signed char load_signed_char()
@@ -208,7 +207,7 @@ namespace eos {
208207
typename std::enable_if<std::is_floating_point<T>::value >::type
209208
load(T & t, dummy<3> = 0)
210209
{
211-
typedef typename fp::detail::fp_traits<T>::type traits;
210+
using traits = typename fp::detail::fp_traits<T>::type;
212211

213212
// if you end here there are three possibilities:
214213
// 1. you're serializing a long double which is not portable

0 commit comments

Comments
 (0)