From 3beb1e98af007f856539a6109b6a87e888bd5ac3 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 15 Jun 2020 19:23:59 +0200 Subject: [PATCH] Use lambdas if possible. Fine tuning in CMake scripts --- src/core/libs/CMakeLists.txt | 9 ++++++++- src/core/receiver/CMakeLists.txt | 16 +++++++++++++++- src/core/receiver/tcp_cmd_interface.cc | 26 ++++++++++++++++++-------- src/core/receiver/tcp_cmd_interface.h | 2 +- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/core/libs/CMakeLists.txt b/src/core/libs/CMakeLists.txt index 933654aa8..70ee5bc76 100644 --- a/src/core/libs/CMakeLists.txt +++ b/src/core/libs/CMakeLists.txt @@ -62,8 +62,9 @@ endif() target_link_libraries(core_libs PUBLIC - Boost::headers + Gnuradio::blocks Gnuradio::runtime + Gnuradio::pmt core_libs_supl core_system_parameters pvt_libs @@ -74,6 +75,12 @@ target_link_libraries(core_libs Pugixml::pugixml ) +if(USE_GENERIC_LAMBDAS AND NOT GNURADIO_USES_STD_POINTERS) + target_link_libraries(core_libs PUBLIC Boost::headers) +else() + target_link_libraries(core_libs PRIVATE Boost::headers) +endif() + if(GNURADIO_USES_STD_POINTERS) target_compile_definitions(core_libs PUBLIC -DGNURADIO_USES_STD_POINTERS=1 diff --git a/src/core/receiver/CMakeLists.txt b/src/core/receiver/CMakeLists.txt index e830b3471..402da9a1d 100644 --- a/src/core/receiver/CMakeLists.txt +++ b/src/core/receiver/CMakeLists.txt @@ -136,7 +136,6 @@ endif() target_link_libraries(core_receiver PUBLIC core_libs - Gnuradio::runtime PRIVATE core_monitor signal_source_adapters @@ -162,6 +161,21 @@ if(ENABLE_ARMA_NO_DEBUG) ) endif() +if(USE_GENERIC_LAMBDAS) + set(has_generic_lambdas HAS_GENERIC_LAMBDA=1) + set(no_has_generic_lambdas HAS_GENERIC_LAMBDA=0) + target_compile_definitions(core_receiver + PRIVATE + "$<$:${has_generic_lambdas}>" + "$<$>:${no_has_generic_lambdas}>" + ) +else() + target_compile_definitions(core_receiver + PRIVATE + -DHAS_GENERIC_LAMBDA=0 + ) +endif() + # Fix for Boost Asio < 1.70 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") if((CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (Boost_VERSION_STRING VERSION_LESS 1.70.0)) diff --git a/src/core/receiver/tcp_cmd_interface.cc b/src/core/receiver/tcp_cmd_interface.cc index 98ae522f3..e39c192c4 100644 --- a/src/core/receiver/tcp_cmd_interface.cc +++ b/src/core/receiver/tcp_cmd_interface.cc @@ -48,13 +48,23 @@ TcpCmdInterface::TcpCmdInterface() void TcpCmdInterface::register_functions() { - functions["status"] = std::bind(&TcpCmdInterface::status, this, std::placeholders::_1); // NOLINT(modernize-avoid-bind) - functions["standby"] = std::bind(&TcpCmdInterface::standby, this, std::placeholders::_1); // NOLINT(modernize-avoid-bind) - functions["reset"] = std::bind(&TcpCmdInterface::reset, this, std::placeholders::_1); // NOLINT(modernize-avoid-bind) - functions["hotstart"] = std::bind(&TcpCmdInterface::hotstart, this, std::placeholders::_1); // NOLINT(modernize-avoid-bind) - functions["warmstart"] = std::bind(&TcpCmdInterface::warmstart, this, std::placeholders::_1); // NOLINT(modernize-avoid-bind) - functions["coldstart"] = std::bind(&TcpCmdInterface::coldstart, this, std::placeholders::_1); // NOLINT(modernize-avoid-bind) - functions["set_ch_satellite"] = std::bind(&TcpCmdInterface::set_ch_satellite, this, std::placeholders::_1); // NOLINT(modernize-avoid-bind) +#if HAS_GENERIC_LAMBDA + functions["status"] = [&](auto &s) { return TcpCmdInterface::status(s); }; + functions["standby"] = [&](auto &s) { return TcpCmdInterface::standby(s); }; + functions["reset"] = [&](auto &s) { return TcpCmdInterface::reset(s); }; + functions["hotstart"] = [&](auto &s) { return TcpCmdInterface::hotstart(s); }; + functions["warmstart"] = [&](auto &s) { return TcpCmdInterface::warmstart(s); }; + functions["coldstart"] = [&](auto &s) { return TcpCmdInterface::coldstart(s); }; + functions["set_ch_satellite"] = [&](auto &s) { return TcpCmdInterface::set_ch_satellite(s); }; +#else + functions["status"] = std::bind(&TcpCmdInterface::status, this, std::placeholders::_1); + functions["standby"] = std::bind(&TcpCmdInterface::standby, this, std::placeholders::_1); + functions["reset"] = std::bind(&TcpCmdInterface::reset, this, std::placeholders::_1); + functions["hotstart"] = std::bind(&TcpCmdInterface::hotstart, this, std::placeholders::_1); + functions["warmstart"] = std::bind(&TcpCmdInterface::warmstart, this, std::placeholders::_1); + functions["coldstart"] = std::bind(&TcpCmdInterface::coldstart, this, std::placeholders::_1); + functions["set_ch_satellite"] = std::bind(&TcpCmdInterface::set_ch_satellite, this, std::placeholders::_1); +#endif } @@ -64,7 +74,7 @@ void TcpCmdInterface::set_pvt(std::shared_ptr PVT_sptr) } -time_t TcpCmdInterface::get_utc_time() +time_t TcpCmdInterface::get_utc_time() const { return receiver_utc_time_; } diff --git a/src/core/receiver/tcp_cmd_interface.h b/src/core/receiver/tcp_cmd_interface.h index e4acb8c85..e1f62b73f 100644 --- a/src/core/receiver/tcp_cmd_interface.h +++ b/src/core/receiver/tcp_cmd_interface.h @@ -45,7 +45,7 @@ public: /*! * \brief gets the UTC time parsed from the last TC command issued */ - time_t get_utc_time(); + time_t get_utc_time() const; /*! * \brief gets the Latitude, Longitude and Altitude vector from the last TC command issued