Skip to content

Commit

Permalink
Additional cleaning up and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mauer committed Jan 23, 2024
1 parent c3d6dbd commit 9062e99
Show file tree
Hide file tree
Showing 13 changed files with 657 additions and 691 deletions.
3 changes: 1 addition & 2 deletions lib/common/midi_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

// Standard
#include <mutex>
#include <vector>

namespace xmidictrl {

Expand Down Expand Up @@ -124,7 +123,7 @@ midi_message* midi_logger::message(int in_index)
void midi_logger::add(const std::shared_ptr<midi_message>& in_msg)
{
std::mutex mutex;
std::lock_guard<std::mutex> lock(mutex);
std::scoped_lock lock(mutex);

if (!m_enabled)
return;
Expand Down
26 changes: 13 additions & 13 deletions lib/env/xplane/data_xplane.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------------------------------------------------------
// XMidiCtrl - MIDI Controller plugin for X-Plane
//
// Copyright (c) 2021-2022 Marco Auer
// Copyright (c) 2021-2024 Marco Auer
//
// XMidiCtrl is free software: you can redistribute it and/or modify it under the terms of the
// GNU Affero General Public License as published by the Free Software Foundation, either version 3
Expand Down Expand Up @@ -31,7 +31,7 @@ namespace xmidictrl {
*/
bool data_xplane::check(std::string_view in_name)
{
data_item *item = retrieve_data(in_name);
const auto item = retrieve_data(in_name);

if (item == nullptr)
return false;
Expand All @@ -47,7 +47,7 @@ bool data_xplane::read(text_logger &in_log, std::string_view in_name, std::strin
{
out_value.assign(std::string());

data_item *item = retrieve_data(in_name);
const auto item = retrieve_data(in_name);

if (item == nullptr)
return false;
Expand Down Expand Up @@ -112,7 +112,7 @@ bool data_xplane::read(text_logger &in_log, std::string_view in_name, float &out
{
out_value = 0.0f;

data_item *item = retrieve_data(in_name);
const auto item = retrieve_data(in_name);

if (item == nullptr)
return false;
Expand Down Expand Up @@ -166,7 +166,7 @@ bool data_xplane::read(text_logger &in_log, std::string_view in_name, float &out
*/
bool data_xplane::read(text_logger &in_log, std::string_view in_name, std::vector<float> &out_values)
{
data_item *item = retrieve_data(in_name);
const auto item = retrieve_data(in_name);
out_values = {};

if (item == nullptr)
Expand All @@ -188,7 +188,7 @@ bool data_xplane::read(text_logger &in_log, std::string_view in_name, std::vecto
*/
bool data_xplane::read(text_logger &in_log, std::string_view in_name, std::vector<int> &out_values)
{
data_item *item = retrieve_data(in_name);
const auto item = retrieve_data(in_name);
out_values = {};

if (item == nullptr)
Expand All @@ -210,7 +210,7 @@ bool data_xplane::read(text_logger &in_log, std::string_view in_name, std::vecto
*/
bool data_xplane::write(text_logger &in_log, std::string_view in_name, std::string_view in_value)
{
data_item *item = retrieve_data(in_name);
const auto item = retrieve_data(in_name);

if (item == nullptr)
return false;
Expand Down Expand Up @@ -265,7 +265,7 @@ bool data_xplane::write(text_logger &in_log, std::string_view in_name, std::stri
*/
bool data_xplane::write(text_logger &in_log, std::string_view in_name, float in_value)
{
data_item *item = retrieve_data(in_name);
const auto item = retrieve_data(in_name);

if (item == nullptr)
return false;
Expand Down Expand Up @@ -313,7 +313,7 @@ std::string data_xplane::toggle(text_logger &in_log,
std::string_view in_value_on,
std::string_view in_value_off)
{
data_item *item = retrieve_data(in_name);
const auto item = retrieve_data(in_name);

if (item == nullptr)
return {};
Expand Down Expand Up @@ -364,8 +364,8 @@ data_item *data_xplane::retrieve_data(std::string_view in_name)
dataref_name = dataref_name.substr(0, dataref_name.find('['));
}

if (m_data_cache.count(dataref_name) == 0) {
std::unique_ptr<data_item> item = std::make_unique<data_item>();
if (m_data_cache.contains(dataref_name)) {
auto item = std::make_unique<data_item>();

item->dataref = XPLMFindDataRef(dataref_name.c_str());
item->name = dataref_name;
Expand All @@ -382,7 +382,7 @@ data_item *data_xplane::retrieve_data(std::string_view in_name)
item->size = XPLMGetDatab(item->dataref, nullptr, 0, 0);

// add new dataref to cache
m_data_cache.emplace(dataref_name, std::move(item));
m_data_cache.try_emplace(dataref_name, std::move(item));
}

return m_data_cache.at(dataref_name).get();
Expand All @@ -398,7 +398,7 @@ int data_xplane::get_index(text_logger &in_log, std::string_view in_name)

// is the dataref an array?
if (in_name.back() == ']') {
int pos = static_cast<int>(in_name.find('['));
auto pos = static_cast<int>(in_name.find('['));

// read index
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/map/map_in/map_in_drf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ std::string map_in_drf::build_mapping_text(bool in_short)

map_str.append("Values = [");

for (auto& value: m_values) map_str.append(" '" + value + "', ");
for (const auto& value: m_values) map_str.append(" '" + value + "', ");

map_str.append("]" + sep_str);

Expand Down
2 changes: 1 addition & 1 deletion lib/map/map_in/map_in_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void map_in_label::read_label(text_logger& in_log, toml::value& in_data, toml::v
for (auto value: values) {
std::string value_id = toml_utils::read_string(in_log, value, CFG_KEY_VALUE);
std::string value_text = toml_utils::read_string(in_log, value, CFG_KEY_TEXT);
m_label->values.emplace(value_id, value_text);
m_label->values.try_emplace(value_id, value_text);
}
} else {
in_log.error_line(in_data.location().line(), "Error reading mapping");
Expand Down
Loading

0 comments on commit 9062e99

Please sign in to comment.