diff options
Diffstat (limited to 'src/client/ClientStore.cpp')
-rw-r--r-- | src/client/ClientStore.cpp | 81 |
1 files changed, 39 insertions, 42 deletions
diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp index d8238c8a..7cfd439d 100644 --- a/src/client/ClientStore.cpp +++ b/src/client/ClientStore.cpp @@ -19,7 +19,6 @@ #include "ingen/Atom.hpp" #include "ingen/Forge.hpp" #include "ingen/Log.hpp" -#include "ingen/Node.hpp" #include "ingen/Properties.hpp" #include "ingen/Resource.hpp" #include "ingen/URIs.hpp" @@ -33,7 +32,6 @@ #include "ingen/paths.hpp" #include "raul/Path.hpp" -#include <boost/variant/apply_visitor.hpp> #include <sigc++/functors/mem_fun.h> #include <cassert> @@ -41,9 +39,9 @@ #include <memory> #include <string> #include <utility> +#include <variant> -namespace ingen { -namespace client { +namespace ingen::client { ClientStore::ClientStore(URIs& uris, Log& log, @@ -76,7 +74,7 @@ ClientStore::add_object(const std::shared_ptr<ObjectModel>& object) std::dynamic_pointer_cast<ObjectModel>(existing->second)->set(object); } else { if (!object->path().is_root()) { - std::shared_ptr<ObjectModel> parent = _object(object->path().parent()); + const std::shared_ptr<ObjectModel> parent = _object(object->path().parent()); if (parent) { assert(object->path().is_child_of(parent->path())); object->set_parent(parent); @@ -103,7 +101,7 @@ std::shared_ptr<ObjectModel> ClientStore::remove_object(const raul::Path& path) { // Find the object, the "top" of the tree to remove - const iterator top = find(path); + const auto top = find(path); if (top == end()) { return nullptr; } @@ -142,7 +140,7 @@ ClientStore::remove_object(const raul::Path& path) std::shared_ptr<PluginModel> ClientStore::_plugin(const URI& uri) { - const Plugins::iterator i = _plugins->find(uri); + const auto i = _plugins->find(uri); return (i == _plugins->end()) ? std::shared_ptr<PluginModel>() : (*i).second; } @@ -152,7 +150,7 @@ ClientStore::_plugin(const Atom& uri) /* FIXME: Should probably be stored with URIs rather than strings, to make this a fast case. */ - const Plugins::iterator i = _plugins->find(URI(_uris.forge.str(uri, false))); + const auto i = _plugins->find(URI(_uris.forge.str(uri, false))); return (i == _plugins->end()) ? std::shared_ptr<PluginModel>() : (*i).second; } @@ -165,15 +163,15 @@ ClientStore::plugin(const URI& uri) const std::shared_ptr<ObjectModel> ClientStore::_object(const raul::Path& path) { - const iterator i = find(path); + const auto i = find(path); if (i == end()) { return nullptr; - } else { - auto model = std::dynamic_pointer_cast<ObjectModel>(i->second); - assert(model); - assert(model->path().is_root() || model->parent()); - return model; } + + auto model = std::dynamic_pointer_cast<ObjectModel>(i->second); + assert(model); + assert(model->path().is_root() || model->parent()); + return model; } std::shared_ptr<const ObjectModel> @@ -187,9 +185,9 @@ ClientStore::_resource(const URI& uri) { if (uri_is_path(uri)) { return _object(uri_to_path(uri)); - } else { - return _plugin(uri); } + + return _plugin(uri); } std::shared_ptr<const Resource> @@ -201,7 +199,7 @@ ClientStore::resource(const URI& uri) const void ClientStore::add_plugin(const std::shared_ptr<PluginModel>& pm) { - std::shared_ptr<PluginModel> existing = _plugin(pm->uri()); + const std::shared_ptr<PluginModel> existing = _plugin(pm->uri()); if (existing) { existing->set(pm); } else { @@ -235,7 +233,7 @@ ClientStore::operator()(const Copy&) void ClientStore::operator()(const Move& msg) { - const iterator top = find(msg.old_path); + const auto top = find(msg.old_path); if (top != end()) { rename(top, msg.new_path); } @@ -244,14 +242,12 @@ ClientStore::operator()(const Move& msg) void ClientStore::message(const Message& msg) { - boost::apply_visitor(*this, msg); + std::visit(*this, msg); } void ClientStore::operator()(const Put& msg) { - using Iterator = Properties::const_iterator; - const auto& uri = msg.uri; const auto& properties = msg.properties; @@ -263,12 +259,12 @@ ClientStore::operator()(const Put& msg) is_graph, is_block, is_port, is_output); // Check for specially handled types - const Iterator t = properties.find(_uris.rdf_type); + const auto t = properties.find(_uris.rdf_type); if (t != properties.end()) { const Atom& type(t->second); if (_uris.pset_Preset == type) { - const Iterator p = properties.find(_uris.lv2_appliesTo); - const Iterator l = properties.find(_uris.rdfs_label); + const auto p = properties.find(_uris.lv2_appliesTo); + const auto l = properties.find(_uris.rdfs_label); std::shared_ptr<PluginModel> plug; if (p == properties.end()) { _log.error("Preset <%1%> with no plugin\n", uri.c_str()); @@ -283,10 +279,12 @@ ClientStore::operator()(const Put& msg) plug->add_preset(uri, l->second.ptr<char>()); } return; - } else if (_uris.ingen_Graph == type) { + } + + if (_uris.ingen_Graph == type) { is_graph = true; } else if (_uris.ingen_Internal == type || _uris.lv2_Plugin == type) { - std::shared_ptr<PluginModel> p(new PluginModel(uris(), uri, type, properties)); + const std::shared_ptr<PluginModel> p{new PluginModel(uris(), uri, type, properties)}; add_plugin(p); return; } @@ -310,7 +308,7 @@ ClientStore::operator()(const Put& msg) } if (is_graph) { - std::shared_ptr<GraphModel> model(new GraphModel(uris(), path)); + const std::shared_ptr<GraphModel> model{new GraphModel(uris(), path)}; model->set_properties(properties); add_object(model); } else if (is_block) { @@ -331,23 +329,23 @@ ClientStore::operator()(const Put& msg) add_plugin(plug); } - std::shared_ptr<BlockModel> bm(new BlockModel(uris(), plug, path)); + const std::shared_ptr<BlockModel> bm{new BlockModel(uris(), plug, path)}; bm->set_properties(properties); add_object(bm); } else { _log.warn("Block %1% has no prototype\n", path.c_str()); } } else if (is_port) { - PortModel::Direction pdir = (is_output) + const PortModel::Direction pdir = (is_output) ? PortModel::Direction::OUTPUT : PortModel::Direction::INPUT; - uint32_t index = 0; - const Iterator i = properties.find(_uris.lv2_index); + uint32_t index = 0; + const auto i = properties.find(_uris.lv2_index); if (i != properties.end() && i->second.type() == _uris.forge.Int) { index = i->second.get<int32_t>(); } - std::shared_ptr<PortModel> p(new PortModel(uris(), path, index, pdir)); + const std::shared_ptr<PortModel> p{new PortModel(uris(), path, index, pdir)}; p->set_properties(properties); add_object(p); } else { @@ -371,7 +369,7 @@ ClientStore::operator()(const Delta& msg) const raul::Path path(uri_to_path(uri)); - std::shared_ptr<ObjectModel> obj = _object(path); + const std::shared_ptr<ObjectModel> obj = _object(path); if (obj) { obj->remove_properties(msg.remove); obj->add_properties(msg.add); @@ -392,7 +390,7 @@ ClientStore::operator()(const SetProperty& msg) predicate.c_str(), _uris.forge.str(value, false)); return; } - std::shared_ptr<Resource> subject = _resource(subject_uri); + const std::shared_ptr<Resource> subject = _resource(subject_uri); if (subject) { if (predicate == _uris.ingen_activity) { /* Activity is transient, trigger any live actions (like GUI @@ -402,7 +400,7 @@ ClientStore::operator()(const SetProperty& msg) subject->set_property(predicate, value, msg.ctx); } } else { - std::shared_ptr<PluginModel> plugin = _plugin(subject_uri); + const std::shared_ptr<PluginModel> plugin = _plugin(subject_uri); if (plugin) { plugin->set_property(predicate, value); } else if (predicate != _uris.ingen_activity) { @@ -450,14 +448,14 @@ ClientStore::attempt_connection(const raul::Path& tail_path, auto head = std::dynamic_pointer_cast<PortModel>(_object(head_path)); if (tail && head) { - std::shared_ptr<GraphModel> graph = connection_graph(tail_path, head_path); - std::shared_ptr<ArcModel> arc(new ArcModel(tail, head)); + const std::shared_ptr<GraphModel> graph = connection_graph(tail_path, head_path); + const std::shared_ptr<ArcModel> arc(new ArcModel(tail, head)); graph->add_arc(arc); return true; - } else { - _log.warn("Failed to connect %1% => %2%\n", tail_path, head_path); - return false; } + + _log.warn("Failed to connect %1% => %2%\n", tail_path, head_path); + return false; } void @@ -501,5 +499,4 @@ ClientStore::operator()(const DisconnectAll& msg) } } -} // namespace client -} // namespace ingen +} // namespace ingen::client |