From e659e4b33defc709fe3129b4a6420deaef67e6b4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 12 May 2023 09:15:44 -0400 Subject: Replace macro with typed constant --- src/Configuration.cpp | 11 ++++------- src/Configuration.hpp | 10 +++++----- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 7bc2b20..5edbbf1 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -22,11 +22,8 @@ namespace patchage { -static const char* const port_type_names[N_PORT_TYPES] = {"JACK_AUDIO", - "JACK_MIDI", - "ALSA_MIDI", - "JACK_OSC", - "JACK_CV"}; +static const char* const port_type_names[Configuration::n_port_types] = + {"JACK_AUDIO", "JACK_MIDI", "ALSA_MIDI", "JACK_OSC", "JACK_CV"}; Configuration::Configuration(std::function on_change) : _on_change(std::move(on_change)) @@ -246,7 +243,7 @@ Configuration::load() file >> std::dec >> std::nouppercase; bool found = false; - for (int i = 0; i < N_PORT_TYPES; ++i) { + for (unsigned i = 0U; i < n_port_types; ++i) { if (type_name == port_type_names[i]) { _port_colors[i] = rgba; found = true; @@ -343,7 +340,7 @@ Configuration::save() file << "human_names " << get() << std::endl; file << std::hex << std::uppercase; - for (int i = 0; i < N_PORT_TYPES; ++i) { + for (unsigned i = 0U; i < n_port_types; ++i) { if (_port_colors[i] != _default_port_colors[i]) { file << "port_color " << port_type_names[i] << " " << _port_colors[i] << std::endl; diff --git a/src/Configuration.hpp b/src/Configuration.hpp index 7837cd0..7b031b5 100644 --- a/src/Configuration.hpp +++ b/src/Configuration.hpp @@ -16,13 +16,13 @@ #include #include -#define N_PORT_TYPES 5 - namespace patchage { class Configuration { public: + static constexpr unsigned n_port_types = 5U; + explicit Configuration(std::function on_change); void load(); @@ -101,7 +101,7 @@ public: visitor(std::get(_settings)); visitor(std::get(_settings)); - for (auto i = 0u; i < N_PORT_TYPES; ++i) { + for (auto i = 0u; i < n_port_types; ++i) { visitor(setting::PortColor{static_cast(i), _port_colors[i]}); } } @@ -120,8 +120,8 @@ private: std::map _module_settings; - uint32_t _default_port_colors[N_PORT_TYPES] = {}; - uint32_t _port_colors[N_PORT_TYPES] = {}; + uint32_t _default_port_colors[n_port_types] = {}; + uint32_t _port_colors[n_port_types] = {}; using Settings = std::tuple