1
0
Fork 0

No need to keep two maps: it's enough the have one PropertyList (vector) and a map

This commit is contained in:
Erik Hofman 2021-04-09 14:43:20 +02:00
parent 162f5f317d
commit c88c47e1b5
2 changed files with 31 additions and 17 deletions

View file

@ -25,6 +25,7 @@
# include <config.h> # include <config.h>
#endif #endif
#include <simgear/structure/exception.hxx>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/io/iochannel.hxx> #include <simgear/io/iochannel.hxx>
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
@ -80,29 +81,42 @@ bool FGDDSProps::process() {
{ {
if (prop.id == FG_DDS_PROP_REQUEST) if (prop.id == FG_DDS_PROP_REQUEST)
{ {
auto it = by_path.find(prop.val._u.String); if (prop.type == FG_DDS_STRING)
if (it == by_path.end())
{ {
SGPropertyNode_ptr props = globals->get_props(); const char *path = prop.val._u.String;
SGPropertyNode_ptr p = props->getNode(prop.val._u.String); auto it = path_list.find(path);
if (p) if (it == path_list.end())
{ {
prop.id = by_id.size(); SGPropertyNode_ptr props = globals->get_props();
by_id[prop.id] = p; SGPropertyNode_ptr p = props->getNode(path);
by_path[prop.val._u.String] = p; if (p)
{
prop.id = prop_list.size();
try {
prop_list.push_back(p);
path_list[prop.val._u.String] = prop.id;
} catch (sg_exception&) {
SG_LOG(SG_IO, SG_ALERT, "out of memory");
}
}
setProp(prop, p);
}
else
{
prop.id = std::distance(path_list.begin(), it);
setProp(prop, prop_list[prop.id]);
} }
setProp(prop, p);
} }
else else
{ {
prop.id = std::distance(by_path.begin(), it); SG_LOG(SG_IO, SG_DEBUG, "Recieved a mangled DDS sample.");
setProp(prop, it->second); setProp(prop, nullptr);
} }
} }
else else {
{ setProp(prop, prop_list[prop.id]);
SGPropertyNode_ptr p = by_id[prop.id];
setProp(prop, p);
} }
// send the response. // send the response.

View file

@ -36,8 +36,8 @@
class FGDDSProps : public FGProtocol { class FGDDSProps : public FGProtocol {
std::map<uint32_t,SGPropertyNode_ptr> by_id; simgear::PropertyList prop_list;
std::map<std::string,SGPropertyNode_ptr> by_path; std::map<std::string,uint32_t> path_list;
static void setProp(FG_DDS_PROP& prop, SGPropertyNode_ptr p); static void setProp(FG_DDS_PROP& prop, SGPropertyNode_ptr p);