Skip to content

Commit

Permalink
More clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentHouliston committed Aug 12, 2024
1 parent b959901 commit ff48504
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 55 deletions.
1 change: 1 addition & 0 deletions src/dsl/word/Optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace dsl {

private:
template <typename... T, int... Index>
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) the elements in it are moved
static auto wrap(std::tuple<T...>&& data, util::Sequence<Index...> /*s*/)
-> decltype(std::make_tuple(OptionalWrapper<T>(std::move(std::get<Index>(data)))...)) {
return std::make_tuple(OptionalWrapper<T>(std::move(std::get<Index>(data)))...);
Expand Down
2 changes: 2 additions & 0 deletions src/threading/TaskScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace threading {
// Run the next task
run_task(get_task());
}
// NOLINTNEXTLINE(bugprone-empty-catch) We definitely don't want to crash here
catch (...) {
}
if (pool->pool_descriptor.counts_for_idle) {
Expand Down Expand Up @@ -158,6 +159,7 @@ namespace threading {
}
// This gets thrown some time if between checking if joinable and joining
// the thread is no longer joinable
// NOLINTNEXTLINE(bugprone-empty-catch) just ignore the exception
catch (const std::system_error&) {
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/util/apply.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ namespace util {
/**
* Dereferences and uses the values from the tuple as the arguments for the function call.
*
* This function uses the values which are stored in the tuple and dereferences them as parameters in
* the callback function.
* This function uses the values which are stored in the tuple and dereferences them as parameters in the callback.
* It does this using the generated sequence of integers for this tuple.
* These values are then used to extract the function parameters in order.
*
Expand All @@ -49,7 +48,7 @@ namespace util {

// Get each of the values from the tuple, dereference them and call the function with them
// Also ensure that each value is a const reference
function(Dereferencer<decltype(std::get<S>(args))>(std::get<S>(args))...);
std::forward<Function>(function)(Dereferencer<decltype(std::get<S>(args))>(std::get<S>(args))...);
}

template <typename Function, typename... Arguments>
Expand Down
2 changes: 2 additions & 0 deletions src/util/tuplify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace util {
}

template <typename T>
// Reaching here there is only one element in the tuple and it is moved
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
static inline T detuplify(std::tuple<T>&& tuple) {
return std::move(std::get<0>(tuple));
}
Expand Down
60 changes: 8 additions & 52 deletions tests/networktest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <array>
#include <csignal>
#include <cstdlib>
#include <iostream>
#include <nuclear>

namespace {
Expand All @@ -37,34 +38,11 @@ class TestReactor : public NUClear::Reactor {
TestReactor(std::unique_ptr<NUClear::Environment> environment) : Reactor(std::move(environment)) {

on<Trigger<NetworkJoin>, Sync<TestReactor>>().then([this](const NetworkJoin& join) {
auto state = join.address.address();
std::cout << "Connected To" << std::endl;
std::cout << "\tName: " << join.name << std::endl;

std::array<char, 255> c = {0};

switch (join.address.sock.sa_family) {
case AF_INET:

std::cout << "\tAddress: "
<< ::inet_ntop(join.address.sock.sa_family,
&join.address.ipv4.sin_addr,
c.data(),
c.size())
<< std::endl;
std::cout << "\tPort: " << ntohs(join.address.ipv4.sin_port) << std::endl;
break;

case AF_INET6:
std::cout << "\tAddress: "
<< ::inet_ntop(join.address.sock.sa_family,
&join.address.ipv6.sin6_addr,
c.data(),
c.size())
<< std::endl;
std::cout << "\tPort: " << ntohs(join.address.ipv6.sin6_port) << std::endl;
break;
}

std::cout << "\tName: " << join.name << std::endl;
std::cout << "\tAddress: " << state.first << std::endl;
std::cout << "\tPort: " << state.second << std::endl;

// Send some data to our new friend

Expand All @@ -85,33 +63,11 @@ class TestReactor : public NUClear::Reactor {
});

on<Trigger<NetworkLeave>, Sync<TestReactor>>().then([](const NetworkLeave& leave) {
auto state = leave.address.address();
std::cout << "Disconnected from" << std::endl;
std::cout << "\tName: " << leave.name << std::endl;

std::array<char, 255> c = {0};

switch (leave.address.sock.sa_family) {
case AF_INET:

std::cout << "\tAddress: "
<< ::inet_ntop(leave.address.sock.sa_family,
&leave.address.ipv4.sin_addr,
c.data(),
c.size())
<< std::endl;
std::cout << "\tPort: " << ntohs(leave.address.ipv4.sin_port) << std::endl;
break;

case AF_INET6:
std::cout << "\tAddress: "
<< ::inet_ntop(leave.address.sock.sa_family,
&leave.address.ipv6.sin6_addr,
c.data(),
c.size())
<< std::endl;
std::cout << "\tPort: " << ntohs(leave.address.ipv6.sin6_port) << std::endl;
break;
}
std::cout << "\tAddress: " << state.first << std::endl;
std::cout << "\tPort: " << state.second << std::endl;
});

on<Network<std::string>, Sync<TestReactor>>().then(
Expand Down

0 comments on commit ff48504

Please sign in to comment.