/* This file is part of Ingen. Copyright 2007-2017 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 . */ #ifndef INGEN_PROPERTIES_HPP #define INGEN_PROPERTIES_HPP #include "ingen/Atom.hpp" #include "ingen/URI.hpp" #include "ingen/URIs.hpp" #include #include #include namespace ingen { /** A property value (an Atom with a context). */ class Property : public Atom { public: enum class Graph { DEFAULT, ///< Default context for "universal" properties EXTERNAL, ///< Externally visible graph properties INTERNAL ///< Internally visible graph properties }; Property(const Atom& atom, Graph ctx=Graph::DEFAULT) : Atom(atom) , _ctx(ctx) {} Property(const URIs::Quark& quark, Graph ctx=Graph::DEFAULT) : Atom(quark.urid_atom()) , _ctx(ctx) {} Graph context() const { return _ctx; } void set_context(Graph ctx) { _ctx = ctx; } private: Graph _ctx; }; class Properties : public std::multimap { public: using Graph = Property::Graph; Properties() = default; Properties(const Properties&) = default; Properties& operator=(const Properties&) = default; Properties(Properties&&) = default; Properties& operator=(Properties&&) = default; Properties(std::initializer_list l) : std::multimap(l) {} void put(const URI& key, const Atom& value, Graph ctx = Graph::DEFAULT) { emplace(key, Property(value, ctx)); } void put(const URI& key, const URIs::Quark& value, Graph ctx = Graph::DEFAULT) { emplace(key, Property(value, ctx)); } bool contains(const URI& key, const Atom& value) { for (auto i = find(key); i != end() && i->first == key; ++i) { if (i->second == value) { return true; } } return false; } }; } // namespace ingen #endif // INGEN_PROPERTIES_HPP