From b617f75ff95d48ab3089976eb767e4f09abaa110 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 15 Mar 2012 23:52:45 +0000 Subject: Remove weird "include" directory and use standard style ("ingen" directory in top level). git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4063 a436a847-0d15-0410-975c-d299462d15a1 --- ingen/Resource.hpp | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 ingen/Resource.hpp (limited to 'ingen/Resource.hpp') diff --git a/ingen/Resource.hpp b/ingen/Resource.hpp new file mode 100644 index 00000000..56b5157a --- /dev/null +++ b/ingen/Resource.hpp @@ -0,0 +1,115 @@ +/* This file is part of Ingen. + * Copyright 2008-2011 David Robillard + * + * Ingen is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) 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 General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef INGEN_INTERFACE_RESOURCE_HPP +#define INGEN_INTERFACE_RESOURCE_HPP + +#include +#include + +#include "raul/Atom.hpp" +#include "raul/URI.hpp" +#include "raul/log.hpp" + +#define NS_INGEN "http://drobilla.net/ns/ingen#" + +namespace Ingen { + +class Resource +{ +public: + enum Graph { + DEFAULT, + EXTERNAL, + INTERNAL + }; + + static Raul::URI graph_to_uri(Graph g) { + switch (g) { + default: + case DEFAULT: + return NS_INGEN "defaultContext"; + case EXTERNAL: + return NS_INGEN "externalContext"; + case INTERNAL: + return NS_INGEN "internalContext"; + } + } + + static Graph uri_to_graph(const char* uri) { + if (strncmp(uri, NS_INGEN, sizeof(NS_INGEN) - 1)) { + return DEFAULT; + } + + const char* suffix = uri + sizeof(NS_INGEN) - 1; + if (!strcmp(suffix, "defaultContext")) { + return DEFAULT; + } else if (!strcmp(suffix, "externalContext")) { + return EXTERNAL; + } else if (!strcmp(suffix, "internalContext")) { + return INTERNAL; + } + + Raul::error << "Unknown context URI " << uri << std::endl; + return DEFAULT; + } + + class Property : public Raul::Atom { + public: + Property(const Raul::Atom& atom, Graph ctx=DEFAULT) + : Raul::Atom(atom) + , _ctx(ctx) + {} + + Graph context() const { return _ctx; } + void set_context(Graph ctx) { _ctx = ctx; } + + private: + Graph _ctx; + }; + + virtual ~Resource() {} + + virtual const Raul::URI& uri() const = 0; + + typedef std::multimap Properties; + + static void set_context(Properties& props, Graph ctx) { + for (Properties::iterator i = props.begin(); i != props.end(); ++i) { + i->second.set_context(ctx); + } + } + + virtual Properties properties(Resource::Graph ctx) const = 0; + + virtual const Properties& properties() const = 0; + virtual Properties& properties() = 0; + virtual const Raul::Atom& get_property(const Raul::URI& uri) const = 0; + virtual const Raul::Atom& set_property(const Raul::URI& uri, + const Raul::Atom& value, + Graph ctx=DEFAULT) = 0; + virtual void add_property(const Raul::URI& uri, + const Raul::Atom& value, + Graph ctx=DEFAULT) = 0; + virtual bool has_property(const Raul::URI& uri, + const Raul::Atom& value) const = 0; +}; + +} // namespace Ingen + +#endif // INGEN_INTERFACE_RESOURCE_HPP + -- cgit v1.2.1