diff options
Diffstat (limited to 'src/Resource.cpp')
-rw-r--r-- | src/Resource.cpp | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/src/Resource.cpp b/src/Resource.cpp index 0bd4b95f..29a82772 100644 --- a/src/Resource.cpp +++ b/src/Resource.cpp @@ -14,11 +14,13 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/Resource.hpp" +#include <ingen/Resource.hpp> -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/URIs.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Properties.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> #include <map> #include <utility> @@ -29,9 +31,8 @@ bool Resource::add_property(const URI& uri, const Atom& value, Graph ctx) { // Ignore duplicate statements - using iterator = Properties::const_iterator; - const std::pair<iterator, iterator> range = _properties.equal_range(uri); - for (iterator i = range.first; i != range.second && i != _properties.end(); ++i) { + const auto range = _properties.equal_range(uri); + for (auto i = range.first; i != range.second && i != _properties.end(); ++i) { if (i->second == value && i->second.context() == ctx) { return false; } @@ -52,6 +53,8 @@ Resource::add_property(const URI& uri, const Atom& value, Graph ctx) const Atom& Resource::set_property(const URI& uri, const Atom& value, Resource::Graph ctx) { + assert(uri != _uris.ingen_activity); // Always ephemeral + // Erase existing property in this context for (auto i = _properties.find(uri); (i != _properties.end()) && (i->first == uri);) { @@ -65,16 +68,10 @@ Resource::set_property(const URI& uri, const Atom& value, Resource::Graph ctx) i = next; } - if (uri != _uris.ingen_activity) { - // Insert new property - const Atom& v = _properties.emplace(uri, Property(value, ctx))->second; - on_property(uri, v); - return v; - } else { - // Announce ephemeral activity, but do not store - on_property(uri, value); - return value; - } + // Insert new property + const Atom& v = _properties.emplace(uri, Property(value, ctx))->second; + on_property(uri, v); + return v; } const Atom& @@ -119,8 +116,9 @@ Resource::has_property(const URI& uri, const Atom& value) const bool Resource::has_property(const URI& uri, const URIs::Quark& value) const { - Properties::const_iterator i = _properties.find(uri); - for (; (i != _properties.end()) && (i->first == uri); ++i) { + for (auto i = _properties.find(uri); + (i != _properties.end()) && (i->first == uri); + ++i) { if (value == i->second) { return true; } @@ -138,7 +136,8 @@ const Atom& Resource::get_property(const URI& uri) const { static const Atom nil; - Properties::const_iterator i = _properties.find(uri); + + const auto i = _properties.find(uri); return (i != _properties.end()) ? i->second : nil; } @@ -150,11 +149,10 @@ Resource::type(const URIs& uris, bool& port, bool& is_output) { - using iterator = Properties::const_iterator; - const std::pair<iterator, iterator> types_range = properties.equal_range(uris.rdf_type); + const auto types_range = properties.equal_range(uris.rdf_type); graph = block = port = is_output = false; - for (iterator i = types_range.first; i != types_range.second; ++i) { + for (auto i = types_range.first; i != types_range.second; ++i) { const Atom& atom = i->second; if (atom.type() != uris.forge.URI && atom.type() != uris.forge.URID) { continue; // Non-URI type, ignore garbage data @@ -176,14 +174,14 @@ Resource::type(const URIs& uris, if (graph && block && !port) { // => graph block = false; return true; - } else if (port && (graph || block)) { // nonsense + } + + if (port && (graph || block)) { // nonsense port = false; return false; - } else if (graph || block || port) { // recognized type - return true; - } else { // unknown - return false; } + + return graph || block || port; // recognized type } void |