From 3b5bd7a5ffb74f1cfdc202d0fcc94f2304f81670 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Sat, 20 Nov 2021 16:27:51 +0000 Subject: [PATCH] Highlighting: changed FGInterface::property_associations() callback to use std::function. Replaces previous function pointer plus void*. --- src/FDM/YASim/FGFDM.cpp | 5 ++--- src/FDM/YASim/FGFDM.hpp | 3 +-- src/FDM/YASim/YASim.cxx | 5 ++--- src/FDM/YASim/YASim.hxx | 3 +-- src/FDM/flight.cxx | 3 +-- src/FDM/flight.hxx | 10 +++++----- src/GUI/Highlight.cxx | 14 +++++++------- 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/FDM/YASim/FGFDM.cpp b/src/FDM/YASim/FGFDM.cpp index 244c0a15e..1845399ee 100644 --- a/src/FDM/YASim/FGFDM.cpp +++ b/src/FDM/YASim/FGFDM.cpp @@ -63,13 +63,12 @@ FGFDM::~FGFDM() } void FGFDM::property_associations( - void* ref, - void (*fn)(void* ref, const std::string& from, const std::string& to) + std::function fn ) { for (auto& a: _property_to_properties) { for (auto& b: a.second) { - fn(ref, a.first, b); + fn(a.first, b); } } } diff --git a/src/FDM/YASim/FGFDM.hpp b/src/FDM/YASim/FGFDM.hpp index c9b03f9dd..440cbc03d 100644 --- a/src/FDM/YASim/FGFDM.hpp +++ b/src/FDM/YASim/FGFDM.hpp @@ -37,8 +37,7 @@ public: float getVehicleRadius(void) const { return _vehicle_radius; } void property_associations( - void* ref, - void (*fn)(void* ref, const std::string& from, const std::string& to) + std::function fn ); private: diff --git a/src/FDM/YASim/YASim.cxx b/src/FDM/YASim/YASim.cxx index 6ed51a60c..e1c523ef6 100644 --- a/src/FDM/YASim/YASim.cxx +++ b/src/FDM/YASim/YASim.cxx @@ -55,11 +55,10 @@ YASim::~YASim() } void YASim::property_associations( - void* ref, - void (*fn)(void* ref, const std::string& from, const std::string& to) + std::function fn ) { - return _fdm->property_associations(ref, fn); + return _fdm->property_associations(fn); } void YASim::report() diff --git a/src/FDM/YASim/YASim.hxx b/src/FDM/YASim/YASim.hxx index f51979db0..4a0d83faf 100644 --- a/src/FDM/YASim/YASim.hxx +++ b/src/FDM/YASim/YASim.hxx @@ -22,8 +22,7 @@ public: static const char* staticSubsystemClassId() { return "yasim"; } void property_associations( - void* ref, - void (*fn)(void* ref, const std::string& from, const std::string& to) + std::function fn ) override; private: diff --git a/src/FDM/flight.cxx b/src/FDM/flight.cxx index 3008dcf8f..221ff28c5 100644 --- a/src/FDM/flight.cxx +++ b/src/FDM/flight.cxx @@ -234,8 +234,7 @@ FGInterface::common_init () } void FGInterface::property_associations( - void* ref, - void (*fn)(void* ref, const std::string& from, const std::string& to) + std::function fn ) { /* Do nothing by default. */ diff --git a/src/FDM/flight.hxx b/src/FDM/flight.hxx index a807f28bb..e98d51a7f 100644 --- a/src/FDM/flight.hxx +++ b/src/FDM/flight.hxx @@ -74,6 +74,7 @@ #include +#include #include #include @@ -440,12 +441,11 @@ public: //perform initializion that is common to all FDM's void common_init(); - // Makes possibly multiple calls of fn(ref, ...) with pairs of property - // paths that are associated in the FDM. Default implementation does - // nothing. Used by the Highlight subsystem. + // Makes possibly multiple calls of fn() with pairs of property paths that + // are associated in the FDM. Default implementation does nothing. Used by + // the Highlight subsystem. virtual void property_associations( - void* ref, - void (*fn)(void* ref, const std::string& from, const std::string& to) + std::function fn ); // Positions diff --git a/src/GUI/Highlight.cxx b/src/GUI/Highlight.cxx index 175f55dfb..fef07aa3d 100644 --- a/src/GUI/Highlight.cxx +++ b/src/GUI/Highlight.cxx @@ -323,12 +323,6 @@ struct FdmInitialisedListener : SGPropertyChangeListener { m_fdm_initialised->addChangeListener(this, true /*initial*/); } - static void property_associations_callback(void* ref, const std::string& from, const std::string& to) - { - SG_LOG(SG_GENERAL, SG_DEBUG, "fdm property association: " << from << " => " << to); - Highlight* highlight = (Highlight*) ref; - highlight->addPropertyProperty(from, to); - } void valueChanged(SGPropertyNode* node) override { if (m_fdm_initialised->getBoolValue()) @@ -338,7 +332,13 @@ struct FdmInitialisedListener : SGPropertyChangeListener FDMShell* fdmshell = (FDMShell*) globals->get_subsystem("flight"); FGInterface* fginterface = fdmshell->getInterface(); assert(fginterface); - fginterface->property_associations(highlight, property_associations_callback); + fginterface->property_associations( + [highlight](const std::string& from, const std::string& to) + { + SG_LOG(SG_GENERAL, SG_DEBUG, "fdm property association: " << from << " => " << to); + highlight->addPropertyProperty(from, to); + } + ); s_fdm_initialised_listener.reset(); } }