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* ref,
void (*fn)(void* ref, const std::string& from, const std::string& to)
std::function<void(const std::string& from, const std::string& to)> fn
)
{
for (auto& a: _property_to_properties) {
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; }
void property_associations(
void* ref,
void (*fn)(void* ref, const std::string& from, const std::string& to)
std::function<void(const std::string& from, const std::string& to)> fn
);
private:

View file

@ -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<void(const std::string& from, const std::string& to)> fn
)
{
return _fdm->property_associations(ref, fn);
return _fdm->property_associations(fn);
}
void YASim::report()

View file

@ -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<void(const std::string& from, const std::string& to)> fn
) override;
private:

View file

@ -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<void(const std::string& from, const std::string& to)> fn
)
{
/* Do nothing by default. */

View file

@ -74,6 +74,7 @@
#include <cmath>
#include <functional>
#include <simgear/compiler.h>
#include <simgear/constants.h>
@ -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<void(const std::string& from, const std::string& to)> fn
);
// Positions

View file

@ -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();
}
}