1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

cfg: simplify get_nodes

This commit is contained in:
Megamouse 2021-03-20 18:06:45 +01:00 committed by Ivan
parent cb9e7358d2
commit 2c05e9719d
5 changed files with 18 additions and 18 deletions

View File

@ -22,15 +22,15 @@ namespace cfg
_base::_base(type _type, node* owner, const std::string& name, bool dynamic) _base::_base(type _type, node* owner, const std::string& name, bool dynamic)
: m_type(_type), m_dynamic(dynamic), m_name(name) : m_type(_type), m_dynamic(dynamic), m_name(name)
{ {
for (const auto& pair : owner->m_nodes) for (const auto& node : owner->m_nodes)
{ {
if (pair.first == name) if (node->get_name() == name)
{ {
cfg_log.fatal("Node already exists: %s", name); cfg_log.fatal("Node already exists: %s", name);
} }
} }
owner->m_nodes.emplace_back(name, this); owner->m_nodes.emplace_back(this);
} }
bool _base::from_string(const std::string&, bool) bool _base::from_string(const std::string&, bool)
@ -218,11 +218,11 @@ void cfg::encode(YAML::Emitter& out, const cfg::_base& rhs)
case type::node: case type::node:
{ {
out << YAML::BeginMap; out << YAML::BeginMap;
for (const auto& np : static_cast<const node&>(rhs).get_nodes()) for (const auto& node : static_cast<const node&>(rhs).get_nodes())
{ {
out << YAML::Key << np.first; out << YAML::Key << node->get_name();
out << YAML::Value; out << YAML::Value;
encode(out, *np.second); encode(out, *node);
} }
out << YAML::EndMap; out << YAML::EndMap;
@ -281,11 +281,11 @@ void cfg::decode(const YAML::Node& data, cfg::_base& rhs, bool dynamic)
if (!pair.first.IsScalar()) continue; if (!pair.first.IsScalar()) continue;
// Find the key among existing nodes // Find the key among existing nodes
for (const auto& _pair : static_cast<node&>(rhs).get_nodes()) for (const auto& node : static_cast<node&>(rhs).get_nodes())
{ {
if (_pair.first == pair.first.Scalar()) if (node->get_name() == pair.first.Scalar())
{ {
decode(pair.second, *_pair.second, dynamic); decode(pair.second, *node, dynamic);
} }
} }
} }
@ -366,7 +366,7 @@ void cfg::node::from_default()
{ {
for (auto& node : m_nodes) for (auto& node : m_nodes)
{ {
node.second->from_default(); node->from_default();
} }
} }

View File

@ -98,7 +98,7 @@ namespace cfg
// Config tree node which contains another nodes // Config tree node which contains another nodes
class node : public _base class node : public _base
{ {
std::vector<std::pair<std::string, _base*>> m_nodes; std::vector<_base*> m_nodes;
friend class _base; friend class _base;

View File

@ -105,9 +105,9 @@ bool evdev_joystick_handler::Init()
for (const auto& node : m_pos_axis_config.get_nodes()) for (const auto& node : m_pos_axis_config.get_nodes())
{ {
if (*static_cast<cfg::_bool*>(node.second)) if (*static_cast<cfg::_bool*>(node))
{ {
const auto name = node.first; const auto name = node->get_name();
const int code = libevdev_event_code_from_name(EV_ABS, name.c_str()); const int code = libevdev_event_code_from_name(EV_ABS, name.c_str());
if (code < 0) if (code < 0)
evdev_log.error("Failed to read axis name from %s. [code = %d] [name = %s]", m_pos_axis_config.cfg_name, code, name); evdev_log.error("Failed to read axis name from %s. [code = %d] [name = %s]", m_pos_axis_config.cfg_name, code, name);

View File

@ -12,11 +12,11 @@ namespace cfg_adapter
{ {
if (root.get_type() == cfg::type::node) if (root.get_type() == cfg::type::node)
{ {
for (const auto& pair : static_cast<cfg::node&>(root).get_nodes()) for (const auto& node : static_cast<cfg::node&>(root).get_nodes())
{ {
if (pair.first == name) if (node->get_name() == name)
{ {
return *pair.second; return *node;
} }
} }
} }

View File

@ -196,9 +196,9 @@ void emu_settings::ValidateSettings()
if (cfg_base && cfg_base->get_type() == cfg::type::node) if (cfg_base && cfg_base->get_type() == cfg::type::node)
{ {
for (const auto& [name, node] : static_cast<const cfg::node*>(cfg_base)->get_nodes()) for (const auto& node : static_cast<const cfg::node*>(cfg_base)->get_nodes())
{ {
if (name == keys[level]) if (node->get_name() == keys[level])
{ {
cfg_node = node; cfg_node = node;
break; break;