From 5cd549c8e512d9a85d7d666db5da8b8a444a281f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 14 Jan 2013 06:53:05 +0000 Subject: Add sord_node_get() for easily getting single property values. git-svn-id: http://svn.drobilla.net/sord/trunk@280 3d64ff67-21c5-427c-a301-fe4f08042e5a --- sord/sord.h | 13 +++++++++++++ sord/sordmm.hpp | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'sord') diff --git a/sord/sord.h b/sord/sord.h index 8f1ef38..ee49764 100644 --- a/sord/sord.h +++ b/sord/sord.h @@ -397,6 +397,19 @@ sord_search(SordModel* model, const SordNode* p, const SordNode* o, const SordNode* g); +/** + Search for a single node that matches a pattern. + Exactly one of @p s, @p p, @p o must be NULL. + This function is mainly useful for predicates that only have one value. + @return the first matching node, or NULL if no matches are found. +*/ +SORD_API +const SordNode* +sord_get(SordModel* model, + const SordNode* s, + const SordNode* p, + const SordNode* o, + const SordNode* g); /** Return true iff a statement exists. diff --git a/sord/sordmm.hpp b/sord/sordmm.hpp index 4ab25e2..da1e49c 100644 --- a/sord/sordmm.hpp +++ b/sord/sordmm.hpp @@ -466,6 +466,10 @@ public: const Node& predicate, const Node& object); + inline Node get(const Node& subject, + const Node& predicate, + const Node& object); + inline World& world() const { return _world; } private: @@ -631,6 +635,18 @@ Model::find(const Node& subject, return Iter(_world, sord_find(_c_obj, quad)); } +inline Node +Model::get(const Node& subject, + const Node& predicate, + const Node& object) +{ + return Node(_world, sord_get(_c_obj, + subject.c_obj(), + predicate.c_obj(), + object.c_obj(), + NULL)); +} + } // namespace Sord #endif // SORD_SORDMM_HPP -- cgit v1.2.1