From 34a5ca666a2dceb9eacc1087acb7bebf2f7e2758 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 27 Nov 2020 17:57:38 +0100 Subject: Use auto where appropriate --- .clang-tidy | 1 - src/AlsaDriver.cpp | 17 ++++++++--------- src/Configuration.cpp | 8 +++----- src/JackDriver.cpp | 27 +++++++++++++-------------- src/Legend.hpp | 4 ++-- src/Patchage.cpp | 30 +++++++++++++++--------------- src/PatchageCanvas.cpp | 32 ++++++++++++++++---------------- src/PatchageModule.cpp | 2 +- src/PatchagePort.hpp | 2 +- 9 files changed, 59 insertions(+), 64 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index ec4bf4a..100a2a7 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,7 +11,6 @@ Checks: > -*-special-member-functions, -*-unused-macros, -*-uppercase-literal-suffix, - -*-use-auto, -*-use-emplace, -*-use-equals-default, -*-use-override, diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index f34fb1b..4ce4ae4 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -304,14 +304,13 @@ AlsaDriver::create_port(PatchageModule& parent, bool is_input, snd_seq_addr_t addr) { - PatchagePort* ret = - new PatchagePort(parent, - ALSA_MIDI, - name, - "", - is_input, - _app->conf()->get_port_color(ALSA_MIDI), - _app->show_human_names()); + auto* ret = new PatchagePort(parent, + ALSA_MIDI, + name, + "", + is_input, + _app->conf()->get_port_color(ALSA_MIDI), + _app->show_human_names()); dynamic_cast(parent.canvas()) ->index_port(PortID(addr, is_input), ret); @@ -506,7 +505,7 @@ AlsaDriver::create_refresh_port() void* AlsaDriver::refresh_main(void* me) { - AlsaDriver* ad = (AlsaDriver*)me; + auto* ad = (AlsaDriver*)me; ad->_refresh_main(); return nullptr; } diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 0c86e3e..11c0d1a 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -1,5 +1,5 @@ /* This file is part of Patchage. - * Copyright 2007-2014 David Robillard + * Copyright 2007-2020 David Robillard * * Patchage is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free @@ -87,8 +87,7 @@ Configuration::set_module_location(const std::string& name, ModuleType type, Coord loc) { - std::map::iterator i = - _module_settings.find(name); + auto i = _module_settings.find(name); if (i == _module_settings.end()) { i = _module_settings .insert( @@ -120,8 +119,7 @@ Configuration::set_module_location(const std::string& name, bool Configuration::get_module_split(const std::string& name, bool default_val) const { - std::map::const_iterator i = - _module_settings.find(name); + auto i = _module_settings.find(name); if (i == _module_settings.end()) { return default_val; } diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index c4a1b6f..6cb4e1f 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -240,15 +240,14 @@ JackDriver::create_port(PatchageModule& parent, jack_port_t* port, PortID id) return nullptr; } - PatchagePort* ret( - new PatchagePort(parent, - port_type, - jack_port_short_name(port), - label, - (jack_port_flags(port) & JackPortIsInput), - _app->conf()->get_port_color(port_type), - _app->show_human_names(), - order)); + auto* ret = new PatchagePort(parent, + port_type, + jack_port_short_name(port), + label, + (jack_port_flags(port) & JackPortIsInput), + _app->conf()->get_port_color(port_type), + _app->show_human_names(), + order); if (id.type != PortID::NULL_PORT_ID) { dynamic_cast(parent.canvas())->index_port(id, ret); @@ -459,7 +458,7 @@ JackDriver::jack_client_registration_cb(const char* name, int registered, void* jack_driver) { - JackDriver* me = reinterpret_cast(jack_driver); + auto* me = reinterpret_cast(jack_driver); assert(me->_client); if (registered) { @@ -475,7 +474,7 @@ JackDriver::jack_port_registration_cb(jack_port_id_t port_id, int registered, void* jack_driver) { - JackDriver* me = reinterpret_cast(jack_driver); + auto* me = reinterpret_cast(jack_driver); assert(me->_client); if (registered) { @@ -492,7 +491,7 @@ JackDriver::jack_port_connect_cb(jack_port_id_t src, int connect, void* jack_driver) { - JackDriver* me = reinterpret_cast(jack_driver); + auto* me = reinterpret_cast(jack_driver); assert(me->_client); if (connect) { @@ -505,7 +504,7 @@ JackDriver::jack_port_connect_cb(jack_port_id_t src, int JackDriver::jack_xrun_cb(void* jack_driver) { - JackDriver* me = reinterpret_cast(jack_driver); + auto* me = reinterpret_cast(jack_driver); assert(me->_client); ++me->_xruns; @@ -520,7 +519,7 @@ void JackDriver::jack_shutdown_cb(void* jack_driver) { assert(jack_driver); - JackDriver* me = reinterpret_cast(jack_driver); + auto* me = reinterpret_cast(jack_driver); me->_app->info_msg("Jack: Shutdown."); Glib::Mutex::Lock lock(me->_shutdown_mutex); me->_client = nullptr; diff --git a/src/Legend.hpp b/src/Legend.hpp index 03d1e5b..b9e6b23 100644 --- a/src/Legend.hpp +++ b/src/Legend.hpp @@ -46,8 +46,8 @@ public: col.set_rgb(((rgba >> 24) & 0xFF) * 0x100, ((rgba >> 16) & 0xFF) * 0x100, ((rgba >> 8) & 0xFF) * 0x100); - Gtk::HBox* box = new Gtk::HBox(); - Gtk::ColorButton* but = new Gtk::ColorButton(col); + auto* box = new Gtk::HBox(); + auto* but = new Gtk::ColorButton(col); but->set_use_alpha(false); but->signal_color_set().connect(sigc::bind( sigc::mem_fun(this, &Legend::on_color_set), id, label, but)); diff --git a/src/Patchage.cpp b/src/Patchage.cpp index 23498e6..516f490 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -87,8 +87,8 @@ configure_cb(GtkWindow* parentWindow, GdkEvent* event, gpointer data) static int port_order(const GanvPort* a, const GanvPort* b, void* data) { - const PatchagePort* pa = dynamic_cast(Glib::wrap(a)); - const PatchagePort* pb = dynamic_cast(Glib::wrap(b)); + const auto* pa = dynamic_cast(Glib::wrap(a)); + const auto* pb = dynamic_cast(Glib::wrap(b)); if (pa && pb) { if (pa->order() && pb->order()) { return *pa->order() - *pb->order(); @@ -605,8 +605,8 @@ static void load_module_location(GanvNode* node, void* data) { if (GANV_IS_MODULE(node)) { - Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node)); - PatchageModule* pmod = dynamic_cast(gmod); + Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node)); + auto* pmod = dynamic_cast(gmod); if (pmod) { pmod->load_location(); } @@ -817,11 +817,11 @@ update_labels(GanvNode* node, void* data) { const bool human_names = *(const bool*)data; if (GANV_IS_MODULE(node)) { - Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node)); - PatchageModule* pmod = dynamic_cast(gmod); + Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node)); + auto* pmod = dynamic_cast(gmod); if (pmod) { for (Ganv::Port* gport : *gmod) { - PatchagePort* pport = dynamic_cast(gport); + auto* pport = dynamic_cast(gport); if (pport) { pport->show_human_name(human_names); } @@ -915,19 +915,19 @@ highlight_color(guint c, guint delta) static void update_port_colors(GanvNode* node, void* data) { - Patchage* patchage = (Patchage*)data; + auto* patchage = (Patchage*)data; if (!GANV_IS_MODULE(node)) { return; } - Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node)); - PatchageModule* pmod = dynamic_cast(gmod); + Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node)); + auto* pmod = dynamic_cast(gmod); if (!pmod) { return; } for (Ganv::Port* p : *pmod) { - PatchagePort* port = dynamic_cast(p); + auto* port = dynamic_cast(p); if (port) { const uint32_t rgba = patchage->conf()->get_port_color(port->type()); @@ -940,10 +940,10 @@ update_port_colors(GanvNode* node, void* data) static void update_edge_color(GanvEdge* edge, void* data) { - Patchage* patchage = (Patchage*)data; + auto* patchage = (Patchage*)data; Ganv::Edge* edgemm = Glib::wrap(edge); - PatchagePort* tail = dynamic_cast((edgemm)->get_tail()); + auto* tail = dynamic_cast((edgemm)->get_tail()); if (tail) { edgemm->set_color(patchage->conf()->get_port_color(tail->type())); } @@ -1008,8 +1008,8 @@ Patchage::on_export_image() dialog.add_filter(filt); } - Gtk::CheckButton* bg_but = new Gtk::CheckButton("Draw _Background", true); - Gtk::Alignment* extra = new Gtk::Alignment(1.0, 0.5, 0.0, 0.0); + auto* bg_but = new Gtk::CheckButton("Draw _Background", true); + auto* extra = new Gtk::Alignment(1.0, 0.5, 0.0, 0.0); bg_but->set_active(true); extra->add(*Gtk::manage(bg_but)); extra->show_all(); diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index 0e5fef0..67668b3 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -71,7 +71,7 @@ PatchageCanvas::find_module(const std::string& name, ModuleType type) void PatchageCanvas::remove_module(const std::string& name) { - ModuleIndex::iterator i = _module_index.find(name); + auto i = _module_index.find(name); while (i != _module_index.end()) { PatchageModule* mod = i->second; _module_index.erase(i); @@ -85,7 +85,7 @@ PatchageCanvas::find_port(const PortID& id) { PatchagePort* pp = nullptr; - PortIndex::iterator i = _port_index.find(id); + auto i = _port_index.find(id); if (i != _port_index.end()) { assert(i->second->get_module()); return i->second; @@ -141,8 +141,8 @@ struct RemovePortsData static void delete_port_if_matches(GanvPort* port, void* cdata) { - RemovePortsData* data = (RemovePortsData*)cdata; - PatchagePort* pport = dynamic_cast(Glib::wrap(port)); + auto* data = (RemovePortsData*)cdata; + auto* pport = dynamic_cast(Glib::wrap(port)); if (pport && data->pred(pport)) { delete pport; } @@ -155,13 +155,13 @@ remove_ports_matching(GanvNode* node, void* cdata) return; } - Ganv::Module* cmodule = Glib::wrap(GANV_MODULE(node)); - PatchageModule* pmodule = dynamic_cast(cmodule); + Ganv::Module* cmodule = Glib::wrap(GANV_MODULE(node)); + auto* pmodule = dynamic_cast(cmodule); if (!pmodule) { return; } - RemovePortsData* data = (RemovePortsData*)cdata; + auto* data = (RemovePortsData*)cdata; pmodule->for_each_port(delete_port_if_matches, data); @@ -177,8 +177,8 @@ PatchageCanvas::remove_ports(bool (*pred)(const PatchagePort*)) for_each_node(remove_ports_matching, &data); - for (PortIndex::iterator i = _port_index.begin(); i != _port_index.end();) { - PortIndex::iterator next = i; + for (auto i = _port_index.begin(); i != _port_index.end();) { + auto next = i; ++next; if (pred(i->second)) { _port_index.erase(i); @@ -213,8 +213,8 @@ PatchageCanvas::find_port_by_name(const std::string& client_name, void PatchageCanvas::connect(Ganv::Node* port1, Ganv::Node* port2) { - PatchagePort* p1 = dynamic_cast(port1); - PatchagePort* p2 = dynamic_cast(port2); + auto* p1 = dynamic_cast(port1); + auto* p2 = dynamic_cast(port2); if (!p1 || !p2) return; @@ -238,8 +238,8 @@ PatchageCanvas::connect(Ganv::Node* port1, Ganv::Node* port2) void PatchageCanvas::disconnect(Ganv::Node* port1, Ganv::Node* port2) { - PatchagePort* input = dynamic_cast(port1); - PatchagePort* output = dynamic_cast(port2); + auto* input = dynamic_cast(port1); + auto* output = dynamic_cast(port2); if (!input || !output) return; @@ -292,8 +292,8 @@ PatchageCanvas::add_module(const std::string& name, PatchageModule* module) static void disconnect_edge(GanvEdge* edge, void* data) { - PatchageCanvas* canvas = (PatchageCanvas*)data; - Ganv::Edge* edgemm = Glib::wrap(edge); + auto* canvas = (PatchageCanvas*)data; + Ganv::Edge* edgemm = Glib::wrap(edge); canvas->disconnect(edgemm->get_tail(), edgemm->get_head()); } @@ -320,7 +320,7 @@ void PatchageCanvas::remove_module(PatchageModule* module) { // Remove module from cache - for (ModuleIndex::iterator i = _module_index.find(module->get_label()); + for (auto i = _module_index.find(module->get_label()); i != _module_index.end() && i->first == module->get_label(); ++i) { if (i->second == module) { diff --git a/src/PatchageModule.cpp b/src/PatchageModule.cpp index 8d8dfa7..3a802f6 100644 --- a/src/PatchageModule.cpp +++ b/src/PatchageModule.cpp @@ -147,7 +147,7 @@ PatchagePort* PatchageModule::get_port(const std::string& name) { for (Ganv::Port* p : *this) { - PatchagePort* pport = dynamic_cast(p); + auto* pport = dynamic_cast(p); if (pport && pport->name() == name) { return pport; } diff --git a/src/PatchagePort.hpp b/src/PatchagePort.hpp index 5ccc751..f351bae 100644 --- a/src/PatchagePort.hpp +++ b/src/PatchagePort.hpp @@ -62,7 +62,7 @@ public: /** Returns the full name of this port, as "modulename:portname" */ std::string full_name() const { - PatchageModule* pmod = dynamic_cast(get_module()); + auto* pmod = dynamic_cast(get_module()); return std::string(pmod->name()) + ":" + _name; } -- cgit v1.2.1