From 9088edb2534a616b757197662d77abcb0291470b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 30 Jul 2012 23:22:44 +0000 Subject: Merge Resource and ResourceImpl, eliminating more virtual inheritance. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4577 a436a847-0d15-0410-975c-d299462d15a1 --- src/Resource.cpp | 218 ++++++++++++++++++++++++++++++++++++++++ src/client/ClientStore.cpp | 4 +- src/client/ObjectModel.cpp | 6 +- src/client/PluginModel.cpp | 6 +- src/gui/PortMenu.cpp | 2 +- src/server/GraphObjectImpl.cpp | 2 +- src/server/GraphObjectImpl.hpp | 14 +-- src/server/PluginImpl.hpp | 5 +- src/server/events/Delta.cpp | 4 +- src/server/events/Delta.hpp | 28 +++--- src/shared/ResourceImpl.cpp | 220 ----------------------------------------- src/shared/wscript | 3 +- 12 files changed, 255 insertions(+), 257 deletions(-) create mode 100644 src/Resource.cpp delete mode 100644 src/shared/ResourceImpl.cpp (limited to 'src') diff --git a/src/Resource.cpp b/src/Resource.cpp new file mode 100644 index 00000000..13959a13 --- /dev/null +++ b/src/Resource.cpp @@ -0,0 +1,218 @@ +/* + This file is part of Ingen. + Copyright 2007-2012 David Robillard + + Ingen 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 of the License, or any later version. + + Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see . +*/ + +#include + +#include "ingen/Resource.hpp" +#include "ingen/shared/URIs.hpp" +#include "raul/Atom.hpp" +#include "raul/log.hpp" + +using namespace std; + +namespace Ingen { + +void +Resource::add_property(const Raul::URI& uri, + const Raul::Atom& value, + Graph ctx) +{ + // Ignore duplicate statements + typedef Resource::Properties::const_iterator iterator; + const std::pair range = _properties.equal_range(uri); + for (iterator i = range.first; i != range.second && i != _properties.end(); ++i) { + if (i->second == value && i->second.context() == ctx) { + return; + } + } + + const Raul::Atom& v = _properties.insert(make_pair(uri, Property(value, ctx)))->second; + on_property(uri, v); +} + +const Raul::Atom& +Resource::set_property(const Raul::URI& uri, + const Raul::Atom& value, + Resource::Graph ctx) +{ + // Erase existing property in this context + for (Properties::iterator i = _properties.find(uri); + (i != _properties.end()) && (i->first == uri);) { + Properties::iterator next = i; + ++next; + if (i->second.context() == ctx) { + _properties.erase(i); + } + i = next; + } + + // Insert new property + const Raul::Atom& v = _properties.insert(make_pair(uri, Property(value, ctx)))->second; + on_property(uri, v); + return v; +} + +void +Resource::remove_property(const Raul::URI& uri, const Raul::Atom& value) +{ + if (value == _uris.wildcard) { + _properties.erase(uri); + } else { + Properties::iterator i = _properties.find(uri); + for (; (i != _properties.end()) && (i->first == uri); ++i) { + if (i->second == value) { + _properties.erase(i); + return; + } + } + } +} + +bool +Resource::has_property(const Raul::URI& uri, const Raul::Atom& value) const +{ + Properties::const_iterator i = _properties.find(uri); + for (; (i != _properties.end()) && (i->first == uri); ++i) { + if (i->second == value) { + return true; + } + } + return false; +} + +const Raul::Atom& +Resource::set_property(const Raul::URI& uri, const Raul::Atom& value) const +{ + return const_cast(this)->set_property(uri, value); +} + +const Raul::Atom& +Resource::get_property(const Raul::URI& uri) const +{ + static const Raul::Atom nil; + Properties::const_iterator i = _properties.find(uri); + return (i != _properties.end()) ? i->second : nil; +} + +bool +Resource::type(const Shared::URIs& uris, + const Properties& properties, + bool& patch, + bool& node, + bool& port, + bool& is_output) +{ + typedef Resource::Properties::const_iterator iterator; + const std::pair types_range = properties.equal_range(uris.rdf_type); + + patch = node = port = is_output = false; + for (iterator i = types_range.first; i != types_range.second; ++i) { + const Raul::Atom& atom = i->second; + if (atom.type() != uris.forge.URI && atom.type() != uris.forge.URID) { + Raul::warn << "[Resource] Non-URI type " << uris.forge.str(atom) << endl; + continue; + } + + if (atom == uris.ingen_Patch) { + patch = true; + } else if (atom == uris.ingen_Node) { + node = true; + } else if (atom == uris.lv2_InputPort) { + port = true; + is_output = false; + } else if (atom == uris.lv2_OutputPort) { + port = true; + is_output = true; + } + } + + if (patch && node && !port) { // => patch + node = false; + return true; + } else if (port && (patch || node)) { // nonsense + port = false; + return false; + } else if (patch || node || port) { // recognized type + return true; + } else { // unknown + return false; + } +} + +void +Resource::set_properties(const Properties& p) +{ + /* Note a simple loop that calls set_property is inappropriate here since + it will not correctly set multiple properties in p (notably rdf:type) + */ + + // Erase existing properties with matching keys + for (Properties::const_iterator i = p.begin(); i != p.end(); ++i) { + _properties.erase(i->first); + } + + // Set new properties + add_properties(p); +} + +void +Resource::add_properties(const Properties& p) +{ + typedef Resource::Properties::const_iterator iterator; + for (iterator i = p.begin(); i != p.end(); ++i) + add_property(i->first, i->second, i->second.context()); +} + +void +Resource::remove_properties(const Properties& p) +{ + typedef Resource::Properties::const_iterator iterator; + for (iterator i = p.begin(); i != p.end(); ++i) { + if (i->second == _uris.wildcard) { + _properties.erase(i->first); + } else { + for (Properties::iterator j = _properties.find(i->first); + (j != _properties.end()) && (j->first == i->first); ++j) { + if (j->second == i->second) { + _properties.erase(j); + break; + } + } + } + } +} + +Resource::Properties +Resource::properties(Resource::Graph ctx) const +{ + if (ctx == Resource::DEFAULT) { + return properties(); + } + + typedef Resource::Properties::const_iterator iterator; + + Properties props; + for (iterator i = _properties.begin(); i != _properties.end(); ++i) { + if (i->second.context() == Resource::DEFAULT + || i->second.context() == ctx) { + props.insert(make_pair(i->first, i->second)); + } + } + + return props; +} + +} // namespace Ingen diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp index 75acef63..56d94b2e 100644 --- a/src/client/ClientStore.cpp +++ b/src/client/ClientStore.cpp @@ -279,8 +279,8 @@ ClientStore::put(const Raul::URI& uri, #endif bool is_patch, is_node, is_port, is_output; - ResourceImpl::type(uris(), properties, - is_patch, is_node, is_port, is_output); + Resource::type(uris(), properties, + is_patch, is_node, is_port, is_output); // Check if uri is a plugin Iterator t = properties.find(_uris.rdf_type); diff --git a/src/client/ObjectModel.cpp b/src/client/ObjectModel.cpp index e7e7a5d8..9a5009ba 100644 --- a/src/client/ObjectModel.cpp +++ b/src/client/ObjectModel.cpp @@ -23,14 +23,14 @@ namespace Ingen { namespace Client { ObjectModel::ObjectModel(Shared::URIs& uris, const Raul::Path& path) - : ResourceImpl(uris, path) + : GraphObject(uris, path) , _path(path) , _symbol((path == Raul::Path::root()) ? "root" : path.symbol()) { } ObjectModel::ObjectModel(const ObjectModel& copy) - : ResourceImpl(copy) + : GraphObject(copy) , _parent(copy._parent) , _path(copy._path) , _symbol(copy._symbol) @@ -82,7 +82,7 @@ ObjectModel::set(SharedPtr o) for (Properties::const_iterator v = o->properties().begin(); v != o->properties().end(); ++v) { - ResourceImpl::set_property(v->first, v->second); + Resource::set_property(v->first, v->second); _signal_property.emit(v->first, v->second); } } diff --git a/src/client/PluginModel.cpp b/src/client/PluginModel.cpp index e3ac9273..f4df6d1c 100644 --- a/src/client/PluginModel.cpp +++ b/src/client/PluginModel.cpp @@ -44,7 +44,7 @@ PluginModel::PluginModel(Shared::URIs& uris, const Raul::URI& uri, const Raul::URI& type_uri, const Resource::Properties& properties) - : ResourceImpl(uris, uri) + : Plugin(uris, uri) , _type(type_from_uri(type_uri.str())) { add_properties(properties); @@ -66,7 +66,7 @@ const Raul::Atom& PluginModel::get_property(const Raul::URI& key) const { static const Raul::Atom nil; - const Raul::Atom& val = ResourceImpl::get_property(key); + const Raul::Atom& val = Resource::get_property(key); if (val.is_valid()) return val; @@ -145,7 +145,7 @@ PluginModel::set(SharedPtr p) for (Properties::const_iterator v = p->properties().begin(); v != p->properties().end(); ++v) { - ResourceImpl::set_property(v->first, v->second); + Resource::set_property(v->first, v->second); _signal_property.emit(v->first, v->second); } diff --git a/src/gui/PortMenu.cpp b/src/gui/PortMenu.cpp index 241811e5..cd611199 100644 --- a/src/gui/PortMenu.cpp +++ b/src/gui/PortMenu.cpp @@ -150,7 +150,7 @@ PortMenu::on_menu_expose() const std::string label = node->label() + " " + node->port_label(port); const Raul::Path path = node->path().str() + "_" + port->symbol().c_str(); - Shared::ResourceImpl r(*_object.get()); + Ingen::Resource r(*_object.get()); r.remove_property(uris.lv2_index, uris.wildcard); r.set_property(uris.lv2_symbol, _app->forge().alloc(path.symbol())); r.set_property(uris.lv2_name, _app->forge().alloc(label.c_str())); diff --git a/src/server/GraphObjectImpl.cpp b/src/server/GraphObjectImpl.cpp index 901be3eb..050992c8 100644 --- a/src/server/GraphObjectImpl.cpp +++ b/src/server/GraphObjectImpl.cpp @@ -28,7 +28,7 @@ namespace Server { GraphObjectImpl::GraphObjectImpl(Ingen::Shared::URIs& uris, GraphObjectImpl* parent, const Raul::Symbol& symbol) - : ResourceImpl(uris, parent ? parent->path().child(symbol) : Raul::Path::root()) + : GraphObject(uris, parent ? parent->path().child(symbol) : "/") , _parent(parent) , _path(parent ? parent->path().child(symbol) : "/") , _symbol(symbol) diff --git a/src/server/GraphObjectImpl.hpp b/src/server/GraphObjectImpl.hpp index b2fa864e..5df7b565 100644 --- a/src/server/GraphObjectImpl.hpp +++ b/src/server/GraphObjectImpl.hpp @@ -17,15 +17,16 @@ #ifndef INGEN_ENGINE_GRAPHOBJECTIMPL_HPP #define INGEN_ENGINE_GRAPHOBJECTIMPL_HPP -#include -#include -#include #include +#include +#include +#include + +#include "ingen/GraphObject.hpp" +#include "ingen/Resource.hpp" #include "raul/Deletable.hpp" #include "raul/Path.hpp" #include "raul/SharedPtr.hpp" -#include "ingen/GraphObject.hpp" -#include "ingen/shared/ResourceImpl.hpp" namespace Raul { class Maid; } @@ -48,8 +49,7 @@ class BufferFactory; * * \ingroup engine */ -class GraphObjectImpl : virtual public GraphObject - , public Ingen::Shared::ResourceImpl +class GraphObjectImpl : public GraphObject { public: virtual ~GraphObjectImpl() {} diff --git a/src/server/PluginImpl.hpp b/src/server/PluginImpl.hpp index 7ad7193c..968c43f6 100644 --- a/src/server/PluginImpl.hpp +++ b/src/server/PluginImpl.hpp @@ -23,7 +23,7 @@ #include #include "ingen/Plugin.hpp" -#include "ingen/shared/ResourceImpl.hpp" +#include "ingen/Resource.hpp" namespace Ingen { @@ -41,14 +41,13 @@ class BufferFactory; * Conceptually, a Node is an instance of this. */ class PluginImpl : public Plugin - , public Ingen::Shared::ResourceImpl , public boost::noncopyable { public: PluginImpl(Ingen::Shared::URIs& uris, Type type, const std::string& uri) - : ResourceImpl(uris, uri) + : Plugin(uris, uri) , _type(type) {} diff --git a/src/server/events/Delta.cpp b/src/server/events/Delta.cpp index 1adb9ba1..4e9ca791 100644 --- a/src/server/events/Delta.cpp +++ b/src/server/events/Delta.cpp @@ -109,7 +109,7 @@ Delta::pre_process() _object = is_graph_object ? _engine.engine_store()->find_object(Raul::Path(_subject.str())) - : static_cast(_engine.node_factory()->plugin(_subject)); + : static_cast(_engine.node_factory()->plugin(_subject)); if (!_object && (!is_graph_object || !_create)) { return Event::pre_process_done(NOT_FOUND, _subject); @@ -120,7 +120,7 @@ Delta::pre_process() if (is_graph_object && !_object) { Raul::Path path(_subject.str()); bool is_patch = false, is_node = false, is_port = false, is_output = false; - Shared::ResourceImpl::type(uris, _properties, is_patch, is_node, is_port, is_output); + Ingen::Resource::type(uris, _properties, is_patch, is_node, is_port, is_output); if (is_patch) { _create_event = new CreatePatch( diff --git a/src/server/events/Delta.hpp b/src/server/events/Delta.hpp index e7d708ae..6bb6508a 100644 --- a/src/server/events/Delta.hpp +++ b/src/server/events/Delta.hpp @@ -26,7 +26,7 @@ namespace Ingen { -namespace Shared { class ResourceImpl; } +class Resource; namespace Server { @@ -97,19 +97,19 @@ private: typedef std::vector SetEvents; - Event* _create_event; - SetEvents _set_events; - std::vector _types; - std::vector _remove_types; - Raul::URI _subject; - Resource::Properties _properties; - Resource::Properties _remove; - Ingen::Shared::ResourceImpl* _object; - PatchImpl* _patch; - CompiledPatch* _compiled_patch; - Resource::Graph _context; - ControlBindings::Key _binding; - bool _create; + Event* _create_event; + SetEvents _set_events; + std::vector _types; + std::vector _remove_types; + Raul::URI _subject; + Resource::Properties _properties; + Resource::Properties _remove; + Ingen::Resource* _object; + PatchImpl* _patch; + CompiledPatch* _compiled_patch; + Resource::Graph _context; + ControlBindings::Key _binding; + bool _create; SharedPtr _old_bindings; }; diff --git a/src/shared/ResourceImpl.cpp b/src/shared/ResourceImpl.cpp deleted file mode 100644 index be3d445f..00000000 --- a/src/shared/ResourceImpl.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard - - Ingen 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 of the License, or any later version. - - Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see . -*/ - -#include - -#include "ingen/shared/ResourceImpl.hpp" -#include "ingen/shared/URIs.hpp" -#include "raul/Atom.hpp" -#include "raul/log.hpp" - -using namespace std; - -namespace Ingen { -namespace Shared { - -void -ResourceImpl::add_property(const Raul::URI& uri, - const Raul::Atom& value, - Graph ctx) -{ - // Ignore duplicate statements - typedef Resource::Properties::const_iterator iterator; - const std::pair range = _properties.equal_range(uri); - for (iterator i = range.first; i != range.second && i != _properties.end(); ++i) { - if (i->second == value && i->second.context() == ctx) { - return; - } - } - - const Raul::Atom& v = _properties.insert(make_pair(uri, Property(value, ctx)))->second; - on_property(uri, v); -} - -const Raul::Atom& -ResourceImpl::set_property(const Raul::URI& uri, - const Raul::Atom& value, - Resource::Graph ctx) -{ - // Erase existing property in this context - for (Properties::iterator i = _properties.find(uri); - (i != _properties.end()) && (i->first == uri);) { - Properties::iterator next = i; - ++next; - if (i->second.context() == ctx) { - _properties.erase(i); - } - i = next; - } - - // Insert new property - const Raul::Atom& v = _properties.insert(make_pair(uri, Property(value, ctx)))->second; - on_property(uri, v); - return v; -} - -void -ResourceImpl::remove_property(const Raul::URI& uri, const Raul::Atom& value) -{ - if (value == _uris.wildcard) { - _properties.erase(uri); - } else { - Properties::iterator i = _properties.find(uri); - for (; (i != _properties.end()) && (i->first == uri); ++i) { - if (i->second == value) { - _properties.erase(i); - return; - } - } - } -} - -bool -ResourceImpl::has_property(const Raul::URI& uri, const Raul::Atom& value) const -{ - Properties::const_iterator i = _properties.find(uri); - for (; (i != _properties.end()) && (i->first == uri); ++i) { - if (i->second == value) { - return true; - } - } - return false; -} - -const Raul::Atom& -ResourceImpl::set_property(const Raul::URI& uri, const Raul::Atom& value) const -{ - return const_cast(this)->set_property(uri, value); -} - -const Raul::Atom& -ResourceImpl::get_property(const Raul::URI& uri) const -{ - static const Raul::Atom nil; - Properties::const_iterator i = _properties.find(uri); - return (i != _properties.end()) ? i->second : nil; -} - -bool -ResourceImpl::type(const URIs& uris, - const Properties& properties, - bool& patch, - bool& node, - bool& port, - bool& is_output) -{ - typedef Resource::Properties::const_iterator iterator; - const std::pair types_range = properties.equal_range(uris.rdf_type); - - patch = node = port = is_output = false; - for (iterator i = types_range.first; i != types_range.second; ++i) { - const Raul::Atom& atom = i->second; - if (atom.type() != uris.forge.URI && atom.type() != uris.forge.URID) { - Raul::warn << "[ResourceImpl] Non-URI type " << uris.forge.str(atom) << endl; - continue; - } - - if (atom == uris.ingen_Patch) { - patch = true; - } else if (atom == uris.ingen_Node) { - node = true; - } else if (atom == uris.lv2_InputPort) { - port = true; - is_output = false; - } else if (atom == uris.lv2_OutputPort) { - port = true; - is_output = true; - } - } - - if (patch && node && !port) { // => patch - node = false; - return true; - } else if (port && (patch || node)) { // nonsense - port = false; - return false; - } else if (patch || node || port) { // recognized type - return true; - } else { // unknown - return false; - } -} - -void -ResourceImpl::set_properties(const Properties& p) -{ - /* Note a simple loop that calls set_property is inappropriate here since - it will not correctly set multiple properties in p (notably rdf:type) - */ - - // Erase existing properties with matching keys - for (Properties::const_iterator i = p.begin(); i != p.end(); ++i) { - _properties.erase(i->first); - } - - // Set new properties - add_properties(p); -} - -void -ResourceImpl::add_properties(const Properties& p) -{ - typedef Resource::Properties::const_iterator iterator; - for (iterator i = p.begin(); i != p.end(); ++i) - add_property(i->first, i->second, i->second.context()); -} - -void -ResourceImpl::remove_properties(const Properties& p) -{ - typedef Resource::Properties::const_iterator iterator; - for (iterator i = p.begin(); i != p.end(); ++i) { - if (i->second == _uris.wildcard) { - _properties.erase(i->first); - } else { - for (Properties::iterator j = _properties.find(i->first); - (j != _properties.end()) && (j->first == i->first); ++j) { - if (j->second == i->second) { - _properties.erase(j); - break; - } - } - } - } -} - -Resource::Properties -ResourceImpl::properties(Resource::Graph ctx) const -{ - if (ctx == Resource::DEFAULT) { - return properties(); - } - - typedef Resource::Properties::const_iterator iterator; - - Properties props; - for (iterator i = _properties.begin(); i != _properties.end(); ++i) { - if (i->second.context() == Resource::DEFAULT - || i->second.context() == ctx) { - props.insert(make_pair(i->first, i->second)); - } - } - - return props; -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/wscript b/src/shared/wscript index 751951e1..8a873653 100644 --- a/src/shared/wscript +++ b/src/shared/wscript @@ -9,7 +9,6 @@ sources = [ 'Configuration.cpp', 'Forge.cpp', 'LV2Features.cpp', - 'ResourceImpl.cpp', 'Store.cpp', 'URIMap.cpp', 'URIs.cpp', @@ -24,6 +23,7 @@ def build(bld): includes = ['../..'], name = 'libingen_shared', target = 'ingen_shared', + use = 'libingen', vnum = '0.0.0', install_path = '${LIBDIR}', lib = ['dl']) @@ -36,6 +36,7 @@ def build(bld): includes = ['../..'], name = 'libingen_shared_profiled', target = 'ingen_shared_profiled', + use = 'libingen', install_path = '', lib = ['dl'] + bld.env['INGEN_TEST_LIBS'], cxxflags = bld.env['INGEN_TEST_CXXFLAGS']) -- cgit v1.2.1