1
0
Fork 0

Highlighting: changed FGInterface::property_associations() callback to use std::function.

Replaces previous function pointer plus void*.
This commit is contained in:
Julian Smith 2021-11-20 16:27:51 +00:00
parent 0c6f4983dc
commit 3b5bd7a5ff
7 changed files with 19 additions and 24 deletions

View file

@ -63,13 +63,12 @@ FGFDM::~FGFDM()
} }
void FGFDM::property_associations( void FGFDM::property_associations(
void* ref, std::function<void(const std::string& from, const std::string& to)> fn
void (*fn)(void* ref, const std::string& from, const std::string& to)
) )
{ {
for (auto& a: _property_to_properties) { for (auto& a: _property_to_properties) {
for (auto& b: a.second) { for (auto& b: a.second) {
fn(ref, a.first, b); fn(a.first, b);
} }
} }
} }

View file

@ -37,8 +37,7 @@ public:
float getVehicleRadius(void) const { return _vehicle_radius; } float getVehicleRadius(void) const { return _vehicle_radius; }
void property_associations( void property_associations(
void* ref, std::function<void(const std::string& from, const std::string& to)> fn
void (*fn)(void* ref, const std::string& from, const std::string& to)
); );
private: private:

View file

@ -55,11 +55,10 @@ YASim::~YASim()
} }
void YASim::property_associations( void YASim::property_associations(
void* ref, std::function<void(const std::string& from, const std::string& to)> fn
void (*fn)(void* ref, const std::string& from, const std::string& to)
) )
{ {
return _fdm->property_associations(ref, fn); return _fdm->property_associations(fn);
} }
void YASim::report() void YASim::report()

View file

@ -22,8 +22,7 @@ public:
static const char* staticSubsystemClassId() { return "yasim"; } static const char* staticSubsystemClassId() { return "yasim"; }
void property_associations( void property_associations(
void* ref, std::function<void(const std::string& from, const std::string& to)> fn
void (*fn)(void* ref, const std::string& from, const std::string& to)
) override; ) override;
private: private:

View file

@ -234,8 +234,7 @@ FGInterface::common_init ()
} }
void FGInterface::property_associations( void FGInterface::property_associations(
void* ref, std::function<void(const std::string& from, const std::string& to)> fn
void (*fn)(void* ref, const std::string& from, const std::string& to)
) )
{ {
/* Do nothing by default. */ /* Do nothing by default. */

View file

@ -74,6 +74,7 @@
#include <cmath> #include <cmath>
#include <functional>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/constants.h> #include <simgear/constants.h>
@ -440,12 +441,11 @@ public:
//perform initializion that is common to all FDM's //perform initializion that is common to all FDM's
void common_init(); void common_init();
// Makes possibly multiple calls of fn(ref, ...) with pairs of property // Makes possibly multiple calls of fn() with pairs of property paths that
// paths that are associated in the FDM. Default implementation does // are associated in the FDM. Default implementation does nothing. Used by
// nothing. Used by the Highlight subsystem. // the Highlight subsystem.
virtual void property_associations( virtual void property_associations(
void* ref, std::function<void(const std::string& from, const std::string& to)> fn
void (*fn)(void* ref, const std::string& from, const std::string& to)
); );
// Positions // Positions

View file

@ -323,12 +323,6 @@ struct FdmInitialisedListener : SGPropertyChangeListener
{ {
m_fdm_initialised->addChangeListener(this, true /*initial*/); 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 void valueChanged(SGPropertyNode* node) override
{ {
if (m_fdm_initialised->getBoolValue()) if (m_fdm_initialised->getBoolValue())
@ -338,7 +332,13 @@ struct FdmInitialisedListener : SGPropertyChangeListener
FDMShell* fdmshell = (FDMShell*) globals->get_subsystem("flight"); FDMShell* fdmshell = (FDMShell*) globals->get_subsystem("flight");
FGInterface* fginterface = fdmshell->getInterface(); FGInterface* fginterface = fdmshell->getInterface();
assert(fginterface); 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(); s_fdm_initialised_listener.reset();
} }
} }