summaryrefslogtreecommitdiffstats
path: root/ingen/Properties.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-02-15 23:18:59 +0100
committerDavid Robillard <d@drobilla.net>2017-02-15 23:26:03 +0100
commitfa6bb9afe8fcf2b0b8348495b9c4e1d6425136f0 (patch)
treee69cd957486b3fe8a82c0b56f26aec0a23b8235c /ingen/Properties.hpp
parent2ba09e4b41b01cbd8f8756eb0e3b7e33136e06b3 (diff)
downloadingen-fa6bb9afe8fcf2b0b8348495b9c4e1d6425136f0.tar.gz
ingen-fa6bb9afe8fcf2b0b8348495b9c4e1d6425136f0.tar.bz2
ingen-fa6bb9afe8fcf2b0b8348495b9c4e1d6425136f0.zip
Move Properties out of Resource
Diffstat (limited to 'ingen/Properties.hpp')
-rw-r--r--ingen/Properties.hpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/ingen/Properties.hpp b/ingen/Properties.hpp
new file mode 100644
index 00000000..ef608574
--- /dev/null
+++ b/ingen/Properties.hpp
@@ -0,0 +1,92 @@
+/*
+ This file is part of Ingen.
+ Copyright 2007-2017 David Robillard <http://drobilla.net/>
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef INGEN_PROPERTIES_HPP
+#define INGEN_PROPERTIES_HPP
+
+#include <map>
+
+#include "ingen/Atom.hpp"
+#include "ingen/URIs.hpp"
+#include "raul/URI.hpp"
+
+namespace Ingen {
+
+/** A property value (an Atom with a context). */
+class Property : public Atom {
+public:
+ enum class Graph {
+ DEFAULT,
+ EXTERNAL,
+ INTERNAL
+ };
+
+ Property(const Atom& atom, Graph ctx=Graph::DEFAULT)
+ : Atom(atom)
+ , _ctx(ctx)
+ {}
+
+ Property(const URIs::Quark& quark, Graph ctx=Graph::DEFAULT)
+ : Atom(quark.urid)
+ , _ctx(ctx)
+ {}
+
+ Graph context() const { return _ctx; }
+ void set_context(Graph ctx) { _ctx = ctx; }
+
+private:
+ Graph _ctx;
+};
+
+class Properties : public std::multimap<Raul::URI, Property> {
+public:
+ using Graph = Property::Graph;
+
+ Properties() {}
+
+ Properties(const Properties& copy)
+ : std::multimap<Raul::URI, Property>(copy)
+ {}
+
+ Properties(std::initializer_list<value_type> l)
+ : std::multimap<Raul::URI, Property>(l)
+ {}
+
+ void put(const Raul::URI& key,
+ const Atom& value,
+ Graph ctx = Graph::DEFAULT) {
+ insert(std::make_pair(key, Property(value, ctx)));
+ }
+
+ void put(const Raul::URI& key,
+ const URIs::Quark& value,
+ Graph ctx = Graph::DEFAULT) {
+ insert(std::make_pair(key, Property(value, ctx)));
+ }
+
+ bool contains(const Raul::URI& key, const Atom& value) {
+ for (const_iterator i = find(key); i != end() && i->first == key; ++i) {
+ if (i->second == value) {
+ return true;
+ }
+ }
+ return false;
+ }
+};
+
+} // namespace Ingen
+
+#endif // INGEN_PROPERTIES_HPP