diff --git a/.gitignore b/.gitignore index 11b04174f..8bd7e270f 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,16 @@ old redland-bindings.spec releases stamp* +dlang/source/rdf/config.d +**/.Rproj.user +**/.Rhistory +**/*.RData +**/*.Rproj +**/*.o +**/*.so +**/.Rproj.user +**/redland-stamp +**/test-out.rdf +.Rproj.user +Makevars +ltmain.sh diff --git a/Makefile.am b/Makefile.am index a6b8d64db..6d2a16844 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,28 +4,28 @@ # # Copyright (C) 2000-2007, David Beckett http://www.dajobe.org/ # Copyright (C) 2000-2005 University of Bristol, UK http://www.bristol.ac.uk/ -# +# # This package is Free Software and part of Redland http://librdf.org/ -# +# # It is licensed under the following three licenses as alternatives: # 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version # 2. GNU General Public License (GPL) V2 or any newer version # 3. Apache License, V2.0 or any newer version -# +# # You may not use this file except in compliance with at least one of # the above three licenses. -# +# # See LICENSE.html or LICENSE.txt at the top of this package for the # complete terms and further detail along with the license texts for # the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively. -# -# +# +# # Subdirectories to build/install etc. SUBDIRS=@SD@ data # Subdirectories to use for distribution DIST_SUBDIRS=data docs \ -lua perl php python ruby +lua perl php python R ruby ada dlang EXTRA_DIST=\ ChangeLog.1 ChangeLog.2 ChangeLog.3 ChangeLog.4 ChangeLog.5 \ diff --git a/R/Dockerfile b/R/Dockerfile new file mode 100644 index 000000000..549251cd3 --- /dev/null +++ b/R/Dockerfile @@ -0,0 +1,27 @@ +FROM debian:testing + +RUN apt-get update && apt-get install -y \ + autoconf \ + libtool \ + python-dev \ + librdf0-dev \ + librdf0 \ + libraptor2-dev \ + librasqal3-dev \ + librasqal3 \ + swig3.0 \ + git \ + make \ + vim \ + r-recommended +RUN R --no-save -e 'options(repos = c(CRAN = "http://cran.rstudio.com")); install.packages(c("devtools", "testthat", "roxygen2", "knitr"))' +RUN cd /usr/bin && ln -s swig3.0 swig && cd / +RUN git clone https://github.com/ropensci/redland-bindings.git +RUN cd /redland-bindings && \ + ./autogen.sh --with-R && \ + make +RUN echo "NEXT STEPS:" && \ + echo "Build & run the container interactively and make should work:" && \ + echo "$ docker build -t redland-bindings ." && \ + echo "$ docker run --rm -it redland-bindings /bin/bash" && \ + echo "cd /redland-bindings/R && make check-local" diff --git a/R/Makefile.am b/R/Makefile.am new file mode 100644 index 000000000..652420f32 --- /dev/null +++ b/R/Makefile.am @@ -0,0 +1,83 @@ +# -*- Mode: Makefile -*- +# +# Makefile.am - automake file for R interface to Redland +# +# Copyright (C) 2014 Matthew Jones +# Derived from code that was originally copyrighted: +# Copyright (C) 2010 David Beckett - http://www.dajobe.org/ +# And used under the terms of the Apache V2.0 license. +# +# This package is Free Software and part of Redland http://librdf.org/ +# +# It is licensed under the following three licenses as alternatives: +# 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version +# 2. GNU General Public License (GPL) V2 or any newer version +# 3. Apache License, V2.0 or any newer version +# +# You may not use this file except in compliance with at least one of +# the above three licenses. +# +# See LICENSE.html or LICENSE.txt at the top of this package for the +# full license terms. +# + +AM_CPPFLAGS=@CPPFLAGS@ @LIBRDF_CPPFLAGS@ -DREDLAND_BINDINGS_VERSION=\"@VERSION@\" +AM_CFLAGS=@STANDARD_CFLAGS@ @LIBRDF_CPPFLAGS@ + +AM_LDFLAGS=@LIBRDF_LDFLAGS@ + +R=R + +R_PACKAGE=redland +R_PACKAGE_SRC=redland/src +R_PACKAGE_BUILD=redland/tools +# If you are rebuilding the wrapper .Rd files for functions defined in +# the SWIG geneated R/redland.R script, you need to have the redland +# source dowloaded and built. Currently the source is available from +# https://github.com/dajobe/librdf. The source dir, for example could +# be "/home/smith/git/redland-1.0.17" +REDLAND_SRC= + +R_CFLAGS=@R_CFLAGS@ +R_LDFLAGS=@R_LDFLAGS@ +R_SO_SUFFIX=so + +SWIG_OUTPUTS=$(R_PACKAGE_SRC)/$(R_PACKAGE).c +SWIG_CRUFT= + +TEST_CRUFT=redland/tools/test-out.rdf + +EXTRA_DIST= $(SWIG_OUTPUTS) + +CLEANFILES=$(R_PACKAGE_SRC)/$(R_PACKAGE).o $(R_PACKAGE)-stamp \ +$(R_PACKAGE_SRC)/$(R_PACKAGE).$(R_SO_SUFFIX) $(R_PACKAGE_SRC)/util.o \ +$(R_PACKAGE).bundle $(TEST_CRUFT) +MAINTAINERCLEANFILES=$(SWIG_OUTPUTS) $(SWIG_CRUFT) $(R_PACKAGE).c.orig + +RUN=@REDLAND_RUN@ + +SWIG_OPTS=-I$(srcdir) + +$(R_PACKAGE_SRC)/redland.c: @REDLAND_SWIG@ + swig -r -namespace -v $(SWIG_OPTS) -module $(R_PACKAGE) -outdir $(R_PACKAGE)/R -o redland/src/redland.c Redland.i + cat Redland.R.in >> redland/R/redland.R + cat redland/R/redland.R | sed 's/RSWIG_createNewRef/SWIG_createNewRef/' > redland/R/redland.R.fix + mv redland/R/redland.R.fix redland/R/redland.R + cd $(R_PACKAGE) && $(R) --no-save -e 'library(devtools); library(roxygen2); document()' + cp ../data/dc.rdf $(R_PACKAGE)/inst/extdata + chmod 755 $(R_PACKAGE)/inst/extdata/dc.rdf + +$(R_PACKAGE_SRC)/redland.so: + R CMD INSTALL --no-multiarch --with-keep.source $(R_PACKAGE) + +test-R: + pwd + cd $(R_PACKAGE) && $(R) --no-save -e 'library(devtools); library(testthat); library(roxygen2); load_all(); test()' + +librdfDocs: + $(R) --no-save -e 'source("createLibrdfDocs.R") ; mkDocs(redlandDocDir="$(REDLAND_SRC)/docs", verbose=FALSE, librdfDocsURL="http://librdf.org/docs")' + +check-local: test-R + +all: $(R_PACKAGE_SRC)/redland.c $(R_PACKAGE_SRC)/redland.so + diff --git a/R/README.md b/R/README.md new file mode 100644 index 000000000..ff22b9380 --- /dev/null +++ b/R/README.md @@ -0,0 +1,60 @@ +R bindings for Redland +====================== + +Bind the [Redland librdf library](http://librdf.org) into the R environment, and +expose the librdf API for R. This is accomplished through the use of SWIG to generate +wrapper code in R that links to the underlying C code from librdf and provides +R functions to call that code. This creates surrogate functions in R for all +of the librdf* functions. In addition, there is a higher-level API written +as a series of S4 classes in R that provide a simpler mechanism to access common +functions from librdf. This API mirrors the python class structure for +librdf-bindings. + +The main R package is in the `redland` subdirectory, and is all that is required +to build and install the R package. This current directory contains the supporting +build infrastructure to build the SWIG bindings and prepare the `redland` package. +Most users will simply follow the build instruction in the `redland/README.md` file. + +## Build notes + +To build the package and generate new interfaces to librdf using SWIG, follow the instructions +below. Again, this is typically not needed by most R users, and is mainly available for +regenerating the R interface when new versions of librdf are released. + +1. (Optional) Install docker and load the Dockerfile into a container and run it + ```bash + docker build -t redland-bindings . + docker run --rm -it redland-bindings /bin/bash + ``` + +2. Run `autoconf` and `make` to generate the shared libraries and compile the R package code, and startup R + ```bash + cd /redland-bindings + ./autogen.sh --with-R + make + cd R/redland + ``` + +3. Load devtools in R and load the package + ```r + > install.packages("devtools") + > library(devtools) + > load_all() + ``` + +4. Run a redland command + ```r + > library(redland) + > world <- librdf_new_world() + > world + An object of class "_p_librdf_world_s" + Slot "ref": + + ``` + +5. Run the existing test suite + ```r + > install.packages("testthat") + > library(testthat) + > test() + ``` diff --git a/R/Redland.R.in b/R/Redland.R.in new file mode 100644 index 000000000..ba3327298 --- /dev/null +++ b/R/Redland.R.in @@ -0,0 +1,3 @@ +setClass('_p_librdf_query', contains = 'ExternalReference') +setClass('_p_librdf_query_results', contains = 'ExternalReference') + diff --git a/R/Redland.i b/R/Redland.i new file mode 100644 index 000000000..9df86c8d2 --- /dev/null +++ b/R/Redland.i @@ -0,0 +1,454 @@ +/* -*- Mode: c; c-basic-offset: 2 -*- + * + * Redland.i - SWIG interface file for interfaces to Redland + * + * Copyright (C) 2000-2010 David Beckett http://www.dajobe.org/ + * Copyright (C) 2000-2005 University of Bristol, UK http://www.bristol.ac.uk/ + * + * This package is Free Software and part of Redland http://librdf.org/ + * + * It is licensed under the following three licenses as alternatives: + * 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version + * 2. GNU General Public License (GPL) V2 or any newer version + * 3. Apache License, V2.0 or any newer version + * + * You may not use this file except in compliance with at least one of + * the above three licenses. + * + * See LICENSE.html or LICENSE.txt at the top of this package for the + * complete terms and further detail along with the license texts for + * the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively. + * + * + */ + +%module Redland +%include typemaps.i + +#ifdef REDLAND_TYPEMAP_I +%include +#endif + +%{ + +/* compile-time include (inside a % ... % block) */ +#ifdef REDLAND_PRE_I +#include +#endif + +#include + +/* + * Thanks to the patch in this Debian bug for the solution + * to the crash inside vsnprintf on some architectures. + * + * "reuse of args inside the while(1) loop is in violation of the + * specs and only happens to work by accident on other systems." + * + * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=104325 + */ + +#ifndef va_copy +#ifdef __va_copy +#define va_copy(dest,src) __va_copy(dest,src) +#else +#define va_copy(dest,src) (dest) = (src) +#endif +#endif + +/* compile-time include (inside a % ... % block) */ +#ifdef REDLAND_POST_I +#include +#endif + +/* Internal prototypes */ +/* FOR TESTING ERRORS ONLY - NOT PART OF API */ +void librdf_internal_test_error(librdf_world *world); +void librdf_internal_test_warning(librdf_world *world); + + +/* prototypes for internal routines called below - NOT PART OF API */ +void librdf_test_error(librdf_world* world, const char* message); +void librdf_test_warning(librdf_world* world, const char* message); + +/* FOR TESTING ERRORS ONLY - NOT PART OF API */ +void +librdf_internal_test_error(librdf_world *world) +{ + librdf_test_error(world, "test error message number 1."); +} + +void +librdf_internal_test_warning(librdf_world *world) +{ + librdf_test_warning(world, "test warning message number 2."); +} + +%} + + + +%init %{ +/* compile-time include (inside a % ... % block) */ +#ifdef REDLAND_INIT_I +#include +#endif +%} + + +/* SWIG-time include (outside a % ... % block) */ +#ifdef REDLAND_TYPES_I +%include +#endif + +typedef struct librdf_world_s librdf_world; +typedef struct librdf_digest_s librdf_digest; +typedef struct librdf_hash_s librdf_hash; +typedef struct librdf_uri_s librdf_uri; +typedef struct librdf_iterator_s librdf_iterator; +typedef struct librdf_node_s librdf_node; +typedef struct librdf_statement_s librdf_statement; +typedef struct librdf_model_s librdf_model; +typedef struct librdf_storage_s librdf_storage; +typedef struct librdf_stream_s librdf_stream; +typedef struct librdf_parser_s librdf_parser; +typedef struct librdf_serializer_s librdf_serializer; + +/* rdf_digest.h */ +%newobject librdf_new_digest; +librdf_digest* librdf_new_digest(librdf_world *world, char *name); +void librdf_free_digest(librdf_digest *digest); +void librdf_digest_init(librdf_digest* digest); +void librdf_digest_update(librdf_digest* digest, const char* buf, size_t length); +void librdf_digest_update_string(librdf_digest* digest, const char* string); +void librdf_digest_final(librdf_digest* digest); +%newobject librdf_digest_to_string; +char* librdf_digest_to_string(librdf_digest* digest); + +/* rdf_hash.h */ +%newobject librdf_new_hash; +%newobject librdf_new_hash_from_string; +%newobject librdf_new_hash_from_array_of_strings; +librdf_hash* librdf_new_hash(librdf_world *world, const char *name); +librdf_hash* librdf_new_hash_from_string(librdf_world *world, const char* name, const char* string); +librdf_hash* librdf_new_hash_from_array_of_strings(librdf_world *world, const char* name, const char* *string); +%newobject librdf_hash_to_string; +char* librdf_hash_to_string(librdf_hash* hash, const char *filter[]); +void librdf_free_hash(librdf_hash *hash); + +/* rdf_init.h */ +%newobject librdf_new_world; + +librdf_world* librdf_new_world(void); +void librdf_free_world(librdf_world *world); +void librdf_world_open(librdf_world *world); + +%newobject librdf_world_get_feature; +librdf_node* librdf_world_get_feature(librdf_world* world, librdf_uri *feature);int librdf_world_set_feature(librdf_world* world, librdf_uri *feature, librdf_node* value); +%newobject librdf_parser_get_accept_header; +char* librdf_parser_get_accept_header(librdf_parser* parser); + +void librdf_world_set_logger(librdf_world* world, void *user_data, librdf_log_func log_handler); + + +/* rdf_iterator.h */ +void librdf_free_iterator(librdf_iterator*); +int librdf_iterator_end(librdf_iterator* iterator); +librdf_node* librdf_iterator_get_object(librdf_iterator* iterator); +librdf_node* librdf_iterator_get_context(librdf_iterator* iterator); +int librdf_iterator_next(librdf_iterator* iterator); + +/* rdf_uri.h */ +%newobject librdf_new_uri; +%newobject librdf_new_uri_from_uri; +%newobject librdf_new_uri_from_filenam; + +librdf_uri* librdf_new_uri (librdf_world *world, char *string); +librdf_uri* librdf_new_uri_from_uri (librdf_uri* uri); +librdf_uri* librdf_new_uri_from_filename(librdf_world* world, const char* filename); +void librdf_free_uri(librdf_uri *uri); +%newobject librdf_uri_to_string; +char* librdf_uri_to_string (librdf_uri* uri); +int librdf_uri_equals(librdf_uri* first_uri, librdf_uri* second_uri); +int librdf_uri_compare(librdf_uri* first_uri, librdf_uri* second_uri); + +/* rdf_node.h */ +%newobject librdf_new_node; +%newobject librdf_new_node_from_uri_string; +%newobject librdf_new_node_from_uri; +%newobject librdf_new_node_from_uri_local_name; +%newobject librdf_new_node_from_normalised_uri_string; +%newobject librdf_new_node_from_literal; +%newobject librdf_new_node_from_typed_literal; +%newobject librdf_new_node_from_node; +%newobject librdf_new_node_from_blank_identifier; + +librdf_node* librdf_new_node(librdf_world *world); +librdf_node* librdf_new_node_from_uri_string(librdf_world *world, const char* string); +librdf_node* librdf_new_node_from_uri(librdf_world *world, librdf_uri *uri); +librdf_node* librdf_new_node_from_uri_local_name(librdf_world* world, librdf_uri *uri, const char *local_name); +librdf_node* librdf_new_node_from_normalised_uri_string(librdf_world* world, const char *uri_string, librdf_uri *source_uri, librdf_uri *base_uri); +librdf_node* librdf_new_node_from_literal(librdf_world *world, const char* string, const char* inStrOrNull /* string */ =NULL, int is_wf_xml=0); +librdf_node* librdf_new_node_from_typed_literal(librdf_world *world, const char* string, const char* inStrOrNull /* string */ =NULL, librdf_uri* inUriOrNull /* datatype_uri */ =NULL); +librdf_node* librdf_new_node_from_node(librdf_node* node); +librdf_node* librdf_new_node_from_blank_identifier(librdf_world *world, const char* inStrOrNull /* identifier */ =NULL); +void librdf_free_node(librdf_node* r); +librdf_uri* librdf_node_get_uri(librdf_node* node); +int librdf_node_get_type(librdf_node* node); +char* librdf_node_get_literal_value(librdf_node* node); +char* librdf_node_get_literal_value_as_latin1(librdf_node* node); +char* librdf_node_get_literal_value_language(librdf_node* node); +librdf_uri* librdf_node_get_literal_value_datatype_uri(librdf_node* node); +int librdf_node_get_literal_value_is_wf_xml(librdf_node* node); +int librdf_node_get_li_ordinal(librdf_node* node); + +int librdf_node_is_resource(librdf_node* node); +int librdf_node_is_literal(librdf_node* node); +int librdf_node_is_blank(librdf_node* node); + +int librdf_node_equals(librdf_node* first_node, librdf_node* second_node); + + +/* rdf_statement.h */ +%newobject librdf_new_statement; +%newobject librdf_new_statement_from_statement; +%newobject librdf_new_statement_from_nodes; + +librdf_statement* librdf_new_statement(librdf_world *world); +librdf_statement* librdf_new_statement_from_statement(librdf_statement* statement); +librdf_statement* librdf_new_statement_from_nodes(librdf_world *world, librdf_node* subject, librdf_node* predicate, librdf_node* object); +void librdf_free_statement(librdf_statement* statement); + +librdf_node* librdf_statement_get_subject(librdf_statement *statement); +void librdf_statement_set_subject(librdf_statement *statement, librdf_node* subject); + +librdf_node* librdf_statement_get_predicate(librdf_statement *statement); +void librdf_statement_set_predicate(librdf_statement *statement, librdf_node* predicate); +librdf_node* librdf_statement_get_object(librdf_statement *statement); +void librdf_statement_set_object(librdf_statement *statement, librdf_node* object); +int librdf_statement_equals(librdf_statement* statement1, librdf_statement* statement2); +int librdf_statement_match(librdf_statement* statement, librdf_statement* partial_statement); + +int librdf_statement_is_complete(librdf_statement *statement); + +/* rdf_model.h */ +%newobject librdf_new_model; +%newobject librdf_new_model_with_options; +%newobject librdf_new_model_from_model; + +librdf_model* librdf_new_model(librdf_world *world, librdf_storage *storage, char* options_string); +librdf_model* librdf_new_model_with_options(librdf_world *world, librdf_storage *storage, librdf_hash* options); +librdf_model* librdf_new_model_from_model(librdf_model* model); +void librdf_free_model(librdf_model* model); +int librdf_model_size(librdf_model* model); +int librdf_model_add(librdf_model* model, librdf_node* subject, librdf_node* predicate, librdf_node* object); +int librdf_model_add_string_literal_statement(librdf_model* model, librdf_node* subject, librdf_node* predicate, const char* literal, const char *inStrOrNull /* xml_language */ =NULL, int is_wf_xml =0); +int librdf_model_add_typed_literal_statement(librdf_model* model, librdf_node* subject, librdf_node* predicate, char* string, char* inStrOrNull /* xml_language */, librdf_uri *inUriOrNull /* datatype_uri */ =NULL); +int librdf_model_add_statement(librdf_model* model, librdf_statement* statement); +int librdf_model_add_statements(librdf_model* model, librdf_stream* statement_stream); +int librdf_model_remove_statement(librdf_model* model, librdf_statement* statement); +int librdf_model_contains_statement(librdf_model* model, librdf_statement* statement); +%newobject librdf_model_as_stream; +librdf_stream* librdf_model_as_stream(librdf_model* model); +%newobject librdf_model_find_statements; +librdf_stream* librdf_model_find_statements(librdf_model* model, librdf_statement* statement); +%newobject librdf_model_find_statements_in_context; +librdf_stream* librdf_model_find_statements_in_context(librdf_model* model, librdf_statement* statement, librdf_node* inNodeOrNull /* context_node */ =NULL); +%newobject librdf_model_get_sources; +librdf_iterator* librdf_model_get_sources(librdf_model* model, librdf_node* arc, librdf_node* target); +%newobject librdf_model_get_arcs; +librdf_iterator* librdf_model_get_arcs(librdf_model* model, librdf_node* source, librdf_node* target); +%newobject librdf_model_get_targets; +librdf_iterator* librdf_model_get_targets(librdf_model* model, librdf_node* source, librdf_node* arc); +%newobject librdf_model_get_source; +librdf_node* librdf_model_get_source(librdf_model* model, librdf_node* arc, librdf_node* target); +%newobject librdf_model_get_arc; +librdf_node* librdf_model_get_arc(librdf_model* model, librdf_node* source, librdf_node* target); +%newobject librdf_model_get_arcs_out; +librdf_iterator* librdf_model_get_arcs_out(librdf_model* model,librdf_node* node); +%newobject librdf_model_get_arcs_in; +librdf_iterator* librdf_model_get_arcs_in(librdf_model* model,librdf_node* node); +int librdf_model_has_arc_in(librdf_model* model,librdf_node* node,librdf_node* property); +int librdf_model_has_arc_out(librdf_model* model,librdf_node* node,librdf_node* property); +%newobject librdf_model_get_target; +librdf_node* librdf_model_get_target(librdf_model* model, librdf_node* source, librdf_node* arc); +int librdf_model_context_add_statement(librdf_model* model, librdf_node* context, librdf_statement* statement); +int librdf_model_context_add_statements(librdf_model* model, librdf_node* context, librdf_stream* stream); +int librdf_model_context_remove_statement(librdf_model* model, librdf_node* context, librdf_statement* statement); +int librdf_model_context_remove_statements(librdf_model* model, librdf_node* context); +%newobject librdf_model_context_as_stream; +librdf_stream* librdf_model_context_as_stream(librdf_model* model, librdf_node* context); +void librdf_model_sync(librdf_model* model); +%newobject librdf_model_get_contexts; +librdf_iterator* librdf_model_get_contexts(librdf_model* model); +int librdf_model_contains_context(librdf_model* model, librdf_node* context); +%newobject librdf_model_get_feature; +librdf_node* librdf_model_get_feature(librdf_model* model, librdf_uri* feature); +int librdf_model_set_feature(librdf_model* model, librdf_uri* feature, librdf_node* value); +int librdf_model_load(librdf_model* model, librdf_uri *uri, const char* name=NULL, const char* mime_type=NULL, librdf_uri *type_uri=NULL); +%newobject librdf_model_query_execute; +librdf_query_results* librdf_model_query_execute(librdf_model* model, librdf_query* query); +%newobject librdf_model_to_string; +char* librdf_model_to_string(librdf_model* model, librdf_uri *uri /* or NULL */, const char* name=NULL /* */ , const char* mime_type=NULL, librdf_uri* inUriOrNull /*type_uri */ =NULL); + +int librdf_model_transaction_start(librdf_model* model); +int librdf_model_transaction_commit(librdf_model* model); +int librdf_model_transaction_rollback(librdf_model* model); + + +/* rdf_storage.h */ +%newobject librdf_new_storage; +%newobject librdf_new_storage_from_storage; + +librdf_storage* librdf_new_storage(librdf_world *world, char *storage_name, char *name, char *options_string); +librdf_storage* librdf_new_storage_from_storage (librdf_storage* old_storage); +void librdf_free_storage(librdf_storage *storage); + +/* rdf_parser.h */ +int librdf_parser_check_name(librdf_world* world, const char *name); + +%newobject librdf_new_parser; + +librdf_parser* librdf_new_parser(librdf_world *world, const char* name, const char* mime_type, librdf_uri *type_uri); +void librdf_free_parser(librdf_parser *parser); + +%newobject librdf_parser_parse_as_stream; +librdf_stream* librdf_parser_parse_as_stream(librdf_parser* parser, librdf_uri* uri, librdf_uri* inUriorNull /* base_uri */ = NULL); +int librdf_parser_parse_into_model(librdf_parser* parser, librdf_uri* uri, librdf_uri* inUriOrNull /* base_uri */, librdf_model* model); +%newobject librdf_parser_parse_string_as_stream; +librdf_stream* librdf_parser_parse_string_as_stream(librdf_parser* parser, const char* string, librdf_uri* base_uri); +int librdf_parser_parse_string_into_model(librdf_parser* parser, const char* string, librdf_uri* base_uri, librdf_model* model); +librdf_stream* librdf_parser_parse_counted_string_as_stream(librdf_parser* parser, const char* string, size_t length, librdf_uri* base_uri); +int librdf_parser_parse_counted_string_into_model(librdf_parser* parser, const char* string, size_t length, librdf_uri* base_uri, librdf_model* model); + +%newobject librdf_parser_get_feature; +librdf_node* librdf_parser_get_feature(librdf_parser* parser, librdf_uri *feature); +int librdf_parser_set_feature(librdf_parser* parser, librdf_uri *feature, librdf_node* value); +const char* librdf_parser_guess_name2(librdf_world* world, const char *mime_type, const char *buffer, const char *identifier); +const char* librdf_parser_get_namespaces_seen_prefix(librdf_parser* parser, int offset); +librdf_uri* librdf_parser_get_namespaces_seen_uri(librdf_parser* parser, int offset); +int librdf_parser_get_namespaces_seen_count(librdf_parser* parser); + +/* rdf_query.h */ +%newobject librdf_new_query; +%newobject librdf_new_query_from_query; + +librdf_query* librdf_new_query(librdf_world* world, const char* name, librdf_uri* uri, const char* query_string, librdf_uri* base_uri); +librdf_query* librdf_new_query_from_query (librdf_query* old_query); +void librdf_free_query(librdf_query *query); + +/* methods */ +%newobject librdf_query_execute; +librdf_query_results* librdf_query_execute(librdf_query* query, librdf_model* model); +int librdf_query_get_limit(librdf_query *query); +int librdf_query_set_limit(librdf_query *query, int limit); +int librdf_query_get_offset(librdf_query *query); +int librdf_query_set_offset(librdf_query *query, int offset); + +%newobject librdf_query_results_as_stream; +librdf_stream* librdf_query_results_as_stream(librdf_query_results* query_results); +int librdf_query_results_get_count(librdf_query_results* query_results); +int librdf_query_results_next(librdf_query_results* query_results); +int librdf_query_results_finished(librdf_query_results* query_results); +%newobject librdf_query_results_get_binding_value; +librdf_node* librdf_query_results_get_binding_value(librdf_query_results* query_results, int offset); +const char* librdf_query_results_get_binding_name(librdf_query_results* query_results, int offset); +%newobject librdf_query_results_get_binding_value_by_name; +librdf_node* librdf_query_results_get_binding_value_by_name(librdf_query_results* query_results, const char* name); +int librdf_query_results_get_bindings_count(librdf_query_results* query_results); +int librdf_query_results_to_file2(librdf_query_results *query_results, const char *name, const char *mime_type, librdf_uri *format_uri, librdf_uri *base_uri); +%newobject librdf_query_results_to_string2; +char* librdf_query_results_to_string2(librdf_query_results *query_results, const char *name, const char *mime_type, librdf_uri *format_uri, librdf_uri *base_uri); + +void librdf_free_query_results(librdf_query_results* query_results); + +int librdf_query_results_is_bindings(librdf_query_results *query_results); +int librdf_query_results_is_boolean(librdf_query_results *query_results); +int librdf_query_results_is_graph(librdf_query_results *query_results); +int librdf_query_results_is_syntax(librdf_query_results* query_results); + +int librdf_query_results_get_boolean(librdf_query_results *query_results); + + +/* rdf_serializer.h */ +int librdf_serializer_check_name(librdf_world* world, const char *name); + +%newobject librdf_new_serializer; + +librdf_serializer* librdf_new_serializer(librdf_world* world, const char* name, const char* mime_type, librdf_uri *type_uri); +void librdf_free_serializer(librdf_serializer *serializer); + +int librdf_serializer_serialize_stream_to_file(librdf_serializer* serializer, const char *name, librdf_uri* base_uri, librdf_stream* stream); +int librdf_serializer_serialize_model_to_file(librdf_serializer* serializer, const char* name, librdf_uri* inUriOrNull /* base_uri */, librdf_model* model); +%newobject librdf_serializer_serialize_stream_to_string; +char* librdf_serializer_serialize_stream_to_string(librdf_serializer *serializer, librdf_uri *base_uri, librdf_stream *stream); +%newobject librdf_serializer_serialize_model_to_string; +char* librdf_serializer_serialize_model_to_string(librdf_serializer* serializer, librdf_uri* inUriOrNull /* base_uri */, librdf_model* model); + +librdf_node* librdf_serializer_get_feature(librdf_serializer* serializer, librdf_uri *feature); +int librdf_serializer_set_feature(librdf_serializer* serializer, librdf_uri *feature, librdf_node* value); +int librdf_serializer_set_namespace(librdf_serializer* serializer, librdf_uri *nspace, const char* prefix); + +/* rdf_stream.h */ +void librdf_free_stream(librdf_stream* stream); +int librdf_stream_end(librdf_stream* stream); +int librdf_stream_next(librdf_stream* stream); +librdf_statement* librdf_stream_get_object(librdf_stream* stream); + + +/* rdf_log.h and raptor.h */ +int librdf_log_message_code(librdf_log_message *message); +int librdf_log_message_level(librdf_log_message *message); +int librdf_log_message_facility(librdf_log_message *message); +const char* librdf_log_message_message(librdf_log_message *message); +raptor_locator* librdf_log_message_locator(librdf_log_message *message); +int raptor_locator_line(raptor_locator *locator); +int raptor_locator_column(raptor_locator *locator); +int raptor_locator_byte(raptor_locator *locator); +const char* raptor_locator_file(raptor_locator *locator); +const char* raptor_locator_uri(raptor_locator *locator); + + +/* FOR TESTING ERRORS ONLY - NOT PART OF API */ +void librdf_internal_test_error(librdf_world *world); +void librdf_internal_test_warning(librdf_world *world); + + +/* SWIG world - declare variables wanted from rdf_init.h */ + +%immutable; +extern const char* const librdf_short_copyright_string; +extern const char* const librdf_copyright_string; +extern const char* const librdf_version_string; +extern const unsigned int librdf_version_major; +extern const unsigned int librdf_version_minor; +extern const unsigned int librdf_version_release; +extern const unsigned int librdf_version_decimal; + +extern const char * const raptor_version_string; +extern const unsigned int raptor_version_major; +extern const unsigned int raptor_version_minor; +extern const unsigned int raptor_version_release; +extern const unsigned int raptor_version_decimal; + +extern const char* const rasqal_version_string; +extern const unsigned int rasqal_version_major; +extern const unsigned int rasqal_version_minor; +extern const unsigned int rasqal_version_release; +extern const unsigned int rasqal_version_decimal; +%mutable; + + +/* SWIG-time include (not inside a % ... % block) */ +#ifdef REDLAND_DECL_I +%include +#endif + +/* CRAN checks (R 3.5+) now require that locally compiled calls are 'registered' (see +https://cran.r-project.org/doc/manuals/R-exts.html#Registering-native-routines). The +following 'init' block will be inserted into the 'R_init_Redland' function which is +called when the redland.so shared object is loaded. */ + +%insert("sinitroutine") %{ + R_useDynamicSymbols(dll, FALSE); +%} diff --git a/R/createLibrdfDocs.R b/R/createLibrdfDocs.R new file mode 100644 index 000000000..ee302c052 --- /dev/null +++ b/R/createLibrdfDocs.R @@ -0,0 +1,157 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2014 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +library(XML) +library(redland) +library(brew) + +# This function creates documentation files for the wrapper functions contained in redland/redland.R +# that make the Redland RDF C library functions available to R. The wrapper file redland.R is +# generated by SWIG, and does not contain any user oriented documentation. This script +# combines documentation from the Redland RDF C source tree and the loaded functions in R +# to create Roxygen files int he redland/man directory for each wrapper function. +# The original C source documentation contains GTKdoc style comments in the C source, which +# are converted to XML, then HTML in the docs/Makefile in the source tree. This R +# script is only intended to be run by redland-bindings developers, and so is not included +# in the R/redland R package for distribution to end users. +# This function is called by the R/Makefile 'librdfDocs' target. In order to build +# the docs, you must: +# 1) download the redland C library source, i.e. https://github.com/dajobe/librdf +# 2) Build the documentation, which creates the ./docs/xml/* files +# 3) edit the Makefile to change redlandDocDir to your redland source directory +# 4) make librdfDocs +# +# Author: Peter Slaughter +# Date: March, 2015 +# +mkDocs <- function (redlandDocDir, verbose=FALSE, librdfDocsURL="http://librdf.org/docs/") { + + # Does the Redland source tree exist, with the generated xml/* files? + if (! file.exists(redlandDocDir)) { + stop(sprintf("The specified location of the redland api docs \"%s\" does not exist\n", redlandDocDir)) + } + outDir <- "redland/man" + #trim <- function (x) gsub("^\\s+|\\s+$", "", x) + # Read in the XML file that contains an index of all librdf functions, macros, etc + indexFile <- sprintf("%s/xml/api-index-full.xml", redlandDocDir) + stopifnot(file.exists(indexFile)) + indexDoc <- xmlInternalTreeParse(indexFile) + nodes <- getNodeSet(indexDoc, "//primaryie") + # Total list of sections is + sections <- c("parser", "hash", "statement", "query", "query_results", "storage", "model", "world", + "stream", "digest", "node", "serializer", "digest", "stream", "uri", "general", "iterator", "log") + sectionDocs <- list() + sectionNames <- list() + # Load an XML for each section needed. + for (iSec in sections) { + sectionDocFile <- sprintf("%s/xml/%s.xml", redlandDocDir, iSec) + if (verbose) cat(sprintf("loading doc file: %s\n", sectionDocFile)) + sectionDocs <- c(sectionDocs, xmlInternalTreeParse(sectionDocFile)) + sectionNames <- c(sectionNames, iSec) + } + + names(sectionDocs) <- sectionNames + # Loop through each function in the API index file, see if it has been loaded in the + # redland package namespace (i.e. was defined in the redland.R script and loaded with library(redland)) + for (node in nodes) { + # The node value is mixed content, with the function (or macro, etc.) value in the first + # element, and the category name that this function is in, in the second element + functionName <- xmlValue(getNodeSet(node, "./link")[[1]]) + functionSection <- xmlValue(getNodeSet(node, "./link")[[2]]) + # See if the name was loaded into the redland namespace + searchPattern <- sprintf("^%s$", functionName) + packMemName <- ls("package:redland", pattern=searchPattern) + if (length(packMemName) > 0) { + if (is.element(functionSection, names(sectionDocs))) { + #if (functionName != "rasqal_version_release_get") next + if (verbose) cat(sprintf("processing functionName: %s\n", functionName)) + xPathStr <- sprintf('/refentry/refsect1/refsect2[./indexterm/primary="%s"]', functionName) + entryTop <- getNodeSet(sectionDocs[[functionSection]], xPathStr)[[1]] + # Obtain the function usage string from the loaded R function, not from the C api docs, + # because we want to document the R parameter types of the wrapper, not the C types + # from the redland library api docs. The SWIG wrapper "redland.R" creates each wrapped + # function with R attributes for the fuction input and return R types. + functionInputs <- formals(functionName) + functionInputNames <- names(functionInputs) + functionParamNames <- list() + for (argName in functionInputNames) { + functionParamNames <- c(functionParamNames, argName) + } + functionInputTypes <- attr(eval(parse(text=functionName)), "inputTypes") + # Format the function inputs + #functionInputs <- paste(lapply(functionInputs, function(x) { s <- gsub('^', '"', x) ; s <- gsub('$', '"', s) }), collapse=", ") + returnValue <- attr(eval(parse(text=functionName)), "returnType") + functionDescr <- xmlValue(getNodeSet(entryTop, "./para")[[1]]) + paramNameNodes <- getNodeSet(entryTop, './refsect3[@role="parameters"]/informaltable//entry[@role="parameter_name"]') + functionParamDescr <- list() + + # We have the param names and types from R, now just get the param descriptions from the api docs + for (pNode in paramNameNodes) { + #paramName <- xmlValue(getNodeSet(pNode, './informaltable//entry[@role="parameter_name"]/para')[[1]]) + paramName <- xmlValue(pNode) + if (paramName == "") { + next + } + paramDescr <- xmlValue(getNodeSet(pNode, '../entry[@role="parameter_description"]/para')[[1]]) + functionParamDescr <- c(functionParamDescr, paramDescr) + } + + # Build the function usage string + functionUsage <- sprintf("%s ( %s )", functionName, paste(functionParamNames, collapse=",\n\t")) + # Append the R datatype to the function description + if (!is.null(functionParamDescr)) { + itype <- 0; + for (inputType in functionInputTypes) { + itype <- itype + 1; + functionParamDescr[itype] <- sprintf('%s ("%s")', functionParamDescr[itype], functionInputTypes[[itype]]) + } + } + + # The function param description list obtained from the api docs may be shorter that + # the list of arguments obtained from the function closure, so pad the param description list if needed. + if(length(functionParamNames) > length(functionParamDescr)) { + lengthDiff <- length(functionParamNames) - length(functionParamDescr) + functionParamDescr <- c(functionParamDescr, as.list(rep(NA, times=lengthDiff))) + } + # Print out copious info if verbose is on. + if (verbose) { + cat(sprintf("functionDescr %s\n", functionDescr)) + cat(sprintf("functionUsage: %s\n", functionUsage)) + cat(sprintf("functionName: %s\n", functionName)) + cat(sprintf("functionDescr: %s\n", functionDescr)) + iparam <- 0 + for (paramName in functionParamNames) { + iparam <- iparam + 1 + cat(sprintf("functionParamNames[[%d]]: %s\n", iparam, functionParamNames[[iparam]])) + cat(sprintf("functionParamDescr[[%d]]: %s\n", iparam, functionParamDescr[[iparam]])) + } + cat(sprintf("returnValue: %s\n", returnValue)) + } + outFile <- sprintf("%s/%s.Rd", outDir, functionName) + if (verbose) cat(sprintf("calling brew on file: %s\n", outFile)) + # Call the template engine, it will substitute local variables such as "functionName" into the template + brew("./librdfFunction.brew", outFile) + } else { + message(sprintf("Error, document not loaded for section %s\n", functionSection)) + } + } + } + if (verbose) cat(sprintf("Done!\n")) +} + +#mkDocs(redlandDocDir="/Users/slaughter/Software/Redland/redland-1.0.17/docs", verbose=FALSE, librdfDocsURL="http://librdf.org/docs") diff --git a/R/librdfFunction.brew b/R/librdfFunction.brew new file mode 100644 index 000000000..5595a2d11 --- /dev/null +++ b/R/librdfFunction.brew @@ -0,0 +1,30 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{<%= functionName %>} +\alias{<%= functionName %>} +\title{<%= functionDescr %>} +\usage{ +<%= functionUsage %> +} +<% if (length(functionParamNames) > 0) { argLine <- "\arguments{" } else { argLine <= "" } %> +<%= argLine %> + +<% i <- 0 ; for (param in functionParamNames) { i <- i + 1 ; -%> + +\item{<%= functionParamNames[[i]] %>}{<%= functionParamDescr[[i]] %>} +<% } %> +<% if (length(functionParamNames) > 0) { argSectionEnd <- "}" } else { argSectionEnd <= "" } %> +<%= argSectionEnd %> + +\value{ +<%= returnValue %> +} +\description{ +<%= functionDescr %> +} +\references{ +\url{<%= {librdfDocsURL} %>} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/.Rbuildignore b/R/redland/.Rbuildignore new file mode 100644 index 000000000..4a8cefada --- /dev/null +++ b/R/redland/.Rbuildignore @@ -0,0 +1,13 @@ +^.*\.Rproj$ +^\.Rproj\.user$ +^\.Rhistory$ +^README\.Rmd$ +^README-*\.png$ +^packrat/ +^\.Rprofile$ +^src/Makevars$ +^src/*.o +^src/*.so +^cran-comments.md +^windows$ +^docker$ diff --git a/R/redland/DESCRIPTION b/R/redland/DESCRIPTION new file mode 100644 index 000000000..ae8edbe45 --- /dev/null +++ b/R/redland/DESCRIPTION @@ -0,0 +1,55 @@ +Package: redland +Version: 1.0.17-11 +Title: RDF Library Bindings in R +Authors@R: c( + person("Matthew B.", "Jones", role = c("aut", "cre"), email="jones@nceas.ucsb.edu"), + person("Peter", "Slaughter", role = c("aut"), email = "slaughter@nceas.ucsb.edu"), + person("Jeroen", "Ooms", role = c("aut"), email="jeroen@berkeley.edu"), + person("Carl", "Boettiger", role = c("aut"), email = "cboettig@gmail.com"), + person("Scott", "Chamberlain", role = c("aut"), email = "myrmecocystus@gmail.com"), + person("David", "Beckett", role = c("cph")), + person("University of Bristol", role = c("cph")), + person("Regents of the University of California", role = c("cph")) + ) +Date: 2019-10-06 +VignetteBuilder: knitr +Description: Provides methods to parse, query and serialize information + stored in the Resource Description Framework (RDF). RDF is described at . + This package supports RDF by implementing an R interface to the Redland RDF C library, + described at . In brief, RDF provides a structured graph + consisting of Statements composed of Subject, Predicate, and Object Nodes. +Depends: + R (>= 3.1.1), + methods +Imports: + roxygen2 +Suggests: + spelling, + knitr, + testthat, + rmarkdown, + stringi +SystemRequirements: Mac OSX: redland (>= 1.0.14) ; Linux: librdf0 (>= 1.0.14), + librdf0-dev (>= 1.0.14) +Collate: + 'redland.R' + 'World.R' + 'Node.R' + 'Statement.R' + 'Storage.R' + 'Model.R' + 'Parser.R' + 'Query.R' + 'QueryResults.R' + 'Serializer.R' + 'mergeNamespace_roclet.R' + 'redland-package.R' + 'util.R' +License: Apache License 2.0 +Copyright: See file (inst/)COPYRIGHTS. +BugReports: https://github.com/ropensci/redland-bindings/issues +RoxygenNote: 6.1.1 +URL: https://github.com/ropensci/redland-bindings/tree/master/R/redland https://github.com/ropensci/redland-bindings/tree/master/R +Encoding: UTF-8 +Language: en-US +Roxygen: list(roclets = c("collate", "rd", "namespace", "mergeNamespace_roclet"), markdown=TRUE) diff --git a/R/redland/NAMESPACE b/R/redland/NAMESPACE new file mode 100644 index 000000000..dfb600a00 --- /dev/null +++ b/R/redland/NAMESPACE @@ -0,0 +1,252 @@ +# Generated by roxygen2: do not edit by hand + +S3method(roclet_output,roclet_mergeNamespace) +S3method(roclet_process,roclet_mergeNamespace) +S3method(roclet_tags,roclet_mergeNamespace) +export(addStatement) +export(executeQuery) +export(freeModel) +export(freeParser) +export(freeQuery) +export(freeQueryResults) +export(freeSerializer) +export(freeStatement) +export(freeStorage) +export(freeWorld) +export(getBlankNodeId) +export(getNodeType) +export(getNodeValue) +export(getQueryResultLimit) +export(getResults) +export(getTermType) +export(is.null.externalptr) +export(mergeNamespace_roclet) +export(parseFileIntoModel) +export(serializeToCharacter) +export(serializeToFile) +export(setNameSpace) +export(setQueryResultLimit) +export(writeResults) +exportClasses(Model) +exportClasses(Node) +exportClasses(Parser) +exportClasses(Query) +exportClasses(QueryResults) +exportClasses(Serializer) +exportClasses(Statement) +exportClasses(Storage) +exportClasses(World) +exportMethods(initialize) +import(methods) +import(roxygen2) +useDynLib(redland, .registration = TRUE) +export(librdf_copyright_string) +export(librdf_copyright_string_get) +export(librdf_digest_final) +export(librdf_digest_init) +export(librdf_digest_to_string) +export(librdf_digest_update) +export(librdf_digest_update_string) +export(librdf_free_digest) +export(librdf_free_hash) +export(librdf_free_iterator) +export(librdf_free_model) +export(librdf_free_node) +export(librdf_free_parser) +export(librdf_free_query) +export(librdf_free_query_results) +export(librdf_free_serializer) +export(librdf_free_statement) +export(librdf_free_storage) +export(librdf_free_stream) +export(librdf_free_uri) +export(librdf_free_world) +export(librdf_hash_to_string) +export(librdf_internal_test_error) +export(librdf_internal_test_warning) +export(librdf_iterator_end) +export(librdf_iterator_get_context) +export(librdf_iterator_get_object) +export(librdf_iterator_next) +export(librdf_log_message_code) +export(librdf_log_message_facility) +export(librdf_log_message_level) +export(librdf_log_message_locator) +export(librdf_log_message_message) +export(librdf_model_add) +export(librdf_model_add_statement) +export(librdf_model_add_statements) +export(librdf_model_add_string_literal_statement) +export(librdf_model_add_typed_literal_statement) +export(librdf_model_as_stream) +export(librdf_model_contains_context) +export(librdf_model_contains_statement) +export(librdf_model_context_add_statement) +export(librdf_model_context_add_statements) +export(librdf_model_context_as_stream) +export(librdf_model_context_remove_statement) +export(librdf_model_context_remove_statements) +export(librdf_model_find_statements) +export(librdf_model_find_statements_in_context) +export(librdf_model_get_arc) +export(librdf_model_get_arcs) +export(librdf_model_get_arcs_in) +export(librdf_model_get_arcs_out) +export(librdf_model_get_contexts) +export(librdf_model_get_feature) +export(librdf_model_get_source) +export(librdf_model_get_sources) +export(librdf_model_get_target) +export(librdf_model_get_targets) +export(librdf_model_has_arc_in) +export(librdf_model_has_arc_out) +export(librdf_model_load) +export(librdf_model_query_execute) +export(librdf_model_remove_statement) +export(librdf_model_set_feature) +export(librdf_model_size) +export(librdf_model_sync) +export(librdf_model_to_string) +export(librdf_model_transaction_commit) +export(librdf_model_transaction_rollback) +export(librdf_model_transaction_start) +export(librdf_new_digest) +export(librdf_new_hash) +export(librdf_new_hash_from_array_of_strings) +export(librdf_new_hash_from_string) +export(librdf_new_model) +export(librdf_new_model_from_model) +export(librdf_new_model_with_options) +export(librdf_new_node) +export(librdf_new_node_from_blank_identifier) +export(librdf_new_node_from_literal) +export(librdf_new_node_from_node) +export(librdf_new_node_from_normalised_uri_string) +export(librdf_new_node_from_typed_literal) +export(librdf_new_node_from_uri) +export(librdf_new_node_from_uri_local_name) +export(librdf_new_node_from_uri_string) +export(librdf_new_parser) +export(librdf_new_query) +export(librdf_new_query_from_query) +export(librdf_new_serializer) +export(librdf_new_statement) +export(librdf_new_statement_from_nodes) +export(librdf_new_statement_from_statement) +export(librdf_new_storage) +export(librdf_new_storage_from_storage) +export(librdf_new_uri) +export(librdf_new_uri_from_filename) +export(librdf_new_uri_from_uri) +export(librdf_new_world) +export(librdf_node_equals) +export(librdf_node_get_blank_identifier) +export(librdf_node_get_li_ordinal) +export(librdf_node_get_literal_value) +export(librdf_node_get_literal_value_as_latin1) +export(librdf_node_get_literal_value_datatype_uri) +export(librdf_node_get_literal_value_is_wf_xml) +export(librdf_node_get_literal_value_language) +export(librdf_node_get_type) +export(librdf_node_get_uri) +export(librdf_node_is_blank) +export(librdf_node_is_literal) +export(librdf_node_is_resource) +export(librdf_parser_check_name) +export(librdf_parser_get_accept_header) +export(librdf_parser_get_feature) +export(librdf_parser_get_namespaces_seen_count) +export(librdf_parser_get_namespaces_seen_prefix) +export(librdf_parser_get_namespaces_seen_uri) +export(librdf_parser_guess_name2) +export(librdf_parser_parse_as_stream) +export(librdf_parser_parse_counted_string_as_stream) +export(librdf_parser_parse_counted_string_into_model) +export(librdf_parser_parse_into_model) +export(librdf_parser_parse_string_as_stream) +export(librdf_parser_parse_string_into_model) +export(librdf_parser_set_feature) +export(librdf_query_execute) +export(librdf_query_get_limit) +export(librdf_query_get_offset) +export(librdf_query_results_as_stream) +export(librdf_query_results_finished) +export(librdf_query_results_get_binding_name) +export(librdf_query_results_get_binding_value) +export(librdf_query_results_get_binding_value_by_name) +export(librdf_query_results_get_bindings_count) +export(librdf_query_results_get_boolean) +export(librdf_query_results_get_count) +export(librdf_query_results_is_bindings) +export(librdf_query_results_is_boolean) +export(librdf_query_results_is_graph) +export(librdf_query_results_is_syntax) +export(librdf_query_results_next) +export(librdf_query_results_to_file2) +export(librdf_query_results_to_string2) +export(librdf_query_set_limit) +export(librdf_query_set_offset) +export(librdf_serializer_check_name) +export(librdf_serializer_get_feature) +export(librdf_serializer_serialize_model_to_file) +export(librdf_serializer_serialize_model_to_string) +export(librdf_serializer_serialize_stream_to_file) +export(librdf_serializer_serialize_stream_to_string) +export(librdf_serializer_set_feature) +export(librdf_serializer_set_namespace) +export(librdf_short_copyright_string) +export(librdf_short_copyright_string_get) +export(librdf_statement_equals) +export(librdf_statement_get_object) +export(librdf_statement_get_predicate) +export(librdf_statement_get_subject) +export(librdf_statement_is_complete) +export(librdf_statement_match) +export(librdf_statement_set_object) +export(librdf_statement_set_predicate) +export(librdf_statement_set_subject) +export(librdf_stream_end) +export(librdf_stream_get_object) +export(librdf_stream_next) +export(librdf_uri_compare) +export(librdf_uri_equals) +export(librdf_uri_to_string) +export(librdf_version_decimal) +export(librdf_version_decimal_get) +export(librdf_version_major) +export(librdf_version_major_get) +export(librdf_version_minor) +export(librdf_version_minor_get) +export(librdf_version_release) +export(librdf_version_release_get) +export(librdf_version_string) +export(librdf_version_string_get) +export(librdf_world_get_feature) +export(librdf_world_open) +export(librdf_world_set_feature) +export(librdf_world_set_logger) +export(raptor_locator_byte) +export(raptor_locator_column) +export(raptor_locator_file) +export(raptor_locator_line) +export(raptor_locator_uri) +export(raptor_version_decimal) +export(raptor_version_decimal_get) +export(raptor_version_major) +export(raptor_version_major_get) +export(raptor_version_minor) +export(raptor_version_minor_get) +export(raptor_version_release) +export(raptor_version_release_get) +export(raptor_version_string) +export(raptor_version_string_get) +export(rasqal_version_decimal) +export(rasqal_version_decimal_get) +export(rasqal_version_major) +export(rasqal_version_major_get) +export(rasqal_version_minor) +export(rasqal_version_minor_get) +export(rasqal_version_release) +export(rasqal_version_release_get) +export(rasqal_version_string) +export(rasqal_version_string_get) diff --git a/R/redland/NEWS b/R/redland/NEWS new file mode 100644 index 000000000..b531b6d7d --- /dev/null +++ b/R/redland/NEWS @@ -0,0 +1,67 @@ +Version 1.0.17-11 + +BUG FIXES + +* Removed deprecated function warnings during package build. (#79) +* Fix memory protection problems reported by 'rchk'. (#78) +* Deprecate the function getNextResult(), which is superceded by getResults(). (#79) + +Version 1.0.17-10 + +BUG FIXES + +* The function 'statement()' now accepts an RDF language tag for literal nodes (#64) + +NEW FEATURES + +* Ability to retrieve all query results at once. (#58) +* New function getNodeValue() (#65) +* New function getResults() (#58) +* New function writeResults() (#58) + +Version 1.0.17-9 + +BUG FIXES + +* Vignettes now build with R 3.4.0 and are now updated to the ./doc directory by package installation. + +* Added an installation cleanup script + +Version 1.0.17-8 + +NEW FEATURES + +* For Mac OS X, binary installations no longer require Redland system libraries to be installed, + as these libraries are now statically linked into the redland package shared library 'redland.so'. + +BUG FIXES + +* Fixed an unresolved symbol problem with Windows 32 bit builds under R 3.3.0 (and gcc 4.9.3 tool chain) + +Version 1.0.17-7 + +BUG FIXES + +* Unit tests have been updated to be compatible with the changes in the + 'testthat' package that were made in development version testthat_0.11.0.9000, + and will be released to CRAN on 4/4/2016. The updated unit tests pass with both + the current version of testthat (0.11.0) and the new version (0.11.0.9000). + +Version 1.0.17 +-------------- + +NEW FEATURES + +* Initial version (see help topic for 'redland', e.g. "?redland") + +* Includes API wrappers for corresponding Redland 1.0.17 C library + +NEW S4 CLASSES + +* Classes Node, Statement, and Model for representing RDF + +* Classes Storage and World for managing collections of statements + +* Classes Parser and Serializer for for loading and saving models + +* classes Query and QueryResults for searching models using SPARQL diff --git a/R/redland/R/Model.R b/R/redland/R/Model.R new file mode 100644 index 000000000..809336506 --- /dev/null +++ b/R/redland/R/Model.R @@ -0,0 +1,102 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 Regents of the University of California +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#' @title A Redland Model object +#' @description A Model object is used to store the statements (triples) of an RDF model. +#' @details A Model may be created manually by creating \code{\link{Statement}} and adding +#' them to the Model using \code{\link{addStatement}}, or a Model may be read in from a +#' previously saved file using \code{\link{parseFileIntoModel}}. Once a Model is created, +#' it can be queried using \code{\link{Query}}. +#' @seealso View examples of creating models by viewing the \code{'redland_overview'} vignette: \code{'vignette("redland_overview")'} +#' @slot librdf_model A redland model object +#' @rdname Model-class +#' @aliases Model +#' @include redland.R +#' @include World.R +#' @include Storage.R +#' @include Statement.R +#' @keywords classes +#' @section Methods: +#' \itemize{ +#' \item{\code{\link{Model-initialize}}}{: Initialize a Model object} +#' \item{\code{\link{addStatement}}}{: Add a Statement object to the Model} +#' \item{\code{\link{freeModel}}}{: Free memory used by a librdf model object} +#' } +#' @seealso \code{\link{redland}}{: redland package} +#' @export +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +setClass("Model", slots=c(librdf_model = "_p_librdf_model_s")) + +#' Constructor for a Model object. +#' @param .Object a Node object +#' @param world a World object +#' @param storage a Storage object +#' @param options extra options for model initialization +#' @rdname Model-initialize +#' @aliases Model-initialize +#' @return the World object +#' @export +setMethod("initialize", signature = "Model", definition = function(.Object, world, storage, options) { + stopifnot(!is.null(world), !is.null(storage)) + .Object@librdf_model <- librdf_new_model(world@librdf_world, storage@librdf_storage, options); + return(.Object) +}) + +#' Add a Statement object to the Model +#' @rdname addStatement +#' @param .Object a Model object +#' @param statement the Statement that will be added +#' @export +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +setGeneric("addStatement", function(.Object, statement) { + standardGeneric("addStatement") +}) + +#' @rdname addStatement +setMethod("addStatement", signature("Model", "Statement"), function(.Object, statement) { + + librdf_model_add_statement(.Object@librdf_model, statement@librdf_statement); +}) + +#' Free memory used by a librdf model. +#' @rdname freeModel +#' @details After this method is called, the Model object is no longer usable and should +#' be deleted \code{"rm(model)"} and a new object created. +#' @param .Object a Model object +#' @export +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +#' # At this point, some operations would be performed with the model. +#' # See '?redland' for a complete example. +#' # When the Model object is no longer needed, the resources it has allocated can be freed. +#' freeModel(model) +#' rm(model) +setGeneric("freeModel", function(.Object) { + standardGeneric("freeModel") +}) + +#' @rdname freeModel +setMethod("freeModel", signature("Model"), function(.Object) { + librdf_free_model(.Object@librdf_model) +}) diff --git a/R/redland/R/Node.R b/R/redland/R/Node.R new file mode 100644 index 000000000..5cff177cd --- /dev/null +++ b/R/redland/R/Node.R @@ -0,0 +1,217 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 Regents of the University of California +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#' @title A Redland Node, used to store one node in an RDF triple statement. +#' @description A Node represents a RDF Resource, Property, Literal or an RDF blank Node. +#' @slot librdf_node A redland node object +#' @include redland.R +#' @include World.R +#' @rdname Node-class +#' @encoding UTF-8 +#' @aliases Node +#' @keywords classes +#' @export +#' @section Methods: +#' \itemize{ +#' \item{\code{\link{Node-initialize}}}{: Initialize a Node object.} +#' \item{\code{\link{getNodeType}}}{: Determine the node type and return as a string.} +#' \item{\code{\link{getNodeValue}}}{: Determine the node type and return as a string.} +#' \item{\code{\link{getBlankNodeId}}}{: Get the value of the node as a string.} +#' } +#' @seealso \code{\link{redland}}{: redland package} +#' @examples +#' world <- new("World") +#' # a blank node is created with a unique identifier generated by librdf +#' node <- new("Node", world) +#' # a blank node is created with a unique identifier generated by librdf +#' node <- new("Node", world, blank=NULL) +#' # a blank node is created with the user specified identifier, i.e. "_:id1" +#' node <- new("Node", world, blank="someid") +#' # a node type of 'literal' is created +#' node <- new("Node", world, literal="A Node Value") +#' # a Node type of 'resource' is created +#' node <- new("Node", world, uri="http://www.example.com") +#' # Create a literal node, specifying a language encoding +#' node <- new("Node", world, literal="Gérard de La Martinière", language="fr") +setClass("Node", slots = c(librdf_node = "_p_librdf_node_s")) + +#' Initialize a Node object. +#' @description A Node has an associated type corresponding to the RDF component that it is representing. The list of possible +#' types is "resource", "literal" or "blank". +#' @details The url=' and 'literal=' arguments determine which type of Node is created. The Node type affects how the Node is processed +#' in serialization, for example a Node created with 'node1 <- new("Node", literal="http://www.example.com")' is processed +#' differently that a Node created with 'node1 <- new("Node", url="http://www.example.com")', with the former being processed +#' as an RDF literal and the latter processed as an RDF resource. +#' @rdname Node-initialize +#' @aliases Node-initialize +#' @param .Object the Node object to be initialized +#' @param world a World object +#' @param literal a literal character value to be assigned to the node +#' @param uri a uri character value to be assigned to the node +#' @param blank a blank node identifier to be assigned to the node +#' @param datatype_uri a uri used to specify the datatype of a literal node, i.e. "http://www.w3.org/2001/XMLSchema#string" +#' @param language a character value specifying the RDF language tag (excluding the "@" symbol), i.e. "fr" +#' @note Refer to https://www.w3.org/TR/rdf11-concepts information on language tags. +#' @return the Node object +#' @export +setMethod("initialize", signature = "Node", definition = function(.Object, world, literal, uri, blank, datatype_uri, language) { + stopifnot(!is.null(world)) + + # Neither 'literal' nor 'uri', nor 'blank' was specified, so create a blank node with librdf generated id + if(missing(literal) && missing(uri) && missing(blank)) { + .Object@librdf_node <- librdf_new_node(world@librdf_world) + } else if (!missing(uri)) { + # 'uri=' was specified + librdf_uri <- librdf_new_uri(world@librdf_world, uri) + .Object@librdf_node <- librdf_new_node_from_uri(world@librdf_world, librdf_uri) + } else if (!missing(literal)) { + # a literal value was specified, but a blank value is not valid + if(missing(language)) language="" # No default for language, so if not specified, set to blank + #if(!grepl(language, "@")) language <- sprintf("@%s", language) + if(literal == "") { + stop(sprintf("Invalid value specified for Node type of literal: \"%s\"", literal)) + } else { + if (missing(datatype_uri)) { + .Object@librdf_node <- librdf_new_node_from_literal(world@librdf_world, literal, language, 0) + } else { + # The datatype_uri specifies the RDF type to be associated with this node + # and can only be applied to a literal value, therefor only to an object node + # that has a literal value. When a statement with such a node is serialize to RDF/XML, the + # rdf type is serialized as an XML attribute, i.e. for the literal node "John Smith" below + # the datatype is an xsd:string: + # + # + # John Smith + # + # + type_uri <- librdf_new_uri(world@librdf_world, datatype_uri) + .Object@librdf_node <- librdf_new_node_from_typed_literal(world@librdf_world, literal, language, type_uri) + } + } + } else if (!missing(blank)) { + # Create a blank node with a librdf generated unique identifier + if(is.null(blank) || blank == "") { + .Object@librdf_node <- librdf_new_node(world@librdf_world) + } else { + # Create a blank node with a user specified identifier + .Object@librdf_node <- librdf_new_node_from_blank_identifier(world@librdf_world, blank) + } + } else { + # If not creating a blank node, either 'literal' or 'uri' must be specified + stop("Please specify either 'literal=\"value\"', 'uri=\"value\"' or 'blank=\"value\"'") + } + return(.Object) +}) + +#' Determine the node type and return as a string +#' @description A Node has a type that is assigned at initialization and can have one of the following values: +#' 'resource', 'literal', 'blank' and 'unknown'. +#' @rdname getNodeType +#' @param .Object a Node object +#' @return a character vector containing the Node type +#' @examples +#' world <- new("World") +#' node <- new("Node", world, uri="http://www.example.com") +#' nodeType <- getNodeType(node) +#' @export +setGeneric("getNodeType", function(.Object) { + standardGeneric("getNodeType") +}) + +#' @rdname getNodeType +setMethod("getNodeType", signature("Node"), function(.Object) { + + if(librdf_node_is_resource(.Object@librdf_node)) { + return("resource") + } else if (librdf_node_is_literal(.Object@librdf_node)) { + return("literal") + } else if (librdf_node_is_blank(.Object@librdf_node)) { + return("blank") + } else { + return("unknown") + } +}) + +#' Get the blank identifier that has been assigned for a specified Node object +#' @details When a Node object is initialized with no value specified, i.e. node <- Node(""), +#' a blank node is created and a locally unique identifier is generated by librdf. This method +#' retrieves this identifier and returns in to the caller. +#' @rdname getBlankNodeId +#' @param .Object a Node object +#' @return a blank node identifier +#' @examples +#' world <- new("World") +#' # a blank node is created with a unique identifier generated by librdf +#' node <- new("Node", world, blank=NULL) +#' nodeId <- getBlankNodeId(node) +#' @export +setGeneric("getBlankNodeId", function(.Object) { + standardGeneric("getBlankNodeId") +}) + +#' @rdname getBlankNodeId +setMethod("getBlankNodeId", signature("Node"), function(.Object) { + if(librdf_node_is_blank(.Object@librdf_node)) { + return(librdf_node_get_blank_identifier(.Object@librdf_node)) + } else { + return(as.character(NA)) + } +}) + +#' Get the value of the node as a string +#' @details The value of the node is returned as a string. If the node type is +#' 'blank', then the blank node identifier is returned. If the node type is +#' 'literal', then the literal value is returned with the form ""@, +#' e.g. \"¡Hola, amigo! ¿Cómo estás?"@es". If the node type is 'uri' +#' then the value is returned as a string. +#' @rdname getNodeValue +#' @encoding UTF-8 +#' @param .Object a Node object +#' @return a string representation of the Node's value +#' @examples +#' world <- new("World") +#' node <- new("Node", world, literal="¡Hola, amigo! ¿Cómo estás?", language="es") +#' value <- getNodeValue(node) +#' @export +setGeneric("getNodeValue", function(.Object) { + standardGeneric("getNodeValue") +}) + +#' @rdname getNodeValue +setMethod("getNodeValue", signature("Node"), function(.Object) { + if(librdf_node_is_resource(.Object@librdf_node)) { + librdf_uri <- librdf_node_get_uri(.Object@librdf_node) + val <- librdf_uri_to_string(librdf_uri) + librdf_free_uri(librdf_uri) + return(val) + } else if (librdf_node_is_literal(.Object@librdf_node)) { + val <- librdf_node_get_literal_value(.Object@librdf_node) + lang <- librdf_node_get_literal_value_language(.Object@librdf_node) + # If the node has a language tag defined, then include it, otherwise don't + if(is.null(lang) || is.na(lang) || lang == "") { + literal <- sprintf("%s", val) + } else { + literal <- sprintf("\"%s\"@%s\"", val, lang) + } + return(literal) + } else if (librdf_node_is_blank(.Object@librdf_node)) { + return(getBlankNodeId(.Object)) + } else { + stop("Node type unknown, cannot get the node value") + } +}) diff --git a/R/redland/R/Parser.R b/R/redland/R/Parser.R new file mode 100644 index 000000000..5d558fbc4 --- /dev/null +++ b/R/redland/R/Parser.R @@ -0,0 +1,152 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 Regents of the University of California +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#' @title An RDF Parser object +#' @description The Parser class provides methods to parse RDF content into a Redland +#' RDF model. +#' @slot librdf_parser A redland parser object +#' @rdname Parser-class +#' @aliases Parser +#' @include redland.R +#' @include World.R +#' @include Model.R +#' @keywords classes +#' @export +#' @section Methods: +#' \itemize{ +#' \item{\code{\link{Parser-initialize}}}{: Initialize a Parser object.} +#' \item{\code{\link{parseFileIntoModel}}}{: Parse the contents of a file into a model.} +#' \item{\code{\link{freeParser}}}{: Free memory used by a librdf parser.} +#' } +#' @seealso \code{\link{redland}}{: redland package} +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +#' # Create the default "rdfxml" parser +#' parser <- new("Parser", world) +#' filePath <- system.file("extdata/example.rdf", package="redland") +#' parseFileIntoModel(parser, world, filePath, model) +setClass("Parser", slots = c(librdf_parser = "_p_librdf_parser_s")) + +#' Initialize a Parser object. +#' @description A Parser object is initialized for a specific RDF serialization. +#' @details The serialization format that are supported by +#' @rdname Parser-initialize +#' @aliases Parser-initialize +#' @param .Object the Parser object +#' @param world a World object +#' @param name name of the parser factory to use +#' @param mimeType a mime type of the syntax of the model +#' @param typeUri a URI for the syntax of the model +#' @return the Parser object +#' @export +setMethod("initialize", signature = "Parser", definition = function(.Object, world, name="rdfxml", mimeType="application/rdf+xml", typeUri=as.character(NA)) { + # Ensure that all provided params are not null + stopifnot(!is.null(world)) + + if(is.na(typeUri)) { + librdf_uri <- librdf_new_uri(world@librdf_world, "") + } else { + librdf_uri <- librdf_new_uri(world@librdf_world, typeUri) + } + + # Create the underlying redland statement object + .Object@librdf_parser <- librdf_new_parser(world@librdf_world, + name, + mimeType, + librdf_uri); + return(.Object) +}) + +#' Parse the contents of a file into a model +#' @description The contents of a the specified file are read and parsed into the initialized +#' Parser object +#' @details The parser factory name specified during initialization determines how the content is +#' parsed, for example, if 'rdfxml' was specified during parser initialization, then the parser +#' expects RDF/XML content as specified in the W3C recommendation (http://www.we3.org/TR/REC-rdf-syntax) +#' @rdname parseFileIntoModel +#' @param .Object a Parser object +#' @param world a World object +#' @param filePath a file that contains the RDF content +#' @param model a Model object to parse the RDF content into +#' @param ... (Additional parameters) +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +#' # Create the default "rdfxml" parser +#' parser <- new("Parser", world) +#' filePath <- system.file("extdata/example.rdf", package="redland") +#' parseFileIntoModel(parser, world, filePath, model) +#' @export +setGeneric("parseFileIntoModel", function(.Object, world, filePath, model, ...) { + standardGeneric("parseFileIntoModel") +}) + +#' @rdname parseFileIntoModel +#' @param baseUri a base URI (i.e. XML base) to apply to the model +setMethod("parseFileIntoModel", signature("Parser", "World", "character", "Model"), function(.Object, world, filePath, model, baseUri=as.character(NA)) { + stopifnot(!is.null(model)) + + if(is.na(baseUri)) { + librdf_uri <- NULL + } else { + librdf_uri <- librdf_new_uri(world@librdf_world, baseUri) + } + + # Construct a file URI of the input file name + err <- try(absFilePath <- normalizePath(filePath, mustWork = TRUE)) + stopifnot (!class(err) == "try-error") + + # Absolute paths on Windows require leading slash: /C:/foo/bar + if(grepl("^[a-zA-Z]:", absFilePath)) + absFilePath <- paste0("/", absFilePath) + + fileUri = sprintf("file://%s", absFilePath) + contentUri <- librdf_new_uri(world@librdf_world, fileUri) + status <- librdf_parser_parse_into_model(.Object@librdf_parser, contentUri, NULL, model@librdf_model) +}) + +#' Free memory used by a librdf parser +#' @details After freeNode is called, the Node object is no longer usable and should +#' be deleted \code{"rm(nodeName)"} and a new object created. +#' @rdname freeParser +#' @param .Object a Node object +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +#' parser <- new("Parser", world) +#' filePath <- system.file("extdata/example.rdf", package="redland") +#' parseFileIntoModel(parser, world, filePath, model) +#' # At this point, some operations would be performed with the Model that has been populated +#' # with the parser. +#' # See '?redland' for a complete example. +#' # When the parser object is no longer needed, the resources it had allocated can be freed. +#' freeParser(parser) +#' rm(parser) +#' @export +setGeneric("freeParser", function(.Object) { + standardGeneric("freeParser") +}) + +#' @rdname freeParser +setMethod("freeParser", signature("Parser"), function(.Object) { + librdf_free_parser(.Object@librdf_parser) +}) diff --git a/R/redland/R/Query.R b/R/redland/R/Query.R new file mode 100644 index 000000000..6f73c12ed --- /dev/null +++ b/R/redland/R/Query.R @@ -0,0 +1,275 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 Regents of the University of California +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#' @title Query an RDF model +#' @description The Query class is used to execute a query on a Model object using the default query +#' language SPARQL. For more information, please refer to \url{http://librdf.org/rasqal/} for details on +#' supported query languages. +#' @details A Query is executed using the executeQuery method, which returns a QueryResults object that +#' can be iterated over the query solution sequence. +#' @slot librdf_query A redland query object +#' @slot librdf_world A redland world object +#' @rdname Query-class +#' @aliases Query +#' @include redland.R +#' @keywords classes +#' @export +#' @references www.example.com +#' @section Methods: +#' \itemize{ +#' \item{\code{\link{Query-initialize}}}{: Initialize a Query object.} +#' \item{\code{\link{executeQuery}}}{: Execute a query.} +#' \item{\code{\link{setQueryResultLimit}}}{: Set limit on returned query results.} +#' \item{\code{\link{getQueryResultLimit}}}{: Get the query result limit.} +#' \item{\code{\link{getResults}}}{: Return all query results.} +#' \item{\code{\link{writeResults}}}{: Write query results to a file.} +#' \item{\code{\link{freeParser}}}{: Free memory used by a librdf query.} +#' } +#' @seealso \code{\link{redland}}{: redland package} +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +#' stmt <- new("Statement", world=world, +#' subject="https://cn.dataone.org/cn/v1/resolve/urn:uuid:274a0c5c-3082-4562-bbd3-2b1288768cac", +#' predicate="http://www.w3.org/ns/prov#hadPlan", +#' object="https://cn.dataone.org/cn/v1/resolve/urn:uuid:01305f45-f22b-40c8-8d27-00357d01e4a5") +#' status <- addStatement(model, stmt) +#' stmt <- new("Statement", world=world, +#' subject="https://orcid.org/0000-0002-2192-403X", +#' predicate="http://www.w3.org/ns/prov#Agent", +#' object="slaughter", +#' objectType="literal", +#' datatype_uri="http://www.w3.org/2001/XMLSchema#string") +#' status <- addStatement(model, stmt) +#' queryString <- +#' paste("PREFIX orcid: ", +#' "PREFIX dataone: ", +#' "PREFIX prov: ", +#' "SELECT ?a ?c WHERE { ?a prov:Agent ?c . }", sep=" ") +#' query <- new("Query", world, queryString, base_uri=NULL, query_language="sparql", query_uri=NULL) +#' # Return all results as a string +#' results <- getResults(query, model, "rdfxml") +#' +setClass("Query", slots = c(librdf_query = "_p_librdf_query", librdf_world = "_p_librdf_world_s")) + +#' Initialize the Query object. +#' @rdname Query-initialize +#' @aliases Query-initialize +#' @param .Object the Query object +#' @param world a World object +#' @param querystring a query string for the language specified in 'query_language' +#' @param base_uri a URI to prepend to relative URI in the document +#' @param query_language the query language to execute the querystring with +#' @param query_uri a URI to prepend to terms in the query +#' @return the Query object +#' @export +setMethod("initialize", + signature = "Query", + definition = function(.Object, world, querystring, base_uri=NULL, query_language="sparql", query_uri=NULL) { + + stopifnot(!is.null(querystring)) + .Object@librdf_query <- librdf_new_query(world@librdf_world, query_language, base_uri, querystring, query_uri) + .Object@librdf_world <- world@librdf_world + + return(.Object) +}) + +#' Execute a query +#' @description The initialize query is executed and the result is returned as a QueryResult object +#' @rdname executeQuery +#' @param .Object a Query object +#' @param model a Model object containing the statements to query +#' @return a QueryResults object +#' @export +setGeneric("executeQuery", function(.Object, model) { + standardGeneric("executeQuery") +}) + +#' @rdname executeQuery +setMethod("executeQuery", signature("Query"), function(.Object, model) { + results <- librdf_query_execute(.Object@librdf_query, model@librdf_model) + queryResultObj <- new("QueryResults", results) + return(queryResultObj) +}) + +#' Set limit on returned query results +#' @rdname setQueryResultsLimit +#' @aliases setQueryResultsLimit +#' @param .Object a Query object +#' @param limit the result set limit. Specify a value >= to have a limit, or a value < 0 to have no limit. +#' @export +setGeneric("setQueryResultLimit", function(.Object, limit) { + standardGeneric("setQueryResultLimit") +}) + +#' @rdname setQueryResultsLimit +setMethod("setQueryResultLimit", signature("Query"), function(.Object, limit) { + librdf_query_set_limit(.Object@librdf_query, as.integer(limit)) +}) + +#' Get the query result limit +#' @rdname getQueryResultsLimit +#' @param .Object a Query object +#' @return the query result limit. If a limit is set then the value will be >= 0. If the value is < 0, no limit is set +#' @export +setGeneric("getQueryResultLimit", function(.Object) { + standardGeneric("getQueryResultLimit") +}) + +#' @rdname getQueryResultsLimit +setMethod("getQueryResultLimit", signature("Query"), function(.Object) { + return(librdf_query_get_limit (.Object@librdf_query)) +}) + +#' Return all query results +#' @details After this method is called, the Query object is no longer usable and should +#' be deleted \code{"rm(query)"} and a new object created. +#' @rdname getResults +#' @param .Object a Query object +#' @param model a Model object +#' @param formatName a string specifying the RDF format name. Currently the supported formats are "rdfxml" ,"turtle", "json", "csv" +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +#' stmt <- new("Statement", world=world, +#' subject="https://orcid.org/0000-0002-2192-403X", +#' predicate="http://www.w3.org/ns/prov#Agent", +#' object="slaughter", +#' objectType="literal", datatype_uri="http://www.w3.org/2001/XMLSchema#string") +#' #objectType="literal", language="en") +#' status <- addStatement(model, stmt) +#' queryString <- paste("PREFIX orcid: ", +#' "PREFIX dataone: ", +#' "PREFIX prov: ", +#' "SELECT ?a ?c WHERE { ?a prov:Agent ?c . }", sep=" ") +#' query <- new("Query", world, queryString, base_uri=NULL, query_language="sparql", query_uri=NULL) +#' # Return all results as a string +#' results <- getResults(query, model, "rdfxml") +#' results <- getResults(query, model, "turtle") +#' results <- getResults(query, model, "json") +#' +#' # When the query object is no longer needed, the resources it had allocated can be freed. +#' freeQuery(query) +#' rm(query) +#' @export +#' @param ... additional parameters +setGeneric("getResults", function(.Object, model, ...) { + standardGeneric("getResults") +}) + +#' @rdname getResults +setMethod("getResults", signature("Query"), function(.Object, model, formatName="rdfxml") { + queryResult <- executeQuery(.Object, model) + if (!is.null(queryResult@librdf_query_results) && librdf_query_results_finished(queryResult@librdf_query_results) == 0) { + # It appears that this redland C library function doesn't allow specifying 'formatName' as "" or NULL, so the next two + # arguments can never be used. Also, a text value has to be specified for the 3rd argument (mimeType) otherwise the function crashes. + if(is.null(formatName) || formatName == "") formatName="rdfxml" + results <- librdf_query_results_to_string2(queryResult@librdf_query_results, formatName, "application/rdf+xml", NULL, NULL); + return(results) + } else { + return(NULL) + } +}) + +#' Write query results to a file. +#' @details After this method is called, the Query object is no longer usable and should +#' be deleted \code{"rm(query)"} and a new object created. +#' @rdname writeResults +#' @param .Object a Query object +#' @param model a Model object +#' @param ... additional parameters +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +#' stmt <- new("Statement", world=world, +#' subject="https://orcid.org/0000-0002-2192-403X", +#' predicate="http://www.w3.org/ns/prov#Agent", +#' object="slaughter", +#' objectType="literal", datatype_uri="http://www.w3.org/2001/XMLSchema#string") +#' status <- addStatement(model, stmt) +#' queryString <- paste("PREFIX orcid: ", +#' "PREFIX dataone: ", +#' "PREFIX prov: ", +#' "SELECT ?a ?c WHERE { ?a prov:Agent ?c . }", sep=" ") +#' query <- new("Query", world, queryString, base_uri=NULL, query_language="sparql", query_uri=NULL) +#' # Return all results as a string +#' tf <- tempfile() +#' writeResults(query, model, file=tf, mimeType="application/x-turtle") +#' +#' # When the query object is no longer needed, the resources it had allocated can be freed. +#' freeQuery(query) +#' rm(query) +#' @export +setGeneric("writeResults", function(.Object, model, ...) { + standardGeneric("writeResults") +}) + +#' @rdname writeResults +#' @param file a string specifying the output file +#' @param mimeType a string specifying the mimeType of the output file. Currently supported values are "application/x-turtle", "text/plain", "application/json", "text/html" +#' @param format_uri (not currently used) +#' @param base_uri (not currently used) +setMethod("writeResults", signature("Query"), function(.Object, model, file, mimeType="application/x-turtle", format_uri=NULL, base_uri=NULL) { + queryResult <- executeQuery(.Object, model) + if (!is.null(queryResult@librdf_query_results) && librdf_query_results_finished(queryResult@librdf_query_results) == 0) { + results <- librdf_query_results_to_file2(queryResult@librdf_query_results, file, mimeType, format_uri, base_uri); + return(results) + } else { + return(NULL) + } +}) + +#' Free memory used by a librdf query +#' @details After this method is called, the Query object is no longer usable and should +#' be deleted \code{"rm(query)"} and a new object created. +#' @rdname freeQuery +#' @param .Object a Query object +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +#' stmt <- new("Statement", world=world, +#' subject="https://orcid.org/0000-0002-2192-403X", +#' predicate="http://www.w3.org/ns/prov#Agent", +#' object="slaughter", +#' objectType="literal", datatype_uri="http://www.w3.org/2001/XMLSchema#string") +#' status <- addStatement(model, stmt) +#' queryString <- paste("PREFIX orcid: ", +#' "PREFIX dataone: ", +#' "PREFIX prov: ", +#' "SELECT ?a ?c WHERE { ?a prov:Agent ?c . }", sep=" ") +#' query <- new("Query", world, queryString, base_uri=NULL, +#' query_language="sparql", query_uri=NULL) +#' # Return all results as a string +#' results <- getResults(query, model, "rdfxml") +#' +#' # When the query object is no longer needed, the resources it had allocated can be freed. +#' freeQuery(query) +#' rm(query) +#' @export +setGeneric("freeQuery", function(.Object) { + standardGeneric("freeQuery") +}) + +#' @rdname freeQuery +setMethod("freeQuery", signature("Query"), function(.Object) { + librdf_free_query(.Object@librdf_query) +}) diff --git a/R/redland/R/QueryResults.R b/R/redland/R/QueryResults.R new file mode 100644 index 000000000..68285b651 --- /dev/null +++ b/R/redland/R/QueryResults.R @@ -0,0 +1,78 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 Regents of the University of California +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#' @title A Redland QueryResults object is used to inspect query results from a Query object. +#' @description The QueryResults object contains the RDF statements that were returned from +#' a query on an RDF model. +#' @slot librdf_query_results A redland query object +#' @rdname QueryResults-class +#' @aliases QueryResults +#' @include redland.R +#' @keywords classes +#' @export +#' @section Methods: +#' \itemize{ +#' \item{\code{\link{QueryResults-initialize}}}{: Initialize a QueryResults object.} +#' \item{\code{\link{freeQueryResults}}}{: Free memory used by a librdf query result.} +#' } +#' @seealso \code{\link{redland}}{: redland package} +setClass("QueryResults", slots = c(librdf_query_results = "_p_librdf_query_results")) + +#' Initialize the QueryResults object. +#' @description The QueryResults object is initialized with the librdf query result from +#' return value of \code{'Query.execute()'}. +#' @details A QueryResults object is returned by the \code{Query.executeQuery()} method, so typically a user +#' does not initialize a QueryResult object by calling \code{new("QueryResult", ...)} +#' @rdname QueryResults-initialize +#' @aliases QueryResults-initialize +#' @param .Object the QueryResults object. +#' @param results a librdf query result +#' @return the QueryResults object +#' @export +setMethod("initialize", signature = "QueryResults", definition = function(.Object, results) { + .Object@librdf_query_results <- results + return(.Object) +}) + +#' Free memory used by a librdf query results +#' @description After this method is called, the QueryResults object is no longer usable and should +#' be deleted with \code{"rm(query)"}. +#' @rdname freeQueryResults +#' @param .Object a QueryResults object +#' @export +setGeneric("freeQueryResults", function(.Object) { + standardGeneric("freeQueryResults") +}) + +#' @rdname freeQueryResults +setMethod("freeQueryResults", signature("QueryResults"), function(.Object) { + # Have to free all of the nodes that were created by the query result that + # hold the bound node values + if (!is.null(.Object@librdf_query_results) && librdf_query_results_finished(.Object@librdf_query_results) == 0) { + num_nodes <- librdf_query_results_get_bindings_count(.Object@librdf_query_results) + for (i in 1:num_nodes-1) { + binding_name <- librdf_query_results_get_binding_name(.Object@librdf_query_results, i) + val = librdf_query_results_get_binding_value(.Object@librdf_query_results, i) + if (!is.null.externalptr(val@ref)) { + librdf_free_node(val) + } + } + } + + librdf_free_query_results(.Object@librdf_query_results) +}) diff --git a/R/redland/R/Serializer.R b/R/redland/R/Serializer.R new file mode 100644 index 000000000..fdba02c9c --- /dev/null +++ b/R/redland/R/Serializer.R @@ -0,0 +1,187 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 Regents of the University of California +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#' @title An RDF Serializer object. +#' @description The Serializer class provides methods to convert a Model object +#' to other forms, for example, write out a Model to a file. +#' @slot librdf_serializer A redland statement object +#' @rdname Serializer-class +#' @aliases Serializer +#' @include redland.R +#' @include World.R +#' @include Model.R +#' @keywords classes +#' @export +#' @section Methods: +#' \itemize{ +#' \item{\code{\link{Serializer-initialize}}}{: Initialize a Serializer object.} +#' \item{\code{\link{setNameSpace}}}{: Set a namespace for the serializer.} +#' \item{\code{\link{serializeToCharacter}}}{: Serialize a model to a character vector.} +#' \item{\code{\link{serializeToFile}}}{: Serialize a model to a file.} +#' \item{\code{\link{freeSerializer}}}{: Free memory used by a librdf serializer.} +#' } +#' @seealso \code{\link{redland}}{: redland package} +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +#' filePath <- system.file("extdata/example.rdf", package="redland") +#' parser <- new("Parser", world) +#' parseFileIntoModel(parser, world, filePath, model) +#' # Creat the default "rdfxml" serizlizer +#' serializer <- new("Serializer", world) +#' # Add a namespace definition to the serializer +#' status <- setNameSpace(serializer, world, namespace="http://purl.org/dc/elements/1.1/", prefix="dc") +#' rdf <- serializeToCharacter(serializer, world, model, baseUri="") +setClass("Serializer", slots = c(librdf_serializer = "_p_librdf_serializer_s")) + +#' Construct a Serializer object. +#' @rdname Serializer-initialize +#' @aliases Serializer-initialize +#' @param .Object the Serializer object +#' @param world a World object +#' @param name name of a previously created serializer factory to use +#' @param mimeType a mime type of the syntax of the model +#' @param typeUri a URI for the syntax of the model +#' @return the Serializer object +#' @export +setMethod("initialize", signature = "Serializer", definition = function(.Object, world, name="rdfxml", mimeType="application/rdf+xml", typeUri=as.character(NA)) { + # Ensure that all provided params are not null + stopifnot(!is.null(world)) + + if(is.na(typeUri)) { + librdf_uri <- NULL + } else { + librdf_uri <- librdf_new_uri(world@librdf_world, typeUri) + } + + # Create the underlying redland statement object + .Object@librdf_serializer <- librdf_new_serializer(world@librdf_world, + name, + mimeType, + librdf_uri); + return(.Object) +}) + +#' Set a namespace for the serializer. +#' @rdname setNameSpace +#' @param .Object a Serializer object +#' @param world a World object +#' @param namespace the namespace to add to the serializer +#' @param prefix the namespace prefix to associate with the namespace +#' @export +setGeneric("setNameSpace", function(.Object, world, namespace, prefix) { + standardGeneric("setNameSpace") +}) + +#' @rdname setNameSpace +setMethod("setNameSpace", signature("Serializer", "World", "character", "character"), function(.Object, world, namespace, prefix) { + + stopifnot(!is.null(world)) + + librdf_uri <- librdf_new_uri(world@librdf_world, namespace) + librdf_serializer_set_namespace(.Object@librdf_serializer, librdf_uri, prefix) +}) + +#' Serialize a model to a character vector. +#' @rdname serializeToCharacter +#' @param .Object a Serializer object +#' @param world a World object +#' @param model a Model object +#' @param ... Additional parameters +#' @return a character vector containing the serialized model +#' @export +setGeneric("serializeToCharacter", function(.Object, world, model, ...) { + standardGeneric("serializeToCharacter") +}) + +#' @rdname serializeToCharacter +#' @param baseUri a URI to prepend to relative URIs in the document +setMethod("serializeToCharacter", signature("Serializer", "World", "Model"), function(.Object, world, model, baseUri=as.character(NA)) { + + stopifnot(!is.null(world)) + stopifnot(!is.null(model)) + + # Convert baseUri to a librdf_uri + if(is.na(baseUri)) { + librdf_uri <- NULL + } else { + librdf_uri <- librdf_new_uri(world@librdf_world, baseUri) + } + + RDFstring <- librdf_serializer_serialize_model_to_string(.Object@librdf_serializer, librdf_uri, model@librdf_model) + return(RDFstring) +}) + +#' Serialize a model to a file. +#' @rdname serializeToFile +#' @param .Object a Serializer object +#' @param world a World object +#' @param model a Model object +#' @param filePath a file path that the serialized model will be written to +#' @param ... Additional parameters +#' @return an integer containing the return status where non zero indicates an error occurred during serialization +#' @export +setGeneric("serializeToFile", function(.Object, world, model, filePath, ...) { + standardGeneric("serializeToFile") +}) + +#' @rdname serializeToFile +#' @param baseUri a base URI to use for the serialization +setMethod("serializeToFile", signature("Serializer", "World", "Model", "character"), function(.Object, world, model, filePath, baseUri=as.character(NA)) { + + stopifnot(!is.null(world)) + stopifnot(!is.null(model)) + stopifnot(!is.null(filePath)) + + # Convert baseUri to a librdf_uri + if(is.na(baseUri)) { + librdf_uri <- NULL + } else { + librdf_uri <- librdf_new_uri(world@librdf_world, baseUri) + } + + status <-librdf_serializer_serialize_model_to_file (.Object@librdf_serializer, filePath, librdf_uri, model@librdf_model); + return(status) +}) + +#' Free memory used by a librdf serializer. +#' @rdname freeSerializer +#' @param .Object a Serializer object +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +#' filePath <- system.file("extdata/example.rdf", package="redland") +#' parser <- new("Parser", world) +#' parseFileIntoModel(parser, world, filePath, model) +#' # Creat the default "rdfxml" serizlizer +#' serializer <- new("Serializer", world) +#' # At this point, some operations would be performed with the Serializer object. +#' # See '?Serializer' for a complete example. +#' # When the serializer object is no longer needed, the resources it had allocated can be freed. +#' freeSerializer(serializer) +#' rm(serializer) +#' @export +setGeneric("freeSerializer", function(.Object) { + standardGeneric("freeSerializer") +}) + +#' @rdname freeSerializer +setMethod("freeSerializer", signature("Serializer"), function(.Object) { + librdf_free_serializer(.Object@librdf_serializer) +}) diff --git a/R/redland/R/Statement.R b/R/redland/R/Statement.R new file mode 100644 index 000000000..32c6b0986 --- /dev/null +++ b/R/redland/R/Statement.R @@ -0,0 +1,256 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 Regents of the University of California +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#' @title An RDF Statement object +#' @slot librdf_statement A redland statement object +#' @rdname Statement-class +#' @aliases Statement +#' @encoding UTF-8 +#' @include redland.R +#' @include World.R +#' @include Node.R +#' @keywords classes +#' @export +#' @description A Statement object is created using the provided subject, predicate and object. +#' @details A Statement object can be created from Node objects that are provided for the subject, +#' predicate and object. An alternative way to create a Statement object is to provide the +#' subject, predicate and object as character values. If this later method is used, the character values will be evaluated to +#' determine the appropriate RDF type for the subject and object. Note that the RDF type for the predicate will always +#' be 'uri' (aka 'resource'). If the automatic determination of RDF types is not desired, then the \code{subjectType} and +#' \code{objectType} parameters can be specified to explicitly set the RDF types. +#' @section Methods: +#' \itemize{ +#' \item{\code{\link{Statement-initialize}}}{: Initialize a Statement object.} +#' \item{\code{\link{getTermType}}}{: Return the redland node type for the specified RDF term in a statement.} +#' \item{\code{\link{freeStatement}}}{: Free memory used by a librdf statement.} +#' } +#' @seealso \code{\link{redland}}{: redland package} +#' @examples +#' world <- new("World") +#' # Create nodes manually and add to the statment +#' subject <- new("Node", blank="_:myid1", world) +#' predicate <- new("Node", uri="http://www.example.com/isa", world) +#' object <- new("Node", literal="thing", world) +#' stmt <- new("Statement", world, subject, predicate, object) +#' +#' # Create the statement specifying node values directly +#' stmt <- new("Statement", world, subject="http://www.example.com/myevent", +#' predicate="http://example.com/occurredAt", +#' object="Tue Feb 17 14:05:13 PST 2015") +#' stmt <- new("Statement", world, subject=NULL, +#' predicate="http://www.example.com/hasAddr", +#' object="http://www.nothing.com", objectType="literal") +#' stmt <- new("Statement", world, subject="http://www.example.com/BobSmith", +#' predicate="http://www.example.com/says", +#' object="¡Hola, amigo! ¿Cómo estás?", +#' objectType="literal", +#' language="es") +setClass("Statement", slots = c(librdf_statement = "_p_librdf_statement_s")) + +#' Construct a Statement object. +#' @rdname Statement-initialize +#' @aliases Statement-initialize +#' @param .Object the Statement object +#' @param world a World object +#' @param subject a Node object +#' @param predicate a Node object +#' @param object a Node object +#' @param subjectType the Node type of the subject, i.e. "blank", "uri" +#' @param objectType the Node type of the object, i.e. "blank", "uri", "literal" +#' @param datatype_uri the datatype URI to associate with a object literal value +#' @param language a character value specifying the RDF language tag for an object literal value (excluding the "@" symbol), i.e. "fr" +#' @return the Statement object +#' @export +setMethod("initialize", signature = "Statement", definition = function(.Object, world, subject, predicate, object, + subjectType=as.character(NA), + objectType=as.character(NA), + datatype_uri=as.character(NA), + language=as.character(NA)) { + # Ensure that all provided params are not null + stopifnot(!is.null(world), !missing(subject), !missing(predicate), !missing(object)) + + # The subject, predicate and object have all been passed in as characters, so we need to + # evaluate them and create appropriate Node objects from them that will be used to + # create the statement object. + if ( (is.null(subject) || class(subject) == "character") && + class(predicate) == "character" && + (is.null(object) || class(object) == "character") ) { + # If subjectType was not specified, determine the subjectType by inspecting the + # subject value + if (is.na(subjectType)) { + if (is.null(subject)) { + subjectType <- "blank" + } else if (length(grep("^_:", subject)) == 1) { + subjectType <- "blank" + } else if (subject == "") { + subjectType <- "blank" + } else { + subjectType <- "uri" + } + } else if (subjectType != "uri" && subjectType != "blank") { + stop(sprintf("Invalid value for subjectType: %s", subjectType)) + } + + # Create the subject Node from the passed in character value, and the + # node type that was either passed in or determined from the character value + if (is.null(subject)) { + subjectNode <- new("Node", world) + } else if (subjectType == "blank") { + subjectNode <- new("Node", world, blank=subject) + } else if (subjectType == "uri") { + subjectNode <- new("Node", world, uri=subject) + } else { + stop(sprintf("Invalid type for subject node: %s", subject)) + } + + # The predicate is always a URI + predicateNode <- new("Node", world, uri=predicate) + + # Determine the type of the object node from the passed in value + if (is.na(objectType)) { + if (is.null(object)) { + objectType <- "blank" + } else if (length(grep("^http:", object)) == 1) { + objectType <- "uri" + } else if (length(grep("^https:", object)) == 1) { + objectType <- "uri" + } else if (length(grep("^urn:", object)) == 1) { + objectType <- "uri" + } else if (length(grep("^_:", object)) == 1) { + objectType <- "blank" + } else if (object == "") { + objectType <- "blank" + } else if (is.null(object)) { + objectType <- "blank" + } else { + objectType <- "literal" + } + } else if (objectType != "uri" && objectType != "literal" && objectType != "blank") { + stop(sprintf("Invalid value for objectType: %s", objectType)) + } + + # Create the object Node from the passed in character value, and the type + # that was either passed in or determined from the argument value + if (is.null(object)) { + objectNode <- new("Node", world) + } else if (objectType == "blank") { + objectNode <- new("Node", world, blank=object) + } else if (objectType == "uri") { + objectNode <- new("Node", world, uri=object) + } else { + if(is.na(language)) language <- "" + if(is.na(datatype_uri)) { + objectNode <- new("Node", world, literal=object, language=language) + } else { + objectNode <- new("Node", world, literal=object, datatype_uri=datatype_uri, language=language) + } + } + + .Object@librdf_statement <- librdf_new_statement_from_nodes(world@librdf_world, + subjectNode@librdf_node, + predicateNode@librdf_node, + objectNode@librdf_node); + } else { + # The subject, predicate and object have all been passed in as Node objects, so create + # the statement from these objects directly. + if (class(subject) == "Node" && class(predicate) == "Node" && class(object) == "Node") { + # Create the underlying redland statement object + .Object@librdf_statement <- librdf_new_statement_from_nodes(world@librdf_world, + subject@librdf_node, + predicate@librdf_node, + object@librdf_node); + } else { + stop(sprintf("Invalid argument types for subject (%s), predicate(%s) or object(%s).", + class(subject), class(predicate), class(object))) + } + } + + return(.Object) +}) + +#' Return the redland node type for the specified RDF term in a statement +#' @description After a Statement object has been created, this method can +#' be used to determine the RDF type ("uri", "literal", "blank") that has been +#' assigned to the specified RDF term, i.e. "subject", "predicate", "object". +#' @rdname getTermType +#' @param .Object a Statement object +#' @param term the RDF term for which the type will be returned +#' @export +#' @examples +#' world <- new("World") +#' subject <- new("Node", blank="_:myid1", world) +#' predicate <- new("Node", uri="http://www.example.com/isa", world) +#' object <- new("Node", literal="thing", world) +#' stmt <- new("Statement", world, subject, predicate, object, world) +#' termType <- getTermType(stmt, "predicate") +setGeneric("getTermType", function(.Object, term) { + standardGeneric("getTermType") +}) + +#' @rdname getTermType +setMethod("getTermType", signature("Statement", "character"), function(.Object, term) { + if (term != "subject" && term != "predicate" && term != "object") { + stop("Must specify \"subject\", \"predicate\", or \"object\" for term") + } + + # Retrieve a pointer to the specified node object from librdf + if (term == "subject") { + termPtr <- librdf_statement_get_subject(.Object@librdf_statement) + } else if (term == "predicate") { + termPtr <- librdf_statement_get_predicate(.Object@librdf_statement) + } else { + termPtr <- librdf_statement_get_object(.Object@librdf_statement) + } + + # Print out the redland node type corresponding to the RDF term type for the specified term + if(librdf_node_is_resource(termPtr)) { + return("resource") + } else if (librdf_node_is_literal(termPtr)) { + return("literal") + } else if (librdf_node_is_blank(termPtr)) { + return("blank") + } else { + return("unknown") + } +}) + +#' Free memory used by a librdf statement +#' @details After this method is called, the Statement object is no longer usable and should +#' be deleted \code{"rm(statement)"} and a new object created. This method frees +#' all resources for the statement, as well as each node in the statement. +#' @rdname freeStatement +#' @param .Object a Statement object +#' @examples +#' world <- new("World") +#' stmt <- new("Statement", world, subject="http://www.example.com/myevent", +#' predicate="http://example.com/occurredAt", +#' object="Tue Feb 17 14:05:13 PST 2015") +#' # At this point, some operations would be performed with the Statement. +#' # See '?redland' for a complete example. +#' # When the Statement object is no longer needed, the resources it had allocated can be freed. +#' freeStatement(stmt) +#' rm(stmt) +#' @export +setGeneric("freeStatement", function(.Object) { + standardGeneric("freeStatement") +}) + +#' @rdname freeStatement +setMethod("freeStatement", signature("Statement"), function(.Object) { + librdf_free_statement(.Object@librdf_statement) +}) \ No newline at end of file diff --git a/R/redland/R/Storage.R b/R/redland/R/Storage.R new file mode 100644 index 000000000..549fb3958 --- /dev/null +++ b/R/redland/R/Storage.R @@ -0,0 +1,84 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 Regents of the University of California +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#' A Redland Storage object +#' @slot librdf_storage A redland storage object +#' @slot type the storage type to create, i.e. "hashes", "mysql", "postgresql", ... +#' @rdname Storage-class +#' @aliases Storage +#' @include redland.R +#' @include World.R +#' @keywords classes +#' @section Methods: +#' \itemize{ +#' \item{\code{\link{Storage-initialize}}}{: Initialize a Storage object} +#' \item{\code{\link{freeStorage}}}{: Free memory used by a librdf storage object} +#' } +#' @seealso \code{\link{redland}}{: redland package} +#' @export +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +setClass("Storage", slots = c(librdf_storage = "_p_librdf_storage_s", + type = "character" +)) + +#' Initialize a Storage object +#' @rdname Storage-initialize +#' @aliases Storage-initialize +#' @param .Object the Storage object +#' @param world the World object +#' @param type the Redland storage type +#' @param name storage instance name +#' @param options storage options +#' @return the Storage object +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' @export +setMethod("initialize", signature = "Storage", definition = function(.Object, world, type="hashes", name="", options="hash-type='memory'") { + stopifnot(!is.null(world)) + .Object@type <- type + .Object@librdf_storage <- librdf_new_storage(world@librdf_world, type, name, options); + #librdf_storage_open(.Object@librdf_storage) + + return(.Object) +}) + +#' Free memory used by a librdf storage object +#' @description After this method is called, the Storage object is no longer usable and should +#' be deleted \code{"rm(storage)"} and a new object created. +#' @rdname freeStorage +#' @param .Object a Storage object to free memory for +#' @examples +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' # At this point we would perform some operations using the storage object. +#' # See '?redland' for a complete example. +#' # When the Storage object is no longer needed, the resources it had allocated can be freed. +#' status <- freeStorage(storage) +#' rm(storage) +#' @export +setGeneric("freeStorage", function(.Object) { + standardGeneric("freeStorage") +}) + +#' @rdname freeStorage +setMethod("freeStorage", signature("Storage"), function(.Object) { + librdf_free_storage(.Object@librdf_storage) +}) \ No newline at end of file diff --git a/R/redland/R/World.R b/R/redland/R/World.R new file mode 100644 index 000000000..652678cb7 --- /dev/null +++ b/R/redland/R/World.R @@ -0,0 +1,70 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 Regents of the University of California +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#' @title A Redland World object, used to initialize the Redland RDF library. +#' @description A World object is the top level object in the Redland RDF library +#' implementation, so it contains all other objects needed to process RDF +#' Models. +#' @slot librdf_world A redland world object +#' @aliases World +#' @include redland.R +#' @keywords classes +#' @useDynLib redland, .registration = TRUE +#' @section Methods: +#' \itemize{ +#' \item{\code{\link{World-initialize}}}{: Initialize a World object} +#' \item{\code{\link{freeWorld}}}{: Free memory used by a librdf world object} +#' } +#' @seealso \code{\link{redland}}{: redland package} +#' @examples +#' world <- new("World") +#' @import methods +#' @export +setClass("World", slots = c(librdf_world = "_p_librdf_world_s")) + +#' Initialize the World object. +#' @rdname World-initialize +#' @aliases World-initialize +#' @param .Object the World object +#' @return the World object +#' @export +setMethod("initialize", signature = "World", definition = function(.Object) { + .Object@librdf_world <- librdf_new_world(); + librdf_world_open(.Object@librdf_world) + return(.Object) +}) + +#' Free memory used by a librdf world object +#' @details After this method is called, the World object is no longer usable and should +#' be deleted \code{"rm(world)"} and a new object created. +#' @rdname freeWorld +#' @param .Object a World object +#' @export +#' @examples +#' world <- new("World") +#' # At this point we would perform some operations using the world object. +#' # When the world object is no longer needed, we can free the resources it has allocated. +#' result <- freeWorld(world) +#' rm(world) +setGeneric("freeWorld", function(.Object) { + standardGeneric("freeWorld") +}) + +#' @rdname freeWorld +setMethod("freeWorld", signature("World"), function(.Object) { + librdf_free_world(.Object@librdf_world) +}) diff --git a/R/redland/R/mergeNamespace_roclet.R b/R/redland/R/mergeNamespace_roclet.R new file mode 100644 index 000000000..9e10c1999 --- /dev/null +++ b/R/redland/R/mergeNamespace_roclet.R @@ -0,0 +1,122 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2014 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#' A custom Roxygen roclet that adds Redland RDF functions to NAMESPACE file generated by Roxygen. +#' @description The redland package uses the SWIG (Simplified Wrapper and Interface Generator) to +#' create the bindings between the Redland RDF C/C++ libraries and R. SWIG creates a NAMESPACE +#' file that contains the function names for the librdf wrapper that it creates, but as of +#' swig 3.0.2 this NAMESPACE file is incorrect and will also be overwritten by Roxygen when +#' 'roxygenize()' or 'devtools:document()' is called, as the wrapper R code doesn't contain +#' Roxygen export annotations used by Roxygen to build the namespace file. +#' To allow for building a NAMESPACE file from all programs in the redland package, this roclet +#' determines the set of wrapper R functions and adds these to the Roxygen generated NAMESPACE file +#' that contains all names from the native R code in the redland package. +#' @details The following line must be present in the DESCRIPTION file for this roclet to be +#' called automatically when 'roxygen2::roxygenize()' or 'devtools::document()' is called: +#' +#' Roxygen: list(roclets = c("collate", "rd", "namespace", "mergeNamespace_roclet")) +#' +#' The 'namespace' roclet must always run before the 'mergeNamespace' roclet. +#' @examples +#' \dontrun{ +#' roxygen2::roxygenize() +#' devtools::document() +#' } +#' @import roxygen2 +#' @param x a roclet +#' @param ... additional parameters +#' @export +mergeNamespace_roclet <- function(x, ...) { + roclet("mergeNamespace") +} + +#' Roxygen process function for the 'mergeNamespace' roclet +#' @description This function is called by the Roxygen2 roxygenize function. +#' @details This function loads the Redland interface file and tests each loaded function to +#' see if it should be exported via the NAMESPACE file. +#' @param x the currently running roclet +#' @param blocks the documentation blocks +#' @param env the current env +#' @param base_path the top directory of the R package +#' @param global_options unused by this roclet +#' @export +roclet_process.roclet_mergeNamespace <- function(x, blocks, env, base_path, global_options = list()) { + #on.exit(detach(".redland-temp")) + #attach(NULL, name=".redland-temp") + tmpEnv <- new.env() + # Load the Redland wrapper file into a temporary environment. This file has a definition of + # each redland library function that will be made available to the package. + filePath <- sprintf("%s/R/redland.R", base_path) + #source(filePath, as.environment(".redland-temp")) + source(file=filePath, local=as.environment(tmpEnv)) + # Check each Redland function to see if it has the SWIGfunction attribute set, and if so + # include this function name in the list of functions to be exported + #funcList <- ls(as.environment(".redland-temp")) + funcList <- ls(as.environment(tmpEnv)) + exportFuncList <- list() + for (functionName in funcList) { + funcType <- attr(get(functionName), "class")[1] + if(is.null(funcType)) next + if (funcType == "SWIGFunction") { + exportFuncList <- c(exportFuncList, functionName) + #cat(sprintf("func: %s\n", functionName)) + } + } + + rm(list=ls(tmpEnv), envir=tmpEnv) + rm(tmpEnv) + + return(exportFuncList) +} + +#' Roxygen output function that merges a base NAMESPACE file with the Roxygen dynamically created NAMSPACE file +#' @description The 'roclet_output' function handles output of the results from the 'roc_process' function. +#' This function merges the NAMESPACE file created by the 'namespace' roclet with the list of Redland RDF +#' functions determined by the 'roc_process' function. +#' @param x the currently running roclet +#' @param results the list of items to process that was generated by the roc_process.mergedNamespace function +#' @param base_path the base directory path of the package +#' @param ... additional parameters +#' @export +roclet_output.roclet_mergeNamespace <- function(x, results, base_path, ...) { + + # Get contents of the NAMESPACE file that was created by the "namespace" roclet + filePathNS <- file.path(base_path, "NAMESPACE") + NScontents <- if (file.exists(filePathNS)) readLines(filePathNS) else "" + + # Merge the contents of the "namespace" roclet NAMESPACE file with the list + # of functions from Redland + mergedContents <- NScontents + for (tm in results) { + tm <- sprintf("export(%s)", tm) + mergedContents <- c(mergedContents, tm) + } + + if (identical(mergedContents, NScontents)) { + warning("No functions added from Redland wrapper file.") + } else { + cat("Adding namespace directives for Redland library\n") + writeLines(mergedContents, filePathNS) + } + + filePathNS +} + +#' @export +roclet_tags.roclet_mergeNamespace <- function(x) { + list() +} diff --git a/R/redland/R/redland-package.R b/R/redland/R/redland-package.R new file mode 100644 index 000000000..f1dc6e756 --- /dev/null +++ b/R/redland/R/redland-package.R @@ -0,0 +1,81 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 Regents of the University of California +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#' @title Create, query and write RDF graphs. +#' @description The R package \emph{redland} provides methods to create, query and write information stored in the +#' Resource Description Framework (RDF). This package is implemented as R scripts that provide an +#' R interface (aka "wrapper") to the Redland RDF C libraries. Documentation for the redland R package classes +#' and functions are available from the standard R help facility, for example, \code{'help("Node-class")'}, \code{'?getNodeType'}, etc. +#' +#' An overview of the redland R package is available with the R command: \code{'vignette("redland_overview")'}. +#' +#' The Redland C library functions are described at \url{http://librdf.org/docs/api/index.html}. +#' +#' An introduction to RDF can be found at \url{http://www.w3.org/TR/rdf-primer}. +#' +#' @details +#' The redland R package classes and the corresponding Redland C library types are shown in the following table: +#' \tabular{llll}{ +#' \strong{Concept}\tab \strong{Redland C type}\tab \strong{redland R class}\tab \strong{Purpose}\cr +#' Resource / Literal\tab librdf_node\tab \linkS4class{Node}\tab RDF Model & Syntax nodes\cr +#' Statement / Triple\tab librdf_statement\tab \linkS4class{Statement}\tab RDF Model & Syntax arcs (statements, triples)\cr +#' Model\tab librdf_model\tab \linkS4class{Model}\tab Set of Statements usually held in one Storage.\cr +#' Node\tab librdf_node\tab \linkS4class{Node}\tab The subject, predicate or object of a Statement\cr +#' Storage\tab librdf_storage\tab \linkS4class{Storage}\tab Storage for Models either persistent or in-memory.\cr +#' Parser\tab librdf_parser\tab \linkS4class{Parser}\tab Syntax parsers delivering Stream of Statements or writing to a Model\cr +#' Query\tab librdf_query\tab \linkS4class{Query}\tab Querying of an Model delivering a QueryResults\cr +#' QueryResults\tab librdf_query_results\tab \linkS4class{QueryResults}\tab Results of applying an Query to a Model giving either variable bindings with Node values or Stream of Statements\cr +#' Serializer\tab librdf_serializer\tab \linkS4class{Serializer}\tab Serializes a Model into a syntax such as RDF/XML\cr +#' World\tab librdf_world\tab \linkS4class{World}\tab RDF wrapper class handling Redland startup/shutdown\cr +#' } +#' +#' @note +#' In order to communicate with the Redland RDF C libraries, the redland R package uses an interface layer that is created +#' with the software package \emph{Simplified Wrapper and Interface Generator} (\href{https://github.com/swig/swig}{SWIG}). +#' The relationship between the redland R package and the Redland C libraries is: +#' +#' User script -> redland R package -> SWIG R interface -> Redland C libraries -> RDF data +#' +#' It is recommended that the redland package R classes be used to interact with RDF, as these higher level classes take care of many of the the +#' details of communicating with the Redland C libraries. However, all of the lower level R interface functions generated by SWIG are made available +#' by the redland package. These interface functions usually have names beginning with \code{'librdf_'}, \code{'rasqal_'} or \code{'raptor_'} and +#' are usually the same name as the underlying C library function. Documentation +#' for the R SWIG interface functions can be found via R help i.e. \code{'?librdf_iterator'}. +#' +#' @examples +#' # This example creates the necessary R objects to hold an RDF model and reads +#' # in a file that contains RDF/XML statements. This model is then queried for +#' # and the query results inspected. +#' world <- new("World") +#' storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +#' model <- new("Model", world, storage, options="") +#' filePath <- system.file("extdata/example.rdf", package="redland") +#' parser <- new("Parser", world) +#' parseFileIntoModel(parser, world, filePath, model) +#' queryString <- paste("PREFIX dc: ", +#' "SELECT ?a ?c WHERE { ?a dc:description ?c . }", sep="") +#' query <- new("Query", world, queryString, base_uri=NULL, +#' query_language="sparql", query_uri=NULL) +#' results <- getResults(query, model, "rdfxml") +#' +#' # When the query object is no longer needed, the resources it had allocated can be freed. +#' freeQuery(query) +#' rm(query) +#' @docType package +#' @name redland +#' @author Matthew B. Jones (NCEAS) and Peter Slaughter (NCEAS) +NULL diff --git a/R/redland/R/redland.R b/R/redland/R/redland.R new file mode 100644 index 000000000..6a637250f --- /dev/null +++ b/R/redland/R/redland.R @@ -0,0 +1,3112 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 3.0.12 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +## Generated via the command line invocation: +## swig -r -namespace -v -I. -module redland -outdir redland/R -o redland/src/redland.c Redland.i + + +# srun.swg # +# +# This is the basic code that is needed at run time within R to +# provide and define the relevant classes. It is included +# automatically in the generated code by copying the contents of +# srun.swg into the newly created binding code. + + +# This could be provided as a separate run-time library but this +# approach allows the code to to be included directly into the +# generated bindings and so removes the need to have and install an +# additional library. We may however end up with multiple copies of +# this and some confusion at run-time as to which class to use. This +# is an issue when we use NAMESPACES as we may need to export certain +# classes. + +###################################################################### + +if(length(getClassDef("RSWIGStruct")) == 0) + setClass("RSWIGStruct", representation("VIRTUAL")) + + + +if(length(getClassDef("ExternalReference")) == 0) +# Should be virtual but this means it loses its slots currently +#representation("VIRTUAL") + setClass("ExternalReference", representation( ref = "externalptr")) + + + +if(length(getClassDef("NativeRoutinePointer")) == 0) + setClass("NativeRoutinePointer", + representation(parameterTypes = "character", + returnType = "character", + "VIRTUAL"), + contains = "ExternalReference") + +if(length(getClassDef("CRoutinePointer")) == 0) + setClass("CRoutinePointer", contains = "NativeRoutinePointer") + + +if(length(getClassDef("EnumerationValue")) == 0) + setClass("EnumerationValue", contains = "integer") + + +if(!isGeneric("copyToR")) + setGeneric("copyToR", + function(value, obj = new(gsub("Ref$", "", class(value)))) + standardGeneric("copyToR" + )) + +setGeneric("delete", function(obj) standardGeneric("delete")) + + +SWIG_createNewRef = +function(className, ..., append = TRUE) +{ + f = get(paste("new", className, sep = "_"), mode = "function") + + f(...) +} + +if(!isGeneric("copyToC")) + setGeneric("copyToC", + function(value, obj = SWIG_createNewRef(class(value))) + standardGeneric("copyToC" + )) + + +# +defineEnumeration = +function(name, .values, where = topenv(parent.frame()), suffix = "Value") +{ + # Mirror the class definitions via the E analogous to .__C__ + defName = paste(".__E__", name, sep = "") + assign(defName, .values, envir = where) + + if(nchar(suffix)) + name = paste(name, suffix, sep = "") + + setClass(name, contains = "EnumerationValue", where = where) +} + +enumToInteger <- function(name,type) +{ + if (is.character(name)) { + ans <- as.integer(get(paste(".__E__", type, sep = ""))[name]) + if (is.na(ans)) {warning("enum not found ", name, " ", type)} + ans + } +} + +enumFromInteger = +function(i,type) +{ + itemlist <- get(paste(".__E__", type, sep="")) + names(itemlist)[match(i, itemlist)] +} + +coerceIfNotSubclass = +function(obj, type) +{ + if(!is(obj, type)) {as(obj, type)} else obj +} + + +setClass("SWIGArray", representation(dims = "integer"), contains = "ExternalReference") + +setMethod("length", "SWIGArray", function(x) x@dims[1]) + + +defineEnumeration("SCopyReferences", + .values = c( "FALSE" = 0, "TRUE" = 1, "DEEP" = 2)) + +assert = +function(condition, message = "") +{ + if(!condition) + stop(message) + + TRUE +} + + +if(FALSE) { +print.SWIGFunction = +function(x, ...) + { + } +} + + +####################################################################### + +R_SWIG_getCallbackFunctionStack = +function() +{ + # No PACKAGE argument as we don't know what the DLL is. + .Call("R_SWIG_debug_getCallbackFunctionData") +} + +R_SWIG_addCallbackFunctionStack = +function(fun, userData = NULL) +{ + # No PACKAGE argument as we don't know what the DLL is. + .Call("R_SWIG_R_pushCallbackFunctionData", fun, userData) +} + + +####################################################################### + + + +setClass('_p_librdf_world_s', contains = 'ExternalReference') +setClass('_p_librdf_digest_s', contains = 'ExternalReference') +setClass('_p_librdf_hash_s', contains = 'ExternalReference') +setClass('_p_librdf_uri_s', contains = 'ExternalReference') +setClass('_p_librdf_iterator_s', contains = 'ExternalReference') +setClass('_p_librdf_node_s', contains = 'ExternalReference') +setClass('_p_librdf_statement_s', contains = 'ExternalReference') +setClass('_p_librdf_model_s', contains = 'ExternalReference') +setClass('_p_librdf_storage_s', contains = 'ExternalReference') +setClass('_p_librdf_stream_s', contains = 'ExternalReference') +setClass('_p_librdf_parser_s', contains = 'ExternalReference') +setClass('_p_librdf_serializer_s', contains = 'ExternalReference') + + + +setMethod('[', "ExternalReference", +function(x,i,j, ..., drop=TRUE) +if (!is.null(x$"__getitem__")) +sapply(i, function(n) x$"__getitem__"(i=as.integer(n-1)))) + +setMethod('[<-' , "ExternalReference", +function(x,i,j, ..., value) +if (!is.null(x$"__setitem__")) { +sapply(1:length(i), function(n) +x$"__setitem__"(i=as.integer(i[n]-1), x=value[n])) +x +}) + +setAs('ExternalReference', 'character', +function(from) {if (!is.null(from$"__str__")) from$"__str__"()}) + +suppressMessages(suppressWarnings(setMethod('print', 'ExternalReference', +function(x) {print(as(x, "character"))}))) + +# Start of librdf_new_digest + +`librdf_new_digest` = function(world, name) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + name = as(name, "character"); + ;ans = .Call('R_swig_librdf_new_digest', world, name, PACKAGE='redland'); + ans <- new("_p_librdf_digest_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_digest`, 'returnType') = '_p_librdf_digest_s' +attr(`librdf_new_digest`, "inputTypes") = c('_p_librdf_world_s', 'character') +class(`librdf_new_digest`) = c("SWIGFunction", class('librdf_new_digest')) + +# Start of librdf_free_digest + +`librdf_free_digest` = function(digest) +{ + if (inherits(digest, "ExternalReference")) digest = slot(digest,"ref") + ;.Call('R_swig_librdf_free_digest', digest, PACKAGE='redland'); + +} + +attr(`librdf_free_digest`, 'returnType') = 'void' +attr(`librdf_free_digest`, "inputTypes") = c('_p_librdf_digest_s') +class(`librdf_free_digest`) = c("SWIGFunction", class('librdf_free_digest')) + +# Start of librdf_digest_init + +`librdf_digest_init` = function(digest) +{ + if (inherits(digest, "ExternalReference")) digest = slot(digest,"ref") + ;.Call('R_swig_librdf_digest_init', digest, PACKAGE='redland'); + +} + +attr(`librdf_digest_init`, 'returnType') = 'void' +attr(`librdf_digest_init`, "inputTypes") = c('_p_librdf_digest_s') +class(`librdf_digest_init`) = c("SWIGFunction", class('librdf_digest_init')) + +# Start of librdf_digest_update + +`librdf_digest_update` = function(digest, buf, length) +{ + if (inherits(digest, "ExternalReference")) digest = slot(digest,"ref") + buf = as(buf, "character"); + length = as.integer(length); + + if(length(length) > 1) { + warning("using only the first element of length"); + }; + + ;.Call('R_swig_librdf_digest_update', digest, buf, length, PACKAGE='redland'); + +} + +attr(`librdf_digest_update`, 'returnType') = 'void' +attr(`librdf_digest_update`, "inputTypes") = c('_p_librdf_digest_s', 'character', 'integer') +class(`librdf_digest_update`) = c("SWIGFunction", class('librdf_digest_update')) + +# Start of librdf_digest_update_string + +`librdf_digest_update_string` = function(digest, string) +{ + if (inherits(digest, "ExternalReference")) digest = slot(digest,"ref") + string = as(string, "character"); + ;.Call('R_swig_librdf_digest_update_string', digest, string, PACKAGE='redland'); + +} + +attr(`librdf_digest_update_string`, 'returnType') = 'void' +attr(`librdf_digest_update_string`, "inputTypes") = c('_p_librdf_digest_s', 'character') +class(`librdf_digest_update_string`) = c("SWIGFunction", class('librdf_digest_update_string')) + +# Start of librdf_digest_final + +`librdf_digest_final` = function(digest) +{ + if (inherits(digest, "ExternalReference")) digest = slot(digest,"ref") + ;.Call('R_swig_librdf_digest_final', digest, PACKAGE='redland'); + +} + +attr(`librdf_digest_final`, 'returnType') = 'void' +attr(`librdf_digest_final`, "inputTypes") = c('_p_librdf_digest_s') +class(`librdf_digest_final`) = c("SWIGFunction", class('librdf_digest_final')) + +# Start of librdf_digest_to_string + +`librdf_digest_to_string` = function(digest) +{ + if (inherits(digest, "ExternalReference")) digest = slot(digest,"ref") + ;.Call('R_swig_librdf_digest_to_string', digest, PACKAGE='redland'); + +} + +attr(`librdf_digest_to_string`, 'returnType') = 'character' +attr(`librdf_digest_to_string`, "inputTypes") = c('_p_librdf_digest_s') +class(`librdf_digest_to_string`) = c("SWIGFunction", class('librdf_digest_to_string')) + +# Start of librdf_new_hash + +`librdf_new_hash` = function(world, name) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + name = as(name, "character"); + ;ans = .Call('R_swig_librdf_new_hash', world, name, PACKAGE='redland'); + ans <- new("_p_librdf_hash_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_hash`, 'returnType') = '_p_librdf_hash_s' +attr(`librdf_new_hash`, "inputTypes") = c('_p_librdf_world_s', 'character') +class(`librdf_new_hash`) = c("SWIGFunction", class('librdf_new_hash')) + +# Start of librdf_new_hash_from_string + +`librdf_new_hash_from_string` = function(world, name, string) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + name = as(name, "character"); + string = as(string, "character"); + ;ans = .Call('R_swig_librdf_new_hash_from_string', world, name, string, PACKAGE='redland'); + ans <- new("_p_librdf_hash_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_hash_from_string`, 'returnType') = '_p_librdf_hash_s' +attr(`librdf_new_hash_from_string`, "inputTypes") = c('_p_librdf_world_s', 'character', 'character') +class(`librdf_new_hash_from_string`) = c("SWIGFunction", class('librdf_new_hash_from_string')) + +# Start of librdf_new_hash_from_array_of_strings + +`librdf_new_hash_from_array_of_strings` = function(world, name, string) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + name = as(name, "character"); + if (inherits(string, "ExternalReference")) string = slot(string,"ref") + ;ans = .Call('R_swig_librdf_new_hash_from_array_of_strings', world, name, string, PACKAGE='redland'); + ans <- new("_p_librdf_hash_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_hash_from_array_of_strings`, 'returnType') = '_p_librdf_hash_s' +attr(`librdf_new_hash_from_array_of_strings`, "inputTypes") = c('_p_librdf_world_s', 'character', 'character') +class(`librdf_new_hash_from_array_of_strings`) = c("SWIGFunction", class('librdf_new_hash_from_array_of_strings')) + +# Start of librdf_hash_to_string + +`librdf_hash_to_string` = function(hash, filter) +{ + if (inherits(hash, "ExternalReference")) hash = slot(hash,"ref") + if (inherits(filter, "ExternalReference")) filter = slot(filter,"ref") + ;.Call('R_swig_librdf_hash_to_string', hash, filter, PACKAGE='redland'); + +} + +attr(`librdf_hash_to_string`, 'returnType') = 'character' +attr(`librdf_hash_to_string`, "inputTypes") = c('_p_librdf_hash_s', '_p_p_char') +class(`librdf_hash_to_string`) = c("SWIGFunction", class('librdf_hash_to_string')) + +# Start of librdf_free_hash + +`librdf_free_hash` = function(hash) +{ + if (inherits(hash, "ExternalReference")) hash = slot(hash,"ref") + ;.Call('R_swig_librdf_free_hash', hash, PACKAGE='redland'); + +} + +attr(`librdf_free_hash`, 'returnType') = 'void' +attr(`librdf_free_hash`, "inputTypes") = c('_p_librdf_hash_s') +class(`librdf_free_hash`) = c("SWIGFunction", class('librdf_free_hash')) + +# Start of librdf_new_world + +`librdf_new_world` = function() +{ + ;ans = .Call('R_swig_librdf_new_world', PACKAGE='redland'); + ans <- new("_p_librdf_world_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_world`, 'returnType') = '_p_librdf_world_s' +class(`librdf_new_world`) = c("SWIGFunction", class('librdf_new_world')) + +# Start of librdf_free_world + +`librdf_free_world` = function(world) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + ;.Call('R_swig_librdf_free_world', world, PACKAGE='redland'); + +} + +attr(`librdf_free_world`, 'returnType') = 'void' +attr(`librdf_free_world`, "inputTypes") = c('_p_librdf_world_s') +class(`librdf_free_world`) = c("SWIGFunction", class('librdf_free_world')) + +# Start of librdf_world_open + +`librdf_world_open` = function(world) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + ;.Call('R_swig_librdf_world_open', world, PACKAGE='redland'); + +} + +attr(`librdf_world_open`, 'returnType') = 'void' +attr(`librdf_world_open`, "inputTypes") = c('_p_librdf_world_s') +class(`librdf_world_open`) = c("SWIGFunction", class('librdf_world_open')) + +# Start of librdf_world_get_feature + +`librdf_world_get_feature` = function(world, feature) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + if (inherits(feature, "ExternalReference")) feature = slot(feature,"ref") + ;ans = .Call('R_swig_librdf_world_get_feature', world, feature, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_world_get_feature`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_world_get_feature`, "inputTypes") = c('_p_librdf_world_s', '_p_librdf_uri_s') +class(`librdf_world_get_feature`) = c("SWIGFunction", class('librdf_world_get_feature')) + +# Start of librdf_world_set_feature + +`librdf_world_set_feature` = function(world, feature, value, .copy = FALSE) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + if (inherits(feature, "ExternalReference")) feature = slot(feature,"ref") + if (inherits(value, "ExternalReference")) value = slot(value,"ref") + ;.Call('R_swig_librdf_world_set_feature', world, feature, value, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_world_set_feature`, 'returnType') = 'integer' +attr(`librdf_world_set_feature`, "inputTypes") = c('_p_librdf_world_s', '_p_librdf_uri_s', '_p_librdf_node_s') +class(`librdf_world_set_feature`) = c("SWIGFunction", class('librdf_world_set_feature')) + +# Start of librdf_parser_get_accept_header + +`librdf_parser_get_accept_header` = function(parser) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + ;.Call('R_swig_librdf_parser_get_accept_header', parser, PACKAGE='redland'); + +} + +attr(`librdf_parser_get_accept_header`, 'returnType') = 'character' +attr(`librdf_parser_get_accept_header`, "inputTypes") = c('_p_librdf_parser_s') +class(`librdf_parser_get_accept_header`) = c("SWIGFunction", class('librdf_parser_get_accept_header')) + +# Start of librdf_world_set_logger + +`librdf_world_set_logger` = function(world, user_data, log_handler) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + if (inherits(user_data, "ExternalReference")) user_data = slot(user_data,"ref") + if (inherits(log_handler, "ExternalReference")) log_handler = slot(log_handler,"ref") + ;.Call('R_swig_librdf_world_set_logger', world, user_data, log_handler, PACKAGE='redland'); + +} + +attr(`librdf_world_set_logger`, 'returnType') = 'void' +attr(`librdf_world_set_logger`, "inputTypes") = c('_p_librdf_world_s', '_p_void', '_p_librdf_log_func') +class(`librdf_world_set_logger`) = c("SWIGFunction", class('librdf_world_set_logger')) + +# Start of librdf_free_iterator + +`librdf_free_iterator` = function(s_arg1) +{ + if (inherits(s_arg1, "ExternalReference")) s_arg1 = slot(s_arg1,"ref") + ;.Call('R_swig_librdf_free_iterator', s_arg1, PACKAGE='redland'); + +} + +attr(`librdf_free_iterator`, 'returnType') = 'void' +attr(`librdf_free_iterator`, "inputTypes") = c('_p_librdf_iterator_s') +class(`librdf_free_iterator`) = c("SWIGFunction", class('librdf_free_iterator')) + +# Start of librdf_iterator_end + +`librdf_iterator_end` = function(iterator, .copy = FALSE) +{ + if (inherits(iterator, "ExternalReference")) iterator = slot(iterator,"ref") + ;.Call('R_swig_librdf_iterator_end', iterator, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_iterator_end`, 'returnType') = 'integer' +attr(`librdf_iterator_end`, "inputTypes") = c('_p_librdf_iterator_s') +class(`librdf_iterator_end`) = c("SWIGFunction", class('librdf_iterator_end')) + +# Start of librdf_iterator_get_object + +`librdf_iterator_get_object` = function(iterator) +{ + if (inherits(iterator, "ExternalReference")) iterator = slot(iterator,"ref") + ;ans = .Call('R_swig_librdf_iterator_get_object', iterator, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_iterator_get_object`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_iterator_get_object`, "inputTypes") = c('_p_librdf_iterator_s') +class(`librdf_iterator_get_object`) = c("SWIGFunction", class('librdf_iterator_get_object')) + +# Start of librdf_iterator_get_context + +`librdf_iterator_get_context` = function(iterator) +{ + if (inherits(iterator, "ExternalReference")) iterator = slot(iterator,"ref") + ;ans = .Call('R_swig_librdf_iterator_get_context', iterator, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_iterator_get_context`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_iterator_get_context`, "inputTypes") = c('_p_librdf_iterator_s') +class(`librdf_iterator_get_context`) = c("SWIGFunction", class('librdf_iterator_get_context')) + +# Start of librdf_iterator_next + +`librdf_iterator_next` = function(iterator, .copy = FALSE) +{ + if (inherits(iterator, "ExternalReference")) iterator = slot(iterator,"ref") + ;.Call('R_swig_librdf_iterator_next', iterator, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_iterator_next`, 'returnType') = 'integer' +attr(`librdf_iterator_next`, "inputTypes") = c('_p_librdf_iterator_s') +class(`librdf_iterator_next`) = c("SWIGFunction", class('librdf_iterator_next')) + +# Start of librdf_new_uri + +`librdf_new_uri` = function(world, string) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + string = as(string, "character"); + ;ans = .Call('R_swig_librdf_new_uri', world, string, PACKAGE='redland'); + ans <- new("_p_librdf_uri_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_uri`, 'returnType') = '_p_librdf_uri_s' +attr(`librdf_new_uri`, "inputTypes") = c('_p_librdf_world_s', 'character') +class(`librdf_new_uri`) = c("SWIGFunction", class('librdf_new_uri')) + +# Start of librdf_new_uri_from_uri + +`librdf_new_uri_from_uri` = function(uri) +{ + if (inherits(uri, "ExternalReference")) uri = slot(uri,"ref") + ;ans = .Call('R_swig_librdf_new_uri_from_uri', uri, PACKAGE='redland'); + ans <- new("_p_librdf_uri_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_uri_from_uri`, 'returnType') = '_p_librdf_uri_s' +attr(`librdf_new_uri_from_uri`, "inputTypes") = c('_p_librdf_uri_s') +class(`librdf_new_uri_from_uri`) = c("SWIGFunction", class('librdf_new_uri_from_uri')) + +# Start of librdf_new_uri_from_filename + +`librdf_new_uri_from_filename` = function(world, filename) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + filename = as(filename, "character"); + ;ans = .Call('R_swig_librdf_new_uri_from_filename', world, filename, PACKAGE='redland'); + ans <- new("_p_librdf_uri_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_uri_from_filename`, 'returnType') = '_p_librdf_uri_s' +attr(`librdf_new_uri_from_filename`, "inputTypes") = c('_p_librdf_world_s', 'character') +class(`librdf_new_uri_from_filename`) = c("SWIGFunction", class('librdf_new_uri_from_filename')) + +# Start of librdf_free_uri + +`librdf_free_uri` = function(uri) +{ + if (inherits(uri, "ExternalReference")) uri = slot(uri,"ref") + ;.Call('R_swig_librdf_free_uri', uri, PACKAGE='redland'); + +} + +attr(`librdf_free_uri`, 'returnType') = 'void' +attr(`librdf_free_uri`, "inputTypes") = c('_p_librdf_uri_s') +class(`librdf_free_uri`) = c("SWIGFunction", class('librdf_free_uri')) + +# Start of librdf_uri_to_string + +`librdf_uri_to_string` = function(uri) +{ + if (inherits(uri, "ExternalReference")) uri = slot(uri,"ref") + ;.Call('R_swig_librdf_uri_to_string', uri, PACKAGE='redland'); + +} + +attr(`librdf_uri_to_string`, 'returnType') = 'character' +attr(`librdf_uri_to_string`, "inputTypes") = c('_p_librdf_uri_s') +class(`librdf_uri_to_string`) = c("SWIGFunction", class('librdf_uri_to_string')) + +# Start of librdf_uri_equals + +`librdf_uri_equals` = function(first_uri, second_uri, .copy = FALSE) +{ + if (inherits(first_uri, "ExternalReference")) first_uri = slot(first_uri,"ref") + if (inherits(second_uri, "ExternalReference")) second_uri = slot(second_uri,"ref") + ;.Call('R_swig_librdf_uri_equals', first_uri, second_uri, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_uri_equals`, 'returnType') = 'integer' +attr(`librdf_uri_equals`, "inputTypes") = c('_p_librdf_uri_s', '_p_librdf_uri_s') +class(`librdf_uri_equals`) = c("SWIGFunction", class('librdf_uri_equals')) + +# Start of librdf_uri_compare + +`librdf_uri_compare` = function(first_uri, second_uri, .copy = FALSE) +{ + if (inherits(first_uri, "ExternalReference")) first_uri = slot(first_uri,"ref") + if (inherits(second_uri, "ExternalReference")) second_uri = slot(second_uri,"ref") + ;.Call('R_swig_librdf_uri_compare', first_uri, second_uri, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_uri_compare`, 'returnType') = 'integer' +attr(`librdf_uri_compare`, "inputTypes") = c('_p_librdf_uri_s', '_p_librdf_uri_s') +class(`librdf_uri_compare`) = c("SWIGFunction", class('librdf_uri_compare')) + +# Start of librdf_new_node + +`librdf_new_node` = function(world) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + ;ans = .Call('R_swig_librdf_new_node', world, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_node`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_new_node`, "inputTypes") = c('_p_librdf_world_s') +class(`librdf_new_node`) = c("SWIGFunction", class('librdf_new_node')) + +# Start of librdf_new_node_from_uri_string + +`librdf_new_node_from_uri_string` = function(world, string) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + string = as(string, "character"); + ;ans = .Call('R_swig_librdf_new_node_from_uri_string', world, string, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_node_from_uri_string`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_new_node_from_uri_string`, "inputTypes") = c('_p_librdf_world_s', 'character') +class(`librdf_new_node_from_uri_string`) = c("SWIGFunction", class('librdf_new_node_from_uri_string')) + +# Start of librdf_new_node_from_uri + +`librdf_new_node_from_uri` = function(world, uri) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + if (inherits(uri, "ExternalReference")) uri = slot(uri,"ref") + ;ans = .Call('R_swig_librdf_new_node_from_uri', world, uri, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_node_from_uri`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_new_node_from_uri`, "inputTypes") = c('_p_librdf_world_s', '_p_librdf_uri_s') +class(`librdf_new_node_from_uri`) = c("SWIGFunction", class('librdf_new_node_from_uri')) + +# Start of librdf_new_node_from_uri_local_name + +`librdf_new_node_from_uri_local_name` = function(world, uri, local_name) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + if (inherits(uri, "ExternalReference")) uri = slot(uri,"ref") + local_name = as(local_name, "character"); + ;ans = .Call('R_swig_librdf_new_node_from_uri_local_name', world, uri, local_name, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_node_from_uri_local_name`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_new_node_from_uri_local_name`, "inputTypes") = c('_p_librdf_world_s', '_p_librdf_uri_s', 'character') +class(`librdf_new_node_from_uri_local_name`) = c("SWIGFunction", class('librdf_new_node_from_uri_local_name')) + +# Start of librdf_new_node_from_normalised_uri_string + +`librdf_new_node_from_normalised_uri_string` = function(world, uri_string, source_uri, base_uri) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + uri_string = as(uri_string, "character"); + if (inherits(source_uri, "ExternalReference")) source_uri = slot(source_uri,"ref") + if (inherits(base_uri, "ExternalReference")) base_uri = slot(base_uri,"ref") + ;ans = .Call('R_swig_librdf_new_node_from_normalised_uri_string', world, uri_string, source_uri, base_uri, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_node_from_normalised_uri_string`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_new_node_from_normalised_uri_string`, "inputTypes") = c('_p_librdf_world_s', 'character', '_p_librdf_uri_s', '_p_librdf_uri_s') +class(`librdf_new_node_from_normalised_uri_string`) = c("SWIGFunction", class('librdf_new_node_from_normalised_uri_string')) + +# Start of librdf_new_node_from_literal + +`librdf_new_node_from_literal` = function(world, string, inStrOrNull, is_wf_xml) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + string = as(string, "character"); + inStrOrNull = as(inStrOrNull, "character"); + is_wf_xml = as.integer(is_wf_xml); + + if(length(is_wf_xml) > 1) { + warning("using only the first element of is_wf_xml"); + }; + + ;ans = .Call('R_swig_librdf_new_node_from_literal', world, string, inStrOrNull, is_wf_xml, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_node_from_literal`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_new_node_from_literal`, "inputTypes") = c('_p_librdf_world_s', 'character', 'character', 'integer') +class(`librdf_new_node_from_literal`) = c("SWIGFunction", class('librdf_new_node_from_literal')) + +# Start of librdf_new_node_from_typed_literal + +`librdf_new_node_from_typed_literal` = function(world, string, inStrOrNull, inUriOrNull) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + string = as(string, "character"); + inStrOrNull = as(inStrOrNull, "character"); + if (inherits(inUriOrNull, "ExternalReference")) inUriOrNull = slot(inUriOrNull,"ref") + ;ans = .Call('R_swig_librdf_new_node_from_typed_literal', world, string, inStrOrNull, inUriOrNull, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_node_from_typed_literal`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_new_node_from_typed_literal`, "inputTypes") = c('_p_librdf_world_s', 'character', 'character', '_p_librdf_uri_s') +class(`librdf_new_node_from_typed_literal`) = c("SWIGFunction", class('librdf_new_node_from_typed_literal')) + +# Start of librdf_new_node_from_node + +`librdf_new_node_from_node` = function(node) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;ans = .Call('R_swig_librdf_new_node_from_node', node, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_node_from_node`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_new_node_from_node`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_new_node_from_node`) = c("SWIGFunction", class('librdf_new_node_from_node')) + +# Start of librdf_new_node_from_blank_identifier + +`librdf_new_node_from_blank_identifier` = function(world, inStrOrNull) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + inStrOrNull = as(inStrOrNull, "character"); + ;ans = .Call('R_swig_librdf_new_node_from_blank_identifier', world, inStrOrNull, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_node_from_blank_identifier`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_new_node_from_blank_identifier`, "inputTypes") = c('_p_librdf_world_s', 'character') +class(`librdf_new_node_from_blank_identifier`) = c("SWIGFunction", class('librdf_new_node_from_blank_identifier')) + +# Start of librdf_free_node + +`librdf_free_node` = function(r) +{ + if (inherits(r, "ExternalReference")) r = slot(r,"ref") + ;.Call('R_swig_librdf_free_node', r, PACKAGE='redland'); + +} + +attr(`librdf_free_node`, 'returnType') = 'void' +attr(`librdf_free_node`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_free_node`) = c("SWIGFunction", class('librdf_free_node')) + +# Start of librdf_node_get_uri + +`librdf_node_get_uri` = function(node) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;ans = .Call('R_swig_librdf_node_get_uri', node, PACKAGE='redland'); + ans <- new("_p_librdf_uri_s", ref=ans) ; + + ans + +} + +attr(`librdf_node_get_uri`, 'returnType') = '_p_librdf_uri_s' +attr(`librdf_node_get_uri`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_get_uri`) = c("SWIGFunction", class('librdf_node_get_uri')) + +# Start of librdf_node_get_type + +`librdf_node_get_type` = function(node, .copy = FALSE) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;.Call('R_swig_librdf_node_get_type', node, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_node_get_type`, 'returnType') = 'integer' +attr(`librdf_node_get_type`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_get_type`) = c("SWIGFunction", class('librdf_node_get_type')) + +# Start of librdf_node_get_literal_value + +`librdf_node_get_literal_value` = function(node) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;.Call('R_swig_librdf_node_get_literal_value', node, PACKAGE='redland'); + +} + +attr(`librdf_node_get_literal_value`, 'returnType') = 'character' +attr(`librdf_node_get_literal_value`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_get_literal_value`) = c("SWIGFunction", class('librdf_node_get_literal_value')) + +# Start of librdf_node_get_literal_value_as_latin1 + +`librdf_node_get_literal_value_as_latin1` = function(node) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;.Call('R_swig_librdf_node_get_literal_value_as_latin1', node, PACKAGE='redland'); + +} + +attr(`librdf_node_get_literal_value_as_latin1`, 'returnType') = 'character' +attr(`librdf_node_get_literal_value_as_latin1`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_get_literal_value_as_latin1`) = c("SWIGFunction", class('librdf_node_get_literal_value_as_latin1')) + +# Start of librdf_node_get_literal_value_language + +`librdf_node_get_literal_value_language` = function(node) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;.Call('R_swig_librdf_node_get_literal_value_language', node, PACKAGE='redland'); + +} + +attr(`librdf_node_get_literal_value_language`, 'returnType') = 'character' +attr(`librdf_node_get_literal_value_language`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_get_literal_value_language`) = c("SWIGFunction", class('librdf_node_get_literal_value_language')) + +# Start of librdf_node_get_literal_value_datatype_uri + +`librdf_node_get_literal_value_datatype_uri` = function(node) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;ans = .Call('R_swig_librdf_node_get_literal_value_datatype_uri', node, PACKAGE='redland'); + ans <- new("_p_librdf_uri_s", ref=ans) ; + + ans + +} + +attr(`librdf_node_get_literal_value_datatype_uri`, 'returnType') = '_p_librdf_uri_s' +attr(`librdf_node_get_literal_value_datatype_uri`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_get_literal_value_datatype_uri`) = c("SWIGFunction", class('librdf_node_get_literal_value_datatype_uri')) + +# Start of librdf_node_get_literal_value_is_wf_xml + +`librdf_node_get_literal_value_is_wf_xml` = function(node, .copy = FALSE) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;.Call('R_swig_librdf_node_get_literal_value_is_wf_xml', node, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_node_get_literal_value_is_wf_xml`, 'returnType') = 'integer' +attr(`librdf_node_get_literal_value_is_wf_xml`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_get_literal_value_is_wf_xml`) = c("SWIGFunction", class('librdf_node_get_literal_value_is_wf_xml')) + +# Start of librdf_node_get_li_ordinal + +`librdf_node_get_li_ordinal` = function(node, .copy = FALSE) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;.Call('R_swig_librdf_node_get_li_ordinal', node, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_node_get_li_ordinal`, 'returnType') = 'integer' +attr(`librdf_node_get_li_ordinal`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_get_li_ordinal`) = c("SWIGFunction", class('librdf_node_get_li_ordinal')) + +# Start of librdf_node_get_blank_identifier + +`librdf_node_get_blank_identifier` = function(node) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;.Call('R_swig_librdf_node_get_blank_identifier', node, PACKAGE='redland'); + +} + +attr(`librdf_node_get_blank_identifier`, 'returnType') = 'character' +attr(`librdf_node_get_blank_identifier`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_get_blank_identifier`) = c("SWIGFunction", class('librdf_node_get_blank_identifier')) + +# Start of librdf_node_is_resource + +`librdf_node_is_resource` = function(node, .copy = FALSE) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;.Call('R_swig_librdf_node_is_resource', node, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_node_is_resource`, 'returnType') = 'integer' +attr(`librdf_node_is_resource`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_is_resource`) = c("SWIGFunction", class('librdf_node_is_resource')) + +# Start of librdf_node_is_literal + +`librdf_node_is_literal` = function(node, .copy = FALSE) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;.Call('R_swig_librdf_node_is_literal', node, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_node_is_literal`, 'returnType') = 'integer' +attr(`librdf_node_is_literal`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_is_literal`) = c("SWIGFunction", class('librdf_node_is_literal')) + +# Start of librdf_node_is_blank + +`librdf_node_is_blank` = function(node, .copy = FALSE) +{ + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;.Call('R_swig_librdf_node_is_blank', node, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_node_is_blank`, 'returnType') = 'integer' +attr(`librdf_node_is_blank`, "inputTypes") = c('_p_librdf_node_s') +class(`librdf_node_is_blank`) = c("SWIGFunction", class('librdf_node_is_blank')) + +# Start of librdf_node_equals + +`librdf_node_equals` = function(first_node, second_node, .copy = FALSE) +{ + if (inherits(first_node, "ExternalReference")) first_node = slot(first_node,"ref") + if (inherits(second_node, "ExternalReference")) second_node = slot(second_node,"ref") + ;.Call('R_swig_librdf_node_equals', first_node, second_node, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_node_equals`, 'returnType') = 'integer' +attr(`librdf_node_equals`, "inputTypes") = c('_p_librdf_node_s', '_p_librdf_node_s') +class(`librdf_node_equals`) = c("SWIGFunction", class('librdf_node_equals')) + +# Start of librdf_new_statement + +`librdf_new_statement` = function(world) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + ;ans = .Call('R_swig_librdf_new_statement', world, PACKAGE='redland'); + ans <- new("_p_librdf_statement_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_statement`, 'returnType') = '_p_librdf_statement_s' +attr(`librdf_new_statement`, "inputTypes") = c('_p_librdf_world_s') +class(`librdf_new_statement`) = c("SWIGFunction", class('librdf_new_statement')) + +# Start of librdf_new_statement_from_statement + +`librdf_new_statement_from_statement` = function(statement) +{ + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;ans = .Call('R_swig_librdf_new_statement_from_statement', statement, PACKAGE='redland'); + ans <- new("_p_librdf_statement_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_statement_from_statement`, 'returnType') = '_p_librdf_statement_s' +attr(`librdf_new_statement_from_statement`, "inputTypes") = c('_p_librdf_statement_s') +class(`librdf_new_statement_from_statement`) = c("SWIGFunction", class('librdf_new_statement_from_statement')) + +# Start of librdf_new_statement_from_nodes + +`librdf_new_statement_from_nodes` = function(world, subject, predicate, object) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + if (inherits(subject, "ExternalReference")) subject = slot(subject,"ref") + if (inherits(predicate, "ExternalReference")) predicate = slot(predicate,"ref") + if (inherits(object, "ExternalReference")) object = slot(object,"ref") + ;ans = .Call('R_swig_librdf_new_statement_from_nodes', world, subject, predicate, object, PACKAGE='redland'); + ans <- new("_p_librdf_statement_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_statement_from_nodes`, 'returnType') = '_p_librdf_statement_s' +attr(`librdf_new_statement_from_nodes`, "inputTypes") = c('_p_librdf_world_s', '_p_librdf_node_s', '_p_librdf_node_s', '_p_librdf_node_s') +class(`librdf_new_statement_from_nodes`) = c("SWIGFunction", class('librdf_new_statement_from_nodes')) + +# Start of librdf_free_statement + +`librdf_free_statement` = function(statement) +{ + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;.Call('R_swig_librdf_free_statement', statement, PACKAGE='redland'); + +} + +attr(`librdf_free_statement`, 'returnType') = 'void' +attr(`librdf_free_statement`, "inputTypes") = c('_p_librdf_statement_s') +class(`librdf_free_statement`) = c("SWIGFunction", class('librdf_free_statement')) + +# Start of librdf_statement_get_subject + +`librdf_statement_get_subject` = function(statement) +{ + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;ans = .Call('R_swig_librdf_statement_get_subject', statement, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_statement_get_subject`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_statement_get_subject`, "inputTypes") = c('_p_librdf_statement_s') +class(`librdf_statement_get_subject`) = c("SWIGFunction", class('librdf_statement_get_subject')) + +# Start of librdf_statement_set_subject + +`librdf_statement_set_subject` = function(statement, subject) +{ + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + if (inherits(subject, "ExternalReference")) subject = slot(subject,"ref") + ;.Call('R_swig_librdf_statement_set_subject', statement, subject, PACKAGE='redland'); + +} + +attr(`librdf_statement_set_subject`, 'returnType') = 'void' +attr(`librdf_statement_set_subject`, "inputTypes") = c('_p_librdf_statement_s', '_p_librdf_node_s') +class(`librdf_statement_set_subject`) = c("SWIGFunction", class('librdf_statement_set_subject')) + +# Start of librdf_statement_get_predicate + +`librdf_statement_get_predicate` = function(statement) +{ + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;ans = .Call('R_swig_librdf_statement_get_predicate', statement, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_statement_get_predicate`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_statement_get_predicate`, "inputTypes") = c('_p_librdf_statement_s') +class(`librdf_statement_get_predicate`) = c("SWIGFunction", class('librdf_statement_get_predicate')) + +# Start of librdf_statement_set_predicate + +`librdf_statement_set_predicate` = function(statement, predicate) +{ + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + if (inherits(predicate, "ExternalReference")) predicate = slot(predicate,"ref") + ;.Call('R_swig_librdf_statement_set_predicate', statement, predicate, PACKAGE='redland'); + +} + +attr(`librdf_statement_set_predicate`, 'returnType') = 'void' +attr(`librdf_statement_set_predicate`, "inputTypes") = c('_p_librdf_statement_s', '_p_librdf_node_s') +class(`librdf_statement_set_predicate`) = c("SWIGFunction", class('librdf_statement_set_predicate')) + +# Start of librdf_statement_get_object + +`librdf_statement_get_object` = function(statement) +{ + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;ans = .Call('R_swig_librdf_statement_get_object', statement, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_statement_get_object`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_statement_get_object`, "inputTypes") = c('_p_librdf_statement_s') +class(`librdf_statement_get_object`) = c("SWIGFunction", class('librdf_statement_get_object')) + +# Start of librdf_statement_set_object + +`librdf_statement_set_object` = function(statement, object) +{ + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + if (inherits(object, "ExternalReference")) object = slot(object,"ref") + ;.Call('R_swig_librdf_statement_set_object', statement, object, PACKAGE='redland'); + +} + +attr(`librdf_statement_set_object`, 'returnType') = 'void' +attr(`librdf_statement_set_object`, "inputTypes") = c('_p_librdf_statement_s', '_p_librdf_node_s') +class(`librdf_statement_set_object`) = c("SWIGFunction", class('librdf_statement_set_object')) + +# Start of librdf_statement_equals + +`librdf_statement_equals` = function(statement1, statement2, .copy = FALSE) +{ + if (inherits(statement1, "ExternalReference")) statement1 = slot(statement1,"ref") + if (inherits(statement2, "ExternalReference")) statement2 = slot(statement2,"ref") + ;.Call('R_swig_librdf_statement_equals', statement1, statement2, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_statement_equals`, 'returnType') = 'integer' +attr(`librdf_statement_equals`, "inputTypes") = c('_p_librdf_statement_s', '_p_librdf_statement_s') +class(`librdf_statement_equals`) = c("SWIGFunction", class('librdf_statement_equals')) + +# Start of librdf_statement_match + +`librdf_statement_match` = function(statement, partial_statement, .copy = FALSE) +{ + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + if (inherits(partial_statement, "ExternalReference")) partial_statement = slot(partial_statement,"ref") + ;.Call('R_swig_librdf_statement_match', statement, partial_statement, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_statement_match`, 'returnType') = 'integer' +attr(`librdf_statement_match`, "inputTypes") = c('_p_librdf_statement_s', '_p_librdf_statement_s') +class(`librdf_statement_match`) = c("SWIGFunction", class('librdf_statement_match')) + +# Start of librdf_statement_is_complete + +`librdf_statement_is_complete` = function(statement, .copy = FALSE) +{ + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;.Call('R_swig_librdf_statement_is_complete', statement, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_statement_is_complete`, 'returnType') = 'integer' +attr(`librdf_statement_is_complete`, "inputTypes") = c('_p_librdf_statement_s') +class(`librdf_statement_is_complete`) = c("SWIGFunction", class('librdf_statement_is_complete')) + +# Start of librdf_new_model + +`librdf_new_model` = function(world, storage, options_string) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + if (inherits(storage, "ExternalReference")) storage = slot(storage,"ref") + options_string = as(options_string, "character"); + ;ans = .Call('R_swig_librdf_new_model', world, storage, options_string, PACKAGE='redland'); + ans <- new("_p_librdf_model_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_model`, 'returnType') = '_p_librdf_model_s' +attr(`librdf_new_model`, "inputTypes") = c('_p_librdf_world_s', '_p_librdf_storage_s', 'character') +class(`librdf_new_model`) = c("SWIGFunction", class('librdf_new_model')) + +# Start of librdf_new_model_with_options + +`librdf_new_model_with_options` = function(world, storage, options) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + if (inherits(storage, "ExternalReference")) storage = slot(storage,"ref") + if (inherits(options, "ExternalReference")) options = slot(options,"ref") + ;ans = .Call('R_swig_librdf_new_model_with_options', world, storage, options, PACKAGE='redland'); + ans <- new("_p_librdf_model_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_model_with_options`, 'returnType') = '_p_librdf_model_s' +attr(`librdf_new_model_with_options`, "inputTypes") = c('_p_librdf_world_s', '_p_librdf_storage_s', '_p_librdf_hash_s') +class(`librdf_new_model_with_options`) = c("SWIGFunction", class('librdf_new_model_with_options')) + +# Start of librdf_new_model_from_model + +`librdf_new_model_from_model` = function(model) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;ans = .Call('R_swig_librdf_new_model_from_model', model, PACKAGE='redland'); + ans <- new("_p_librdf_model_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_model_from_model`, 'returnType') = '_p_librdf_model_s' +attr(`librdf_new_model_from_model`, "inputTypes") = c('_p_librdf_model_s') +class(`librdf_new_model_from_model`) = c("SWIGFunction", class('librdf_new_model_from_model')) + +# Start of librdf_free_model + +`librdf_free_model` = function(model) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;.Call('R_swig_librdf_free_model', model, PACKAGE='redland'); + +} + +attr(`librdf_free_model`, 'returnType') = 'void' +attr(`librdf_free_model`, "inputTypes") = c('_p_librdf_model_s') +class(`librdf_free_model`) = c("SWIGFunction", class('librdf_free_model')) + +# Start of librdf_model_size + +`librdf_model_size` = function(model, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;.Call('R_swig_librdf_model_size', model, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_size`, 'returnType') = 'integer' +attr(`librdf_model_size`, "inputTypes") = c('_p_librdf_model_s') +class(`librdf_model_size`) = c("SWIGFunction", class('librdf_model_size')) + +# Start of librdf_model_add + +`librdf_model_add` = function(model, subject, predicate, object, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(subject, "ExternalReference")) subject = slot(subject,"ref") + if (inherits(predicate, "ExternalReference")) predicate = slot(predicate,"ref") + if (inherits(object, "ExternalReference")) object = slot(object,"ref") + ;.Call('R_swig_librdf_model_add', model, subject, predicate, object, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_add`, 'returnType') = 'integer' +attr(`librdf_model_add`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_node_s', '_p_librdf_node_s') +class(`librdf_model_add`) = c("SWIGFunction", class('librdf_model_add')) + +# Start of librdf_model_add_string_literal_statement + +`librdf_model_add_string_literal_statement` = function(model, subject, predicate, literal, inStrOrNull, is_wf_xml, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(subject, "ExternalReference")) subject = slot(subject,"ref") + if (inherits(predicate, "ExternalReference")) predicate = slot(predicate,"ref") + literal = as(literal, "character"); + inStrOrNull = as(inStrOrNull, "character"); + is_wf_xml = as.integer(is_wf_xml); + + if(length(is_wf_xml) > 1) { + warning("using only the first element of is_wf_xml"); + }; + + ;.Call('R_swig_librdf_model_add_string_literal_statement', model, subject, predicate, literal, inStrOrNull, is_wf_xml, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_add_string_literal_statement`, 'returnType') = 'integer' +attr(`librdf_model_add_string_literal_statement`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_node_s', 'character', 'character', 'integer') +class(`librdf_model_add_string_literal_statement`) = c("SWIGFunction", class('librdf_model_add_string_literal_statement')) + +# Start of librdf_model_add_typed_literal_statement + +`librdf_model_add_typed_literal_statement` = function(model, subject, predicate, string, inStrOrNull, inUriOrNull, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(subject, "ExternalReference")) subject = slot(subject,"ref") + if (inherits(predicate, "ExternalReference")) predicate = slot(predicate,"ref") + string = as(string, "character"); + inStrOrNull = as(inStrOrNull, "character"); + if (inherits(inUriOrNull, "ExternalReference")) inUriOrNull = slot(inUriOrNull,"ref") + ;.Call('R_swig_librdf_model_add_typed_literal_statement', model, subject, predicate, string, inStrOrNull, inUriOrNull, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_add_typed_literal_statement`, 'returnType') = 'integer' +attr(`librdf_model_add_typed_literal_statement`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_node_s', 'character', 'character', '_p_librdf_uri_s') +class(`librdf_model_add_typed_literal_statement`) = c("SWIGFunction", class('librdf_model_add_typed_literal_statement')) + +# Start of librdf_model_add_statement + +`librdf_model_add_statement` = function(model, statement, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;.Call('R_swig_librdf_model_add_statement', model, statement, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_add_statement`, 'returnType') = 'integer' +attr(`librdf_model_add_statement`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_statement_s') +class(`librdf_model_add_statement`) = c("SWIGFunction", class('librdf_model_add_statement')) + +# Start of librdf_model_add_statements + +`librdf_model_add_statements` = function(model, statement_stream, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(statement_stream, "ExternalReference")) statement_stream = slot(statement_stream,"ref") + ;.Call('R_swig_librdf_model_add_statements', model, statement_stream, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_add_statements`, 'returnType') = 'integer' +attr(`librdf_model_add_statements`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_stream_s') +class(`librdf_model_add_statements`) = c("SWIGFunction", class('librdf_model_add_statements')) + +# Start of librdf_model_remove_statement + +`librdf_model_remove_statement` = function(model, statement, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;.Call('R_swig_librdf_model_remove_statement', model, statement, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_remove_statement`, 'returnType') = 'integer' +attr(`librdf_model_remove_statement`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_statement_s') +class(`librdf_model_remove_statement`) = c("SWIGFunction", class('librdf_model_remove_statement')) + +# Start of librdf_model_contains_statement + +`librdf_model_contains_statement` = function(model, statement, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;.Call('R_swig_librdf_model_contains_statement', model, statement, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_contains_statement`, 'returnType') = 'integer' +attr(`librdf_model_contains_statement`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_statement_s') +class(`librdf_model_contains_statement`) = c("SWIGFunction", class('librdf_model_contains_statement')) + +# Start of librdf_model_as_stream + +`librdf_model_as_stream` = function(model) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;ans = .Call('R_swig_librdf_model_as_stream', model, PACKAGE='redland'); + ans <- new("_p_librdf_stream_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_as_stream`, 'returnType') = '_p_librdf_stream_s' +attr(`librdf_model_as_stream`, "inputTypes") = c('_p_librdf_model_s') +class(`librdf_model_as_stream`) = c("SWIGFunction", class('librdf_model_as_stream')) + +# Start of librdf_model_find_statements + +`librdf_model_find_statements` = function(model, statement) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;ans = .Call('R_swig_librdf_model_find_statements', model, statement, PACKAGE='redland'); + ans <- new("_p_librdf_stream_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_find_statements`, 'returnType') = '_p_librdf_stream_s' +attr(`librdf_model_find_statements`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_statement_s') +class(`librdf_model_find_statements`) = c("SWIGFunction", class('librdf_model_find_statements')) + +# Start of librdf_model_find_statements_in_context + +`librdf_model_find_statements_in_context` = function(model, statement, inNodeOrNull) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + if (inherits(inNodeOrNull, "ExternalReference")) inNodeOrNull = slot(inNodeOrNull,"ref") + ;ans = .Call('R_swig_librdf_model_find_statements_in_context', model, statement, inNodeOrNull, PACKAGE='redland'); + ans <- new("_p_librdf_stream_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_find_statements_in_context`, 'returnType') = '_p_librdf_stream_s' +attr(`librdf_model_find_statements_in_context`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_statement_s', '_p_librdf_node_s') +class(`librdf_model_find_statements_in_context`) = c("SWIGFunction", class('librdf_model_find_statements_in_context')) + +# Start of librdf_model_get_sources + +`librdf_model_get_sources` = function(model, arc, target) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(arc, "ExternalReference")) arc = slot(arc,"ref") + if (inherits(target, "ExternalReference")) target = slot(target,"ref") + ;ans = .Call('R_swig_librdf_model_get_sources', model, arc, target, PACKAGE='redland'); + ans <- new("_p_librdf_iterator_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_get_sources`, 'returnType') = '_p_librdf_iterator_s' +attr(`librdf_model_get_sources`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_node_s') +class(`librdf_model_get_sources`) = c("SWIGFunction", class('librdf_model_get_sources')) + +# Start of librdf_model_get_arcs + +`librdf_model_get_arcs` = function(model, source, target) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(source, "ExternalReference")) source = slot(source,"ref") + if (inherits(target, "ExternalReference")) target = slot(target,"ref") + ;ans = .Call('R_swig_librdf_model_get_arcs', model, source, target, PACKAGE='redland'); + ans <- new("_p_librdf_iterator_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_get_arcs`, 'returnType') = '_p_librdf_iterator_s' +attr(`librdf_model_get_arcs`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_node_s') +class(`librdf_model_get_arcs`) = c("SWIGFunction", class('librdf_model_get_arcs')) + +# Start of librdf_model_get_targets + +`librdf_model_get_targets` = function(model, source, arc) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(source, "ExternalReference")) source = slot(source,"ref") + if (inherits(arc, "ExternalReference")) arc = slot(arc,"ref") + ;ans = .Call('R_swig_librdf_model_get_targets', model, source, arc, PACKAGE='redland'); + ans <- new("_p_librdf_iterator_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_get_targets`, 'returnType') = '_p_librdf_iterator_s' +attr(`librdf_model_get_targets`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_node_s') +class(`librdf_model_get_targets`) = c("SWIGFunction", class('librdf_model_get_targets')) + +# Start of librdf_model_get_source + +`librdf_model_get_source` = function(model, arc, target) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(arc, "ExternalReference")) arc = slot(arc,"ref") + if (inherits(target, "ExternalReference")) target = slot(target,"ref") + ;ans = .Call('R_swig_librdf_model_get_source', model, arc, target, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_get_source`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_model_get_source`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_node_s') +class(`librdf_model_get_source`) = c("SWIGFunction", class('librdf_model_get_source')) + +# Start of librdf_model_get_arc + +`librdf_model_get_arc` = function(model, source, target) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(source, "ExternalReference")) source = slot(source,"ref") + if (inherits(target, "ExternalReference")) target = slot(target,"ref") + ;ans = .Call('R_swig_librdf_model_get_arc', model, source, target, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_get_arc`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_model_get_arc`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_node_s') +class(`librdf_model_get_arc`) = c("SWIGFunction", class('librdf_model_get_arc')) + +# Start of librdf_model_get_arcs_out + +`librdf_model_get_arcs_out` = function(model, node) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;ans = .Call('R_swig_librdf_model_get_arcs_out', model, node, PACKAGE='redland'); + ans <- new("_p_librdf_iterator_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_get_arcs_out`, 'returnType') = '_p_librdf_iterator_s' +attr(`librdf_model_get_arcs_out`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s') +class(`librdf_model_get_arcs_out`) = c("SWIGFunction", class('librdf_model_get_arcs_out')) + +# Start of librdf_model_get_arcs_in + +`librdf_model_get_arcs_in` = function(model, node) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + ;ans = .Call('R_swig_librdf_model_get_arcs_in', model, node, PACKAGE='redland'); + ans <- new("_p_librdf_iterator_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_get_arcs_in`, 'returnType') = '_p_librdf_iterator_s' +attr(`librdf_model_get_arcs_in`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s') +class(`librdf_model_get_arcs_in`) = c("SWIGFunction", class('librdf_model_get_arcs_in')) + +# Start of librdf_model_has_arc_in + +`librdf_model_has_arc_in` = function(model, node, property, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + if (inherits(property, "ExternalReference")) property = slot(property,"ref") + ;.Call('R_swig_librdf_model_has_arc_in', model, node, property, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_has_arc_in`, 'returnType') = 'integer' +attr(`librdf_model_has_arc_in`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_node_s') +class(`librdf_model_has_arc_in`) = c("SWIGFunction", class('librdf_model_has_arc_in')) + +# Start of librdf_model_has_arc_out + +`librdf_model_has_arc_out` = function(model, node, property, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(node, "ExternalReference")) node = slot(node,"ref") + if (inherits(property, "ExternalReference")) property = slot(property,"ref") + ;.Call('R_swig_librdf_model_has_arc_out', model, node, property, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_has_arc_out`, 'returnType') = 'integer' +attr(`librdf_model_has_arc_out`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_node_s') +class(`librdf_model_has_arc_out`) = c("SWIGFunction", class('librdf_model_has_arc_out')) + +# Start of librdf_model_get_target + +`librdf_model_get_target` = function(model, source, arc) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(source, "ExternalReference")) source = slot(source,"ref") + if (inherits(arc, "ExternalReference")) arc = slot(arc,"ref") + ;ans = .Call('R_swig_librdf_model_get_target', model, source, arc, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_get_target`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_model_get_target`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_node_s') +class(`librdf_model_get_target`) = c("SWIGFunction", class('librdf_model_get_target')) + +# Start of librdf_model_context_add_statement + +`librdf_model_context_add_statement` = function(model, context, statement, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(context, "ExternalReference")) context = slot(context,"ref") + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;.Call('R_swig_librdf_model_context_add_statement', model, context, statement, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_context_add_statement`, 'returnType') = 'integer' +attr(`librdf_model_context_add_statement`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_statement_s') +class(`librdf_model_context_add_statement`) = c("SWIGFunction", class('librdf_model_context_add_statement')) + +# Start of librdf_model_context_add_statements + +`librdf_model_context_add_statements` = function(model, context, stream, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(context, "ExternalReference")) context = slot(context,"ref") + if (inherits(stream, "ExternalReference")) stream = slot(stream,"ref") + ;.Call('R_swig_librdf_model_context_add_statements', model, context, stream, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_context_add_statements`, 'returnType') = 'integer' +attr(`librdf_model_context_add_statements`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_stream_s') +class(`librdf_model_context_add_statements`) = c("SWIGFunction", class('librdf_model_context_add_statements')) + +# Start of librdf_model_context_remove_statement + +`librdf_model_context_remove_statement` = function(model, context, statement, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(context, "ExternalReference")) context = slot(context,"ref") + if (inherits(statement, "ExternalReference")) statement = slot(statement,"ref") + ;.Call('R_swig_librdf_model_context_remove_statement', model, context, statement, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_context_remove_statement`, 'returnType') = 'integer' +attr(`librdf_model_context_remove_statement`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s', '_p_librdf_statement_s') +class(`librdf_model_context_remove_statement`) = c("SWIGFunction", class('librdf_model_context_remove_statement')) + +# Start of librdf_model_context_remove_statements + +`librdf_model_context_remove_statements` = function(model, context, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(context, "ExternalReference")) context = slot(context,"ref") + ;.Call('R_swig_librdf_model_context_remove_statements', model, context, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_context_remove_statements`, 'returnType') = 'integer' +attr(`librdf_model_context_remove_statements`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s') +class(`librdf_model_context_remove_statements`) = c("SWIGFunction", class('librdf_model_context_remove_statements')) + +# Start of librdf_model_context_as_stream + +`librdf_model_context_as_stream` = function(model, context) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(context, "ExternalReference")) context = slot(context,"ref") + ;ans = .Call('R_swig_librdf_model_context_as_stream', model, context, PACKAGE='redland'); + ans <- new("_p_librdf_stream_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_context_as_stream`, 'returnType') = '_p_librdf_stream_s' +attr(`librdf_model_context_as_stream`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s') +class(`librdf_model_context_as_stream`) = c("SWIGFunction", class('librdf_model_context_as_stream')) + +# Start of librdf_model_sync + +`librdf_model_sync` = function(model) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;.Call('R_swig_librdf_model_sync', model, PACKAGE='redland'); + +} + +attr(`librdf_model_sync`, 'returnType') = 'void' +attr(`librdf_model_sync`, "inputTypes") = c('_p_librdf_model_s') +class(`librdf_model_sync`) = c("SWIGFunction", class('librdf_model_sync')) + +# Start of librdf_model_get_contexts + +`librdf_model_get_contexts` = function(model) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;ans = .Call('R_swig_librdf_model_get_contexts', model, PACKAGE='redland'); + ans <- new("_p_librdf_iterator_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_get_contexts`, 'returnType') = '_p_librdf_iterator_s' +attr(`librdf_model_get_contexts`, "inputTypes") = c('_p_librdf_model_s') +class(`librdf_model_get_contexts`) = c("SWIGFunction", class('librdf_model_get_contexts')) + +# Start of librdf_model_contains_context + +`librdf_model_contains_context` = function(model, context, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(context, "ExternalReference")) context = slot(context,"ref") + ;.Call('R_swig_librdf_model_contains_context', model, context, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_contains_context`, 'returnType') = 'integer' +attr(`librdf_model_contains_context`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_node_s') +class(`librdf_model_contains_context`) = c("SWIGFunction", class('librdf_model_contains_context')) + +# Start of librdf_model_get_feature + +`librdf_model_get_feature` = function(model, feature) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(feature, "ExternalReference")) feature = slot(feature,"ref") + ;ans = .Call('R_swig_librdf_model_get_feature', model, feature, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_model_get_feature`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_model_get_feature`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_uri_s') +class(`librdf_model_get_feature`) = c("SWIGFunction", class('librdf_model_get_feature')) + +# Start of librdf_model_set_feature + +`librdf_model_set_feature` = function(model, feature, value, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(feature, "ExternalReference")) feature = slot(feature,"ref") + if (inherits(value, "ExternalReference")) value = slot(value,"ref") + ;.Call('R_swig_librdf_model_set_feature', model, feature, value, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_set_feature`, 'returnType') = 'integer' +attr(`librdf_model_set_feature`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_uri_s', '_p_librdf_node_s') +class(`librdf_model_set_feature`) = c("SWIGFunction", class('librdf_model_set_feature')) + +# Start of librdf_model_load + +`librdf_model_load` = function(model, uri, name, mime_type, type_uri, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(uri, "ExternalReference")) uri = slot(uri,"ref") + name = as(name, "character"); + mime_type = as(mime_type, "character"); + if (inherits(type_uri, "ExternalReference")) type_uri = slot(type_uri,"ref") + ;.Call('R_swig_librdf_model_load', model, uri, name, mime_type, type_uri, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_load`, 'returnType') = 'integer' +attr(`librdf_model_load`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_uri_s', 'character', 'character', '_p_librdf_uri_s') +class(`librdf_model_load`) = c("SWIGFunction", class('librdf_model_load')) + +# Start of librdf_model_query_execute + +`librdf_model_query_execute` = function(model, query) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(query, "ExternalReference")) query = slot(query,"ref") + ;ans = .Call('R_swig_librdf_model_query_execute', model, query, PACKAGE='redland'); + ans <- new("_p_librdf_query_results", ref=ans) ; + + ans + +} + +attr(`librdf_model_query_execute`, 'returnType') = '_p_librdf_query_results' +attr(`librdf_model_query_execute`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_query') +class(`librdf_model_query_execute`) = c("SWIGFunction", class('librdf_model_query_execute')) + +# Start of librdf_model_to_string + +`librdf_model_to_string` = function(model, uri, name, mime_type, inUriOrNull) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + if (inherits(uri, "ExternalReference")) uri = slot(uri,"ref") + name = as(name, "character"); + mime_type = as(mime_type, "character"); + if (inherits(inUriOrNull, "ExternalReference")) inUriOrNull = slot(inUriOrNull,"ref") + ;.Call('R_swig_librdf_model_to_string', model, uri, name, mime_type, inUriOrNull, PACKAGE='redland'); + +} + +attr(`librdf_model_to_string`, 'returnType') = 'character' +attr(`librdf_model_to_string`, "inputTypes") = c('_p_librdf_model_s', '_p_librdf_uri_s', 'character', 'character', '_p_librdf_uri_s') +class(`librdf_model_to_string`) = c("SWIGFunction", class('librdf_model_to_string')) + +# Start of librdf_model_transaction_start + +`librdf_model_transaction_start` = function(model, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;.Call('R_swig_librdf_model_transaction_start', model, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_transaction_start`, 'returnType') = 'integer' +attr(`librdf_model_transaction_start`, "inputTypes") = c('_p_librdf_model_s') +class(`librdf_model_transaction_start`) = c("SWIGFunction", class('librdf_model_transaction_start')) + +# Start of librdf_model_transaction_commit + +`librdf_model_transaction_commit` = function(model, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;.Call('R_swig_librdf_model_transaction_commit', model, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_transaction_commit`, 'returnType') = 'integer' +attr(`librdf_model_transaction_commit`, "inputTypes") = c('_p_librdf_model_s') +class(`librdf_model_transaction_commit`) = c("SWIGFunction", class('librdf_model_transaction_commit')) + +# Start of librdf_model_transaction_rollback + +`librdf_model_transaction_rollback` = function(model, .copy = FALSE) +{ + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;.Call('R_swig_librdf_model_transaction_rollback', model, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_model_transaction_rollback`, 'returnType') = 'integer' +attr(`librdf_model_transaction_rollback`, "inputTypes") = c('_p_librdf_model_s') +class(`librdf_model_transaction_rollback`) = c("SWIGFunction", class('librdf_model_transaction_rollback')) + +# Start of librdf_new_storage + +`librdf_new_storage` = function(world, storage_name, name, options_string) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + storage_name = as(storage_name, "character"); + name = as(name, "character"); + options_string = as(options_string, "character"); + ;ans = .Call('R_swig_librdf_new_storage', world, storage_name, name, options_string, PACKAGE='redland'); + ans <- new("_p_librdf_storage_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_storage`, 'returnType') = '_p_librdf_storage_s' +attr(`librdf_new_storage`, "inputTypes") = c('_p_librdf_world_s', 'character', 'character', 'character') +class(`librdf_new_storage`) = c("SWIGFunction", class('librdf_new_storage')) + +# Start of librdf_new_storage_from_storage + +`librdf_new_storage_from_storage` = function(old_storage) +{ + if (inherits(old_storage, "ExternalReference")) old_storage = slot(old_storage,"ref") + ;ans = .Call('R_swig_librdf_new_storage_from_storage', old_storage, PACKAGE='redland'); + ans <- new("_p_librdf_storage_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_storage_from_storage`, 'returnType') = '_p_librdf_storage_s' +attr(`librdf_new_storage_from_storage`, "inputTypes") = c('_p_librdf_storage_s') +class(`librdf_new_storage_from_storage`) = c("SWIGFunction", class('librdf_new_storage_from_storage')) + +# Start of librdf_free_storage + +`librdf_free_storage` = function(storage) +{ + if (inherits(storage, "ExternalReference")) storage = slot(storage,"ref") + ;.Call('R_swig_librdf_free_storage', storage, PACKAGE='redland'); + +} + +attr(`librdf_free_storage`, 'returnType') = 'void' +attr(`librdf_free_storage`, "inputTypes") = c('_p_librdf_storage_s') +class(`librdf_free_storage`) = c("SWIGFunction", class('librdf_free_storage')) + +# Start of librdf_parser_check_name + +`librdf_parser_check_name` = function(world, name, .copy = FALSE) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + name = as(name, "character"); + ;.Call('R_swig_librdf_parser_check_name', world, name, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_parser_check_name`, 'returnType') = 'integer' +attr(`librdf_parser_check_name`, "inputTypes") = c('_p_librdf_world_s', 'character') +class(`librdf_parser_check_name`) = c("SWIGFunction", class('librdf_parser_check_name')) + +# Start of librdf_new_parser + +`librdf_new_parser` = function(world, name, mime_type, type_uri) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + name = as(name, "character"); + mime_type = as(mime_type, "character"); + if (inherits(type_uri, "ExternalReference")) type_uri = slot(type_uri,"ref") + ;ans = .Call('R_swig_librdf_new_parser', world, name, mime_type, type_uri, PACKAGE='redland'); + ans <- new("_p_librdf_parser_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_parser`, 'returnType') = '_p_librdf_parser_s' +attr(`librdf_new_parser`, "inputTypes") = c('_p_librdf_world_s', 'character', 'character', '_p_librdf_uri_s') +class(`librdf_new_parser`) = c("SWIGFunction", class('librdf_new_parser')) + +# Start of librdf_free_parser + +`librdf_free_parser` = function(parser) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + ;.Call('R_swig_librdf_free_parser', parser, PACKAGE='redland'); + +} + +attr(`librdf_free_parser`, 'returnType') = 'void' +attr(`librdf_free_parser`, "inputTypes") = c('_p_librdf_parser_s') +class(`librdf_free_parser`) = c("SWIGFunction", class('librdf_free_parser')) + +# Start of librdf_parser_parse_as_stream + +`librdf_parser_parse_as_stream` = function(parser, uri, inUriorNull) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + if (inherits(uri, "ExternalReference")) uri = slot(uri,"ref") + if (inherits(inUriorNull, "ExternalReference")) inUriorNull = slot(inUriorNull,"ref") + ;ans = .Call('R_swig_librdf_parser_parse_as_stream', parser, uri, inUriorNull, PACKAGE='redland'); + ans <- new("_p_librdf_stream_s", ref=ans) ; + + ans + +} + +attr(`librdf_parser_parse_as_stream`, 'returnType') = '_p_librdf_stream_s' +attr(`librdf_parser_parse_as_stream`, "inputTypes") = c('_p_librdf_parser_s', '_p_librdf_uri_s', '_p_librdf_uri_s') +class(`librdf_parser_parse_as_stream`) = c("SWIGFunction", class('librdf_parser_parse_as_stream')) + +# Start of librdf_parser_parse_into_model + +`librdf_parser_parse_into_model` = function(parser, uri, inUriOrNull, model, .copy = FALSE) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + if (inherits(uri, "ExternalReference")) uri = slot(uri,"ref") + if (inherits(inUriOrNull, "ExternalReference")) inUriOrNull = slot(inUriOrNull,"ref") + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;.Call('R_swig_librdf_parser_parse_into_model', parser, uri, inUriOrNull, model, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_parser_parse_into_model`, 'returnType') = 'integer' +attr(`librdf_parser_parse_into_model`, "inputTypes") = c('_p_librdf_parser_s', '_p_librdf_uri_s', '_p_librdf_uri_s', '_p_librdf_model_s') +class(`librdf_parser_parse_into_model`) = c("SWIGFunction", class('librdf_parser_parse_into_model')) + +# Start of librdf_parser_parse_string_as_stream + +`librdf_parser_parse_string_as_stream` = function(parser, string, base_uri) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + string = as(string, "character"); + if (inherits(base_uri, "ExternalReference")) base_uri = slot(base_uri,"ref") + ;ans = .Call('R_swig_librdf_parser_parse_string_as_stream', parser, string, base_uri, PACKAGE='redland'); + ans <- new("_p_librdf_stream_s", ref=ans) ; + + ans + +} + +attr(`librdf_parser_parse_string_as_stream`, 'returnType') = '_p_librdf_stream_s' +attr(`librdf_parser_parse_string_as_stream`, "inputTypes") = c('_p_librdf_parser_s', 'character', '_p_librdf_uri_s') +class(`librdf_parser_parse_string_as_stream`) = c("SWIGFunction", class('librdf_parser_parse_string_as_stream')) + +# Start of librdf_parser_parse_string_into_model + +`librdf_parser_parse_string_into_model` = function(parser, string, base_uri, model, .copy = FALSE) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + string = as(string, "character"); + if (inherits(base_uri, "ExternalReference")) base_uri = slot(base_uri,"ref") + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;.Call('R_swig_librdf_parser_parse_string_into_model', parser, string, base_uri, model, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_parser_parse_string_into_model`, 'returnType') = 'integer' +attr(`librdf_parser_parse_string_into_model`, "inputTypes") = c('_p_librdf_parser_s', 'character', '_p_librdf_uri_s', '_p_librdf_model_s') +class(`librdf_parser_parse_string_into_model`) = c("SWIGFunction", class('librdf_parser_parse_string_into_model')) + +# Start of librdf_parser_parse_counted_string_as_stream + +`librdf_parser_parse_counted_string_as_stream` = function(parser, string, length, base_uri) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + string = as(string, "character"); + length = as.integer(length); + + if(length(length) > 1) { + warning("using only the first element of length"); + }; + + if (inherits(base_uri, "ExternalReference")) base_uri = slot(base_uri,"ref") + ;ans = .Call('R_swig_librdf_parser_parse_counted_string_as_stream', parser, string, length, base_uri, PACKAGE='redland'); + ans <- new("_p_librdf_stream_s", ref=ans) ; + + ans + +} + +attr(`librdf_parser_parse_counted_string_as_stream`, 'returnType') = '_p_librdf_stream_s' +attr(`librdf_parser_parse_counted_string_as_stream`, "inputTypes") = c('_p_librdf_parser_s', 'character', 'integer', '_p_librdf_uri_s') +class(`librdf_parser_parse_counted_string_as_stream`) = c("SWIGFunction", class('librdf_parser_parse_counted_string_as_stream')) + +# Start of librdf_parser_parse_counted_string_into_model + +`librdf_parser_parse_counted_string_into_model` = function(parser, string, length, base_uri, model, .copy = FALSE) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + string = as(string, "character"); + length = as.integer(length); + + if(length(length) > 1) { + warning("using only the first element of length"); + }; + + if (inherits(base_uri, "ExternalReference")) base_uri = slot(base_uri,"ref") + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;.Call('R_swig_librdf_parser_parse_counted_string_into_model', parser, string, length, base_uri, model, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_parser_parse_counted_string_into_model`, 'returnType') = 'integer' +attr(`librdf_parser_parse_counted_string_into_model`, "inputTypes") = c('_p_librdf_parser_s', 'character', 'integer', '_p_librdf_uri_s', '_p_librdf_model_s') +class(`librdf_parser_parse_counted_string_into_model`) = c("SWIGFunction", class('librdf_parser_parse_counted_string_into_model')) + +# Start of librdf_parser_get_feature + +`librdf_parser_get_feature` = function(parser, feature) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + if (inherits(feature, "ExternalReference")) feature = slot(feature,"ref") + ;ans = .Call('R_swig_librdf_parser_get_feature', parser, feature, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_parser_get_feature`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_parser_get_feature`, "inputTypes") = c('_p_librdf_parser_s', '_p_librdf_uri_s') +class(`librdf_parser_get_feature`) = c("SWIGFunction", class('librdf_parser_get_feature')) + +# Start of librdf_parser_set_feature + +`librdf_parser_set_feature` = function(parser, feature, value, .copy = FALSE) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + if (inherits(feature, "ExternalReference")) feature = slot(feature,"ref") + if (inherits(value, "ExternalReference")) value = slot(value,"ref") + ;.Call('R_swig_librdf_parser_set_feature', parser, feature, value, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_parser_set_feature`, 'returnType') = 'integer' +attr(`librdf_parser_set_feature`, "inputTypes") = c('_p_librdf_parser_s', '_p_librdf_uri_s', '_p_librdf_node_s') +class(`librdf_parser_set_feature`) = c("SWIGFunction", class('librdf_parser_set_feature')) + +# Start of librdf_parser_guess_name2 + +`librdf_parser_guess_name2` = function(world, mime_type, buffer, identifier) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + mime_type = as(mime_type, "character"); + buffer = as(buffer, "character"); + identifier = as(identifier, "character"); + ;.Call('R_swig_librdf_parser_guess_name2', world, mime_type, buffer, identifier, PACKAGE='redland'); + +} + +attr(`librdf_parser_guess_name2`, 'returnType') = 'character' +attr(`librdf_parser_guess_name2`, "inputTypes") = c('_p_librdf_world_s', 'character', 'character', 'character') +class(`librdf_parser_guess_name2`) = c("SWIGFunction", class('librdf_parser_guess_name2')) + +# Start of librdf_parser_get_namespaces_seen_prefix + +`librdf_parser_get_namespaces_seen_prefix` = function(parser, offset) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + offset = as.integer(offset); + + if(length(offset) > 1) { + warning("using only the first element of offset"); + }; + + ;.Call('R_swig_librdf_parser_get_namespaces_seen_prefix', parser, offset, PACKAGE='redland'); + +} + +attr(`librdf_parser_get_namespaces_seen_prefix`, 'returnType') = 'character' +attr(`librdf_parser_get_namespaces_seen_prefix`, "inputTypes") = c('_p_librdf_parser_s', 'integer') +class(`librdf_parser_get_namespaces_seen_prefix`) = c("SWIGFunction", class('librdf_parser_get_namespaces_seen_prefix')) + +# Start of librdf_parser_get_namespaces_seen_uri + +`librdf_parser_get_namespaces_seen_uri` = function(parser, offset) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + offset = as.integer(offset); + + if(length(offset) > 1) { + warning("using only the first element of offset"); + }; + + ;ans = .Call('R_swig_librdf_parser_get_namespaces_seen_uri', parser, offset, PACKAGE='redland'); + ans <- new("_p_librdf_uri_s", ref=ans) ; + + ans + +} + +attr(`librdf_parser_get_namespaces_seen_uri`, 'returnType') = '_p_librdf_uri_s' +attr(`librdf_parser_get_namespaces_seen_uri`, "inputTypes") = c('_p_librdf_parser_s', 'integer') +class(`librdf_parser_get_namespaces_seen_uri`) = c("SWIGFunction", class('librdf_parser_get_namespaces_seen_uri')) + +# Start of librdf_parser_get_namespaces_seen_count + +`librdf_parser_get_namespaces_seen_count` = function(parser, .copy = FALSE) +{ + if (inherits(parser, "ExternalReference")) parser = slot(parser,"ref") + ;.Call('R_swig_librdf_parser_get_namespaces_seen_count', parser, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_parser_get_namespaces_seen_count`, 'returnType') = 'integer' +attr(`librdf_parser_get_namespaces_seen_count`, "inputTypes") = c('_p_librdf_parser_s') +class(`librdf_parser_get_namespaces_seen_count`) = c("SWIGFunction", class('librdf_parser_get_namespaces_seen_count')) + +# Start of librdf_new_query + +`librdf_new_query` = function(world, name, uri, query_string, base_uri) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + name = as(name, "character"); + if (inherits(uri, "ExternalReference")) uri = slot(uri,"ref") + query_string = as(query_string, "character"); + if (inherits(base_uri, "ExternalReference")) base_uri = slot(base_uri,"ref") + ;ans = .Call('R_swig_librdf_new_query', world, name, uri, query_string, base_uri, PACKAGE='redland'); + ans <- new("_p_librdf_query", ref=ans) ; + + ans + +} + +attr(`librdf_new_query`, 'returnType') = '_p_librdf_query' +attr(`librdf_new_query`, "inputTypes") = c('_p_librdf_world_s', 'character', '_p_librdf_uri_s', 'character', '_p_librdf_uri_s') +class(`librdf_new_query`) = c("SWIGFunction", class('librdf_new_query')) + +# Start of librdf_new_query_from_query + +`librdf_new_query_from_query` = function(old_query) +{ + if (inherits(old_query, "ExternalReference")) old_query = slot(old_query,"ref") + ;ans = .Call('R_swig_librdf_new_query_from_query', old_query, PACKAGE='redland'); + ans <- new("_p_librdf_query", ref=ans) ; + + ans + +} + +attr(`librdf_new_query_from_query`, 'returnType') = '_p_librdf_query' +attr(`librdf_new_query_from_query`, "inputTypes") = c('_p_librdf_query') +class(`librdf_new_query_from_query`) = c("SWIGFunction", class('librdf_new_query_from_query')) + +# Start of librdf_free_query + +`librdf_free_query` = function(query) +{ + if (inherits(query, "ExternalReference")) query = slot(query,"ref") + ;.Call('R_swig_librdf_free_query', query, PACKAGE='redland'); + +} + +attr(`librdf_free_query`, 'returnType') = 'void' +attr(`librdf_free_query`, "inputTypes") = c('_p_librdf_query') +class(`librdf_free_query`) = c("SWIGFunction", class('librdf_free_query')) + +# Start of librdf_query_execute + +`librdf_query_execute` = function(query, model) +{ + if (inherits(query, "ExternalReference")) query = slot(query,"ref") + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;ans = .Call('R_swig_librdf_query_execute', query, model, PACKAGE='redland'); + ans <- new("_p_librdf_query_results", ref=ans) ; + + ans + +} + +attr(`librdf_query_execute`, 'returnType') = '_p_librdf_query_results' +attr(`librdf_query_execute`, "inputTypes") = c('_p_librdf_query', '_p_librdf_model_s') +class(`librdf_query_execute`) = c("SWIGFunction", class('librdf_query_execute')) + +# Start of librdf_query_get_limit + +`librdf_query_get_limit` = function(query, .copy = FALSE) +{ + if (inherits(query, "ExternalReference")) query = slot(query,"ref") + ;.Call('R_swig_librdf_query_get_limit', query, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_get_limit`, 'returnType') = 'integer' +attr(`librdf_query_get_limit`, "inputTypes") = c('_p_librdf_query') +class(`librdf_query_get_limit`) = c("SWIGFunction", class('librdf_query_get_limit')) + +# Start of librdf_query_set_limit + +`librdf_query_set_limit` = function(query, limit, .copy = FALSE) +{ + if (inherits(query, "ExternalReference")) query = slot(query,"ref") + limit = as.integer(limit); + + if(length(limit) > 1) { + warning("using only the first element of limit"); + }; + + ;.Call('R_swig_librdf_query_set_limit', query, limit, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_set_limit`, 'returnType') = 'integer' +attr(`librdf_query_set_limit`, "inputTypes") = c('_p_librdf_query', 'integer') +class(`librdf_query_set_limit`) = c("SWIGFunction", class('librdf_query_set_limit')) + +# Start of librdf_query_get_offset + +`librdf_query_get_offset` = function(query, .copy = FALSE) +{ + if (inherits(query, "ExternalReference")) query = slot(query,"ref") + ;.Call('R_swig_librdf_query_get_offset', query, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_get_offset`, 'returnType') = 'integer' +attr(`librdf_query_get_offset`, "inputTypes") = c('_p_librdf_query') +class(`librdf_query_get_offset`) = c("SWIGFunction", class('librdf_query_get_offset')) + +# Start of librdf_query_set_offset + +`librdf_query_set_offset` = function(query, offset, .copy = FALSE) +{ + if (inherits(query, "ExternalReference")) query = slot(query,"ref") + offset = as.integer(offset); + + if(length(offset) > 1) { + warning("using only the first element of offset"); + }; + + ;.Call('R_swig_librdf_query_set_offset', query, offset, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_set_offset`, 'returnType') = 'integer' +attr(`librdf_query_set_offset`, "inputTypes") = c('_p_librdf_query', 'integer') +class(`librdf_query_set_offset`) = c("SWIGFunction", class('librdf_query_set_offset')) + +# Start of librdf_query_results_as_stream + +`librdf_query_results_as_stream` = function(query_results) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + ;ans = .Call('R_swig_librdf_query_results_as_stream', query_results, PACKAGE='redland'); + ans <- new("_p_librdf_stream_s", ref=ans) ; + + ans + +} + +attr(`librdf_query_results_as_stream`, 'returnType') = '_p_librdf_stream_s' +attr(`librdf_query_results_as_stream`, "inputTypes") = c('_p_librdf_query_results') +class(`librdf_query_results_as_stream`) = c("SWIGFunction", class('librdf_query_results_as_stream')) + +# Start of librdf_query_results_get_count + +`librdf_query_results_get_count` = function(query_results, .copy = FALSE) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + ;.Call('R_swig_librdf_query_results_get_count', query_results, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_results_get_count`, 'returnType') = 'integer' +attr(`librdf_query_results_get_count`, "inputTypes") = c('_p_librdf_query_results') +class(`librdf_query_results_get_count`) = c("SWIGFunction", class('librdf_query_results_get_count')) + +# Start of librdf_query_results_next + +`librdf_query_results_next` = function(query_results, .copy = FALSE) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + ;.Call('R_swig_librdf_query_results_next', query_results, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_results_next`, 'returnType') = 'integer' +attr(`librdf_query_results_next`, "inputTypes") = c('_p_librdf_query_results') +class(`librdf_query_results_next`) = c("SWIGFunction", class('librdf_query_results_next')) + +# Start of librdf_query_results_finished + +`librdf_query_results_finished` = function(query_results, .copy = FALSE) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + ;.Call('R_swig_librdf_query_results_finished', query_results, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_results_finished`, 'returnType') = 'integer' +attr(`librdf_query_results_finished`, "inputTypes") = c('_p_librdf_query_results') +class(`librdf_query_results_finished`) = c("SWIGFunction", class('librdf_query_results_finished')) + +# Start of librdf_query_results_get_binding_value + +`librdf_query_results_get_binding_value` = function(query_results, offset) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + offset = as.integer(offset); + + if(length(offset) > 1) { + warning("using only the first element of offset"); + }; + + ;ans = .Call('R_swig_librdf_query_results_get_binding_value', query_results, offset, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_query_results_get_binding_value`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_query_results_get_binding_value`, "inputTypes") = c('_p_librdf_query_results', 'integer') +class(`librdf_query_results_get_binding_value`) = c("SWIGFunction", class('librdf_query_results_get_binding_value')) + +# Start of librdf_query_results_get_binding_name + +`librdf_query_results_get_binding_name` = function(query_results, offset) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + offset = as.integer(offset); + + if(length(offset) > 1) { + warning("using only the first element of offset"); + }; + + ;.Call('R_swig_librdf_query_results_get_binding_name', query_results, offset, PACKAGE='redland'); + +} + +attr(`librdf_query_results_get_binding_name`, 'returnType') = 'character' +attr(`librdf_query_results_get_binding_name`, "inputTypes") = c('_p_librdf_query_results', 'integer') +class(`librdf_query_results_get_binding_name`) = c("SWIGFunction", class('librdf_query_results_get_binding_name')) + +# Start of librdf_query_results_get_binding_value_by_name + +`librdf_query_results_get_binding_value_by_name` = function(query_results, name) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + name = as(name, "character"); + ;ans = .Call('R_swig_librdf_query_results_get_binding_value_by_name', query_results, name, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_query_results_get_binding_value_by_name`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_query_results_get_binding_value_by_name`, "inputTypes") = c('_p_librdf_query_results', 'character') +class(`librdf_query_results_get_binding_value_by_name`) = c("SWIGFunction", class('librdf_query_results_get_binding_value_by_name')) + +# Start of librdf_query_results_get_bindings_count + +`librdf_query_results_get_bindings_count` = function(query_results, .copy = FALSE) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + ;.Call('R_swig_librdf_query_results_get_bindings_count', query_results, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_results_get_bindings_count`, 'returnType') = 'integer' +attr(`librdf_query_results_get_bindings_count`, "inputTypes") = c('_p_librdf_query_results') +class(`librdf_query_results_get_bindings_count`) = c("SWIGFunction", class('librdf_query_results_get_bindings_count')) + +# Start of librdf_query_results_to_file2 + +`librdf_query_results_to_file2` = function(query_results, name, mime_type, format_uri, base_uri, .copy = FALSE) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + name = as(name, "character"); + mime_type = as(mime_type, "character"); + if (inherits(format_uri, "ExternalReference")) format_uri = slot(format_uri,"ref") + if (inherits(base_uri, "ExternalReference")) base_uri = slot(base_uri,"ref") + ;.Call('R_swig_librdf_query_results_to_file2', query_results, name, mime_type, format_uri, base_uri, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_results_to_file2`, 'returnType') = 'integer' +attr(`librdf_query_results_to_file2`, "inputTypes") = c('_p_librdf_query_results', 'character', 'character', '_p_librdf_uri_s', '_p_librdf_uri_s') +class(`librdf_query_results_to_file2`) = c("SWIGFunction", class('librdf_query_results_to_file2')) + +# Start of librdf_query_results_to_string2 + +`librdf_query_results_to_string2` = function(query_results, name, mime_type, format_uri, base_uri) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + name = as(name, "character"); + mime_type = as(mime_type, "character"); + if (inherits(format_uri, "ExternalReference")) format_uri = slot(format_uri,"ref") + if (inherits(base_uri, "ExternalReference")) base_uri = slot(base_uri,"ref") + ;.Call('R_swig_librdf_query_results_to_string2', query_results, name, mime_type, format_uri, base_uri, PACKAGE='redland'); + +} + +attr(`librdf_query_results_to_string2`, 'returnType') = 'character' +attr(`librdf_query_results_to_string2`, "inputTypes") = c('_p_librdf_query_results', 'character', 'character', '_p_librdf_uri_s', '_p_librdf_uri_s') +class(`librdf_query_results_to_string2`) = c("SWIGFunction", class('librdf_query_results_to_string2')) + +# Start of librdf_free_query_results + +`librdf_free_query_results` = function(query_results) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + ;.Call('R_swig_librdf_free_query_results', query_results, PACKAGE='redland'); + +} + +attr(`librdf_free_query_results`, 'returnType') = 'void' +attr(`librdf_free_query_results`, "inputTypes") = c('_p_librdf_query_results') +class(`librdf_free_query_results`) = c("SWIGFunction", class('librdf_free_query_results')) + +# Start of librdf_query_results_is_bindings + +`librdf_query_results_is_bindings` = function(query_results, .copy = FALSE) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + ;.Call('R_swig_librdf_query_results_is_bindings', query_results, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_results_is_bindings`, 'returnType') = 'integer' +attr(`librdf_query_results_is_bindings`, "inputTypes") = c('_p_librdf_query_results') +class(`librdf_query_results_is_bindings`) = c("SWIGFunction", class('librdf_query_results_is_bindings')) + +# Start of librdf_query_results_is_boolean + +`librdf_query_results_is_boolean` = function(query_results, .copy = FALSE) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + ;.Call('R_swig_librdf_query_results_is_boolean', query_results, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_results_is_boolean`, 'returnType') = 'integer' +attr(`librdf_query_results_is_boolean`, "inputTypes") = c('_p_librdf_query_results') +class(`librdf_query_results_is_boolean`) = c("SWIGFunction", class('librdf_query_results_is_boolean')) + +# Start of librdf_query_results_is_graph + +`librdf_query_results_is_graph` = function(query_results, .copy = FALSE) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + ;.Call('R_swig_librdf_query_results_is_graph', query_results, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_results_is_graph`, 'returnType') = 'integer' +attr(`librdf_query_results_is_graph`, "inputTypes") = c('_p_librdf_query_results') +class(`librdf_query_results_is_graph`) = c("SWIGFunction", class('librdf_query_results_is_graph')) + +# Start of librdf_query_results_is_syntax + +`librdf_query_results_is_syntax` = function(query_results, .copy = FALSE) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + ;.Call('R_swig_librdf_query_results_is_syntax', query_results, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_results_is_syntax`, 'returnType') = 'integer' +attr(`librdf_query_results_is_syntax`, "inputTypes") = c('_p_librdf_query_results') +class(`librdf_query_results_is_syntax`) = c("SWIGFunction", class('librdf_query_results_is_syntax')) + +# Start of librdf_query_results_get_boolean + +`librdf_query_results_get_boolean` = function(query_results, .copy = FALSE) +{ + if (inherits(query_results, "ExternalReference")) query_results = slot(query_results,"ref") + ;.Call('R_swig_librdf_query_results_get_boolean', query_results, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_query_results_get_boolean`, 'returnType') = 'integer' +attr(`librdf_query_results_get_boolean`, "inputTypes") = c('_p_librdf_query_results') +class(`librdf_query_results_get_boolean`) = c("SWIGFunction", class('librdf_query_results_get_boolean')) + +# Start of librdf_serializer_check_name + +`librdf_serializer_check_name` = function(world, name, .copy = FALSE) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + name = as(name, "character"); + ;.Call('R_swig_librdf_serializer_check_name', world, name, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_serializer_check_name`, 'returnType') = 'integer' +attr(`librdf_serializer_check_name`, "inputTypes") = c('_p_librdf_world_s', 'character') +class(`librdf_serializer_check_name`) = c("SWIGFunction", class('librdf_serializer_check_name')) + +# Start of librdf_new_serializer + +`librdf_new_serializer` = function(world, name, mime_type, type_uri) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + name = as(name, "character"); + mime_type = as(mime_type, "character"); + if (inherits(type_uri, "ExternalReference")) type_uri = slot(type_uri,"ref") + ;ans = .Call('R_swig_librdf_new_serializer', world, name, mime_type, type_uri, PACKAGE='redland'); + ans <- new("_p_librdf_serializer_s", ref=ans) ; + + ans + +} + +attr(`librdf_new_serializer`, 'returnType') = '_p_librdf_serializer_s' +attr(`librdf_new_serializer`, "inputTypes") = c('_p_librdf_world_s', 'character', 'character', '_p_librdf_uri_s') +class(`librdf_new_serializer`) = c("SWIGFunction", class('librdf_new_serializer')) + +# Start of librdf_free_serializer + +`librdf_free_serializer` = function(serializer) +{ + if (inherits(serializer, "ExternalReference")) serializer = slot(serializer,"ref") + ;.Call('R_swig_librdf_free_serializer', serializer, PACKAGE='redland'); + +} + +attr(`librdf_free_serializer`, 'returnType') = 'void' +attr(`librdf_free_serializer`, "inputTypes") = c('_p_librdf_serializer_s') +class(`librdf_free_serializer`) = c("SWIGFunction", class('librdf_free_serializer')) + +# Start of librdf_serializer_serialize_stream_to_file + +`librdf_serializer_serialize_stream_to_file` = function(serializer, name, base_uri, stream, .copy = FALSE) +{ + if (inherits(serializer, "ExternalReference")) serializer = slot(serializer,"ref") + name = as(name, "character"); + if (inherits(base_uri, "ExternalReference")) base_uri = slot(base_uri,"ref") + if (inherits(stream, "ExternalReference")) stream = slot(stream,"ref") + ;.Call('R_swig_librdf_serializer_serialize_stream_to_file', serializer, name, base_uri, stream, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_serializer_serialize_stream_to_file`, 'returnType') = 'integer' +attr(`librdf_serializer_serialize_stream_to_file`, "inputTypes") = c('_p_librdf_serializer_s', 'character', '_p_librdf_uri_s', '_p_librdf_stream_s') +class(`librdf_serializer_serialize_stream_to_file`) = c("SWIGFunction", class('librdf_serializer_serialize_stream_to_file')) + +# Start of librdf_serializer_serialize_model_to_file + +`librdf_serializer_serialize_model_to_file` = function(serializer, name, inUriOrNull, model, .copy = FALSE) +{ + if (inherits(serializer, "ExternalReference")) serializer = slot(serializer,"ref") + name = as(name, "character"); + if (inherits(inUriOrNull, "ExternalReference")) inUriOrNull = slot(inUriOrNull,"ref") + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;.Call('R_swig_librdf_serializer_serialize_model_to_file', serializer, name, inUriOrNull, model, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_serializer_serialize_model_to_file`, 'returnType') = 'integer' +attr(`librdf_serializer_serialize_model_to_file`, "inputTypes") = c('_p_librdf_serializer_s', 'character', '_p_librdf_uri_s', '_p_librdf_model_s') +class(`librdf_serializer_serialize_model_to_file`) = c("SWIGFunction", class('librdf_serializer_serialize_model_to_file')) + +# Start of librdf_serializer_serialize_stream_to_string + +`librdf_serializer_serialize_stream_to_string` = function(serializer, base_uri, stream) +{ + if (inherits(serializer, "ExternalReference")) serializer = slot(serializer,"ref") + if (inherits(base_uri, "ExternalReference")) base_uri = slot(base_uri,"ref") + if (inherits(stream, "ExternalReference")) stream = slot(stream,"ref") + ;.Call('R_swig_librdf_serializer_serialize_stream_to_string', serializer, base_uri, stream, PACKAGE='redland'); + +} + +attr(`librdf_serializer_serialize_stream_to_string`, 'returnType') = 'character' +attr(`librdf_serializer_serialize_stream_to_string`, "inputTypes") = c('_p_librdf_serializer_s', '_p_librdf_uri_s', '_p_librdf_stream_s') +class(`librdf_serializer_serialize_stream_to_string`) = c("SWIGFunction", class('librdf_serializer_serialize_stream_to_string')) + +# Start of librdf_serializer_serialize_model_to_string + +`librdf_serializer_serialize_model_to_string` = function(serializer, inUriOrNull, model) +{ + if (inherits(serializer, "ExternalReference")) serializer = slot(serializer,"ref") + if (inherits(inUriOrNull, "ExternalReference")) inUriOrNull = slot(inUriOrNull,"ref") + if (inherits(model, "ExternalReference")) model = slot(model,"ref") + ;.Call('R_swig_librdf_serializer_serialize_model_to_string', serializer, inUriOrNull, model, PACKAGE='redland'); + +} + +attr(`librdf_serializer_serialize_model_to_string`, 'returnType') = 'character' +attr(`librdf_serializer_serialize_model_to_string`, "inputTypes") = c('_p_librdf_serializer_s', '_p_librdf_uri_s', '_p_librdf_model_s') +class(`librdf_serializer_serialize_model_to_string`) = c("SWIGFunction", class('librdf_serializer_serialize_model_to_string')) + +# Start of librdf_serializer_get_feature + +`librdf_serializer_get_feature` = function(serializer, feature) +{ + if (inherits(serializer, "ExternalReference")) serializer = slot(serializer,"ref") + if (inherits(feature, "ExternalReference")) feature = slot(feature,"ref") + ;ans = .Call('R_swig_librdf_serializer_get_feature', serializer, feature, PACKAGE='redland'); + ans <- new("_p_librdf_node_s", ref=ans) ; + + ans + +} + +attr(`librdf_serializer_get_feature`, 'returnType') = '_p_librdf_node_s' +attr(`librdf_serializer_get_feature`, "inputTypes") = c('_p_librdf_serializer_s', '_p_librdf_uri_s') +class(`librdf_serializer_get_feature`) = c("SWIGFunction", class('librdf_serializer_get_feature')) + +# Start of librdf_serializer_set_feature + +`librdf_serializer_set_feature` = function(serializer, feature, value, .copy = FALSE) +{ + if (inherits(serializer, "ExternalReference")) serializer = slot(serializer,"ref") + if (inherits(feature, "ExternalReference")) feature = slot(feature,"ref") + if (inherits(value, "ExternalReference")) value = slot(value,"ref") + ;.Call('R_swig_librdf_serializer_set_feature', serializer, feature, value, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_serializer_set_feature`, 'returnType') = 'integer' +attr(`librdf_serializer_set_feature`, "inputTypes") = c('_p_librdf_serializer_s', '_p_librdf_uri_s', '_p_librdf_node_s') +class(`librdf_serializer_set_feature`) = c("SWIGFunction", class('librdf_serializer_set_feature')) + +# Start of librdf_serializer_set_namespace + +`librdf_serializer_set_namespace` = function(serializer, nspace, prefix, .copy = FALSE) +{ + if (inherits(serializer, "ExternalReference")) serializer = slot(serializer,"ref") + if (inherits(nspace, "ExternalReference")) nspace = slot(nspace,"ref") + prefix = as(prefix, "character"); + ;.Call('R_swig_librdf_serializer_set_namespace', serializer, nspace, prefix, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_serializer_set_namespace`, 'returnType') = 'integer' +attr(`librdf_serializer_set_namespace`, "inputTypes") = c('_p_librdf_serializer_s', '_p_librdf_uri_s', 'character') +class(`librdf_serializer_set_namespace`) = c("SWIGFunction", class('librdf_serializer_set_namespace')) + +# Start of librdf_free_stream + +`librdf_free_stream` = function(stream) +{ + if (inherits(stream, "ExternalReference")) stream = slot(stream,"ref") + ;.Call('R_swig_librdf_free_stream', stream, PACKAGE='redland'); + +} + +attr(`librdf_free_stream`, 'returnType') = 'void' +attr(`librdf_free_stream`, "inputTypes") = c('_p_librdf_stream_s') +class(`librdf_free_stream`) = c("SWIGFunction", class('librdf_free_stream')) + +# Start of librdf_stream_end + +`librdf_stream_end` = function(stream, .copy = FALSE) +{ + if (inherits(stream, "ExternalReference")) stream = slot(stream,"ref") + ;.Call('R_swig_librdf_stream_end', stream, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_stream_end`, 'returnType') = 'integer' +attr(`librdf_stream_end`, "inputTypes") = c('_p_librdf_stream_s') +class(`librdf_stream_end`) = c("SWIGFunction", class('librdf_stream_end')) + +# Start of librdf_stream_next + +`librdf_stream_next` = function(stream, .copy = FALSE) +{ + if (inherits(stream, "ExternalReference")) stream = slot(stream,"ref") + ;.Call('R_swig_librdf_stream_next', stream, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_stream_next`, 'returnType') = 'integer' +attr(`librdf_stream_next`, "inputTypes") = c('_p_librdf_stream_s') +class(`librdf_stream_next`) = c("SWIGFunction", class('librdf_stream_next')) + +# Start of librdf_stream_get_object + +`librdf_stream_get_object` = function(stream) +{ + if (inherits(stream, "ExternalReference")) stream = slot(stream,"ref") + ;ans = .Call('R_swig_librdf_stream_get_object', stream, PACKAGE='redland'); + ans <- new("_p_librdf_statement_s", ref=ans) ; + + ans + +} + +attr(`librdf_stream_get_object`, 'returnType') = '_p_librdf_statement_s' +attr(`librdf_stream_get_object`, "inputTypes") = c('_p_librdf_stream_s') +class(`librdf_stream_get_object`) = c("SWIGFunction", class('librdf_stream_get_object')) + +# Start of librdf_log_message_code + +`librdf_log_message_code` = function(message, .copy = FALSE) +{ + if (inherits(message, "ExternalReference")) message = slot(message,"ref") + ;.Call('R_swig_librdf_log_message_code', message, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_log_message_code`, 'returnType') = 'integer' +attr(`librdf_log_message_code`, "inputTypes") = c('_p_librdf_log_message') +class(`librdf_log_message_code`) = c("SWIGFunction", class('librdf_log_message_code')) + +# Start of librdf_log_message_level + +`librdf_log_message_level` = function(message, .copy = FALSE) +{ + if (inherits(message, "ExternalReference")) message = slot(message,"ref") + ;.Call('R_swig_librdf_log_message_level', message, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_log_message_level`, 'returnType') = 'integer' +attr(`librdf_log_message_level`, "inputTypes") = c('_p_librdf_log_message') +class(`librdf_log_message_level`) = c("SWIGFunction", class('librdf_log_message_level')) + +# Start of librdf_log_message_facility + +`librdf_log_message_facility` = function(message, .copy = FALSE) +{ + if (inherits(message, "ExternalReference")) message = slot(message,"ref") + ;.Call('R_swig_librdf_log_message_facility', message, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_log_message_facility`, 'returnType') = 'integer' +attr(`librdf_log_message_facility`, "inputTypes") = c('_p_librdf_log_message') +class(`librdf_log_message_facility`) = c("SWIGFunction", class('librdf_log_message_facility')) + +# Start of librdf_log_message_message + +`librdf_log_message_message` = function(message) +{ + if (inherits(message, "ExternalReference")) message = slot(message,"ref") + ;.Call('R_swig_librdf_log_message_message', message, PACKAGE='redland'); + +} + +attr(`librdf_log_message_message`, 'returnType') = 'character' +attr(`librdf_log_message_message`, "inputTypes") = c('_p_librdf_log_message') +class(`librdf_log_message_message`) = c("SWIGFunction", class('librdf_log_message_message')) + +# Start of librdf_log_message_locator + +`librdf_log_message_locator` = function(message) +{ + if (inherits(message, "ExternalReference")) message = slot(message,"ref") + ;ans = .Call('R_swig_librdf_log_message_locator', message, PACKAGE='redland'); + ans <- new("_p_raptor_locator", ref=ans) ; + + ans + +} + +attr(`librdf_log_message_locator`, 'returnType') = '_p_raptor_locator' +attr(`librdf_log_message_locator`, "inputTypes") = c('_p_librdf_log_message') +class(`librdf_log_message_locator`) = c("SWIGFunction", class('librdf_log_message_locator')) + +# Start of raptor_locator_line + +`raptor_locator_line` = function(locator, .copy = FALSE) +{ + if (inherits(locator, "ExternalReference")) locator = slot(locator,"ref") + ;.Call('R_swig_raptor_locator_line', locator, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`raptor_locator_line`, 'returnType') = 'integer' +attr(`raptor_locator_line`, "inputTypes") = c('_p_raptor_locator') +class(`raptor_locator_line`) = c("SWIGFunction", class('raptor_locator_line')) + +# Start of raptor_locator_column + +`raptor_locator_column` = function(locator, .copy = FALSE) +{ + if (inherits(locator, "ExternalReference")) locator = slot(locator,"ref") + ;.Call('R_swig_raptor_locator_column', locator, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`raptor_locator_column`, 'returnType') = 'integer' +attr(`raptor_locator_column`, "inputTypes") = c('_p_raptor_locator') +class(`raptor_locator_column`) = c("SWIGFunction", class('raptor_locator_column')) + +# Start of raptor_locator_byte + +`raptor_locator_byte` = function(locator, .copy = FALSE) +{ + if (inherits(locator, "ExternalReference")) locator = slot(locator,"ref") + ;.Call('R_swig_raptor_locator_byte', locator, as.logical(.copy), PACKAGE='redland'); + +} + +attr(`raptor_locator_byte`, 'returnType') = 'integer' +attr(`raptor_locator_byte`, "inputTypes") = c('_p_raptor_locator') +class(`raptor_locator_byte`) = c("SWIGFunction", class('raptor_locator_byte')) + +# Start of raptor_locator_file + +`raptor_locator_file` = function(locator) +{ + if (inherits(locator, "ExternalReference")) locator = slot(locator,"ref") + ;.Call('R_swig_raptor_locator_file', locator, PACKAGE='redland'); + +} + +attr(`raptor_locator_file`, 'returnType') = 'character' +attr(`raptor_locator_file`, "inputTypes") = c('_p_raptor_locator') +class(`raptor_locator_file`) = c("SWIGFunction", class('raptor_locator_file')) + +# Start of raptor_locator_uri + +`raptor_locator_uri` = function(locator) +{ + if (inherits(locator, "ExternalReference")) locator = slot(locator,"ref") + ;.Call('R_swig_raptor_locator_uri', locator, PACKAGE='redland'); + +} + +attr(`raptor_locator_uri`, 'returnType') = 'character' +attr(`raptor_locator_uri`, "inputTypes") = c('_p_raptor_locator') +class(`raptor_locator_uri`) = c("SWIGFunction", class('raptor_locator_uri')) + +# Start of librdf_internal_test_error + +`librdf_internal_test_error` = function(world) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + ;.Call('R_swig_librdf_internal_test_error', world, PACKAGE='redland'); + +} + +attr(`librdf_internal_test_error`, 'returnType') = 'void' +attr(`librdf_internal_test_error`, "inputTypes") = c('_p_librdf_world_s') +class(`librdf_internal_test_error`) = c("SWIGFunction", class('librdf_internal_test_error')) + +# Start of librdf_internal_test_warning + +`librdf_internal_test_warning` = function(world) +{ + if (inherits(world, "ExternalReference")) world = slot(world,"ref") + ;.Call('R_swig_librdf_internal_test_warning', world, PACKAGE='redland'); + +} + +attr(`librdf_internal_test_warning`, 'returnType') = 'void' +attr(`librdf_internal_test_warning`, "inputTypes") = c('_p_librdf_world_s') +class(`librdf_internal_test_warning`) = c("SWIGFunction", class('librdf_internal_test_warning')) + +# Start of librdf_short_copyright_string_get + +`librdf_short_copyright_string_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_librdf_short_copyright_string_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_short_copyright_string_get`, 'returnType') = 'character' +class(`librdf_short_copyright_string_get`) = c("SWIGFunction", class('librdf_short_copyright_string_get')) + +librdf_short_copyright_string = librdf_short_copyright_string_get +# Start of librdf_copyright_string_get + +`librdf_copyright_string_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_librdf_copyright_string_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_copyright_string_get`, 'returnType') = 'character' +class(`librdf_copyright_string_get`) = c("SWIGFunction", class('librdf_copyright_string_get')) + +librdf_copyright_string = librdf_copyright_string_get +# Start of librdf_version_string_get + +`librdf_version_string_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_librdf_version_string_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_version_string_get`, 'returnType') = 'character' +class(`librdf_version_string_get`) = c("SWIGFunction", class('librdf_version_string_get')) + +librdf_version_string = librdf_version_string_get +# Start of librdf_version_major_get + +`librdf_version_major_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_librdf_version_major_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_version_major_get`, 'returnType') = 'integer' +class(`librdf_version_major_get`) = c("SWIGFunction", class('librdf_version_major_get')) + +librdf_version_major = librdf_version_major_get +# Start of librdf_version_minor_get + +`librdf_version_minor_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_librdf_version_minor_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_version_minor_get`, 'returnType') = 'integer' +class(`librdf_version_minor_get`) = c("SWIGFunction", class('librdf_version_minor_get')) + +librdf_version_minor = librdf_version_minor_get +# Start of librdf_version_release_get + +`librdf_version_release_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_librdf_version_release_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_version_release_get`, 'returnType') = 'integer' +class(`librdf_version_release_get`) = c("SWIGFunction", class('librdf_version_release_get')) + +librdf_version_release = librdf_version_release_get +# Start of librdf_version_decimal_get + +`librdf_version_decimal_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_librdf_version_decimal_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`librdf_version_decimal_get`, 'returnType') = 'integer' +class(`librdf_version_decimal_get`) = c("SWIGFunction", class('librdf_version_decimal_get')) + +librdf_version_decimal = librdf_version_decimal_get +# Start of raptor_version_string_get + +`raptor_version_string_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_raptor_version_string_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`raptor_version_string_get`, 'returnType') = 'character' +class(`raptor_version_string_get`) = c("SWIGFunction", class('raptor_version_string_get')) + +raptor_version_string = raptor_version_string_get +# Start of raptor_version_major_get + +`raptor_version_major_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_raptor_version_major_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`raptor_version_major_get`, 'returnType') = 'integer' +class(`raptor_version_major_get`) = c("SWIGFunction", class('raptor_version_major_get')) + +raptor_version_major = raptor_version_major_get +# Start of raptor_version_minor_get + +`raptor_version_minor_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_raptor_version_minor_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`raptor_version_minor_get`, 'returnType') = 'integer' +class(`raptor_version_minor_get`) = c("SWIGFunction", class('raptor_version_minor_get')) + +raptor_version_minor = raptor_version_minor_get +# Start of raptor_version_release_get + +`raptor_version_release_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_raptor_version_release_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`raptor_version_release_get`, 'returnType') = 'integer' +class(`raptor_version_release_get`) = c("SWIGFunction", class('raptor_version_release_get')) + +raptor_version_release = raptor_version_release_get +# Start of raptor_version_decimal_get + +`raptor_version_decimal_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_raptor_version_decimal_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`raptor_version_decimal_get`, 'returnType') = 'integer' +class(`raptor_version_decimal_get`) = c("SWIGFunction", class('raptor_version_decimal_get')) + +raptor_version_decimal = raptor_version_decimal_get +# Start of rasqal_version_string_get + +`rasqal_version_string_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_rasqal_version_string_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`rasqal_version_string_get`, 'returnType') = 'character' +class(`rasqal_version_string_get`) = c("SWIGFunction", class('rasqal_version_string_get')) + +rasqal_version_string = rasqal_version_string_get +# Start of rasqal_version_major_get + +`rasqal_version_major_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_rasqal_version_major_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`rasqal_version_major_get`, 'returnType') = 'integer' +class(`rasqal_version_major_get`) = c("SWIGFunction", class('rasqal_version_major_get')) + +rasqal_version_major = rasqal_version_major_get +# Start of rasqal_version_minor_get + +`rasqal_version_minor_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_rasqal_version_minor_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`rasqal_version_minor_get`, 'returnType') = 'integer' +class(`rasqal_version_minor_get`) = c("SWIGFunction", class('rasqal_version_minor_get')) + +rasqal_version_minor = rasqal_version_minor_get +# Start of rasqal_version_release_get + +`rasqal_version_release_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_rasqal_version_release_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`rasqal_version_release_get`, 'returnType') = 'integer' +class(`rasqal_version_release_get`) = c("SWIGFunction", class('rasqal_version_release_get')) + +rasqal_version_release = rasqal_version_release_get +# Start of rasqal_version_decimal_get + +`rasqal_version_decimal_get` = function(.copy = FALSE) +{ + ;.Call('R_swig_rasqal_version_decimal_get', as.logical(.copy), PACKAGE='redland'); + +} + +attr(`rasqal_version_decimal_get`, 'returnType') = 'integer' +class(`rasqal_version_decimal_get`) = c("SWIGFunction", class('rasqal_version_decimal_get')) + +rasqal_version_decimal = rasqal_version_decimal_get + +setClass('_p_librdf_query', contains = 'ExternalReference') +setClass('_p_librdf_query_results', contains = 'ExternalReference') + diff --git a/R/redland/R/util.R b/R/redland/R/util.R new file mode 100644 index 000000000..f2db42d96 --- /dev/null +++ b/R/redland/R/util.R @@ -0,0 +1,28 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 Regents of the University of California +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#' Determine whether an externalptr object is NULL. +#' +#' The pointer is treated as an externalptr and checked via a call in C to see if it is NULL. +#' @param pointer externalptr to be checked for NULL value +#' @return logical TRUE if the pointer is NULL, otherwise FALSE +#' @export +is.null.externalptr <- function(pointer) { + if (class(pointer)!="externalptr") stop("pointer is not an externalptr.") + rv <- .Call("isnull", pointer) + return(rv) +} diff --git a/R/redland/README.md b/R/redland/README.md new file mode 100644 index 000000000..cf1d03dd1 --- /dev/null +++ b/R/redland/README.md @@ -0,0 +1,173 @@ +## redland +[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/redland)](https://cran.r-project.org/package=redland) + +- **Authors**: Matthew B. Jones, Peter Slaughter, Jeroen Ooms, Carl Boettiger, and Scott Chamberlain ([NCEAS](http://www.nceas.ucsb.edu)) +- [doi:10.5063/F1VM496B](http://doi.org/10.5063/F1VM496B) +- **License**: [Apache 2](http://opensource.org/licenses/Apache-2.0) +- [Package source code on Github](https://github.com/ropensci/redland-bindings) +- [**Submit Bugs and feature requests**](https://github.com/ropensci/redland-bindings/issues) + +The R package `redland` provides methods to create, query and write information +stored in the Resource Description Framework (RDF). An introduction to RDF can be +found at http://www.w3.org/TR/rdf-primer. In brief, RDF provides a structured +graph consisting of Statements composed of Subject, Predicate, and Object Nodes. + +This package is implemented as R scripts that provide an R interface (aka +"wrapper") to the Redland RDF C libraries that are described at +http://librdf.org/docs/api/index.html. Additional information about the software that +provides the connection or 'bindings' between R and the Redland RDF C libraries +is available at https://github.com/ropensci/redland-bindings/tree/master/R. + +In this redland R package, S4 classes are +used to model RDF data structures. A `redland::Statement` is composed of +`redland::Node`s representing the subject, predicate, and object of each triple +statement. Statements can be composed into a graph by adding them to a +`redland::Model`, which in turn can be serialized and deserialized to RDF's text +formats using `redland::Serializer` and `redland::Parser`, respectively. + +See the `redland_overview` vignette for a brief example of usage. + +## Installation Notes + +The *redland* R package is now available from CRAN. Before the `redland` R package can be installed, the Redland C libraries may need to be installed, depending on the platform type you are installing to and whether or not you wish to install +from source. + +### Installing on Mac OS X + +On Mac OS X, the binary build from CRAN can be installed without installing the Redland C libraries by typing the +following commands in the R console: + +``` +install.packages("redland") +library(redland) +``` + +The *redland* R package should be available for use at this point. + +Alternatively, to install *redland* from source, please continue reading this section. + +The required Redland C libraries can be installed with either [Mac Ports](https://www.macports.org) package manager +or the [HomeBrew](http://brew.sh) package manager. The HomeBrew package manager can be significantly faster to install +but either one will work provided the directions shown below are followed. + +You can check if you have MacPorts installed by entering the following command in a terminal window: + +``` +port version +``` + +#### Installing on Mac OS X with Macports +If you are already using the MacPorts package manager, you can install *redland* with the following commands, +otherwise, it is recommended that you skip to the next section *Installing with HomeBrew*. To install +the *redland* R package with MacPorts, enter these commands at a terminal window: + +``` +sudo port install redland +``` +Then enter these commands in the R console: +``` +install.packages("redland", type="source") +library(redland) +``` + +Please note that the *install.packages* command specifies a "source" installation. Installing from +source is only necessary if Macports is being used, and is not a requirement if Homebrew is used. + +The *redland* R package should be available for use at this point + +#### Installing on Mac OS X with HomeBrew +On Mac OS X you can use the package management system [HomeBrew](http://brew.sh) to install the +necessary libraries. The HomeBrew software can be installed with the following command entered at a terminal window: + +``` +ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" +``` + +Once HomeBrew has been installed, you can then enter the following command to install the Redland C libraries: + +``` +brew install redland +``` + +Next, install the *redland* R package with these commands typed at the R console window: +``` +install.packages("redland", type="source") +library(redland) +``` + +The *redland* R package should be available for use at this point. + +## Installing on Ubuntu + +For ubuntu, install the required Redland C libraries: + +``` +sudo apt-get update +sudo apt-get install librdf0 librdf0-dev +``` + +Then install the R packages from the R console: + +``` +install.packages("redland") +library(redland) +``` + +## Installing on Windows + +For windows, the redland R package is distributed as a binary release, and it is not necessary to install any +additional system libraries. + +To install the R packages from the R console: + +``` +install.packages("redland") +library(redland) +``` + +## Example Usage + +The `redland` library can be used for a wide variety of RDF parsing and creation tasks. Some examples +are provided in the `redland_overview` vignette. As a quick start, here is an example that +creates an RDF graph using an in-memory storage model, adds some triples, and then +serializes the graph to disk. + +```r +library(redland) + +# World is the redland mechanism for scoping models +world <- new("World") + +# Storage provides a mechanism to store models; in-memory hashes are convenient for small models +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") + +# A model is a set of Statements, and is associated with a particular Storage instance +model <- new("Model", world=world, storage, options="") + +# Add some Dublin Core properties to the model +dc <- "http://purl.org/dc/elements/1.1/" +stmt <- new("Statement", world=world, + subject="http://ropensci.org/", predicate=paste0(dc, "title"), object="ROpenSci") +addStatement(model, stmt) +stmt <- new("Statement", world=world, + subject="http://ropensci.org/", predicate=paste0(dc, "language"), object="en") +addStatement(model, stmt) +stmt <- new("Statement", world=world, + subject="http://ropensci.org/", predicate=paste0(dc, "license"), + object="https://creativecommons.org/licenses/by/2.0/") +addStatement(model, stmt) + +# Serialize the model to a TTL file +serializer <- new("Serializer", world, name="turtle", mimeType="text/turtle") +status <- setNameSpace(serializer, world, namespace="http://purl.org/dc/elements/1.1/", prefix="dc") +filePath <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".ttl") +status <- serializeToFile(serializer, world, model, filePath) +readLines(file(filePath)) +``` + +## Acknowledgments +Work on this package was supported by NSF-ABI grant #1262458 to C. Gries, M. Jones, and S. Collins. + +[![nceas_footer](https://www.nceas.ucsb.edu/files/newLogo_0.png)](http://www.nceas.ucsb.edu) + +[![ropensci_footer](http://ropensci.org/public_images/github_footer.png)](http://ropensci.org) diff --git a/R/redland/cleanup b/R/redland/cleanup new file mode 100755 index 000000000..3c020d388 --- /dev/null +++ b/R/redland/cleanup @@ -0,0 +1,2 @@ +#!/bin/sh +rm -f src/Makevars diff --git a/R/redland/configure b/R/redland/configure new file mode 100755 index 000000000..a088286cb --- /dev/null +++ b/R/redland/configure @@ -0,0 +1,74 @@ +#!/bin/bash +# Anticonf (tm) script by Jeroen Ooms (2017) +# This script will query 'pkg-config' for the required cflags and ldflags. +# If pkg-config is unavailable or does not find the library, try setting +# INCLUDE_DIR and LIB_DIR manually via e.g: +# R CMD INSTALL --configure-vars='INCLUDE_DIR=/.../include LIB_DIR=/.../lib' + +# Library settings +PKG_CONFIG_NAME="redland" +PKG_DEB_NAME="librdf0-dev" +PKG_RPM_NAME="redland-devel" +PKG_BREW_NAME="redland" +PKG_TEST_HEADER="" +PKG_LIBS="-lrdf" +PKG_CFLAGS="" + +# Use pkg-config if available +if [ $(command -v pkg-config) ]; then + PKGCONFIG_CFLAGS=$(pkg-config --cflags --silence-errors ${PKG_CONFIG_NAME}) + PKGCONFIG_LIBS=$(pkg-config --libs ${PKG_CONFIG_NAME}) +fi + +# Note that cflags may be empty in case of success +if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then + echo "Found INCLUDE_DIR and/or LIB_DIR!" + PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS" + PKG_LIBS="-L$LIB_DIR $PKG_LIBS" +elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then + echo "Found pkg-config cflags and libs!" + PKG_CFLAGS=${PKGCONFIG_CFLAGS} + PKG_LIBS=${PKGCONFIG_LIBS} +elif [[ "$OSTYPE" == "darwin"* ]]; then + if [ $(command -v brew) ]; then + BREWDIR=$(brew --prefix) + else + curl -sfL "https://jeroen.github.io/autobrew/$PKG_BREW_NAME" > autobrew + source autobrew + fi + PKG_CFLAGS=$($BREWDIR/opt/pkg-config/bin/pkg-config --cflags ${PKG_CONFIG_NAME}) + PKG_LIBS=$($BREWDIR/opt/pkg-config/bin/pkg-config --libs --static ${PKG_CONFIG_NAME}) +fi + +# For debugging +echo "Using PKG_CFLAGS=$PKG_CFLAGS" +echo "Using PKG_LIBS=$PKG_LIBS" + +# Find compiler +CC=$(${R_HOME}/bin/R CMD config CC) +CFLAGS=$(${R_HOME}/bin/R CMD config CFLAGS) +CPPFLAGS=$(${R_HOME}/bin/R CMD config CPPFLAGS) + +# Test configuration +echo "#include $PKG_TEST_HEADER" | ${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E -xc - >/dev/null 2>&1 || R_CONFIG_ERROR=1; + +# Customize the error +if [ $R_CONFIG_ERROR ]; then + echo "------------------------- ANTICONF ERROR ---------------------------" + echo "Configuration failed because $PKG_CONFIG_NAME was not found. Try installing:" + echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu, etc)" + echo " * rpm: $PKG_RPM_NAME (Fedora, EPEL)" + echo " * brew: $PKG_BREW_NAME (OSX)" + echo "If $PKG_CONFIG_NAME is already installed, check that 'pkg-config' is in your" + echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config" + echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:" + echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'" + echo "--------------------------------------------------------------------" + exit 1; +fi + +# Write to Makevars +sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars + +# Success +exit 0 diff --git a/R/redland/configure.win b/R/redland/configure.win new file mode 100644 index 000000000..e69de29bb diff --git a/R/redland/cran-comments.md b/R/redland/cran-comments.md new file mode 100644 index 000000000..bb9112552 --- /dev/null +++ b/R/redland/cran-comments.md @@ -0,0 +1,34 @@ + +## Test environments + +* macOS 10.14.5, R 3.6.1 +* Ubuntu 19.04, R 3.6.1 +* Windows 7, R 3.6.1, R 3.6.1 +* Windows (via win-builder): x86_64-w64-mingw32 (64-bit), R version 3.5.3 (2019-03-11) +* Windows (via win-builder): x86_64-w64-mingw32 (64-bit), R version 3.6.1 (2019-07-05) +* Windows (via win-builder): x86_64-w64-mingw32 (64-bit), R Under development (unstable) 2019-09-27 r77229 + +## Changes since last release + +* Resolve deprecated function warnings during package build. (#79) + Note the the first CRAN submission for this package version 1.10.17-11 contained build warnings regarding + the deprecated C library rdflib_node_to_string(). In order to remove this warning, the dependant R + function getNextResult() has been removed. The function getNextResult() has been superceded by the + more efficient getResults(). +* Fix memory protection problems reported by 'rchk'. (#78) + +## R CMD check results + +* There were no ERRORs. +* There were several WARNINGS, all of which originate in the upstream librdf code library which is + being wrapped in R, and so are not due to the code in this package. +* There was the following 1 NOTE: + - A NOTE regarding "sub-directories of 1Mb or more" for the libs directory. + For the Windows builds only, the "libs" directory contains only the redland.dll + files build for each Windows sub-architecture (i385, x64) and is necessary for + the redland package to run. + +## Downstream dependencies + +* The downstream dependencies (datapack, rdflib) have been checked with devtools::revdep_check(), which passed + with 0 errors, 0 warnings, 0 notes. diff --git a/R/redland/inst/CITATION b/R/redland/inst/CITATION new file mode 100644 index 000000000..8f92ba925 --- /dev/null +++ b/R/redland/inst/CITATION @@ -0,0 +1,15 @@ +year <- sub("-.*", "", meta$Date) +note <- sprintf("R package version %s", meta$Version) +title <- meta$Title +authors <- c(person("Matthew B.", "Jones", role = c("aut", "cre"), email = "jones@nceas.ucsb.edu"), + person("Peter", "Slaughter", role = c("aut"), email = "slaughter@nceas.ucsb.edu"), + person("Jeroen", "Ooms", role=c("aut"), email="jereonooms@gmail.com"), + person("Carl", "Boettiger", role = c("aut"), email = "cboettig@gmail.com"), + person("Scott", "Chamberlain", role = c("aut"), email = "myrmecocystus@gmail.com")) +bibentry(bibtype = "Manual", + title = paste0("{redland}: ", title), + author = authors, + year = year, + note = note, + url = "https://github.com/ropensci/redland-bindings/tree/master/R/redland", + doi = "10.5063/F1VM496B") diff --git a/R/redland/inst/COPYRIGHTS b/R/redland/inst/COPYRIGHTS new file mode 100644 index 000000000..a8a1e1a13 --- /dev/null +++ b/R/redland/inst/COPYRIGHTS @@ -0,0 +1,23 @@ +The Redland R package is copyright; + Copyright (C) 2014-2016 Regents of the University of California + +This product includes Redland software (http://librdf.org/) +developed at the Institute for Learning and Research Technology, +University of Bristol, UK (http://www.bristol.ac.uk/). + +Redland Software is copyright: + Copyright (C) 2000-2013 David Beckett + Copyright (C) 2000-2005 University of Bristol + +and is included in this derivative product under the terms of the Apache 2 license, which +requires posting of a NOTICE file, which is included in this package. + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +except in compliance with the License. You may obtain a copy of the License at: + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +either express or implied. See the License for the specific language governing permissions +and limitations under the License. diff --git a/R/redland/inst/NOTICE b/R/redland/inst/NOTICE new file mode 100644 index 000000000..c0aedda59 --- /dev/null +++ b/R/redland/inst/NOTICE @@ -0,0 +1,13 @@ +This product includes Redland software (http://librdf.org/) +developed at the Institute for Learning and Research Technology, +University of Bristol, UK (http://www.bristol.ac.uk/). + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +except in compliance with the License. You may obtain a copy of the License at: + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +either express or implied. See the License for the specific language governing permissions +and limitations under the License. diff --git a/R/redland/inst/WORDLIST b/R/redland/inst/WORDLIST new file mode 100644 index 000000000..3a865f286 --- /dev/null +++ b/R/redland/inst/WORDLIST @@ -0,0 +1,80 @@ +ABI +Cómo +Destructor +ExternalReferences +Github +Gries +Hola +HomeBrew +Homebrew +MacPorts +Macports +NAMSPACE +NCEAS +QueryResult +QueryResults +RDF +RDF's +Rasqal +Roxygen +SPARQL +SWIGArray +Serializer +Synchronise +URI +URIs +Uuri +VM +VignetteEncoding +VignetteEngine +VignetteIndexEntry +XMLSchema +api +conten +csv +deserialized +devtools +doi +env +estás +executeQuery +externalptr +formness +freeNode +func +funciton +getNextResult +http +https +initialise +isa +json +knitr +lexicographically +li +libdf +librdf +mergeNamespace +mergedNamespace +mimeType +mysql +nceas +nodeID +normalised +parsers +postgresql +querystring +rdf +rdfxml +rmarkdown +roc +roclet +roclets +ropensci +roxygen +roxygenize +roxygenized +serializer +ubuntu +uri +www \ No newline at end of file diff --git a/R/redland/inst/extdata/dc.rdf b/R/redland/inst/extdata/dc.rdf new file mode 100755 index 000000000..9afbf0377 --- /dev/null +++ b/R/redland/inst/extdata/dc.rdf @@ -0,0 +1,9 @@ + + + + Dave Beckett's Home Page + Dave Beckett + The generic home page of Dave Beckett. + + diff --git a/R/redland/inst/extdata/example.rdf b/R/redland/inst/extdata/example.rdf new file mode 100644 index 000000000..5ebd01738 --- /dev/null +++ b/R/redland/inst/extdata/example.rdf @@ -0,0 +1,9 @@ + + + + John Smith's Home Page + John Smith + The generic home page of John Smith + + diff --git a/R/redland/man/Model-class.Rd b/R/redland/man/Model-class.Rd new file mode 100644 index 000000000..d53a195cc --- /dev/null +++ b/R/redland/man/Model-class.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Model.R +\docType{class} +\name{Model-class} +\alias{Model-class} +\alias{Model} +\title{A Redland Model object} +\description{ +A Model object is used to store the statements (triples) of an RDF model. +} +\details{ +A Model may be created manually by creating \code{\link{Statement}} and adding +them to the Model using \code{\link{addStatement}}, or a Model may be read in from a +previously saved file using \code{\link{parseFileIntoModel}}. Once a Model is created, +it can be queried using \code{\link{Query}}. +} +\section{Slots}{ + +\describe{ +\item{\code{librdf_model}}{A redland model object} +}} + +\section{Methods}{ + +\itemize{ +\item{\code{\link{Model-initialize}}}{: Initialize a Model object} +\item{\code{\link{addStatement}}}{: Add a Statement object to the Model} +\item{\code{\link{freeModel}}}{: Free memory used by a librdf model object} +} +} + +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +} +\seealso{ +View examples of creating models by viewing the \code{'redland_overview'} vignette: \code{'vignette("redland_overview")'} + +\code{\link{redland}}{: redland package} +} +\keyword{classes} diff --git a/R/redland/man/Model-initialize.Rd b/R/redland/man/Model-initialize.Rd new file mode 100644 index 000000000..51511101c --- /dev/null +++ b/R/redland/man/Model-initialize.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Model.R +\docType{methods} +\name{initialize,Model-method} +\alias{initialize,Model-method} +\alias{Model-initialize} +\title{Constructor for a Model object.} +\usage{ +\S4method{initialize}{Model}(.Object, world, storage, options) +} +\arguments{ +\item{.Object}{a Node object} + +\item{world}{a World object} + +\item{storage}{a Storage object} + +\item{options}{extra options for model initialization} +} +\value{ +the World object +} +\description{ +Constructor for a Model object. +} diff --git a/R/redland/man/Node-class.Rd b/R/redland/man/Node-class.Rd new file mode 100644 index 000000000..d5c34a270 --- /dev/null +++ b/R/redland/man/Node-class.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Node.R +\docType{class} +\encoding{UTF-8} +\name{Node-class} +\alias{Node-class} +\alias{Node} +\title{A Redland Node, used to store one node in an RDF triple statement.} +\description{ +A Node represents a RDF Resource, Property, Literal or an RDF blank Node. +} +\section{Slots}{ + +\describe{ +\item{\code{librdf_node}}{A redland node object} +}} + +\section{Methods}{ + +\itemize{ +\item{\code{\link{Node-initialize}}}{: Initialize a Node object.} +\item{\code{\link{getNodeType}}}{: Determine the node type and return as a string.} +\item{\code{\link{getNodeValue}}}{: Determine the node type and return as a string.} +\item{\code{\link{getBlankNodeId}}}{: Get the value of the node as a string.} +} +} + +\examples{ +world <- new("World") +# a blank node is created with a unique identifier generated by librdf +node <- new("Node", world) +# a blank node is created with a unique identifier generated by librdf +node <- new("Node", world, blank=NULL) +# a blank node is created with the user specified identifier, i.e. "_:id1" +node <- new("Node", world, blank="someid") +# a node type of 'literal' is created +node <- new("Node", world, literal="A Node Value") +# a Node type of 'resource' is created +node <- new("Node", world, uri="http://www.example.com") +# Create a literal node, specifying a language encoding +node <- new("Node", world, literal="Gérard de La Martinière", language="fr") +} +\seealso{ +\code{\link{redland}}{: redland package} +} +\keyword{classes} diff --git a/R/redland/man/Node-initialize.Rd b/R/redland/man/Node-initialize.Rd new file mode 100644 index 000000000..04445927a --- /dev/null +++ b/R/redland/man/Node-initialize.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Node.R +\docType{methods} +\name{initialize,Node-method} +\alias{initialize,Node-method} +\alias{Node-initialize} +\title{Initialize a Node object.} +\usage{ +\S4method{initialize}{Node}(.Object, world, literal, uri, blank, + datatype_uri, language) +} +\arguments{ +\item{.Object}{the Node object to be initialized} + +\item{world}{a World object} + +\item{literal}{a literal character value to be assigned to the node} + +\item{uri}{a uri character value to be assigned to the node} + +\item{blank}{a blank node identifier to be assigned to the node} + +\item{datatype_uri}{a uri used to specify the datatype of a literal node, i.e. "http://www.w3.org/2001/XMLSchema#string"} + +\item{language}{a character value specifying the RDF language tag (excluding the "@" symbol), i.e. "fr"} +} +\value{ +the Node object +} +\description{ +A Node has an associated type corresponding to the RDF component that it is representing. The list of possible +types is "resource", "literal" or "blank". +} +\details{ +The url=' and 'literal=' arguments determine which type of Node is created. The Node type affects how the Node is processed +in serialization, for example a Node created with 'node1 <- new("Node", literal="http://www.example.com")' is processed +differently that a Node created with 'node1 <- new("Node", url="http://www.example.com")', with the former being processed +as an RDF literal and the latter processed as an RDF resource. +} +\note{ +Refer to https://www.w3.org/TR/rdf11-concepts information on language tags. +} diff --git a/R/redland/man/Parser-class.Rd b/R/redland/man/Parser-class.Rd new file mode 100644 index 000000000..42093256b --- /dev/null +++ b/R/redland/man/Parser-class.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Parser.R +\docType{class} +\name{Parser-class} +\alias{Parser-class} +\alias{Parser} +\title{An RDF Parser object} +\description{ +The Parser class provides methods to parse RDF content into a Redland +RDF model. +} +\section{Slots}{ + +\describe{ +\item{\code{librdf_parser}}{A redland parser object} +}} + +\section{Methods}{ + +\itemize{ +\item{\code{\link{Parser-initialize}}}{: Initialize a Parser object.} +\item{\code{\link{parseFileIntoModel}}}{: Parse the contents of a file into a model.} +\item{\code{\link{freeParser}}}{: Free memory used by a librdf parser.} +} +} + +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +# Create the default "rdfxml" parser +parser <- new("Parser", world) +filePath <- system.file("extdata/example.rdf", package="redland") +parseFileIntoModel(parser, world, filePath, model) +} +\seealso{ +\code{\link{redland}}{: redland package} +} +\keyword{classes} diff --git a/R/redland/man/Parser-initialize.Rd b/R/redland/man/Parser-initialize.Rd new file mode 100644 index 000000000..693112653 --- /dev/null +++ b/R/redland/man/Parser-initialize.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Parser.R +\docType{methods} +\name{initialize,Parser-method} +\alias{initialize,Parser-method} +\alias{Parser-initialize} +\title{Initialize a Parser object.} +\usage{ +\S4method{initialize}{Parser}(.Object, world, name = "rdfxml", + mimeType = "application/rdf+xml", typeUri = as.character(NA)) +} +\arguments{ +\item{.Object}{the Parser object} + +\item{world}{a World object} + +\item{name}{name of the parser factory to use} + +\item{mimeType}{a mime type of the syntax of the model} + +\item{typeUri}{a URI for the syntax of the model} +} +\value{ +the Parser object +} +\description{ +A Parser object is initialized for a specific RDF serialization. +} +\details{ +The serialization format that are supported by +} diff --git a/R/redland/man/Query-class.Rd b/R/redland/man/Query-class.Rd new file mode 100644 index 000000000..1eab176e5 --- /dev/null +++ b/R/redland/man/Query-class.Rd @@ -0,0 +1,70 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Query.R +\docType{class} +\name{Query-class} +\alias{Query-class} +\alias{Query} +\title{Query an RDF model} +\description{ +The Query class is used to execute a query on a Model object using the default query +language SPARQL. For more information, please refer to \url{http://librdf.org/rasqal/} for details on +supported query languages. +} +\details{ +A Query is executed using the executeQuery method, which returns a QueryResults object that +can be iterated over the query solution sequence. +} +\section{Slots}{ + +\describe{ +\item{\code{librdf_query}}{A redland query object} + +\item{\code{librdf_world}}{A redland world object} +}} + +\section{Methods}{ + +\itemize{ +\item{\code{\link{Query-initialize}}}{: Initialize a Query object.} +\item{\code{\link{executeQuery}}}{: Execute a query.} +\item{\code{\link{setQueryResultLimit}}}{: Set limit on returned query results.} +\item{\code{\link{getQueryResultLimit}}}{: Get the query result limit.} +\item{\code{\link{getResults}}}{: Return all query results.} +\item{\code{\link{writeResults}}}{: Write query results to a file.} +\item{\code{\link{freeParser}}}{: Free memory used by a librdf query.} +} +} + +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +stmt <- new("Statement", world=world, + subject="https://cn.dataone.org/cn/v1/resolve/urn:uuid:274a0c5c-3082-4562-bbd3-2b1288768cac", + predicate="http://www.w3.org/ns/prov#hadPlan", + object="https://cn.dataone.org/cn/v1/resolve/urn:uuid:01305f45-f22b-40c8-8d27-00357d01e4a5") +status <- addStatement(model, stmt) +stmt <- new("Statement", world=world, + subject="https://orcid.org/0000-0002-2192-403X", + predicate="http://www.w3.org/ns/prov#Agent", + object="slaughter", + objectType="literal", + datatype_uri="http://www.w3.org/2001/XMLSchema#string") +status <- addStatement(model, stmt) +queryString <- + paste("PREFIX orcid: ", + "PREFIX dataone: ", + "PREFIX prov: ", + "SELECT ?a ?c WHERE { ?a prov:Agent ?c . }", sep=" ") +query <- new("Query", world, queryString, base_uri=NULL, query_language="sparql", query_uri=NULL) +# Return all results as a string +results <- getResults(query, model, "rdfxml") + +} +\references{ +www.example.com +} +\seealso{ +\code{\link{redland}}{: redland package} +} +\keyword{classes} diff --git a/R/redland/man/Query-initialize.Rd b/R/redland/man/Query-initialize.Rd new file mode 100644 index 000000000..e0ae33b66 --- /dev/null +++ b/R/redland/man/Query-initialize.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Query.R +\docType{methods} +\name{initialize,Query-method} +\alias{initialize,Query-method} +\alias{Query-initialize} +\title{Initialize the Query object.} +\usage{ +\S4method{initialize}{Query}(.Object, world, querystring, + base_uri = NULL, query_language = "sparql", query_uri = NULL) +} +\arguments{ +\item{.Object}{the Query object} + +\item{world}{a World object} + +\item{querystring}{a query string for the language specified in 'query_language'} + +\item{base_uri}{a URI to prepend to relative URI in the document} + +\item{query_language}{the query language to execute the querystring with} + +\item{query_uri}{a URI to prepend to terms in the query} +} +\value{ +the Query object +} +\description{ +Initialize the Query object. +} diff --git a/R/redland/man/QueryResults-class.Rd b/R/redland/man/QueryResults-class.Rd new file mode 100644 index 000000000..866e9b78b --- /dev/null +++ b/R/redland/man/QueryResults-class.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/QueryResults.R +\docType{class} +\name{QueryResults-class} +\alias{QueryResults-class} +\alias{QueryResults} +\title{A Redland QueryResults object is used to inspect query results from a Query object.} +\description{ +The QueryResults object contains the RDF statements that were returned from +a query on an RDF model. +} +\section{Slots}{ + +\describe{ +\item{\code{librdf_query_results}}{A redland query object} +}} + +\section{Methods}{ + +\itemize{ +\item{\code{\link{QueryResults-initialize}}}{: Initialize a QueryResults object.} +\item{\code{\link{freeQueryResults}}}{: Free memory used by a librdf query result.} +} +} + +\seealso{ +\code{\link{redland}}{: redland package} +} +\keyword{classes} diff --git a/R/redland/man/QueryResults-initialize.Rd b/R/redland/man/QueryResults-initialize.Rd new file mode 100644 index 000000000..b4d037c3f --- /dev/null +++ b/R/redland/man/QueryResults-initialize.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/QueryResults.R +\docType{methods} +\name{initialize,QueryResults-method} +\alias{initialize,QueryResults-method} +\alias{QueryResults-initialize} +\title{Initialize the QueryResults object.} +\usage{ +\S4method{initialize}{QueryResults}(.Object, results) +} +\arguments{ +\item{.Object}{the QueryResults object.} + +\item{results}{a librdf query result} +} +\value{ +the QueryResults object +} +\description{ +The QueryResults object is initialized with the librdf query result from +return value of \code{'Query.execute()'}. +} +\details{ +A QueryResults object is returned by the \code{Query.executeQuery()} method, so typically a user +does not initialize a QueryResult object by calling \code{new("QueryResult", ...)} +} diff --git a/R/redland/man/Serializer-class.Rd b/R/redland/man/Serializer-class.Rd new file mode 100644 index 000000000..b0bf936c7 --- /dev/null +++ b/R/redland/man/Serializer-class.Rd @@ -0,0 +1,45 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Serializer.R +\docType{class} +\name{Serializer-class} +\alias{Serializer-class} +\alias{Serializer} +\title{An RDF Serializer object.} +\description{ +The Serializer class provides methods to convert a Model object +to other forms, for example, write out a Model to a file. +} +\section{Slots}{ + +\describe{ +\item{\code{librdf_serializer}}{A redland statement object} +}} + +\section{Methods}{ + +\itemize{ +\item{\code{\link{Serializer-initialize}}}{: Initialize a Serializer object.} +\item{\code{\link{setNameSpace}}}{: Set a namespace for the serializer.} +\item{\code{\link{serializeToCharacter}}}{: Serialize a model to a character vector.} +\item{\code{\link{serializeToFile}}}{: Serialize a model to a file.} +\item{\code{\link{freeSerializer}}}{: Free memory used by a librdf serializer.} +} +} + +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +filePath <- system.file("extdata/example.rdf", package="redland") +parser <- new("Parser", world) +parseFileIntoModel(parser, world, filePath, model) +# Creat the default "rdfxml" serizlizer +serializer <- new("Serializer", world) +# Add a namespace definition to the serializer +status <- setNameSpace(serializer, world, namespace="http://purl.org/dc/elements/1.1/", prefix="dc") +rdf <- serializeToCharacter(serializer, world, model, baseUri="") +} +\seealso{ +\code{\link{redland}}{: redland package} +} +\keyword{classes} diff --git a/R/redland/man/Serializer-initialize.Rd b/R/redland/man/Serializer-initialize.Rd new file mode 100644 index 000000000..82c41ca8f --- /dev/null +++ b/R/redland/man/Serializer-initialize.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Serializer.R +\docType{methods} +\name{initialize,Serializer-method} +\alias{initialize,Serializer-method} +\alias{Serializer-initialize} +\title{Construct a Serializer object.} +\usage{ +\S4method{initialize}{Serializer}(.Object, world, name = "rdfxml", + mimeType = "application/rdf+xml", typeUri = as.character(NA)) +} +\arguments{ +\item{.Object}{the Serializer object} + +\item{world}{a World object} + +\item{name}{name of a previously created serializer factory to use} + +\item{mimeType}{a mime type of the syntax of the model} + +\item{typeUri}{a URI for the syntax of the model} +} +\value{ +the Serializer object +} +\description{ +Construct a Serializer object. +} diff --git a/R/redland/man/Statement-class.Rd b/R/redland/man/Statement-class.Rd new file mode 100644 index 000000000..f8ba61228 --- /dev/null +++ b/R/redland/man/Statement-class.Rd @@ -0,0 +1,59 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Statement.R +\docType{class} +\encoding{UTF-8} +\name{Statement-class} +\alias{Statement-class} +\alias{Statement} +\title{An RDF Statement object} +\description{ +A Statement object is created using the provided subject, predicate and object. +} +\details{ +A Statement object can be created from Node objects that are provided for the subject, +predicate and object. An alternative way to create a Statement object is to provide the +subject, predicate and object as character values. If this later method is used, the character values will be evaluated to +determine the appropriate RDF type for the subject and object. Note that the RDF type for the predicate will always +be 'uri' (aka 'resource'). If the automatic determination of RDF types is not desired, then the \code{subjectType} and +\code{objectType} parameters can be specified to explicitly set the RDF types. +} +\section{Slots}{ + +\describe{ +\item{\code{librdf_statement}}{A redland statement object} +}} + +\section{Methods}{ + +\itemize{ +\item{\code{\link{Statement-initialize}}}{: Initialize a Statement object.} +\item{\code{\link{getTermType}}}{: Return the redland node type for the specified RDF term in a statement.} +\item{\code{\link{freeStatement}}}{: Free memory used by a librdf statement.} +} +} + +\examples{ +world <- new("World") +# Create nodes manually and add to the statment +subject <- new("Node", blank="_:myid1", world) +predicate <- new("Node", uri="http://www.example.com/isa", world) +object <- new("Node", literal="thing", world) +stmt <- new("Statement", world, subject, predicate, object) + +# Create the statement specifying node values directly +stmt <- new("Statement", world, subject="http://www.example.com/myevent", + predicate="http://example.com/occurredAt", + object="Tue Feb 17 14:05:13 PST 2015") +stmt <- new("Statement", world, subject=NULL, + predicate="http://www.example.com/hasAddr", + object="http://www.nothing.com", objectType="literal") +stmt <- new("Statement", world, subject="http://www.example.com/BobSmith", + predicate="http://www.example.com/says", + object="¡Hola, amigo! ¿Cómo estás?", + objectType="literal", + language="es") +} +\seealso{ +\code{\link{redland}}{: redland package} +} +\keyword{classes} diff --git a/R/redland/man/Statement-initialize.Rd b/R/redland/man/Statement-initialize.Rd new file mode 100644 index 000000000..d30a6df9e --- /dev/null +++ b/R/redland/man/Statement-initialize.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Statement.R +\docType{methods} +\name{initialize,Statement-method} +\alias{initialize,Statement-method} +\alias{Statement-initialize} +\title{Construct a Statement object.} +\usage{ +\S4method{initialize}{Statement}(.Object, world, subject, predicate, + object, subjectType = as.character(NA), + objectType = as.character(NA), datatype_uri = as.character(NA), + language = as.character(NA)) +} +\arguments{ +\item{.Object}{the Statement object} + +\item{world}{a World object} + +\item{subject}{a Node object} + +\item{predicate}{a Node object} + +\item{object}{a Node object} + +\item{subjectType}{the Node type of the subject, i.e. "blank", "uri"} + +\item{objectType}{the Node type of the object, i.e. "blank", "uri", "literal"} + +\item{datatype_uri}{the datatype URI to associate with a object literal value} + +\item{language}{a character value specifying the RDF language tag for an object literal value (excluding the "@" symbol), i.e. "fr"} +} +\value{ +the Statement object +} +\description{ +Construct a Statement object. +} diff --git a/R/redland/man/Storage-class.Rd b/R/redland/man/Storage-class.Rd new file mode 100644 index 000000000..e3d3c5380 --- /dev/null +++ b/R/redland/man/Storage-class.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Storage.R +\docType{class} +\name{Storage-class} +\alias{Storage-class} +\alias{Storage} +\title{A Redland Storage object} +\description{ +A Redland Storage object +} +\section{Slots}{ + +\describe{ +\item{\code{librdf_storage}}{A redland storage object} + +\item{\code{type}}{the storage type to create, i.e. "hashes", "mysql", "postgresql", ...} +}} + +\section{Methods}{ + +\itemize{ +\item{\code{\link{Storage-initialize}}}{: Initialize a Storage object} +\item{\code{\link{freeStorage}}}{: Free memory used by a librdf storage object} +} +} + +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +} +\seealso{ +\code{\link{redland}}{: redland package} +} +\keyword{classes} diff --git a/R/redland/man/Storage-initialize.Rd b/R/redland/man/Storage-initialize.Rd new file mode 100644 index 000000000..e0828511b --- /dev/null +++ b/R/redland/man/Storage-initialize.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Storage.R +\docType{methods} +\name{initialize,Storage-method} +\alias{initialize,Storage-method} +\alias{Storage-initialize} +\title{Initialize a Storage object} +\usage{ +\S4method{initialize}{Storage}(.Object, world, type = "hashes", + name = "", options = "hash-type='memory'") +} +\arguments{ +\item{.Object}{the Storage object} + +\item{world}{the World object} + +\item{type}{the Redland storage type} + +\item{name}{storage instance name} + +\item{options}{storage options} +} +\value{ +the Storage object +} +\description{ +Initialize a Storage object +} +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +} diff --git a/R/redland/man/World-class.Rd b/R/redland/man/World-class.Rd new file mode 100644 index 000000000..b9be64811 --- /dev/null +++ b/R/redland/man/World-class.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/World.R +\docType{class} +\name{World-class} +\alias{World-class} +\alias{World} +\title{A Redland World object, used to initialize the Redland RDF library.} +\description{ +A World object is the top level object in the Redland RDF library +implementation, so it contains all other objects needed to process RDF +Models. +} +\section{Slots}{ + +\describe{ +\item{\code{librdf_world}}{A redland world object} +}} + +\section{Methods}{ + +\itemize{ +\item{\code{\link{World-initialize}}}{: Initialize a World object} +\item{\code{\link{freeWorld}}}{: Free memory used by a librdf world object} +} +} + +\examples{ +world <- new("World") +} +\seealso{ +\code{\link{redland}}{: redland package} +} +\keyword{classes} diff --git a/R/redland/man/World-initialize.Rd b/R/redland/man/World-initialize.Rd new file mode 100644 index 000000000..80a5c3673 --- /dev/null +++ b/R/redland/man/World-initialize.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/World.R +\docType{methods} +\name{initialize,World-method} +\alias{initialize,World-method} +\alias{World-initialize} +\title{Initialize the World object.} +\usage{ +\S4method{initialize}{World}(.Object) +} +\arguments{ +\item{.Object}{the World object} +} +\value{ +the World object +} +\description{ +Initialize the World object. +} diff --git a/R/redland/man/addStatement.Rd b/R/redland/man/addStatement.Rd new file mode 100644 index 000000000..4708dace0 --- /dev/null +++ b/R/redland/man/addStatement.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Model.R +\docType{methods} +\name{addStatement} +\alias{addStatement} +\alias{addStatement,Model,Statement-method} +\title{Add a Statement object to the Model} +\usage{ +addStatement(.Object, statement) + +\S4method{addStatement}{Model,Statement}(.Object, statement) +} +\arguments{ +\item{.Object}{a Model object} + +\item{statement}{the Statement that will be added} +} +\description{ +Add a Statement object to the Model +} +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +} diff --git a/R/redland/man/executeQuery.Rd b/R/redland/man/executeQuery.Rd new file mode 100644 index 000000000..d8aad5fd9 --- /dev/null +++ b/R/redland/man/executeQuery.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Query.R +\docType{methods} +\name{executeQuery} +\alias{executeQuery} +\alias{executeQuery,Query-method} +\title{Execute a query} +\usage{ +executeQuery(.Object, model) + +\S4method{executeQuery}{Query}(.Object, model) +} +\arguments{ +\item{.Object}{a Query object} + +\item{model}{a Model object containing the statements to query} +} +\value{ +a QueryResults object +} +\description{ +The initialize query is executed and the result is returned as a QueryResult object +} diff --git a/R/redland/man/freeModel.Rd b/R/redland/man/freeModel.Rd new file mode 100644 index 000000000..6941db95c --- /dev/null +++ b/R/redland/man/freeModel.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Model.R +\docType{methods} +\name{freeModel} +\alias{freeModel} +\alias{freeModel,Model-method} +\title{Free memory used by a librdf model.} +\usage{ +freeModel(.Object) + +\S4method{freeModel}{Model}(.Object) +} +\arguments{ +\item{.Object}{a Model object} +} +\description{ +Free memory used by a librdf model. +} +\details{ +After this method is called, the Model object is no longer usable and should +be deleted \code{"rm(model)"} and a new object created. +} +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +# At this point, some operations would be performed with the model. +# See '?redland' for a complete example. +# When the Model object is no longer needed, the resources it has allocated can be freed. +freeModel(model) +rm(model) +} diff --git a/R/redland/man/freeParser.Rd b/R/redland/man/freeParser.Rd new file mode 100644 index 000000000..dd7fac047 --- /dev/null +++ b/R/redland/man/freeParser.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Parser.R +\docType{methods} +\name{freeParser} +\alias{freeParser} +\alias{freeParser,Parser-method} +\title{Free memory used by a librdf parser} +\usage{ +freeParser(.Object) + +\S4method{freeParser}{Parser}(.Object) +} +\arguments{ +\item{.Object}{a Node object} +} +\description{ +Free memory used by a librdf parser +} +\details{ +After freeNode is called, the Node object is no longer usable and should +be deleted \code{"rm(nodeName)"} and a new object created. +} +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +parser <- new("Parser", world) +filePath <- system.file("extdata/example.rdf", package="redland") +parseFileIntoModel(parser, world, filePath, model) +# At this point, some operations would be performed with the Model that has been populated +# with the parser. +# See '?redland' for a complete example. +# When the parser object is no longer needed, the resources it had allocated can be freed. +freeParser(parser) +rm(parser) +} diff --git a/R/redland/man/freeQuery.Rd b/R/redland/man/freeQuery.Rd new file mode 100644 index 000000000..ca416abb6 --- /dev/null +++ b/R/redland/man/freeQuery.Rd @@ -0,0 +1,45 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Query.R +\docType{methods} +\name{freeQuery} +\alias{freeQuery} +\alias{freeQuery,Query-method} +\title{Free memory used by a librdf query} +\usage{ +freeQuery(.Object) + +\S4method{freeQuery}{Query}(.Object) +} +\arguments{ +\item{.Object}{a Query object} +} +\description{ +Free memory used by a librdf query +} +\details{ +After this method is called, the Query object is no longer usable and should +be deleted \code{"rm(query)"} and a new object created. +} +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +stmt <- new("Statement", world=world, + subject="https://orcid.org/0000-0002-2192-403X", + predicate="http://www.w3.org/ns/prov#Agent", + object="slaughter", + objectType="literal", datatype_uri="http://www.w3.org/2001/XMLSchema#string") +status <- addStatement(model, stmt) +queryString <- paste("PREFIX orcid: ", + "PREFIX dataone: ", + "PREFIX prov: ", + "SELECT ?a ?c WHERE { ?a prov:Agent ?c . }", sep=" ") +query <- new("Query", world, queryString, base_uri=NULL, + query_language="sparql", query_uri=NULL) +# Return all results as a string +results <- getResults(query, model, "rdfxml") + +# When the query object is no longer needed, the resources it had allocated can be freed. +freeQuery(query) +rm(query) +} diff --git a/R/redland/man/freeQueryResults.Rd b/R/redland/man/freeQueryResults.Rd new file mode 100644 index 000000000..65b5afe7d --- /dev/null +++ b/R/redland/man/freeQueryResults.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/QueryResults.R +\docType{methods} +\name{freeQueryResults} +\alias{freeQueryResults} +\alias{freeQueryResults,QueryResults-method} +\title{Free memory used by a librdf query results} +\usage{ +freeQueryResults(.Object) + +\S4method{freeQueryResults}{QueryResults}(.Object) +} +\arguments{ +\item{.Object}{a QueryResults object} +} +\description{ +After this method is called, the QueryResults object is no longer usable and should +be deleted with \code{"rm(query)"}. +} diff --git a/R/redland/man/freeSerializer.Rd b/R/redland/man/freeSerializer.Rd new file mode 100644 index 000000000..a27e531a3 --- /dev/null +++ b/R/redland/man/freeSerializer.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Serializer.R +\docType{methods} +\name{freeSerializer} +\alias{freeSerializer} +\alias{freeSerializer,Serializer-method} +\title{Free memory used by a librdf serializer.} +\usage{ +freeSerializer(.Object) + +\S4method{freeSerializer}{Serializer}(.Object) +} +\arguments{ +\item{.Object}{a Serializer object} +} +\description{ +Free memory used by a librdf serializer. +} +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +filePath <- system.file("extdata/example.rdf", package="redland") +parser <- new("Parser", world) +parseFileIntoModel(parser, world, filePath, model) +# Creat the default "rdfxml" serizlizer +serializer <- new("Serializer", world) +# At this point, some operations would be performed with the Serializer object. +# See '?Serializer' for a complete example. +# When the serializer object is no longer needed, the resources it had allocated can be freed. +freeSerializer(serializer) +rm(serializer) +} diff --git a/R/redland/man/freeStatement.Rd b/R/redland/man/freeStatement.Rd new file mode 100644 index 000000000..b4a6127c3 --- /dev/null +++ b/R/redland/man/freeStatement.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Statement.R +\docType{methods} +\name{freeStatement} +\alias{freeStatement} +\alias{freeStatement,Statement-method} +\title{Free memory used by a librdf statement} +\usage{ +freeStatement(.Object) + +\S4method{freeStatement}{Statement}(.Object) +} +\arguments{ +\item{.Object}{a Statement object} +} +\description{ +Free memory used by a librdf statement +} +\details{ +After this method is called, the Statement object is no longer usable and should +be deleted \code{"rm(statement)"} and a new object created. This method frees +all resources for the statement, as well as each node in the statement. +} +\examples{ +world <- new("World") +stmt <- new("Statement", world, subject="http://www.example.com/myevent", + predicate="http://example.com/occurredAt", + object="Tue Feb 17 14:05:13 PST 2015") +# At this point, some operations would be performed with the Statement. +# See '?redland' for a complete example. +# When the Statement object is no longer needed, the resources it had allocated can be freed. +freeStatement(stmt) +rm(stmt) +} diff --git a/R/redland/man/freeStorage.Rd b/R/redland/man/freeStorage.Rd new file mode 100644 index 000000000..8640c43c7 --- /dev/null +++ b/R/redland/man/freeStorage.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Storage.R +\docType{methods} +\name{freeStorage} +\alias{freeStorage} +\alias{freeStorage,Storage-method} +\title{Free memory used by a librdf storage object} +\usage{ +freeStorage(.Object) + +\S4method{freeStorage}{Storage}(.Object) +} +\arguments{ +\item{.Object}{a Storage object to free memory for} +} +\description{ +After this method is called, the Storage object is no longer usable and should +be deleted \code{"rm(storage)"} and a new object created. +} +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +# At this point we would perform some operations using the storage object. +# See '?redland' for a complete example. +# When the Storage object is no longer needed, the resources it had allocated can be freed. +status <- freeStorage(storage) +rm(storage) +} diff --git a/R/redland/man/freeWorld.Rd b/R/redland/man/freeWorld.Rd new file mode 100644 index 000000000..e9639c752 --- /dev/null +++ b/R/redland/man/freeWorld.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/World.R +\docType{methods} +\name{freeWorld} +\alias{freeWorld} +\alias{freeWorld,World-method} +\title{Free memory used by a librdf world object} +\usage{ +freeWorld(.Object) + +\S4method{freeWorld}{World}(.Object) +} +\arguments{ +\item{.Object}{a World object} +} +\description{ +Free memory used by a librdf world object +} +\details{ +After this method is called, the World object is no longer usable and should +be deleted \code{"rm(world)"} and a new object created. +} +\examples{ +world <- new("World") +# At this point we would perform some operations using the world object. +# When the world object is no longer needed, we can free the resources it has allocated. +result <- freeWorld(world) +rm(world) +} diff --git a/R/redland/man/getBlankNodeId.Rd b/R/redland/man/getBlankNodeId.Rd new file mode 100644 index 000000000..c861d364d --- /dev/null +++ b/R/redland/man/getBlankNodeId.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Node.R +\docType{methods} +\name{getBlankNodeId} +\alias{getBlankNodeId} +\alias{getBlankNodeId,Node-method} +\title{Get the blank identifier that has been assigned for a specified Node object} +\usage{ +getBlankNodeId(.Object) + +\S4method{getBlankNodeId}{Node}(.Object) +} +\arguments{ +\item{.Object}{a Node object} +} +\value{ +a blank node identifier +} +\description{ +Get the blank identifier that has been assigned for a specified Node object +} +\details{ +When a Node object is initialized with no value specified, i.e. node <- Node(""), +a blank node is created and a locally unique identifier is generated by librdf. This method +retrieves this identifier and returns in to the caller. +} +\examples{ +world <- new("World") +# a blank node is created with a unique identifier generated by librdf +node <- new("Node", world, blank=NULL) +nodeId <- getBlankNodeId(node) +} diff --git a/R/redland/man/getNodeType.Rd b/R/redland/man/getNodeType.Rd new file mode 100644 index 000000000..9286b68c5 --- /dev/null +++ b/R/redland/man/getNodeType.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Node.R +\docType{methods} +\name{getNodeType} +\alias{getNodeType} +\alias{getNodeType,Node-method} +\title{Determine the node type and return as a string} +\usage{ +getNodeType(.Object) + +\S4method{getNodeType}{Node}(.Object) +} +\arguments{ +\item{.Object}{a Node object} +} +\value{ +a character vector containing the Node type +} +\description{ +A Node has a type that is assigned at initialization and can have one of the following values: +'resource', 'literal', 'blank' and 'unknown'. +} +\examples{ +world <- new("World") +node <- new("Node", world, uri="http://www.example.com") +nodeType <- getNodeType(node) +} diff --git a/R/redland/man/getNodeValue.Rd b/R/redland/man/getNodeValue.Rd new file mode 100644 index 000000000..bbc4b8259 --- /dev/null +++ b/R/redland/man/getNodeValue.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Node.R +\docType{methods} +\encoding{UTF-8} +\name{getNodeValue} +\alias{getNodeValue} +\alias{getNodeValue,Node-method} +\title{Get the value of the node as a string} +\usage{ +getNodeValue(.Object) + +\S4method{getNodeValue}{Node}(.Object) +} +\arguments{ +\item{.Object}{a Node object} +} +\value{ +a string representation of the Node's value +} +\description{ +Get the value of the node as a string +} +\details{ +The value of the node is returned as a string. If the node type is +'blank', then the blank node identifier is returned. If the node type is +'literal', then the literal value is returned with the form ""@, +e.g. "¡Hola, amigo! ¿Cómo estás?"@es". If the node type is 'uri' +then the value is returned as a string. +} +\examples{ +world <- new("World") +node <- new("Node", world, literal="¡Hola, amigo! ¿Cómo estás?", language="es") +value <- getNodeValue(node) +} diff --git a/R/redland/man/getQueryResultsLimit.Rd b/R/redland/man/getQueryResultsLimit.Rd new file mode 100644 index 000000000..a5b6babf2 --- /dev/null +++ b/R/redland/man/getQueryResultsLimit.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Query.R +\docType{methods} +\name{getQueryResultLimit} +\alias{getQueryResultLimit} +\alias{getQueryResultLimit,Query-method} +\title{Get the query result limit} +\usage{ +getQueryResultLimit(.Object) + +\S4method{getQueryResultLimit}{Query}(.Object) +} +\arguments{ +\item{.Object}{a Query object} +} +\value{ +the query result limit. If a limit is set then the value will be >= 0. If the value is < 0, no limit is set +} +\description{ +Get the query result limit +} diff --git a/R/redland/man/getResults.Rd b/R/redland/man/getResults.Rd new file mode 100644 index 000000000..75262fd88 --- /dev/null +++ b/R/redland/man/getResults.Rd @@ -0,0 +1,53 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Query.R +\docType{methods} +\name{getResults} +\alias{getResults} +\alias{getResults,Query-method} +\title{Return all query results} +\usage{ +getResults(.Object, model, ...) + +\S4method{getResults}{Query}(.Object, model, formatName = "rdfxml") +} +\arguments{ +\item{.Object}{a Query object} + +\item{model}{a Model object} + +\item{...}{additional parameters} + +\item{formatName}{a string specifying the RDF format name. Currently the supported formats are "rdfxml" ,"turtle", "json", "csv"} +} +\description{ +Return all query results +} +\details{ +After this method is called, the Query object is no longer usable and should +be deleted \code{"rm(query)"} and a new object created. +} +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +stmt <- new("Statement", world=world, + subject="https://orcid.org/0000-0002-2192-403X", + predicate="http://www.w3.org/ns/prov#Agent", + object="slaughter", + objectType="literal", datatype_uri="http://www.w3.org/2001/XMLSchema#string") + #objectType="literal", language="en") +status <- addStatement(model, stmt) +queryString <- paste("PREFIX orcid: ", + "PREFIX dataone: ", + "PREFIX prov: ", + "SELECT ?a ?c WHERE { ?a prov:Agent ?c . }", sep=" ") +query <- new("Query", world, queryString, base_uri=NULL, query_language="sparql", query_uri=NULL) +# Return all results as a string +results <- getResults(query, model, "rdfxml") +results <- getResults(query, model, "turtle") +results <- getResults(query, model, "json") + +# When the query object is no longer needed, the resources it had allocated can be freed. +freeQuery(query) +rm(query) +} diff --git a/R/redland/man/getTermType.Rd b/R/redland/man/getTermType.Rd new file mode 100644 index 000000000..d2b22a00b --- /dev/null +++ b/R/redland/man/getTermType.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Statement.R +\docType{methods} +\name{getTermType} +\alias{getTermType} +\alias{getTermType,Statement,character-method} +\title{Return the redland node type for the specified RDF term in a statement} +\usage{ +getTermType(.Object, term) + +\S4method{getTermType}{Statement,character}(.Object, term) +} +\arguments{ +\item{.Object}{a Statement object} + +\item{term}{the RDF term for which the type will be returned} +} +\description{ +After a Statement object has been created, this method can +be used to determine the RDF type ("uri", "literal", "blank") that has been +assigned to the specified RDF term, i.e. "subject", "predicate", "object". +} +\examples{ +world <- new("World") +subject <- new("Node", blank="_:myid1", world) +predicate <- new("Node", uri="http://www.example.com/isa", world) +object <- new("Node", literal="thing", world) +stmt <- new("Statement", world, subject, predicate, object, world) +termType <- getTermType(stmt, "predicate") +} diff --git a/R/redland/man/is.null.externalptr.Rd b/R/redland/man/is.null.externalptr.Rd new file mode 100644 index 000000000..285143027 --- /dev/null +++ b/R/redland/man/is.null.externalptr.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/util.R +\name{is.null.externalptr} +\alias{is.null.externalptr} +\title{Determine whether an externalptr object is NULL.} +\usage{ +is.null.externalptr(pointer) +} +\arguments{ +\item{pointer}{externalptr to be checked for NULL value} +} +\value{ +logical TRUE if the pointer is NULL, otherwise FALSE +} +\description{ +The pointer is treated as an externalptr and checked via a call in C to see if it is NULL. +} diff --git a/R/redland/man/length-SWIGArray-method.Rd b/R/redland/man/length-SWIGArray-method.Rd new file mode 100644 index 000000000..6d191209d --- /dev/null +++ b/R/redland/man/length-SWIGArray-method.Rd @@ -0,0 +1,14 @@ +\docType{methods} +\name{length,SWIGArray-method} +\alias{length,SWIGArray-method} +\title{Return length of a SWIGArray} +\usage{ +\S4method{length}{SWIGArray}(x) +} +\arguments{ +\item{x}{the SWIGArray} +} +\description{ +Return length of a SWIGArray +} + diff --git a/R/redland/man/librdf_copyright_string.Rd b/R/redland/man/librdf_copyright_string.Rd new file mode 100644 index 000000000..3850909c5 --- /dev/null +++ b/R/redland/man/librdf_copyright_string.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_copyright_string} +\alias{librdf_copyright_string} +\title{Copyright string (multiple lines).} +\usage{ +librdf_copyright_string ( .copy ) +} +\arguments{ + +\item{.copy}{NA} + +} +\value{ +character +} +\description{ +Copyright string (multiple lines). +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_copyright_string_get.Rd b/R/redland/man/librdf_copyright_string_get.Rd new file mode 100644 index 000000000..f1275caf3 --- /dev/null +++ b/R/redland/man/librdf_copyright_string_get.Rd @@ -0,0 +1,24 @@ +\name{librdf_copyright_string_get} +\alias{librdf_copyright_string_get} +\title{Return Redland RDF copyright string} +\usage{ +librdf_copyright_string_get (.copy) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +character +} +\description{ +Return the Redland RDF copyright +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_digest_final.Rd b/R/redland/man/librdf_digest_final.Rd new file mode 100644 index 000000000..65fef9cfb --- /dev/null +++ b/R/redland/man/librdf_digest_final.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_digest_final} +\alias{librdf_digest_final} +\title{Finish the digesting of data.} +\usage{ +librdf_digest_final ( digest ) +} +\arguments{ + +\item{digest}{the digest ("_p_librdf_digest_s")} + +} +\value{ +void +} +\description{ +Finish the digesting of data. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_digest_init.Rd b/R/redland/man/librdf_digest_init.Rd new file mode 100644 index 000000000..c801db8ed --- /dev/null +++ b/R/redland/man/librdf_digest_init.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_digest_init} +\alias{librdf_digest_init} +\title{(Re)initialise the librdf_digest object.} +\usage{ +librdf_digest_init ( digest ) +} +\arguments{ + +\item{digest}{the digest ("_p_librdf_digest_s")} + +} +\value{ +void +} +\description{ +(Re)initialise the librdf_digest object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_digest_to_string.Rd b/R/redland/man/librdf_digest_to_string.Rd new file mode 100644 index 000000000..216b547e5 --- /dev/null +++ b/R/redland/man/librdf_digest_to_string.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_digest_to_string} +\alias{librdf_digest_to_string} +\title{Get a string representation of the digest object.} +\usage{ +librdf_digest_to_string ( digest ) +} +\arguments{ + +\item{digest}{the digest ("_p_librdf_digest_s")} + +} +\value{ +character +} +\description{ +Get a string representation of the digest object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_digest_update.Rd b/R/redland/man/librdf_digest_update.Rd new file mode 100644 index 000000000..432650b70 --- /dev/null +++ b/R/redland/man/librdf_digest_update.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_digest_update} +\alias{librdf_digest_update} +\title{Add more data to the librdf_digest object.} +\usage{ +librdf_digest_update ( digest, + buf, + length ) +} +\arguments{ + +\item{digest}{the digest ("_p_librdf_digest_s")} + +\item{buf}{the data buffer ("character")} + +\item{length}{the length of the data ("integer")} + +} +\value{ +void +} +\description{ +Add more data to the librdf_digest object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_digest_update_string.Rd b/R/redland/man/librdf_digest_update_string.Rd new file mode 100644 index 000000000..0af311940 --- /dev/null +++ b/R/redland/man/librdf_digest_update_string.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_digest_update_string} +\alias{librdf_digest_update_string} +\title{Add a string to the librdf_digest object.} +\usage{ +librdf_digest_update_string ( digest, + string ) +} +\arguments{ + +\item{digest}{the digest ("_p_librdf_digest_s")} + +\item{string}{string to add ("character")} + +} +\value{ +void +} +\description{ +Add a string to the librdf_digest object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_digest.Rd b/R/redland/man/librdf_free_digest.Rd new file mode 100644 index 000000000..83e0d402e --- /dev/null +++ b/R/redland/man/librdf_free_digest.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_digest} +\alias{librdf_free_digest} +\title{Destructor - destroy a librdf_digest object.} +\usage{ +librdf_free_digest ( digest ) +} +\arguments{ + +\item{digest}{the digest ("_p_librdf_digest_s")} + +} +\value{ +void +} +\description{ +Destructor - destroy a librdf_digest object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_hash.Rd b/R/redland/man/librdf_free_hash.Rd new file mode 100644 index 000000000..5a14e5e7a --- /dev/null +++ b/R/redland/man/librdf_free_hash.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_hash} +\alias{librdf_free_hash} +\title{Destructor - destroy a librdf_hash object.} +\usage{ +librdf_free_hash ( hash ) +} +\arguments{ + +\item{hash}{hash object ("_p_librdf_hash_s")} + +} +\value{ +void +} +\description{ +Destructor - destroy a librdf_hash object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_iterator.Rd b/R/redland/man/librdf_free_iterator.Rd new file mode 100644 index 000000000..6812d372d --- /dev/null +++ b/R/redland/man/librdf_free_iterator.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_iterator} +\alias{librdf_free_iterator} +\title{Destructor - destroy a librdf_iterator object.} +\usage{ +librdf_free_iterator ( s_arg1 ) +} +\arguments{ + +\item{s_arg1}{the librdf_iterator object ("_p_librdf_iterator_s")} + +} +\value{ +void +} +\description{ +Destructor - destroy a librdf_iterator object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_model.Rd b/R/redland/man/librdf_free_model.Rd new file mode 100644 index 000000000..96522a8c1 --- /dev/null +++ b/R/redland/man/librdf_free_model.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_model} +\alias{librdf_free_model} +\title{Destructor - Destroy a librdf_model object.} +\usage{ +librdf_free_model ( model ) +} +\arguments{ + +\item{model}{librdf_model model to destroy ("_p_librdf_model_s")} + +} +\value{ +void +} +\description{ +Destructor - Destroy a librdf_model object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_node.Rd b/R/redland/man/librdf_free_node.Rd new file mode 100644 index 000000000..cb025bac4 --- /dev/null +++ b/R/redland/man/librdf_free_node.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_node} +\alias{librdf_free_node} +\title{Destructor - destroy an librdf_node object.} +\usage{ +librdf_free_node ( r ) +} +\arguments{ + +\item{r}{librdf_node object ("_p_librdf_node_s")} + +} +\value{ +void +} +\description{ +Destructor - destroy an librdf_node object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_parser.Rd b/R/redland/man/librdf_free_parser.Rd new file mode 100644 index 000000000..f688f7c2e --- /dev/null +++ b/R/redland/man/librdf_free_parser.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_parser} +\alias{librdf_free_parser} +\title{Destructor - destroys a librdf_parser object.} +\usage{ +librdf_free_parser ( parser ) +} +\arguments{ + +\item{parser}{the parser ("_p_librdf_parser_s")} + +} +\value{ +void +} +\description{ +Destructor - destroys a librdf_parser object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_query.Rd b/R/redland/man/librdf_free_query.Rd new file mode 100644 index 000000000..6c164c949 --- /dev/null +++ b/R/redland/man/librdf_free_query.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_query} +\alias{librdf_free_query} +\title{Destructor - destroy a librdf_query object.} +\usage{ +librdf_free_query ( query ) +} +\arguments{ + +\item{query}{librdf_query object ("_p_librdf_query")} + +} +\value{ +void +} +\description{ +Destructor - destroy a librdf_query object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_query_results.Rd b/R/redland/man/librdf_free_query_results.Rd new file mode 100644 index 000000000..2adbcbd39 --- /dev/null +++ b/R/redland/man/librdf_free_query_results.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_query_results} +\alias{librdf_free_query_results} +\title{Destructor - destroy a librdf_query_results object.} +\usage{ +librdf_free_query_results ( query_results ) +} +\arguments{ + +\item{query_results}{librdf_query_results object ("_p_librdf_query_results")} + +} +\value{ +void +} +\description{ +Destructor - destroy a librdf_query_results object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_serializer.Rd b/R/redland/man/librdf_free_serializer.Rd new file mode 100644 index 000000000..73f39505b --- /dev/null +++ b/R/redland/man/librdf_free_serializer.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_serializer} +\alias{librdf_free_serializer} +\title{Destructor - destroys a librdf_serializer object.} +\usage{ +librdf_free_serializer ( serializer ) +} +\arguments{ + +\item{serializer}{the serializer ("_p_librdf_serializer_s")} + +} +\value{ +void +} +\description{ +Destructor - destroys a librdf_serializer object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_statement.Rd b/R/redland/man/librdf_free_statement.Rd new file mode 100644 index 000000000..78712cabc --- /dev/null +++ b/R/redland/man/librdf_free_statement.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_statement} +\alias{librdf_free_statement} +\title{Destructor - destroy a librdf_statement.} +\usage{ +librdf_free_statement ( statement ) +} +\arguments{ + +\item{statement}{librdf_statement object ("_p_librdf_statement_s")} + +} +\value{ +void +} +\description{ +Destructor - destroy a librdf_statement. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_storage.Rd b/R/redland/man/librdf_free_storage.Rd new file mode 100644 index 000000000..a04bc7bae --- /dev/null +++ b/R/redland/man/librdf_free_storage.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_storage} +\alias{librdf_free_storage} +\title{Destructor - destroy a librdf_storage object.} +\usage{ +librdf_free_storage ( storage ) +} +\arguments{ + +\item{storage}{librdf_storage object ("_p_librdf_storage_s")} + +} +\value{ +void +} +\description{ +Destructor - destroy a librdf_storage object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_stream.Rd b/R/redland/man/librdf_free_stream.Rd new file mode 100644 index 000000000..479bf04e1 --- /dev/null +++ b/R/redland/man/librdf_free_stream.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_stream} +\alias{librdf_free_stream} +\title{Destructor - destroy an libdf_stream object.} +\usage{ +librdf_free_stream ( stream ) +} +\arguments{ + +\item{stream}{librdf_stream object ("_p_librdf_stream_s")} + +} +\value{ +void +} +\description{ +Destructor - destroy an libdf_stream object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_uri.Rd b/R/redland/man/librdf_free_uri.Rd new file mode 100644 index 000000000..539902164 --- /dev/null +++ b/R/redland/man/librdf_free_uri.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_uri} +\alias{librdf_free_uri} +\title{Destructor - destroy a librdf_uri object.} +\usage{ +librdf_free_uri ( uri ) +} +\arguments{ + +\item{uri}{librdf_uri object ("_p_librdf_uri_s")} + +} +\value{ +void +} +\description{ +Destructor - destroy a librdf_uri object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_free_world.Rd b/R/redland/man/librdf_free_world.Rd new file mode 100644 index 000000000..fc8d4d2fe --- /dev/null +++ b/R/redland/man/librdf_free_world.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_free_world} +\alias{librdf_free_world} +\title{Terminate the library and frees all allocated resources.} +\usage{ +librdf_free_world ( world ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +} +\value{ +void +} +\description{ +Terminate the library and frees all allocated resources. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_hash_to_string.Rd b/R/redland/man/librdf_hash_to_string.Rd new file mode 100644 index 000000000..05f480a80 --- /dev/null +++ b/R/redland/man/librdf_hash_to_string.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_hash_to_string} +\alias{librdf_hash_to_string} +\title{Format the hash as a string, suitable for parsing by librdf_hash_from_string.} +\usage{ +librdf_hash_to_string ( hash, + filter ) +} +\arguments{ + +\item{hash}{librdf_hash object ("_p_librdf_hash_s")} + +\item{filter}{NULL terminated list of keys to ignore ("_p_p_char")} + +} +\value{ +character +} +\description{ +Format the hash as a string, suitable for parsing by librdf_hash_from_string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_internal_test_error.Rd b/R/redland/man/librdf_internal_test_error.Rd new file mode 100644 index 000000000..a0e3e77dd --- /dev/null +++ b/R/redland/man/librdf_internal_test_error.Rd @@ -0,0 +1,24 @@ +\name{librdf_internal_test_error} +\alias{librdf_internal_test_error} +\title{For internal testing, not part of public API} +\usage{ +librdf_internal_test_error ( world ) +} +\arguments{ + +\item{world}{librdf_world object ("_p_librdf_world_s")} + +} +\value{ +void +} +\description{ +This funciton is for internal testing of the Redland software and is not part of the public API. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_internal_test_warning.Rd b/R/redland/man/librdf_internal_test_warning.Rd new file mode 100644 index 000000000..4b3e5d0e3 --- /dev/null +++ b/R/redland/man/librdf_internal_test_warning.Rd @@ -0,0 +1,24 @@ +\name{librdf_internal_test_warning} +\alias{librdf_internal_test_warning} +\title{For internal testing, not part of public API} +\usage{ +librdf_internal_test_warning ( world ) +} +\arguments{ + +\item{world}{librdf_world ("_p_librdf_world_s")} + +} +\value{ +void +} +\description{ +This funciton is for internal testing of the Redland software and is not part of the public API. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_iterator_end.Rd b/R/redland/man/librdf_iterator_end.Rd new file mode 100644 index 000000000..3a2113d02 --- /dev/null +++ b/R/redland/man/librdf_iterator_end.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_iterator_end} +\alias{librdf_iterator_end} +\title{Test if the iterator has finished.} +\usage{ +librdf_iterator_end ( iterator, + .copy ) +} +\arguments{ + +\item{iterator}{the librdf_iterator object ("_p_librdf_iterator_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Test if the iterator has finished. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_iterator_get_context.Rd b/R/redland/man/librdf_iterator_get_context.Rd new file mode 100644 index 000000000..5b20457c2 --- /dev/null +++ b/R/redland/man/librdf_iterator_get_context.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_iterator_get_context} +\alias{librdf_iterator_get_context} +\title{Get the context of the current object on the iterator.} +\usage{ +librdf_iterator_get_context ( iterator ) +} +\arguments{ + +\item{iterator}{the librdf_iterator object ("_p_librdf_iterator_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Get the context of the current object on the iterator. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_iterator_get_object.Rd b/R/redland/man/librdf_iterator_get_object.Rd new file mode 100644 index 000000000..e0dcc1bf4 --- /dev/null +++ b/R/redland/man/librdf_iterator_get_object.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_iterator_get_object} +\alias{librdf_iterator_get_object} +\title{Get the current object from the iterator.} +\usage{ +librdf_iterator_get_object ( iterator ) +} +\arguments{ + +\item{iterator}{the librdf_iterator object ("_p_librdf_iterator_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Get the current object from the iterator. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_iterator_next.Rd b/R/redland/man/librdf_iterator_next.Rd new file mode 100644 index 000000000..780f67802 --- /dev/null +++ b/R/redland/man/librdf_iterator_next.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_iterator_next} +\alias{librdf_iterator_next} +\title{Move to the next iterator element.} +\usage{ +librdf_iterator_next ( iterator, + .copy ) +} +\arguments{ + +\item{iterator}{the librdf_iterator object ("_p_librdf_iterator_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Move to the next iterator element. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_log_message_code.Rd b/R/redland/man/librdf_log_message_code.Rd new file mode 100644 index 000000000..558f76375 --- /dev/null +++ b/R/redland/man/librdf_log_message_code.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_log_message_code} +\alias{librdf_log_message_code} +\title{Retrieve error code from log message.} +\usage{ +librdf_log_message_code ( message, + .copy ) +} +\arguments{ + +\item{message}{log message ("_p_librdf_log_message")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Retrieve error code from log message. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_log_message_facility.Rd b/R/redland/man/librdf_log_message_facility.Rd new file mode 100644 index 000000000..12b772501 --- /dev/null +++ b/R/redland/man/librdf_log_message_facility.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_log_message_facility} +\alias{librdf_log_message_facility} +\title{Retrieve facility that generated the message.} +\usage{ +librdf_log_message_facility ( message, + .copy ) +} +\arguments{ + +\item{message}{log message ("_p_librdf_log_message")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Retrieve facility that generated the message. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_log_message_level.Rd b/R/redland/man/librdf_log_message_level.Rd new file mode 100644 index 000000000..01fd42ccf --- /dev/null +++ b/R/redland/man/librdf_log_message_level.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_log_message_level} +\alias{librdf_log_message_level} +\title{Retrieve severity of log message.} +\usage{ +librdf_log_message_level ( message, + .copy ) +} +\arguments{ + +\item{message}{log message ("_p_librdf_log_message")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Retrieve severity of log message. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_log_message_locator.Rd b/R/redland/man/librdf_log_message_locator.Rd new file mode 100644 index 000000000..72d229d13 --- /dev/null +++ b/R/redland/man/librdf_log_message_locator.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_log_message_locator} +\alias{librdf_log_message_locator} +\title{Retrieve locator of log entry.} +\usage{ +librdf_log_message_locator ( message ) +} +\arguments{ + +\item{message}{log message ("_p_librdf_log_message")} + +} +\value{ +_p_raptor_locator +} +\description{ +Retrieve locator of log entry. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_log_message_message.Rd b/R/redland/man/librdf_log_message_message.Rd new file mode 100644 index 000000000..1a93cb881 --- /dev/null +++ b/R/redland/man/librdf_log_message_message.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_log_message_message} +\alias{librdf_log_message_message} +\title{Retrieve text message from log entry.} +\usage{ +librdf_log_message_message ( message ) +} +\arguments{ + +\item{message}{log message ("_p_librdf_log_message")} + +} +\value{ +character +} +\description{ +Retrieve text message from log entry. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_add.Rd b/R/redland/man/librdf_model_add.Rd new file mode 100644 index 000000000..b6669f8d9 --- /dev/null +++ b/R/redland/man/librdf_model_add.Rd @@ -0,0 +1,37 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_add} +\alias{librdf_model_add} +\title{Create and add a new statement about a resource to the model.} +\usage{ +librdf_model_add ( model, + subject, + predicate, + object, + .copy ) +} +\arguments{ + +\item{model}{model object ("_p_librdf_model_s")} + +\item{subject}{librdf_node of subject ("_p_librdf_node_s")} + +\item{predicate}{librdf_node of predicate ("_p_librdf_node_s")} + +\item{object}{librdf_node of object (literal or resource) ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Create and add a new statement about a resource to the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_add_statement.Rd b/R/redland/man/librdf_model_add_statement.Rd new file mode 100644 index 000000000..c33601709 --- /dev/null +++ b/R/redland/man/librdf_model_add_statement.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_add_statement} +\alias{librdf_model_add_statement} +\title{Add a statement to the model.} +\usage{ +librdf_model_add_statement ( model, + statement, + .copy ) +} +\arguments{ + +\item{model}{model object ("_p_librdf_model_s")} + +\item{statement}{statement object ("_p_librdf_statement_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Add a statement to the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_add_statements.Rd b/R/redland/man/librdf_model_add_statements.Rd new file mode 100644 index 000000000..9e1359958 --- /dev/null +++ b/R/redland/man/librdf_model_add_statements.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_add_statements} +\alias{librdf_model_add_statements} +\title{Add a stream of statements to the model.} +\usage{ +librdf_model_add_statements ( model, + statement_stream, + .copy ) +} +\arguments{ + +\item{model}{model object ("_p_librdf_model_s")} + +\item{statement_stream}{stream of statements to use ("_p_librdf_stream_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Add a stream of statements to the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_add_string_literal_statement.Rd b/R/redland/man/librdf_model_add_string_literal_statement.Rd new file mode 100644 index 000000000..ae1b22068 --- /dev/null +++ b/R/redland/man/librdf_model_add_string_literal_statement.Rd @@ -0,0 +1,43 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_add_string_literal_statement} +\alias{librdf_model_add_string_literal_statement} +\title{Create and add a new statement about a literal to the model.} +\usage{ +librdf_model_add_string_literal_statement ( model, + subject, + predicate, + literal, + inStrOrNull, + is_wf_xml, + .copy ) +} +\arguments{ + +\item{model}{model object ("_p_librdf_model_s")} + +\item{subject}{librdf_node of subject ("_p_librdf_node_s")} + +\item{predicate}{librdf_node of predicate ("_p_librdf_node_s")} + +\item{literal}{string literal conten ("character")} + +\item{inStrOrNull}{language of literal ("character")} + +\item{is_wf_xml}{literal is XML ("integer")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Create and add a new statement about a literal to the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_add_typed_literal_statement.Rd b/R/redland/man/librdf_model_add_typed_literal_statement.Rd new file mode 100644 index 000000000..afa09c241 --- /dev/null +++ b/R/redland/man/librdf_model_add_typed_literal_statement.Rd @@ -0,0 +1,43 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_add_typed_literal_statement} +\alias{librdf_model_add_typed_literal_statement} +\title{Create and add a new statement about a typed literal to the model.} +\usage{ +librdf_model_add_typed_literal_statement ( model, + subject, + predicate, + string, + inStrOrNull, + inUriOrNull, + .copy ) +} +\arguments{ + +\item{model}{model object ("_p_librdf_model_s")} + +\item{subject}{librdf_node of subject ("_p_librdf_node_s")} + +\item{predicate}{librdf_node of predicate ("_p_librdf_node_s")} + +\item{string}{string literal content ("character")} + +\item{inStrOrNull}{language of literal ("character")} + +\item{inUriOrNull}{datatype librdf_uri ("_p_librdf_uri_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Create and add a new statement about a typed literal to the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_as_stream.Rd b/R/redland/man/librdf_model_as_stream.Rd new file mode 100644 index 000000000..806c72e1f --- /dev/null +++ b/R/redland/man/librdf_model_as_stream.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_as_stream} +\alias{librdf_model_as_stream} +\title{List the model contents as a stream of statements.} +\usage{ +librdf_model_as_stream ( model ) +} +\arguments{ + +\item{model}{the model object ("_p_librdf_model_s")} + +} +\value{ +_p_librdf_stream_s +} +\description{ +List the model contents as a stream of statements. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_contains_context.Rd b/R/redland/man/librdf_model_contains_context.Rd new file mode 100644 index 000000000..2e79166b1 --- /dev/null +++ b/R/redland/man/librdf_model_contains_context.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_contains_context} +\alias{librdf_model_contains_context} +\title{Check for a context in the model.} +\usage{ +librdf_model_contains_context ( model, + context, + .copy ) +} +\arguments{ + +\item{model}{the model object ("_p_librdf_model_s")} + +\item{context}{the contest ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Check for a context in the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_contains_statement.Rd b/R/redland/man/librdf_model_contains_statement.Rd new file mode 100644 index 000000000..0929fcfff --- /dev/null +++ b/R/redland/man/librdf_model_contains_statement.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_contains_statement} +\alias{librdf_model_contains_statement} +\title{Check for a statement in the model.} +\usage{ +librdf_model_contains_statement ( model, + statement, + .copy ) +} +\arguments{ + +\item{model}{the model object ("_p_librdf_model_s")} + +\item{statement}{the statement ("_p_librdf_statement_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Check for a statement in the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_context_add_statement.Rd b/R/redland/man/librdf_model_context_add_statement.Rd new file mode 100644 index 000000000..1293a28b9 --- /dev/null +++ b/R/redland/man/librdf_model_context_add_statement.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_context_add_statement} +\alias{librdf_model_context_add_statement} +\title{Add a statement to a model with a context.} +\usage{ +librdf_model_context_add_statement ( model, + context, + statement, + .copy ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{context}{librdf_node context ("_p_librdf_node_s")} + +\item{statement}{librdf_statement statement object ("_p_librdf_statement_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Add a statement to a model with a context. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_context_add_statements.Rd b/R/redland/man/librdf_model_context_add_statements.Rd new file mode 100644 index 000000000..ebe3c0da4 --- /dev/null +++ b/R/redland/man/librdf_model_context_add_statements.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_context_add_statements} +\alias{librdf_model_context_add_statements} +\title{Add statements to a model with a context.} +\usage{ +librdf_model_context_add_statements ( model, + context, + stream, + .copy ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{context}{librdf_node context ("_p_librdf_node_s")} + +\item{stream}{librdf_stream stream object ("_p_librdf_stream_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Add statements to a model with a context. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_context_as_stream.Rd b/R/redland/man/librdf_model_context_as_stream.Rd new file mode 100644 index 000000000..9bf769147 --- /dev/null +++ b/R/redland/man/librdf_model_context_as_stream.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_context_as_stream} +\alias{librdf_model_context_as_stream} +\title{List all statements in a model context.} +\usage{ +librdf_model_context_as_stream ( model, + context ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{context}{librdf_node context ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_stream_s +} +\description{ +List all statements in a model context. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_context_remove_statement.Rd b/R/redland/man/librdf_model_context_remove_statement.Rd new file mode 100644 index 000000000..1d8fe56f6 --- /dev/null +++ b/R/redland/man/librdf_model_context_remove_statement.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_context_remove_statement} +\alias{librdf_model_context_remove_statement} +\title{Remove a statement from a model in a context.} +\usage{ +librdf_model_context_remove_statement ( model, + context, + statement, + .copy ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{context}{librdf_node context ("_p_librdf_node_s")} + +\item{statement}{librdf_statement statement ("_p_librdf_statement_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Remove a statement from a model in a context. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_context_remove_statements.Rd b/R/redland/man/librdf_model_context_remove_statements.Rd new file mode 100644 index 000000000..d1ed6ef4b --- /dev/null +++ b/R/redland/man/librdf_model_context_remove_statements.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_context_remove_statements} +\alias{librdf_model_context_remove_statements} +\title{Remove statements from a model with the given context.} +\usage{ +librdf_model_context_remove_statements ( model, + context, + .copy ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{context}{librdf_node context ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Remove statements from a model with the given context. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_find_statements.Rd b/R/redland/man/librdf_model_find_statements.Rd new file mode 100644 index 000000000..b7d1ce930 --- /dev/null +++ b/R/redland/man/librdf_model_find_statements.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_find_statements} +\alias{librdf_model_find_statements} +\title{Find matching statements in the model.} +\usage{ +librdf_model_find_statements ( model, + statement ) +} +\arguments{ + +\item{model}{the model object ("_p_librdf_model_s")} + +\item{statement}{the partial statement to match ("_p_librdf_statement_s")} + +} +\value{ +_p_librdf_stream_s +} +\description{ +Find matching statements in the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_find_statements_in_context.Rd b/R/redland/man/librdf_model_find_statements_in_context.Rd new file mode 100644 index 000000000..74e3020ac --- /dev/null +++ b/R/redland/man/librdf_model_find_statements_in_context.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_find_statements_in_context} +\alias{librdf_model_find_statements_in_context} +\title{Search the model for matching statements in a given context.} +\usage{ +librdf_model_find_statements_in_context ( model, + statement, + inNodeOrNull ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{statement}{librdf_statement partial statement to find ("_p_librdf_statement_s")} + +\item{inNodeOrNull}{context librdf_node (or NULL) ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_stream_s +} +\description{ +Search the model for matching statements in a given context. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_get_arc.Rd b/R/redland/man/librdf_model_get_arc.Rd new file mode 100644 index 000000000..20e41200a --- /dev/null +++ b/R/redland/man/librdf_model_get_arc.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_get_arc} +\alias{librdf_model_get_arc} +\title{Return one arc (predicate) of an arc in an RDF graph given source (subject) and target (object).} +\usage{ +librdf_model_get_arc ( model, + source, + target ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{source}{librdf_node source ("_p_librdf_node_s")} + +\item{target}{librdf_node target ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Return one arc (predicate) of an arc in an RDF graph given source (subject) and target (object). +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_get_arcs.Rd b/R/redland/man/librdf_model_get_arcs.Rd new file mode 100644 index 000000000..946ace3fd --- /dev/null +++ b/R/redland/man/librdf_model_get_arcs.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_get_arcs} +\alias{librdf_model_get_arcs} +\title{Return the arcs (predicates) of an arc in an RDF graph given source (subject) and target (object).} +\usage{ +librdf_model_get_arcs ( model, + source, + target ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{source}{librdf_node source ("_p_librdf_node_s")} + +\item{target}{librdf_node target ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_iterator_s +} +\description{ +Return the arcs (predicates) of an arc in an RDF graph given source (subject) and target (object). +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_get_arcs_in.Rd b/R/redland/man/librdf_model_get_arcs_in.Rd new file mode 100644 index 000000000..3e4b7c5c9 --- /dev/null +++ b/R/redland/man/librdf_model_get_arcs_in.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_get_arcs_in} +\alias{librdf_model_get_arcs_in} +\title{Return the properties pointing to the given resource.} +\usage{ +librdf_model_get_arcs_in ( model, + node ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{node}{librdf_node resource node ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_iterator_s +} +\description{ +Return the properties pointing to the given resource. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_get_arcs_out.Rd b/R/redland/man/librdf_model_get_arcs_out.Rd new file mode 100644 index 000000000..84b23c8f2 --- /dev/null +++ b/R/redland/man/librdf_model_get_arcs_out.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_get_arcs_out} +\alias{librdf_model_get_arcs_out} +\title{Return the properties pointing from the given resource.} +\usage{ +librdf_model_get_arcs_out ( model, + node ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{node}{librdf_node resource node ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_iterator_s +} +\description{ +Return the properties pointing from the given resource. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_get_contexts.Rd b/R/redland/man/librdf_model_get_contexts.Rd new file mode 100644 index 000000000..a94b9a2ce --- /dev/null +++ b/R/redland/man/librdf_model_get_contexts.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_get_contexts} +\alias{librdf_model_get_contexts} +\title{Return the list of contexts in the graph.} +\usage{ +librdf_model_get_contexts ( model ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +} +\value{ +_p_librdf_iterator_s +} +\description{ +Return the list of contexts in the graph. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_get_feature.Rd b/R/redland/man/librdf_model_get_feature.Rd new file mode 100644 index 000000000..95a96b52c --- /dev/null +++ b/R/redland/man/librdf_model_get_feature.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_get_feature} +\alias{librdf_model_get_feature} +\title{Get the value of a graph feature .} +\usage{ +librdf_model_get_feature ( model, + feature ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{feature}{librdf_uri feature property ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Get the value of a graph feature . +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_get_source.Rd b/R/redland/man/librdf_model_get_source.Rd new file mode 100644 index 000000000..d3f389b9d --- /dev/null +++ b/R/redland/man/librdf_model_get_source.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_get_source} +\alias{librdf_model_get_source} +\title{Return one source (subject) of arc in an RDF graph given arc (predicate) and target (object).} +\usage{ +librdf_model_get_source ( model, + arc, + target ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{arc}{librdf_node arc ("_p_librdf_node_s")} + +\item{target}{librdf_node target ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Return one source (subject) of arc in an RDF graph given arc (predicate) and target (object). +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_get_sources.Rd b/R/redland/man/librdf_model_get_sources.Rd new file mode 100644 index 000000000..37bdac6c9 --- /dev/null +++ b/R/redland/man/librdf_model_get_sources.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_get_sources} +\alias{librdf_model_get_sources} +\title{Return the sources (subjects) of arc in an RDF graph given arc (predicate) and target (object).} +\usage{ +librdf_model_get_sources ( model, + arc, + target ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{arc}{librdf_node arc ("_p_librdf_node_s")} + +\item{target}{librdf_node target ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_iterator_s +} +\description{ +Return the sources (subjects) of arc in an RDF graph given arc (predicate) and target (object). +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_get_target.Rd b/R/redland/man/librdf_model_get_target.Rd new file mode 100644 index 000000000..5c2d372d0 --- /dev/null +++ b/R/redland/man/librdf_model_get_target.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_get_target} +\alias{librdf_model_get_target} +\title{Return one target (object) of an arc in an RDF graph given source (subject) and arc (predicate).} +\usage{ +librdf_model_get_target ( model, + source, + arc ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{source}{librdf_node source ("_p_librdf_node_s")} + +\item{arc}{librdf_node arc ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Return one target (object) of an arc in an RDF graph given source (subject) and arc (predicate). +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_get_targets.Rd b/R/redland/man/librdf_model_get_targets.Rd new file mode 100644 index 000000000..d3e76517e --- /dev/null +++ b/R/redland/man/librdf_model_get_targets.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_get_targets} +\alias{librdf_model_get_targets} +\title{Return the targets (objects) of an arc in an RDF graph given source (subject) and arc (predicate).} +\usage{ +librdf_model_get_targets ( model, + source, + arc ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{source}{librdf_node source ("_p_librdf_node_s")} + +\item{arc}{librdf_node arc ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_iterator_s +} +\description{ +Return the targets (objects) of an arc in an RDF graph given source (subject) and arc (predicate). +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_has_arc_in.Rd b/R/redland/man/librdf_model_has_arc_in.Rd new file mode 100644 index 000000000..1cbeefd0a --- /dev/null +++ b/R/redland/man/librdf_model_has_arc_in.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_has_arc_in} +\alias{librdf_model_has_arc_in} +\title{Check if a node has a given property pointing to it.} +\usage{ +librdf_model_has_arc_in ( model, + node, + property, + .copy ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{node}{librdf_node resource node ("_p_librdf_node_s")} + +\item{property}{librdf_node property node ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Check if a node has a given property pointing to it. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_has_arc_out.Rd b/R/redland/man/librdf_model_has_arc_out.Rd new file mode 100644 index 000000000..30a8c08f7 --- /dev/null +++ b/R/redland/man/librdf_model_has_arc_out.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_has_arc_out} +\alias{librdf_model_has_arc_out} +\title{Check if a node has a given property pointing from it.} +\usage{ +librdf_model_has_arc_out ( model, + node, + property, + .copy ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{node}{librdf_node resource node ("_p_librdf_node_s")} + +\item{property}{librdf_node property node ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Check if a node has a given property pointing from it. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_load.Rd b/R/redland/man/librdf_model_load.Rd new file mode 100644 index 000000000..ac094a0b7 --- /dev/null +++ b/R/redland/man/librdf_model_load.Rd @@ -0,0 +1,40 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_load} +\alias{librdf_model_load} +\title{Load content from a URI into the model.} +\usage{ +librdf_model_load ( model, + uri, + name, + mime_type, + type_uri, + .copy ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{uri}{the URI to read the content ("_p_librdf_uri_s")} + +\item{name}{the name of the parser (or NULL) ("character")} + +\item{mime_type}{the MIME type of the syntax (NULL if not used) ("character")} + +\item{type_uri}{URI identifying the syntax (NULL if not used) ("_p_librdf_uri_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Load content from a URI into the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_query_execute.Rd b/R/redland/man/librdf_model_query_execute.Rd new file mode 100644 index 000000000..9e95246af --- /dev/null +++ b/R/redland/man/librdf_model_query_execute.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_query_execute} +\alias{librdf_model_query_execute} +\title{Execute a query against the model.} +\usage{ +librdf_model_query_execute ( model, + query ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{query}{librdf_query object ("_p_librdf_query")} + +} +\value{ +_p_librdf_query_results +} +\description{ +Execute a query against the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_remove_statement.Rd b/R/redland/man/librdf_model_remove_statement.Rd new file mode 100644 index 000000000..41bc382b8 --- /dev/null +++ b/R/redland/man/librdf_model_remove_statement.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_remove_statement} +\alias{librdf_model_remove_statement} +\title{Remove a known statement from the model.} +\usage{ +librdf_model_remove_statement ( model, + statement, + .copy ) +} +\arguments{ + +\item{model}{the model object ("_p_librdf_model_s")} + +\item{statement}{the statement ("_p_librdf_statement_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Remove a known statement from the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_set_feature.Rd b/R/redland/man/librdf_model_set_feature.Rd new file mode 100644 index 000000000..6ef879805 --- /dev/null +++ b/R/redland/man/librdf_model_set_feature.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_set_feature} +\alias{librdf_model_set_feature} +\title{Set the value of a graph feature.} +\usage{ +librdf_model_set_feature ( model, + feature, + value, + .copy ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{feature}{librdf_uri feature property ("_p_librdf_uri_s")} + +\item{value}{librdf_node feature property value ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Set the value of a graph feature. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_size.Rd b/R/redland/man/librdf_model_size.Rd new file mode 100644 index 000000000..8d4fc0d40 --- /dev/null +++ b/R/redland/man/librdf_model_size.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_size} +\alias{librdf_model_size} +\title{Get the number of statements in the model.} +\usage{ +librdf_model_size ( model, + .copy ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Get the number of statements in the model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_sync.Rd b/R/redland/man/librdf_model_sync.Rd new file mode 100644 index 000000000..75985f7e0 --- /dev/null +++ b/R/redland/man/librdf_model_sync.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_sync} +\alias{librdf_model_sync} +\title{Synchronise the model to the model implementation.} +\usage{ +librdf_model_sync ( model ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +} +\value{ +void +} +\description{ +Synchronise the model to the model implementation. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_to_string.Rd b/R/redland/man/librdf_model_to_string.Rd new file mode 100644 index 000000000..df5b807d9 --- /dev/null +++ b/R/redland/man/librdf_model_to_string.Rd @@ -0,0 +1,37 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_to_string} +\alias{librdf_model_to_string} +\title{Write serialized model to a string.} +\usage{ +librdf_model_to_string ( model, + uri, + name, + mime_type, + inUriOrNull ) +} +\arguments{ + +\item{model}{librdf_model object ("_p_librdf_model_s")} + +\item{uri}{base URI to use in serializing (or NULL if not used) ("_p_librdf_uri_s")} + +\item{name}{the name of the serializer (or NULL for default) ("character")} + +\item{mime_type}{the MIME type of the syntax (NULL if not used) ("character")} + +\item{inUriOrNull}{URI identifying the syntax (NULL if not used) ("_p_librdf_uri_s")} + +} +\value{ +character +} +\description{ +Write serialized model to a string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_transaction_commit.Rd b/R/redland/man/librdf_model_transaction_commit.Rd new file mode 100644 index 000000000..cc2ae7f91 --- /dev/null +++ b/R/redland/man/librdf_model_transaction_commit.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_transaction_commit} +\alias{librdf_model_transaction_commit} +\title{Commit a transaction.} +\usage{ +librdf_model_transaction_commit ( model, + .copy ) +} +\arguments{ + +\item{model}{the model object ("_p_librdf_model_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Commit a transaction. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_transaction_rollback.Rd b/R/redland/man/librdf_model_transaction_rollback.Rd new file mode 100644 index 000000000..62e51ffb2 --- /dev/null +++ b/R/redland/man/librdf_model_transaction_rollback.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_transaction_rollback} +\alias{librdf_model_transaction_rollback} +\title{Rollback a transaction.} +\usage{ +librdf_model_transaction_rollback ( model, + .copy ) +} +\arguments{ + +\item{model}{the model object ("_p_librdf_model_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Rollback a transaction. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_model_transaction_start.Rd b/R/redland/man/librdf_model_transaction_start.Rd new file mode 100644 index 000000000..7d87d42c2 --- /dev/null +++ b/R/redland/man/librdf_model_transaction_start.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_model_transaction_start} +\alias{librdf_model_transaction_start} +\title{Start a transaction} +\usage{ +librdf_model_transaction_start ( model, + .copy ) +} +\arguments{ + +\item{model}{the model object ("_p_librdf_model_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Start a transaction +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_digest.Rd b/R/redland/man/librdf_new_digest.Rd new file mode 100644 index 000000000..f237c0ff8 --- /dev/null +++ b/R/redland/man/librdf_new_digest.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_digest} +\alias{librdf_new_digest} +\title{Constructor - create a new librdf_digest object.} +\usage{ +librdf_new_digest ( world, + name ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{name}{the digest name to use to create this digest ("character")} + +} +\value{ +_p_librdf_digest_s +} +\description{ +Constructor - create a new librdf_digest object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_hash.Rd b/R/redland/man/librdf_new_hash.Rd new file mode 100644 index 000000000..62b51f3b7 --- /dev/null +++ b/R/redland/man/librdf_new_hash.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_hash} +\alias{librdf_new_hash} +\title{Constructor - create a new librdf_hash object.} +\usage{ +librdf_new_hash ( world, + name ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{name}{factory name ("character")} + +} +\value{ +_p_librdf_hash_s +} +\description{ +Constructor - create a new librdf_hash object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_hash_from_array_of_strings.Rd b/R/redland/man/librdf_new_hash_from_array_of_strings.Rd new file mode 100644 index 000000000..3f2fc7992 --- /dev/null +++ b/R/redland/man/librdf_new_hash_from_array_of_strings.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_hash_from_array_of_strings} +\alias{librdf_new_hash_from_array_of_strings} +\title{Constructor - create a new librdf_hash object from an array of strings.} +\usage{ +librdf_new_hash_from_array_of_strings ( world, + name, + string ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{name}{hash name ("character")} + +\item{string}{address of the start of the array of char* pointers ("character")} + +} +\value{ +_p_librdf_hash_s +} +\description{ +Constructor - create a new librdf_hash object from an array of strings. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_hash_from_string.Rd b/R/redland/man/librdf_new_hash_from_string.Rd new file mode 100644 index 000000000..0ceb5d9ef --- /dev/null +++ b/R/redland/man/librdf_new_hash_from_string.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_hash_from_string} +\alias{librdf_new_hash_from_string} +\title{Constructor - create a new librdf_hash object from a string.} +\usage{ +librdf_new_hash_from_string ( world, + name, + string ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{name}{hash name ("character")} + +\item{string}{hash encoded as a string ("character")} + +} +\value{ +_p_librdf_hash_s +} +\description{ +Constructor - create a new librdf_hash object from a string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_model.Rd b/R/redland/man/librdf_new_model.Rd new file mode 100644 index 000000000..13831012c --- /dev/null +++ b/R/redland/man/librdf_new_model.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_model} +\alias{librdf_new_model} +\title{Constructor - create a new storage librdf_model object.} +\usage{ +librdf_new_model ( world, + storage, + options_string ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{storage}{librdf_storage to use ("_p_librdf_storage_s")} + +\item{options_string}{options to initialise model ("character")} + +} +\value{ +_p_librdf_model_s +} +\description{ +Constructor - create a new storage librdf_model object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_model_from_model.Rd b/R/redland/man/librdf_new_model_from_model.Rd new file mode 100644 index 000000000..77637bba6 --- /dev/null +++ b/R/redland/man/librdf_new_model_from_model.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_model_from_model} +\alias{librdf_new_model_from_model} +\title{Copy constructor - create a new librdf_model from an existing one.} +\usage{ +librdf_new_model_from_model ( model ) +} +\arguments{ + +\item{model}{the existing librdf_model ("_p_librdf_model_s")} + +} +\value{ +_p_librdf_model_s +} +\description{ +Copy constructor - create a new librdf_model from an existing one. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_model_with_options.Rd b/R/redland/man/librdf_new_model_with_options.Rd new file mode 100644 index 000000000..553a7d03b --- /dev/null +++ b/R/redland/man/librdf_new_model_with_options.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_model_with_options} +\alias{librdf_new_model_with_options} +\title{Constructor - Create a new librdf_model with storage.} +\usage{ +librdf_new_model_with_options ( world, + storage, + options ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{storage}{librdf_storage storage to use ("_p_librdf_storage_s")} + +\item{options}{librdf_hash of options to use ("_p_librdf_hash_s")} + +} +\value{ +_p_librdf_model_s +} +\description{ +Constructor - Create a new librdf_model with storage. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_node.Rd b/R/redland/man/librdf_new_node.Rd new file mode 100644 index 000000000..fa755a070 --- /dev/null +++ b/R/redland/man/librdf_new_node.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_node} +\alias{librdf_new_node} +\title{Constructor - create a new librdf_node object with a private identifier.} +\usage{ +librdf_new_node ( world ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Constructor - create a new librdf_node object with a private identifier. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_node_from_blank_identifier.Rd b/R/redland/man/librdf_new_node_from_blank_identifier.Rd new file mode 100644 index 000000000..98bb31cc8 --- /dev/null +++ b/R/redland/man/librdf_new_node_from_blank_identifier.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_node_from_blank_identifier} +\alias{librdf_new_node_from_blank_identifier} +\title{Constructor - create a new blank node librdf_node object from a blank node identifier.} +\usage{ +librdf_new_node_from_blank_identifier ( world, + inStrOrNull ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{inStrOrNull}{UTF-8 encoded blank node identifier or NULL ("character")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Constructor - create a new blank node librdf_node object from a blank node identifier. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_node_from_literal.Rd b/R/redland/man/librdf_new_node_from_literal.Rd new file mode 100644 index 000000000..259721670 --- /dev/null +++ b/R/redland/man/librdf_new_node_from_literal.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_node_from_literal} +\alias{librdf_new_node_from_literal} +\title{Constructor - create a new literal librdf_node object.} +\usage{ +librdf_new_node_from_literal ( world, + string, + inStrOrNull, + is_wf_xml ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{string}{literal UTF-8 encoded string value ("character")} + +\item{inStrOrNull}{literal XML language (or NULL, empty string) ("character")} + +\item{is_wf_xml}{non 0 if literal is XML ("integer")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Constructor - create a new literal librdf_node object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_node_from_node.Rd b/R/redland/man/librdf_new_node_from_node.Rd new file mode 100644 index 000000000..a546c5d5a --- /dev/null +++ b/R/redland/man/librdf_new_node_from_node.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_node_from_node} +\alias{librdf_new_node_from_node} +\title{Copy constructor - create a new librdf_node object from an existing librdf_node object.} +\usage{ +librdf_new_node_from_node ( node ) +} +\arguments{ + +\item{node}{librdf_node object to copy ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Copy constructor - create a new librdf_node object from an existing librdf_node object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_node_from_normalised_uri_string.Rd b/R/redland/man/librdf_new_node_from_normalised_uri_string.Rd new file mode 100644 index 000000000..66b1968ba --- /dev/null +++ b/R/redland/man/librdf_new_node_from_normalised_uri_string.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_node_from_normalised_uri_string} +\alias{librdf_new_node_from_normalised_uri_string} +\title{Constructor - create a new librdf_node object from a UTF-8 encoded URI string normalised to a new base URI.} +\usage{ +librdf_new_node_from_normalised_uri_string ( world, + uri_string, + source_uri, + base_uri ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{uri_string}{UTF-8 encoded string representing a URI ("character")} + +\item{source_uri}{source URI ("_p_librdf_uri_s")} + +\item{base_uri}{base URI ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Constructor - create a new librdf_node object from a UTF-8 encoded URI string normalised to a new base URI. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_node_from_typed_literal.Rd b/R/redland/man/librdf_new_node_from_typed_literal.Rd new file mode 100644 index 000000000..336c843c4 --- /dev/null +++ b/R/redland/man/librdf_new_node_from_typed_literal.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_node_from_typed_literal} +\alias{librdf_new_node_from_typed_literal} +\title{Constructor - create a new typed literal librdf_node object.} +\usage{ +librdf_new_node_from_typed_literal ( world, + string, + inStrOrNull, + inUriOrNull ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{string}{literal UTF-8 encoded string value ("character")} + +\item{inStrOrNull}{literal XML language (or NULL, empty string) ("character")} + +\item{inUriOrNull}{URI of typed literal datatype or NULL ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Constructor - create a new typed literal librdf_node object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_node_from_uri.Rd b/R/redland/man/librdf_new_node_from_uri.Rd new file mode 100644 index 000000000..d28752c4a --- /dev/null +++ b/R/redland/man/librdf_new_node_from_uri.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_node_from_uri} +\alias{librdf_new_node_from_uri} +\title{Constructor - create a new resource librdf_node object with a given URI.} +\usage{ +librdf_new_node_from_uri ( world, + uri ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{uri}{librdf_uri object ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Constructor - create a new resource librdf_node object with a given URI. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_node_from_uri_local_name.Rd b/R/redland/man/librdf_new_node_from_uri_local_name.Rd new file mode 100644 index 000000000..b57803eaa --- /dev/null +++ b/R/redland/man/librdf_new_node_from_uri_local_name.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_node_from_uri_local_name} +\alias{librdf_new_node_from_uri_local_name} +\title{Constructor - create a new resource librdf_node object with a given URI and local name.} +\usage{ +librdf_new_node_from_uri_local_name ( world, + uri, + local_name ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{uri}{librdf_uri object ("_p_librdf_uri_s")} + +\item{local_name}{local name to append to URI ("character")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Constructor - create a new resource librdf_node object with a given URI and local name. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_node_from_uri_string.Rd b/R/redland/man/librdf_new_node_from_uri_string.Rd new file mode 100644 index 000000000..70286b2ec --- /dev/null +++ b/R/redland/man/librdf_new_node_from_uri_string.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_node_from_uri_string} +\alias{librdf_new_node_from_uri_string} +\title{Constructor - create a new librdf_node object from a URI string.} +\usage{ +librdf_new_node_from_uri_string ( world, + string ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{string}{string representing a URI ("character")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Constructor - create a new librdf_node object from a URI string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_parser.Rd b/R/redland/man/librdf_new_parser.Rd new file mode 100644 index 000000000..5aae4f872 --- /dev/null +++ b/R/redland/man/librdf_new_parser.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_parser} +\alias{librdf_new_parser} +\title{Constructor - create a new librdf_parser object.} +\usage{ +librdf_new_parser ( world, + name, + mime_type, + type_uri ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{name}{the parser factory name (or NULL or empty string if don't care) ("character")} + +\item{mime_type}{the MIME type of the syntax (NULL if not used) ("character")} + +\item{type_uri}{URI of syntax (NULL if not used) ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_parser_s +} +\description{ +Constructor - create a new librdf_parser object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_query.Rd b/R/redland/man/librdf_new_query.Rd new file mode 100644 index 000000000..77d7bdfa6 --- /dev/null +++ b/R/redland/man/librdf_new_query.Rd @@ -0,0 +1,37 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_query} +\alias{librdf_new_query} +\title{Constructor - create a new librdf_query object.} +\usage{ +librdf_new_query ( world, + name, + uri, + query_string, + base_uri ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{name}{the name identifying the query language ("character")} + +\item{uri}{the URI identifying the query language (or NULL) ("_p_librdf_uri_s")} + +\item{query_string}{the query string ("character")} + +\item{base_uri}{the base URI of the query string (or NULL) ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_query +} +\description{ +Constructor - create a new librdf_query object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_query_from_query.Rd b/R/redland/man/librdf_new_query_from_query.Rd new file mode 100644 index 000000000..fe539fa87 --- /dev/null +++ b/R/redland/man/librdf_new_query_from_query.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_query_from_query} +\alias{librdf_new_query_from_query} +\title{Copy constructor - create a new librdf_query object from an existing one} +\usage{ +librdf_new_query_from_query ( old_query ) +} +\arguments{ + +\item{old_query}{the existing query librdf_query to use ("_p_librdf_query")} + +} +\value{ +_p_librdf_query +} +\description{ +Copy constructor - create a new librdf_query object from an existing one +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_serializer.Rd b/R/redland/man/librdf_new_serializer.Rd new file mode 100644 index 000000000..5d021d2bd --- /dev/null +++ b/R/redland/man/librdf_new_serializer.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_serializer} +\alias{librdf_new_serializer} +\title{Constructor - create a new librdf_serializer object.} +\usage{ +librdf_new_serializer ( world, + name, + mime_type, + type_uri ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{name}{the serializer factory name (or NULL or empty string if don't care) ("character")} + +\item{mime_type}{the MIME type of the syntax (NULL if not used) ("character")} + +\item{type_uri}{URI of syntax (NULL if not used) ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_serializer_s +} +\description{ +Constructor - create a new librdf_serializer object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_statement.Rd b/R/redland/man/librdf_new_statement.Rd new file mode 100644 index 000000000..4a6136afc --- /dev/null +++ b/R/redland/man/librdf_new_statement.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_statement} +\alias{librdf_new_statement} +\title{Constructor - create a new empty librdf_statement.} +\usage{ +librdf_new_statement ( world ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +} +\value{ +_p_librdf_statement_s +} +\description{ +Constructor - create a new empty librdf_statement. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_statement_from_nodes.Rd b/R/redland/man/librdf_new_statement_from_nodes.Rd new file mode 100644 index 000000000..482e0aec0 --- /dev/null +++ b/R/redland/man/librdf_new_statement_from_nodes.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_statement_from_nodes} +\alias{librdf_new_statement_from_nodes} +\title{Constructor - create a new librdf_statement from existing librdf_node objects.} +\usage{ +librdf_new_statement_from_nodes ( world, + subject, + predicate, + object ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{subject}{librdf_node ("_p_librdf_node_s")} + +\item{predicate}{librdf_node ("_p_librdf_node_s")} + +\item{object}{librdf_node ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_statement_s +} +\description{ +Constructor - create a new librdf_statement from existing librdf_node objects. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_statement_from_statement.Rd b/R/redland/man/librdf_new_statement_from_statement.Rd new file mode 100644 index 000000000..5ae78ece6 --- /dev/null +++ b/R/redland/man/librdf_new_statement_from_statement.Rd @@ -0,0 +1,27 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_statement_from_statement} +\alias{librdf_new_statement_from_statement} +\title{Copy constructor - create a new librdf_statement from an existing librdf_statement. +Creates a deep copy - changes to original statement nodes are not reflected in the copy.} +\usage{ +librdf_new_statement_from_statement ( statement ) +} +\arguments{ + +\item{statement}{librdf_statement to copy ("_p_librdf_statement_s")} + +} +\value{ +_p_librdf_statement_s +} +\description{ +Copy constructor - create a new librdf_statement from an existing librdf_statement. +Creates a deep copy - changes to original statement nodes are not reflected in the copy. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_storage.Rd b/R/redland/man/librdf_new_storage.Rd new file mode 100644 index 000000000..e1d7419af --- /dev/null +++ b/R/redland/man/librdf_new_storage.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_storage} +\alias{librdf_new_storage} +\title{Constructor - create a new librdf_storage object.} +\usage{ +librdf_new_storage ( world, + storage_name, + name, + options_string ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{storage_name}{the storage factory name ("character")} + +\item{name}{an identifier for the storage ("character")} + +\item{options_string}{options to initialise storage ("character")} + +} +\value{ +_p_librdf_storage_s +} +\description{ +Constructor - create a new librdf_storage object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_storage_from_storage.Rd b/R/redland/man/librdf_new_storage_from_storage.Rd new file mode 100644 index 000000000..7a2e04e1c --- /dev/null +++ b/R/redland/man/librdf_new_storage_from_storage.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_storage_from_storage} +\alias{librdf_new_storage_from_storage} +\title{Copy constructor - create a new librdf_storage object from an existing one} +\usage{ +librdf_new_storage_from_storage ( old_storage ) +} +\arguments{ + +\item{old_storage}{the existing storage librdf_storage to use ("_p_librdf_storage_s")} + +} +\value{ +_p_librdf_storage_s +} +\description{ +Copy constructor - create a new librdf_storage object from an existing one +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_uri.Rd b/R/redland/man/librdf_new_uri.Rd new file mode 100644 index 000000000..91c3350f3 --- /dev/null +++ b/R/redland/man/librdf_new_uri.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_uri} +\alias{librdf_new_uri} +\title{Constructor - create a new librdf_uri object from a URI string.} +\usage{ +librdf_new_uri ( world, + string ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{string}{URI in string form ("character")} + +} +\value{ +_p_librdf_uri_s +} +\description{ +Constructor - create a new librdf_uri object from a URI string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_uri_from_filename.Rd b/R/redland/man/librdf_new_uri_from_filename.Rd new file mode 100644 index 000000000..9b65f23c2 --- /dev/null +++ b/R/redland/man/librdf_new_uri_from_filename.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_uri_from_filename} +\alias{librdf_new_uri_from_filename} +\title{Constructor - create a new librdf_uri object from a filename.} +\usage{ +librdf_new_uri_from_filename ( world, + filename ) +} +\arguments{ + +\item{world}{Redland librdf_world object ("_p_librdf_world_s")} + +\item{filename}{filename ("character")} + +} +\value{ +_p_librdf_uri_s +} +\description{ +Constructor - create a new librdf_uri object from a filename. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_uri_from_uri.Rd b/R/redland/man/librdf_new_uri_from_uri.Rd new file mode 100644 index 000000000..5dfff169a --- /dev/null +++ b/R/redland/man/librdf_new_uri_from_uri.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_uri_from_uri} +\alias{librdf_new_uri_from_uri} +\title{Copy constructor - create a new librdf_uri object from an existing librdf_uri object.} +\usage{ +librdf_new_uri_from_uri ( uri ) +} +\arguments{ + +\item{uri}{librdf_uri object ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_uri_s +} +\description{ +Copy constructor - create a new librdf_uri object from an existing librdf_uri object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_new_world.Rd b/R/redland/man/librdf_new_world.Rd new file mode 100644 index 000000000..8d80243e3 --- /dev/null +++ b/R/redland/man/librdf_new_world.Rd @@ -0,0 +1,20 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_new_world} +\alias{librdf_new_world} +\title{Create a new Redland execution environment.} +\usage{ +librdf_new_world ( ) +} +\value{ +_p_librdf_world_s +} +\description{ +Create a new Redland execution environment. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_equals.Rd b/R/redland/man/librdf_node_equals.Rd new file mode 100644 index 000000000..b4ee01d8e --- /dev/null +++ b/R/redland/man/librdf_node_equals.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_equals} +\alias{librdf_node_equals} +\title{Compare two librdf_node objects for equality.} +\usage{ +librdf_node_equals ( first_node, + second_node, + .copy ) +} +\arguments{ + +\item{first_node}{first librdf_node node ("_p_librdf_node_s")} + +\item{second_node}{second librdf_node node ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Compare two librdf_node objects for equality. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_get_blank_identifier.Rd b/R/redland/man/librdf_node_get_blank_identifier.Rd new file mode 100644 index 000000000..70944f9b2 --- /dev/null +++ b/R/redland/man/librdf_node_get_blank_identifier.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_get_blank_identifier} +\alias{librdf_node_get_blank_identifier} +\title{Get the blank node identifier as a UTF-8 encoded string.} +\usage{ +librdf_node_get_blank_identifier ( node ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +} +\value{ +character +} +\description{ +Get the blank node identifier as a UTF-8 encoded string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_get_li_ordinal.Rd b/R/redland/man/librdf_node_get_li_ordinal.Rd new file mode 100644 index 000000000..c1da9f8f2 --- /dev/null +++ b/R/redland/man/librdf_node_get_li_ordinal.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_get_li_ordinal} +\alias{librdf_node_get_li_ordinal} +\title{Get the node li object ordinal value.} +\usage{ +librdf_node_get_li_ordinal ( node, + .copy ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Get the node li object ordinal value. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_get_literal_value.Rd b/R/redland/man/librdf_node_get_literal_value.Rd new file mode 100644 index 000000000..13715074a --- /dev/null +++ b/R/redland/man/librdf_node_get_literal_value.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_get_literal_value} +\alias{librdf_node_get_literal_value} +\title{Get the literal value of the node as a UTF-8 encoded string.} +\usage{ +librdf_node_get_literal_value ( node ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +} +\value{ +character +} +\description{ +Get the literal value of the node as a UTF-8 encoded string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_get_literal_value_as_latin1.Rd b/R/redland/man/librdf_node_get_literal_value_as_latin1.Rd new file mode 100644 index 000000000..dcd669ea7 --- /dev/null +++ b/R/redland/man/librdf_node_get_literal_value_as_latin1.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_get_literal_value_as_latin1} +\alias{librdf_node_get_literal_value_as_latin1} +\title{Get the string literal value of the node as ISO Latin-1.} +\usage{ +librdf_node_get_literal_value_as_latin1 ( node ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +} +\value{ +character +} +\description{ +Get the string literal value of the node as ISO Latin-1. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_get_literal_value_datatype_uri.Rd b/R/redland/man/librdf_node_get_literal_value_datatype_uri.Rd new file mode 100644 index 000000000..86946983c --- /dev/null +++ b/R/redland/man/librdf_node_get_literal_value_datatype_uri.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_get_literal_value_datatype_uri} +\alias{librdf_node_get_literal_value_datatype_uri} +\title{Get the typed literal datatype URI of the literal node.} +\usage{ +librdf_node_get_literal_value_datatype_uri ( node ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_uri_s +} +\description{ +Get the typed literal datatype URI of the literal node. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_get_literal_value_is_wf_xml.Rd b/R/redland/man/librdf_node_get_literal_value_is_wf_xml.Rd new file mode 100644 index 000000000..edc901af7 --- /dev/null +++ b/R/redland/man/librdf_node_get_literal_value_is_wf_xml.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_get_literal_value_is_wf_xml} +\alias{librdf_node_get_literal_value_is_wf_xml} +\title{Get the XML well-formness property of the node.} +\usage{ +librdf_node_get_literal_value_is_wf_xml ( node, + .copy ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Get the XML well-formness property of the node. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_get_literal_value_language.Rd b/R/redland/man/librdf_node_get_literal_value_language.Rd new file mode 100644 index 000000000..061a5111d --- /dev/null +++ b/R/redland/man/librdf_node_get_literal_value_language.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_get_literal_value_language} +\alias{librdf_node_get_literal_value_language} +\title{Get the XML language of the node.} +\usage{ +librdf_node_get_literal_value_language ( node ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +} +\value{ +character +} +\description{ +Get the XML language of the node. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_get_type.Rd b/R/redland/man/librdf_node_get_type.Rd new file mode 100644 index 000000000..acbf17afd --- /dev/null +++ b/R/redland/man/librdf_node_get_type.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_get_type} +\alias{librdf_node_get_type} +\title{Get the type of the node.} +\usage{ +librdf_node_get_type ( node, + .copy ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Get the type of the node. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_get_uri.Rd b/R/redland/man/librdf_node_get_uri.Rd new file mode 100644 index 000000000..a0757731e --- /dev/null +++ b/R/redland/man/librdf_node_get_uri.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_get_uri} +\alias{librdf_node_get_uri} +\title{Get the URI for a node object.} +\usage{ +librdf_node_get_uri ( node ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +} +\value{ +_p_librdf_uri_s +} +\description{ +Get the URI for a node object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_is_blank.Rd b/R/redland/man/librdf_node_is_blank.Rd new file mode 100644 index 000000000..d97ed1ab6 --- /dev/null +++ b/R/redland/man/librdf_node_is_blank.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_is_blank} +\alias{librdf_node_is_blank} +\title{Check node is a blank nodeID.} +\usage{ +librdf_node_is_blank ( node, + .copy ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Check node is a blank nodeID. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_is_literal.Rd b/R/redland/man/librdf_node_is_literal.Rd new file mode 100644 index 000000000..7c95f42cb --- /dev/null +++ b/R/redland/man/librdf_node_is_literal.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_is_literal} +\alias{librdf_node_is_literal} +\title{Check node is a literal.} +\usage{ +librdf_node_is_literal ( node, + .copy ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Check node is a literal. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_node_is_resource.Rd b/R/redland/man/librdf_node_is_resource.Rd new file mode 100644 index 000000000..162797e8f --- /dev/null +++ b/R/redland/man/librdf_node_is_resource.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_node_is_resource} +\alias{librdf_node_is_resource} +\title{Check node is a resource.} +\usage{ +librdf_node_is_resource ( node, + .copy ) +} +\arguments{ + +\item{node}{the node object ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Check node is a resource. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_check_name.Rd b/R/redland/man/librdf_parser_check_name.Rd new file mode 100644 index 000000000..27e742b7e --- /dev/null +++ b/R/redland/man/librdf_parser_check_name.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_check_name} +\alias{librdf_parser_check_name} +\title{Check if a parser name is known} +\usage{ +librdf_parser_check_name ( world, + name, + .copy ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{name}{name of parser ("character")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Check if a parser name is known +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_get_accept_header.Rd b/R/redland/man/librdf_parser_get_accept_header.Rd new file mode 100644 index 000000000..91730d73c --- /dev/null +++ b/R/redland/man/librdf_parser_get_accept_header.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_get_accept_header} +\alias{librdf_parser_get_accept_header} +\title{Get an HTTP Accept value for the parser.} +\usage{ +librdf_parser_get_accept_header ( parser ) +} +\arguments{ + +\item{parser}{parser ("_p_librdf_parser_s")} + +} +\value{ +character +} +\description{ +Get an HTTP Accept value for the parser. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_get_feature.Rd b/R/redland/man/librdf_parser_get_feature.Rd new file mode 100644 index 000000000..46cc0c0bb --- /dev/null +++ b/R/redland/man/librdf_parser_get_feature.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_get_feature} +\alias{librdf_parser_get_feature} +\title{Get the value of a parser feature.} +\usage{ +librdf_parser_get_feature ( parser, + feature ) +} +\arguments{ + +\item{parser}{librdf_parser object ("_p_librdf_parser_s")} + +\item{feature}{librdf_Uuri feature property ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Get the value of a parser feature. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_get_namespaces_seen_count.Rd b/R/redland/man/librdf_parser_get_namespaces_seen_count.Rd new file mode 100644 index 000000000..a0d0023c0 --- /dev/null +++ b/R/redland/man/librdf_parser_get_namespaces_seen_count.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_get_namespaces_seen_count} +\alias{librdf_parser_get_namespaces_seen_count} +\title{Get the number of namespaces seen during parsing} +\usage{ +librdf_parser_get_namespaces_seen_count ( parser, + .copy ) +} +\arguments{ + +\item{parser}{librdf_parser object ("_p_librdf_parser_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Get the number of namespaces seen during parsing +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_get_namespaces_seen_prefix.Rd b/R/redland/man/librdf_parser_get_namespaces_seen_prefix.Rd new file mode 100644 index 000000000..506095b98 --- /dev/null +++ b/R/redland/man/librdf_parser_get_namespaces_seen_prefix.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_get_namespaces_seen_prefix} +\alias{librdf_parser_get_namespaces_seen_prefix} +\title{Get the prefix of namespaces seen during parsing} +\usage{ +librdf_parser_get_namespaces_seen_prefix ( parser, + offset ) +} +\arguments{ + +\item{parser}{librdf_parser object ("_p_librdf_parser_s")} + +\item{offset}{index into list of namespaces ("integer")} + +} +\value{ +character +} +\description{ +Get the prefix of namespaces seen during parsing +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_get_namespaces_seen_uri.Rd b/R/redland/man/librdf_parser_get_namespaces_seen_uri.Rd new file mode 100644 index 000000000..947bdde42 --- /dev/null +++ b/R/redland/man/librdf_parser_get_namespaces_seen_uri.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_get_namespaces_seen_uri} +\alias{librdf_parser_get_namespaces_seen_uri} +\title{Get the uri of namespaces seen during parsing} +\usage{ +librdf_parser_get_namespaces_seen_uri ( parser, + offset ) +} +\arguments{ + +\item{parser}{librdf_parser object ("_p_librdf_parser_s")} + +\item{offset}{index into list of namespaces ("integer")} + +} +\value{ +_p_librdf_uri_s +} +\description{ +Get the uri of namespaces seen during parsing +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_guess_name2.Rd b/R/redland/man/librdf_parser_guess_name2.Rd new file mode 100644 index 000000000..e525450e6 --- /dev/null +++ b/R/redland/man/librdf_parser_guess_name2.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_guess_name2} +\alias{librdf_parser_guess_name2} +\title{Get a parser name for content with type or identifier} +\usage{ +librdf_parser_guess_name2 ( world, + mime_type, + buffer, + identifier ) +} +\arguments{ + +\item{world}{librdf_world object ("_p_librdf_world_s")} + +\item{mime_type}{MIME type of syntax or NULL ("character")} + +\item{buffer}{content buffer or NULL ("character")} + +\item{identifier}{content identifier or NULL ("character")} + +} +\value{ +character +} +\description{ +Get a parser name for content with type or identifier +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_parse_as_stream.Rd b/R/redland/man/librdf_parser_parse_as_stream.Rd new file mode 100644 index 000000000..d3d8f3603 --- /dev/null +++ b/R/redland/man/librdf_parser_parse_as_stream.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_parse_as_stream} +\alias{librdf_parser_parse_as_stream} +\title{Parse a URI to a librdf_stream of statements.} +\usage{ +librdf_parser_parse_as_stream ( parser, + uri, + inUriorNull ) +} +\arguments{ + +\item{parser}{the parser ("_p_librdf_parser_s")} + +\item{uri}{the URI to read ("_p_librdf_uri_s")} + +\item{inUriorNull}{the base URI to use or NULL ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_stream_s +} +\description{ +Parse a URI to a librdf_stream of statements. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_parse_counted_string_as_stream.Rd b/R/redland/man/librdf_parser_parse_counted_string_as_stream.Rd new file mode 100644 index 000000000..23c5fde78 --- /dev/null +++ b/R/redland/man/librdf_parser_parse_counted_string_as_stream.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_parse_counted_string_as_stream} +\alias{librdf_parser_parse_counted_string_as_stream} +\title{Parse a counted string of content to a librdf_stream of statements.} +\usage{ +librdf_parser_parse_counted_string_as_stream ( parser, + string, + length, + base_uri ) +} +\arguments{ + +\item{parser}{the parser ("_p_librdf_parser_s")} + +\item{string}{the string to parse ("character")} + +\item{length}{length of the string content (must be >0) ("integer")} + +\item{base_uri}{the base URI to use or NULL ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_stream_s +} +\description{ +Parse a counted string of content to a librdf_stream of statements. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_parse_counted_string_into_model.Rd b/R/redland/man/librdf_parser_parse_counted_string_into_model.Rd new file mode 100644 index 000000000..3826ef0e3 --- /dev/null +++ b/R/redland/man/librdf_parser_parse_counted_string_into_model.Rd @@ -0,0 +1,40 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_parse_counted_string_into_model} +\alias{librdf_parser_parse_counted_string_into_model} +\title{Parse a counted string of content into an librdf_model.} +\usage{ +librdf_parser_parse_counted_string_into_model ( parser, + string, + length, + base_uri, + model, + .copy ) +} +\arguments{ + +\item{parser}{the parser ("_p_librdf_parser_s")} + +\item{string}{the content to parse ("character")} + +\item{length}{length of content (must be >0) ("integer")} + +\item{base_uri}{the base URI to use or NULL ("_p_librdf_uri_s")} + +\item{model}{the model to use ("_p_librdf_model_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Parse a counted string of content into an librdf_model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_parse_into_model.Rd b/R/redland/man/librdf_parser_parse_into_model.Rd new file mode 100644 index 000000000..5d63e71d4 --- /dev/null +++ b/R/redland/man/librdf_parser_parse_into_model.Rd @@ -0,0 +1,37 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_parse_into_model} +\alias{librdf_parser_parse_into_model} +\title{Parse a URI of content into an librdf_model.} +\usage{ +librdf_parser_parse_into_model ( parser, + uri, + inUriOrNull, + model, + .copy ) +} +\arguments{ + +\item{parser}{the parser ("_p_librdf_parser_s")} + +\item{uri}{the URI to read the content ("_p_librdf_uri_s")} + +\item{inUriOrNull}{the base URI to use or NULL ("_p_librdf_uri_s")} + +\item{model}{the model to use ("_p_librdf_model_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Parse a URI of content into an librdf_model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_parse_string_as_stream.Rd b/R/redland/man/librdf_parser_parse_string_as_stream.Rd new file mode 100644 index 000000000..700778b26 --- /dev/null +++ b/R/redland/man/librdf_parser_parse_string_as_stream.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_parse_string_as_stream} +\alias{librdf_parser_parse_string_as_stream} +\title{Parse a string of content to a librdf_stream of statements.} +\usage{ +librdf_parser_parse_string_as_stream ( parser, + string, + base_uri ) +} +\arguments{ + +\item{parser}{the parser ("_p_librdf_parser_s")} + +\item{string}{the string to parse ("character")} + +\item{base_uri}{the base URI to use or NULL ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_stream_s +} +\description{ +Parse a string of content to a librdf_stream of statements. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_parse_string_into_model.Rd b/R/redland/man/librdf_parser_parse_string_into_model.Rd new file mode 100644 index 000000000..33012cc1e --- /dev/null +++ b/R/redland/man/librdf_parser_parse_string_into_model.Rd @@ -0,0 +1,37 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_parse_string_into_model} +\alias{librdf_parser_parse_string_into_model} +\title{Parse a string of content into an librdf_model.} +\usage{ +librdf_parser_parse_string_into_model ( parser, + string, + base_uri, + model, + .copy ) +} +\arguments{ + +\item{parser}{the parser ("_p_librdf_parser_s")} + +\item{string}{the content to parse ("character")} + +\item{base_uri}{the base URI to use or NULL ("_p_librdf_uri_s")} + +\item{model}{the model to use ("_p_librdf_model_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Parse a string of content into an librdf_model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_parser_set_feature.Rd b/R/redland/man/librdf_parser_set_feature.Rd new file mode 100644 index 000000000..ab410ee6b --- /dev/null +++ b/R/redland/man/librdf_parser_set_feature.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_parser_set_feature} +\alias{librdf_parser_set_feature} +\title{Set the value of a parser feature.} +\usage{ +librdf_parser_set_feature ( parser, + feature, + value, + .copy ) +} +\arguments{ + +\item{parser}{librdf_parser object ("_p_librdf_parser_s")} + +\item{feature}{librdf_uri feature property ("_p_librdf_uri_s")} + +\item{value}{librdf_node feature property value ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Set the value of a parser feature. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_execute.Rd b/R/redland/man/librdf_query_execute.Rd new file mode 100644 index 000000000..a3d61a20e --- /dev/null +++ b/R/redland/man/librdf_query_execute.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_execute} +\alias{librdf_query_execute} +\title{Run the query on a model.} +\usage{ +librdf_query_execute ( query, + model ) +} +\arguments{ + +\item{query}{librdf_query object ("_p_librdf_query")} + +\item{model}{model to operate query on ("_p_librdf_model_s")} + +} +\value{ +_p_librdf_query_results +} +\description{ +Run the query on a model. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_get_limit.Rd b/R/redland/man/librdf_query_get_limit.Rd new file mode 100644 index 000000000..c5cf5499c --- /dev/null +++ b/R/redland/man/librdf_query_get_limit.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_get_limit} +\alias{librdf_query_get_limit} +\title{Get the query-specified limit on results.} +\usage{ +librdf_query_get_limit ( query, + .copy ) +} +\arguments{ + +\item{query}{librdf_query query object ("_p_librdf_query")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Get the query-specified limit on results. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_get_offset.Rd b/R/redland/man/librdf_query_get_offset.Rd new file mode 100644 index 000000000..152a09d9f --- /dev/null +++ b/R/redland/man/librdf_query_get_offset.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_get_offset} +\alias{librdf_query_get_offset} +\title{Get the query-specified offset on results.} +\usage{ +librdf_query_get_offset ( query, + .copy ) +} +\arguments{ + +\item{query}{librdf_query query object ("_p_librdf_query")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Get the query-specified offset on results. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_as_stream.Rd b/R/redland/man/librdf_query_results_as_stream.Rd new file mode 100644 index 000000000..aa2c5918d --- /dev/null +++ b/R/redland/man/librdf_query_results_as_stream.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_as_stream} +\alias{librdf_query_results_as_stream} +\title{Get a query result as an RDF graph in librdf_stream form} +\usage{ +librdf_query_results_as_stream ( query_results ) +} +\arguments{ + +\item{query_results}{librdf_query_results query_results ("_p_librdf_query_results")} + +} +\value{ +_p_librdf_stream_s +} +\description{ +Get a query result as an RDF graph in librdf_stream form +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_finished.Rd b/R/redland/man/librdf_query_results_finished.Rd new file mode 100644 index 000000000..dd4aba213 --- /dev/null +++ b/R/redland/man/librdf_query_results_finished.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_finished} +\alias{librdf_query_results_finished} +\title{Find out if binding results are exhausted.} +\usage{ +librdf_query_results_finished ( query_results, + .copy ) +} +\arguments{ + +\item{query_results}{librdf_query_results query results ("_p_librdf_query_results")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Find out if binding results are exhausted. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_get_binding_name.Rd b/R/redland/man/librdf_query_results_get_binding_name.Rd new file mode 100644 index 000000000..96140a17b --- /dev/null +++ b/R/redland/man/librdf_query_results_get_binding_name.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_get_binding_name} +\alias{librdf_query_results_get_binding_name} +\title{Get binding name for the current result.} +\usage{ +librdf_query_results_get_binding_name ( query_results, + offset ) +} +\arguments{ + +\item{query_results}{librdf_query_results query results ("_p_librdf_query_results")} + +\item{offset}{offset of binding name into array of known names ("integer")} + +} +\value{ +character +} +\description{ +Get binding name for the current result. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_get_binding_value.Rd b/R/redland/man/librdf_query_results_get_binding_value.Rd new file mode 100644 index 000000000..e7073cda1 --- /dev/null +++ b/R/redland/man/librdf_query_results_get_binding_value.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_get_binding_value} +\alias{librdf_query_results_get_binding_value} +\title{Get one binding value for the current result.} +\usage{ +librdf_query_results_get_binding_value ( query_results, + offset ) +} +\arguments{ + +\item{query_results}{librdf_query_results query results ("_p_librdf_query_results")} + +\item{offset}{offset of binding name into array of known names ("integer")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Get one binding value for the current result. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_get_binding_value_by_name.Rd b/R/redland/man/librdf_query_results_get_binding_value_by_name.Rd new file mode 100644 index 000000000..b627975b7 --- /dev/null +++ b/R/redland/man/librdf_query_results_get_binding_value_by_name.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_get_binding_value_by_name} +\alias{librdf_query_results_get_binding_value_by_name} +\title{Get one binding value for a given name in the current result.} +\usage{ +librdf_query_results_get_binding_value_by_name ( query_results, + name ) +} +\arguments{ + +\item{query_results}{librdf_query_results query results ("_p_librdf_query_results")} + +\item{name}{variable name ("character")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Get one binding value for a given name in the current result. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_get_bindings_count.Rd b/R/redland/man/librdf_query_results_get_bindings_count.Rd new file mode 100644 index 000000000..dbbe521db --- /dev/null +++ b/R/redland/man/librdf_query_results_get_bindings_count.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_get_bindings_count} +\alias{librdf_query_results_get_bindings_count} +\title{Get the number of bound variables in the result.} +\usage{ +librdf_query_results_get_bindings_count ( query_results, + .copy ) +} +\arguments{ + +\item{query_results}{librdf_query_results query results ("_p_librdf_query_results")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Get the number of bound variables in the result. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_get_boolean.Rd b/R/redland/man/librdf_query_results_get_boolean.Rd new file mode 100644 index 000000000..fb648178c --- /dev/null +++ b/R/redland/man/librdf_query_results_get_boolean.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_get_boolean} +\alias{librdf_query_results_get_boolean} +\title{Get boolean query result.} +\usage{ +librdf_query_results_get_boolean ( query_results, + .copy ) +} +\arguments{ + +\item{query_results}{librdf_query_results query_results ("_p_librdf_query_results")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Get boolean query result. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_get_count.Rd b/R/redland/man/librdf_query_results_get_count.Rd new file mode 100644 index 000000000..3d23425d8 --- /dev/null +++ b/R/redland/man/librdf_query_results_get_count.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_get_count} +\alias{librdf_query_results_get_count} +\title{Get number of bindings so far.} +\usage{ +librdf_query_results_get_count ( query_results, + .copy ) +} +\arguments{ + +\item{query_results}{librdf_query_results query results ("_p_librdf_query_results")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Get number of bindings so far. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_is_bindings.Rd b/R/redland/man/librdf_query_results_is_bindings.Rd new file mode 100644 index 000000000..635d37635 --- /dev/null +++ b/R/redland/man/librdf_query_results_is_bindings.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_is_bindings} +\alias{librdf_query_results_is_bindings} +\title{Test if librdf_query_results is variable bindings format.} +\usage{ +librdf_query_results_is_bindings ( query_results, + .copy ) +} +\arguments{ + +\item{query_results}{librdf_query_results object ("_p_librdf_query_results")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Test if librdf_query_results is variable bindings format. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_is_boolean.Rd b/R/redland/man/librdf_query_results_is_boolean.Rd new file mode 100644 index 000000000..6297ef7d0 --- /dev/null +++ b/R/redland/man/librdf_query_results_is_boolean.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_is_boolean} +\alias{librdf_query_results_is_boolean} +\title{Test if librdf_query_results is boolean format.} +\usage{ +librdf_query_results_is_boolean ( query_results, + .copy ) +} +\arguments{ + +\item{query_results}{librdf_query_results object ("_p_librdf_query_results")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Test if librdf_query_results is boolean format. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_is_graph.Rd b/R/redland/man/librdf_query_results_is_graph.Rd new file mode 100644 index 000000000..3d0585c78 --- /dev/null +++ b/R/redland/man/librdf_query_results_is_graph.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_is_graph} +\alias{librdf_query_results_is_graph} +\title{Test if librdf_query_results is RDF graph format.} +\usage{ +librdf_query_results_is_graph ( query_results, + .copy ) +} +\arguments{ + +\item{query_results}{librdf_query_results object ("_p_librdf_query_results")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Test if librdf_query_results is RDF graph format. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_is_syntax.Rd b/R/redland/man/librdf_query_results_is_syntax.Rd new file mode 100644 index 000000000..53e8297f2 --- /dev/null +++ b/R/redland/man/librdf_query_results_is_syntax.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_is_syntax} +\alias{librdf_query_results_is_syntax} +\title{Test if librdf_query_results is a syntax.} +\usage{ +librdf_query_results_is_syntax ( query_results, + .copy ) +} +\arguments{ + +\item{query_results}{librdf_query_results object ("_p_librdf_query_results")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Test if librdf_query_results is a syntax. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_next.Rd b/R/redland/man/librdf_query_results_next.Rd new file mode 100644 index 000000000..1e526f8ae --- /dev/null +++ b/R/redland/man/librdf_query_results_next.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_next} +\alias{librdf_query_results_next} +\title{Move to the next result.} +\usage{ +librdf_query_results_next ( query_results, + .copy ) +} +\arguments{ + +\item{query_results}{librdf_query_results query results ("_p_librdf_query_results")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Move to the next result. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_to_file2.Rd b/R/redland/man/librdf_query_results_to_file2.Rd new file mode 100644 index 000000000..573a7fb0a --- /dev/null +++ b/R/redland/man/librdf_query_results_to_file2.Rd @@ -0,0 +1,40 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_to_file2} +\alias{librdf_query_results_to_file2} +\title{Write a query results to a file.} +\usage{ +librdf_query_results_to_file2 ( query_results, + name, + mime_type, + format_uri, + base_uri, + .copy ) +} +\arguments{ + +\item{query_results}{librdf_query_results object ("_p_librdf_query_results")} + +\item{name}{filename to write to ("character")} + +\item{mime_type}{mime type (or NULL) ("character")} + +\item{format_uri}{URI of syntax to format to (or NULL) ("_p_librdf_uri_s")} + +\item{base_uri}{Base URI of output formatted syntax (or NULL) ("_p_librdf_uri_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Write a query results to a file. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_results_to_string2.Rd b/R/redland/man/librdf_query_results_to_string2.Rd new file mode 100644 index 000000000..55ae95b3e --- /dev/null +++ b/R/redland/man/librdf_query_results_to_string2.Rd @@ -0,0 +1,37 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_results_to_string2} +\alias{librdf_query_results_to_string2} +\title{Turn a query results into a string.} +\usage{ +librdf_query_results_to_string2 ( query_results, + name, + mime_type, + format_uri, + base_uri ) +} +\arguments{ + +\item{query_results}{librdf_query_results object ("_p_librdf_query_results")} + +\item{name}{format name ("character")} + +\item{mime_type}{format mime type (or NULL) ("character")} + +\item{format_uri}{URI of syntax to format to (or NULL) ("_p_librdf_uri_s")} + +\item{base_uri}{Base URI of output formatted syntax (or NULL) ("_p_librdf_uri_s")} + +} +\value{ +character +} +\description{ +Turn a query results into a string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_set_limit.Rd b/R/redland/man/librdf_query_set_limit.Rd new file mode 100644 index 000000000..9734468b0 --- /dev/null +++ b/R/redland/man/librdf_query_set_limit.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_set_limit} +\alias{librdf_query_set_limit} +\title{Set the query-specified limit on results.} +\usage{ +librdf_query_set_limit ( query, + limit, + .copy ) +} +\arguments{ + +\item{query}{librdf_query query object ("_p_librdf_query")} + +\item{limit}{the limit on results, >=0 to set a limit, <0 to have no limit ("integer")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Set the query-specified limit on results. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_query_set_offset.Rd b/R/redland/man/librdf_query_set_offset.Rd new file mode 100644 index 000000000..7e3ade7a6 --- /dev/null +++ b/R/redland/man/librdf_query_set_offset.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_query_set_offset} +\alias{librdf_query_set_offset} +\title{Set the query-specified offset on results.} +\usage{ +librdf_query_set_offset ( query, + offset, + .copy ) +} +\arguments{ + +\item{query}{librdf_query query object ("_p_librdf_query")} + +\item{offset}{offset for results, >=0 to set an offset, <0 to have no offset ("integer")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Set the query-specified offset on results. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_serializer_check_name.Rd b/R/redland/man/librdf_serializer_check_name.Rd new file mode 100644 index 000000000..dbbf8d9db --- /dev/null +++ b/R/redland/man/librdf_serializer_check_name.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_serializer_check_name} +\alias{librdf_serializer_check_name} +\title{Check if a serializer name is known} +\usage{ +librdf_serializer_check_name ( world, + name, + .copy ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{name}{name of serializer ("character")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Check if a serializer name is known +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_serializer_get_feature.Rd b/R/redland/man/librdf_serializer_get_feature.Rd new file mode 100644 index 000000000..7d29fd7d9 --- /dev/null +++ b/R/redland/man/librdf_serializer_get_feature.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_serializer_get_feature} +\alias{librdf_serializer_get_feature} +\title{Get the value of a serializer feature.} +\usage{ +librdf_serializer_get_feature ( serializer, + feature ) +} +\arguments{ + +\item{serializer}{serializer object ("_p_librdf_serializer_s")} + +\item{feature}{URI of feature ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Get the value of a serializer feature. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_serializer_serialize_model_to_file.Rd b/R/redland/man/librdf_serializer_serialize_model_to_file.Rd new file mode 100644 index 000000000..147417c50 --- /dev/null +++ b/R/redland/man/librdf_serializer_serialize_model_to_file.Rd @@ -0,0 +1,37 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_serializer_serialize_model_to_file} +\alias{librdf_serializer_serialize_model_to_file} +\title{Write a serialized librdf_model to a file.} +\usage{ +librdf_serializer_serialize_model_to_file ( serializer, + name, + inUriOrNull, + model, + .copy ) +} +\arguments{ + +\item{serializer}{the serializer ("_p_librdf_serializer_s")} + +\item{name}{filename to serialize to ("character")} + +\item{inUriOrNull}{the base URI to use (or NULL) ("_p_librdf_uri_s")} + +\item{model}{the librdf_model model to use ("_p_librdf_model_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Write a serialized librdf_model to a file. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_serializer_serialize_model_to_string.Rd b/R/redland/man/librdf_serializer_serialize_model_to_string.Rd new file mode 100644 index 000000000..aec1541bd --- /dev/null +++ b/R/redland/man/librdf_serializer_serialize_model_to_string.Rd @@ -0,0 +1,33 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_serializer_serialize_model_to_string} +\alias{librdf_serializer_serialize_model_to_string} +\title{Write a serialized librdf_model to a string. +The returned string must be freed by the caller using librdf_free_memory().} +\usage{ +librdf_serializer_serialize_model_to_string ( serializer, + inUriOrNull, + model ) +} +\arguments{ + +\item{serializer}{the serializer ("_p_librdf_serializer_s")} + +\item{inUriOrNull}{the base URI to use (or NULL) ("_p_librdf_uri_s")} + +\item{model}{the librdf_model model to use ("_p_librdf_model_s")} + +} +\value{ +character +} +\description{ +Write a serialized librdf_model to a string. +The returned string must be freed by the caller using librdf_free_memory(). +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_serializer_serialize_stream_to_file.Rd b/R/redland/man/librdf_serializer_serialize_stream_to_file.Rd new file mode 100644 index 000000000..9bc4de539 --- /dev/null +++ b/R/redland/man/librdf_serializer_serialize_stream_to_file.Rd @@ -0,0 +1,37 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_serializer_serialize_stream_to_file} +\alias{librdf_serializer_serialize_stream_to_file} +\title{Write a librdf_stream to a file.} +\usage{ +librdf_serializer_serialize_stream_to_file ( serializer, + name, + base_uri, + stream, + .copy ) +} +\arguments{ + +\item{serializer}{the serializer ("_p_librdf_serializer_s")} + +\item{name}{filename to serialize to ("character")} + +\item{base_uri}{the base URI to use (or NULL) ("_p_librdf_uri_s")} + +\item{stream}{the librdf_stream stream to use ("_p_librdf_stream_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Write a librdf_stream to a file. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_serializer_serialize_stream_to_string.Rd b/R/redland/man/librdf_serializer_serialize_stream_to_string.Rd new file mode 100644 index 000000000..6591e3e84 --- /dev/null +++ b/R/redland/man/librdf_serializer_serialize_stream_to_string.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_serializer_serialize_stream_to_string} +\alias{librdf_serializer_serialize_stream_to_string} +\title{Write a librdf_stream to a string.} +\usage{ +librdf_serializer_serialize_stream_to_string ( serializer, + base_uri, + stream ) +} +\arguments{ + +\item{serializer}{the serializer ("_p_librdf_serializer_s")} + +\item{base_uri}{the base URI to use (or NULL) ("_p_librdf_uri_s")} + +\item{stream}{the librdf_stream stream to use ("_p_librdf_stream_s")} + +} +\value{ +character +} +\description{ +Write a librdf_stream to a string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_serializer_set_feature.Rd b/R/redland/man/librdf_serializer_set_feature.Rd new file mode 100644 index 000000000..d2ab3e3b7 --- /dev/null +++ b/R/redland/man/librdf_serializer_set_feature.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_serializer_set_feature} +\alias{librdf_serializer_set_feature} +\title{Set the value of a serializer feature.} +\usage{ +librdf_serializer_set_feature ( serializer, + feature, + value, + .copy ) +} +\arguments{ + +\item{serializer}{serializer object ("_p_librdf_serializer_s")} + +\item{feature}{URI of feature ("_p_librdf_uri_s")} + +\item{value}{value to set ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Set the value of a serializer feature. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_serializer_set_namespace.Rd b/R/redland/man/librdf_serializer_set_namespace.Rd new file mode 100644 index 000000000..ee4fc1e3d --- /dev/null +++ b/R/redland/man/librdf_serializer_set_namespace.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_serializer_set_namespace} +\alias{librdf_serializer_set_namespace} +\title{Set a namespace URI/prefix mapping.} +\usage{ +librdf_serializer_set_namespace ( serializer, + nspace, + prefix, + .copy ) +} +\arguments{ + +\item{serializer}{serializer object ("_p_librdf_serializer_s")} + +\item{nspace}{URI of namespace or NULL ("_p_librdf_uri_s")} + +\item{prefix}{prefix to use or NULL ("character")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Set a namespace URI/prefix mapping. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_short_copyright_string.Rd b/R/redland/man/librdf_short_copyright_string.Rd new file mode 100644 index 000000000..2714f3159 --- /dev/null +++ b/R/redland/man/librdf_short_copyright_string.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_short_copyright_string} +\alias{librdf_short_copyright_string} +\title{Short copyright string (one line).} +\usage{ +librdf_short_copyright_string ( .copy ) +} +\arguments{ + +\item{.copy}{NA} + +} +\value{ +character +} +\description{ +Short copyright string (one line). +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_short_copyright_string_get.Rd b/R/redland/man/librdf_short_copyright_string_get.Rd new file mode 100644 index 000000000..9c6952148 --- /dev/null +++ b/R/redland/man/librdf_short_copyright_string_get.Rd @@ -0,0 +1,24 @@ +\name{librdf_short_copyright_string_get} +\alias{librdf_short_copyright_string_get} +\title{Return Redland librdf copyright string} +\usage{ +librdf_short_copyright_string_get( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +character +} +\description{ +Return Redland librdf copyright string +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_statement_equals.Rd b/R/redland/man/librdf_statement_equals.Rd new file mode 100644 index 000000000..92c2ada2e --- /dev/null +++ b/R/redland/man/librdf_statement_equals.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_statement_equals} +\alias{librdf_statement_equals} +\title{Check if two statements are equal.} +\usage{ +librdf_statement_equals ( statement1, + statement2, + .copy ) +} +\arguments{ + +\item{statement1}{first librdf_statement ("_p_librdf_statement_s")} + +\item{statement2}{second librdf_statement ("_p_librdf_statement_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Check if two statements are equal. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_statement_get_object.Rd b/R/redland/man/librdf_statement_get_object.Rd new file mode 100644 index 000000000..3810f1637 --- /dev/null +++ b/R/redland/man/librdf_statement_get_object.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_statement_get_object} +\alias{librdf_statement_get_object} +\title{Get the statement object.} +\usage{ +librdf_statement_get_object ( statement ) +} +\arguments{ + +\item{statement}{librdf_statement object ("_p_librdf_statement_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Get the statement object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_statement_get_predicate.Rd b/R/redland/man/librdf_statement_get_predicate.Rd new file mode 100644 index 000000000..d77bbb9cb --- /dev/null +++ b/R/redland/man/librdf_statement_get_predicate.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_statement_get_predicate} +\alias{librdf_statement_get_predicate} +\title{Get the statement predicate.} +\usage{ +librdf_statement_get_predicate ( statement ) +} +\arguments{ + +\item{statement}{librdf_statement object ("_p_librdf_statement_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Get the statement predicate. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_statement_get_subject.Rd b/R/redland/man/librdf_statement_get_subject.Rd new file mode 100644 index 000000000..b686c798c --- /dev/null +++ b/R/redland/man/librdf_statement_get_subject.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_statement_get_subject} +\alias{librdf_statement_get_subject} +\title{Get the statement subject.} +\usage{ +librdf_statement_get_subject ( statement ) +} +\arguments{ + +\item{statement}{librdf_statement object ("_p_librdf_statement_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Get the statement subject. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_statement_is_complete.Rd b/R/redland/man/librdf_statement_is_complete.Rd new file mode 100644 index 000000000..35b3dd350 --- /dev/null +++ b/R/redland/man/librdf_statement_is_complete.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_statement_is_complete} +\alias{librdf_statement_is_complete} +\title{Check if statement is a complete and legal RDF triple.} +\usage{ +librdf_statement_is_complete ( statement, + .copy ) +} +\arguments{ + +\item{statement}{librdf_statement object ("_p_librdf_statement_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Check if statement is a complete and legal RDF triple. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_statement_match.Rd b/R/redland/man/librdf_statement_match.Rd new file mode 100644 index 000000000..e28d01582 --- /dev/null +++ b/R/redland/man/librdf_statement_match.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_statement_match} +\alias{librdf_statement_match} +\title{Match a statement against a 'partial' statement.} +\usage{ +librdf_statement_match ( statement, + partial_statement, + .copy ) +} +\arguments{ + +\item{statement}{statement ("_p_librdf_statement_s")} + +\item{partial_statement}{statement with possible empty parts ("_p_librdf_statement_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Match a statement against a 'partial' statement. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_statement_set_object.Rd b/R/redland/man/librdf_statement_set_object.Rd new file mode 100644 index 000000000..574f9a699 --- /dev/null +++ b/R/redland/man/librdf_statement_set_object.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_statement_set_object} +\alias{librdf_statement_set_object} +\title{Set the statement object.} +\usage{ +librdf_statement_set_object ( statement, + object ) +} +\arguments{ + +\item{statement}{librdf_statement object ("_p_librdf_statement_s")} + +\item{object}{librdf_node of object ("_p_librdf_node_s")} + +} +\value{ +void +} +\description{ +Set the statement object. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_statement_set_predicate.Rd b/R/redland/man/librdf_statement_set_predicate.Rd new file mode 100644 index 000000000..259b02191 --- /dev/null +++ b/R/redland/man/librdf_statement_set_predicate.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_statement_set_predicate} +\alias{librdf_statement_set_predicate} +\title{Set the statement predicate.} +\usage{ +librdf_statement_set_predicate ( statement, + predicate ) +} +\arguments{ + +\item{statement}{librdf_statement object ("_p_librdf_statement_s")} + +\item{predicate}{librdf_node of predicate ("_p_librdf_node_s")} + +} +\value{ +void +} +\description{ +Set the statement predicate. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_statement_set_subject.Rd b/R/redland/man/librdf_statement_set_subject.Rd new file mode 100644 index 000000000..4a7ea9700 --- /dev/null +++ b/R/redland/man/librdf_statement_set_subject.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_statement_set_subject} +\alias{librdf_statement_set_subject} +\title{Set the statement subject.} +\usage{ +librdf_statement_set_subject ( statement, + subject ) +} +\arguments{ + +\item{statement}{librdf_statement object ("_p_librdf_statement_s")} + +\item{subject}{librdf_node of subject ("_p_librdf_node_s")} + +} +\value{ +void +} +\description{ +Set the statement subject. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_stream_end.Rd b/R/redland/man/librdf_stream_end.Rd new file mode 100644 index 000000000..05cc70edd --- /dev/null +++ b/R/redland/man/librdf_stream_end.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_stream_end} +\alias{librdf_stream_end} +\title{Test if the stream has ended.} +\usage{ +librdf_stream_end ( stream, + .copy ) +} +\arguments{ + +\item{stream}{librdf_stream object ("_p_librdf_stream_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Test if the stream has ended. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_stream_get_object.Rd b/R/redland/man/librdf_stream_get_object.Rd new file mode 100644 index 000000000..c116d4cec --- /dev/null +++ b/R/redland/man/librdf_stream_get_object.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_stream_get_object} +\alias{librdf_stream_get_object} +\title{Get the current librdf_statement in the stream.} +\usage{ +librdf_stream_get_object ( stream ) +} +\arguments{ + +\item{stream}{librdf_stream object ("_p_librdf_stream_s")} + +} +\value{ +_p_librdf_statement_s +} +\description{ +Get the current librdf_statement in the stream. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_stream_next.Rd b/R/redland/man/librdf_stream_next.Rd new file mode 100644 index 000000000..cfa2a08ca --- /dev/null +++ b/R/redland/man/librdf_stream_next.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_stream_next} +\alias{librdf_stream_next} +\title{Move to the next librdf_statement in the stream.} +\usage{ +librdf_stream_next ( stream, + .copy ) +} +\arguments{ + +\item{stream}{librdf_stream object ("_p_librdf_stream_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Move to the next librdf_statement in the stream. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_uri_compare.Rd b/R/redland/man/librdf_uri_compare.Rd new file mode 100644 index 000000000..e655cdc13 --- /dev/null +++ b/R/redland/man/librdf_uri_compare.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_uri_compare} +\alias{librdf_uri_compare} +\title{Compare two librdf_uri objects lexicographically.} +\usage{ +librdf_uri_compare ( first_uri, + second_uri, + .copy ) +} +\arguments{ + +\item{first_uri}{librdf_uri object 1 or NULL ("_p_librdf_uri_s")} + +\item{second_uri}{librdf_uri object 2 or NULL ("_p_librdf_uri_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Compare two librdf_uri objects lexicographically. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_uri_equals.Rd b/R/redland/man/librdf_uri_equals.Rd new file mode 100644 index 000000000..3ed147dbb --- /dev/null +++ b/R/redland/man/librdf_uri_equals.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_uri_equals} +\alias{librdf_uri_equals} +\title{Compare two librdf_uri objects for equality.} +\usage{ +librdf_uri_equals ( first_uri, + second_uri, + .copy ) +} +\arguments{ + +\item{first_uri}{librdf_uri object 1 ("_p_librdf_uri_s")} + +\item{second_uri}{librdf_uri object 2 ("_p_librdf_uri_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Compare two librdf_uri objects for equality. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_uri_to_string.Rd b/R/redland/man/librdf_uri_to_string.Rd new file mode 100644 index 000000000..12cff0b24 --- /dev/null +++ b/R/redland/man/librdf_uri_to_string.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_uri_to_string} +\alias{librdf_uri_to_string} +\title{Format the URI as a string.} +\usage{ +librdf_uri_to_string ( uri ) +} +\arguments{ + +\item{uri}{librdf_uri object ("_p_librdf_uri_s")} + +} +\value{ +character +} +\description{ +Format the URI as a string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_version_decimal.Rd b/R/redland/man/librdf_version_decimal.Rd new file mode 100644 index 000000000..4bada67b8 --- /dev/null +++ b/R/redland/man/librdf_version_decimal.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_version_decimal} +\alias{librdf_version_decimal} +\title{Library full version as a decimal integer.} +\usage{ +librdf_version_decimal ( .copy ) +} +\arguments{ + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Library full version as a decimal integer. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_version_decimal_get.Rd b/R/redland/man/librdf_version_decimal_get.Rd new file mode 100644 index 000000000..70f52ce17 --- /dev/null +++ b/R/redland/man/librdf_version_decimal_get.Rd @@ -0,0 +1,24 @@ +\name{librdf_version_decimal_get} +\alias{librdf_version_decimal_get} +\title{Return Redland librdf copyright} +\usage{ +librdf_version_decimal_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Return Redland librdf copyright +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_version_major.Rd b/R/redland/man/librdf_version_major.Rd new file mode 100644 index 000000000..a4e4bf9ad --- /dev/null +++ b/R/redland/man/librdf_version_major.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_version_major} +\alias{librdf_version_major} +\title{Library major version number as a decimal integer.} +\usage{ +librdf_version_major ( .copy ) +} +\arguments{ + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Library major version number as a decimal integer. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_version_major_get.Rd b/R/redland/man/librdf_version_major_get.Rd new file mode 100644 index 000000000..9cd7238b2 --- /dev/null +++ b/R/redland/man/librdf_version_major_get.Rd @@ -0,0 +1,24 @@ +\name{librdf_version_major_get} +\alias{librdf_version_major_get} +\title{Return the Redland librdf major version number} +\usage{ +librdf_version_major_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Return the Redland librdf major version number +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_version_minor.Rd b/R/redland/man/librdf_version_minor.Rd new file mode 100644 index 000000000..b40ee6d09 --- /dev/null +++ b/R/redland/man/librdf_version_minor.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_version_minor} +\alias{librdf_version_minor} +\title{Library minor version number as a decimal integer.} +\usage{ +librdf_version_minor ( .copy ) +} +\arguments{ + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Library minor version number as a decimal integer. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_version_minor_get.Rd b/R/redland/man/librdf_version_minor_get.Rd new file mode 100644 index 000000000..e86390895 --- /dev/null +++ b/R/redland/man/librdf_version_minor_get.Rd @@ -0,0 +1,24 @@ +\name{librdf_version_minor_get} +\alias{librdf_version_minor_get} +\title{Return the Redland librdf minor version number} +\usage{ +librdf_version_minor_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Return the Redland librdf minor version number +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_version_release.Rd b/R/redland/man/librdf_version_release.Rd new file mode 100644 index 000000000..316371690 --- /dev/null +++ b/R/redland/man/librdf_version_release.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_version_release} +\alias{librdf_version_release} +\title{Library release version number as a decimal integer.} +\usage{ +librdf_version_release ( .copy ) +} +\arguments{ + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Library release version number as a decimal integer. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_version_release_get.Rd b/R/redland/man/librdf_version_release_get.Rd new file mode 100644 index 000000000..8e988e3d8 --- /dev/null +++ b/R/redland/man/librdf_version_release_get.Rd @@ -0,0 +1,24 @@ +\name{librdf_version_release_get} +\alias{librdf_version_release_get} +\title{Return the Redland librdf release version number} +\usage{ +librdf_version_release_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Return the Redland librdf release version number +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_version_string.Rd b/R/redland/man/librdf_version_string.Rd new file mode 100644 index 000000000..92f3bb79e --- /dev/null +++ b/R/redland/man/librdf_version_string.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_version_string} +\alias{librdf_version_string} +\title{Library full version as a string.} +\usage{ +librdf_version_string ( .copy ) +} +\arguments{ + +\item{.copy}{NA} + +} +\value{ +character +} +\description{ +Library full version as a string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_version_string_get.Rd b/R/redland/man/librdf_version_string_get.Rd new file mode 100644 index 000000000..fefe93233 --- /dev/null +++ b/R/redland/man/librdf_version_string_get.Rd @@ -0,0 +1,24 @@ +\name{librdf_version_string_get} +\alias{librdf_version_string_get} +\title{Return the Redland librdf version as a string.} +\usage{ +librdf_version_string_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +character +} +\description{ +Return the Redland librdf version as a string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_world_get_feature.Rd b/R/redland/man/librdf_world_get_feature.Rd new file mode 100644 index 000000000..6cfe60d58 --- /dev/null +++ b/R/redland/man/librdf_world_get_feature.Rd @@ -0,0 +1,28 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_world_get_feature} +\alias{librdf_world_get_feature} +\title{Get the value of a world feature.} +\usage{ +librdf_world_get_feature ( world, + feature ) +} +\arguments{ + +\item{world}{librdf_world object ("_p_librdf_world_s")} + +\item{feature}{librdf_uri feature property ("_p_librdf_uri_s")} + +} +\value{ +_p_librdf_node_s +} +\description{ +Get the value of a world feature. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_world_open.Rd b/R/redland/man/librdf_world_open.Rd new file mode 100644 index 000000000..17e651ebf --- /dev/null +++ b/R/redland/man/librdf_world_open.Rd @@ -0,0 +1,25 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_world_open} +\alias{librdf_world_open} +\title{Open a created redland world environment.} +\usage{ +librdf_world_open ( world ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +} +\value{ +void +} +\description{ +Open a created redland world environment. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_world_set_feature.Rd b/R/redland/man/librdf_world_set_feature.Rd new file mode 100644 index 000000000..da61471f1 --- /dev/null +++ b/R/redland/man/librdf_world_set_feature.Rd @@ -0,0 +1,34 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_world_set_feature} +\alias{librdf_world_set_feature} +\title{Set the value of a world feature.} +\usage{ +librdf_world_set_feature ( world, + feature, + value, + .copy ) +} +\arguments{ + +\item{world}{librdf_world object ("_p_librdf_world_s")} + +\item{feature}{librdf_uri feature property ("_p_librdf_uri_s")} + +\item{value}{librdf_node feature property value ("_p_librdf_node_s")} + +\item{.copy}{NA} + +} +\value{ +integer +} +\description{ +Set the value of a world feature. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/librdf_world_set_logger.Rd b/R/redland/man/librdf_world_set_logger.Rd new file mode 100644 index 000000000..2e2069b16 --- /dev/null +++ b/R/redland/man/librdf_world_set_logger.Rd @@ -0,0 +1,31 @@ +% Generated by redland-bindings R program "createLibrdfDocs.R": do not edit by hand +\name{librdf_world_set_logger} +\alias{librdf_world_set_logger} +\title{Set the world log handling function.} +\usage{ +librdf_world_set_logger ( world, + user_data, + log_handler ) +} +\arguments{ + +\item{world}{redland world object ("_p_librdf_world_s")} + +\item{user_data}{user data to pass to function ("_p_void")} + +\item{log_handler}{pointer to the function ("_p_librdf_log_func")} + +} +\value{ +void +} +\description{ +Set the world log handling function. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/mergeNamespace_roclet.Rd b/R/redland/man/mergeNamespace_roclet.Rd new file mode 100644 index 000000000..8d4729c49 --- /dev/null +++ b/R/redland/man/mergeNamespace_roclet.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mergeNamespace_roclet.R +\name{mergeNamespace_roclet} +\alias{mergeNamespace_roclet} +\title{A custom Roxygen roclet that adds Redland RDF functions to NAMESPACE file generated by Roxygen.} +\usage{ +mergeNamespace_roclet(x, ...) +} +\arguments{ +\item{x}{a roclet} + +\item{...}{additional parameters} +} +\description{ +The redland package uses the SWIG (Simplified Wrapper and Interface Generator) to +create the bindings between the Redland RDF C/C++ libraries and R. SWIG creates a NAMESPACE +file that contains the function names for the librdf wrapper that it creates, but as of +swig 3.0.2 this NAMESPACE file is incorrect and will also be overwritten by Roxygen when +'roxygenize()' or 'devtools:document()' is called, as the wrapper R code doesn't contain +Roxygen export annotations used by Roxygen to build the namespace file. +To allow for building a NAMESPACE file from all programs in the redland package, this roclet +determines the set of wrapper R functions and adds these to the Roxygen generated NAMESPACE file +that contains all names from the native R code in the redland package. +} +\details{ +The following line must be present in the DESCRIPTION file for this roclet to be +called automatically when 'roxygen2::roxygenize()' or 'devtools::document()' is called: + +Roxygen: list(roclets = c("collate", "rd", "namespace", "mergeNamespace_roclet")) + +The 'namespace' roclet must always run before the 'mergeNamespace' roclet. +} +\examples{ +\dontrun{ +roxygen2::roxygenize() +devtools::document() +} +} diff --git a/R/redland/man/parseFileIntoModel.Rd b/R/redland/man/parseFileIntoModel.Rd new file mode 100644 index 000000000..dc10fcca3 --- /dev/null +++ b/R/redland/man/parseFileIntoModel.Rd @@ -0,0 +1,44 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Parser.R +\docType{methods} +\name{parseFileIntoModel} +\alias{parseFileIntoModel} +\alias{parseFileIntoModel,Parser,World,character,Model-method} +\title{Parse the contents of a file into a model} +\usage{ +parseFileIntoModel(.Object, world, filePath, model, ...) + +\S4method{parseFileIntoModel}{Parser,World,character,Model}(.Object, world, + filePath, model, baseUri = as.character(NA)) +} +\arguments{ +\item{.Object}{a Parser object} + +\item{world}{a World object} + +\item{filePath}{a file that contains the RDF content} + +\item{model}{a Model object to parse the RDF content into} + +\item{...}{(Additional parameters)} + +\item{baseUri}{a base URI (i.e. XML base) to apply to the model} +} +\description{ +The contents of a the specified file are read and parsed into the initialized +Parser object +} +\details{ +The parser factory name specified during initialization determines how the content is +parsed, for example, if 'rdfxml' was specified during parser initialization, then the parser +expects RDF/XML content as specified in the W3C recommendation (http://www.we3.org/TR/REC-rdf-syntax) +} +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +# Create the default "rdfxml" parser +parser <- new("Parser", world) +filePath <- system.file("extdata/example.rdf", package="redland") +parseFileIntoModel(parser, world, filePath, model) +} diff --git a/R/redland/man/raptor_locator_byte.Rd b/R/redland/man/raptor_locator_byte.Rd new file mode 100644 index 000000000..3969c9604 --- /dev/null +++ b/R/redland/man/raptor_locator_byte.Rd @@ -0,0 +1,26 @@ +\name{raptor_locator_byte} +\alias{raptor_locator_byte} +\title{Get the locator byte offset from locator.} +\usage{ +raptor_locator_byte ( locator, .copy ) +} +\arguments{ + +\item{locator}{raptor locator ("_p_raptor_locator")} + +\item{.copy}{logical} + +} +\value{ +character +} +\description{ +Get the locator byte offset from locator +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_locator_column.Rd b/R/redland/man/raptor_locator_column.Rd new file mode 100644 index 000000000..efc6f1aa4 --- /dev/null +++ b/R/redland/man/raptor_locator_column.Rd @@ -0,0 +1,27 @@ +\name{raptor_locator_column} +\alias{raptor_locator_column} +\title{Get column number from locator} +\usage{ +raptor_locator_column ( locator, + .copy ) +} +\arguments{ + +\item{locator}{raptor locator ("_p_raptor_locator")} + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Get column number from locator +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_locator_file.Rd b/R/redland/man/raptor_locator_file.Rd new file mode 100644 index 000000000..1309504d5 --- /dev/null +++ b/R/redland/man/raptor_locator_file.Rd @@ -0,0 +1,24 @@ +\name{raptor_locator_file} +\alias{raptor_locator_file} +\title{Get file name from locator.} +\usage{ +raptor_locator_file ( locator ) +} +\arguments{ + +\item{locator}{raptor locator ("_p_raptor_locator")} + +} +\value{ +character +} +\description{ +Get file name from locator. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_locator_line.Rd b/R/redland/man/raptor_locator_line.Rd new file mode 100644 index 000000000..9128beb62 --- /dev/null +++ b/R/redland/man/raptor_locator_line.Rd @@ -0,0 +1,26 @@ +\name{raptor_locator_line} +\alias{raptor_locator_line} +\title{Get line number from locator.} +\usage{ +raptor_locator_line ( locator, .copy ) +} +\arguments{ + +\item{locator}{raptor locator ("_p_raptor_locator")} + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Get line number from locator. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_locator_uri.Rd b/R/redland/man/raptor_locator_uri.Rd new file mode 100644 index 000000000..671b427cc --- /dev/null +++ b/R/redland/man/raptor_locator_uri.Rd @@ -0,0 +1,24 @@ +\name{raptor_locator_uri} +\alias{raptor_locator_uri} +\title{Get URI from locator.} +\usage{ +raptor_locator_uri ( locator ) +} +\arguments{ + +\item{locator}{raptor locator ("_p_raptor_locator")} + +} +\value{ +character +} +\description{ +Get URI from locator. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_version_decimal.Rd b/R/redland/man/raptor_version_decimal.Rd new file mode 100644 index 000000000..92e748f6b --- /dev/null +++ b/R/redland/man/raptor_version_decimal.Rd @@ -0,0 +1,24 @@ +\name{raptor_version_decimal} +\alias{raptor_version_decimal} +\title{Raptor version as a decimal number} +\usage{ +raptor_version_decimal ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Raptor version as a decimal number +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_version_decimal_get.Rd b/R/redland/man/raptor_version_decimal_get.Rd new file mode 100644 index 000000000..8e62875d4 --- /dev/null +++ b/R/redland/man/raptor_version_decimal_get.Rd @@ -0,0 +1,24 @@ +\name{raptor_version_decimal_get} +\alias{raptor_version_decimal_get} +\title{Raptor version as a decimal number.} +\usage{ +raptor_version_decimal_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Raptor version as a decimal number. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_version_major.Rd b/R/redland/man/raptor_version_major.Rd new file mode 100644 index 000000000..1b64cffff --- /dev/null +++ b/R/redland/man/raptor_version_major.Rd @@ -0,0 +1,24 @@ +\name{raptor_version_major} +\alias{raptor_version_major} +\title{Raptor library major version} +\usage{ +raptor_version_major ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Raptor library major version. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_version_major_get.Rd b/R/redland/man/raptor_version_major_get.Rd new file mode 100644 index 000000000..ec9edcb04 --- /dev/null +++ b/R/redland/man/raptor_version_major_get.Rd @@ -0,0 +1,24 @@ +\name{raptor_version_major_get} +\alias{raptor_version_major_get} +\title{Get Raptor library major version} +\usage{ +raptor_version_major_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Get Raptor library major version. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_version_minor.Rd b/R/redland/man/raptor_version_minor.Rd new file mode 100644 index 000000000..20ebef001 --- /dev/null +++ b/R/redland/man/raptor_version_minor.Rd @@ -0,0 +1,24 @@ +\name{raptor_version_minor} +\alias{raptor_version_minor} +\title{Raptor library minor version.} +\usage{ +raptor_version_minor ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Raptor library minor version. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_version_minor_get.Rd b/R/redland/man/raptor_version_minor_get.Rd new file mode 100644 index 000000000..c0f61fba5 --- /dev/null +++ b/R/redland/man/raptor_version_minor_get.Rd @@ -0,0 +1,24 @@ +\name{raptor_version_minor_get} +\alias{raptor_version_minor_get} +\title{Get Raptor library minor version.} +\usage{ +raptor_version_minor_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Get Raptor library minor version. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_version_release.Rd b/R/redland/man/raptor_version_release.Rd new file mode 100644 index 000000000..a47691701 --- /dev/null +++ b/R/redland/man/raptor_version_release.Rd @@ -0,0 +1,24 @@ +\name{raptor_version_release} +\alias{raptor_version_release} +\title{Raptor library release.} +\usage{ +raptor_version_release ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Raptor library release. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_version_release_get.Rd b/R/redland/man/raptor_version_release_get.Rd new file mode 100644 index 000000000..657c1742b --- /dev/null +++ b/R/redland/man/raptor_version_release_get.Rd @@ -0,0 +1,24 @@ +\name{raptor_version_release_get} +\alias{raptor_version_release_get} +\title{Raptor library release.} +\usage{ +raptor_version_release_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Get Raptor library release. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_version_string.Rd b/R/redland/man/raptor_version_string.Rd new file mode 100644 index 000000000..484fe64c3 --- /dev/null +++ b/R/redland/man/raptor_version_string.Rd @@ -0,0 +1,24 @@ +\name{raptor_version_string} +\alias{raptor_version_string} +\title{Raptor library version string.} +\usage{ +raptor_version_string ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +character +} +\description{ +Raptor library version string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/raptor_version_string_get.Rd b/R/redland/man/raptor_version_string_get.Rd new file mode 100644 index 000000000..6eddfa737 --- /dev/null +++ b/R/redland/man/raptor_version_string_get.Rd @@ -0,0 +1,24 @@ +\name{raptor_version_string_get} +\alias{raptor_version_string_get} +\title{Get Raptor library version string.} +\usage{ +raptor_version_string_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +character +} +\description{ +Get Raptor library version string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/rasqal_version_decimal.Rd b/R/redland/man/rasqal_version_decimal.Rd new file mode 100644 index 000000000..774f72201 --- /dev/null +++ b/R/redland/man/rasqal_version_decimal.Rd @@ -0,0 +1,24 @@ +\name{rasqal_version_decimal} +\alias{rasqal_version_decimal} +\title{Rasqal version as a decimal number.} +\usage{ +rasqal_version_decimal ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Rasqal version as a decimal number. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/rasqal_version_decimal_get.Rd b/R/redland/man/rasqal_version_decimal_get.Rd new file mode 100644 index 000000000..7fad32306 --- /dev/null +++ b/R/redland/man/rasqal_version_decimal_get.Rd @@ -0,0 +1,24 @@ +\name{rasqal_version_decimal_get} +\alias{rasqal_version_decimal_get} +\title{Get the Rasqal version as a decimal number.} +\usage{ +rasqal_version_decimal_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Get the Rasqal version as a decimal number. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/rasqal_version_major.Rd b/R/redland/man/rasqal_version_major.Rd new file mode 100644 index 000000000..6d63fde1f --- /dev/null +++ b/R/redland/man/rasqal_version_major.Rd @@ -0,0 +1,24 @@ +\name{rasqal_version_major} +\alias{rasqal_version_major} +\title{Rasqal major version number.} +\usage{ +rasqal_version_major ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Rasqal major version number. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/rasqal_version_major_get.Rd b/R/redland/man/rasqal_version_major_get.Rd new file mode 100644 index 000000000..7eca38060 --- /dev/null +++ b/R/redland/man/rasqal_version_major_get.Rd @@ -0,0 +1,24 @@ +\name{rasqal_version_major_get} +\alias{rasqal_version_major_get} +\title{Get Rasqal major version number.} +\usage{ +rasqal_version_major_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Get Rasqal major version number. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/rasqal_version_minor.Rd b/R/redland/man/rasqal_version_minor.Rd new file mode 100644 index 000000000..f71e599b2 --- /dev/null +++ b/R/redland/man/rasqal_version_minor.Rd @@ -0,0 +1,24 @@ +\name{rasqal_version_minor} +\alias{rasqal_version_minor} +\title{Rasqal minor version number.} +\usage{ +rasqal_version_minor ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Rasqal minor version number. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/rasqal_version_minor_get.Rd b/R/redland/man/rasqal_version_minor_get.Rd new file mode 100644 index 000000000..91f2c04a7 --- /dev/null +++ b/R/redland/man/rasqal_version_minor_get.Rd @@ -0,0 +1,24 @@ +\name{rasqal_version_minor_get} +\alias{rasqal_version_minor_get} +\title{Get the Rasqal minor version number.} +\usage{ +rasqal_version_minor_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Get the Rasqal minor version number. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/rasqal_version_release.Rd b/R/redland/man/rasqal_version_release.Rd new file mode 100644 index 000000000..a2e55ffe7 --- /dev/null +++ b/R/redland/man/rasqal_version_release.Rd @@ -0,0 +1,24 @@ +\name{rasqal_version_release} +\alias{rasqal_version_release} +\title{Rasqal release version number.} +\usage{ +rasqal_version_release ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Rasqal release version number. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/rasqal_version_release_get.Rd b/R/redland/man/rasqal_version_release_get.Rd new file mode 100644 index 000000000..eaf04c4c2 --- /dev/null +++ b/R/redland/man/rasqal_version_release_get.Rd @@ -0,0 +1,24 @@ +\name{rasqal_version_release_get} +\alias{rasqal_version_release_get} +\title{Get the Rasqal release version number.} +\usage{ +rasqal_version_release_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Get the Rasqal release version number. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/rasqal_version_string.Rd b/R/redland/man/rasqal_version_string.Rd new file mode 100644 index 000000000..e8594701f --- /dev/null +++ b/R/redland/man/rasqal_version_string.Rd @@ -0,0 +1,24 @@ +\name{rasqal_version_string} +\alias{rasqal_version_string} +\title{Rasqal version as a string} +\usage{ +rasqal_version_string ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Rasqal version as a string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/rasqal_version_string_get.Rd b/R/redland/man/rasqal_version_string_get.Rd new file mode 100644 index 000000000..21817b517 --- /dev/null +++ b/R/redland/man/rasqal_version_string_get.Rd @@ -0,0 +1,24 @@ +\name{rasqal_version_string_get} +\alias{rasqal_version_string_get} +\title{Get the Rasqal version as a string} +\usage{ +rasqal_version_string_get ( .copy ) +} +\arguments{ + +\item{.copy}{logical} + +} +\value{ +integer +} +\description{ +Get the Rasqal version as a string. +} +\references{ +\url{http://librdf.org/docs} +} +\seealso{ +This R function is a wrapper function that directly calls the the Redland RDF C libraries. +For more information about Redland RDF, view the online documentation indicated in the 'References' section. +} diff --git a/R/redland/man/redland.Rd b/R/redland/man/redland.Rd new file mode 100644 index 000000000..5f0bae924 --- /dev/null +++ b/R/redland/man/redland.Rd @@ -0,0 +1,71 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/redland-package.R +\docType{package} +\name{redland} +\alias{redland} +\alias{redland-package} +\title{Create, query and write RDF graphs.} +\description{ +The R package \emph{redland} provides methods to create, query and write information stored in the +Resource Description Framework (RDF). This package is implemented as R scripts that provide an +R interface (aka "wrapper") to the Redland RDF C libraries. Documentation for the redland R package classes +and functions are available from the standard R help facility, for example, \code{'help("Node-class")'}, \code{'?getNodeType'}, etc. + +An overview of the redland R package is available with the R command: \code{'vignette("redland_overview")'}. + +The Redland C library functions are described at \url{http://librdf.org/docs/api/index.html}. + +An introduction to RDF can be found at \url{http://www.w3.org/TR/rdf-primer}. +} +\details{ +The redland R package classes and the corresponding Redland C library types are shown in the following table: +\tabular{llll}{ +\strong{Concept}\tab \strong{Redland C type}\tab \strong{redland R class}\tab \strong{Purpose}\cr +Resource / Literal\tab librdf_node\tab \linkS4class{Node}\tab RDF Model & Syntax nodes\cr +Statement / Triple\tab librdf_statement\tab \linkS4class{Statement}\tab RDF Model & Syntax arcs (statements, triples)\cr +Model\tab librdf_model\tab \linkS4class{Model}\tab Set of Statements usually held in one Storage.\cr +Node\tab librdf_node\tab \linkS4class{Node}\tab The subject, predicate or object of a Statement\cr +Storage\tab librdf_storage\tab \linkS4class{Storage}\tab Storage for Models either persistent or in-memory.\cr +Parser\tab librdf_parser\tab \linkS4class{Parser}\tab Syntax parsers delivering Stream of Statements or writing to a Model\cr +Query\tab librdf_query\tab \linkS4class{Query}\tab Querying of an Model delivering a QueryResults\cr +QueryResults\tab librdf_query_results\tab \linkS4class{QueryResults}\tab Results of applying an Query to a Model giving either variable bindings with Node values or Stream of Statements\cr +Serializer\tab librdf_serializer\tab \linkS4class{Serializer}\tab Serializes a Model into a syntax such as RDF/XML\cr +World\tab librdf_world\tab \linkS4class{World}\tab RDF wrapper class handling Redland startup/shutdown\cr +} +} +\note{ +In order to communicate with the Redland RDF C libraries, the redland R package uses an interface layer that is created +with the software package \emph{Simplified Wrapper and Interface Generator} (\href{https://github.com/swig/swig}{SWIG}). +The relationship between the redland R package and the Redland C libraries is: + +User script -> redland R package -> SWIG R interface -> Redland C libraries -> RDF data + +It is recommended that the redland package R classes be used to interact with RDF, as these higher level classes take care of many of the the +details of communicating with the Redland C libraries. However, all of the lower level R interface functions generated by SWIG are made available +by the redland package. These interface functions usually have names beginning with \code{'librdf_'}, \code{'rasqal_'} or \code{'raptor_'} and +are usually the same name as the underlying C library function. Documentation +for the R SWIG interface functions can be found via R help i.e. \code{'?librdf_iterator'}. +} +\examples{ +# This example creates the necessary R objects to hold an RDF model and reads +# in a file that contains RDF/XML statements. This model is then queried for +# and the query results inspected. +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +filePath <- system.file("extdata/example.rdf", package="redland") +parser <- new("Parser", world) +parseFileIntoModel(parser, world, filePath, model) +queryString <- paste("PREFIX dc: ", + "SELECT ?a ?c WHERE { ?a dc:description ?c . }", sep="") +query <- new("Query", world, queryString, base_uri=NULL, + query_language="sparql", query_uri=NULL) +results <- getResults(query, model, "rdfxml") + +# When the query object is no longer needed, the resources it had allocated can be freed. +freeQuery(query) +rm(query) +} +\author{ +Matthew B. Jones (NCEAS) and Peter Slaughter (NCEAS) +} diff --git a/R/redland/man/roclet_output.roclet_mergeNamespace.Rd b/R/redland/man/roclet_output.roclet_mergeNamespace.Rd new file mode 100644 index 000000000..9514bf563 --- /dev/null +++ b/R/redland/man/roclet_output.roclet_mergeNamespace.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mergeNamespace_roclet.R +\name{roclet_output.roclet_mergeNamespace} +\alias{roclet_output.roclet_mergeNamespace} +\title{Roxygen output function that merges a base NAMESPACE file with the Roxygen dynamically created NAMSPACE file} +\usage{ +\method{roclet_output}{roclet_mergeNamespace}(x, results, base_path, ...) +} +\arguments{ +\item{x}{the currently running roclet} + +\item{results}{the list of items to process that was generated by the roc_process.mergedNamespace function} + +\item{base_path}{the base directory path of the package} + +\item{...}{additional parameters} +} +\description{ +The 'roclet_output' function handles output of the results from the 'roc_process' function. +This function merges the NAMESPACE file created by the 'namespace' roclet with the list of Redland RDF +functions determined by the 'roc_process' function. +} diff --git a/R/redland/man/roclet_process.roclet_mergeNamespace.Rd b/R/redland/man/roclet_process.roclet_mergeNamespace.Rd new file mode 100644 index 000000000..1e69adc8e --- /dev/null +++ b/R/redland/man/roclet_process.roclet_mergeNamespace.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mergeNamespace_roclet.R +\name{roclet_process.roclet_mergeNamespace} +\alias{roclet_process.roclet_mergeNamespace} +\title{Roxygen process function for the 'mergeNamespace' roclet} +\usage{ +\method{roclet_process}{roclet_mergeNamespace}(x, blocks, env, base_path, + global_options = list()) +} +\arguments{ +\item{x}{the currently running roclet} + +\item{blocks}{the documentation blocks} + +\item{env}{the current env} + +\item{base_path}{the top directory of the R package} + +\item{global_options}{unused by this roclet} +} +\description{ +This function is called by the Roxygen2 roxygenize function. +} +\details{ +This function loads the Redland interface file and tests each loaded function to +see if it should be exported via the NAMESPACE file. +} diff --git a/R/redland/man/serializeToCharacter.Rd b/R/redland/man/serializeToCharacter.Rd new file mode 100644 index 000000000..9136b9e35 --- /dev/null +++ b/R/redland/man/serializeToCharacter.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Serializer.R +\docType{methods} +\name{serializeToCharacter} +\alias{serializeToCharacter} +\alias{serializeToCharacter,Serializer,World,Model-method} +\title{Serialize a model to a character vector.} +\usage{ +serializeToCharacter(.Object, world, model, ...) + +\S4method{serializeToCharacter}{Serializer,World,Model}(.Object, world, + model, baseUri = as.character(NA)) +} +\arguments{ +\item{.Object}{a Serializer object} + +\item{world}{a World object} + +\item{model}{a Model object} + +\item{...}{Additional parameters} + +\item{baseUri}{a URI to prepend to relative URIs in the document} +} +\value{ +a character vector containing the serialized model +} +\description{ +Serialize a model to a character vector. +} diff --git a/R/redland/man/serializeToFile.Rd b/R/redland/man/serializeToFile.Rd new file mode 100644 index 000000000..030516c99 --- /dev/null +++ b/R/redland/man/serializeToFile.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Serializer.R +\docType{methods} +\name{serializeToFile} +\alias{serializeToFile} +\alias{serializeToFile,Serializer,World,Model,character-method} +\title{Serialize a model to a file.} +\usage{ +serializeToFile(.Object, world, model, filePath, ...) + +\S4method{serializeToFile}{Serializer,World,Model,character}(.Object, + world, model, filePath, baseUri = as.character(NA)) +} +\arguments{ +\item{.Object}{a Serializer object} + +\item{world}{a World object} + +\item{model}{a Model object} + +\item{filePath}{a file path that the serialized model will be written to} + +\item{...}{Additional parameters} + +\item{baseUri}{a base URI to use for the serialization} +} +\value{ +an integer containing the return status where non zero indicates an error occurred during serialization +} +\description{ +Serialize a model to a file. +} diff --git a/R/redland/man/setNameSpace.Rd b/R/redland/man/setNameSpace.Rd new file mode 100644 index 000000000..d0d3ba2e3 --- /dev/null +++ b/R/redland/man/setNameSpace.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Serializer.R +\docType{methods} +\name{setNameSpace} +\alias{setNameSpace} +\alias{setNameSpace,Serializer,World,character,character-method} +\title{Set a namespace for the serializer.} +\usage{ +setNameSpace(.Object, world, namespace, prefix) + +\S4method{setNameSpace}{Serializer,World,character,character}(.Object, + world, namespace, prefix) +} +\arguments{ +\item{.Object}{a Serializer object} + +\item{world}{a World object} + +\item{namespace}{the namespace to add to the serializer} + +\item{prefix}{the namespace prefix to associate with the namespace} +} +\description{ +Set a namespace for the serializer. +} diff --git a/R/redland/man/setQueryResultsLimit.Rd b/R/redland/man/setQueryResultsLimit.Rd new file mode 100644 index 000000000..7b7e414d6 --- /dev/null +++ b/R/redland/man/setQueryResultsLimit.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Query.R +\docType{methods} +\name{setQueryResultLimit} +\alias{setQueryResultLimit} +\alias{setQueryResultsLimit} +\alias{setQueryResultLimit,Query-method} +\title{Set limit on returned query results} +\usage{ +setQueryResultLimit(.Object, limit) + +\S4method{setQueryResultLimit}{Query}(.Object, limit) +} +\arguments{ +\item{.Object}{a Query object} + +\item{limit}{the result set limit. Specify a value >= to have a limit, or a value < 0 to have no limit.} +} +\description{ +Set limit on returned query results +} diff --git a/R/redland/man/sub-ExternalReference-method.Rd b/R/redland/man/sub-ExternalReference-method.Rd new file mode 100644 index 000000000..2b3353329 --- /dev/null +++ b/R/redland/man/sub-ExternalReference-method.Rd @@ -0,0 +1,22 @@ +\docType{methods} +\name{[,ExternalReference-method} +\alias{[,ExternalReference-method} +\title{Subset a list of ExternalReferences} +\usage{ +\S4method{[}{ExternalReference}(x, i, j, ..., drop = TRUE) +} +\arguments{ +\item{x}{a list of ExternalReferences} + +\item{i}{row subscript} + +\item{j}{column subscript} + +\item{...}{additional arguments} + +\item{drop}{a logical} +} +\description{ +Subset a list of ExternalReferences +} + diff --git a/R/redland/man/subset-ExternalReference-method.Rd b/R/redland/man/subset-ExternalReference-method.Rd new file mode 100644 index 000000000..b1f44a61b --- /dev/null +++ b/R/redland/man/subset-ExternalReference-method.Rd @@ -0,0 +1,22 @@ +\docType{methods} +\name{[<-,ExternalReference-method} +\alias{[<-,ExternalReference-method} +\title{Assign values in a list of ExternalReferences} +\usage{ +\S4method{[}{ExternalReference}(x, i, j, ...) <- value +} +\arguments{ +\item{x}{a list of ExternalReferences} + +\item{i}{row subscript} + +\item{j}{column subscript} + +\item{...}{additional arguments} + +\item{value}{a value to assign} +} +\description{ +Assign values in a list of ExternalReferences +} + diff --git a/R/redland/man/writeResults.Rd b/R/redland/man/writeResults.Rd new file mode 100644 index 000000000..22ebed46d --- /dev/null +++ b/R/redland/man/writeResults.Rd @@ -0,0 +1,59 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Query.R +\docType{methods} +\name{writeResults} +\alias{writeResults} +\alias{writeResults,Query-method} +\title{Write query results to a file.} +\usage{ +writeResults(.Object, model, ...) + +\S4method{writeResults}{Query}(.Object, model, file, + mimeType = "application/x-turtle", format_uri = NULL, + base_uri = NULL) +} +\arguments{ +\item{.Object}{a Query object} + +\item{model}{a Model object} + +\item{...}{additional parameters} + +\item{file}{a string specifying the output file} + +\item{mimeType}{a string specifying the mimeType of the output file. Currently supported values are "application/x-turtle", "text/plain", "application/json", "text/html"} + +\item{format_uri}{(not currently used)} + +\item{base_uri}{(not currently used)} +} +\description{ +Write query results to a file. +} +\details{ +After this method is called, the Query object is no longer usable and should +be deleted \code{"rm(query)"} and a new object created. +} +\examples{ +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world, storage, options="") +stmt <- new("Statement", world=world, + subject="https://orcid.org/0000-0002-2192-403X", + predicate="http://www.w3.org/ns/prov#Agent", + object="slaughter", + objectType="literal", datatype_uri="http://www.w3.org/2001/XMLSchema#string") +status <- addStatement(model, stmt) +queryString <- paste("PREFIX orcid: ", + "PREFIX dataone: ", + "PREFIX prov: ", + "SELECT ?a ?c WHERE { ?a prov:Agent ?c . }", sep=" ") +query <- new("Query", world, queryString, base_uri=NULL, query_language="sparql", query_uri=NULL) +# Return all results as a string +tf <- tempfile() +writeResults(query, model, file=tf, mimeType="application/x-turtle") + +# When the query object is no longer needed, the resources it had allocated can be freed. +freeQuery(query) +rm(query) +} diff --git a/R/redland/src/Makevars.in b/R/redland/src/Makevars.in new file mode 100644 index 000000000..deb13f194 --- /dev/null +++ b/R/redland/src/Makevars.in @@ -0,0 +1,7 @@ +PKG_CPPFLAGS=@cflags@ +PKG_LIBS=@libs@ + +all: clean + +clean: + rm -f *.o *.so \ No newline at end of file diff --git a/R/redland/src/Makevars.win b/R/redland/src/Makevars.win new file mode 100644 index 000000000..8320c1156 --- /dev/null +++ b/R/redland/src/Makevars.win @@ -0,0 +1,24 @@ +PKG_CPPFLAGS= -I../windows/redland-1.0.17/include \ + -I../windows/redland-1.0.17/include/rasqal \ + -I../windows/redland-1.0.17/include/raptor2 + +PKG_LIBS=-L../windows/redland-1.0.17/lib${R_ARCH} -lrdf \ + -pipe -lrasqal -lpcre -lraptor2 -lxml2 -lpcre -lws2_32 + +## Workaround for missing _mkgmtime on Win32, See also +## https://sourceforge.net/p/mingw-w64/bugs/473/ +ifeq "${R_ARCH}" "/i386" +ifeq "${R_COMPILED_BY}" "gcc 4.9.3" +PKG_LIBS += -lmsvcr100 +endif +endif + +PKG_CFLAGS=-DRASQAL_STATIC -DRAPTOR_STATIC -DREDLAND_STATIC + +all: clean winlibs + +winlibs: clean + "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" "../tools/winlibs.R" + +clean: + rm -f $(OBJECTS) redland.dll diff --git a/R/redland/src/redland.c b/R/redland/src/redland.c new file mode 100644 index 000000000..66f52d4aa --- /dev/null +++ b/R/redland/src/redland.c @@ -0,0 +1,8341 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 3.0.12 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + + +#ifndef SWIGR +#define SWIGR +#endif + +/* ----------------------------------------------------------------------------- + * This section contains generic SWIG labels for method/variable + * declarations/attributes, and other compiler dependent labels. + * ----------------------------------------------------------------------------- */ + +/* template workaround for compilers that cannot correctly implement the C++ standard */ +#ifndef SWIGTEMPLATEDISAMBIGUATOR +# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) +# define SWIGTEMPLATEDISAMBIGUATOR template +# elif defined(__HP_aCC) +/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ +/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ +# define SWIGTEMPLATEDISAMBIGUATOR template +# else +# define SWIGTEMPLATEDISAMBIGUATOR +# endif +#endif + +/* inline attribute */ +#ifndef SWIGINLINE +# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) +# define SWIGINLINE inline +# else +# define SWIGINLINE +# endif +#endif + +/* attribute recognised by some compilers to avoid 'unused' warnings */ +#ifndef SWIGUNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +# elif defined(__ICC) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +#endif + +#ifndef SWIG_MSC_UNSUPPRESS_4505 +# if defined(_MSC_VER) +# pragma warning(disable : 4505) /* unreferenced local function has been removed */ +# endif +#endif + +#ifndef SWIGUNUSEDPARM +# ifdef __cplusplus +# define SWIGUNUSEDPARM(p) +# else +# define SWIGUNUSEDPARM(p) p SWIGUNUSED +# endif +#endif + +/* internal SWIG method */ +#ifndef SWIGINTERN +# define SWIGINTERN static SWIGUNUSED +#endif + +/* internal inline SWIG method */ +#ifndef SWIGINTERNINLINE +# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE +#endif + +/* exporting methods */ +#if defined(__GNUC__) +# if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +# ifndef GCC_HASCLASSVISIBILITY +# define GCC_HASCLASSVISIBILITY +# endif +# endif +#endif + +#ifndef SWIGEXPORT +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# if defined(STATIC_LINKED) +# define SWIGEXPORT +# else +# define SWIGEXPORT __declspec(dllexport) +# endif +# else +# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) +# define SWIGEXPORT __attribute__ ((visibility("default"))) +# else +# define SWIGEXPORT +# endif +# endif +#endif + +/* calling conventions for Windows */ +#ifndef SWIGSTDCALL +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# define SWIGSTDCALL __stdcall +# else +# define SWIGSTDCALL +# endif +#endif + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ +#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) +# define _SCL_SECURE_NO_DEPRECATE +#endif + +/* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ +#if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) +# define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 +#endif + +/* Intel's compiler complains if a variable which was never initialised is + * cast to void, which is a common idiom which we use to indicate that we + * are aware a variable isn't used. So we just silence that warning. + * See: https://github.com/swig/swig/issues/192 for more discussion. + */ +#ifdef __INTEL_COMPILER +# pragma warning disable 592 +#endif + +/* ----------------------------------------------------------------------------- + * swigrun.swg + * + * This file contains generic C API SWIG runtime support for pointer + * type checking. + * ----------------------------------------------------------------------------- */ + +/* This should only be incremented when either the layout of swig_type_info changes, + or for whatever reason, the runtime changes incompatibly */ +#define SWIG_RUNTIME_VERSION "4" + +/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ +#ifdef SWIG_TYPE_TABLE +# define SWIG_QUOTE_STRING(x) #x +# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) +# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) +#else +# define SWIG_TYPE_TABLE_NAME +#endif + +/* + You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for + creating a static or dynamic library from the SWIG runtime code. + In 99.9% of the cases, SWIG just needs to declare them as 'static'. + + But only do this if strictly necessary, ie, if you have problems + with your compiler or suchlike. +*/ + +#ifndef SWIGRUNTIME +# define SWIGRUNTIME SWIGINTERN +#endif + +#ifndef SWIGRUNTIMEINLINE +# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE +#endif + +/* Generic buffer size */ +#ifndef SWIG_BUFFER_SIZE +# define SWIG_BUFFER_SIZE 1024 +#endif + +/* Flags for pointer conversions */ +#define SWIG_POINTER_DISOWN 0x1 +#define SWIG_CAST_NEW_MEMORY 0x2 + +/* Flags for new pointer objects */ +#define SWIG_POINTER_OWN 0x1 + + +/* + Flags/methods for returning states. + + The SWIG conversion methods, as ConvertPtr, return an integer + that tells if the conversion was successful or not. And if not, + an error code can be returned (see swigerrors.swg for the codes). + + Use the following macros/flags to set or process the returning + states. + + In old versions of SWIG, code such as the following was usually written: + + if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { + // success code + } else { + //fail code + } + + Now you can be more explicit: + + int res = SWIG_ConvertPtr(obj,vptr,ty.flags); + if (SWIG_IsOK(res)) { + // success code + } else { + // fail code + } + + which is the same really, but now you can also do + + Type *ptr; + int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); + if (SWIG_IsOK(res)) { + // success code + if (SWIG_IsNewObj(res) { + ... + delete *ptr; + } else { + ... + } + } else { + // fail code + } + + I.e., now SWIG_ConvertPtr can return new objects and you can + identify the case and take care of the deallocation. Of course that + also requires SWIG_ConvertPtr to return new result values, such as + + int SWIG_ConvertPtr(obj, ptr,...) { + if () { + if () { + *ptr = ; + return SWIG_NEWOBJ; + } else { + *ptr = ; + return SWIG_OLDOBJ; + } + } else { + return SWIG_BADOBJ; + } + } + + Of course, returning the plain '0(success)/-1(fail)' still works, but you can be + more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the + SWIG errors code. + + Finally, if the SWIG_CASTRANK_MODE is enabled, the result code + allows to return the 'cast rank', for example, if you have this + + int food(double) + int fooi(int); + + and you call + + food(1) // cast rank '1' (1 -> 1.0) + fooi(1) // cast rank '0' + + just use the SWIG_AddCast()/SWIG_CheckState() +*/ + +#define SWIG_OK (0) +#define SWIG_ERROR (-1) +#define SWIG_IsOK(r) (r >= 0) +#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) + +/* The CastRankLimit says how many bits are used for the cast rank */ +#define SWIG_CASTRANKLIMIT (1 << 8) +/* The NewMask denotes the object was created (using new/malloc) */ +#define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) +/* The TmpMask is for in/out typemaps that use temporal objects */ +#define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) +/* Simple returning values */ +#define SWIG_BADOBJ (SWIG_ERROR) +#define SWIG_OLDOBJ (SWIG_OK) +#define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) +#define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) +/* Check, add and del mask methods */ +#define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) +#define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) +#define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) +#define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) +#define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) +#define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) + +/* Cast-Rank Mode */ +#if defined(SWIG_CASTRANK_MODE) +# ifndef SWIG_TypeRank +# define SWIG_TypeRank unsigned long +# endif +# ifndef SWIG_MAXCASTRANK /* Default cast allowed */ +# define SWIG_MAXCASTRANK (2) +# endif +# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) +# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) +SWIGINTERNINLINE int SWIG_AddCast(int r) { + return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; +} +SWIGINTERNINLINE int SWIG_CheckState(int r) { + return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; +} +#else /* no cast-rank mode */ +# define SWIG_AddCast(r) (r) +# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) +#endif + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *(*swig_converter_func)(void *, int *); +typedef struct swig_type_info *(*swig_dycast_func)(void **); + +/* Structure to store information on one type */ +typedef struct swig_type_info { + const char *name; /* mangled name of this type */ + const char *str; /* human readable name of this type */ + swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ + struct swig_cast_info *cast; /* linked list of types that can cast into this type */ + void *clientdata; /* language specific type data */ + int owndata; /* flag if the structure owns the clientdata */ +} swig_type_info; + +/* Structure to store a type and conversion function used for casting */ +typedef struct swig_cast_info { + swig_type_info *type; /* pointer to type that is equivalent to this type */ + swig_converter_func converter; /* function to cast the void pointers */ + struct swig_cast_info *next; /* pointer to next cast in linked list */ + struct swig_cast_info *prev; /* pointer to the previous cast */ +} swig_cast_info; + +/* Structure used to store module information + * Each module generates one structure like this, and the runtime collects + * all of these structures and stores them in a circularly linked list.*/ +typedef struct swig_module_info { + swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ + size_t size; /* Number of types in this module */ + struct swig_module_info *next; /* Pointer to next element in circularly linked list */ + swig_type_info **type_initial; /* Array of initially generated type structures */ + swig_cast_info **cast_initial; /* Array of initially generated casting structures */ + void *clientdata; /* Language specific module data */ +} swig_module_info; + +/* + Compare two type names skipping the space characters, therefore + "char*" == "char *" and "Class" == "Class", etc. + + Return 0 when the two name types are equivalent, as in + strncmp, but skipping ' '. +*/ +SWIGRUNTIME int +SWIG_TypeNameComp(const char *f1, const char *l1, + const char *f2, const char *l2) { + for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { + while ((*f1 == ' ') && (f1 != l1)) ++f1; + while ((*f2 == ' ') && (f2 != l2)) ++f2; + if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; + } + return (int)((l1 - f1) - (l2 - f2)); +} + +/* + Check type equivalence in a name list like ||... + Return 0 if equal, -1 if nb < tb, 1 if nb > tb +*/ +SWIGRUNTIME int +SWIG_TypeCmp(const char *nb, const char *tb) { + int equiv = 1; + const char* te = tb + strlen(tb); + const char* ne = nb; + while (equiv != 0 && *ne) { + for (nb = ne; *ne; ++ne) { + if (*ne == '|') break; + } + equiv = SWIG_TypeNameComp(nb, ne, tb, te); + if (*ne) ++ne; + } + return equiv; +} + +/* + Check type equivalence in a name list like ||... + Return 0 if not equal, 1 if equal +*/ +SWIGRUNTIME int +SWIG_TypeEquiv(const char *nb, const char *tb) { + return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; +} + +/* + Check the typename +*/ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheck(const char *c, swig_type_info *ty) { + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (strcmp(iter->type->name, c) == 0) { + if (iter == ty->cast) + return iter; + /* Move iter to the top of the linked list */ + iter->prev->next = iter->next; + if (iter->next) + iter->next->prev = iter->prev; + iter->next = ty->cast; + iter->prev = 0; + if (ty->cast) ty->cast->prev = iter; + ty->cast = iter; + return iter; + } + iter = iter->next; + } + } + return 0; +} + +/* + Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison +*/ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (iter->type == from) { + if (iter == ty->cast) + return iter; + /* Move iter to the top of the linked list */ + iter->prev->next = iter->next; + if (iter->next) + iter->next->prev = iter->prev; + iter->next = ty->cast; + iter->prev = 0; + if (ty->cast) ty->cast->prev = iter; + ty->cast = iter; + return iter; + } + iter = iter->next; + } + } + return 0; +} + +/* + Cast a pointer up an inheritance hierarchy +*/ +SWIGRUNTIMEINLINE void * +SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); +} + +/* + Dynamic pointer casting. Down an inheritance hierarchy +*/ +SWIGRUNTIME swig_type_info * +SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { + swig_type_info *lastty = ty; + if (!ty || !ty->dcast) return ty; + while (ty && (ty->dcast)) { + ty = (*ty->dcast)(ptr); + if (ty) lastty = ty; + } + return lastty; +} + +/* + Return the name associated with this type +*/ +SWIGRUNTIMEINLINE const char * +SWIG_TypeName(const swig_type_info *ty) { + return ty->name; +} + +/* + Return the pretty name associated with this type, + that is an unmangled type name in a form presentable to the user. +*/ +SWIGRUNTIME const char * +SWIG_TypePrettyName(const swig_type_info *type) { + /* The "str" field contains the equivalent pretty names of the + type, separated by vertical-bar characters. We choose + to print the last name, as it is often (?) the most + specific. */ + if (!type) return NULL; + if (type->str != NULL) { + const char *last_name = type->str; + const char *s; + for (s = type->str; *s; s++) + if (*s == '|') last_name = s+1; + return last_name; + } + else + return type->name; +} + +/* + Set the clientdata field for a type +*/ +SWIGRUNTIME void +SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { + swig_cast_info *cast = ti->cast; + /* if (ti->clientdata == clientdata) return; */ + ti->clientdata = clientdata; + + while (cast) { + if (!cast->converter) { + swig_type_info *tc = cast->type; + if (!tc->clientdata) { + SWIG_TypeClientData(tc, clientdata); + } + } + cast = cast->next; + } +} +SWIGRUNTIME void +SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { + SWIG_TypeClientData(ti, clientdata); + ti->owndata = 1; +} + +/* + Search for a swig_type_info structure only by mangled name + Search is a O(log #types) + + We start searching at module start, and finish searching when start == end. + Note: if start == end at the beginning of the function, we go all the way around + the circular list. +*/ +SWIGRUNTIME swig_type_info * +SWIG_MangledTypeQueryModule(swig_module_info *start, + swig_module_info *end, + const char *name) { + swig_module_info *iter = start; + do { + if (iter->size) { + size_t l = 0; + size_t r = iter->size - 1; + do { + /* since l+r >= 0, we can (>> 1) instead (/ 2) */ + size_t i = (l + r) >> 1; + const char *iname = iter->types[i]->name; + if (iname) { + int compare = strcmp(name, iname); + if (compare == 0) { + return iter->types[i]; + } else if (compare < 0) { + if (i) { + r = i - 1; + } else { + break; + } + } else if (compare > 0) { + l = i + 1; + } + } else { + break; /* should never happen */ + } + } while (l <= r); + } + iter = iter->next; + } while (iter != end); + return 0; +} + +/* + Search for a swig_type_info structure for either a mangled name or a human readable name. + It first searches the mangled names of the types, which is a O(log #types) + If a type is not found it then searches the human readable names, which is O(#types). + + We start searching at module start, and finish searching when start == end. + Note: if start == end at the beginning of the function, we go all the way around + the circular list. +*/ +SWIGRUNTIME swig_type_info * +SWIG_TypeQueryModule(swig_module_info *start, + swig_module_info *end, + const char *name) { + /* STEP 1: Search the name field using binary search */ + swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); + if (ret) { + return ret; + } else { + /* STEP 2: If the type hasn't been found, do a complete search + of the str field (the human readable name) */ + swig_module_info *iter = start; + do { + size_t i = 0; + for (; i < iter->size; ++i) { + if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) + return iter->types[i]; + } + iter = iter->next; + } while (iter != end); + } + + /* neither found a match */ + return 0; +} + +/* + Pack binary data into a string +*/ +SWIGRUNTIME char * +SWIG_PackData(char *c, void *ptr, size_t sz) { + static const char hex[17] = "0123456789abcdef"; + const unsigned char *u = (unsigned char *) ptr; + const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + unsigned char uu = *u; + *(c++) = hex[(uu & 0xf0) >> 4]; + *(c++) = hex[uu & 0xf]; + } + return c; +} + +/* + Unpack binary data from a string +*/ +SWIGRUNTIME const char * +SWIG_UnpackData(const char *c, void *ptr, size_t sz) { + unsigned char *u = (unsigned char *) ptr; + const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + char d = *(c++); + unsigned char uu; + if ((d >= '0') && (d <= '9')) + uu = (unsigned char)((d - '0') << 4); + else if ((d >= 'a') && (d <= 'f')) + uu = (unsigned char)((d - ('a'-10)) << 4); + else + return (char *) 0; + d = *(c++); + if ((d >= '0') && (d <= '9')) + uu |= (unsigned char)(d - '0'); + else if ((d >= 'a') && (d <= 'f')) + uu |= (unsigned char)(d - ('a'-10)); + else + return (char *) 0; + *u = uu; + } + return c; +} + +/* + Pack 'void *' into a string buffer. +*/ +SWIGRUNTIME char * +SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { + char *r = buff; + if ((2*sizeof(void *) + 2) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r,&ptr,sizeof(void *)); + if (strlen(name) + 1 > (bsz - (r - buff))) return 0; + strcpy(r,name); + return buff; +} + +SWIGRUNTIME const char * +SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { + if (*c != '_') { + if (strcmp(c,"NULL") == 0) { + *ptr = (void *) 0; + return name; + } else { + return 0; + } + } + return SWIG_UnpackData(++c,ptr,sizeof(void *)); +} + +SWIGRUNTIME char * +SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { + char *r = buff; + size_t lname = (name ? strlen(name) : 0); + if ((2*sz + 2 + lname) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r,ptr,sz); + if (lname) { + strncpy(r,name,lname+1); + } else { + *r = 0; + } + return buff; +} + +SWIGRUNTIME const char * +SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { + if (*c != '_') { + if (strcmp(c,"NULL") == 0) { + memset(ptr,0,sz); + return name; + } else { + return 0; + } + } + return SWIG_UnpackData(++c,ptr,sz); +} + +#ifdef __cplusplus +} +#endif + + +/* Remove global namespace pollution */ +#if !defined(SWIG_NO_R_NO_REMAP) +# define R_NO_REMAP +#endif +#if !defined(SWIG_NO_STRICT_R_HEADERS) +# define STRICT_R_HEADERS +#endif + +#include +#include + +#ifdef __cplusplus +#include +extern "C" { +#endif + +/* for raw pointer */ +#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_R_ConvertPtr(obj, pptr, type, flags) +#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_R_ConvertPtr(obj, pptr, type, flags) +#define SWIG_NewPointerObj(ptr, type, flags) SWIG_R_NewPointerObj(ptr, type, flags) + +#include +#include +#include + +#if R_VERSION >= R_Version(2,6,0) +#define VMAXTYPE void * +#else +#define VMAXTYPE char * +#endif + +/* + This is mainly a way to avoid having lots of local variables that may + conflict with those in the routine. + + Change name to R_SWIG_Callb.... +*/ +typedef struct RCallbackFunctionData { + + SEXP fun; + SEXP userData; + + + SEXP expr; + SEXP retValue; + int errorOccurred; + + SEXP el; /* Temporary pointer used in the construction of the expression to call the R function. */ + + struct RCallbackFunctionData *previous; /* Stack */ + +} RCallbackFunctionData; + +static RCallbackFunctionData *callbackFunctionDataStack; + + +SWIGRUNTIME SEXP +R_SWIG_debug_getCallbackFunctionData() +{ + int n, i; + SEXP ans; + RCallbackFunctionData *p = callbackFunctionDataStack; + + n = 0; + while(p) { + n++; + p = p->previous; + } + + Rf_protect(ans = Rf_allocVector(VECSXP, n)); + for(p = callbackFunctionDataStack, i = 0; i < n; p = p->previous, i++) + SET_VECTOR_ELT(ans, i, p->fun); + + Rf_unprotect(1); + + return(ans); +} + + + +SWIGRUNTIME RCallbackFunctionData * +R_SWIG_pushCallbackFunctionData(SEXP fun, SEXP userData) +{ + RCallbackFunctionData *el; + el = (RCallbackFunctionData *) calloc(1, sizeof(RCallbackFunctionData)); + el->fun = fun; + el->userData = userData; + el->previous = callbackFunctionDataStack; + + callbackFunctionDataStack = el; + + return(el); +} + + +SWIGRUNTIME SEXP +R_SWIG_R_pushCallbackFunctionData(SEXP fun, SEXP userData) +{ + R_SWIG_pushCallbackFunctionData(fun, userData); + return R_NilValue; +} + +SWIGRUNTIME RCallbackFunctionData * +R_SWIG_getCallbackFunctionData() +{ + if(!callbackFunctionDataStack) { + Rf_error("Supposedly impossible error occurred in the SWIG callback mechanism." + " No callback function data set."); + } + + return callbackFunctionDataStack; +} + +SWIGRUNTIME void +R_SWIG_popCallbackFunctionData(int doFree) +{ + RCallbackFunctionData *el = NULL; + if(!callbackFunctionDataStack) + return ; /* Error !!! */ + + el = callbackFunctionDataStack ; + callbackFunctionDataStack = callbackFunctionDataStack->previous; + + if(doFree) + free(el); +} + + +/* + Interface to S function + is(obj, type) + which is to be used to determine if an + external pointer inherits from the right class. + + Ideally, we would like to be able to do this without an explicit call to the is() function. + When the S4 class system uses its own SEXP types, then we will hopefully be able to do this + in the C code. + + Should we make the expression static and preserve it to avoid the overhead of + allocating each time. +*/ +SWIGRUNTIME int +R_SWIG_checkInherits(SEXP obj, SEXP tag, const char *type) +{ + SEXP e, val; + int check_err = 0; + + Rf_protect(e = Rf_allocVector(LANGSXP, 3)); + SETCAR(e, Rf_install("extends")); + + SETCAR(CDR(e), Rf_mkString(CHAR(PRINTNAME(tag)))); + SETCAR(CDR(CDR(e)), Rf_mkString(type)); + + val = R_tryEval(e, R_GlobalEnv, &check_err); + Rf_unprotect(1); + if(check_err) + return(0); + + + return(LOGICAL(val)[0]); +} + + +SWIGRUNTIME void * +R_SWIG_resolveExternalRef(SEXP arg, const char * const type, const char * const argName, Rboolean nullOk) +{ + void *ptr; + SEXP orig = arg; + + if(TYPEOF(arg) != EXTPTRSXP) + arg = GET_SLOT(arg, Rf_mkString("ref")); + + + if(TYPEOF(arg) != EXTPTRSXP) { + Rf_error("argument %s must be an external pointer (from an ExternalReference)", argName); + } + + + ptr = R_ExternalPtrAddr(arg); + + if(ptr == NULL && nullOk == (Rboolean) FALSE) { + Rf_error("the external pointer (of type %s) for argument %s has value NULL", argName, type); + } + + if(type[0] && R_ExternalPtrTag(arg) != Rf_install(type) && strcmp(type, "voidRef") + && !R_SWIG_checkInherits(orig, R_ExternalPtrTag(arg), type)) { + Rf_error("the external pointer for argument %s has tag %s, not the expected value %s", + argName, CHAR(PRINTNAME(R_ExternalPtrTag(arg))), type); + } + + + return(ptr); +} + +SWIGRUNTIME void +R_SWIG_ReferenceFinalizer(SEXP el) +{ + void *ptr = R_SWIG_resolveExternalRef(el, "", "", (Rboolean) 1); + Rf_PrintValue(el); + + if(ptr) { + if(TYPEOF(el) != EXTPTRSXP) + el = GET_SLOT(el, Rf_mkString("ref")); + + if(TYPEOF(el) == EXTPTRSXP) + R_ClearExternalPtr(el); + + free(ptr); + } + + return; +} + +typedef enum {R_SWIG_EXTERNAL, R_SWIG_OWNER } R_SWIG_Owner; + +SWIGRUNTIME SEXP +SWIG_MakePtr(void *ptr, const char *typeName, R_SWIG_Owner owner) +{ + SEXP external, r_obj; + + Rf_protect(external = R_MakeExternalPtr(ptr, Rf_install(typeName), R_NilValue)); + Rf_protect(r_obj = NEW_OBJECT(MAKE_CLASS((char *) typeName))); + + if(owner) + R_RegisterCFinalizer(external, R_SWIG_ReferenceFinalizer); + + r_obj = SET_SLOT(r_obj, Rf_mkString((char *) "ref"), external); + SET_S4_OBJECT(r_obj); + Rf_unprotect(2); + + return(r_obj); +} + + +SWIGRUNTIME SEXP +R_SWIG_create_SWIG_R_Array(const char *typeName, SEXP ref, int len) +{ + SEXP arr; + +/*XXX remove the char * cast when we can. MAKE_CLASS should be declared appropriately. */ + Rf_protect(arr = NEW_OBJECT(MAKE_CLASS((char *) typeName))); + Rf_protect(arr = R_do_slot_assign(arr, Rf_mkString("ref"), ref)); + Rf_protect(arr = R_do_slot_assign(arr, Rf_mkString("dims"), Rf_ScalarInteger(len))); + + Rf_unprotect(3); + SET_S4_OBJECT(arr); + return arr; +} + +#define ADD_OUTPUT_ARG(result, pos, value, name) r_ans = AddOutputArgToReturn(pos, value, name, OutputValues); + +SWIGRUNTIME SEXP +AddOutputArgToReturn(int pos, SEXP value, const char *name, SEXP output) +{ + SET_VECTOR_ELT(output, pos, value); + + return(output); +} + +/* Create a new pointer object */ +SWIGRUNTIMEINLINE SEXP +SWIG_R_NewPointerObj(void *ptr, swig_type_info *type, int flags) { + SEXP rptr = PROTECT(R_MakeExternalPtr(ptr, PROTECT(R_MakeExternalPtr(type, R_NilValue, R_NilValue)), R_NilValue)); + SET_S4_OBJECT(rptr); + UNPROTECT(2); + return rptr; +} + + +/* Convert a pointer value */ +SWIGRUNTIMEINLINE int +SWIG_R_ConvertPtr(SEXP obj, void **ptr, swig_type_info *ty, int flags) { + void *vptr; + if (!obj) return SWIG_ERROR; + if (obj == R_NilValue) { + if (ptr) *ptr = NULL; + return SWIG_OK; + } + + vptr = R_ExternalPtrAddr(obj); + if (ty) { + swig_type_info *to = (swig_type_info*) + R_ExternalPtrAddr(R_ExternalPtrTag(obj)); + if (to == ty) { + if (ptr) *ptr = vptr; + } else { + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + int newmemory = 0; + if (ptr) *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } + } else { + if (ptr) *ptr = vptr; + } + return SWIG_OK; +} + +SWIGRUNTIME swig_module_info * +SWIG_GetModule(void *SWIGUNUSEDPARM(clientdata)) { + static void *type_pointer = (void *)0; + return (swig_module_info *) type_pointer; +} + +SWIGRUNTIME void +SWIG_SetModule(void *v, swig_module_info *swig_module) { +} + +typedef struct { + void *pack; + swig_type_info *ty; + size_t size; +} RSwigPacked; + +/* Create a new packed object */ + +SWIGRUNTIMEINLINE SEXP RSwigPacked_New(void *ptr, size_t sz, + swig_type_info *ty) { + SEXP rptr; + RSwigPacked *sobj = + (RSwigPacked*) malloc(sizeof(RSwigPacked)); + if (sobj) { + void *pack = malloc(sz); + if (pack) { + memcpy(pack, ptr, sz); + sobj->pack = pack; + sobj->ty = ty; + sobj->size = sz; + } else { + sobj = 0; + } + } + rptr = R_MakeExternalPtr(sobj, R_NilValue, R_NilValue); + return rptr; +} + +SWIGRUNTIME swig_type_info * +RSwigPacked_UnpackData(SEXP obj, void *ptr, size_t size) +{ + RSwigPacked *sobj = + (RSwigPacked *)R_ExternalPtrAddr(obj); + if (sobj->size != size) return 0; + memcpy(ptr, sobj->pack, size); + return sobj->ty; +} + +SWIGRUNTIMEINLINE SEXP +SWIG_R_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { + return ptr ? RSwigPacked_New((void *) ptr, sz, type) : R_NilValue; +} + +/* Convert a packed value value */ + +SWIGRUNTIME int +SWIG_R_ConvertPacked(SEXP obj, void *ptr, size_t sz, swig_type_info *ty) { + swig_type_info *to = RSwigPacked_UnpackData(obj, ptr, sz); + if (!to) return SWIG_ERROR; + if (ty) { + if (to != ty) { + /* check type cast? */ + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + if (!tc) return SWIG_ERROR; + } + } + return SWIG_OK; +} + +#ifdef __cplusplus +#define SWIG_exception_noreturn(code, msg) do { throw std::runtime_error(msg); } while(0) +#else +#define SWIG_exception_noreturn(code, msg) do { return result; } while(0) +#endif + +#ifdef __cplusplus +} +#endif + + + +#define SWIG_exception_fail(code, msg) do { Rf_warning(msg); return Rf_ScalarLogical(NA_LOGICAL); return Rf_ScalarLogical(NA_LOGICAL); } while(0) + +#define SWIG_contract_assert(expr, msg) if (!(expr)) { Rf_warning(msg); return Rf_ScalarLogical(NA_LOGICAL); return Rf_ScalarLogical(NA_LOGICAL); } else + + + +/* -------- TYPES TABLE (BEGIN) -------- */ + +#define SWIGTYPE_p_char swig_types[0] +#define SWIGTYPE_p_librdf_digest_s swig_types[1] +#define SWIGTYPE_p_librdf_hash_s swig_types[2] +#define SWIGTYPE_p_librdf_iterator_s swig_types[3] +#define SWIGTYPE_p_librdf_log_func swig_types[4] +#define SWIGTYPE_p_librdf_log_message swig_types[5] +#define SWIGTYPE_p_librdf_model_s swig_types[6] +#define SWIGTYPE_p_librdf_node_s swig_types[7] +#define SWIGTYPE_p_librdf_parser_s swig_types[8] +#define SWIGTYPE_p_librdf_query swig_types[9] +#define SWIGTYPE_p_librdf_query_results swig_types[10] +#define SWIGTYPE_p_librdf_serializer_s swig_types[11] +#define SWIGTYPE_p_librdf_statement_s swig_types[12] +#define SWIGTYPE_p_librdf_storage_s swig_types[13] +#define SWIGTYPE_p_librdf_stream_s swig_types[14] +#define SWIGTYPE_p_librdf_uri_s swig_types[15] +#define SWIGTYPE_p_librdf_world_s swig_types[16] +#define SWIGTYPE_p_p_char swig_types[17] +#define SWIGTYPE_p_raptor_locator swig_types[18] +static swig_type_info *swig_types[20]; +static swig_module_info swig_module = {swig_types, 19, 0, 0, 0, 0}; +#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) +#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) + +/* -------- TYPES TABLE (END) -------- */ + + +/* ----------------------------------------------------------------------------- + * This section contains generic SWIG labels for method/variable + * declarations/attributes, and other compiler dependent labels. + * ----------------------------------------------------------------------------- */ + +/* template workaround for compilers that cannot correctly implement the C++ standard */ +#ifndef SWIGTEMPLATEDISAMBIGUATOR +# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) +# define SWIGTEMPLATEDISAMBIGUATOR template +# elif defined(__HP_aCC) +/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ +/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ +# define SWIGTEMPLATEDISAMBIGUATOR template +# else +# define SWIGTEMPLATEDISAMBIGUATOR +# endif +#endif + +/* inline attribute */ +#ifndef SWIGINLINE +# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) +# define SWIGINLINE inline +# else +# define SWIGINLINE +# endif +#endif + +/* attribute recognised by some compilers to avoid 'unused' warnings */ +#ifndef SWIGUNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +# elif defined(__ICC) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +#endif + +#ifndef SWIG_MSC_UNSUPPRESS_4505 +# if defined(_MSC_VER) +# pragma warning(disable : 4505) /* unreferenced local function has been removed */ +# endif +#endif + +#ifndef SWIGUNUSEDPARM +# ifdef __cplusplus +# define SWIGUNUSEDPARM(p) +# else +# define SWIGUNUSEDPARM(p) p SWIGUNUSED +# endif +#endif + +/* internal SWIG method */ +#ifndef SWIGINTERN +# define SWIGINTERN static SWIGUNUSED +#endif + +/* internal inline SWIG method */ +#ifndef SWIGINTERNINLINE +# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE +#endif + +/* exporting methods */ +#if defined(__GNUC__) +# if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +# ifndef GCC_HASCLASSVISIBILITY +# define GCC_HASCLASSVISIBILITY +# endif +# endif +#endif + +#ifndef SWIGEXPORT +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# if defined(STATIC_LINKED) +# define SWIGEXPORT +# else +# define SWIGEXPORT __declspec(dllexport) +# endif +# else +# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) +# define SWIGEXPORT __attribute__ ((visibility("default"))) +# else +# define SWIGEXPORT +# endif +# endif +#endif + +/* calling conventions for Windows */ +#ifndef SWIGSTDCALL +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# define SWIGSTDCALL __stdcall +# else +# define SWIGSTDCALL +# endif +#endif + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ +#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) +# define _SCL_SECURE_NO_DEPRECATE +#endif + +/* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ +#if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) +# define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 +#endif + +/* Intel's compiler complains if a variable which was never initialised is + * cast to void, which is a common idiom which we use to indicate that we + * are aware a variable isn't used. So we just silence that warning. + * See: https://github.com/swig/swig/issues/192 for more discussion. + */ +#ifdef __INTEL_COMPILER +# pragma warning disable 592 +#endif + +/* Errors in SWIG */ +#define SWIG_UnknownError -1 +#define SWIG_IOError -2 +#define SWIG_RuntimeError -3 +#define SWIG_IndexError -4 +#define SWIG_TypeError -5 +#define SWIG_DivisionByZero -6 +#define SWIG_OverflowError -7 +#define SWIG_SyntaxError -8 +#define SWIG_ValueError -9 +#define SWIG_SystemError -10 +#define SWIG_AttributeError -11 +#define SWIG_MemoryError -12 +#define SWIG_NullReferenceError -13 + + + + +#define SWIGVERSION 0x030012 +#define SWIG_VERSION SWIGVERSION + + +#define SWIG_as_voidptr(a) (void *)((const void *)(a)) +#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a)) + + + +/* compile-time include (inside a % ... % block) */ +#ifdef REDLAND_PRE_I +#include +#endif + +#include + +/* + * Thanks to the patch in this Debian bug for the solution + * to the crash inside vsnprintf on some architectures. + * + * "reuse of args inside the while(1) loop is in violation of the + * specs and only happens to work by accident on other systems." + * + * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=104325 + */ + +#ifndef va_copy +#ifdef __va_copy +#define va_copy(dest,src) __va_copy(dest,src) +#else +#define va_copy(dest,src) (dest) = (src) +#endif +#endif + +/* compile-time include (inside a % ... % block) */ +#ifdef REDLAND_POST_I +#include +#endif + +/* Internal prototypes */ +/* FOR TESTING ERRORS ONLY - NOT PART OF API */ +void librdf_internal_test_error(librdf_world *world); +void librdf_internal_test_warning(librdf_world *world); + + +/* prototypes for internal routines called below - NOT PART OF API */ +void librdf_test_error(librdf_world* world, const char* message); +void librdf_test_warning(librdf_world* world, const char* message); + +/* FOR TESTING ERRORS ONLY - NOT PART OF API */ +void +librdf_internal_test_error(librdf_world *world) +{ + librdf_test_error(world, "test error message number 1."); +} + +void +librdf_internal_test_warning(librdf_world *world) +{ + librdf_test_warning(world, "test warning message number 2."); +} + + + +SWIGINTERN char * +SWIG_strdup(const char *str) +{ + char *newstr = (char *)(malloc(strlen(str) + 1)); + return strcpy(newstr, str); +} + + +SWIGINTERN int +SWIG_AsCharPtrAndSize(SEXP obj, char** cptr, size_t* psize, int *alloc) +{ + if (cptr && Rf_isString(obj)) { + char *cstr = (char *)(CHAR(STRING_ELT(obj, 0))); + int len = strlen(cstr); + + if (alloc) { + if (*alloc == SWIG_NEWOBJ) { + *cptr = (char *)memcpy(malloc((len + 1)*sizeof(char)), cstr, sizeof(char)*(len + 1)); + *alloc = SWIG_NEWOBJ; + } else { + *cptr = cstr; + } + } else { + *cptr = (char *)(malloc(len + 1)); + *cptr = strcpy(*cptr, cstr); + } + if (psize) *psize = len + 1; + return SWIG_OK; + } + return SWIG_TypeError; +} + + + + + +#include +#if !defined(SWIG_NO_LLONG_MAX) +# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) +# define LLONG_MAX __LONG_LONG_MAX__ +# define LLONG_MIN (-LLONG_MAX - 1LL) +# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) +# endif +#endif + + +SWIGINTERNINLINE int +SWIG_AsVal_long (SEXP obj, long *val) +{ + if (val) *val = Rf_asInteger(obj); + return SWIG_OK; +} + + +SWIGINTERN int +SWIG_AsVal_int (SEXP obj, int *val) +{ + long v; + int res = SWIG_AsVal_long (obj, &v); + if (SWIG_IsOK(res)) { + if ((v < INT_MIN || v > INT_MAX)) { + return SWIG_OverflowError; + } else { + if (val) *val = (int)(v); + } + } + return res; +} + + +SWIGINTERN SEXP +SWIG_FromCharPtrAndSize(const char* carray, size_t size) +{ + SEXP t, c; + if (!carray) return R_NilValue; +/* See R internals document 1.10. + MkCharLen was introduced in 2.7.0. Use that instead of hand + creating vector. + + Starting in 2.8.0 creating strings via vectors was deprecated in + order to allow for use of CHARSXP caches. */ + + Rf_protect(t = Rf_allocVector(STRSXP, 1)); +#if R_VERSION >= R_Version(2,7,0) + c = Rf_mkCharLen(carray, size); +#else + c = Rf_allocVector(CHARSXP, size); + strncpy((char *)CHAR(c), carray, size); +#endif + SET_STRING_ELT(t, 0, c); + Rf_unprotect(1); + return t; +} + + +SWIGINTERNINLINE SEXP +SWIG_FromCharPtr(const char *cptr) +{ + return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); +} + + +SWIGINTERNINLINE SEXP +SWIG_From_unsigned_SS_long (unsigned long value) +{ + return Rf_ScalarInteger((int)value); +} + + +SWIGINTERNINLINE SEXP +SWIG_From_unsigned_SS_int (unsigned int value) +{ + return SWIG_From_unsigned_SS_long (value); +} + + +#ifdef __cplusplus +extern "C" { +#endif + +SWIGEXPORT SEXP +R_swig_librdf_new_digest ( SEXP world, SEXP name) +{ + librdf_digest *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_digest" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + arg2 = (char *)(SWIG_strdup(CHAR(STRING_ELT(name, 0)))); + result = (librdf_digest *)librdf_new_digest(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_digest_s, R_SWIG_OWNER | 0 ); + + free(arg2); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_digest ( SEXP digest) +{ + librdf_digest *arg1 = (librdf_digest *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(digest, &argp1, SWIGTYPE_p_librdf_digest_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_digest" "', argument " "1"" of type '" "librdf_digest *""'"); + } + arg1 = (librdf_digest *)(argp1); + librdf_free_digest(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_digest_init ( SEXP digest) +{ + librdf_digest *arg1 = (librdf_digest *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(digest, &argp1, SWIGTYPE_p_librdf_digest_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_digest_init" "', argument " "1"" of type '" "librdf_digest *""'"); + } + arg1 = (librdf_digest *)(argp1); + librdf_digest_init(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_digest_update ( SEXP digest, SEXP buf, SEXP length) +{ + librdf_digest *arg1 = (librdf_digest *) 0 ; + char *arg2 = (char *) 0 ; + size_t arg3 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int val3 ; + int ecode3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(digest, &argp1, SWIGTYPE_p_librdf_digest_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_digest_update" "', argument " "1"" of type '" "librdf_digest *""'"); + } + arg1 = (librdf_digest *)(argp1); + res2 = SWIG_AsCharPtrAndSize(buf, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_digest_update" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + ecode3 = SWIG_AsVal_int(length, &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "librdf_digest_update" "', argument " "3"" of type '" "size_t""'"); + } + arg3 = (size_t)(val3); + librdf_digest_update(arg1,(char const *)arg2,arg3); + r_ans = R_NilValue; + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_digest_update_string ( SEXP digest, SEXP string) +{ + librdf_digest *arg1 = (librdf_digest *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(digest, &argp1, SWIGTYPE_p_librdf_digest_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_digest_update_string" "', argument " "1"" of type '" "librdf_digest *""'"); + } + arg1 = (librdf_digest *)(argp1); + res2 = SWIG_AsCharPtrAndSize(string, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_digest_update_string" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + librdf_digest_update_string(arg1,(char const *)arg2); + r_ans = R_NilValue; + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_digest_final ( SEXP digest) +{ + librdf_digest *arg1 = (librdf_digest *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(digest, &argp1, SWIGTYPE_p_librdf_digest_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_digest_final" "', argument " "1"" of type '" "librdf_digest *""'"); + } + arg1 = (librdf_digest *)(argp1); + librdf_digest_final(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_digest_to_string ( SEXP digest) +{ + char *result = 0 ; + librdf_digest *arg1 = (librdf_digest *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(digest, &argp1, SWIGTYPE_p_librdf_digest_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_digest_to_string" "', argument " "1"" of type '" "librdf_digest *""'"); + } + arg1 = (librdf_digest *)(argp1); + result = (char *)librdf_digest_to_string(arg1); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + free((char*)result); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_hash ( SEXP world, SEXP name) +{ + librdf_hash *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_hash" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_hash" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (librdf_hash *)librdf_new_hash(arg1,(char const *)arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_hash_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_hash_from_string ( SEXP world, SEXP name, SEXP string) +{ + librdf_hash *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_hash_from_string" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_hash_from_string" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_AsCharPtrAndSize(string, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_new_hash_from_string" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + result = (librdf_hash *)librdf_new_hash_from_string(arg1,(char const *)arg2,(char const *)arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_hash_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_hash_from_array_of_strings ( SEXP world, SEXP name, SEXP string) +{ + librdf_hash *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + char **arg3 = (char **) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_hash_from_array_of_strings" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_hash_from_array_of_strings" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_R_ConvertPtr(string, &argp3, SWIGTYPE_p_p_char, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_new_hash_from_array_of_strings" "', argument " "3"" of type '" "char const **""'"); + } + arg3 = (char **)(argp3); + result = (librdf_hash *)librdf_new_hash_from_array_of_strings(arg1,(char const *)arg2,(char const **)arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_hash_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_hash_to_string ( SEXP hash, SEXP filter) +{ + char *result = 0 ; + librdf_hash *arg1 = (librdf_hash *) 0 ; + char **arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(hash, &argp1, SWIGTYPE_p_librdf_hash_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_hash_to_string" "', argument " "1"" of type '" "librdf_hash *""'"); + } + arg1 = (librdf_hash *)(argp1); + arg2 = (char **)(SWIG_strdup(CHAR(STRING_ELT(filter, 0)))); + result = (char *)librdf_hash_to_string(arg1,(char const *(*))arg2); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + free(arg2); + free((char*)result); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_hash ( SEXP hash) +{ + librdf_hash *arg1 = (librdf_hash *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(hash, &argp1, SWIGTYPE_p_librdf_hash_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_hash" "', argument " "1"" of type '" "librdf_hash *""'"); + } + arg1 = (librdf_hash *)(argp1); + librdf_free_hash(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_world ( ) +{ + librdf_world *result = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (librdf_world *)librdf_new_world(); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_world_s, R_SWIG_OWNER | 0 ); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_world ( SEXP world) +{ + librdf_world *arg1 = (librdf_world *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_world" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + librdf_free_world(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_world_open ( SEXP world) +{ + librdf_world *arg1 = (librdf_world *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_world_open" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + librdf_world_open(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_world_get_feature ( SEXP world, SEXP feature) +{ + librdf_node *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_world_get_feature" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_R_ConvertPtr(feature, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_world_get_feature" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + result = (librdf_node *)librdf_world_get_feature(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_world_set_feature ( SEXP world, SEXP feature, SEXP value, SEXP s_swig_copy) +{ + int result; + librdf_world *arg1 = (librdf_world *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_world_set_feature" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_R_ConvertPtr(feature, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_world_set_feature" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_R_ConvertPtr(value, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_world_set_feature" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (int)librdf_world_set_feature(arg1,arg2,arg3); + r_ans = Rf_ScalarInteger(result); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_get_accept_header ( SEXP parser) +{ + char *result = 0 ; + librdf_parser *arg1 = (librdf_parser *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_get_accept_header" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + result = (char *)librdf_parser_get_accept_header(arg1); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + free((char*)result); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_world_set_logger ( SEXP world, SEXP user_data, SEXP log_handler) +{ + librdf_world *arg1 = (librdf_world *) 0 ; + void *arg2 = (void *) 0 ; + librdf_log_func arg3 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + void *argp3 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_world_set_logger" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_R_ConvertPtr(user_data, SWIG_as_voidptrptr(&arg2), 0, 0); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_world_set_logger" "', argument " "2"" of type '" "void *""'"); + } + { + res3 = SWIG_R_ConvertPtr(log_handler, &argp3, SWIGTYPE_p_librdf_log_func, 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_world_set_logger" "', argument " "3"" of type '" "librdf_log_func""'"); + } + if (!argp3) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "librdf_world_set_logger" "', argument " "3"" of type '" "librdf_log_func""'"); + } else { + arg3 = *((librdf_log_func *)(argp3)); + } + } + librdf_world_set_logger(arg1,arg2,arg3); + r_ans = R_NilValue; + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_iterator ( SEXP s_arg1) +{ + librdf_iterator *arg1 = (librdf_iterator *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(s_arg1, &argp1, SWIGTYPE_p_librdf_iterator_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_iterator" "', argument " "1"" of type '" "librdf_iterator *""'"); + } + arg1 = (librdf_iterator *)(argp1); + librdf_free_iterator(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_iterator_end ( SEXP iterator, SEXP s_swig_copy) +{ + int result; + librdf_iterator *arg1 = (librdf_iterator *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(iterator, &argp1, SWIGTYPE_p_librdf_iterator_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_iterator_end" "', argument " "1"" of type '" "librdf_iterator *""'"); + } + arg1 = (librdf_iterator *)(argp1); + result = (int)librdf_iterator_end(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_iterator_get_object ( SEXP iterator) +{ + librdf_node *result = 0 ; + librdf_iterator *arg1 = (librdf_iterator *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(iterator, &argp1, SWIGTYPE_p_librdf_iterator_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_iterator_get_object" "', argument " "1"" of type '" "librdf_iterator *""'"); + } + arg1 = (librdf_iterator *)(argp1); + result = (librdf_node *)librdf_iterator_get_object(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_EXTERNAL | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_iterator_get_context ( SEXP iterator) +{ + librdf_node *result = 0 ; + librdf_iterator *arg1 = (librdf_iterator *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(iterator, &argp1, SWIGTYPE_p_librdf_iterator_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_iterator_get_context" "', argument " "1"" of type '" "librdf_iterator *""'"); + } + arg1 = (librdf_iterator *)(argp1); + result = (librdf_node *)librdf_iterator_get_context(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_EXTERNAL | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_iterator_next ( SEXP iterator, SEXP s_swig_copy) +{ + int result; + librdf_iterator *arg1 = (librdf_iterator *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(iterator, &argp1, SWIGTYPE_p_librdf_iterator_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_iterator_next" "', argument " "1"" of type '" "librdf_iterator *""'"); + } + arg1 = (librdf_iterator *)(argp1); + result = (int)librdf_iterator_next(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_uri ( SEXP world, SEXP string) +{ + librdf_uri *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_uri" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + arg2 = (char *)(SWIG_strdup(CHAR(STRING_ELT(string, 0)))); + result = (librdf_uri *)librdf_new_uri(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_uri_s, R_SWIG_OWNER | 0 ); + + free(arg2); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_uri_from_uri ( SEXP uri) +{ + librdf_uri *result = 0 ; + librdf_uri *arg1 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(uri, &argp1, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_uri_from_uri" "', argument " "1"" of type '" "librdf_uri *""'"); + } + arg1 = (librdf_uri *)(argp1); + result = (librdf_uri *)librdf_new_uri_from_uri(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_uri_s, R_SWIG_OWNER | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_uri_from_filename ( SEXP world, SEXP filename) +{ + librdf_uri *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_uri_from_filename" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(filename, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_uri_from_filename" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (librdf_uri *)librdf_new_uri_from_filename(arg1,(char const *)arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_uri_s, R_SWIG_EXTERNAL | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_uri ( SEXP uri) +{ + librdf_uri *arg1 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(uri, &argp1, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_uri" "', argument " "1"" of type '" "librdf_uri *""'"); + } + arg1 = (librdf_uri *)(argp1); + librdf_free_uri(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_uri_to_string ( SEXP uri) +{ + char *result = 0 ; + librdf_uri *arg1 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(uri, &argp1, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_uri_to_string" "', argument " "1"" of type '" "librdf_uri *""'"); + } + arg1 = (librdf_uri *)(argp1); + result = (char *)librdf_uri_to_string(arg1); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + free((char*)result); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_uri_equals ( SEXP first_uri, SEXP second_uri, SEXP s_swig_copy) +{ + int result; + librdf_uri *arg1 = (librdf_uri *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(first_uri, &argp1, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_uri_equals" "', argument " "1"" of type '" "librdf_uri *""'"); + } + arg1 = (librdf_uri *)(argp1); + res2 = SWIG_R_ConvertPtr(second_uri, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_uri_equals" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + result = (int)librdf_uri_equals(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_uri_compare ( SEXP first_uri, SEXP second_uri, SEXP s_swig_copy) +{ + int result; + librdf_uri *arg1 = (librdf_uri *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(first_uri, &argp1, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_uri_compare" "', argument " "1"" of type '" "librdf_uri *""'"); + } + arg1 = (librdf_uri *)(argp1); + res2 = SWIG_R_ConvertPtr(second_uri, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_uri_compare" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + result = (int)librdf_uri_compare(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_node ( SEXP world) +{ + librdf_node *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_node" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + result = (librdf_node *)librdf_new_node(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_node_from_uri_string ( SEXP world, SEXP string) +{ + librdf_node *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_node_from_uri_string" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(string, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_node_from_uri_string" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (librdf_node *)librdf_new_node_from_uri_string(arg1,(char const *)arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_node_from_uri ( SEXP world, SEXP uri) +{ + librdf_node *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_node_from_uri" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_R_ConvertPtr(uri, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_node_from_uri" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + result = (librdf_node *)librdf_new_node_from_uri(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_node_from_uri_local_name ( SEXP world, SEXP uri, SEXP local_name) +{ + librdf_node *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + char *arg3 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_node_from_uri_local_name" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_R_ConvertPtr(uri, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_node_from_uri_local_name" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_AsCharPtrAndSize(local_name, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_new_node_from_uri_local_name" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + result = (librdf_node *)librdf_new_node_from_uri_local_name(arg1,arg2,(char const *)arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_node_from_normalised_uri_string ( SEXP world, SEXP uri_string, SEXP source_uri, SEXP base_uri) +{ + librdf_node *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + librdf_uri *arg3 = (librdf_uri *) 0 ; + librdf_uri *arg4 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_node_from_normalised_uri_string" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(uri_string, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_node_from_normalised_uri_string" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_R_ConvertPtr(source_uri, &argp3, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_new_node_from_normalised_uri_string" "', argument " "3"" of type '" "librdf_uri *""'"); + } + arg3 = (librdf_uri *)(argp3); + res4 = SWIG_R_ConvertPtr(base_uri, &argp4, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_new_node_from_normalised_uri_string" "', argument " "4"" of type '" "librdf_uri *""'"); + } + arg4 = (librdf_uri *)(argp4); + result = (librdf_node *)librdf_new_node_from_normalised_uri_string(arg1,(char const *)arg2,arg3,arg4); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_node_from_literal ( SEXP world, SEXP string, SEXP inStrOrNull, SEXP is_wf_xml) +{ + librdf_node *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) NULL ; + int arg4 = (int) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_node_from_literal" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(string, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_node_from_literal" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_AsCharPtrAndSize(inStrOrNull, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_new_node_from_literal" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + arg4 = (int)(INTEGER(is_wf_xml)[0]); + result = (librdf_node *)librdf_new_node_from_literal(arg1,(char const *)arg2,(char const *)arg3,arg4); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_node_from_typed_literal ( SEXP world, SEXP string, SEXP inStrOrNull, SEXP inUriOrNull) +{ + librdf_node *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) NULL ; + librdf_uri *arg4 = (librdf_uri *) NULL ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_node_from_typed_literal" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(string, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_node_from_typed_literal" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_AsCharPtrAndSize(inStrOrNull, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_new_node_from_typed_literal" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + res4 = SWIG_R_ConvertPtr(inUriOrNull, &argp4, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_new_node_from_typed_literal" "', argument " "4"" of type '" "librdf_uri *""'"); + } + arg4 = (librdf_uri *)(argp4); + result = (librdf_node *)librdf_new_node_from_typed_literal(arg1,(char const *)arg2,(char const *)arg3,arg4); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_node_from_node ( SEXP node) +{ + librdf_node *result = 0 ; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_node_from_node" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (librdf_node *)librdf_new_node_from_node(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_node_from_blank_identifier ( SEXP world, SEXP inStrOrNull) +{ + librdf_node *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) NULL ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_node_from_blank_identifier" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(inStrOrNull, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_node_from_blank_identifier" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (librdf_node *)librdf_new_node_from_blank_identifier(arg1,(char const *)arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_node ( SEXP r) +{ + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(r, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_node" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + librdf_free_node(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_get_uri ( SEXP node) +{ + librdf_uri *result = 0 ; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_get_uri" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (librdf_uri *)librdf_node_get_uri(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_uri_s, R_SWIG_EXTERNAL | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_get_type ( SEXP node, SEXP s_swig_copy) +{ + int result; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_get_type" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (int)librdf_node_get_type(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_get_literal_value ( SEXP node) +{ + char *result = 0 ; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_get_literal_value" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (char *)librdf_node_get_literal_value(arg1); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_get_literal_value_as_latin1 ( SEXP node) +{ + char *result = 0 ; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_get_literal_value_as_latin1" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (char *)librdf_node_get_literal_value_as_latin1(arg1); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_get_literal_value_language ( SEXP node) +{ + char *result = 0 ; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_get_literal_value_language" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (char *)librdf_node_get_literal_value_language(arg1); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_get_literal_value_datatype_uri ( SEXP node) +{ + librdf_uri *result = 0 ; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_get_literal_value_datatype_uri" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (librdf_uri *)librdf_node_get_literal_value_datatype_uri(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_uri_s, R_SWIG_EXTERNAL | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_get_literal_value_is_wf_xml ( SEXP node, SEXP s_swig_copy) +{ + int result; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_get_literal_value_is_wf_xml" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (int)librdf_node_get_literal_value_is_wf_xml(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_get_li_ordinal ( SEXP node, SEXP s_swig_copy) +{ + int result; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_get_li_ordinal" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (int)librdf_node_get_li_ordinal(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_get_blank_identifier ( SEXP node) +{ + char *result = 0 ; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_get_blank_identifier" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (char *)librdf_node_get_blank_identifier(arg1); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_is_resource ( SEXP node, SEXP s_swig_copy) +{ + int result; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_is_resource" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (int)librdf_node_is_resource(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_is_literal ( SEXP node, SEXP s_swig_copy) +{ + int result; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_is_literal" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (int)librdf_node_is_literal(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_is_blank ( SEXP node, SEXP s_swig_copy) +{ + int result; + librdf_node *arg1 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_is_blank" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + result = (int)librdf_node_is_blank(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_node_equals ( SEXP first_node, SEXP second_node, SEXP s_swig_copy) +{ + int result; + librdf_node *arg1 = (librdf_node *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(first_node, &argp1, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_node_equals" "', argument " "1"" of type '" "librdf_node *""'"); + } + arg1 = (librdf_node *)(argp1); + res2 = SWIG_R_ConvertPtr(second_node, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_node_equals" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + result = (int)librdf_node_equals(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_statement ( SEXP world) +{ + librdf_statement *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_statement" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + result = (librdf_statement *)librdf_new_statement(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_statement_s, R_SWIG_OWNER | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_statement_from_statement ( SEXP statement) +{ + librdf_statement *result = 0 ; + librdf_statement *arg1 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(statement, &argp1, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_statement_from_statement" "', argument " "1"" of type '" "librdf_statement *""'"); + } + arg1 = (librdf_statement *)(argp1); + result = (librdf_statement *)librdf_new_statement_from_statement(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_statement_s, R_SWIG_OWNER | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_statement_from_nodes ( SEXP world, SEXP subject, SEXP predicate, SEXP object) +{ + librdf_statement *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + librdf_node *arg4 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_statement_from_nodes" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_R_ConvertPtr(subject, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_statement_from_nodes" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(predicate, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_new_statement_from_nodes" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + res4 = SWIG_R_ConvertPtr(object, &argp4, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_new_statement_from_nodes" "', argument " "4"" of type '" "librdf_node *""'"); + } + arg4 = (librdf_node *)(argp4); + result = (librdf_statement *)librdf_new_statement_from_nodes(arg1,arg2,arg3,arg4); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_statement_s, R_SWIG_OWNER | 0 ); + + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_statement ( SEXP statement) +{ + librdf_statement *arg1 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(statement, &argp1, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_statement" "', argument " "1"" of type '" "librdf_statement *""'"); + } + arg1 = (librdf_statement *)(argp1); + librdf_free_statement(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_statement_get_subject ( SEXP statement) +{ + librdf_node *result = 0 ; + librdf_statement *arg1 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(statement, &argp1, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_statement_get_subject" "', argument " "1"" of type '" "librdf_statement *""'"); + } + arg1 = (librdf_statement *)(argp1); + result = (librdf_node *)librdf_statement_get_subject(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_EXTERNAL | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_statement_set_subject ( SEXP statement, SEXP subject) +{ + librdf_statement *arg1 = (librdf_statement *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(statement, &argp1, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_statement_set_subject" "', argument " "1"" of type '" "librdf_statement *""'"); + } + arg1 = (librdf_statement *)(argp1); + res2 = SWIG_R_ConvertPtr(subject, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_statement_set_subject" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + librdf_statement_set_subject(arg1,arg2); + r_ans = R_NilValue; + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_statement_get_predicate ( SEXP statement) +{ + librdf_node *result = 0 ; + librdf_statement *arg1 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(statement, &argp1, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_statement_get_predicate" "', argument " "1"" of type '" "librdf_statement *""'"); + } + arg1 = (librdf_statement *)(argp1); + result = (librdf_node *)librdf_statement_get_predicate(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_EXTERNAL | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_statement_set_predicate ( SEXP statement, SEXP predicate) +{ + librdf_statement *arg1 = (librdf_statement *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(statement, &argp1, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_statement_set_predicate" "', argument " "1"" of type '" "librdf_statement *""'"); + } + arg1 = (librdf_statement *)(argp1); + res2 = SWIG_R_ConvertPtr(predicate, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_statement_set_predicate" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + librdf_statement_set_predicate(arg1,arg2); + r_ans = R_NilValue; + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_statement_get_object ( SEXP statement) +{ + librdf_node *result = 0 ; + librdf_statement *arg1 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(statement, &argp1, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_statement_get_object" "', argument " "1"" of type '" "librdf_statement *""'"); + } + arg1 = (librdf_statement *)(argp1); + result = (librdf_node *)librdf_statement_get_object(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_EXTERNAL | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_statement_set_object ( SEXP statement, SEXP object) +{ + librdf_statement *arg1 = (librdf_statement *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(statement, &argp1, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_statement_set_object" "', argument " "1"" of type '" "librdf_statement *""'"); + } + arg1 = (librdf_statement *)(argp1); + res2 = SWIG_R_ConvertPtr(object, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_statement_set_object" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + librdf_statement_set_object(arg1,arg2); + r_ans = R_NilValue; + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_statement_equals ( SEXP statement1, SEXP statement2, SEXP s_swig_copy) +{ + int result; + librdf_statement *arg1 = (librdf_statement *) 0 ; + librdf_statement *arg2 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(statement1, &argp1, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_statement_equals" "', argument " "1"" of type '" "librdf_statement *""'"); + } + arg1 = (librdf_statement *)(argp1); + res2 = SWIG_R_ConvertPtr(statement2, &argp2, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_statement_equals" "', argument " "2"" of type '" "librdf_statement *""'"); + } + arg2 = (librdf_statement *)(argp2); + result = (int)librdf_statement_equals(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_statement_match ( SEXP statement, SEXP partial_statement, SEXP s_swig_copy) +{ + int result; + librdf_statement *arg1 = (librdf_statement *) 0 ; + librdf_statement *arg2 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(statement, &argp1, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_statement_match" "', argument " "1"" of type '" "librdf_statement *""'"); + } + arg1 = (librdf_statement *)(argp1); + res2 = SWIG_R_ConvertPtr(partial_statement, &argp2, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_statement_match" "', argument " "2"" of type '" "librdf_statement *""'"); + } + arg2 = (librdf_statement *)(argp2); + result = (int)librdf_statement_match(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_statement_is_complete ( SEXP statement, SEXP s_swig_copy) +{ + int result; + librdf_statement *arg1 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(statement, &argp1, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_statement_is_complete" "', argument " "1"" of type '" "librdf_statement *""'"); + } + arg1 = (librdf_statement *)(argp1); + result = (int)librdf_statement_is_complete(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_model ( SEXP world, SEXP storage, SEXP options_string) +{ + librdf_model *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + librdf_storage *arg2 = (librdf_storage *) 0 ; + char *arg3 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_model" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_R_ConvertPtr(storage, &argp2, SWIGTYPE_p_librdf_storage_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_model" "', argument " "2"" of type '" "librdf_storage *""'"); + } + arg2 = (librdf_storage *)(argp2); + arg3 = (char *)(SWIG_strdup(CHAR(STRING_ELT(options_string, 0)))); + result = (librdf_model *)librdf_new_model(arg1,arg2,arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_model_s, R_SWIG_OWNER | 0 ); + + + free(arg3); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_model_with_options ( SEXP world, SEXP storage, SEXP options) +{ + librdf_model *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + librdf_storage *arg2 = (librdf_storage *) 0 ; + librdf_hash *arg3 = (librdf_hash *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_model_with_options" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_R_ConvertPtr(storage, &argp2, SWIGTYPE_p_librdf_storage_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_model_with_options" "', argument " "2"" of type '" "librdf_storage *""'"); + } + arg2 = (librdf_storage *)(argp2); + res3 = SWIG_R_ConvertPtr(options, &argp3, SWIGTYPE_p_librdf_hash_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_new_model_with_options" "', argument " "3"" of type '" "librdf_hash *""'"); + } + arg3 = (librdf_hash *)(argp3); + result = (librdf_model *)librdf_new_model_with_options(arg1,arg2,arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_model_s, R_SWIG_OWNER | 0 ); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_model_from_model ( SEXP model) +{ + librdf_model *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_model_from_model" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + result = (librdf_model *)librdf_new_model_from_model(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_model_s, R_SWIG_OWNER | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_model ( SEXP model) +{ + librdf_model *arg1 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_model" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + librdf_free_model(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_size ( SEXP model, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_size" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + result = (int)librdf_model_size(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_add ( SEXP model, SEXP subject, SEXP predicate, SEXP object, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + librdf_node *arg4 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_add" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(subject, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_add" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(predicate, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_add" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + res4 = SWIG_R_ConvertPtr(object, &argp4, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_model_add" "', argument " "4"" of type '" "librdf_node *""'"); + } + arg4 = (librdf_node *)(argp4); + result = (int)librdf_model_add(arg1,arg2,arg3,arg4); + r_ans = Rf_ScalarInteger(result); + + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_add_string_literal_statement ( SEXP model, SEXP subject, SEXP predicate, SEXP literal, SEXP inStrOrNull, SEXP is_wf_xml, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + char *arg4 = (char *) 0 ; + char *arg5 = (char *) NULL ; + int arg6 = (int) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + int res4 ; + char *buf4 = 0 ; + int alloc4 = 0 ; + int res5 ; + char *buf5 = 0 ; + int alloc5 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_add_string_literal_statement" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(subject, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_add_string_literal_statement" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(predicate, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_add_string_literal_statement" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + res4 = SWIG_AsCharPtrAndSize(literal, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_model_add_string_literal_statement" "', argument " "4"" of type '" "char const *""'"); + } + arg4 = (char *)(buf4); + res5 = SWIG_AsCharPtrAndSize(inStrOrNull, &buf5, NULL, &alloc5); + if (!SWIG_IsOK(res5)) { + SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "librdf_model_add_string_literal_statement" "', argument " "5"" of type '" "char const *""'"); + } + arg5 = (char *)(buf5); + arg6 = (int)(INTEGER(is_wf_xml)[0]); + result = (int)librdf_model_add_string_literal_statement(arg1,arg2,arg3,(char const *)arg4,(char const *)arg5,arg6); + r_ans = Rf_ScalarInteger(result); + + + + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); + if (alloc5 == SWIG_NEWOBJ) free((char*)buf5); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_add_typed_literal_statement ( SEXP model, SEXP subject, SEXP predicate, SEXP string, SEXP inStrOrNull, SEXP inUriOrNull, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + char *arg4 = (char *) 0 ; + char *arg5 = (char *) 0 ; + librdf_uri *arg6 = (librdf_uri *) NULL ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + void *argp6 = 0 ; + int res6 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_add_typed_literal_statement" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(subject, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_add_typed_literal_statement" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(predicate, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_add_typed_literal_statement" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + arg4 = (char *)(SWIG_strdup(CHAR(STRING_ELT(string, 0)))); + arg5 = (char *)(SWIG_strdup(CHAR(STRING_ELT(inStrOrNull, 0)))); + res6 = SWIG_R_ConvertPtr(inUriOrNull, &argp6, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res6)) { + SWIG_exception_fail(SWIG_ArgError(res6), "in method '" "librdf_model_add_typed_literal_statement" "', argument " "6"" of type '" "librdf_uri *""'"); + } + arg6 = (librdf_uri *)(argp6); + result = (int)librdf_model_add_typed_literal_statement(arg1,arg2,arg3,arg4,arg5,arg6); + r_ans = Rf_ScalarInteger(result); + + + + free(arg4); + free(arg5); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_add_statement ( SEXP model, SEXP statement, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_statement *arg2 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_add_statement" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(statement, &argp2, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_add_statement" "', argument " "2"" of type '" "librdf_statement *""'"); + } + arg2 = (librdf_statement *)(argp2); + result = (int)librdf_model_add_statement(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_add_statements ( SEXP model, SEXP statement_stream, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_stream *arg2 = (librdf_stream *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_add_statements" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(statement_stream, &argp2, SWIGTYPE_p_librdf_stream_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_add_statements" "', argument " "2"" of type '" "librdf_stream *""'"); + } + arg2 = (librdf_stream *)(argp2); + result = (int)librdf_model_add_statements(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_remove_statement ( SEXP model, SEXP statement, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_statement *arg2 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_remove_statement" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(statement, &argp2, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_remove_statement" "', argument " "2"" of type '" "librdf_statement *""'"); + } + arg2 = (librdf_statement *)(argp2); + result = (int)librdf_model_remove_statement(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_contains_statement ( SEXP model, SEXP statement, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_statement *arg2 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_contains_statement" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(statement, &argp2, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_contains_statement" "', argument " "2"" of type '" "librdf_statement *""'"); + } + arg2 = (librdf_statement *)(argp2); + result = (int)librdf_model_contains_statement(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_as_stream ( SEXP model) +{ + librdf_stream *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_as_stream" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + result = (librdf_stream *)librdf_model_as_stream(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_stream_s, R_SWIG_OWNER | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_find_statements ( SEXP model, SEXP statement) +{ + librdf_stream *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_statement *arg2 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_find_statements" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(statement, &argp2, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_find_statements" "', argument " "2"" of type '" "librdf_statement *""'"); + } + arg2 = (librdf_statement *)(argp2); + result = (librdf_stream *)librdf_model_find_statements(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_stream_s, R_SWIG_OWNER | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_find_statements_in_context ( SEXP model, SEXP statement, SEXP inNodeOrNull) +{ + librdf_stream *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_statement *arg2 = (librdf_statement *) 0 ; + librdf_node *arg3 = (librdf_node *) NULL ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_find_statements_in_context" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(statement, &argp2, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_find_statements_in_context" "', argument " "2"" of type '" "librdf_statement *""'"); + } + arg2 = (librdf_statement *)(argp2); + res3 = SWIG_R_ConvertPtr(inNodeOrNull, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_find_statements_in_context" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (librdf_stream *)librdf_model_find_statements_in_context(arg1,arg2,arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_stream_s, R_SWIG_OWNER | 0 ); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_get_sources ( SEXP model, SEXP arc, SEXP target) +{ + librdf_iterator *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_get_sources" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(arc, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_get_sources" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(target, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_get_sources" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (librdf_iterator *)librdf_model_get_sources(arg1,arg2,arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_iterator_s, R_SWIG_OWNER | 0 ); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_get_arcs ( SEXP model, SEXP source, SEXP target) +{ + librdf_iterator *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_get_arcs" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(source, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_get_arcs" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(target, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_get_arcs" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (librdf_iterator *)librdf_model_get_arcs(arg1,arg2,arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_iterator_s, R_SWIG_OWNER | 0 ); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_get_targets ( SEXP model, SEXP source, SEXP arc) +{ + librdf_iterator *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_get_targets" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(source, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_get_targets" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(arc, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_get_targets" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (librdf_iterator *)librdf_model_get_targets(arg1,arg2,arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_iterator_s, R_SWIG_OWNER | 0 ); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_get_source ( SEXP model, SEXP arc, SEXP target) +{ + librdf_node *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_get_source" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(arc, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_get_source" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(target, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_get_source" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (librdf_node *)librdf_model_get_source(arg1,arg2,arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_get_arc ( SEXP model, SEXP source, SEXP target) +{ + librdf_node *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_get_arc" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(source, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_get_arc" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(target, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_get_arc" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (librdf_node *)librdf_model_get_arc(arg1,arg2,arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_get_arcs_out ( SEXP model, SEXP node) +{ + librdf_iterator *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_get_arcs_out" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(node, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_get_arcs_out" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + result = (librdf_iterator *)librdf_model_get_arcs_out(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_iterator_s, R_SWIG_OWNER | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_get_arcs_in ( SEXP model, SEXP node) +{ + librdf_iterator *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_get_arcs_in" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(node, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_get_arcs_in" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + result = (librdf_iterator *)librdf_model_get_arcs_in(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_iterator_s, R_SWIG_OWNER | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_has_arc_in ( SEXP model, SEXP node, SEXP property, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_has_arc_in" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(node, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_has_arc_in" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(property, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_has_arc_in" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (int)librdf_model_has_arc_in(arg1,arg2,arg3); + r_ans = Rf_ScalarInteger(result); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_has_arc_out ( SEXP model, SEXP node, SEXP property, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_has_arc_out" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(node, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_has_arc_out" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(property, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_has_arc_out" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (int)librdf_model_has_arc_out(arg1,arg2,arg3); + r_ans = Rf_ScalarInteger(result); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_get_target ( SEXP model, SEXP source, SEXP arc) +{ + librdf_node *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_get_target" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(source, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_get_target" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(arc, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_get_target" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (librdf_node *)librdf_model_get_target(arg1,arg2,arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_context_add_statement ( SEXP model, SEXP context, SEXP statement, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_statement *arg3 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_context_add_statement" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(context, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_context_add_statement" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(statement, &argp3, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_context_add_statement" "', argument " "3"" of type '" "librdf_statement *""'"); + } + arg3 = (librdf_statement *)(argp3); + result = (int)librdf_model_context_add_statement(arg1,arg2,arg3); + r_ans = Rf_ScalarInteger(result); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_context_add_statements ( SEXP model, SEXP context, SEXP stream, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_stream *arg3 = (librdf_stream *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_context_add_statements" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(context, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_context_add_statements" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(stream, &argp3, SWIGTYPE_p_librdf_stream_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_context_add_statements" "', argument " "3"" of type '" "librdf_stream *""'"); + } + arg3 = (librdf_stream *)(argp3); + result = (int)librdf_model_context_add_statements(arg1,arg2,arg3); + r_ans = Rf_ScalarInteger(result); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_context_remove_statement ( SEXP model, SEXP context, SEXP statement, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + librdf_statement *arg3 = (librdf_statement *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_context_remove_statement" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(context, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_context_remove_statement" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + res3 = SWIG_R_ConvertPtr(statement, &argp3, SWIGTYPE_p_librdf_statement_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_context_remove_statement" "', argument " "3"" of type '" "librdf_statement *""'"); + } + arg3 = (librdf_statement *)(argp3); + result = (int)librdf_model_context_remove_statement(arg1,arg2,arg3); + r_ans = Rf_ScalarInteger(result); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_context_remove_statements ( SEXP model, SEXP context, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_context_remove_statements" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(context, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_context_remove_statements" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + result = (int)librdf_model_context_remove_statements(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_context_as_stream ( SEXP model, SEXP context) +{ + librdf_stream *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_context_as_stream" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(context, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_context_as_stream" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + result = (librdf_stream *)librdf_model_context_as_stream(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_stream_s, R_SWIG_OWNER | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_sync ( SEXP model) +{ + librdf_model *arg1 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_sync" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + librdf_model_sync(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_get_contexts ( SEXP model) +{ + librdf_iterator *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_get_contexts" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + result = (librdf_iterator *)librdf_model_get_contexts(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_iterator_s, R_SWIG_OWNER | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_contains_context ( SEXP model, SEXP context, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_node *arg2 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_contains_context" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(context, &argp2, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_contains_context" "', argument " "2"" of type '" "librdf_node *""'"); + } + arg2 = (librdf_node *)(argp2); + result = (int)librdf_model_contains_context(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_get_feature ( SEXP model, SEXP feature) +{ + librdf_node *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_get_feature" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(feature, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_get_feature" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + result = (librdf_node *)librdf_model_get_feature(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_set_feature ( SEXP model, SEXP feature, SEXP value, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_set_feature" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(feature, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_set_feature" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_R_ConvertPtr(value, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_set_feature" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (int)librdf_model_set_feature(arg1,arg2,arg3); + r_ans = Rf_ScalarInteger(result); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_load ( SEXP model, SEXP uri, SEXP name, SEXP mime_type, SEXP type_uri, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + char *arg3 = (char *) NULL ; + char *arg4 = (char *) NULL ; + librdf_uri *arg5 = (librdf_uri *) NULL ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + int res4 ; + char *buf4 = 0 ; + int alloc4 = 0 ; + void *argp5 = 0 ; + int res5 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_load" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(uri, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_load" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_AsCharPtrAndSize(name, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_load" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + res4 = SWIG_AsCharPtrAndSize(mime_type, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_model_load" "', argument " "4"" of type '" "char const *""'"); + } + arg4 = (char *)(buf4); + res5 = SWIG_R_ConvertPtr(type_uri, &argp5, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res5)) { + SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "librdf_model_load" "', argument " "5"" of type '" "librdf_uri *""'"); + } + arg5 = (librdf_uri *)(argp5); + result = (int)librdf_model_load(arg1,arg2,(char const *)arg3,(char const *)arg4,arg5); + r_ans = Rf_ScalarInteger(result); + + + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_query_execute ( SEXP model, SEXP query) +{ + librdf_query_results *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_query *arg2 = (librdf_query *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_query_execute" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(query, &argp2, SWIGTYPE_p_librdf_query, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_query_execute" "', argument " "2"" of type '" "librdf_query *""'"); + } + arg2 = (librdf_query *)(argp2); + result = (librdf_query_results *)librdf_model_query_execute(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_query_results, R_SWIG_OWNER | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_to_string ( SEXP model, SEXP uri, SEXP name, SEXP mime_type, SEXP inUriOrNull) +{ + char *result = 0 ; + librdf_model *arg1 = (librdf_model *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + char *arg3 = (char *) NULL ; + char *arg4 = (char *) NULL ; + librdf_uri *arg5 = (librdf_uri *) NULL ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + int res4 ; + char *buf4 = 0 ; + int alloc4 = 0 ; + void *argp5 = 0 ; + int res5 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_to_string" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + res2 = SWIG_R_ConvertPtr(uri, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_model_to_string" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_AsCharPtrAndSize(name, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_model_to_string" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + res4 = SWIG_AsCharPtrAndSize(mime_type, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_model_to_string" "', argument " "4"" of type '" "char const *""'"); + } + arg4 = (char *)(buf4); + res5 = SWIG_R_ConvertPtr(inUriOrNull, &argp5, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res5)) { + SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "librdf_model_to_string" "', argument " "5"" of type '" "librdf_uri *""'"); + } + arg5 = (librdf_uri *)(argp5); + result = (char *)librdf_model_to_string(arg1,arg2,(char const *)arg3,(char const *)arg4,arg5); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); + + free((char*)result); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_transaction_start ( SEXP model, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_transaction_start" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + result = (int)librdf_model_transaction_start(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_transaction_commit ( SEXP model, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_transaction_commit" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + result = (int)librdf_model_transaction_commit(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_model_transaction_rollback ( SEXP model, SEXP s_swig_copy) +{ + int result; + librdf_model *arg1 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(model, &argp1, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_model_transaction_rollback" "', argument " "1"" of type '" "librdf_model *""'"); + } + arg1 = (librdf_model *)(argp1); + result = (int)librdf_model_transaction_rollback(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_storage ( SEXP world, SEXP storage_name, SEXP name, SEXP options_string) +{ + librdf_storage *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + char *arg4 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_storage" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + arg2 = (char *)(SWIG_strdup(CHAR(STRING_ELT(storage_name, 0)))); + arg3 = (char *)(SWIG_strdup(CHAR(STRING_ELT(name, 0)))); + arg4 = (char *)(SWIG_strdup(CHAR(STRING_ELT(options_string, 0)))); + result = (librdf_storage *)librdf_new_storage(arg1,arg2,arg3,arg4); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_storage_s, R_SWIG_OWNER | 0 ); + + free(arg2); + free(arg3); + free(arg4); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_storage_from_storage ( SEXP old_storage) +{ + librdf_storage *result = 0 ; + librdf_storage *arg1 = (librdf_storage *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(old_storage, &argp1, SWIGTYPE_p_librdf_storage_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_storage_from_storage" "', argument " "1"" of type '" "librdf_storage *""'"); + } + arg1 = (librdf_storage *)(argp1); + result = (librdf_storage *)librdf_new_storage_from_storage(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_storage_s, R_SWIG_OWNER | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_storage ( SEXP storage) +{ + librdf_storage *arg1 = (librdf_storage *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(storage, &argp1, SWIGTYPE_p_librdf_storage_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_storage" "', argument " "1"" of type '" "librdf_storage *""'"); + } + arg1 = (librdf_storage *)(argp1); + librdf_free_storage(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_check_name ( SEXP world, SEXP name, SEXP s_swig_copy) +{ + int result; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_check_name" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_parser_check_name" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (int)librdf_parser_check_name(arg1,(char const *)arg2); + r_ans = Rf_ScalarInteger(result); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_parser ( SEXP world, SEXP name, SEXP mime_type, SEXP type_uri) +{ + librdf_parser *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + librdf_uri *arg4 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_parser" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_parser" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_AsCharPtrAndSize(mime_type, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_new_parser" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + res4 = SWIG_R_ConvertPtr(type_uri, &argp4, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_new_parser" "', argument " "4"" of type '" "librdf_uri *""'"); + } + arg4 = (librdf_uri *)(argp4); + result = (librdf_parser *)librdf_new_parser(arg1,(char const *)arg2,(char const *)arg3,arg4); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_parser_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_parser ( SEXP parser) +{ + librdf_parser *arg1 = (librdf_parser *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_parser" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + librdf_free_parser(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_parse_as_stream ( SEXP parser, SEXP uri, SEXP inUriorNull) +{ + librdf_stream *result = 0 ; + librdf_parser *arg1 = (librdf_parser *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + librdf_uri *arg3 = (librdf_uri *) NULL ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_parse_as_stream" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + res2 = SWIG_R_ConvertPtr(uri, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_parser_parse_as_stream" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_R_ConvertPtr(inUriorNull, &argp3, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_parser_parse_as_stream" "', argument " "3"" of type '" "librdf_uri *""'"); + } + arg3 = (librdf_uri *)(argp3); + result = (librdf_stream *)librdf_parser_parse_as_stream(arg1,arg2,arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_stream_s, R_SWIG_OWNER | 0 ); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_parse_into_model ( SEXP parser, SEXP uri, SEXP inUriOrNull, SEXP model, SEXP s_swig_copy) +{ + int result; + librdf_parser *arg1 = (librdf_parser *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + librdf_uri *arg3 = (librdf_uri *) 0 ; + librdf_model *arg4 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_parse_into_model" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + res2 = SWIG_R_ConvertPtr(uri, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_parser_parse_into_model" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_R_ConvertPtr(inUriOrNull, &argp3, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_parser_parse_into_model" "', argument " "3"" of type '" "librdf_uri *""'"); + } + arg3 = (librdf_uri *)(argp3); + res4 = SWIG_R_ConvertPtr(model, &argp4, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_parser_parse_into_model" "', argument " "4"" of type '" "librdf_model *""'"); + } + arg4 = (librdf_model *)(argp4); + result = (int)librdf_parser_parse_into_model(arg1,arg2,arg3,arg4); + r_ans = Rf_ScalarInteger(result); + + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_parse_string_as_stream ( SEXP parser, SEXP string, SEXP base_uri) +{ + librdf_stream *result = 0 ; + librdf_parser *arg1 = (librdf_parser *) 0 ; + char *arg2 = (char *) 0 ; + librdf_uri *arg3 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_parse_string_as_stream" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + res2 = SWIG_AsCharPtrAndSize(string, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_parser_parse_string_as_stream" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_R_ConvertPtr(base_uri, &argp3, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_parser_parse_string_as_stream" "', argument " "3"" of type '" "librdf_uri *""'"); + } + arg3 = (librdf_uri *)(argp3); + result = (librdf_stream *)librdf_parser_parse_string_as_stream(arg1,(char const *)arg2,arg3); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_stream_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_parse_string_into_model ( SEXP parser, SEXP string, SEXP base_uri, SEXP model, SEXP s_swig_copy) +{ + int result; + librdf_parser *arg1 = (librdf_parser *) 0 ; + char *arg2 = (char *) 0 ; + librdf_uri *arg3 = (librdf_uri *) 0 ; + librdf_model *arg4 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_parse_string_into_model" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + res2 = SWIG_AsCharPtrAndSize(string, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_parser_parse_string_into_model" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_R_ConvertPtr(base_uri, &argp3, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_parser_parse_string_into_model" "', argument " "3"" of type '" "librdf_uri *""'"); + } + arg3 = (librdf_uri *)(argp3); + res4 = SWIG_R_ConvertPtr(model, &argp4, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_parser_parse_string_into_model" "', argument " "4"" of type '" "librdf_model *""'"); + } + arg4 = (librdf_model *)(argp4); + result = (int)librdf_parser_parse_string_into_model(arg1,(char const *)arg2,arg3,arg4); + r_ans = Rf_ScalarInteger(result); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_parse_counted_string_as_stream ( SEXP parser, SEXP string, SEXP length, SEXP base_uri) +{ + librdf_stream *result = 0 ; + librdf_parser *arg1 = (librdf_parser *) 0 ; + char *arg2 = (char *) 0 ; + size_t arg3 ; + librdf_uri *arg4 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int val3 ; + int ecode3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_parse_counted_string_as_stream" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + res2 = SWIG_AsCharPtrAndSize(string, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_parser_parse_counted_string_as_stream" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + ecode3 = SWIG_AsVal_int(length, &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "librdf_parser_parse_counted_string_as_stream" "', argument " "3"" of type '" "size_t""'"); + } + arg3 = (size_t)(val3); + res4 = SWIG_R_ConvertPtr(base_uri, &argp4, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_parser_parse_counted_string_as_stream" "', argument " "4"" of type '" "librdf_uri *""'"); + } + arg4 = (librdf_uri *)(argp4); + result = (librdf_stream *)librdf_parser_parse_counted_string_as_stream(arg1,(char const *)arg2,arg3,arg4); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_stream_s, R_SWIG_EXTERNAL | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_parse_counted_string_into_model ( SEXP parser, SEXP string, SEXP length, SEXP base_uri, SEXP model, SEXP s_swig_copy) +{ + int result; + librdf_parser *arg1 = (librdf_parser *) 0 ; + char *arg2 = (char *) 0 ; + size_t arg3 ; + librdf_uri *arg4 = (librdf_uri *) 0 ; + librdf_model *arg5 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int val3 ; + int ecode3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + void *argp5 = 0 ; + int res5 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_parse_counted_string_into_model" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + res2 = SWIG_AsCharPtrAndSize(string, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_parser_parse_counted_string_into_model" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + ecode3 = SWIG_AsVal_int(length, &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "librdf_parser_parse_counted_string_into_model" "', argument " "3"" of type '" "size_t""'"); + } + arg3 = (size_t)(val3); + res4 = SWIG_R_ConvertPtr(base_uri, &argp4, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_parser_parse_counted_string_into_model" "', argument " "4"" of type '" "librdf_uri *""'"); + } + arg4 = (librdf_uri *)(argp4); + res5 = SWIG_R_ConvertPtr(model, &argp5, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res5)) { + SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "librdf_parser_parse_counted_string_into_model" "', argument " "5"" of type '" "librdf_model *""'"); + } + arg5 = (librdf_model *)(argp5); + result = (int)librdf_parser_parse_counted_string_into_model(arg1,(char const *)arg2,arg3,arg4,arg5); + r_ans = Rf_ScalarInteger(result); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_get_feature ( SEXP parser, SEXP feature) +{ + librdf_node *result = 0 ; + librdf_parser *arg1 = (librdf_parser *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_get_feature" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + res2 = SWIG_R_ConvertPtr(feature, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_parser_get_feature" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + result = (librdf_node *)librdf_parser_get_feature(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_set_feature ( SEXP parser, SEXP feature, SEXP value, SEXP s_swig_copy) +{ + int result; + librdf_parser *arg1 = (librdf_parser *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_set_feature" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + res2 = SWIG_R_ConvertPtr(feature, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_parser_set_feature" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_R_ConvertPtr(value, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_parser_set_feature" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (int)librdf_parser_set_feature(arg1,arg2,arg3); + r_ans = Rf_ScalarInteger(result); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + +SWIGEXPORT SEXP +R_swig_librdf_parser_guess_name2 ( SEXP world, SEXP mime_type, SEXP buffer, SEXP identifier) +{ + char *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + char *arg4 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + int res4 ; + char *buf4 = 0 ; + int alloc4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_guess_name2" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(mime_type, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_parser_guess_name2" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_AsCharPtrAndSize(buffer, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_parser_guess_name2" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + res4 = SWIG_AsCharPtrAndSize(identifier, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_parser_guess_name2" "', argument " "4"" of type '" "char const *""'"); + } + arg4 = (char *)(buf4); + result = (char *)librdf_parser_guess_name2(arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4); + r_ans = SWIG_FromCharPtr((const char *)result); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_get_namespaces_seen_prefix ( SEXP parser, SEXP offset) +{ + char *result = 0 ; + librdf_parser *arg1 = (librdf_parser *) 0 ; + int arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_get_namespaces_seen_prefix" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + arg2 = (int)(INTEGER(offset)[0]); + result = (char *)librdf_parser_get_namespaces_seen_prefix(arg1,arg2); + r_ans = SWIG_FromCharPtr((const char *)result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_get_namespaces_seen_uri ( SEXP parser, SEXP offset) +{ + librdf_uri *result = 0 ; + librdf_parser *arg1 = (librdf_parser *) 0 ; + int arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_get_namespaces_seen_uri" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + arg2 = (int)(INTEGER(offset)[0]); + result = (librdf_uri *)librdf_parser_get_namespaces_seen_uri(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_uri_s, R_SWIG_EXTERNAL | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_parser_get_namespaces_seen_count ( SEXP parser, SEXP s_swig_copy) +{ + int result; + librdf_parser *arg1 = (librdf_parser *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(parser, &argp1, SWIGTYPE_p_librdf_parser_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_parser_get_namespaces_seen_count" "', argument " "1"" of type '" "librdf_parser *""'"); + } + arg1 = (librdf_parser *)(argp1); + result = (int)librdf_parser_get_namespaces_seen_count(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_query ( SEXP world, SEXP name, SEXP uri, SEXP query_string, SEXP base_uri) +{ + librdf_query *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + librdf_uri *arg3 = (librdf_uri *) 0 ; + char *arg4 = (char *) 0 ; + librdf_uri *arg5 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + int res4 ; + char *buf4 = 0 ; + int alloc4 = 0 ; + void *argp5 = 0 ; + int res5 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_query" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_query" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_R_ConvertPtr(uri, &argp3, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_new_query" "', argument " "3"" of type '" "librdf_uri *""'"); + } + arg3 = (librdf_uri *)(argp3); + res4 = SWIG_AsCharPtrAndSize(query_string, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_new_query" "', argument " "4"" of type '" "char const *""'"); + } + arg4 = (char *)(buf4); + res5 = SWIG_R_ConvertPtr(base_uri, &argp5, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res5)) { + SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "librdf_new_query" "', argument " "5"" of type '" "librdf_uri *""'"); + } + arg5 = (librdf_uri *)(argp5); + result = (librdf_query *)librdf_new_query(arg1,(char const *)arg2,arg3,(char const *)arg4,arg5); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_query, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_query_from_query ( SEXP old_query) +{ + librdf_query *result = 0 ; + librdf_query *arg1 = (librdf_query *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(old_query, &argp1, SWIGTYPE_p_librdf_query, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_query_from_query" "', argument " "1"" of type '" "librdf_query *""'"); + } + arg1 = (librdf_query *)(argp1); + result = (librdf_query *)librdf_new_query_from_query(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_query, R_SWIG_OWNER | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_query ( SEXP query) +{ + librdf_query *arg1 = (librdf_query *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query, &argp1, SWIGTYPE_p_librdf_query, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_query" "', argument " "1"" of type '" "librdf_query *""'"); + } + arg1 = (librdf_query *)(argp1); + librdf_free_query(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_execute ( SEXP query, SEXP model) +{ + librdf_query_results *result = 0 ; + librdf_query *arg1 = (librdf_query *) 0 ; + librdf_model *arg2 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query, &argp1, SWIGTYPE_p_librdf_query, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_execute" "', argument " "1"" of type '" "librdf_query *""'"); + } + arg1 = (librdf_query *)(argp1); + res2 = SWIG_R_ConvertPtr(model, &argp2, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_query_execute" "', argument " "2"" of type '" "librdf_model *""'"); + } + arg2 = (librdf_model *)(argp2); + result = (librdf_query_results *)librdf_query_execute(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_query_results, R_SWIG_OWNER | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_get_limit ( SEXP query, SEXP s_swig_copy) +{ + int result; + librdf_query *arg1 = (librdf_query *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query, &argp1, SWIGTYPE_p_librdf_query, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_get_limit" "', argument " "1"" of type '" "librdf_query *""'"); + } + arg1 = (librdf_query *)(argp1); + result = (int)librdf_query_get_limit(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_set_limit ( SEXP query, SEXP limit, SEXP s_swig_copy) +{ + int result; + librdf_query *arg1 = (librdf_query *) 0 ; + int arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query, &argp1, SWIGTYPE_p_librdf_query, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_set_limit" "', argument " "1"" of type '" "librdf_query *""'"); + } + arg1 = (librdf_query *)(argp1); + arg2 = (int)(INTEGER(limit)[0]); + result = (int)librdf_query_set_limit(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_get_offset ( SEXP query, SEXP s_swig_copy) +{ + int result; + librdf_query *arg1 = (librdf_query *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query, &argp1, SWIGTYPE_p_librdf_query, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_get_offset" "', argument " "1"" of type '" "librdf_query *""'"); + } + arg1 = (librdf_query *)(argp1); + result = (int)librdf_query_get_offset(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_set_offset ( SEXP query, SEXP offset, SEXP s_swig_copy) +{ + int result; + librdf_query *arg1 = (librdf_query *) 0 ; + int arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query, &argp1, SWIGTYPE_p_librdf_query, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_set_offset" "', argument " "1"" of type '" "librdf_query *""'"); + } + arg1 = (librdf_query *)(argp1); + arg2 = (int)(INTEGER(offset)[0]); + result = (int)librdf_query_set_offset(arg1,arg2); + r_ans = Rf_ScalarInteger(result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_as_stream ( SEXP query_results) +{ + librdf_stream *result = 0 ; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_as_stream" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + result = (librdf_stream *)librdf_query_results_as_stream(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_stream_s, R_SWIG_OWNER | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_get_count ( SEXP query_results, SEXP s_swig_copy) +{ + int result; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_get_count" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + result = (int)librdf_query_results_get_count(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_next ( SEXP query_results, SEXP s_swig_copy) +{ + int result; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_next" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + result = (int)librdf_query_results_next(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_finished ( SEXP query_results, SEXP s_swig_copy) +{ + int result; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_finished" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + result = (int)librdf_query_results_finished(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_get_binding_value ( SEXP query_results, SEXP offset) +{ + librdf_node *result = 0 ; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + int arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_get_binding_value" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + arg2 = (int)(INTEGER(offset)[0]); + result = (librdf_node *)librdf_query_results_get_binding_value(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_get_binding_name ( SEXP query_results, SEXP offset) +{ + char *result = 0 ; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + int arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_get_binding_name" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + arg2 = (int)(INTEGER(offset)[0]); + result = (char *)librdf_query_results_get_binding_name(arg1,arg2); + r_ans = SWIG_FromCharPtr((const char *)result); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_get_binding_value_by_name ( SEXP query_results, SEXP name) +{ + librdf_node *result = 0 ; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_get_binding_value_by_name" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_query_results_get_binding_value_by_name" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (librdf_node *)librdf_query_results_get_binding_value_by_name(arg1,(char const *)arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_get_bindings_count ( SEXP query_results, SEXP s_swig_copy) +{ + int result; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_get_bindings_count" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + result = (int)librdf_query_results_get_bindings_count(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_to_file2 ( SEXP query_results, SEXP name, SEXP mime_type, SEXP format_uri, SEXP base_uri, SEXP s_swig_copy) +{ + int result; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + librdf_uri *arg4 = (librdf_uri *) 0 ; + librdf_uri *arg5 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + void *argp5 = 0 ; + int res5 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_to_file2" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_query_results_to_file2" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_AsCharPtrAndSize(mime_type, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_query_results_to_file2" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + res4 = SWIG_R_ConvertPtr(format_uri, &argp4, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_query_results_to_file2" "', argument " "4"" of type '" "librdf_uri *""'"); + } + arg4 = (librdf_uri *)(argp4); + res5 = SWIG_R_ConvertPtr(base_uri, &argp5, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res5)) { + SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "librdf_query_results_to_file2" "', argument " "5"" of type '" "librdf_uri *""'"); + } + arg5 = (librdf_uri *)(argp5); + result = (int)librdf_query_results_to_file2(arg1,(char const *)arg2,(char const *)arg3,arg4,arg5); + r_ans = Rf_ScalarInteger(result); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_to_string2 ( SEXP query_results, SEXP name, SEXP mime_type, SEXP format_uri, SEXP base_uri) +{ + char *result = 0 ; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + librdf_uri *arg4 = (librdf_uri *) 0 ; + librdf_uri *arg5 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + void *argp5 = 0 ; + int res5 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_to_string2" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_query_results_to_string2" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_AsCharPtrAndSize(mime_type, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_query_results_to_string2" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + res4 = SWIG_R_ConvertPtr(format_uri, &argp4, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_query_results_to_string2" "', argument " "4"" of type '" "librdf_uri *""'"); + } + arg4 = (librdf_uri *)(argp4); + res5 = SWIG_R_ConvertPtr(base_uri, &argp5, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res5)) { + SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "librdf_query_results_to_string2" "', argument " "5"" of type '" "librdf_uri *""'"); + } + arg5 = (librdf_uri *)(argp5); + result = (char *)librdf_query_results_to_string2(arg1,(char const *)arg2,(char const *)arg3,arg4,arg5); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + + + free((char*)result); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_query_results ( SEXP query_results) +{ + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_query_results" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + librdf_free_query_results(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_is_bindings ( SEXP query_results, SEXP s_swig_copy) +{ + int result; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_is_bindings" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + result = (int)librdf_query_results_is_bindings(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_is_boolean ( SEXP query_results, SEXP s_swig_copy) +{ + int result; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_is_boolean" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + result = (int)librdf_query_results_is_boolean(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_is_graph ( SEXP query_results, SEXP s_swig_copy) +{ + int result; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_is_graph" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + result = (int)librdf_query_results_is_graph(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_is_syntax ( SEXP query_results, SEXP s_swig_copy) +{ + int result; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_is_syntax" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + result = (int)librdf_query_results_is_syntax(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_query_results_get_boolean ( SEXP query_results, SEXP s_swig_copy) +{ + int result; + librdf_query_results *arg1 = (librdf_query_results *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(query_results, &argp1, SWIGTYPE_p_librdf_query_results, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_query_results_get_boolean" "', argument " "1"" of type '" "librdf_query_results *""'"); + } + arg1 = (librdf_query_results *)(argp1); + result = (int)librdf_query_results_get_boolean(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_serializer_check_name ( SEXP world, SEXP name, SEXP s_swig_copy) +{ + int result; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_serializer_check_name" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_serializer_check_name" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (int)librdf_serializer_check_name(arg1,(char const *)arg2); + r_ans = Rf_ScalarInteger(result); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_new_serializer ( SEXP world, SEXP name, SEXP mime_type, SEXP type_uri) +{ + librdf_serializer *result = 0 ; + librdf_world *arg1 = (librdf_world *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + librdf_uri *arg4 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_new_serializer" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_new_serializer" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_AsCharPtrAndSize(mime_type, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_new_serializer" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + res4 = SWIG_R_ConvertPtr(type_uri, &argp4, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_new_serializer" "', argument " "4"" of type '" "librdf_uri *""'"); + } + arg4 = (librdf_uri *)(argp4); + result = (librdf_serializer *)librdf_new_serializer(arg1,(char const *)arg2,(char const *)arg3,arg4); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_serializer_s, R_SWIG_OWNER | 0 ); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_serializer ( SEXP serializer) +{ + librdf_serializer *arg1 = (librdf_serializer *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(serializer, &argp1, SWIGTYPE_p_librdf_serializer_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_serializer" "', argument " "1"" of type '" "librdf_serializer *""'"); + } + arg1 = (librdf_serializer *)(argp1); + librdf_free_serializer(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_serializer_serialize_stream_to_file ( SEXP serializer, SEXP name, SEXP base_uri, SEXP stream, SEXP s_swig_copy) +{ + int result; + librdf_serializer *arg1 = (librdf_serializer *) 0 ; + char *arg2 = (char *) 0 ; + librdf_uri *arg3 = (librdf_uri *) 0 ; + librdf_stream *arg4 = (librdf_stream *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(serializer, &argp1, SWIGTYPE_p_librdf_serializer_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_serializer_serialize_stream_to_file" "', argument " "1"" of type '" "librdf_serializer *""'"); + } + arg1 = (librdf_serializer *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_serializer_serialize_stream_to_file" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_R_ConvertPtr(base_uri, &argp3, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_serializer_serialize_stream_to_file" "', argument " "3"" of type '" "librdf_uri *""'"); + } + arg3 = (librdf_uri *)(argp3); + res4 = SWIG_R_ConvertPtr(stream, &argp4, SWIGTYPE_p_librdf_stream_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_serializer_serialize_stream_to_file" "', argument " "4"" of type '" "librdf_stream *""'"); + } + arg4 = (librdf_stream *)(argp4); + result = (int)librdf_serializer_serialize_stream_to_file(arg1,(char const *)arg2,arg3,arg4); + r_ans = Rf_ScalarInteger(result); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_serializer_serialize_model_to_file ( SEXP serializer, SEXP name, SEXP inUriOrNull, SEXP model, SEXP s_swig_copy) +{ + int result; + librdf_serializer *arg1 = (librdf_serializer *) 0 ; + char *arg2 = (char *) 0 ; + librdf_uri *arg3 = (librdf_uri *) 0 ; + librdf_model *arg4 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + void *argp4 = 0 ; + int res4 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(serializer, &argp1, SWIGTYPE_p_librdf_serializer_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_serializer_serialize_model_to_file" "', argument " "1"" of type '" "librdf_serializer *""'"); + } + arg1 = (librdf_serializer *)(argp1); + res2 = SWIG_AsCharPtrAndSize(name, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_serializer_serialize_model_to_file" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + res3 = SWIG_R_ConvertPtr(inUriOrNull, &argp3, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_serializer_serialize_model_to_file" "', argument " "3"" of type '" "librdf_uri *""'"); + } + arg3 = (librdf_uri *)(argp3); + res4 = SWIG_R_ConvertPtr(model, &argp4, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "librdf_serializer_serialize_model_to_file" "', argument " "4"" of type '" "librdf_model *""'"); + } + arg4 = (librdf_model *)(argp4); + result = (int)librdf_serializer_serialize_model_to_file(arg1,(char const *)arg2,arg3,arg4); + r_ans = Rf_ScalarInteger(result); + + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_serializer_serialize_stream_to_string ( SEXP serializer, SEXP base_uri, SEXP stream) +{ + char *result = 0 ; + librdf_serializer *arg1 = (librdf_serializer *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + librdf_stream *arg3 = (librdf_stream *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(serializer, &argp1, SWIGTYPE_p_librdf_serializer_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_serializer_serialize_stream_to_string" "', argument " "1"" of type '" "librdf_serializer *""'"); + } + arg1 = (librdf_serializer *)(argp1); + res2 = SWIG_R_ConvertPtr(base_uri, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_serializer_serialize_stream_to_string" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_R_ConvertPtr(stream, &argp3, SWIGTYPE_p_librdf_stream_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_serializer_serialize_stream_to_string" "', argument " "3"" of type '" "librdf_stream *""'"); + } + arg3 = (librdf_stream *)(argp3); + result = (char *)librdf_serializer_serialize_stream_to_string(arg1,arg2,arg3); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + + + free((char*)result); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_serializer_serialize_model_to_string ( SEXP serializer, SEXP inUriOrNull, SEXP model) +{ + char *result = 0 ; + librdf_serializer *arg1 = (librdf_serializer *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + librdf_model *arg3 = (librdf_model *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(serializer, &argp1, SWIGTYPE_p_librdf_serializer_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_serializer_serialize_model_to_string" "', argument " "1"" of type '" "librdf_serializer *""'"); + } + arg1 = (librdf_serializer *)(argp1); + res2 = SWIG_R_ConvertPtr(inUriOrNull, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_serializer_serialize_model_to_string" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_R_ConvertPtr(model, &argp3, SWIGTYPE_p_librdf_model_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_serializer_serialize_model_to_string" "', argument " "3"" of type '" "librdf_model *""'"); + } + arg3 = (librdf_model *)(argp3); + result = (char *)librdf_serializer_serialize_model_to_string(arg1,arg2,arg3); + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + + + + free((char*)result); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_serializer_get_feature ( SEXP serializer, SEXP feature) +{ + librdf_node *result = 0 ; + librdf_serializer *arg1 = (librdf_serializer *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(serializer, &argp1, SWIGTYPE_p_librdf_serializer_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_serializer_get_feature" "', argument " "1"" of type '" "librdf_serializer *""'"); + } + arg1 = (librdf_serializer *)(argp1); + res2 = SWIG_R_ConvertPtr(feature, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_serializer_get_feature" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + result = (librdf_node *)librdf_serializer_get_feature(arg1,arg2); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_node_s, R_SWIG_EXTERNAL | 0 ); + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_serializer_set_feature ( SEXP serializer, SEXP feature, SEXP value, SEXP s_swig_copy) +{ + int result; + librdf_serializer *arg1 = (librdf_serializer *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + librdf_node *arg3 = (librdf_node *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(serializer, &argp1, SWIGTYPE_p_librdf_serializer_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_serializer_set_feature" "', argument " "1"" of type '" "librdf_serializer *""'"); + } + arg1 = (librdf_serializer *)(argp1); + res2 = SWIG_R_ConvertPtr(feature, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_serializer_set_feature" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_R_ConvertPtr(value, &argp3, SWIGTYPE_p_librdf_node_s, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_serializer_set_feature" "', argument " "3"" of type '" "librdf_node *""'"); + } + arg3 = (librdf_node *)(argp3); + result = (int)librdf_serializer_set_feature(arg1,arg2,arg3); + r_ans = Rf_ScalarInteger(result); + + + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_serializer_set_namespace ( SEXP serializer, SEXP nspace, SEXP prefix, SEXP s_swig_copy) +{ + int result; + librdf_serializer *arg1 = (librdf_serializer *) 0 ; + librdf_uri *arg2 = (librdf_uri *) 0 ; + char *arg3 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(serializer, &argp1, SWIGTYPE_p_librdf_serializer_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_serializer_set_namespace" "', argument " "1"" of type '" "librdf_serializer *""'"); + } + arg1 = (librdf_serializer *)(argp1); + res2 = SWIG_R_ConvertPtr(nspace, &argp2, SWIGTYPE_p_librdf_uri_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "librdf_serializer_set_namespace" "', argument " "2"" of type '" "librdf_uri *""'"); + } + arg2 = (librdf_uri *)(argp2); + res3 = SWIG_AsCharPtrAndSize(prefix, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "librdf_serializer_set_namespace" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + result = (int)librdf_serializer_set_namespace(arg1,arg2,(char const *)arg3); + r_ans = Rf_ScalarInteger(result); + + + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_free_stream ( SEXP stream) +{ + librdf_stream *arg1 = (librdf_stream *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(stream, &argp1, SWIGTYPE_p_librdf_stream_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_free_stream" "', argument " "1"" of type '" "librdf_stream *""'"); + } + arg1 = (librdf_stream *)(argp1); + librdf_free_stream(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_stream_end ( SEXP stream, SEXP s_swig_copy) +{ + int result; + librdf_stream *arg1 = (librdf_stream *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(stream, &argp1, SWIGTYPE_p_librdf_stream_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_stream_end" "', argument " "1"" of type '" "librdf_stream *""'"); + } + arg1 = (librdf_stream *)(argp1); + result = (int)librdf_stream_end(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_stream_next ( SEXP stream, SEXP s_swig_copy) +{ + int result; + librdf_stream *arg1 = (librdf_stream *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(stream, &argp1, SWIGTYPE_p_librdf_stream_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_stream_next" "', argument " "1"" of type '" "librdf_stream *""'"); + } + arg1 = (librdf_stream *)(argp1); + result = (int)librdf_stream_next(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_stream_get_object ( SEXP stream) +{ + librdf_statement *result = 0 ; + librdf_stream *arg1 = (librdf_stream *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(stream, &argp1, SWIGTYPE_p_librdf_stream_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_stream_get_object" "', argument " "1"" of type '" "librdf_stream *""'"); + } + arg1 = (librdf_stream *)(argp1); + result = (librdf_statement *)librdf_stream_get_object(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_librdf_statement_s, R_SWIG_EXTERNAL | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_log_message_code ( SEXP message, SEXP s_swig_copy) +{ + int result; + librdf_log_message *arg1 = (librdf_log_message *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(message, &argp1, SWIGTYPE_p_librdf_log_message, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_log_message_code" "', argument " "1"" of type '" "librdf_log_message *""'"); + } + arg1 = (librdf_log_message *)(argp1); + result = (int)librdf_log_message_code(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_log_message_level ( SEXP message, SEXP s_swig_copy) +{ + int result; + librdf_log_message *arg1 = (librdf_log_message *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(message, &argp1, SWIGTYPE_p_librdf_log_message, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_log_message_level" "', argument " "1"" of type '" "librdf_log_message *""'"); + } + arg1 = (librdf_log_message *)(argp1); + result = (int)librdf_log_message_level(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_log_message_facility ( SEXP message, SEXP s_swig_copy) +{ + int result; + librdf_log_message *arg1 = (librdf_log_message *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(message, &argp1, SWIGTYPE_p_librdf_log_message, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_log_message_facility" "', argument " "1"" of type '" "librdf_log_message *""'"); + } + arg1 = (librdf_log_message *)(argp1); + result = (int)librdf_log_message_facility(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_log_message_message ( SEXP message) +{ + char *result = 0 ; + librdf_log_message *arg1 = (librdf_log_message *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(message, &argp1, SWIGTYPE_p_librdf_log_message, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_log_message_message" "', argument " "1"" of type '" "librdf_log_message *""'"); + } + arg1 = (librdf_log_message *)(argp1); + result = (char *)librdf_log_message_message(arg1); + r_ans = SWIG_FromCharPtr((const char *)result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_log_message_locator ( SEXP message) +{ + raptor_locator *result = 0 ; + librdf_log_message *arg1 = (librdf_log_message *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(message, &argp1, SWIGTYPE_p_librdf_log_message, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_log_message_locator" "', argument " "1"" of type '" "librdf_log_message *""'"); + } + arg1 = (librdf_log_message *)(argp1); + result = (raptor_locator *)librdf_log_message_locator(arg1); + r_ans = SWIG_R_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_raptor_locator, R_SWIG_EXTERNAL | 0 ); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_raptor_locator_line ( SEXP locator, SEXP s_swig_copy) +{ + int result; + raptor_locator *arg1 = (raptor_locator *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(locator, &argp1, SWIGTYPE_p_raptor_locator, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "raptor_locator_line" "', argument " "1"" of type '" "raptor_locator *""'"); + } + arg1 = (raptor_locator *)(argp1); + result = (int)raptor_locator_line(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_raptor_locator_column ( SEXP locator, SEXP s_swig_copy) +{ + int result; + raptor_locator *arg1 = (raptor_locator *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(locator, &argp1, SWIGTYPE_p_raptor_locator, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "raptor_locator_column" "', argument " "1"" of type '" "raptor_locator *""'"); + } + arg1 = (raptor_locator *)(argp1); + result = (int)raptor_locator_column(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_raptor_locator_byte ( SEXP locator, SEXP s_swig_copy) +{ + int result; + raptor_locator *arg1 = (raptor_locator *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(locator, &argp1, SWIGTYPE_p_raptor_locator, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "raptor_locator_byte" "', argument " "1"" of type '" "raptor_locator *""'"); + } + arg1 = (raptor_locator *)(argp1); + result = (int)raptor_locator_byte(arg1); + r_ans = Rf_ScalarInteger(result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_raptor_locator_file ( SEXP locator) +{ + char *result = 0 ; + raptor_locator *arg1 = (raptor_locator *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(locator, &argp1, SWIGTYPE_p_raptor_locator, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "raptor_locator_file" "', argument " "1"" of type '" "raptor_locator *""'"); + } + arg1 = (raptor_locator *)(argp1); + result = (char *)raptor_locator_file(arg1); + r_ans = SWIG_FromCharPtr((const char *)result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_raptor_locator_uri ( SEXP locator) +{ + char *result = 0 ; + raptor_locator *arg1 = (raptor_locator *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(locator, &argp1, SWIGTYPE_p_raptor_locator, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "raptor_locator_uri" "', argument " "1"" of type '" "raptor_locator *""'"); + } + arg1 = (raptor_locator *)(argp1); + result = (char *)raptor_locator_uri(arg1); + r_ans = SWIG_FromCharPtr((const char *)result); + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_internal_test_error ( SEXP world) +{ + librdf_world *arg1 = (librdf_world *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_internal_test_error" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + librdf_internal_test_error(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_internal_test_warning ( SEXP world) +{ + librdf_world *arg1 = (librdf_world *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + res1 = SWIG_R_ConvertPtr(world, &argp1, SWIGTYPE_p_librdf_world_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "librdf_internal_test_warning" "', argument " "1"" of type '" "librdf_world *""'"); + } + arg1 = (librdf_world *)(argp1); + librdf_internal_test_warning(arg1); + r_ans = R_NilValue; + + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_short_copyright_string_get ( SEXP s_swig_copy) +{ + char *result = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (char *)(char *)librdf_short_copyright_string; + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_copyright_string_get ( SEXP s_swig_copy) +{ + char *result = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (char *)(char *)librdf_copyright_string; + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_version_string_get ( SEXP s_swig_copy) +{ + char *result = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (char *)(char *)librdf_version_string; + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_version_major_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)librdf_version_major; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_version_minor_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)librdf_version_minor; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_version_release_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)librdf_version_release; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_librdf_version_decimal_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)librdf_version_decimal; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_raptor_version_string_get ( SEXP s_swig_copy) +{ + char *result = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (char *)(char *)raptor_version_string; + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_raptor_version_major_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)raptor_version_major; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_raptor_version_minor_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)raptor_version_minor; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_raptor_version_release_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)raptor_version_release; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_raptor_version_decimal_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)raptor_version_decimal; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_rasqal_version_string_get ( SEXP s_swig_copy) +{ + char *result = 0 ; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (char *)(char *)rasqal_version_string; + r_ans = result ? Rf_mkString((char *)(result)) : R_NilValue; + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_rasqal_version_major_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)rasqal_version_major; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_rasqal_version_minor_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)rasqal_version_minor; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_rasqal_version_release_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)rasqal_version_release; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +SWIGEXPORT SEXP +R_swig_rasqal_version_decimal_get ( SEXP s_swig_copy) +{ + unsigned int result; + unsigned int r_nprotect = 0; + SEXP r_ans = R_NilValue ; + VMAXTYPE r_vmax = vmaxget() ; + + result = (unsigned int)(unsigned int)rasqal_version_decimal; + r_ans = SWIG_From_unsigned_SS_int((unsigned int)(result)); + vmaxset(r_vmax); + if(r_nprotect) Rf_unprotect(r_nprotect); + + return r_ans; +} + + +#ifdef __cplusplus +} +#endif + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ + +static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_digest_s = {"_p_librdf_digest_s", "struct librdf_digest_s *|librdf_digest *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_hash_s = {"_p_librdf_hash_s", "librdf_hash *|struct librdf_hash_s *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_iterator_s = {"_p_librdf_iterator_s", "struct librdf_iterator_s *|librdf_iterator *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_log_func = {"_p_librdf_log_func", "librdf_log_func *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_log_message = {"_p_librdf_log_message", "librdf_log_message *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_model_s = {"_p_librdf_model_s", "struct librdf_model_s *|librdf_model *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_node_s = {"_p_librdf_node_s", "struct librdf_node_s *|librdf_node *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_parser_s = {"_p_librdf_parser_s", "librdf_parser *|struct librdf_parser_s *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_query = {"_p_librdf_query", "librdf_query *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_query_results = {"_p_librdf_query_results", "librdf_query_results *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_serializer_s = {"_p_librdf_serializer_s", "struct librdf_serializer_s *|librdf_serializer *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_statement_s = {"_p_librdf_statement_s", "struct librdf_statement_s *|librdf_statement *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_storage_s = {"_p_librdf_storage_s", "struct librdf_storage_s *|librdf_storage *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_stream_s = {"_p_librdf_stream_s", "struct librdf_stream_s *|librdf_stream *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_uri_s = {"_p_librdf_uri_s", "librdf_uri *|struct librdf_uri_s *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_librdf_world_s = {"_p_librdf_world_s", "struct librdf_world_s *|librdf_world *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_p_char = {"_p_p_char", "char **", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_raptor_locator = {"_p_raptor_locator", "raptor_locator *", 0, 0, (void*)0, 0}; + +static swig_type_info *swig_type_initial[] = { + &_swigt__p_char, + &_swigt__p_librdf_digest_s, + &_swigt__p_librdf_hash_s, + &_swigt__p_librdf_iterator_s, + &_swigt__p_librdf_log_func, + &_swigt__p_librdf_log_message, + &_swigt__p_librdf_model_s, + &_swigt__p_librdf_node_s, + &_swigt__p_librdf_parser_s, + &_swigt__p_librdf_query, + &_swigt__p_librdf_query_results, + &_swigt__p_librdf_serializer_s, + &_swigt__p_librdf_statement_s, + &_swigt__p_librdf_storage_s, + &_swigt__p_librdf_stream_s, + &_swigt__p_librdf_uri_s, + &_swigt__p_librdf_world_s, + &_swigt__p_p_char, + &_swigt__p_raptor_locator, +}; + +static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_digest_s[] = { {&_swigt__p_librdf_digest_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_hash_s[] = { {&_swigt__p_librdf_hash_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_iterator_s[] = { {&_swigt__p_librdf_iterator_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_log_func[] = { {&_swigt__p_librdf_log_func, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_log_message[] = { {&_swigt__p_librdf_log_message, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_model_s[] = { {&_swigt__p_librdf_model_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_node_s[] = { {&_swigt__p_librdf_node_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_parser_s[] = { {&_swigt__p_librdf_parser_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_query[] = { {&_swigt__p_librdf_query, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_query_results[] = { {&_swigt__p_librdf_query_results, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_serializer_s[] = { {&_swigt__p_librdf_serializer_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_statement_s[] = { {&_swigt__p_librdf_statement_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_storage_s[] = { {&_swigt__p_librdf_storage_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_stream_s[] = { {&_swigt__p_librdf_stream_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_uri_s[] = { {&_swigt__p_librdf_uri_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_librdf_world_s[] = { {&_swigt__p_librdf_world_s, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_p_char[] = { {&_swigt__p_p_char, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_raptor_locator[] = { {&_swigt__p_raptor_locator, 0, 0, 0},{0, 0, 0, 0}}; + +static swig_cast_info *swig_cast_initial[] = { + _swigc__p_char, + _swigc__p_librdf_digest_s, + _swigc__p_librdf_hash_s, + _swigc__p_librdf_iterator_s, + _swigc__p_librdf_log_func, + _swigc__p_librdf_log_message, + _swigc__p_librdf_model_s, + _swigc__p_librdf_node_s, + _swigc__p_librdf_parser_s, + _swigc__p_librdf_query, + _swigc__p_librdf_query_results, + _swigc__p_librdf_serializer_s, + _swigc__p_librdf_statement_s, + _swigc__p_librdf_storage_s, + _swigc__p_librdf_stream_s, + _swigc__p_librdf_uri_s, + _swigc__p_librdf_world_s, + _swigc__p_p_char, + _swigc__p_raptor_locator, +}; + + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ + + +/* ----------------------------------------------------------------------------- + * Type initialization: + * This problem is tough by the requirement that no dynamic + * memory is used. Also, since swig_type_info structures store pointers to + * swig_cast_info structures and swig_cast_info structures store pointers back + * to swig_type_info structures, we need some lookup code at initialization. + * The idea is that swig generates all the structures that are needed. + * The runtime then collects these partially filled structures. + * The SWIG_InitializeModule function takes these initial arrays out of + * swig_module, and does all the lookup, filling in the swig_module.types + * array with the correct data and linking the correct swig_cast_info + * structures together. + * + * The generated swig_type_info structures are assigned statically to an initial + * array. We just loop through that array, and handle each type individually. + * First we lookup if this type has been already loaded, and if so, use the + * loaded structure instead of the generated one. Then we have to fill in the + * cast linked list. The cast data is initially stored in something like a + * two-dimensional array. Each row corresponds to a type (there are the same + * number of rows as there are in the swig_type_initial array). Each entry in + * a column is one of the swig_cast_info structures for that type. + * The cast_initial array is actually an array of arrays, because each row has + * a variable number of columns. So to actually build the cast linked list, + * we find the array of casts associated with the type, and loop through it + * adding the casts to the list. The one last trick we need to do is making + * sure the type pointer in the swig_cast_info struct is correct. + * + * First off, we lookup the cast->type name to see if it is already loaded. + * There are three cases to handle: + * 1) If the cast->type has already been loaded AND the type we are adding + * casting info to has not been loaded (it is in this module), THEN we + * replace the cast->type pointer with the type pointer that has already + * been loaded. + * 2) If BOTH types (the one we are adding casting info to, and the + * cast->type) are loaded, THEN the cast info has already been loaded by + * the previous module so we just ignore it. + * 3) Finally, if cast->type has not already been loaded, then we add that + * swig_cast_info to the linked list (because the cast->type) pointer will + * be correct. + * ----------------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* c-mode */ +#endif +#endif + +#if 0 +#define SWIGRUNTIME_DEBUG +#endif + + +SWIGRUNTIME void +SWIG_InitializeModule(void *clientdata) { + size_t i; + swig_module_info *module_head, *iter; + int init; + + /* check to see if the circular list has been setup, if not, set it up */ + if (swig_module.next==0) { + /* Initialize the swig_module */ + swig_module.type_initial = swig_type_initial; + swig_module.cast_initial = swig_cast_initial; + swig_module.next = &swig_module; + init = 1; + } else { + init = 0; + } + + /* Try and load any already created modules */ + module_head = SWIG_GetModule(clientdata); + if (!module_head) { + /* This is the first module loaded for this interpreter */ + /* so set the swig module into the interpreter */ + SWIG_SetModule(clientdata, &swig_module); + } else { + /* the interpreter has loaded a SWIG module, but has it loaded this one? */ + iter=module_head; + do { + if (iter==&swig_module) { + /* Our module is already in the list, so there's nothing more to do. */ + return; + } + iter=iter->next; + } while (iter!= module_head); + + /* otherwise we must add our module into the list */ + swig_module.next = module_head->next; + module_head->next = &swig_module; + } + + /* When multiple interpreters are used, a module could have already been initialized in + a different interpreter, but not yet have a pointer in this interpreter. + In this case, we do not want to continue adding types... everything should be + set up already */ + if (init == 0) return; + + /* Now work on filling in swig_module.types */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: size %d\n", swig_module.size); +#endif + for (i = 0; i < swig_module.size; ++i) { + swig_type_info *type = 0; + swig_type_info *ret; + swig_cast_info *cast; + +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); +#endif + + /* if there is another module already loaded */ + if (swig_module.next != &swig_module) { + type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); + } + if (type) { + /* Overwrite clientdata field */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found type %s\n", type->name); +#endif + if (swig_module.type_initial[i]->clientdata) { + type->clientdata = swig_module.type_initial[i]->clientdata; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); +#endif + } + } else { + type = swig_module.type_initial[i]; + } + + /* Insert casting types */ + cast = swig_module.cast_initial[i]; + while (cast->type) { + + /* Don't need to add information already in the list */ + ret = 0; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); +#endif + if (swig_module.next != &swig_module) { + ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); +#ifdef SWIGRUNTIME_DEBUG + if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); +#endif + } + if (ret) { + if (type == swig_module.type_initial[i]) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: skip old type %s\n", ret->name); +#endif + cast->type = ret; + ret = 0; + } else { + /* Check for casting already in the list */ + swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); +#ifdef SWIGRUNTIME_DEBUG + if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); +#endif + if (!ocast) ret = 0; + } + } + + if (!ret) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); +#endif + if (type->cast) { + type->cast->prev = cast; + cast->next = type->cast; + } + type->cast = cast; + } + cast++; + } + /* Set entry in modules->types array equal to the type */ + swig_module.types[i] = type; + } + swig_module.types[i] = 0; + +#ifdef SWIGRUNTIME_DEBUG + printf("**** SWIG_InitializeModule: Cast List ******\n"); + for (i = 0; i < swig_module.size; ++i) { + int j = 0; + swig_cast_info *cast = swig_module.cast_initial[i]; + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); + while (cast->type) { + printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); + cast++; + ++j; + } + printf("---- Total casts: %d\n",j); + } + printf("**** SWIG_InitializeModule: Cast List ******\n"); +#endif +} + +/* This function will propagate the clientdata field of type to +* any new swig_type_info structures that have been added into the list +* of equivalent types. It is like calling +* SWIG_TypeClientData(type, clientdata) a second time. +*/ +SWIGRUNTIME void +SWIG_PropagateClientData(void) { + size_t i; + swig_cast_info *equiv; + static int init_run = 0; + + if (init_run) return; + init_run = 1; + + for (i = 0; i < swig_module.size; i++) { + if (swig_module.types[i]->clientdata) { + equiv = swig_module.types[i]->cast; + while (equiv) { + if (!equiv->converter) { + if (equiv->type && !equiv->type->clientdata) + SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); + } + equiv = equiv->next; + } + } + } +} + +#ifdef __cplusplus +#if 0 +{ /* c-mode */ +#endif +} +#endif + + +SWIGEXPORT void SWIG_init(void) { + + +/* compile-time include (inside a % ... % block) */ +#ifdef REDLAND_INIT_I +#include +#endif + +} +#include + +extern SEXP isnull(SEXP); + +SWIGINTERN R_CallMethodDef CallEntries[] = { + {"isnull", (DL_FUNC) &isnull, 1}, + {"R_swig_librdf_parser_set_feature", (DL_FUNC) &R_swig_librdf_parser_set_feature, 4}, + {"R_swig_librdf_parser_get_feature", (DL_FUNC) &R_swig_librdf_parser_get_feature, 2}, + {"R_swig_librdf_model_set_feature", (DL_FUNC) &R_swig_librdf_model_set_feature, 4}, + {"R_swig_librdf_model_get_feature", (DL_FUNC) &R_swig_librdf_model_get_feature, 2}, + {"R_swig_librdf_world_set_feature", (DL_FUNC) &R_swig_librdf_world_set_feature, 4}, + {"R_swig_librdf_world_get_feature", (DL_FUNC) &R_swig_librdf_world_get_feature, 2}, + {"R_swig_librdf_serializer_get_feature", (DL_FUNC) &R_swig_librdf_serializer_get_feature, 2}, + {"R_swig_librdf_serializer_set_feature", (DL_FUNC) &R_swig_librdf_serializer_set_feature, 4}, + {"R_swig_librdf_model_to_string", (DL_FUNC) &R_swig_librdf_model_to_string, 5}, + {"R_swig_librdf_new_node_from_uri_string", (DL_FUNC) &R_swig_librdf_new_node_from_uri_string, 2}, + {"R_swig_librdf_uri_to_string", (DL_FUNC) &R_swig_librdf_uri_to_string, 1}, + {"R_swig_librdf_digest_update_string", (DL_FUNC) &R_swig_librdf_digest_update_string, 2}, + {"R_swig_librdf_digest_to_string", (DL_FUNC) &R_swig_librdf_digest_to_string, 1}, + {"R_swig_librdf_new_hash_from_string", (DL_FUNC) &R_swig_librdf_new_hash_from_string, 3}, + {"R_swig_librdf_hash_to_string", (DL_FUNC) &R_swig_librdf_hash_to_string, 2}, + {"R_swig_librdf_new_node_from_normalised_uri_string", (DL_FUNC) &R_swig_librdf_new_node_from_normalised_uri_string, 4}, + {"R_swig_librdf_serializer_serialize_model_to_string", (DL_FUNC) &R_swig_librdf_serializer_serialize_model_to_string, 3}, + {"R_swig_librdf_stream_end", (DL_FUNC) &R_swig_librdf_stream_end, 2}, + {"R_swig_librdf_internal_test_error", (DL_FUNC) &R_swig_librdf_internal_test_error, 1}, + {"R_swig_librdf_query_results_get_binding_name", (DL_FUNC) &R_swig_librdf_query_results_get_binding_name, 2}, + {"R_swig_librdf_digest_init", (DL_FUNC) &R_swig_librdf_digest_init, 1}, + {"R_swig_librdf_query_set_limit", (DL_FUNC) &R_swig_librdf_query_set_limit, 3}, + {"R_swig_librdf_query_get_limit", (DL_FUNC) &R_swig_librdf_query_get_limit, 2}, + {"R_swig_librdf_model_get_contexts", (DL_FUNC) &R_swig_librdf_model_get_contexts, 1}, + {"R_swig_librdf_model_sync", (DL_FUNC) &R_swig_librdf_model_sync, 1}, + {"R_swig_librdf_free_hash", (DL_FUNC) &R_swig_librdf_free_hash, 1}, + {"R_swig_librdf_query_results_is_bindings", (DL_FUNC) &R_swig_librdf_query_results_is_bindings, 2}, + {"R_swig_librdf_query_results_finished", (DL_FUNC) &R_swig_librdf_query_results_finished, 2}, + {"R_swig_librdf_parser_get_accept_header", (DL_FUNC) &R_swig_librdf_parser_get_accept_header, 1}, + {"R_swig_librdf_serializer_serialize_model_to_file", (DL_FUNC) &R_swig_librdf_serializer_serialize_model_to_file, 5}, + {"R_swig_librdf_serializer_serialize_stream_to_file", (DL_FUNC) &R_swig_librdf_serializer_serialize_stream_to_file, 5}, + {"R_swig_raptor_locator_uri", (DL_FUNC) &R_swig_raptor_locator_uri, 1}, + {"R_swig_librdf_model_get_arcs_out", (DL_FUNC) &R_swig_librdf_model_get_arcs_out, 2}, + {"R_swig_librdf_query_results_is_graph", (DL_FUNC) &R_swig_librdf_query_results_is_graph, 2}, + {"R_swig_librdf_model_get_arc", (DL_FUNC) &R_swig_librdf_model_get_arc, 3}, + {"R_swig_raptor_locator_byte", (DL_FUNC) &R_swig_raptor_locator_byte, 2}, + {"R_swig_librdf_model_get_arcs_in", (DL_FUNC) &R_swig_librdf_model_get_arcs_in, 2}, + {"R_swig_librdf_node_get_literal_value_as_latin1", (DL_FUNC) &R_swig_librdf_node_get_literal_value_as_latin1, 1}, + {"R_swig_raptor_locator_file", (DL_FUNC) &R_swig_raptor_locator_file, 1}, + {"R_swig_librdf_free_node", (DL_FUNC) &R_swig_librdf_free_node, 1}, + {"R_swig_librdf_iterator_get_object", (DL_FUNC) &R_swig_librdf_iterator_get_object, 1}, + {"R_swig_librdf_statement_get_object", (DL_FUNC) &R_swig_librdf_statement_get_object, 1}, + {"R_swig_librdf_statement_set_object", (DL_FUNC) &R_swig_librdf_statement_set_object, 2}, + {"R_swig_librdf_stream_get_object", (DL_FUNC) &R_swig_librdf_stream_get_object, 1}, + {"R_swig_librdf_free_parser", (DL_FUNC) &R_swig_librdf_free_parser, 1}, + {"R_swig_librdf_new_parser", (DL_FUNC) &R_swig_librdf_new_parser, 4}, + {"R_swig_librdf_new_node_from_uri", (DL_FUNC) &R_swig_librdf_new_node_from_uri, 2}, + {"R_swig_librdf_new_uri_from_uri", (DL_FUNC) &R_swig_librdf_new_uri_from_uri, 1}, + {"R_swig_librdf_new_model_with_options", (DL_FUNC) &R_swig_librdf_new_model_with_options, 3}, + {"R_swig_librdf_free_uri", (DL_FUNC) &R_swig_librdf_free_uri, 1}, + {"R_swig_librdf_new_hash_from_array_of_strings", (DL_FUNC) &R_swig_librdf_new_hash_from_array_of_strings, 3}, + {"R_swig_librdf_free_iterator", (DL_FUNC) &R_swig_librdf_free_iterator, 1}, + {"R_swig_librdf_query_results_next", (DL_FUNC) &R_swig_librdf_query_results_next, 2}, + {"R_swig_librdf_short_copyright_string_get", (DL_FUNC) &R_swig_librdf_short_copyright_string_get, 1}, + {"R_swig_librdf_copyright_string_get", (DL_FUNC) &R_swig_librdf_copyright_string_get, 1}, + {"R_swig_librdf_version_string_get", (DL_FUNC) &R_swig_librdf_version_string_get, 1}, + {"R_swig_raptor_version_string_get", (DL_FUNC) &R_swig_raptor_version_string_get, 1}, + {"R_swig_rasqal_version_string_get", (DL_FUNC) &R_swig_rasqal_version_string_get, 1}, + {"R_swig_librdf_query_results_as_stream", (DL_FUNC) &R_swig_librdf_query_results_as_stream, 1}, + {"R_swig_librdf_parser_parse_string_as_stream", (DL_FUNC) &R_swig_librdf_parser_parse_string_as_stream, 3}, + {"R_swig_librdf_parser_parse_as_stream", (DL_FUNC) &R_swig_librdf_parser_parse_as_stream, 3}, + {"R_swig_librdf_model_context_as_stream", (DL_FUNC) &R_swig_librdf_model_context_as_stream, 2}, + {"R_swig_librdf_model_as_stream", (DL_FUNC) &R_swig_librdf_model_as_stream, 1}, + {"R_swig_librdf_free_stream", (DL_FUNC) &R_swig_librdf_free_stream, 1}, + {"R_swig_librdf_digest_update", (DL_FUNC) &R_swig_librdf_digest_update, 3}, + {"R_swig_librdf_parser_parse_counted_string_into_model", (DL_FUNC) &R_swig_librdf_parser_parse_counted_string_into_model, 6}, + {"R_swig_librdf_query_set_offset", (DL_FUNC) &R_swig_librdf_query_set_offset, 3}, + {"R_swig_librdf_query_get_offset", (DL_FUNC) &R_swig_librdf_query_get_offset, 2}, + {"R_swig_librdf_node_get_literal_value_is_wf_xml", (DL_FUNC) &R_swig_librdf_node_get_literal_value_is_wf_xml, 2}, + {"R_swig_librdf_model_transaction_rollback", (DL_FUNC) &R_swig_librdf_model_transaction_rollback, 2}, + {"R_swig_librdf_parser_guess_name2", (DL_FUNC) &R_swig_librdf_parser_guess_name2, 4}, + {"R_swig_librdf_model_has_arc_in", (DL_FUNC) &R_swig_librdf_model_has_arc_in, 4}, + {"R_swig_librdf_query_execute", (DL_FUNC) &R_swig_librdf_query_execute, 2}, + {"R_swig_librdf_model_query_execute", (DL_FUNC) &R_swig_librdf_model_query_execute, 2}, + {"R_swig_librdf_query_results_get_binding_value", (DL_FUNC) &R_swig_librdf_query_results_get_binding_value, 2}, + {"R_swig_librdf_query_results_is_syntax", (DL_FUNC) &R_swig_librdf_query_results_is_syntax, 2}, + {"R_swig_librdf_model_contains_context", (DL_FUNC) &R_swig_librdf_model_contains_context, 3}, + {"R_swig_librdf_model_find_statements_in_context", (DL_FUNC) &R_swig_librdf_model_find_statements_in_context, 3}, + {"R_swig_librdf_iterator_get_context", (DL_FUNC) &R_swig_librdf_iterator_get_context, 1}, + {"R_swig_librdf_version_release_get", (DL_FUNC) &R_swig_librdf_version_release_get, 1}, + {"R_swig_raptor_version_release_get", (DL_FUNC) &R_swig_raptor_version_release_get, 1}, + {"R_swig_rasqal_version_release_get", (DL_FUNC) &R_swig_rasqal_version_release_get, 1}, + {"R_swig_librdf_model_load", (DL_FUNC) &R_swig_librdf_model_load, 6}, + {"R_swig_librdf_new_hash", (DL_FUNC) &R_swig_librdf_new_hash, 2}, + {"R_swig_librdf_statement_is_complete", (DL_FUNC) &R_swig_librdf_statement_is_complete, 2}, + {"R_swig_librdf_serializer_serialize_stream_to_string", (DL_FUNC) &R_swig_librdf_serializer_serialize_stream_to_string, 3}, + {"R_swig_librdf_log_message_level", (DL_FUNC) &R_swig_librdf_log_message_level, 2}, + {"R_swig_librdf_query_results_get_bindings_count", (DL_FUNC) &R_swig_librdf_query_results_get_bindings_count, 2}, + {"R_swig_librdf_model_has_arc_out", (DL_FUNC) &R_swig_librdf_model_has_arc_out, 4}, + {"R_swig_librdf_statement_get_predicate", (DL_FUNC) &R_swig_librdf_statement_get_predicate, 1}, + {"R_swig_librdf_statement_set_predicate", (DL_FUNC) &R_swig_librdf_statement_set_predicate, 2}, + {"R_swig_librdf_model_context_remove_statement", (DL_FUNC) &R_swig_librdf_model_context_remove_statement, 4}, + {"R_swig_librdf_model_context_add_statement", (DL_FUNC) &R_swig_librdf_model_context_add_statement, 4}, + {"R_swig_librdf_model_contains_statement", (DL_FUNC) &R_swig_librdf_model_contains_statement, 3}, + {"R_swig_librdf_model_remove_statement", (DL_FUNC) &R_swig_librdf_model_remove_statement, 3}, + {"R_swig_librdf_model_add_statement", (DL_FUNC) &R_swig_librdf_model_add_statement, 3}, + {"R_swig_librdf_model_add_typed_literal_statement", (DL_FUNC) &R_swig_librdf_model_add_typed_literal_statement, 7}, + {"R_swig_librdf_model_add_string_literal_statement", (DL_FUNC) &R_swig_librdf_model_add_string_literal_statement, 7}, + {"R_swig_librdf_new_statement", (DL_FUNC) &R_swig_librdf_new_statement, 1}, + {"R_swig_librdf_new_statement_from_statement", (DL_FUNC) &R_swig_librdf_new_statement_from_statement, 1}, + {"R_swig_librdf_free_statement", (DL_FUNC) &R_swig_librdf_free_statement, 1}, + {"R_swig_librdf_statement_match", (DL_FUNC) &R_swig_librdf_statement_match, 3}, + {"R_swig_librdf_node_get_li_ordinal", (DL_FUNC) &R_swig_librdf_node_get_li_ordinal, 2}, + {"R_swig_librdf_model_get_target", (DL_FUNC) &R_swig_librdf_model_get_target, 3}, + {"R_swig_librdf_serializer_check_name", (DL_FUNC) &R_swig_librdf_serializer_check_name, 3}, + {"R_swig_librdf_parser_check_name", (DL_FUNC) &R_swig_librdf_parser_check_name, 3}, + {"R_swig_librdf_query_results_to_file2", (DL_FUNC) &R_swig_librdf_query_results_to_file2, 6}, + {"R_swig_librdf_new_node_from_node", (DL_FUNC) &R_swig_librdf_new_node_from_node, 1}, + {"R_swig_librdf_internal_test_warning", (DL_FUNC) &R_swig_librdf_internal_test_warning, 1}, + {"R_swig_librdf_world_open", (DL_FUNC) &R_swig_librdf_world_open, 1}, + {"R_swig_librdf_model_get_source", (DL_FUNC) &R_swig_librdf_model_get_source, 3}, + {"R_swig_librdf_node_is_resource", (DL_FUNC) &R_swig_librdf_node_is_resource, 2}, + {"R_swig_raptor_locator_column", (DL_FUNC) &R_swig_raptor_locator_column, 2}, + {"R_swig_librdf_free_serializer", (DL_FUNC) &R_swig_librdf_free_serializer, 1}, + {"R_swig_librdf_new_serializer", (DL_FUNC) &R_swig_librdf_new_serializer, 4}, + {"R_swig_librdf_model_get_targets", (DL_FUNC) &R_swig_librdf_model_get_targets, 3}, + {"R_swig_librdf_node_get_literal_value", (DL_FUNC) &R_swig_librdf_node_get_literal_value, 1}, + {"R_swig_librdf_model_transaction_commit", (DL_FUNC) &R_swig_librdf_model_transaction_commit, 2}, + {"R_swig_librdf_parser_parse_counted_string_as_stream", (DL_FUNC) &R_swig_librdf_parser_parse_counted_string_as_stream, 4}, + {"R_swig_librdf_free_query_results", (DL_FUNC) &R_swig_librdf_free_query_results, 1}, + {"R_swig_librdf_world_set_logger", (DL_FUNC) &R_swig_librdf_world_set_logger, 3}, + {"R_swig_librdf_query_results_get_count", (DL_FUNC) &R_swig_librdf_query_results_get_count, 2}, + {"R_swig_librdf_parser_get_namespaces_seen_count", (DL_FUNC) &R_swig_librdf_parser_get_namespaces_seen_count, 2}, + {"R_swig_librdf_model_transaction_start", (DL_FUNC) &R_swig_librdf_model_transaction_start, 2}, + {"R_swig_librdf_new_node", (DL_FUNC) &R_swig_librdf_new_node, 1}, + {"R_swig_librdf_node_get_literal_value_language", (DL_FUNC) &R_swig_librdf_node_get_literal_value_language, 1}, + {"R_swig_librdf_new_digest", (DL_FUNC) &R_swig_librdf_new_digest, 2}, + {"R_swig_librdf_free_digest", (DL_FUNC) &R_swig_librdf_free_digest, 1}, + {"R_swig_librdf_node_get_literal_value_datatype_uri", (DL_FUNC) &R_swig_librdf_node_get_literal_value_datatype_uri, 1}, + {"R_swig_librdf_log_message_message", (DL_FUNC) &R_swig_librdf_log_message_message, 1}, + {"R_swig_librdf_new_node_from_literal", (DL_FUNC) &R_swig_librdf_new_node_from_literal, 4}, + {"R_swig_librdf_new_node_from_typed_literal", (DL_FUNC) &R_swig_librdf_new_node_from_typed_literal, 4}, + {"R_swig_librdf_node_is_literal", (DL_FUNC) &R_swig_librdf_node_is_literal, 2}, + {"R_swig_librdf_parser_parse_string_into_model", (DL_FUNC) &R_swig_librdf_parser_parse_string_into_model, 5}, + {"R_swig_librdf_parser_parse_into_model", (DL_FUNC) &R_swig_librdf_parser_parse_into_model, 5}, + {"R_swig_librdf_new_model", (DL_FUNC) &R_swig_librdf_new_model, 3}, + {"R_swig_librdf_new_model_from_model", (DL_FUNC) &R_swig_librdf_new_model_from_model, 1}, + {"R_swig_librdf_free_model", (DL_FUNC) &R_swig_librdf_free_model, 1}, + {"R_swig_librdf_log_message_locator", (DL_FUNC) &R_swig_librdf_log_message_locator, 1}, + {"R_swig_librdf_parser_get_namespaces_seen_prefix", (DL_FUNC) &R_swig_librdf_parser_get_namespaces_seen_prefix, 2}, + {"R_swig_librdf_free_query", (DL_FUNC) &R_swig_librdf_free_query, 1}, + {"R_swig_librdf_new_query_from_query", (DL_FUNC) &R_swig_librdf_new_query_from_query, 1}, + {"R_swig_librdf_new_query", (DL_FUNC) &R_swig_librdf_new_query, 5}, + {"R_swig_librdf_new_statement_from_nodes", (DL_FUNC) &R_swig_librdf_new_statement_from_nodes, 4}, + {"R_swig_librdf_node_is_blank", (DL_FUNC) &R_swig_librdf_node_is_blank, 2}, + {"R_swig_librdf_new_node_from_blank_identifier", (DL_FUNC) &R_swig_librdf_new_node_from_blank_identifier, 2}, + {"R_swig_librdf_node_get_blank_identifier", (DL_FUNC) &R_swig_librdf_node_get_blank_identifier, 1}, + {"R_swig_librdf_statement_get_subject", (DL_FUNC) &R_swig_librdf_statement_get_subject, 1}, + {"R_swig_librdf_statement_set_subject", (DL_FUNC) &R_swig_librdf_statement_set_subject, 2}, + {"R_swig_librdf_stream_next", (DL_FUNC) &R_swig_librdf_stream_next, 2}, + {"R_swig_librdf_version_major_get", (DL_FUNC) &R_swig_librdf_version_major_get, 1}, + {"R_swig_librdf_version_minor_get", (DL_FUNC) &R_swig_librdf_version_minor_get, 1}, + {"R_swig_raptor_version_major_get", (DL_FUNC) &R_swig_raptor_version_major_get, 1}, + {"R_swig_raptor_version_minor_get", (DL_FUNC) &R_swig_raptor_version_minor_get, 1}, + {"R_swig_rasqal_version_major_get", (DL_FUNC) &R_swig_rasqal_version_major_get, 1}, + {"R_swig_rasqal_version_minor_get", (DL_FUNC) &R_swig_rasqal_version_minor_get, 1}, + {"R_swig_librdf_model_add", (DL_FUNC) &R_swig_librdf_model_add, 5}, + {"R_swig_librdf_model_get_arcs", (DL_FUNC) &R_swig_librdf_model_get_arcs, 3}, + {"R_swig_librdf_log_message_facility", (DL_FUNC) &R_swig_librdf_log_message_facility, 2}, + {"R_swig_librdf_node_get_type", (DL_FUNC) &R_swig_librdf_node_get_type, 2}, + {"R_swig_librdf_query_results_get_binding_value_by_name", (DL_FUNC) &R_swig_librdf_query_results_get_binding_value_by_name, 2}, + {"R_swig_librdf_new_world", (DL_FUNC) &R_swig_librdf_new_world, 0}, + {"R_swig_librdf_free_world", (DL_FUNC) &R_swig_librdf_free_world, 1}, + {"R_swig_librdf_iterator_next", (DL_FUNC) &R_swig_librdf_iterator_next, 2}, + {"R_swig_librdf_serializer_set_namespace", (DL_FUNC) &R_swig_librdf_serializer_set_namespace, 4}, + {"R_swig_librdf_query_results_get_boolean", (DL_FUNC) &R_swig_librdf_query_results_get_boolean, 2}, + {"R_swig_librdf_query_results_is_boolean", (DL_FUNC) &R_swig_librdf_query_results_is_boolean, 2}, + {"R_swig_raptor_locator_line", (DL_FUNC) &R_swig_raptor_locator_line, 2}, + {"R_swig_librdf_model_context_remove_statements", (DL_FUNC) &R_swig_librdf_model_context_remove_statements, 3}, + {"R_swig_librdf_model_context_add_statements", (DL_FUNC) &R_swig_librdf_model_context_add_statements, 4}, + {"R_swig_librdf_model_find_statements", (DL_FUNC) &R_swig_librdf_model_find_statements, 2}, + {"R_swig_librdf_model_add_statements", (DL_FUNC) &R_swig_librdf_model_add_statements, 3}, + {"R_swig_librdf_digest_final", (DL_FUNC) &R_swig_librdf_digest_final, 1}, + {"R_swig_librdf_new_uri_from_filename", (DL_FUNC) &R_swig_librdf_new_uri_from_filename, 2}, + {"R_swig_librdf_iterator_end", (DL_FUNC) &R_swig_librdf_iterator_end, 2}, + {"R_swig_librdf_uri_equals", (DL_FUNC) &R_swig_librdf_uri_equals, 3}, + {"R_swig_librdf_node_equals", (DL_FUNC) &R_swig_librdf_node_equals, 3}, + {"R_swig_librdf_statement_equals", (DL_FUNC) &R_swig_librdf_statement_equals, 3}, + {"R_swig_librdf_node_get_uri", (DL_FUNC) &R_swig_librdf_node_get_uri, 1}, + {"R_swig_librdf_free_storage", (DL_FUNC) &R_swig_librdf_free_storage, 1}, + {"R_swig_librdf_new_storage_from_storage", (DL_FUNC) &R_swig_librdf_new_storage_from_storage, 1}, + {"R_swig_librdf_new_storage", (DL_FUNC) &R_swig_librdf_new_storage, 4}, + {"R_swig_librdf_model_size", (DL_FUNC) &R_swig_librdf_model_size, 2}, + {"R_swig_librdf_query_results_to_string2", (DL_FUNC) &R_swig_librdf_query_results_to_string2, 5}, + {"R_swig_librdf_log_message_code", (DL_FUNC) &R_swig_librdf_log_message_code, 2}, + {"R_swig_librdf_version_decimal_get", (DL_FUNC) &R_swig_librdf_version_decimal_get, 1}, + {"R_swig_raptor_version_decimal_get", (DL_FUNC) &R_swig_raptor_version_decimal_get, 1}, + {"R_swig_rasqal_version_decimal_get", (DL_FUNC) &R_swig_rasqal_version_decimal_get, 1}, + {"R_swig_librdf_new_node_from_uri_local_name", (DL_FUNC) &R_swig_librdf_new_node_from_uri_local_name, 3}, + {"R_swig_librdf_uri_compare", (DL_FUNC) &R_swig_librdf_uri_compare, 3}, + {"R_swig_librdf_new_uri", (DL_FUNC) &R_swig_librdf_new_uri, 2}, + {"R_swig_librdf_model_get_sources", (DL_FUNC) &R_swig_librdf_model_get_sources, 3}, + {"R_swig_librdf_parser_get_namespaces_seen_uri", (DL_FUNC) &R_swig_librdf_parser_get_namespaces_seen_uri, 2}, + {NULL, NULL, 0} +}; + +SWIGEXPORT void R_init_redland(DllInfo *dll) { + R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); + R_useDynamicSymbols(dll, FALSE); +} diff --git a/R/redland/src/util.c b/R/redland/src/util.c new file mode 100644 index 000000000..167f164a8 --- /dev/null +++ b/R/redland/src/util.c @@ -0,0 +1,15 @@ +#include +#include +#include + +SEXP isnull(SEXP pointer) { + void *ptr = R_ExternalPtrAddr(pointer); + SEXP rvalue = PROTECT(NEW_LOGICAL(1)); + if (ptr==NULL) { + LOGICAL_DATA(rvalue)[0] = (Rboolean)TRUE; + } else { + LOGICAL_DATA(rvalue)[0] = (Rboolean)FALSE; + } + UNPROTECT(1); + return(rvalue); +} diff --git a/R/redland/tests/spelling.R b/R/redland/tests/spelling.R new file mode 100644 index 000000000..02e46f4e2 --- /dev/null +++ b/R/redland/tests/spelling.R @@ -0,0 +1,2 @@ +if(requireNamespace('spelling', quietly=TRUE)) + spelling::spell_check_test(vignettes = TRUE, error = FALSE, skip_on_cran = TRUE) diff --git a/R/redland/tests/test-all.R b/R/redland/tests/test-all.R new file mode 100644 index 000000000..f0766af52 --- /dev/null +++ b/R/redland/tests/test-all.R @@ -0,0 +1,19 @@ +# +# This work was created by the National Center for Ecological Analysis and Synthesis. +# +# Copyright 2015 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +library("testthat") +test_check("redland") diff --git a/R/redland/tests/testthat/test.Model.R b/R/redland/tests/testthat/test.Model.R new file mode 100644 index 000000000..ca334213c --- /dev/null +++ b/R/redland/tests/testthat/test.Model.R @@ -0,0 +1,51 @@ +context("Model tests") +test_that("redland library loads", { + library(redland) + # Add a line to this test to prevent 'Empty test' (skipped) msg. + expect_true(require(redland)) +}) +test_that("Model constructor", { + library(redland) + world <- new("World") + expect_false(is.null(world)) + + # Test creating the Storage system + storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") + expect_false(is.null(storage)) + expect_match(class(storage@librdf_storage), "_p_librdf_storage_s") + + # Test creating the Model + model <- new("Model", world, storage, options="") + expect_false(is.null(model)) + expect_match(class(model@librdf_model), "_p_librdf_model_s") + + # Test that model creation fails if world is not provided or is null + err <- try(model <- new("Model", world=NULL, storage, options=""), silent=TRUE) + expect_match(class(err), "try-error") + + # Test that model creation fails if storage is not provided or is null + err <- try(model <- new("Model", world, storage=NULL, options=""), silent=TRUE) + expect_match(class(err), "try-error") + + # Test adding a Statement to the Model + subject <- new("Node", world, uri="http://www.dajobe.org") + expect_match(class(subject@librdf_node), "_p_librdf_node_s") + predicate <- new("Node", world, uri="http://purl.org/dc/elements/1.1/creator") + expect_match(class(predicate@librdf_node), "_p_librdf_node_s") + object <- new("Node", world, literal="John Smith") + expect_match(class(object@librdf_node), "_p_librdf_node_s") + + statement <- new("Statement", world, subject, predicate, object) + expect_false(is.null(statement)) + expect_match(class(statement@librdf_statement), "_p_librdf_statement_s") + addStatement(model, statement) + + err <- try(freeStatement(statement), silent=TRUE) + expect_false(class(err) == "try-error") + err <- try(freeModel(model), silent=TRUE) + expect_false(class(err) == "try-error") + err <- try(freeStorage(storage), silent=TRUE) + expect_false(class(err) == "try-error") + err <- try(freeWorld(world), silent=TRUE) + expect_false(class(err) == "try-error") +}) \ No newline at end of file diff --git a/R/redland/tests/testthat/test.Node.R b/R/redland/tests/testthat/test.Node.R new file mode 100644 index 000000000..d0dfe126e --- /dev/null +++ b/R/redland/tests/testthat/test.Node.R @@ -0,0 +1,81 @@ +context("Node tests") +test_that("redland library loads", { + library(redland) + # Add a line to this test to prevent 'Empty test' (skipped) msg. + expect_true(require(redland)) +}) +test_that("Node constructor", { + library(redland) + world <- new("World") + expect_false(is.null(world)) + + # Test creating a blank node + node <- new("Node", world) + expect_false(is.null(node)) + expect_match(class(node), "Node") + expect_match(getNodeType(node), "blank") + + # Test creating a blank node with librdf generated identifier + node <- new("Node", world, blank=NULL) + expect_match(class(node@librdf_node), "_p_librdf_node_s") + expect_match(getNodeType(node), "blank") + + # Test creating a blank node with librdf generated identifier + node <- new("Node", world, blank="_:1234") + expect_match(class(node@librdf_node), "_p_librdf_node_s") + expect_match(getNodeType(node), "blank") + + # Test creating a node with a literal value + node <- new("Node", world, "Fee Fi Fo Fum") + expect_match(class(node@librdf_node), "_p_librdf_node_s") + expect_match(getNodeType(node), "literal") + # err <- try(freeNode(node), silent=TRUE) + # expect_match(class(err), not("try-error")) + + # Test creating a node with a literal value + node <- new("Node", world, literal="Fee Fi Fo Fum") + expect_match(class(node@librdf_node), "_p_librdf_node_s") + expect_match(getNodeType(node), "literal") + + # Test creating a node with a URI value + node <- new("Node", world, uri="http://www.example.com/") + expect_match(class(node@librdf_node), "_p_librdf_node_s") + expect_match(getNodeType(node), "resource") + + # Test that node creation fails if world is not provided or is null + err <- try(node <- new("Node", literal="Fee Fi Fo Fum"), silent=TRUE) + expect_match(class(err), "try-error") + err <- try(node <- new("Node", world=NULL, literal="Fee Fi Fo Fum"), silent=TRUE) + expect_match(class(err), "try-error") + + # Test that node values can be assigned and retrieved + # a blank node is created with a unique identifier generated by librdf + node <- new("Node", world, blank=NULL) + expect_gt(nchar(getNodeValue(node)), 0) + # a blank node is created with the user specified identifier, i.e. "_:id1" + # THe blank node id will be returned as a string + node <- new("Node", world, blank="_:b1") + expect_match(getNodeValue(node), "_:b1") + # a node type of 'literal' is created + node <- new("Node", world, literal="A Node Value") + expect_match(getNodeValue(node), "A Node Value") + # a Node type of 'resource' is created + node <- new("Node", world, uri="http://www.example.com") + expect_match(getNodeValue(node), "http://www.example.com") + # Create a literal node without a language tag + node <- new("Node", world, literal="just plain text") + expect_match(getNodeValue(node), "just plain text") + + node <- new("Node", world, literal="Jean Pierre Rampal", language="fr") + expect_match(getNodeValue(node), '\"Jean Pierre Rampal"@fr\"') + + # Activate this check when testthat properly handles UTF-8 in tests. This + # test works fine from the command line on all platforms, but when testthat + # reads a test in, it is reading in the code as ASCII and ignoring the package + # encoding, therefor the test is not performed with the correct string. + # + # Create a literal node, specifying a language encoding + #node <- new("Node", world, literal="Gérard de La Martinière", language="fr") + #expect_match(getNodeValue(node), "\"Gérard de La Martinière\"@fr\"") + +}) \ No newline at end of file diff --git a/R/redland/tests/testthat/test.Parser.R b/R/redland/tests/testthat/test.Parser.R new file mode 100644 index 000000000..57982757b --- /dev/null +++ b/R/redland/tests/testthat/test.Parser.R @@ -0,0 +1,59 @@ +context("Parser tests") +test_that("redland library loads", { + library(redland) + # Add a line to this test to prevent 'Empty test' (skipped) msg. + expect_true(require(redland)) +}) +test_that("Parser constructor", { + library(redland) + world <- new("World") + expect_false(is.null(world)) + + # Test creating the Storage system + storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") + expect_false(is.null(storage)) + expect_match(class(storage@librdf_storage), "_p_librdf_storage_s") + + # Test creating the Model + model <- new("Model", world, storage, options="") + expect_false(is.null(model)) + expect_match(class(model@librdf_model), "_p_librdf_model_s") + + # Test that model creation fails if world is not provided or is null + err <- try(model <- new("Model", world=NULL, storage, options=""), silent=TRUE) + expect_match(class(err), "try-error") + + expect_false(is.null(model)) + expect_match(class(model@librdf_model), "_p_librdf_model_s") + + # Test parsing an RDF document into a Model + parser <- new("Parser", world) + expect_false(is.null(parser)) + expect_match(class(parser@librdf_parser), "_p_librdf_parser_s") + + parseFileIntoModel(parser, world, system.file('extdata/example.rdf', package='redland'), model) + + # Test creating a Serializer and serializing the content just parsed into the model + serializer <- new("Serializer", world) + expect_false(is.null(serializer)) + expect_match(class(serializer@librdf_serializer), "_p_librdf_serializer_s") + + # Test performing a serialization on an RDF model + rdf <- serializeToCharacter(serializer, world, model) + expect_match(rdf, "John Smith") + + err <- try(freeModel(model), silent=TRUE) + expect_false(class(err) == "try-error") + + err <- try(freeStorage(storage), silent=TRUE) + expect_false(class(err) == "try-error") + + err <- try(freeParser(parser), silent=TRUE) + expect_false(class(err) == "try-error") + + err <- try(freeSerializer(serializer), silent=TRUE) + expect_false(class(err) == "try-error") + + err <- try(freeWorld(world), silent=TRUE) + expect_false(class(err) == "try-error") +}) diff --git a/R/redland/tests/testthat/test.Query.R b/R/redland/tests/testthat/test.Query.R new file mode 100644 index 000000000..db16dce74 --- /dev/null +++ b/R/redland/tests/testthat/test.Query.R @@ -0,0 +1,136 @@ +context("Query tests") +test_that("redland library loads", { + library(redland) + # Add a line to this test to prevent 'Empty test' (skipped) msg. + expect_true(require(redland)) +}) +test_that("Query works", { + library(redland) + world <- new("World") + expect_false(is.null(world)) + + world <- new("World") + storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") + model <- new("Model", world, storage, options="") + + # Literal for object node has RDF language tag + stmt <- new("Statement", + world = world, + subject="", + predicate="http://schema.org/name", + object="Maëlle Salmon", + language="fr") + addStatement(model, stmt) + + queryString <-'SELECT ?s ?p ?o WHERE { ?s ?p ?o}' + query <- new("Query", world, queryString, base_uri=NULL, query_language="sparql", query_uri=NULL) + results <- getResults(query, model, "turtle") + expect_true(grepl("http://schema.org/name", results)) + + # The Redlands library can return UTF characters that are outside the + # ASCII range as the unicode literal string, i.e. https://en.wikipedia.org/wiki/List_of_Unicode_characters. + # If 'stringi' is available, then check the original representation, otherwise check the escaped codepoint + # representation. + if(require("stringi", character.only = TRUE)) { + expect_match(stringi::stri_unescape_unicode(results), "Maëlle Salmon") + } else { + expect_match(results$o, '"Ma\\\\u00EBlle Salmon"@fr') + } + + freeQuery(query) + rm(query) + freeStorage(storage) + rm(storage) + freeModel(model) + rm(model) + freeWorld(world) + rm(world) + +}) + + +test_that("getResults, writeResults work", { + library(redland) + world <- new("World") + expect_false(is.null(world)) + storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") + model <- new("Model", world, storage, options="") + stmt <- new("Statement", world=world, + subject="https://orcid.org/0000-0002-2192-403X", + predicate="http://www.w3.org/ns/prov#Agent", + object="slaughter", + objectType="literal", datatype_uri="http://www.w3.org/2001/XMLSchema#string") + status <- addStatement(model, stmt) + queryString <- paste("PREFIX orcid: ", + "PREFIX dataone: ", + "PREFIX prov: ", + "SELECT ?a ?c WHERE { ?a prov:Agent ?c . }", sep=" ") + query <- new("Query", world, queryString, base_uri=NULL, query_language="sparql", query_uri=NULL) + # Return all results as a string + results <- getResults(query, model, "rdfxml") + expect_true(grepl("0000-0002-2192-403X", results)) + expect_true(grepl("slaughter", results)) + + results <- getResults(query, model, "turtle") + expect_true(grepl("slaughter", results)) + expect_true(grepl("0000-0002-2192-403X", results)) + + results <- getResults(query, model, "json") + expect_true(grepl("slaughter", results)) + expect_true(grepl("0000-0002-2192-403X", results)) + + # When the query object is no longer needed, the resources it had allocated can be freed. + freeQuery(query) + rm(query) + + # Test writeResults + world <- new("World") + storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") + model <- new("Model", world, storage, options="") + stmt <- new("Statement", world=world, + subject="https://orcid.org/0000-0002-2192-403X", + predicate="http://www.w3.org/ns/prov#Agent", + object="slaughter", + objectType="literal", datatype_uri="http://www.w3.org/2001/XMLSchema#string") + status <- addStatement(model, stmt) + queryString <- paste("PREFIX orcid: ", + "PREFIX dataone: ", + "PREFIX prov: ", + "SELECT ?a ?c WHERE { ?a prov:Agent ?c . }", sep=" ") + query <- new("Query", world, queryString, base_uri=NULL, query_language="sparql", query_uri=NULL) + # Return all results as a string + tf <- tempfile() + writeResults(query, model, file=tf, mimeType="application/x-turtle") + inbuf <- readLines(tf) + expect_true(any(grepl("slaughter", inbuf))) + expect_true(any(grepl("0000-0002-2192-403X", inbuf))) + + # Ntriples + tf <- tempfile() + writeResults(query, model, file=tf, mimeType="text/plain") + inbuf <- readLines(tf) + expect_true(any(grepl("slaughter", inbuf))) + expect_true(any(grepl("0000-0002-2192-403X", inbuf))) + + tf <- tempfile() + writeResults(query, model, file=tf, mimeType="application/json") + inbuf <- readLines(tf) + expect_true(any(grepl("slaughter", inbuf))) + expect_true(any(grepl("0000-0002-2192-403X", inbuf))) + + tf <- tempfile() + writeResults(query, model, file=tf, mimeType="text/html") + inbuf <- readLines(tf) + expect_true(any(grepl("slaughter", inbuf))) + expect_true(any(grepl("0000-0002-2192-403X", inbuf))) + + # When the query object is no longer needed, the resources it had allocated can be freed. + freeQuery(query) + rm(query) + freeStorage(storage) + rm(storage) + freeModel(model) + rm(model) + freeWorld(world) + rm(world) +}) \ No newline at end of file diff --git a/R/redland/tests/testthat/test.Serializer.R b/R/redland/tests/testthat/test.Serializer.R new file mode 100644 index 000000000..931d4f1dd --- /dev/null +++ b/R/redland/tests/testthat/test.Serializer.R @@ -0,0 +1,76 @@ +context("Serializer tests") +test_that("redland library loads", { + library(redland) + # Add a line to this test to prevent 'Empty test' (skipped) msg. + expect_true(require(redland)) +}) +test_that("Serializer constructor", { + library(redland) + world <- new("World") + expect_false(is.null(world)) + + # Test creating the Storage system + storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") + expect_false(is.null(storage)) + expect_match(class(storage@librdf_storage), "_p_librdf_storage_s") + + # Test creating the Model + model <- new("Model", world, storage, options="") + expect_false(is.null(model)) + expect_match(class(model@librdf_model), "_p_librdf_model_s") + + # Test that model creation fails if world is not provided or is null + err <- try(model <- new("Model", world=NULL, storage, options=""), silent=TRUE) + expect_match(class(err), "try-error") + + expect_false(is.null(model)) + expect_match(class(model@librdf_model), "_p_librdf_model_s") + + # Test adding a Statement to the Model + subject <- new("Node", world, uri="http://www.johnsmith.com/") + expect_match(class(subject@librdf_node), "_p_librdf_node_s") + predicate <- new("Node", world, uri="http://purl.org/dc/elements/1.1/creator") + expect_match(class(predicate@librdf_node), "_p_librdf_node_s") + object <- new("Node", world, literal="John Smith", datatype_uri="http://www.w3.org/2001/XMLSchema#string") + expect_match(class(object@librdf_node), "_p_librdf_node_s") + statement <- new("Statement", world, subject, predicate, object) + expect_false(is.null(statement)) + expect_match(class(statement@librdf_statement), "_p_librdf_statement_s") + addStatement(model, statement) + + # Test creating a Serializer + serializer <- new("Serializer", world, mimeType="application/rdf+xml") + expect_false(is.null(serializer)) + expect_match(class(serializer@librdf_serializer), "_p_librdf_serializer_s") + + # Test adding a namespace to a serializer + status <- setNameSpace(serializer, world, namespace="http://purl.org/dc/elements/1.1/", prefix="dc") + expect_that(status, equals(0)) + + # Test serialization of an RDF model to a string + rdf <- serializeToCharacter(serializer, world, model, "") + expect_match(rdf, "John Smith") + + # Test serialization of an RDF model to a file + filePath <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".rdf") + status <- serializeToFile(serializer, world, model, filePath) + found <- grep("John Smith", readLines(filePath)) + expect_that(found, is_more_than(0)) + unlink(filePath) + + err <- try(freeStatement(statement), silent=TRUE) + expect_false(class(err) == "try-error") + + err <- try(freeSerializer(serializer), silent=TRUE) + expect_false(class(err) == "try-error") + + err <- try(freeModel(model), silent=TRUE) + expect_false(class(err) == "try-error") + + err <- try(freeStorage(storage), silent=TRUE) + expect_false(class(err) == "try-error") + + err <- try(freeWorld(world), silent=TRUE) + expect_false(class(err) == "try-error") + +}) \ No newline at end of file diff --git a/R/redland/tests/testthat/test.Statement.R b/R/redland/tests/testthat/test.Statement.R new file mode 100644 index 000000000..257ccedaf --- /dev/null +++ b/R/redland/tests/testthat/test.Statement.R @@ -0,0 +1,86 @@ +context("Statement tests") +test_that("redland library loads", { + library(redland) + # Add a line to this test to prevent 'Empty test' (skipped) msg. + expect_true(require(redland)) +}) +test_that("Statement constructor", { + library(redland) + world <- new("World") + expect_false(is.null(world)) + + # Test creating Subject, predicate, and object Nodes + subject <- new("Node", world, literal="subject") + expect_match(class(subject@librdf_node), "_p_librdf_node_s") + predicate <- new("Node", world, literal="subject") + expect_match(class(predicate@librdf_node), "_p_librdf_node_s") + object <- new("Node", world, literal="subject") + expect_match(class(object@librdf_node), "_p_librdf_node_s") + + # Test creating the Statement + stmt <- new("Statement", world, subject, predicate, object) + expect_false(is.null(stmt)) + expect_match(class(stmt@librdf_statement), "_p_librdf_statement_s") + + # Test that statement creation fails if world is not provided or is null + err <- try(stmt <- new("Statement", world=NULL, subject=subject, predicate=predicate, object=object), silent=TRUE) + expect_match(class(err), "try-error") + + # Test that statement creation fails if subject, predicate, or object is not provided or is null + err <- try(stmt <- new("Statement", world=world, subject=NULL, predicate=predicate, object=object), silent=TRUE) + expect_match(class(err), "try-error") + err <- try(stmt <- new("Statement", world=world, subject=subject, predicate=NULL, object=object), silent=TRUE) + expect_match(class(err), "try-error") + err <- try(stmt <- new("Statement", world=world, subject=subject, predicate=predicate, object=NULL), silent=TRUE) + expect_match(class(err), "try-error") + + # Test statement creation when subject, predicate, object are passed in as character and RDF type is not specified + stmt <- new("Statement", world=world, + subject="https://cn.dataone.org/cn/v1/resolve/resourceMap_5cbcdecd-6b0e-4b24-a0be-20291b2e49a7#aggregation", + predicate="http://purl.org/dc/terms/identifier", + object="resourceMap_5cbcdecd-6b0e-4b24-a0be-20291b2e49a7^^xsd:string") + + expect_match(getTermType(stmt, "subject"), "resource") + expect_match(getTermType(stmt, "predicate"), "resource") + expect_match(getTermType(stmt, "object"), "literal") + + # Test + stmt <- new("Statement", world=world, + subject="_:foo1", + predicate="http://purl.org/dc/terms/identifier", + object=NULL) + + expect_match(getTermType(stmt, "subject"), "blank") + expect_match(getTermType(stmt, "predicate"), "resource") + expect_match(getTermType(stmt, "object"), "blank") + + err <- try(freeStatement(stmt), silent=TRUE) + expect_false(class(err) == "try-error") + + stmt <- new("Statement", world=world, + subject=NULL, + predicate="http://purl.org/dc/terms/identifier", + object="id1234") + + expect_match(getTermType(stmt, "subject"), "blank") + expect_match(getTermType(stmt, "predicate"), "resource") + expect_match(getTermType(stmt, "object"), "literal") + + err <- try(freeStatement(stmt), silent=TRUE) + expect_false(class(err) == "try-error") + + # Test statement creation when subject, predicate and object are passed in as charater and RDF types are specified + stmt <- new("Statement", world=world, + subject="http://www.exmaple.com/subject", + predicate="http://purl.org/dc/terms/identifier", + object="http://www.exmaple.com/object", subjectType="blank", objectType="literal") + + expect_match(getTermType(stmt, "subject"), "blank") + expect_match(getTermType(stmt, "predicate"), "resource") + expect_match(getTermType(stmt, "object"), "literal") + + err <- try(freeStatement(stmt), silent=TRUE) + expect_false(class(err) == "try-error") + err <- try(freeWorld(world), silent=TRUE) + expect_false(class(err) == "try-error") +}) \ No newline at end of file diff --git a/R/redland/tests/testthat/test.Storage.R b/R/redland/tests/testthat/test.Storage.R new file mode 100644 index 000000000..5763820c3 --- /dev/null +++ b/R/redland/tests/testthat/test.Storage.R @@ -0,0 +1,25 @@ +context("Storage tests") +test_that("redland library loads", { + library(redland) + # Add a line to this test to prevent 'Empty test' (skipped) msg. + expect_true(require(redland)) +}) +test_that("Storage constructor", { + library(redland) + world <- new("World") + expect_false(is.null(world)) + + # Test creating the Storage system + storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") + expect_false(is.null(storage)) + expect_match(class(storage@librdf_storage), "_p_librdf_storage_s") + + # Test that storage creation fails if world is not provided or is null + err <- try(storage <- new("Storage", world=NULL, "hashes", name="", options="hash-type='memory'"), silent=TRUE) + expect_match(class(err), "try-error") + + # Test that storage creation succeeds even if type and related options are not provided (use defaults) + err <- try(storage <- new("Storage", world=world), silent=TRUE) + expect_match(class(err), "Storage") + +}) \ No newline at end of file diff --git a/R/redland/tests/testthat/test.World.R b/R/redland/tests/testthat/test.World.R new file mode 100644 index 000000000..dd857f842 --- /dev/null +++ b/R/redland/tests/testthat/test.World.R @@ -0,0 +1,15 @@ +context("World tests") +test_that("redland library loads", { + library(redland) + # Add a line to this test to prevent 'Empty test' (skipped) msg. + expect_true(require(redland)) +}) +test_that("World constructor", { + library(redland) + world <- new("World"); + expect_match(class(world), "World") + expect_match(class(world@librdf_world), "_p_librdf_world_s") + err <- try(freeWorld(world), silent=TRUE) + expect_false(class(err) == "try-error") + +}) \ No newline at end of file diff --git a/R/redland/tests/testthat/test.redland_base.R b/R/redland/tests/testthat/test.redland_base.R new file mode 100644 index 000000000..24454beac --- /dev/null +++ b/R/redland/tests/testthat/test.redland_base.R @@ -0,0 +1,74 @@ +context("librdf base API tests") +test_that("redland library loads", { + library(redland) + # Add a line to this test to prevent 'Empty test' (skipped) msg. + expect_true(require(redland)) +}) +test_that("librdf basic functions", { + library(redland) + world <- librdf_new_world(); + expect_match(class(world), "_p_librdf_world_s") + storage <- librdf_new_storage(world,'hashes','dummy',"new=yes,hash-type='memory'") + expect_match(class(storage), "_p_librdf_storage_s") + + model <- librdf_new_model(world,storage,'') + expect_match(class(model), "_p_librdf_model_s") + + parser <- librdf_new_parser(world,'rdfxml','application/rdf+xml',NULL) + expect_match(class(parser), "_p_librdf_parser_s") + uri <- librdf_new_uri(world,paste0('file:',system.file('extdata/dc.rdf', package='redland'))) + expect_match(class(uri), "_p_librdf_uri_s") + rv <- librdf_parser_parse_into_model(parser,uri,uri,model) + expect_that(rv, equals(0)) + librdf_free_uri(uri); + librdf_free_parser(parser); + + query <- librdf_new_query(world, 'sparql', NULL, "PREFIX dc: SELECT ?a ?c ?d WHERE { ?a dc:title ?c . OPTIONAL { ?a dc:related ?d } }", NULL) + results <- librdf_model_query_execute(model, query); + expect_false(is.null(results)) + expect_match(class(results), "_p_librdf_query_results") + + # Convert the whole sparql result to a string and check its value + qstr <- librdf_query_results_to_string2(results, "rdfxml", "application/rdf+xml", NULL, NULL) + expect_match(qstr, "http://www.dajobe.org/") + expect_match(qstr, "Beckett") + + # Test adding a new Statement to the model + about <- "http://matt.magisa.org/" + subject <- librdf_new_node_from_uri_string(world, about) + expect_false(is.null(subject)) + expect_match(class(subject), "_p_librdf_node_s") + pred <- librdf_new_node_from_uri_string(world, "http://purl.org/dc/elements/1.1/title") + expect_false(is.null(pred)) + expect_match(class(pred), "_p_librdf_node_s") + object <- librdf_new_node_from_literal(world, "Matt Jones' Home Page", "", 0) + expect_false(is.null(object)) + expect_match(class(object), "_p_librdf_node_s") + statement <- librdf_new_statement_from_nodes(world, subject, pred, object) + expect_false(is.null(statement)) + expect_match(class(statement), "_p_librdf_statement_s") + + rc <- librdf_model_add_statement(model, statement) + expect_that(rc, equals(0)) + + # Don't need to call librdf_free_node, just librdf_free_statement. + librdf_free_statement(statement) + + # Test serialization of the model to a text file + serializer <- librdf_new_serializer(world, "rdfxml", "", NULL); + expect_false(is.null(serializer)) + expect_match(class(serializer), "_p_librdf_serializer") + base = librdf_new_uri(world, "http://example.org/base.rdf"); + filePath <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".rdf") + + librdf_serializer_serialize_model_to_file(serializer,filePath,base,model); + expect_true(file.exists(filePath)) + unlink(filePath) + + # Free resources + librdf_free_serializer(serializer); + librdf_free_uri(base); + librdf_free_model(model); + librdf_free_storage(storage); + expect_that("Reached end.", equals("Reached end.")) +}) diff --git a/R/redland/tools/winlibs.R b/R/redland/tools/winlibs.R new file mode 100644 index 000000000..9d90cfe35 --- /dev/null +++ b/R/redland/tools/winlibs.R @@ -0,0 +1,8 @@ +# Build against mingw-w64 build of redland +if(!file.exists("../windows/redland-1.0.17/include/redland.h")){ + if(getRversion() < "3.3.0") setInternet2() + download.file("https://github.com/rwinlib/redland/archive/v1.0.17.zip", "lib.zip", quiet = TRUE) + dir.create("../windows", showWarnings = FALSE) + unzip("lib.zip", exdir = "../windows") + unlink("lib.zip") +} diff --git a/R/redland/vignettes/redland_overview.Rmd b/R/redland/vignettes/redland_overview.Rmd new file mode 100644 index 000000000..34bf4d000 --- /dev/null +++ b/R/redland/vignettes/redland_overview.Rmd @@ -0,0 +1,59 @@ +--- +title: "redland: create, query and write RDF graphs" +author: "Peter Slaughter" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{redland RDF} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +## Introduction + +The `redland` R package provides methods to create, query and write to disk data stored in the Resource Description Framework (RDF). RDF provides a standardized way to make statements about resources and the relationships between them. Typical resources include datasets that are available via URLs. Resources don't have to be available online, for example a resource could also be the name of the person that created a dataset. A collection of RDF statements comprise an RDF graph, which can be read and interpreted by an RDF capable software application that uses the resources described in the graph. + +An introduction to RDF can be found at http://www.w3.org/TR/2014/NOTE-rdf11-primer-20140624. + +## Examples + +The following example reads an RDF graph from a disk file that was previously saved in the RDF/XML format: + +```{r} +library(redland) +world <- new("World") +storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'") +model <- new("Model", world=world, storage, options="") +parser <- new("Parser", world) +parseFileIntoModel(parser, world, system.file("extdata", "dc.rdf", package="redland"), model) + +``` +Next the RDF graph is queried for statements of interest, using the [SPARQL query syntax](http://www.w3.org/TR/rdf-sparql-query) + +```{r} +queryString <- 'PREFIX dc: SELECT ?a ?c WHERE { ?a dc:creator ?c . }' +query <- new("Query", world, queryString, base_uri=NULL, query_language="sparql", query_uri=NULL) +queryResult <- executeQuery(query, model) +results <- getResults(query, model, "rdfxml") + +cat(sprintf("Results from query: %s\n", results)) +``` + +Next, additional statements can be added to the RDF graph: +```{r} +stmt <- new("Statement", world=world, + subject="http://www.dajobe.org/", + predicate="http://purl.org/dc/elements/1.1/language", + object="en") +addStatement(model, stmt) +``` + +Now the RDF graph can be written to disk: + +```{r} +serializer <- new("Serializer", world, mimeType="application/rdf+xml") +status <- setNameSpace(serializer, world, namespace="http://purl.org/dc/elements/1.1/", prefix="dc") +filePath <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".rdf") +status <- serializeToFile(serializer, world, model, filePath) +``` + diff --git a/ada/.gitignore b/ada/.gitignore new file mode 100644 index 000000000..b25c15b81 --- /dev/null +++ b/ada/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/ada/Makefile.am b/ada/Makefile.am new file mode 100644 index 000000000..b17e84d2a --- /dev/null +++ b/ada/Makefile.am @@ -0,0 +1,81 @@ +# -*- Mode: Makefile -*- +# +# Makefile.am - automake file for Ada2012 interface to Redland +# +# Copyright (C) 2014 Victor Porton - http://freesoft.portonvictor.org/ +# +# This package is Free Software and part of Redland http://librdf.org/ +# +# It is licensed under the following three licenses as alternatives: +# 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version +# 2. GNU General Public License (GPL) V2 or any newer version +# 3. Apache License, V2.0 or any newer version +# +# You may not use this file except in compliance with at least one of +# the above three licenses. +# +# See LICENSE.html or LICENSE.txt at the top of this package for the +# full license terms. +# +# + +soversion = 2.0.15 +soname = librdf-ada.so.$(soversion) + +ADAINCLUDE = $(includedir)/librdf +ADALIB = $(libdir)/librdf + +LIB_DIR = $(builddir)/lib + +EXTRA_DIST = librdf.gpr test.gpr src/*.ad[bs] src/test/*.ad[bs] + +# $(LIB_DIR)/librdf-ada.so: my-dynamic-lib + +if DEBUG +DEBUG_MODE=debug +else +DEBUG_MODE=release +endif + +GPRBUILD = @GPRBUILD@ --relocate-build-tree -p -s -we +GPRCLEAN = @GPRCLEAN@ +GPRINSTALL = @GPRINSTALL@ --prefix=$(prefix) --relocate-build-tree + +my-dynamic-lib: + $(GPRBUILD) librdf.gpr \ + -XLIBRARY_KIND=dynamic -XOBJ_DIR=$(builddir)/obj-dynamic -Xsoversion=$(soname) -XMODE=Install -XDEBUG_MODE=$(DEBUG_MODE) + +# $(LIB_DIR)/librdf-ada.a: my-static-lib + +my-static-lib: + $(GPRBUILD) librdf.gpr \ + -XLIBRARY_KIND=static -XOBJ_DIR=$(builddir)/obj-static -Xsoversion=$(soname) -XMODE=Install -XDEBUG_MODE=$(DEBUG_MODE) + +check-syntax: + $(GPRBUILD) librdf.gpr -c \ + -XLIBRARY_KIND=static -XOBJ_DIR=$(builddir)/obj-static -Xsoversion=$(soname) -XMODE=Install -XDEBUG_MODE=check + +all-local: my-dynamic-lib my-static-lib + +check-local: $(builddir)/obj-static/test/run_all_tests + $(builddir)/obj-static/test/run_all_tests $(srcdir) + +$(builddir)/obj-static/test/run_all_tests: my-static-lib + $(GPRBUILD) test.gpr \ + -XLIBRARY_KIND=static -XOBJ_DIR=$(builddir)/obj-static -XMODE=Install -XDEBUG_MODE=debug + +clean-local: + $(GPRCLEAN) -r librdf.gpr -XLIBRARY_KIND=dynamic -XOBJ_DIR=$(builddir)/obj-dynamic -Xsoversion=$(soname) -XMODE=Install + $(GPRCLEAN) -r librdf.gpr -XLIBRARY_KIND=static -XOBJ_DIR=$(builddir)/obj-static -Xsoversion=$(soname) -XMODE=Install + $(GPRCLEAN) -r test.gpr -XLIBRARY_KIND=static -XOBJ_DIR=$(builddir)/obj-static/test -Xsoversion=$(soname) -XMODE=Install +# rm -f $(builddir)/lib/$(soname) + +install-data-local: + $(GPRINSTALL) -f -p librdf.gpr -XLIBRARY_KIND=dynamic -XOBJ_DIR=$(builddir)/obj-dynamic -Xsoversion=$(soname) -XMODE=Install --build-name=dynamic + $(GPRINSTALL) -f -p librdf.gpr -XLIBRARY_KIND=static -XOBJ_DIR=$(builddir)/obj-static -Xsoversion=$(soname) -XMODE=Install --build-name=static + +uninstall-local: + $(GPRINSTALL) --uninstall -f -p librdf.gpr -XLIBRARY_KIND=dynamic -XOBJ_DIR=$(builddir)/obj-dynamic -Xsoversion=$(soname) -XMODE=Install + $(GPRINSTALL) --uninstall -f -p librdf.gpr -XLIBRARY_KIND=static -XOBJ_DIR=$(builddir)/obj-static -Xsoversion=$(soname) -XMODE=Install + +.PHONY: my-dynamic-lib my-static-lib check-syntax diff --git a/ada/README b/ada/README new file mode 100644 index 000000000..df063006a --- /dev/null +++ b/ada/README @@ -0,0 +1,56 @@ +This are thick object orienteed Ada2012 bindings for Redland +Raptor library. + +Backward incompatible API changes are possible at this stage. + +Some parts of RDF Syntax Library are not supported (I mean, not bound to +Ada): + +* AVL Trees (internals) +* SAX2 (use XMLAda instead) +* Sequence (internals) +* String buffer (use Ada code instead) +* Unicode (use an Ada library) +* XML QName (internals) +* XML (use XMLAda instead) +* Rasqal expressions (internals) +* Rasqal graph patterns (internals) +* Rasqal literals (internals) +* Rasqal prefixes (internals) +* Rasqal triples (internals) +* Rasqal triple sources (internals) +* Rasqal variables (internals) +* Rasqal variable tables (internals) +* Rasqal updates (internals) +* Rasqal utilities (internals) +* XSD related objects (not a priority to implement) +* Query Results Formatter +* Query Result Row (C API is too rudimentary) +* Service (requires Sequences which are not yet implemented) +* Redland Digests (internals) +* Redland Files (internals) +* Redland Hashes (internals) +* Redland Heuristics (internals) +* Redland List (internals) +* Redland Parser factories, Serializer factories, and query factories (internals) +* Redland Query limit and offset (not clear what should be Ada API) +* Redland Concepts + +The following APIs are implemented partially: + +* Rasqal Query +* Literals (not implemented things related to patterns) +* Redland iterators (we only use iterators, not construct them) +* Redland streams (we only use streams, not construct them) +* Triple stores (considered internals) + +It may be downgraded to Ada2005 but this isn't a priority for me. + +Documentation of the Ada bindings are not written yet. +Should we use GNATdoc or AdaBrowse? + +There are some unit tests (using AUnit library), but they do not cover +all code. I would not recommend to use this library for software which +should be highly reliable. + +-- Victor Porton diff --git a/ada/TODO b/ada/TODO new file mode 100644 index 000000000..463c5d896 --- /dev/null +++ b/ada/TODO @@ -0,0 +1,62 @@ +* Replace To_C with My_To_C_Without_Nul when needed (done?) + +* Consider replacing controlling argument types with class-wide types. + +* There are memory leaks in run_all_tests. + +* Add "pragma Pure()" where appropriate. + +* {Get,Set}_Feature for RDF.Redland.Serializer, + Get_Language, Get_Type of RDF.Rasqal.Literal + are not implemented due + http://bugs.librdf.org/mantis/view.php?id=641 + +* librdf_iterator_map_handler, librdf_iterator_map_free_context_handler, + librdf_new_iterator() are unimplemented. + +* librdf_new_storage_with_options() and + librdf_model_find_statements_with_options() not implemented, because + we have not implemented librdf_hash + +* Implement From_File and From_String in RDF.Rasqal.Data_Graph. + Note that as of Rasqal 0.9.32 they are not implemented in Rasqal. + So we probably should implement it as an Ada object not a binding. + The same for From_String in RDF.Rasqal.Query_Results, + Get_Language in RDF.Rasqal.Literal. + +* librdf_parser_get_uri_filter() and librdf_parser_set_uri_filter() + Should it be implemented as a primitive subprogram or as a separate object? + +* Add "limited" to records where appropriate. + +* Should Base_Stream be an interface rather than a tagged type? + +* Check sources with AdaControl and gnatcheck. + +* Add strings to exception raised. + +* Some raptor_parser_*() and librdf_storage_*() functions return <0 on missing + required base URI. Should we raise a different exception in this case? + Also librdf_parser_set_feature(), lib_rdf_model_set_feature(). + +* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82639 + Because of this GNAT compliler bug, some records which should be private + are not. + See rdf-raptor-term.ads + +* Consider if we can remove World argument in RDF.Rasqal.Bnode.Do_handle + and make the API the same as in RDF.Raptor.Bnode, possibly merging both + tagged types. + +* rasqal_new_query_results2() is not supported as of Rasqal 0.9.32 + installed on my system. + +* Rasqal and Redland iterators of query results should warn if more than one + iterator is created for single results object. (We should provide "debug + mode" for this.) + +* query_results_formatter and related functions + +* transactions in RDF.Redland.Model. + +* More testing. diff --git a/ada/libaunit-3.7.2/.pc/.quilt_patches b/ada/libaunit-3.7.2/.pc/.quilt_patches new file mode 100644 index 000000000..6857a8d44 --- /dev/null +++ b/ada/libaunit-3.7.2/.pc/.quilt_patches @@ -0,0 +1 @@ +debian/patches diff --git a/ada/libaunit-3.7.2/.pc/.quilt_series b/ada/libaunit-3.7.2/.pc/.quilt_series new file mode 100644 index 000000000..c2067066a --- /dev/null +++ b/ada/libaunit-3.7.2/.pc/.quilt_series @@ -0,0 +1 @@ +series diff --git a/ada/libaunit-3.7.2/.pc/.version b/ada/libaunit-3.7.2/.pc/.version new file mode 100644 index 000000000..0cfbf0888 --- /dev/null +++ b/ada/libaunit-3.7.2/.pc/.version @@ -0,0 +1 @@ +2 diff --git a/ada/libaunit-3.7.2/.pc/adapt_projects.diff/lib/gnat/aunit.gpr b/ada/libaunit-3.7.2/.pc/adapt_projects.diff/lib/gnat/aunit.gpr new file mode 100644 index 000000000..e7517db63 --- /dev/null +++ b/ada/libaunit-3.7.2/.pc/adapt_projects.diff/lib/gnat/aunit.gpr @@ -0,0 +1,58 @@ + +with "aunit_shared"; + +project AUnit is + + type Compilation_Mode_Type is ("Devel", "Install"); + Mode : Compilation_Mode_Type := external ("MODE", "Install"); + + for Source_Dirs use + ("../../include/aunit/framework", + "../../include/aunit/containers", + "../../include/aunit/reporters", + "../../include/aunit/framework/" & AUnit_Shared.Except, + "../../include/aunit/framework/" & AUnit_Shared.Calend, + "../../include/aunit/framework/" & AUnit_Shared.Memory); + + for Library_Dir use AUnit_Shared.Library_Dir; + + Obj_Dir := external ("OBJDIR", "../aunit-obj/" + & AUnit_Shared.Target & "-" & AUnit_Shared.Runtime); + for Object_Dir use Obj_Dir; + + for Library_Name use "aunit"; + for Library_Kind use "static"; + + -------------- + -- Compiler -- + -------------- + + package Compiler is + case Mode is + when "Devel" => + for Default_Switches ("ada") use + ("-g", "-gnatQ", "-O1", "-gnatf", "-gnato", + "-gnatwa.Xe", "-gnaty"); + + when "Install" => + for Default_Switches ("ada") use + ("-O2", "-gnatp", "-gnatn", "-gnatwa.X"); + end case; + + for Switches ("aunit.adb") use + Compiler'Default_Switches ("ada") & ("-fno-strict-aliasing"); + end Compiler; + + ------------- + -- Install -- + ------------- + + package Install is + for Artifacts ("share/doc/aunit") use + ("../../docs/*.html", "../../docs/*.info", + "../../docs/*.pdf", "../../docs/*.txt"); + for Artifacts ("share/gps/plug-ins") use ("../../support/aunit.xml"); + for Artifacts ("share/examples/aunit") use ("../../examples/*"); + end Install; + +end AUnit; diff --git a/ada/libaunit-3.7.2/.pc/adapt_projects.diff/lib/gnat/aunit_shared.gpr b/ada/libaunit-3.7.2/.pc/adapt_projects.diff/lib/gnat/aunit_shared.gpr new file mode 100644 index 000000000..294957ab6 --- /dev/null +++ b/ada/libaunit-3.7.2/.pc/adapt_projects.diff/lib/gnat/aunit_shared.gpr @@ -0,0 +1,43 @@ +project AUnit_Shared is + + Target := external ("PLATFORM", "native"); + + type Runtime_Type is + ("cert", "default", "full", "hi", "kernel", "kernel-sjlj", "kernel-smp", + "pthread", "sjlj", "ravenscar", "ravenscar-apex", "ravenscar-full", + "ravenscar-cert", "ravenscar-cert-rci", "ravenscar-cert-rtp", + "ravenscar-sfp", "rtp", + "rtp-smp", "soft-float", "xenomai", "zcx", "zfp", "minimal"); + Runtime : Runtime_Type := external ("RUNTIME", "full"); + + Library_Dir := external ("LIBDIR", "../aunit/" & Target & "-" & Runtime); + + for Source_Dirs use (); + + type Exception_Type is ("fullexception", "certexception", "zfpexception"); + type Calendar_Type is ("calendar", "nocalendar"); + type Memory_type is ("nativememory", "staticmemory"); + + Except : Exception_Type := "fullexception"; + Calend : Calendar_Type := "calendar"; + Memory : Memory_Type := "nativememory"; + + case Runtime is + when "hi" | "ravenscar-sfp" | "zfp" | "minimal" => + Except := "zfpexception"; + Calend := "nocalendar"; + Memory := "staticmemory"; + when "ravenscar-full" | "ravenscar" => + Except := "certexception"; + Calend := "nocalendar"; + when "ravenscar-cert" | "ravenscar-cert-rci" | "ravenscar-cert-rtp" => + Except := "certexception"; + Calend := "nocalendar"; + Memory := "staticmemory"; + when "cert" => + Except := "certexception"; + Memory := "staticmemory"; + when others => + end case; + +end AUnit_Shared; diff --git a/ada/libaunit-3.7.2/.pc/applied-patches b/ada/libaunit-3.7.2/.pc/applied-patches new file mode 100644 index 000000000..6e66b3bdc --- /dev/null +++ b/ada/libaunit-3.7.2/.pc/applied-patches @@ -0,0 +1,6 @@ +gpl.diff +adapt_projects.diff +path_doc_gps_plugin.diff +style_warnings.diff +info_directory_entry.diff +paths_in_doc.diff diff --git a/ada/libaunit-3.7.2/.pc/gpl.diff/docs/aunit.texi b/ada/libaunit-3.7.2/.pc/gpl.diff/docs/aunit.texi new file mode 100644 index 000000000..96147d6f4 --- /dev/null +++ b/ada/libaunit-3.7.2/.pc/gpl.diff/docs/aunit.texi @@ -0,0 +1,1619 @@ +\input texinfo @c -*-texinfo-*- + +@c AUnit Cookbook +@c Copyright (C) 2000-2015, AdaCore + +@c %**start of header +@setfilename aunit.info +@settitle AUnit Cookbook +@setchapternewpage odd +@syncodeindex fn cp + +@iftex +@afourpaper +@end iftex + +@c ----------------------------------------- MACRO + +@c Macro used for all AUnit examples +@c No cartouche on HTML as this is part of the css +@macro AEXP{TXT} +@ifhtml +@smallexample +@group +\TXT\ +@end group +@end smallexample +@end ifhtml +@ifnothtml +@cartouche +@smallexample +@group +\TXT\ +@end group +@end smallexample +@end cartouche +@end ifnothtml +@end macro + +@include version.texi +@set VERSION @value{MAJOR_VERSION}@value{MINOR_VERSION} + +@c ----------------------------------------- END MACRO + +@titlepage + +@title AUnit Cookbook +@subtitle AUnit - version @value{VERSION} +@subtitle Configuration level $Revision: 314387 $ +@subtitle Date: @today{} +@author AdaCore + +@sp 1 +@url{http://www.adacore.com} + +@vskip 0pt plus 1filll + +@page + +Copyright @copyright{} 2000-2014, AdaCore + +@* + +This document may be copied, in whole or in part, in any form or by any +means, as is or with alterations, provided that (1) alterations are clearly +marked as alterations and (2) this copyright notice is included +unmodified in any copy. + +@end titlepage + +@ifhtml +@c title page for the HTML documentation +@html + +

AUnit Cookbook +

AUnit - version @value{VERSION} +

Configuration level $Revision: 314387 $ +

Date: @today{} +

AdaCore + + + +

@url{http://www.adacore.com} + + +@page + +

Copyright @copyright{} 2000-2014, AdaCore + +

This document may be copied, in whole or in part, in any form or by any +means, as is or with alterations, provided that (1) alterations are clearly +marked as alterations and (2) this copyright notice is included +unmodified in any copy. +@end html +@end ifhtml + +@finalout + +@ifnothtml +@contents +@end ifnothtml + +@ifinfo + +@node Top +@top AUnit + +@menu +* Introduction:: +* Overview:: +* Test Cases:: +* Fixture:: +* Suite:: +* Reporting:: +* Test Organization:: +* Using AUnit with Restricted Run-Time Libraries:: +* Installation and Use:: +* GPS Support:: +@end menu +@end ifinfo + +@c ====================================================================== + +@node Introduction +@chapter Introduction + +@noindent +This is a short guide for using the AUnit test framework. +AUnit is an adaptation of the Java JUnit (Kent Beck, Erich Gamma) and C++ +CppUnit (M. Feathers, J. Lacoste, E. Sommerlade, B. Lepilleur, B. Bakker, +S. Robbins) unit test frameworks for Ada code. + +@c --------------------------- +@section What's new in AUnit 3 + +AUnit 3 brings several enhancements over AUnit 2 and AUnit 1: +@itemize + +@item Removal of the genericity of the AUnit framework, making the AUnit 3 +API as close as possible to AUnit 1. + +@item Emulates dynamic memory management for limited run-time profiles. + +@item Provides a new XML reporter, and changes harness invocation to support +easy switching among text, XML and customized reporters. + +@item Provides new tagged types Simple_Test_Case, Test_Fixture and +Test_Caller that correspond to CppUnit's TestCase, TestFixture and TestCaller +classes. + +@item Emulates exception propagation for restricted run-time profiles +(e.g. ZFP), by using the gcc builtin setjmp/longjmp mechanism. + +@item Reports the source location of an error when possible. + +@end itemize + +@c -------------- +@section Examples + +With this version, we have provided new examples illustrating the enhanced +features of the framework. These examples are in the AUnit +installation directory: +/share/examples/aunit, and are also available in the source +distribution aunit-@value{VERSION}-src/examples. + +The following examples are provided: +@itemize +@item simple_test: shows use of AUnit.Simple_Test_Cases +(@pxref{AUnit.Simple_Test_Cases}). +@item test_caller: shows use of AUnit.Test_Caller (@pxref{AUnit.Test_Caller}). +@item test_fixture: example of a test fixture (@pxref{Fixture}). +@item liskov: This suite tests conformance to the Liskov Substitution Principle +of a pair of simple tagged types. (@pxref{OOP considerations}) +@item failures: example of handling and reporting failed tests +(@pxref{Reporting}). +@item calculator: a full example of test suite organization. +@end itemize + +@c ---------------------------------- +@section Note about limited run-times + +AUnit allows a great deal of flexibility as to the structure of test cases, +suites and harnesses. The templates and examples given in this document +illustrate how to use AUnit while staying within the constraints of the +GNAT Pro restricted and Zero Foot Print (ZFP) run-time libraries. Therefore, +they avoid the use of dynamic allocation and some other features that would +be outside of the profiles corresponding to these libraries. Tests targeted +to the full Ada run-time library need not comply with these constraints. + +@c ------------ +@section Thanks + +This document is adapted from the JUnit and CppUnit Cookbooks documents +contained in their respective release packages. + +Special thanks to Francois Brun of Thales Avionics for his ideas about +support for OOP testing. + +@c ====================================================================== + +@node Overview +@chapter Overview + +How do you write testing code? + +The simplest way is as an expression in a debugger. You can change +debug expressions without recompiling, and you can wait to decide +what to write until you have seen the running objects. You can also +write test expressions as statements that print to the standard +output stream. Both styles of tests are limited because they require +human judgment to analyze their results. Also, they don't compose +nicely - you can only execute one debug expression at a time and a +program with too many print statements causes the dreaded "Scroll +Blindness". + +AUnit tests do not require human judgment to interpret, and it is +easy to run many of them at the same time. When you need to test +something, here is what you do: + +@enumerate + +@item Derive a test case type from @code{AUnit.Simple_Test_Cases.Test_Case}. + +Several test case types are available: +@itemize +@item @code{AUnit.Simple_Test_Cases.Test_Case}: the base type for all test +cases. Needs overriding of @code{Name} and @code{Run_Test}. +@item @code{AUnit.Test_Cases.Test_Case}: the traditional AUnit test case type, +allowing multiple test routines registration, each being run and reported +independently. +@item @code{AUnit.Test_Fixtures.Test_Fixture}: used together with +@code{AUnit.Test_Caller}, this allows easy creation of test suites comprising +several test cases that share the same fixture (@pxref{Fixture}). +@end itemize + +@xref{Test Cases}, for simple examples of use of these types. + +@item When you want to check a value@footnote{While JUnit and some other +members of the xUnit family of unit test frameworks provide specialized forms +of assertions (e.g. @code{assertEqual}), we took a design decision in AUnit +not to provide such forms. Ada has a much more rich type system giving a +plethora of possible scalar types, and leading to an explosion of possible +special forms of assert routines. This is exacerbated by the lack of a single +root type for most types, as is found in Java. With the introduction of +AUnit 2 for use with restricted run-time profiles, where even 'Image is +missing, providing a comprehensive set of special assert routines in the +framework itself becomes even more unrealistic. Since AUnit is intended to +be an extensible toolkit, users can certainly write their own custom +collection of such assert routines to suit local usage.}, use one of the +following @code{Assert}@footnote{Note that in AUnit 3, and contrary to +AUnit 2, the procedural form of @code{Assert} has the same behavior whatever +the underlying Ada run-time library: a failed assertion will cause the +execution of the calling test routine to be abandoned. The functional form of +@code{Assert} always continues on a failed assertion, and provides you +with a choice of behaviors.} methods: + +@AEXP{AUnit.Assertions.Assert (@b{Boolean_Expression}, @b{String_Description});} +or: +@AEXP{if not AUnit.Assertions.Assert (@b{Boolean_Expression}, @b{String_Description}) then + return; +end if;} + +If you need to test that a method raises an expected exception, there +is the procedure @code{Assert_Exception} that takes an access value designating the procedure +to be tested as a parameter: + +@AEXP{ + type Throwing_Exception_Proc is access procedure; + + procedure Assert_Exception + (Proc : Throwing_Exception_Proc; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line); + -- Test that Proc throws an exception and record "Message" if not. +} + +Example: + +@AEXP{ + -- Declared at library level: + procedure Test_Raising_Exception is + begin + call_to_the_tested_method (some_args); + end Test_Raising_Exception; + +-- In test routine: +procedure My_Routine (...) is +begin + Assert_Exception (Test_Raising_Exception'Access, @b{String_Description}); +end;} + +This procedure can handle exceptions with all run-time profiles (including +zfp). If you are using a run-time library capable of propagating exceptions, +you can use the following idiom instead: + +@AEXP{ + procedure My_Routine (...) is + begin + ... + -- Call subprogram expected to raise an exception: + Call_To_The_Tested_Method (some_args); + Assert (False, ``exception not raised''); + exception + when desired_exception => + null; + end My_Procedure;} + +An unexpected exception will be recorded as such by the framework. If you want +your test routine to continue beyond verifying that an expected exception has +been raised, you can nest the call and handler in a block. + +@item Create a suite function inside a package to gather together test cases +and sub-suites@footnote{If using the ZFP or the 'cert' run-time profiles, test + cases and suites must be allocated using + @code{AUnit.Memory.Utils.Gen_Alloc}, @code{AUnit.Test_Caller.Create}, + @code{AUnit.Test_Suites.New_Suite}, or be statically allocated.}. + +@item At any level at which you wish to run tests, create a harness by +instantiating procedure @code{AUnit.Run.Test_Runner} or function +@code{AUnit.Run.Test_Runner_With_Status} with the top-level suite +function to be executed. This instantiation provides a routine +that executes all of the tests in the suite. We will call this +user-instantiated routine @code{@b{Run}} in the text for backward compatibility +to tests developed for AUnit 1. Note that only one instance of @code{@b{Run}} +can execute at a time. This is a tradeoff made to reduce the stack requirement +of the framework by allocating test result reporting data structures +statically. + +It is possible to pass a filter to a @code{Test_Runner}, so that only a +subset of the tests run. In particular, this filter could be initialized from +a command line parameter. See the package @code{AUnit.Test_Filters} for an +example of such a filter. AUnit does not automatically initialize this filter +from the command line both because it would not be supported with some of the +limited runtimes (zero footprint for instance), and because you might want to +pass the argument through different ways (as a parameter to switch, or a stand-alone +command line argument for instance). + +It is also possible to control the contents of the output report by passing an +object of type @code{AUnit_Options} to the @code{Test_Runner}. See package +@code{AUnit.Options} for details. + +@item Build the code that calls the harness @code{@b{Run}} routine using +gnatmake or gprbuild. The GNAT project file @i{aunit.gpr} contains all +necessary switches, and should be imported into your root project file. + +@end enumerate + +@c ====================================================================== + +@node Test Cases +@chapter Test Case + +@menu +* AUnit.Simple_Test_Cases:: +* AUnit.Test_Cases:: +* AUnit.Test_Caller:: +@end menu + +@noindent +In this chapter, we will introduce how to use the various forms of Test +Cases. We will illustrate with a very simple test routine, that verifies +that the sum of two Moneys with the same currency result in a value +which is the sum of the values of the two Moneys: + +@AEXP{declare + X, Y: Some_Currency; +begin + X := 12; Y := 14; + Assert (X + Y = 26, "Addition is incorrect"); +end;} + +The following sections will show how to use this test method using the +different test case types available in AUnit. + +@c ----------------------------- +@node AUnit.Simple_Test_Cases +@section AUnit.Simple_Test_Cases + +@noindent +@code{AUnit.Simple_Test_Cases.Test_Case} is the root type of all test + cases. Although generally not meant to be used directly, it provides a + simple and quick way to run a test. + +This tagged type has several methods that need to be defined, or may be +overridden. + +@itemize +@item @code{function Name (T : Test_Case) return Message_String is abstract}: + +This function returns the Test name. You can easily translate regular +strings to Message_String using @code{AUnit.Format}. For example: + +@AEXP{function Name (@b{T} : @b{Money_Test}) return Message_String is +begin + return Format (@b{"Money Tests"}); +end Name;} + +@item @code{procedure Run_Test (T : in out Test_Case) is abstract}: + +This procedure contains the test code. For example: +@AEXP{procedure Run_Test (@b{T} : in out @b{Money_Test}) is + @b{X, Y: Some_Currency;} +begin + @b{X := 12; Y := 14;} + @b{Assert (X + Y = 26, "Addition is incorrect");} +end Run_Test;} + +@item @code{procedure Set_Up (T : in out Test_Case);} and @code{procedure +Tear_Down (T : in out Test_Case);} (default implementations do nothing): + +These procedures are meant to respectively set up or tear down the +environment before running the test case. @xref{Fixture}, for examples +of how to use these methods. + +@end itemize + +You can find a compilable example of +@code{AUnit.Simple_Test_Cases.Test_Case} usage in your AUnit installation +directory: /share/examples/aunit/simple_test/ or from the +source distribution aunit-@value{VERSION}-src/examples/simple_test/ + +@c ---------------------- +@node AUnit.Test_Cases +@section AUnit.Test_Cases + +@code{AUnit.Test_Cases.Test_Case} is derived from +@code{AUnit.Simple_Test_Cases.Test_Case} and defines its +@code{Run_Test} procedure. + +It allows a very flexible composition of Test routines inside a single +test case, each being reported independently. + +The following subprograms must be considered for inheritance, overriding or +completion: + +@itemize + +@item @code{function Name (T : Test_Case) return Message_String is abstract;} +Inherited. @xref{AUnit.Simple_Test_Cases}. + +@item @code{procedure Set_Up (T : in out Test_Case)} and @code{procedure +Tear_Down (T : in out Test_Case)} +Inherited. @xref{AUnit.Simple_Test_Cases}. + +@item @code{procedure Set_Up_Case (T : in out Test_Case)} and +@code{procedure Tear_Down_Case (T : in out Test_Case)} +Default implementation does nothing. + + +The latter procedures provide an opportunity to Set Up and Tear Down the test +case before and after all test routines have been executed. In contrast, the +inherited @code{Set_Up} and @code{Tear_Down} are called before and after the +execution of each individual test routine. + +@item @code{procedure Register_Tests (T : in out Test_Case) is +abstract} +This procedure must be overridden. It is responsible for registering all +the test routines that will be run. You need to use either +@code{Registration.Register_Routine} or the generic +@code{Specific_Test_Case.Register_Wrapper} methods defined in +@code{AUnit.Test_Cases} to register a routine. A test routine has the +form: +@AEXP{procedure Test_Routine (T : in out Test_Case'Class);} +or +@AEXP{procedure Test_Wrapper (T : in out Specific_Test_Case'Class);} + +The former procedure is used mainly for dispatching calls +(@pxref{OOP considerations}). + +@end itemize + +Using this type to test our money addition, the package spec is: + +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Cases; use AUnit.Test_Cases; + +package @b{Money_Tests} is + + type @b{Money_Test} is new Test_Cases.Test_Case with @b{null record}; + + procedure Register_Tests (@b{T}: in out @b{Money_Test}); + -- Register routines to be run + + function Name (@b{T}: @b{Money_Test}) return Message_String; + -- Provide name identifying the test case + + -- Test Routines: + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class); +end @b{Money_Tests};} + +The package body is: + +@AEXP{with AUnit.Assertions; use AUnit.Assertions; + +package body @b{Money_Tests} is + + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class) is + @b{X, Y : Some_Currency;} + begin + @b{X := 12; Y := 14;} + @b{Assert (X + Y = 26, "Addition is incorrect");} + end @b{Test_Simple_Add}; + + -- Register test routines to call + procedure Register_Tests (@b{T}: in out @b{Money_Test}) is + + use AUnit.Test_Cases.Registration; + + begin + -- Repeat for each test routine: + Register_Routine (@b{T}, @b{Test_Simple_Add}'Access, @b{"Test Addition"}); + end Register_Tests; + + -- Identifier of test case + + function Name (@b{T}: @b{Money_Test}) return Test_String is + begin + return Format (@b{"Money Tests"}); + end Name; + +end @b{Money_Tests};} + +@c ----------------------- +@node AUnit.Test_Caller +@section AUnit.Test_Caller + +@noindent +@code{Test_Caller} is a generic package that is used with +@code{AUnit.Test_Fixtures.Test_Fixture}. @code{Test_Fixture} is a very +simple type that provides only the @code{Set_Up} and @code{Tear_Down} +procedures. This type is meant to contain a set of user-defined test +routines, all using the same Set up and Tear down mechanisms. Once those +routines are defined, the Test_Caller package is used to incorporate them +directly into a test suite. + +With our money example, the Test_Fixture is: + +@AEXP{with AUnit.Test_Fixtures; +package @b{Money_Tests} is + type @b{Money_Test} is new AUnit.Test_Fixtures.Test_Fixture @b{with null record}; + + procedure @b{Test_Simple_Add} (@b{T} : in out @b{Money_Test}); + +end @b{Money_Tests};} + +The test suite (@pxref{Suite}) calling the test cases created from +this Test_Fixture is: + +@AEXP{with AUnit.Test_Suites; + +package Money_Suite is + function Suite return AUnit.Test_Suites.Access_Test_Suite; +end Money_Suite;} + +With the corresponding body: + +@AEXP{with AUnit.Test_Caller; +with Money_Tests; + +package body Money_Suite is + + package Money_Caller is new AUnit.Test_Caller + (Money_Tests.Money_Test); + + function Suite return Aunit.Test_Suites.Access_Test_Suite is + Ret : AUnit.Test_Suites.Access_Test_Suite := + AUnit.Test_Suites.New_Suite; + begin + Ret.Add_Test + (Money_Caller.Create + (@b{"Money Test : Test Addition"}, + @b{Money_Tests.Test_Simple_Add}'Access)); + return Ret; + end Suite; + +end Money_Suite;} + +Note that @code{New_Suite} and @code{Create} are fully compatible with +limited run-times (in particular, those without dynamic allocation support). +Note, however, that for non-native run-time libraries, you cannot extend +@code{Test_Fixture} with a controlled component. + +You can find a compilable example of +@code{AUnit.Test_Caller} use in the AUnit installation +directory: /share/examples/aunit/test_caller/ or from the +source distribution aunit-@value{VERSION}-src/examples/test_caller/ + +@c ====================================================================== + +@node Fixture +@chapter Fixture + +@noindent +Tests need to run against the background of a set of known entities. +This set is called a test fixture. When you are +writing tests you will often find that you spend more time writing +code to set up the fixture than you do in actually testing values. + +You can make writing fixture code easier by sharing it. +Often you will be able to use the same fixture for several different +tests. Each case will send slightly different messages or parameters to the +fixture and will check for different results. + +When you have a common fixture, here is what you do: + +@enumerate +@item Create a Test Case package as in previous section. + +@item Declare variables or components for elements of the fixture either +as part of the test case type or in the package body. + +@item According to the Test_Case type used, override its @code{Set_Up} +and/or @code{Set_Up_Case} method: + +@itemize +@item @code{AUnit.Simple_Test_Cases}: @code{Set_Up} is called before +@code{Run_Test}. + +@item @code{AUnit.Test_Cases}: @code{Set_Up} is called before each test +routine while @code{Set_Up_Case} is called once before the routines are run. + +@item @code{AUnit.Test_Fixture}: @code{Set_Up} is called before each +test case created using @code{Aunit.Test_Caller}. +@end itemize + +@item You can also override @code{Tear_Down} and/or +@code{Tear_Down_Case} that are executed after the test is run. + +@end enumerate + +@noindent +For example, to write several test cases that want to work with +different combinations of 12 Euros, 14 Euros, and 26 US Dollars, first +create a fixture. The package spec is now: + +@AEXP{with @b{AUnit}; use @b{AUnit}; + +package @b{Money_Tests} is + use Test_Results; + + type @b{Money_Test} is new Test_Cases.Test_Case with @b{null record}; + + procedure Register_Tests (@b{T}: in out @b{Money_Test}); + -- Register routines to be run + + function Name (@b{T} : @b{Money_Test}) return Test_String; + -- Provide name identifying the test case + + procedure Set_Up (@b{T} : in out @b{Money_Test}); + -- Set up performed before each test routine + + -- Test Routines: + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class); +end @b{Money_Tests};} + +The body becomes: + +@AEXP{package body @b{Money_Tests} is + + use Assertions; + + -- Fixture elements + + @b{EU_12, EU_14 : Euro; + US_26 : US_Dollar;} + + -- Preparation performed before each routine + + procedure Set_Up (@b{T}: in out @b{Money_Test}) is + begin + @b{EU_12 := 12; EU_14 := 14; + US_26 := 26;} + end Set_Up; + + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class) is + @b{X, Y : Some_Currency;} + begin + @b{Assert + (EU_12 + EU_14 /= US_26, + "US and EU currencies not differentiated");} + end @b{Test_Simple_Add}; + + -- Register test routines to call + procedure Register_Tests (@b{T}: in out @b{Money_Test}) is + + use @b{Test_Cases.Registration}; + + begin + -- Repeat for each test routine: + Register_Routine (@b{T}, @b{Test_Simple_Add}'Access, @b{"Test Addition"}); + end Register_Tests; + + -- Identifier of test case + function Name (@b{T}: @b{Money_Test}) return Test_String is + begin + return Format (@b{"Money Tests"}); + end Name; + +end @b{Money_Tests};} + +@noindent +Once you have the fixture in place, you can write as many test +routines as you like. Calls to @code{Set_Up} and @code{Tear_Down} +bracket the invocation of each test routine. + +Once you have several test cases, organize them into a Suite. + +You can find a compilable example of fixture set up using +@code{AUnit.Test_Fixture} in your AUnit installation +directory: /share/examples/aunit/test_fixture/ or from the +AUnit source distribution aunit-@value{VERSION}-src/examples/test_fixture/. + +@c ====================================================================== + +@node Suite +@chapter Suite + +@c --------------------------- +@section Creating a Test Suite + +How do you run several test cases at once? + +As soon as you have two tests, you'll want to run them together. +You could run the tests one at a time yourself, but you would quickly +grow tired of that. Instead, AUnit provides an object, @code{Test_Suite}, +that runs any number of test cases together. + +@noindent +To create a suite of two test cases and run them together, first create +a test suite: + +@AEXP{with AUnit.Test_Suites; +package @b{My_Suite} is + function @b{Suite} return AUnit.Test_Suites.Access_Test_Suite; +end @b{My_Suite};} + +@AEXP{-- Import tests and sub-suites to run +with @b{Test_Case_1, Test_Case_2}; + +package body @b{My_Suite} is + use AUnit.Test_Suites; + + -- Statically allocate test suite: + @b{Result} : aliased Test_Suite; + + -- Statically allocate test cases: + @b{Test_1 : aliased Test_Case_1.Test_Case;} + @b{Test_2 : aliased Test_Case_2.Test_Case;} + + function @b{Suite} return Access_Test_Suite is + begin + Add_Test (@b{Result'Access, Test_Case_1'Access}); + Add_Test (@b{Result'Access, Test_Case_2'Access}); + return @b{Result'Access}; + end @b{Suite}; +end @b{My_Suite};} + +Instead of statically allocating test cases and suites, +you can also use @code{AUnit.Test_Suites.New_Suite} and/or +@code{AUnit.Memory.Utils.Gen_Alloc}. These routines emulate dynamic +memory management (@pxref{Using AUnit with Restricted Run-Time Libraries}). +Similarly, if you know that the tests will always be executed for a run-time +profile that supports dynamic memory management, you can allocate these +objects directly with the Ada @code{"new"} operator. + +@noindent +The harness is: +@AEXP{with @b{My_Suite}; +with AUnit.Run; +with AUnit.Reporter.Text; + +procedure @b{My_Tests} is + procedure @b{Run} is new AUnit.Run.Test_Runner (@b{My_Suite.Suite}); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + @b{Run} (Reporter); +end @b{My_Tests};} + +@c --------------------------- +@section Composition of Suites + +@noindent +Typically, one will want the flexibility to execute a complete set +of tests, or some subset of them. In order to facilitate this, we can +compose both suites and test cases, and provide a harness for any given +suite: + +@AEXP{-- Composition package: +with @b{AUnit}; use @b{AUnit}; +package @b{Composite_Suite} is + function @b{Suite} return Test_Suites.Access_Test_Suite; +end @b{Composite_Suite}; + +-- Import tests and suites to run +with @b{This_Suite, That_Suite}; +with AUnit.Tests; + +package body @b{Composite_Suite} is + use Test_Suites; + + -- Here we dynamically allocate the suite using the New_Suite function + -- We use the 'Suite' functions provided in This_Suite and That_Suite + -- We also use Ada 2005 distinguished receiver notation to call Add_Test + + function @b{Suite} return Access_Test_Suite is + @b{Result} : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + @b{Result}.Add_Test (@b{This_Suite.Suite}); + @b{Result}.Add_Test (@b{That_Suite.Suite}); + return @b{Result}; + end @b{Suite}; +end @b{Composite_Suite};} + +@noindent +The harness remains the same: + +@AEXP{with @b{Composite_Suite}; +with AUnit.Run; + +procedure @b{My_Tests} is + procedure @b{Run} is new AUnit.Run.Test_Runner (@b{Composite_Suite.Suite}); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + @b{Run} (Reporter); +end @b{My_Tests};} + +@noindent +As can be seen, this is a very flexible way of composing test cases +into execution runs: any combination of test cases and sub-suites can +be collected into a suite. + +@c ====================================================================== + +@node Reporting +@chapter Reporting + +Test results can be reported using several 'Reporters'. By default, two +reporters are available in AUnit: +@code{AUnit.Reporter.Text.Text_Reporter} and +@code{AUnit.Reporter.XML.XML_Reporter}. The first one is a simple +console reporting routine, while the second one outputs the result using +an XML format. These are invoked when the @code{Run} routine of an +instantiation of @code{AUnit.Run.Test_Runner} is called. + +@noindent +New reporters can be created using children of +@code{AUnit.Reporter.Reporter}. + +@noindent +The Reporter is selected by specifying it when calling @b{Run}: + +@AEXP{with A_Suite; +with AUnit.Run; +@b{with AUnit.Reporter.Text;} + +procedure My_Tests is + procedure Run is new AUnit.Run.Test_Runner (A_Suite.Suite); + @b{Reporter : AUnit.Reporter.Text.Text_Reporter;} +begin + Run (@b{Reporter}); +end My_Tests;} + +The final report is output once all tests have been run, so that they can be +grouped depending on their status (passed or fail). If you need to output the +tests as they are run, you should consider extending the @code{Test_Result} +type and do some output every time a success or failure is registered. + +@section Text output + +Here is an example where the test harness runs 4 tests, one reporting an +assertion failure, one reporting an unexpected error (exception): + +@smallexample +-------------------- + + Total Tests Run: 4 + + Successful Tests: 2 + Test addition + Test subtraction + + Failed Assertions: 1 + + Test addition (failure expected) + Test should fail this assertion, as 5+3 /= 9 + at math-test.adb:29 + + + Unexpected Errors: 1 + + Test addition (error expected) + CONSTRAINT_ERROR + + + +Time: 2.902E-4 seconds +@end smallexample + +@cindex colors +This reporter can optionally use colors (green to report success, red to report +errors). Since not all consoles support it, this is off by default, but you can +call @code{Set_Use_ANSI_Colors} to activate support for colors. + +@section XML output + +Following is the same harness run using XML output. The XML format used +matches the one used by CppUnit. + +Note that text set in the Assert methods, or as test case names should +be compatible with utf-8 character encoding, or the XML will not be +correctly formatted. + +@smallexample + + + + 4 + 2 + 1 + 1 + + + + Test addition + + + Test subtraction + + + + + Test addition (failure expected) + Assertion + Test should fail this assertion, as 5+3 /= 9 + + math-test.adb + 29 + + + + Test addition (error expected) + Error + CONSTRAINT_ERROR + + + +@end smallexample + +@c ====================================================================== + +@node Test Organization +@chapter Test Organization + +@menu +* General considerations:: +* OOP considerations:: +* Testing generic units:: +@end menu + +@c --------------------------- +@node General considerations +@section General considerations + +This section will discuss an approach to organizing an AUnit test harness, +considering some possibilities offered by Ada language features. + +The general idea behind this approach to test organization is that making the +test case a child of the unit under test gives some useful facilities. +The test case gains visibility to the private part of the unit under test. +This offers a more ``white box'' approach to examining the state of the unit +under test than would, for instance, accessor functions defined in a separate +fixture that is a child of the unit under test. Making the test case a child of +the unit under test also provides a way to make the test case share certain +characteristics of the unit under test. For instance, if the unit under test +is generic, then any child package (here the test case) must be also generic: +any instantiation of the parent package will require an instantiation of the +test case in order to accomplish its aims. + +Another useful concept is matching the test case type to that of the unit +under test: + +@itemize +@item When testing a generic package, the test package should also be +generic. +@item When testing a tagged type, then test routines should be +dispatching, and the test case type for a derived tagged type should be a +derivation of the test case type for the parent. +@item etc. +@end itemize + +Maintaining such similarity of properties between the test case and unit under +test can facilitate the testing of units derived in various ways. + +The following sections will concentrate on applying these concepts to +the testing of tagged type hierarchies and to the testing of generic units. + +A full example of this kind of test organization is available in the AUnit +installation directory: /share/examples/aunit/calculator, or +from the AUnit source distribution +aunit-@value{VERSION}-src/examples/calculator. + +@c --------------------------- +@node OOP considerations +@section OOP considerations + +When testing a hierarchy of tagged types, one will often want to run tests +for parent types against their derivations without rewriting those tests. + +We will illustrate some of the possible solutions available in AUnit, +using the following simple example that we want to test: + +First we consider a @code{Root} package defining the @code{Parent} +tagged type, with two procedures P1 and P2. + +@AEXP{package Root is + type Parent is tagged private; + + procedure P1 (P : in out Parent); + procedure P2 (P : in out Parent); +private + type Parent is tagged record + Some_Value : Some_Type; + end record; +end Root;} + +We will also consider a derivation of type @code{Parent}: + +@AEXP{with Root; +package Branch is + type Child is new Root.Parent with private; + + procedure P2 (C : in out Child); + procedure P3 (C : in out Child); +private + type Child is new Root.Parent with null record; +end Branch;} + +@noindent +Note that @code{Child} retains the parent implementation of @code{P1}, +overrides @code{P2} and adds @code{P3}. Its test will override +@code{Test_P2} when we override @code{P2} (not necessary, but certainly +possible). + +@subsection Using AUnit.Test_Fixtures + +@noindent +Using @code{Test_Fixture} type, we first test @code{Parent} using the +following test case: +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Fixtures; use AUnit.Test_Fixtures; + +-- We make this package a child package of Parent so that it can have +-- visibility to its private part +package @b{Root.Tests} is + + type @b{Parent_Access} is access all @b{Root.Parent'Class}; + + -- Reference an object of type Parent'Class in the test object, so + -- that test procedures can have access to it. + type @b{Parent_Test} is new Test_Fixture @b{with record} + @b{Fixture : Parent_Access;} + @b{end record}; + + -- This will initialize P. + procedure Set_Up (@b{P} : in out @b{Parent_Test}); + + -- Test routines. If derived types are declared in child packages, + -- these can be in the private part. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}); + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}); + +end @b{Root.Tests}; + +package body @b{Root.Tests} is + + @b{Fixture : aliased Parent;} + + -- We set Fixture in Parent_Test to an object of type Parent. + procedure Set_Up (@b{P} : in out @b{Parent_Test}) is + begin + @b{P.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up; + + -- Test routines: References to the Parent object are made via + -- P.Fixture.all, and are thus dispatching. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}) is ...; + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}) is ...; + +end @b{Root.Tests};} + +@noindent +The associated test suite will be: + +@AEXP{with AUnit.Test_Caller; +with @b{Root.Tests}; + +package body @b{Root_Suite} is + package @b{Caller} is new AUnit.Test_Caller with (@b{Root.Tests.Parent_Test}); + + function Suite return AUnit.Test_Suites.Access_Test_Suite is + @b{Ret} : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + AUnit.Test_Suites.Add_Test + (@b{Ret}, Caller.Create (@b{"Test Parent : P1"}, @b{Root.Tests.Test_P1'Access})); + AUnit.Test_Suites.Add_Test + (@b{Ret}, Caller.Create (@b{"Test Parent : P2"}, @b{Root.Tests.Test_P2'Access})); + return @b{Ret}; + end Suite; +end @b{Root_Suite};} + +@noindent +Now we define the test suite for the @code{Child} type. To do this, +we inherit a test fixture from @code{Parent_Test}, +overriding the @code{Set_Up} procedure to initialize @code{Fixture} with +a @code{Child} object. We also override @code{Test_P2} to adapt it +to the new implementation. We define a new @code{Test_P3} to test +@code{P3}. And we inherit @code{Test_P1}, since @code{P1} is unchanged. + +@AEXP{with @b{Root.Tests}; use @b{Root.Tests}; +with AUnit; use AUnit; +with AUnit.Test_Fixtures; use AUnit.Test_Fixtures; + +package @b{Branch.Tests} is + + type @b{Child_Test} is new @b{Parent_Test} @b{with null record}; + + procedure Set_Up (@b{C} : in out @b{Child_Test}); + + -- Test routines: + -- Test_P2 is overridden + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}); + -- Test_P3 is new + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}); + +end @b{Branch.Tests}; + +package body @b{Branch.Tests} is + use Assertions; + + @b{Fixture : Child;} + -- This could also be a field of Child_Test + + procedure Set_Up (@b{C} : in out @b{Child_Test}) is + begin + -- The Fixture for this test will now be a Child + @b{C.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up; + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}) is ...; + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}) is ...; + +end @b{Branch.Tests};} + +The suite for Branch.Tests will now be: + +@AEXP{with AUnit.Test_Caller; +with @b{Branch.Tests}; + +package body @b{Branch_Suite} is + package @b{Caller} is new AUnit.Test_Caller with (@b{Branch.Tests.Parent_Test}); + + -- In this suite, we use Ada 2005 distinguished receiver notation to + -- simplify the code. + + function Suite return Access_Test_Suite is + Ret : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + -- We use the inherited Test_P1. Note that it is + -- Branch.Tests.Set_Up that will be called, and so Test_P1 will be run + -- against an object of type Child + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P1"}, @b{Branch.Tests.Test_P1'Access})); + -- We use the overridden Test_P2 + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P2"}, @b{Branch.Tests.Test_P2'Access})); + -- We use the new Test_P2 + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P3"}, @b{Branch.Tests.Test_P3'Access})); + return @b{Ret}; + end Suite; +end @b{Branch_Suite};} + +@subsection Using AUnit.Test_Cases + +@noindent +Using an @code{AUnit.Test_Cases.Test_Case} derived type, we obtain the +following code for testing @code{Parent}: + +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Cases; +package @b{Root.Tests} is + + type @b{Parent_Access} is access all @b{Root.Parent'Class}; + + type @b{Parent_Test} is new AUnit.Test_Cases.Test_Case @b{with record} + @b{Fixture : Parent_Access;} + @b{end record}; + + function Name (@b{P} : @b{Parent_Test}) return Message_String; + procedure Register_Tests (@b{P} : in out @b{Parent_Test}); + + procedure Set_Up_Case (@b{P} : in out @b{Parent_Test}); + + -- Test routines. If derived types are declared in child packages, + -- these can be in the private part. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}); + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}); + +end @b{Root.Tests};} + +@noindent +The body of the test case will follow the usual pattern, declaring one or +more objects of type @code{@b{Parent}}, and executing statements in the +test routines against them. However, in order to support dispatching to +overriding routines of derived test cases, we need to introduce class-wide +wrapper routines for each primitive test routine of the parent type that +we anticipate may be overridden. Instead of registering the parent's +overridable primitive operations directly using @code{Register_Routine}, +we register the wrapper using @code{Register_Wrapper}. This latter routine +is exported by instantiating +@code{@b{AUnit}.Test_Cases.Specific_Test_Case_Registration} with the actual +parameter being the parent test case type. + +@AEXP{with AUnit.Assertions; use AUnit.Assertions +package body @b{Root.Tests} is + + -- Declare class-wide wrapper routines for any test routines that will be + -- overridden: + procedure @b{Test_P1_Wrapper} (@b{P} : in out @b{Parent_Test}'Class); + procedure @b{Test_P2_Wrapper} (@b{P} : in out @b{Parent_Test}'Class); + + function Name (@b{P} : @b{Parent_Test}) return Message_String is ...; + + -- Set the fixture in P + @b{Fixture : aliased Parent;} + procedure Set_Up_Case (@b{P} : in out @b{Parent_Test}) is + begin + @b{P.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up_Case; + + -- Register Wrappers: + procedure Register_Tests (@b{P} : in out @b{Parent_Test}) is + + package @b{Register_Specific} is + new Test_Cases.Specific_Test_Case_Registration (@b{Parent_Test}); + + use Register_Specific; + + begin + Register_Wrapper (@b{P}, @b{Test_P1_Wrapper}'Access, @b{"Test P1"}); + Register_Wrapper (@b{P}, @b{Test_P2_Wrapper}'Access, @b{"Test P2"}); + end Register_Tests; + + -- Test routines: + procedure @b{Test_P1} (@b{P} : in out Parent_Test) is ...; + procedure @b{Test_P2} (@b{C} : in out Parent_Test) is ...; + + -- Wrapper routines. These dispatch to the corresponding primitive + -- test routines of the specific types. + procedure @b{Test_P1_Wrapper} (@b{P} : in out @b{Parent_Test}'Class) is + begin + @b{Test_P1} (@b{P}); + end @b{Test_P1_Wrapper}; + + procedure @b{Test_P2_Wrapper} (@b{P} : in out @b{Parent_Test}'Class) is + begin + @b{Test_P2} (@b{P}); + end @b{Test_P2_Wrapper}; + +end @b{Root.Tests};} + +@noindent +The code for testing the @code{Child} type will now be: + +@AEXP{with @b{Parent_Tests}; use @b{Parent_Tests}; +with AUnit; use AUnit; +package @b{Branch.Tests} is + + type @b{Child_Test} is new @b{Parent_Test} @b{with private}; + + function Name (@b{C} : @b{Child_Test}) return Message_String; + procedure Register_Tests (@b{C} : in out @b{Child_Test}); + + -- Override Set_Up_Case so that the fixture changes. + procedure Set_Up_Case (@b{C} : in out @b{Child_Test}); + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}); + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}); + +private + type @b{Child_Test} is new @b{Parent_Test} @b{with null record}; +end @b{Branch.Tests}; + +with AUnit.Assertions; use AUnit.Assertions; +package body @b{Branch.Tests} is + + -- Declare wrapper for Test_P3: + procedure @b{Test_P3_Wrapper} (@b{C} : in out @b{Child_Test}'Class); + + function Name (@b{C} : @b{Child_Test}) return Test_String is ...; + + procedure Register_Tests (@b{C} : in out @b{Child_Test}) is + + package @b{Register_Specific} is + new Test_Cases.Specific_Test_Case_Registration (@b{Child_Test}); + use @b{Register_Specific}; + + begin + -- Register parent tests for P1 and P2: + @b{Parent_Tests}.Register_Tests (@b{Parent_Test} (@b{C})); + + -- Repeat for each new test routine (Test_P3 in this case): + @b{Register_Wrapper} (@b{C}, @b{Test_P3_Wrapper}'Access, @b{"Test P3"}); + end Register_Tests; + + -- Set the fixture in P + @b{Fixture : aliased Child;} + procedure Set_Up_Case (@b{C} : in out @b{Child_Test}) is + begin + @b{C.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up_Case; + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}) is ...; + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}) is ...; + + -- Wrapper for new routine: + procedure @b{Test_P3_Wrapper} (@b{C} : in out @b{Child_Test}'Class) is + begin + @b{Test_P3} (@b{C}); + end @b{Test_P3_Wrapper}; + +end @b{Branch.Tests};} + +@noindent +Note that inherited and overridden tests do not need to be explicitly +re-registered in derived test cases - one just calls the parent version of +@code{Register_Tests}. If the application tagged type hierarchy is organized +into parent and child units, one could also organize the test cases into a +hierarchy that reflects that of the units under test. + +@c --------------------------- +@node Testing generic units +@section Testing generic units + +When testing generic units, one would like to apply the same generic tests +to all instantiations in an application. A simple approach is to make the +test case a child package of the unit under test (which then must also be +generic). + +For instance, suppose the generic unit under test is a package (it could +be a subprogram, and the same principle would apply): +@AEXP{generic + -- Formal parameter list +package Template is + -- Declarations +end Template;} + +@noindent +The corresponding test case would be: +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Fixtures; +generic +package @b{Template.Gen_Tests} is + + type @b{Template_Test} is new AUnit.Test_Fixtures.Test_Fixture with @b{...}; + + -- Declare test routines + +end @b{Template.Gen_Tests};} + +The body will follow the usual patterns with the fixture based on the +parent package @code{Template}. Note that due to an Ada AI, accesses to +test routines, along with the test routine specifications, must be defined +in the package specification rather than in its body. + +Instances of @code{Template} will define automatically the Tests child +package that can be directly instantiated as follow: + +@AEXP{with Template.Gen_Test; +with Instance_Of_Template; +package Instance_Of_Template.Tests is new Instance_Of_Template.Gen_Test;} + +The instantiated test case objects are added to a suite in the usual manner. + +@c ================================================================= + +@node Using AUnit with Restricted Run-Time Libraries +@chapter Using AUnit with Restricted Run-Time Libraries + +@noindent +AUnit 3 - like AUnit 2 - is designed so that it can be used in +environments with restricted Ada run-time libraries, such as ZFP and the cert +run-time profile on Wind River Systems' VxWorks 653. The patterns given in +this document for writing tests, suites and harnesses are not the only +patterns that can be used with AUnit, but they are compatible with the +restricted run-time libraries provided with GNAT Pro. + +In general, dynamic allocation and deallocation must be used carefully in test +code. For the cert profile on VxWorks 653, all dynamic allocation must be +done prior to setting the application partition into ``normal'' mode. +Deallocation is prohibited in this profile. For the default ZFP profile, +dynamic memory management is not provided as part of the run-time, as it is +not available on a bare board environment, and should not be used unless +you have provided implementations as described in the GNAT Pro High Integrity +User Guide. + +Starting with AUnit 3, a simple memory management mechanism has been +included in the framework, using a kind of storage pool. This memory +management mechanism uses a static array allocated at startup, and simulates +dynamic allocation afterwards by allocating parts of this array upon request. +Deallocation is not permitted. + +By default, the allocated array is a 100 KB array. This value can be changed +by modifying its size in the file: +@file{aunit-@value{VERSION}-src/aunit/framework/staticmemory/aunit-memory.adb} + +To allocate a new object, you use @code{AUnit.Memory.Utils.Gen_Alloc}. + +Additional restrictions relevant to the default ZFP profile include: +@enumerate +@item +Normally the ZFP profile requires a user-defined +@code{__gnat_last_chance_handler} routine +to handle raised exceptions. However, AUnit now provides a mechanism to +simulate exception propagation using gcc builtin setjmp/longjmp mechanism. +This mechanism defines the @code{__gnat_last_chance_handler} routine, so it +should not be redefined elsewhere. In order to be compatible with this +restriction, the user-defined last chance handler routine can be defined as a +"weak" symbol; this way, it will still be linked into the standalone executable, +but will be replaced by the AUnit implementation when linked with the harness. +The pragma Weak_External can be used for that, e.g.: + +@smallexample +pragma Weak_External (Last_Chance_Handler); +@end smallexample + +@item +AUnit requires @code{GNAT.IO} provided in @file{g-io.ad?} in the full or cert +profile run-time library sources (or as implemented by the user). Since this +is a run-time library unit it must be compiled with the gnatmake ``-a'' +switch. + +@item +The AUnit framework has been modified so that no call to the secondary +stack is performed, nor any call to memcpy or memset. However, if the unit +under test, or the tests themselves require use of those routines, then the +application or test framework must define those symbols and provide the +requisite implementations. + +@item +The timed parameter of the Harness @code{Run} routine has no effect when used +with the ZFP profile, and on profiles not supporting Ada.Calendar. +@end enumerate + +@node Installation and Use +@chapter Installation and Use + +@menu +* Note on gprbuild:: +* Support for other platforms/run-times:: +* Installing AUnit:: +* Installed files:: +@end menu + +@noindent +AUnit 3 contains support for limited run-times such as zero-foot-print +(ZFP) and certified run-time (cert). It can now be installed simultaneously +for several targets and run-times. + +@c -------------------------------------- +@node Note on gprbuild +@section Note on gprbuild + +@noindent +In order to compile, install and use AUnit, you need gprbuild and gprinstall +version 2.2.0 or above. + +@c --------------------------------------------------------- +@node Support for other platforms/run-times +@section Support for other platforms/run-times + +AUnit should be built and installed separately for each target and run-time +it is meant to be used with. The necessary customizations are performed at +AUnit build time, so once the framework is installed, it is always referenced +simply by adding the line + +@smallexample +with "aunit"; +@end smallexample + +to your project. + +@c -------------------------------------- +@node Installing AUnit +@section Installing AUnit + +@noindent +Normally AUnit comes preinstalled and ready-to-use for all runtimes in +your GNAT distribution. The following instructions are for rebuilding it from +sources for the custom configuration that the user may have. + +@itemize +@item +Extract the archive: +@smallexample + $ gunzip -dc aunit-@value{VERSION}-src.tgz | tar xf - +@end smallexample + +@item +To build AUnit for a full Ada run-time: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make +@end smallexample + +To build AUnit for a zfp run-time targeting powerpc-elf platform: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make TARGET=powerpc-elf RTS=zfp +@end smallexample + +To build AUnit for a reconfigurable runtime zfp-leon3 targeting leon3-elf +platform: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make TARGET=leon3-elf RTS=zfp RTS_CONF="--RTS=zfp-leon3" +@end smallexample + + +Once the above build procedure has been performed for the desired platform, you +can install AUnit: +@smallexample + $ make install INSTALL= +@end smallexample + +We recommend that you install AUnit into the standard location used by gprbuild +to find the libraries for a given configuration. For example for the case above +(runtime zfp-leon3 targeting leon3-elf), the default location is +/leon3-elf/zfp-leon3. If the runtime is located in a custom +directory and specified by the full path, using this exact path also as + is a sensible choice. + +If INSTALL is not specified, then AUnit will use the root directory where +gprbuild is installed. + +@item +Specific installation: + + The AUnit makefile supports some specific options, activated using + environment variables. The following options are defined: + +@itemize +@item @b{INSTALL}: defines the AUnit base installation directory, set to +gprbuild's base installation directory as found in the PATH. + +@item @b{TARGET}: defines the gnat tools prefix to use. For example, to compile +AUnit for powerpc VxWorks, TARGET should be set to powerpc-wrs-vxworks. If not +set, the native compiler will be used. + +@item @b{RTS}: defines both the run-time used to compile AUnit and the value +given to the AUnit project as RUNTIME scenario variable. + +@item @b{RTS_CONF}: defines the gprbuild Runtime config flag. The value is +set to "--RTS=$(RTS)" by default. Can be used when compiling AUnit for a +configurable run-time. +@end itemize + +@item +To test AUnit: + + The AUnit test suite is in the test subdirectory of the source package. +@smallexample + $ cd test + $ make +@end smallexample + The test suite's makefile supports the following variables: + @itemize + @item @b{RTS} + @item @b{TARGET} + @end itemize +@end itemize + + +@c --------------------- +@node Installed files +@section Installed files + +@noindent +The AUnit library is installed in the specified directory ( +identifies the root installation directory as specified during the installation +procedures above): + +@itemize +@item + the aunit.gpr project is installed in /lib/gnat +@item + the AUnit source files are installed in /include/aunit +@item + the AUnit library files are installed in /lib/aunit +@item + the AUnit documentation is installed in /share/doc/aunit +@item + the AUnit examples are installed in /share/examples/aunit +@end itemize + +@node GPS Support +@chapter GPS Support + +@noindent +GPS IDE relies on gnattest tool that creates unit-test skeletons as well as +a test driver infrastructure (harness). Harness can be generated for project +hierarchy, single project or a package. Generation process can be launched +from @b{Tools -> GNATtest} menu or from contextual menu. + +@bye diff --git a/ada/libaunit-3.7.2/.pc/info_directory_entry.diff/docs/aunit.texi b/ada/libaunit-3.7.2/.pc/info_directory_entry.diff/docs/aunit.texi new file mode 100644 index 000000000..029111bd5 --- /dev/null +++ b/ada/libaunit-3.7.2/.pc/info_directory_entry.diff/docs/aunit.texi @@ -0,0 +1,1611 @@ +\input texinfo @c -*-texinfo-*- + +@c AUnit Cookbook +@c Copyright (C) 2000-2015, AdaCore + +@c %**start of header +@setfilename aunit.info +@settitle AUnit Cookbook +@setchapternewpage odd +@syncodeindex fn cp + +@iftex +@afourpaper +@end iftex + +@c ----------------------------------------- MACRO + +@c Macro used for all AUnit examples +@c No cartouche on HTML as this is part of the css +@macro AEXP{TXT} +@ifhtml +@smallexample +@group +\TXT\ +@end group +@end smallexample +@end ifhtml +@ifnothtml +@cartouche +@smallexample +@group +\TXT\ +@end group +@end smallexample +@end cartouche +@end ifnothtml +@end macro + +@include version.texi +@set VERSION @value{MAJOR_VERSION}@value{MINOR_VERSION} + +@c ----------------------------------------- END MACRO + +@titlepage + +@title AUnit Cookbook +@subtitle AUnit - version @value{VERSION} +@subtitle Configuration level $Revision: 314387 $ +@subtitle Date: @today{} +@author AdaCore + +@sp 1 +@url{http://www.adacore.com} + +@vskip 0pt plus 1filll + +@page + +Copyright @copyright{} 2000-2014, AdaCore + +@end titlepage + +@ifhtml +@c title page for the HTML documentation +@html + +

AUnit Cookbook +

AUnit - version @value{VERSION} +

Configuration level $Revision: 314387 $ +

Date: @today{} +

AdaCore + + + +

@url{http://www.adacore.com} + + +@page + +

Copyright @copyright{} 2000-2014, AdaCore + +

This document is licensed under the GNU General Public License, +either version 3 of the License, or (at your option) any later version. + +@end html +@end ifhtml + +@finalout + +@ifnothtml +@contents +@end ifnothtml + +@ifinfo + +@node Top +@top AUnit + +@menu +* Introduction:: +* Overview:: +* Test Cases:: +* Fixture:: +* Suite:: +* Reporting:: +* Test Organization:: +* Using AUnit with Restricted Run-Time Libraries:: +* Installation and Use:: +* GPS Support:: +@end menu +@end ifinfo + +@c ====================================================================== + +@node Introduction +@chapter Introduction + +@noindent +This is a short guide for using the AUnit test framework. +AUnit is an adaptation of the Java JUnit (Kent Beck, Erich Gamma) and C++ +CppUnit (M. Feathers, J. Lacoste, E. Sommerlade, B. Lepilleur, B. Bakker, +S. Robbins) unit test frameworks for Ada code. + +@c --------------------------- +@section What's new in AUnit 3 + +AUnit 3 brings several enhancements over AUnit 2 and AUnit 1: +@itemize + +@item Removal of the genericity of the AUnit framework, making the AUnit 3 +API as close as possible to AUnit 1. + +@item Emulates dynamic memory management for limited run-time profiles. + +@item Provides a new XML reporter, and changes harness invocation to support +easy switching among text, XML and customized reporters. + +@item Provides new tagged types Simple_Test_Case, Test_Fixture and +Test_Caller that correspond to CppUnit's TestCase, TestFixture and TestCaller +classes. + +@item Emulates exception propagation for restricted run-time profiles +(e.g. ZFP), by using the gcc builtin setjmp/longjmp mechanism. + +@item Reports the source location of an error when possible. + +@end itemize + +@c -------------- +@section Examples + +With this version, we have provided new examples illustrating the enhanced +features of the framework. These examples are in the AUnit +installation directory: +/share/examples/aunit, and are also available in the source +distribution aunit-@value{VERSION}-src/examples. + +The following examples are provided: +@itemize +@item simple_test: shows use of AUnit.Simple_Test_Cases +(@pxref{AUnit.Simple_Test_Cases}). +@item test_caller: shows use of AUnit.Test_Caller (@pxref{AUnit.Test_Caller}). +@item test_fixture: example of a test fixture (@pxref{Fixture}). +@item liskov: This suite tests conformance to the Liskov Substitution Principle +of a pair of simple tagged types. (@pxref{OOP considerations}) +@item failures: example of handling and reporting failed tests +(@pxref{Reporting}). +@item calculator: a full example of test suite organization. +@end itemize + +@c ---------------------------------- +@section Note about limited run-times + +AUnit allows a great deal of flexibility as to the structure of test cases, +suites and harnesses. The templates and examples given in this document +illustrate how to use AUnit while staying within the constraints of the +GNAT Pro restricted and Zero Foot Print (ZFP) run-time libraries. Therefore, +they avoid the use of dynamic allocation and some other features that would +be outside of the profiles corresponding to these libraries. Tests targeted +to the full Ada run-time library need not comply with these constraints. + +@c ------------ +@section Thanks + +This document is adapted from the JUnit and CppUnit Cookbooks documents +contained in their respective release packages. + +Special thanks to Francois Brun of Thales Avionics for his ideas about +support for OOP testing. + +@c ====================================================================== + +@node Overview +@chapter Overview + +How do you write testing code? + +The simplest way is as an expression in a debugger. You can change +debug expressions without recompiling, and you can wait to decide +what to write until you have seen the running objects. You can also +write test expressions as statements that print to the standard +output stream. Both styles of tests are limited because they require +human judgment to analyze their results. Also, they don't compose +nicely - you can only execute one debug expression at a time and a +program with too many print statements causes the dreaded "Scroll +Blindness". + +AUnit tests do not require human judgment to interpret, and it is +easy to run many of them at the same time. When you need to test +something, here is what you do: + +@enumerate + +@item Derive a test case type from @code{AUnit.Simple_Test_Cases.Test_Case}. + +Several test case types are available: +@itemize +@item @code{AUnit.Simple_Test_Cases.Test_Case}: the base type for all test +cases. Needs overriding of @code{Name} and @code{Run_Test}. +@item @code{AUnit.Test_Cases.Test_Case}: the traditional AUnit test case type, +allowing multiple test routines registration, each being run and reported +independently. +@item @code{AUnit.Test_Fixtures.Test_Fixture}: used together with +@code{AUnit.Test_Caller}, this allows easy creation of test suites comprising +several test cases that share the same fixture (@pxref{Fixture}). +@end itemize + +@xref{Test Cases}, for simple examples of use of these types. + +@item When you want to check a value@footnote{While JUnit and some other +members of the xUnit family of unit test frameworks provide specialized forms +of assertions (e.g. @code{assertEqual}), we took a design decision in AUnit +not to provide such forms. Ada has a much more rich type system giving a +plethora of possible scalar types, and leading to an explosion of possible +special forms of assert routines. This is exacerbated by the lack of a single +root type for most types, as is found in Java. With the introduction of +AUnit 2 for use with restricted run-time profiles, where even 'Image is +missing, providing a comprehensive set of special assert routines in the +framework itself becomes even more unrealistic. Since AUnit is intended to +be an extensible toolkit, users can certainly write their own custom +collection of such assert routines to suit local usage.}, use one of the +following @code{Assert}@footnote{Note that in AUnit 3, and contrary to +AUnit 2, the procedural form of @code{Assert} has the same behavior whatever +the underlying Ada run-time library: a failed assertion will cause the +execution of the calling test routine to be abandoned. The functional form of +@code{Assert} always continues on a failed assertion, and provides you +with a choice of behaviors.} methods: + +@AEXP{AUnit.Assertions.Assert (@b{Boolean_Expression}, @b{String_Description});} +or: +@AEXP{if not AUnit.Assertions.Assert (@b{Boolean_Expression}, @b{String_Description}) then + return; +end if;} + +If you need to test that a method raises an expected exception, there +is the procedure @code{Assert_Exception} that takes an access value designating the procedure +to be tested as a parameter: + +@AEXP{ + type Throwing_Exception_Proc is access procedure; + + procedure Assert_Exception + (Proc : Throwing_Exception_Proc; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line); + -- Test that Proc throws an exception and record "Message" if not. +} + +Example: + +@AEXP{ + -- Declared at library level: + procedure Test_Raising_Exception is + begin + call_to_the_tested_method (some_args); + end Test_Raising_Exception; + +-- In test routine: +procedure My_Routine (...) is +begin + Assert_Exception (Test_Raising_Exception'Access, @b{String_Description}); +end;} + +This procedure can handle exceptions with all run-time profiles (including +zfp). If you are using a run-time library capable of propagating exceptions, +you can use the following idiom instead: + +@AEXP{ + procedure My_Routine (...) is + begin + ... + -- Call subprogram expected to raise an exception: + Call_To_The_Tested_Method (some_args); + Assert (False, ``exception not raised''); + exception + when desired_exception => + null; + end My_Procedure;} + +An unexpected exception will be recorded as such by the framework. If you want +your test routine to continue beyond verifying that an expected exception has +been raised, you can nest the call and handler in a block. + +@item Create a suite function inside a package to gather together test cases +and sub-suites@footnote{If using the ZFP or the 'cert' run-time profiles, test + cases and suites must be allocated using + @code{AUnit.Memory.Utils.Gen_Alloc}, @code{AUnit.Test_Caller.Create}, + @code{AUnit.Test_Suites.New_Suite}, or be statically allocated.}. + +@item At any level at which you wish to run tests, create a harness by +instantiating procedure @code{AUnit.Run.Test_Runner} or function +@code{AUnit.Run.Test_Runner_With_Status} with the top-level suite +function to be executed. This instantiation provides a routine +that executes all of the tests in the suite. We will call this +user-instantiated routine @code{@b{Run}} in the text for backward compatibility +to tests developed for AUnit 1. Note that only one instance of @code{@b{Run}} +can execute at a time. This is a tradeoff made to reduce the stack requirement +of the framework by allocating test result reporting data structures +statically. + +It is possible to pass a filter to a @code{Test_Runner}, so that only a +subset of the tests run. In particular, this filter could be initialized from +a command line parameter. See the package @code{AUnit.Test_Filters} for an +example of such a filter. AUnit does not automatically initialize this filter +from the command line both because it would not be supported with some of the +limited runtimes (zero footprint for instance), and because you might want to +pass the argument through different ways (as a parameter to switch, or a stand-alone +command line argument for instance). + +It is also possible to control the contents of the output report by passing an +object of type @code{AUnit_Options} to the @code{Test_Runner}. See package +@code{AUnit.Options} for details. + +@item Build the code that calls the harness @code{@b{Run}} routine using +gnatmake or gprbuild. The GNAT project file @i{aunit.gpr} contains all +necessary switches, and should be imported into your root project file. + +@end enumerate + +@c ====================================================================== + +@node Test Cases +@chapter Test Case + +@menu +* AUnit.Simple_Test_Cases:: +* AUnit.Test_Cases:: +* AUnit.Test_Caller:: +@end menu + +@noindent +In this chapter, we will introduce how to use the various forms of Test +Cases. We will illustrate with a very simple test routine, that verifies +that the sum of two Moneys with the same currency result in a value +which is the sum of the values of the two Moneys: + +@AEXP{declare + X, Y: Some_Currency; +begin + X := 12; Y := 14; + Assert (X + Y = 26, "Addition is incorrect"); +end;} + +The following sections will show how to use this test method using the +different test case types available in AUnit. + +@c ----------------------------- +@node AUnit.Simple_Test_Cases +@section AUnit.Simple_Test_Cases + +@noindent +@code{AUnit.Simple_Test_Cases.Test_Case} is the root type of all test + cases. Although generally not meant to be used directly, it provides a + simple and quick way to run a test. + +This tagged type has several methods that need to be defined, or may be +overridden. + +@itemize +@item @code{function Name (T : Test_Case) return Message_String is abstract}: + +This function returns the Test name. You can easily translate regular +strings to Message_String using @code{AUnit.Format}. For example: + +@AEXP{function Name (@b{T} : @b{Money_Test}) return Message_String is +begin + return Format (@b{"Money Tests"}); +end Name;} + +@item @code{procedure Run_Test (T : in out Test_Case) is abstract}: + +This procedure contains the test code. For example: +@AEXP{procedure Run_Test (@b{T} : in out @b{Money_Test}) is + @b{X, Y: Some_Currency;} +begin + @b{X := 12; Y := 14;} + @b{Assert (X + Y = 26, "Addition is incorrect");} +end Run_Test;} + +@item @code{procedure Set_Up (T : in out Test_Case);} and @code{procedure +Tear_Down (T : in out Test_Case);} (default implementations do nothing): + +These procedures are meant to respectively set up or tear down the +environment before running the test case. @xref{Fixture}, for examples +of how to use these methods. + +@end itemize + +You can find a compilable example of +@code{AUnit.Simple_Test_Cases.Test_Case} usage in your AUnit installation +directory: /share/examples/aunit/simple_test/ or from the +source distribution aunit-@value{VERSION}-src/examples/simple_test/ + +@c ---------------------- +@node AUnit.Test_Cases +@section AUnit.Test_Cases + +@code{AUnit.Test_Cases.Test_Case} is derived from +@code{AUnit.Simple_Test_Cases.Test_Case} and defines its +@code{Run_Test} procedure. + +It allows a very flexible composition of Test routines inside a single +test case, each being reported independently. + +The following subprograms must be considered for inheritance, overriding or +completion: + +@itemize + +@item @code{function Name (T : Test_Case) return Message_String is abstract;} +Inherited. @xref{AUnit.Simple_Test_Cases}. + +@item @code{procedure Set_Up (T : in out Test_Case)} and @code{procedure +Tear_Down (T : in out Test_Case)} +Inherited. @xref{AUnit.Simple_Test_Cases}. + +@item @code{procedure Set_Up_Case (T : in out Test_Case)} and +@code{procedure Tear_Down_Case (T : in out Test_Case)} +Default implementation does nothing. + + +The latter procedures provide an opportunity to Set Up and Tear Down the test +case before and after all test routines have been executed. In contrast, the +inherited @code{Set_Up} and @code{Tear_Down} are called before and after the +execution of each individual test routine. + +@item @code{procedure Register_Tests (T : in out Test_Case) is +abstract} +This procedure must be overridden. It is responsible for registering all +the test routines that will be run. You need to use either +@code{Registration.Register_Routine} or the generic +@code{Specific_Test_Case.Register_Wrapper} methods defined in +@code{AUnit.Test_Cases} to register a routine. A test routine has the +form: +@AEXP{procedure Test_Routine (T : in out Test_Case'Class);} +or +@AEXP{procedure Test_Wrapper (T : in out Specific_Test_Case'Class);} + +The former procedure is used mainly for dispatching calls +(@pxref{OOP considerations}). + +@end itemize + +Using this type to test our money addition, the package spec is: + +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Cases; use AUnit.Test_Cases; + +package @b{Money_Tests} is + + type @b{Money_Test} is new Test_Cases.Test_Case with @b{null record}; + + procedure Register_Tests (@b{T}: in out @b{Money_Test}); + -- Register routines to be run + + function Name (@b{T}: @b{Money_Test}) return Message_String; + -- Provide name identifying the test case + + -- Test Routines: + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class); +end @b{Money_Tests};} + +The package body is: + +@AEXP{with AUnit.Assertions; use AUnit.Assertions; + +package body @b{Money_Tests} is + + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class) is + @b{X, Y : Some_Currency;} + begin + @b{X := 12; Y := 14;} + @b{Assert (X + Y = 26, "Addition is incorrect");} + end @b{Test_Simple_Add}; + + -- Register test routines to call + procedure Register_Tests (@b{T}: in out @b{Money_Test}) is + + use AUnit.Test_Cases.Registration; + + begin + -- Repeat for each test routine: + Register_Routine (@b{T}, @b{Test_Simple_Add}'Access, @b{"Test Addition"}); + end Register_Tests; + + -- Identifier of test case + + function Name (@b{T}: @b{Money_Test}) return Test_String is + begin + return Format (@b{"Money Tests"}); + end Name; + +end @b{Money_Tests};} + +@c ----------------------- +@node AUnit.Test_Caller +@section AUnit.Test_Caller + +@noindent +@code{Test_Caller} is a generic package that is used with +@code{AUnit.Test_Fixtures.Test_Fixture}. @code{Test_Fixture} is a very +simple type that provides only the @code{Set_Up} and @code{Tear_Down} +procedures. This type is meant to contain a set of user-defined test +routines, all using the same Set up and Tear down mechanisms. Once those +routines are defined, the Test_Caller package is used to incorporate them +directly into a test suite. + +With our money example, the Test_Fixture is: + +@AEXP{with AUnit.Test_Fixtures; +package @b{Money_Tests} is + type @b{Money_Test} is new AUnit.Test_Fixtures.Test_Fixture @b{with null record}; + + procedure @b{Test_Simple_Add} (@b{T} : in out @b{Money_Test}); + +end @b{Money_Tests};} + +The test suite (@pxref{Suite}) calling the test cases created from +this Test_Fixture is: + +@AEXP{with AUnit.Test_Suites; + +package Money_Suite is + function Suite return AUnit.Test_Suites.Access_Test_Suite; +end Money_Suite;} + +With the corresponding body: + +@AEXP{with AUnit.Test_Caller; +with Money_Tests; + +package body Money_Suite is + + package Money_Caller is new AUnit.Test_Caller + (Money_Tests.Money_Test); + + function Suite return Aunit.Test_Suites.Access_Test_Suite is + Ret : AUnit.Test_Suites.Access_Test_Suite := + AUnit.Test_Suites.New_Suite; + begin + Ret.Add_Test + (Money_Caller.Create + (@b{"Money Test : Test Addition"}, + @b{Money_Tests.Test_Simple_Add}'Access)); + return Ret; + end Suite; + +end Money_Suite;} + +Note that @code{New_Suite} and @code{Create} are fully compatible with +limited run-times (in particular, those without dynamic allocation support). +Note, however, that for non-native run-time libraries, you cannot extend +@code{Test_Fixture} with a controlled component. + +You can find a compilable example of +@code{AUnit.Test_Caller} use in the AUnit installation +directory: /share/examples/aunit/test_caller/ or from the +source distribution aunit-@value{VERSION}-src/examples/test_caller/ + +@c ====================================================================== + +@node Fixture +@chapter Fixture + +@noindent +Tests need to run against the background of a set of known entities. +This set is called a test fixture. When you are +writing tests you will often find that you spend more time writing +code to set up the fixture than you do in actually testing values. + +You can make writing fixture code easier by sharing it. +Often you will be able to use the same fixture for several different +tests. Each case will send slightly different messages or parameters to the +fixture and will check for different results. + +When you have a common fixture, here is what you do: + +@enumerate +@item Create a Test Case package as in previous section. + +@item Declare variables or components for elements of the fixture either +as part of the test case type or in the package body. + +@item According to the Test_Case type used, override its @code{Set_Up} +and/or @code{Set_Up_Case} method: + +@itemize +@item @code{AUnit.Simple_Test_Cases}: @code{Set_Up} is called before +@code{Run_Test}. + +@item @code{AUnit.Test_Cases}: @code{Set_Up} is called before each test +routine while @code{Set_Up_Case} is called once before the routines are run. + +@item @code{AUnit.Test_Fixture}: @code{Set_Up} is called before each +test case created using @code{Aunit.Test_Caller}. +@end itemize + +@item You can also override @code{Tear_Down} and/or +@code{Tear_Down_Case} that are executed after the test is run. + +@end enumerate + +@noindent +For example, to write several test cases that want to work with +different combinations of 12 Euros, 14 Euros, and 26 US Dollars, first +create a fixture. The package spec is now: + +@AEXP{with @b{AUnit}; use @b{AUnit}; + +package @b{Money_Tests} is + use Test_Results; + + type @b{Money_Test} is new Test_Cases.Test_Case with @b{null record}; + + procedure Register_Tests (@b{T}: in out @b{Money_Test}); + -- Register routines to be run + + function Name (@b{T} : @b{Money_Test}) return Test_String; + -- Provide name identifying the test case + + procedure Set_Up (@b{T} : in out @b{Money_Test}); + -- Set up performed before each test routine + + -- Test Routines: + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class); +end @b{Money_Tests};} + +The body becomes: + +@AEXP{package body @b{Money_Tests} is + + use Assertions; + + -- Fixture elements + + @b{EU_12, EU_14 : Euro; + US_26 : US_Dollar;} + + -- Preparation performed before each routine + + procedure Set_Up (@b{T}: in out @b{Money_Test}) is + begin + @b{EU_12 := 12; EU_14 := 14; + US_26 := 26;} + end Set_Up; + + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class) is + @b{X, Y : Some_Currency;} + begin + @b{Assert + (EU_12 + EU_14 /= US_26, + "US and EU currencies not differentiated");} + end @b{Test_Simple_Add}; + + -- Register test routines to call + procedure Register_Tests (@b{T}: in out @b{Money_Test}) is + + use @b{Test_Cases.Registration}; + + begin + -- Repeat for each test routine: + Register_Routine (@b{T}, @b{Test_Simple_Add}'Access, @b{"Test Addition"}); + end Register_Tests; + + -- Identifier of test case + function Name (@b{T}: @b{Money_Test}) return Test_String is + begin + return Format (@b{"Money Tests"}); + end Name; + +end @b{Money_Tests};} + +@noindent +Once you have the fixture in place, you can write as many test +routines as you like. Calls to @code{Set_Up} and @code{Tear_Down} +bracket the invocation of each test routine. + +Once you have several test cases, organize them into a Suite. + +You can find a compilable example of fixture set up using +@code{AUnit.Test_Fixture} in your AUnit installation +directory: /share/examples/aunit/test_fixture/ or from the +AUnit source distribution aunit-@value{VERSION}-src/examples/test_fixture/. + +@c ====================================================================== + +@node Suite +@chapter Suite + +@c --------------------------- +@section Creating a Test Suite + +How do you run several test cases at once? + +As soon as you have two tests, you'll want to run them together. +You could run the tests one at a time yourself, but you would quickly +grow tired of that. Instead, AUnit provides an object, @code{Test_Suite}, +that runs any number of test cases together. + +@noindent +To create a suite of two test cases and run them together, first create +a test suite: + +@AEXP{with AUnit.Test_Suites; +package @b{My_Suite} is + function @b{Suite} return AUnit.Test_Suites.Access_Test_Suite; +end @b{My_Suite};} + +@AEXP{-- Import tests and sub-suites to run +with @b{Test_Case_1, Test_Case_2}; + +package body @b{My_Suite} is + use AUnit.Test_Suites; + + -- Statically allocate test suite: + @b{Result} : aliased Test_Suite; + + -- Statically allocate test cases: + @b{Test_1 : aliased Test_Case_1.Test_Case;} + @b{Test_2 : aliased Test_Case_2.Test_Case;} + + function @b{Suite} return Access_Test_Suite is + begin + Add_Test (@b{Result'Access, Test_Case_1'Access}); + Add_Test (@b{Result'Access, Test_Case_2'Access}); + return @b{Result'Access}; + end @b{Suite}; +end @b{My_Suite};} + +Instead of statically allocating test cases and suites, +you can also use @code{AUnit.Test_Suites.New_Suite} and/or +@code{AUnit.Memory.Utils.Gen_Alloc}. These routines emulate dynamic +memory management (@pxref{Using AUnit with Restricted Run-Time Libraries}). +Similarly, if you know that the tests will always be executed for a run-time +profile that supports dynamic memory management, you can allocate these +objects directly with the Ada @code{"new"} operator. + +@noindent +The harness is: +@AEXP{with @b{My_Suite}; +with AUnit.Run; +with AUnit.Reporter.Text; + +procedure @b{My_Tests} is + procedure @b{Run} is new AUnit.Run.Test_Runner (@b{My_Suite.Suite}); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + @b{Run} (Reporter); +end @b{My_Tests};} + +@c --------------------------- +@section Composition of Suites + +@noindent +Typically, one will want the flexibility to execute a complete set +of tests, or some subset of them. In order to facilitate this, we can +compose both suites and test cases, and provide a harness for any given +suite: + +@AEXP{-- Composition package: +with @b{AUnit}; use @b{AUnit}; +package @b{Composite_Suite} is + function @b{Suite} return Test_Suites.Access_Test_Suite; +end @b{Composite_Suite}; + +-- Import tests and suites to run +with @b{This_Suite, That_Suite}; +with AUnit.Tests; + +package body @b{Composite_Suite} is + use Test_Suites; + + -- Here we dynamically allocate the suite using the New_Suite function + -- We use the 'Suite' functions provided in This_Suite and That_Suite + -- We also use Ada 2005 distinguished receiver notation to call Add_Test + + function @b{Suite} return Access_Test_Suite is + @b{Result} : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + @b{Result}.Add_Test (@b{This_Suite.Suite}); + @b{Result}.Add_Test (@b{That_Suite.Suite}); + return @b{Result}; + end @b{Suite}; +end @b{Composite_Suite};} + +@noindent +The harness remains the same: + +@AEXP{with @b{Composite_Suite}; +with AUnit.Run; + +procedure @b{My_Tests} is + procedure @b{Run} is new AUnit.Run.Test_Runner (@b{Composite_Suite.Suite}); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + @b{Run} (Reporter); +end @b{My_Tests};} + +@noindent +As can be seen, this is a very flexible way of composing test cases +into execution runs: any combination of test cases and sub-suites can +be collected into a suite. + +@c ====================================================================== + +@node Reporting +@chapter Reporting + +Test results can be reported using several 'Reporters'. By default, two +reporters are available in AUnit: +@code{AUnit.Reporter.Text.Text_Reporter} and +@code{AUnit.Reporter.XML.XML_Reporter}. The first one is a simple +console reporting routine, while the second one outputs the result using +an XML format. These are invoked when the @code{Run} routine of an +instantiation of @code{AUnit.Run.Test_Runner} is called. + +@noindent +New reporters can be created using children of +@code{AUnit.Reporter.Reporter}. + +@noindent +The Reporter is selected by specifying it when calling @b{Run}: + +@AEXP{with A_Suite; +with AUnit.Run; +@b{with AUnit.Reporter.Text;} + +procedure My_Tests is + procedure Run is new AUnit.Run.Test_Runner (A_Suite.Suite); + @b{Reporter : AUnit.Reporter.Text.Text_Reporter;} +begin + Run (@b{Reporter}); +end My_Tests;} + +The final report is output once all tests have been run, so that they can be +grouped depending on their status (passed or fail). If you need to output the +tests as they are run, you should consider extending the @code{Test_Result} +type and do some output every time a success or failure is registered. + +@section Text output + +Here is an example where the test harness runs 4 tests, one reporting an +assertion failure, one reporting an unexpected error (exception): + +@smallexample +-------------------- + + Total Tests Run: 4 + + Successful Tests: 2 + Test addition + Test subtraction + + Failed Assertions: 1 + + Test addition (failure expected) + Test should fail this assertion, as 5+3 /= 9 + at math-test.adb:29 + + + Unexpected Errors: 1 + + Test addition (error expected) + CONSTRAINT_ERROR + + + +Time: 2.902E-4 seconds +@end smallexample + +@cindex colors +This reporter can optionally use colors (green to report success, red to report +errors). Since not all consoles support it, this is off by default, but you can +call @code{Set_Use_ANSI_Colors} to activate support for colors. + +@section XML output + +Following is the same harness run using XML output. The XML format used +matches the one used by CppUnit. + +Note that text set in the Assert methods, or as test case names should +be compatible with utf-8 character encoding, or the XML will not be +correctly formatted. + +@smallexample + + + + 4 + 2 + 1 + 1 + + + + Test addition + + + Test subtraction + + + + + Test addition (failure expected) + Assertion + Test should fail this assertion, as 5+3 /= 9 + + math-test.adb + 29 + + + + Test addition (error expected) + Error + CONSTRAINT_ERROR + + + +@end smallexample + +@c ====================================================================== + +@node Test Organization +@chapter Test Organization + +@menu +* General considerations:: +* OOP considerations:: +* Testing generic units:: +@end menu + +@c --------------------------- +@node General considerations +@section General considerations + +This section will discuss an approach to organizing an AUnit test harness, +considering some possibilities offered by Ada language features. + +The general idea behind this approach to test organization is that making the +test case a child of the unit under test gives some useful facilities. +The test case gains visibility to the private part of the unit under test. +This offers a more ``white box'' approach to examining the state of the unit +under test than would, for instance, accessor functions defined in a separate +fixture that is a child of the unit under test. Making the test case a child of +the unit under test also provides a way to make the test case share certain +characteristics of the unit under test. For instance, if the unit under test +is generic, then any child package (here the test case) must be also generic: +any instantiation of the parent package will require an instantiation of the +test case in order to accomplish its aims. + +Another useful concept is matching the test case type to that of the unit +under test: + +@itemize +@item When testing a generic package, the test package should also be +generic. +@item When testing a tagged type, then test routines should be +dispatching, and the test case type for a derived tagged type should be a +derivation of the test case type for the parent. +@item etc. +@end itemize + +Maintaining such similarity of properties between the test case and unit under +test can facilitate the testing of units derived in various ways. + +The following sections will concentrate on applying these concepts to +the testing of tagged type hierarchies and to the testing of generic units. + +A full example of this kind of test organization is available in the AUnit +installation directory: /share/examples/aunit/calculator, or +from the AUnit source distribution +aunit-@value{VERSION}-src/examples/calculator. + +@c --------------------------- +@node OOP considerations +@section OOP considerations + +When testing a hierarchy of tagged types, one will often want to run tests +for parent types against their derivations without rewriting those tests. + +We will illustrate some of the possible solutions available in AUnit, +using the following simple example that we want to test: + +First we consider a @code{Root} package defining the @code{Parent} +tagged type, with two procedures P1 and P2. + +@AEXP{package Root is + type Parent is tagged private; + + procedure P1 (P : in out Parent); + procedure P2 (P : in out Parent); +private + type Parent is tagged record + Some_Value : Some_Type; + end record; +end Root;} + +We will also consider a derivation of type @code{Parent}: + +@AEXP{with Root; +package Branch is + type Child is new Root.Parent with private; + + procedure P2 (C : in out Child); + procedure P3 (C : in out Child); +private + type Child is new Root.Parent with null record; +end Branch;} + +@noindent +Note that @code{Child} retains the parent implementation of @code{P1}, +overrides @code{P2} and adds @code{P3}. Its test will override +@code{Test_P2} when we override @code{P2} (not necessary, but certainly +possible). + +@subsection Using AUnit.Test_Fixtures + +@noindent +Using @code{Test_Fixture} type, we first test @code{Parent} using the +following test case: +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Fixtures; use AUnit.Test_Fixtures; + +-- We make this package a child package of Parent so that it can have +-- visibility to its private part +package @b{Root.Tests} is + + type @b{Parent_Access} is access all @b{Root.Parent'Class}; + + -- Reference an object of type Parent'Class in the test object, so + -- that test procedures can have access to it. + type @b{Parent_Test} is new Test_Fixture @b{with record} + @b{Fixture : Parent_Access;} + @b{end record}; + + -- This will initialize P. + procedure Set_Up (@b{P} : in out @b{Parent_Test}); + + -- Test routines. If derived types are declared in child packages, + -- these can be in the private part. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}); + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}); + +end @b{Root.Tests}; + +package body @b{Root.Tests} is + + @b{Fixture : aliased Parent;} + + -- We set Fixture in Parent_Test to an object of type Parent. + procedure Set_Up (@b{P} : in out @b{Parent_Test}) is + begin + @b{P.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up; + + -- Test routines: References to the Parent object are made via + -- P.Fixture.all, and are thus dispatching. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}) is ...; + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}) is ...; + +end @b{Root.Tests};} + +@noindent +The associated test suite will be: + +@AEXP{with AUnit.Test_Caller; +with @b{Root.Tests}; + +package body @b{Root_Suite} is + package @b{Caller} is new AUnit.Test_Caller with (@b{Root.Tests.Parent_Test}); + + function Suite return AUnit.Test_Suites.Access_Test_Suite is + @b{Ret} : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + AUnit.Test_Suites.Add_Test + (@b{Ret}, Caller.Create (@b{"Test Parent : P1"}, @b{Root.Tests.Test_P1'Access})); + AUnit.Test_Suites.Add_Test + (@b{Ret}, Caller.Create (@b{"Test Parent : P2"}, @b{Root.Tests.Test_P2'Access})); + return @b{Ret}; + end Suite; +end @b{Root_Suite};} + +@noindent +Now we define the test suite for the @code{Child} type. To do this, +we inherit a test fixture from @code{Parent_Test}, +overriding the @code{Set_Up} procedure to initialize @code{Fixture} with +a @code{Child} object. We also override @code{Test_P2} to adapt it +to the new implementation. We define a new @code{Test_P3} to test +@code{P3}. And we inherit @code{Test_P1}, since @code{P1} is unchanged. + +@AEXP{with @b{Root.Tests}; use @b{Root.Tests}; +with AUnit; use AUnit; +with AUnit.Test_Fixtures; use AUnit.Test_Fixtures; + +package @b{Branch.Tests} is + + type @b{Child_Test} is new @b{Parent_Test} @b{with null record}; + + procedure Set_Up (@b{C} : in out @b{Child_Test}); + + -- Test routines: + -- Test_P2 is overridden + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}); + -- Test_P3 is new + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}); + +end @b{Branch.Tests}; + +package body @b{Branch.Tests} is + use Assertions; + + @b{Fixture : Child;} + -- This could also be a field of Child_Test + + procedure Set_Up (@b{C} : in out @b{Child_Test}) is + begin + -- The Fixture for this test will now be a Child + @b{C.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up; + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}) is ...; + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}) is ...; + +end @b{Branch.Tests};} + +The suite for Branch.Tests will now be: + +@AEXP{with AUnit.Test_Caller; +with @b{Branch.Tests}; + +package body @b{Branch_Suite} is + package @b{Caller} is new AUnit.Test_Caller with (@b{Branch.Tests.Parent_Test}); + + -- In this suite, we use Ada 2005 distinguished receiver notation to + -- simplify the code. + + function Suite return Access_Test_Suite is + Ret : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + -- We use the inherited Test_P1. Note that it is + -- Branch.Tests.Set_Up that will be called, and so Test_P1 will be run + -- against an object of type Child + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P1"}, @b{Branch.Tests.Test_P1'Access})); + -- We use the overridden Test_P2 + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P2"}, @b{Branch.Tests.Test_P2'Access})); + -- We use the new Test_P2 + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P3"}, @b{Branch.Tests.Test_P3'Access})); + return @b{Ret}; + end Suite; +end @b{Branch_Suite};} + +@subsection Using AUnit.Test_Cases + +@noindent +Using an @code{AUnit.Test_Cases.Test_Case} derived type, we obtain the +following code for testing @code{Parent}: + +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Cases; +package @b{Root.Tests} is + + type @b{Parent_Access} is access all @b{Root.Parent'Class}; + + type @b{Parent_Test} is new AUnit.Test_Cases.Test_Case @b{with record} + @b{Fixture : Parent_Access;} + @b{end record}; + + function Name (@b{P} : @b{Parent_Test}) return Message_String; + procedure Register_Tests (@b{P} : in out @b{Parent_Test}); + + procedure Set_Up_Case (@b{P} : in out @b{Parent_Test}); + + -- Test routines. If derived types are declared in child packages, + -- these can be in the private part. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}); + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}); + +end @b{Root.Tests};} + +@noindent +The body of the test case will follow the usual pattern, declaring one or +more objects of type @code{@b{Parent}}, and executing statements in the +test routines against them. However, in order to support dispatching to +overriding routines of derived test cases, we need to introduce class-wide +wrapper routines for each primitive test routine of the parent type that +we anticipate may be overridden. Instead of registering the parent's +overridable primitive operations directly using @code{Register_Routine}, +we register the wrapper using @code{Register_Wrapper}. This latter routine +is exported by instantiating +@code{@b{AUnit}.Test_Cases.Specific_Test_Case_Registration} with the actual +parameter being the parent test case type. + +@AEXP{with AUnit.Assertions; use AUnit.Assertions +package body @b{Root.Tests} is + + -- Declare class-wide wrapper routines for any test routines that will be + -- overridden: + procedure @b{Test_P1_Wrapper} (@b{P} : in out @b{Parent_Test}'Class); + procedure @b{Test_P2_Wrapper} (@b{P} : in out @b{Parent_Test}'Class); + + function Name (@b{P} : @b{Parent_Test}) return Message_String is ...; + + -- Set the fixture in P + @b{Fixture : aliased Parent;} + procedure Set_Up_Case (@b{P} : in out @b{Parent_Test}) is + begin + @b{P.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up_Case; + + -- Register Wrappers: + procedure Register_Tests (@b{P} : in out @b{Parent_Test}) is + + package @b{Register_Specific} is + new Test_Cases.Specific_Test_Case_Registration (@b{Parent_Test}); + + use Register_Specific; + + begin + Register_Wrapper (@b{P}, @b{Test_P1_Wrapper}'Access, @b{"Test P1"}); + Register_Wrapper (@b{P}, @b{Test_P2_Wrapper}'Access, @b{"Test P2"}); + end Register_Tests; + + -- Test routines: + procedure @b{Test_P1} (@b{P} : in out Parent_Test) is ...; + procedure @b{Test_P2} (@b{C} : in out Parent_Test) is ...; + + -- Wrapper routines. These dispatch to the corresponding primitive + -- test routines of the specific types. + procedure @b{Test_P1_Wrapper} (@b{P} : in out @b{Parent_Test}'Class) is + begin + @b{Test_P1} (@b{P}); + end @b{Test_P1_Wrapper}; + + procedure @b{Test_P2_Wrapper} (@b{P} : in out @b{Parent_Test}'Class) is + begin + @b{Test_P2} (@b{P}); + end @b{Test_P2_Wrapper}; + +end @b{Root.Tests};} + +@noindent +The code for testing the @code{Child} type will now be: + +@AEXP{with @b{Parent_Tests}; use @b{Parent_Tests}; +with AUnit; use AUnit; +package @b{Branch.Tests} is + + type @b{Child_Test} is new @b{Parent_Test} @b{with private}; + + function Name (@b{C} : @b{Child_Test}) return Message_String; + procedure Register_Tests (@b{C} : in out @b{Child_Test}); + + -- Override Set_Up_Case so that the fixture changes. + procedure Set_Up_Case (@b{C} : in out @b{Child_Test}); + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}); + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}); + +private + type @b{Child_Test} is new @b{Parent_Test} @b{with null record}; +end @b{Branch.Tests}; + +with AUnit.Assertions; use AUnit.Assertions; +package body @b{Branch.Tests} is + + -- Declare wrapper for Test_P3: + procedure @b{Test_P3_Wrapper} (@b{C} : in out @b{Child_Test}'Class); + + function Name (@b{C} : @b{Child_Test}) return Test_String is ...; + + procedure Register_Tests (@b{C} : in out @b{Child_Test}) is + + package @b{Register_Specific} is + new Test_Cases.Specific_Test_Case_Registration (@b{Child_Test}); + use @b{Register_Specific}; + + begin + -- Register parent tests for P1 and P2: + @b{Parent_Tests}.Register_Tests (@b{Parent_Test} (@b{C})); + + -- Repeat for each new test routine (Test_P3 in this case): + @b{Register_Wrapper} (@b{C}, @b{Test_P3_Wrapper}'Access, @b{"Test P3"}); + end Register_Tests; + + -- Set the fixture in P + @b{Fixture : aliased Child;} + procedure Set_Up_Case (@b{C} : in out @b{Child_Test}) is + begin + @b{C.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up_Case; + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}) is ...; + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}) is ...; + + -- Wrapper for new routine: + procedure @b{Test_P3_Wrapper} (@b{C} : in out @b{Child_Test}'Class) is + begin + @b{Test_P3} (@b{C}); + end @b{Test_P3_Wrapper}; + +end @b{Branch.Tests};} + +@noindent +Note that inherited and overridden tests do not need to be explicitly +re-registered in derived test cases - one just calls the parent version of +@code{Register_Tests}. If the application tagged type hierarchy is organized +into parent and child units, one could also organize the test cases into a +hierarchy that reflects that of the units under test. + +@c --------------------------- +@node Testing generic units +@section Testing generic units + +When testing generic units, one would like to apply the same generic tests +to all instantiations in an application. A simple approach is to make the +test case a child package of the unit under test (which then must also be +generic). + +For instance, suppose the generic unit under test is a package (it could +be a subprogram, and the same principle would apply): +@AEXP{generic + -- Formal parameter list +package Template is + -- Declarations +end Template;} + +@noindent +The corresponding test case would be: +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Fixtures; +generic +package @b{Template.Gen_Tests} is + + type @b{Template_Test} is new AUnit.Test_Fixtures.Test_Fixture with @b{...}; + + -- Declare test routines + +end @b{Template.Gen_Tests};} + +The body will follow the usual patterns with the fixture based on the +parent package @code{Template}. Note that due to an Ada AI, accesses to +test routines, along with the test routine specifications, must be defined +in the package specification rather than in its body. + +Instances of @code{Template} will define automatically the Tests child +package that can be directly instantiated as follow: + +@AEXP{with Template.Gen_Test; +with Instance_Of_Template; +package Instance_Of_Template.Tests is new Instance_Of_Template.Gen_Test;} + +The instantiated test case objects are added to a suite in the usual manner. + +@c ================================================================= + +@node Using AUnit with Restricted Run-Time Libraries +@chapter Using AUnit with Restricted Run-Time Libraries + +@noindent +AUnit 3 - like AUnit 2 - is designed so that it can be used in +environments with restricted Ada run-time libraries, such as ZFP and the cert +run-time profile on Wind River Systems' VxWorks 653. The patterns given in +this document for writing tests, suites and harnesses are not the only +patterns that can be used with AUnit, but they are compatible with the +restricted run-time libraries provided with GNAT Pro. + +In general, dynamic allocation and deallocation must be used carefully in test +code. For the cert profile on VxWorks 653, all dynamic allocation must be +done prior to setting the application partition into ``normal'' mode. +Deallocation is prohibited in this profile. For the default ZFP profile, +dynamic memory management is not provided as part of the run-time, as it is +not available on a bare board environment, and should not be used unless +you have provided implementations as described in the GNAT Pro High Integrity +User Guide. + +Starting with AUnit 3, a simple memory management mechanism has been +included in the framework, using a kind of storage pool. This memory +management mechanism uses a static array allocated at startup, and simulates +dynamic allocation afterwards by allocating parts of this array upon request. +Deallocation is not permitted. + +By default, the allocated array is a 100 KB array. This value can be changed +by modifying its size in the file: +@file{aunit-@value{VERSION}-src/aunit/framework/staticmemory/aunit-memory.adb} + +To allocate a new object, you use @code{AUnit.Memory.Utils.Gen_Alloc}. + +Additional restrictions relevant to the default ZFP profile include: +@enumerate +@item +Normally the ZFP profile requires a user-defined +@code{__gnat_last_chance_handler} routine +to handle raised exceptions. However, AUnit now provides a mechanism to +simulate exception propagation using gcc builtin setjmp/longjmp mechanism. +This mechanism defines the @code{__gnat_last_chance_handler} routine, so it +should not be redefined elsewhere. In order to be compatible with this +restriction, the user-defined last chance handler routine can be defined as a +"weak" symbol; this way, it will still be linked into the standalone executable, +but will be replaced by the AUnit implementation when linked with the harness. +The pragma Weak_External can be used for that, e.g.: + +@smallexample +pragma Weak_External (Last_Chance_Handler); +@end smallexample + +@item +AUnit requires @code{GNAT.IO} provided in @file{g-io.ad?} in the full or cert +profile run-time library sources (or as implemented by the user). Since this +is a run-time library unit it must be compiled with the gnatmake ``-a'' +switch. + +@item +The AUnit framework has been modified so that no call to the secondary +stack is performed, nor any call to memcpy or memset. However, if the unit +under test, or the tests themselves require use of those routines, then the +application or test framework must define those symbols and provide the +requisite implementations. + +@item +The timed parameter of the Harness @code{Run} routine has no effect when used +with the ZFP profile, and on profiles not supporting Ada.Calendar. +@end enumerate + +@node Installation and Use +@chapter Installation and Use + +@menu +* Note on gprbuild:: +* Support for other platforms/run-times:: +* Installing AUnit:: +* Installed files:: +@end menu + +@noindent +AUnit 3 contains support for limited run-times such as zero-foot-print +(ZFP) and certified run-time (cert). It can now be installed simultaneously +for several targets and run-times. + +@c -------------------------------------- +@node Note on gprbuild +@section Note on gprbuild + +@noindent +In order to compile, install and use AUnit, you need gprbuild and gprinstall +version 2.2.0 or above. + +@c --------------------------------------------------------- +@node Support for other platforms/run-times +@section Support for other platforms/run-times + +AUnit should be built and installed separately for each target and run-time +it is meant to be used with. The necessary customizations are performed at +AUnit build time, so once the framework is installed, it is always referenced +simply by adding the line + +@smallexample +with "aunit"; +@end smallexample + +to your project. + +@c -------------------------------------- +@node Installing AUnit +@section Installing AUnit + +@noindent +Normally AUnit comes preinstalled and ready-to-use for all runtimes in +your GNAT distribution. The following instructions are for rebuilding it from +sources for the custom configuration that the user may have. + +@itemize +@item +Extract the archive: +@smallexample + $ gunzip -dc aunit-@value{VERSION}-src.tgz | tar xf - +@end smallexample + +@item +To build AUnit for a full Ada run-time: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make +@end smallexample + +To build AUnit for a zfp run-time targeting powerpc-elf platform: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make TARGET=powerpc-elf RTS=zfp +@end smallexample + +To build AUnit for a reconfigurable runtime zfp-leon3 targeting leon3-elf +platform: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make TARGET=leon3-elf RTS=zfp RTS_CONF="--RTS=zfp-leon3" +@end smallexample + + +Once the above build procedure has been performed for the desired platform, you +can install AUnit: +@smallexample + $ make install INSTALL= +@end smallexample + +We recommend that you install AUnit into the standard location used by gprbuild +to find the libraries for a given configuration. For example for the case above +(runtime zfp-leon3 targeting leon3-elf), the default location is +/leon3-elf/zfp-leon3. If the runtime is located in a custom +directory and specified by the full path, using this exact path also as + is a sensible choice. + +If INSTALL is not specified, then AUnit will use the root directory where +gprbuild is installed. + +@item +Specific installation: + + The AUnit makefile supports some specific options, activated using + environment variables. The following options are defined: + +@itemize +@item @b{INSTALL}: defines the AUnit base installation directory, set to +gprbuild's base installation directory as found in the PATH. + +@item @b{TARGET}: defines the gnat tools prefix to use. For example, to compile +AUnit for powerpc VxWorks, TARGET should be set to powerpc-wrs-vxworks. If not +set, the native compiler will be used. + +@item @b{RTS}: defines both the run-time used to compile AUnit and the value +given to the AUnit project as RUNTIME scenario variable. + +@item @b{RTS_CONF}: defines the gprbuild Runtime config flag. The value is +set to "--RTS=$(RTS)" by default. Can be used when compiling AUnit for a +configurable run-time. +@end itemize + +@item +To test AUnit: + + The AUnit test suite is in the test subdirectory of the source package. +@smallexample + $ cd test + $ make +@end smallexample + The test suite's makefile supports the following variables: + @itemize + @item @b{RTS} + @item @b{TARGET} + @end itemize +@end itemize + + +@c --------------------- +@node Installed files +@section Installed files + +@noindent +The AUnit library is installed in the specified directory ( +identifies the root installation directory as specified during the installation +procedures above): + +@itemize +@item + the aunit.gpr project is installed in /lib/gnat +@item + the AUnit source files are installed in /include/aunit +@item + the AUnit library files are installed in /lib/aunit +@item + the AUnit documentation is installed in /share/doc/aunit +@item + the AUnit examples are installed in /share/examples/aunit +@end itemize + +@node GPS Support +@chapter GPS Support + +@noindent +GPS IDE relies on gnattest tool that creates unit-test skeletons as well as +a test driver infrastructure (harness). Harness can be generated for project +hierarchy, single project or a package. Generation process can be launched +from @b{Tools -> GNATtest} menu or from contextual menu. + +@bye diff --git a/ada/libaunit-3.7.2/.pc/path_doc_gps_plugin.diff/support/aunit.xml b/ada/libaunit-3.7.2/.pc/path_doc_gps_plugin.diff/support/aunit.xml new file mode 100644 index 000000000..a5ded97f0 --- /dev/null +++ b/ada/libaunit-3.7.2/.pc/path_doc_gps_plugin.diff/support/aunit.xml @@ -0,0 +1,15 @@ + + + share/doc/aunit + + + /Help/AUnit + + + + aunit.html + AUnit User's Guide + AUnit +

/Help/AUnit/AUnit User's Guide + + diff --git a/ada/libaunit-3.7.2/.pc/paths_in_doc.diff/docs/aunit.texi b/ada/libaunit-3.7.2/.pc/paths_in_doc.diff/docs/aunit.texi new file mode 100644 index 000000000..18bbf1fc3 --- /dev/null +++ b/ada/libaunit-3.7.2/.pc/paths_in_doc.diff/docs/aunit.texi @@ -0,0 +1,1616 @@ +\input texinfo @c -*-texinfo-*- + +@c AUnit Cookbook +@c Copyright (C) 2000-2015, AdaCore + +@c %**start of header +@setfilename aunit.info +@settitle AUnit Cookbook +@setchapternewpage odd +@syncodeindex fn cp + +@iftex +@afourpaper +@end iftex + +@dircategory Software development +@direntry +* AUnit: (aunit). Ada unit test framework, similar to the Java JUnit +@end direntry + +@c ----------------------------------------- MACRO + +@c Macro used for all AUnit examples +@c No cartouche on HTML as this is part of the css +@macro AEXP{TXT} +@ifhtml +@smallexample +@group +\TXT\ +@end group +@end smallexample +@end ifhtml +@ifnothtml +@cartouche +@smallexample +@group +\TXT\ +@end group +@end smallexample +@end cartouche +@end ifnothtml +@end macro + +@include version.texi +@set VERSION @value{MAJOR_VERSION}@value{MINOR_VERSION} + +@c ----------------------------------------- END MACRO + +@titlepage + +@title AUnit Cookbook +@subtitle AUnit - version @value{VERSION} +@subtitle Configuration level $Revision: 314387 $ +@subtitle Date: @today{} +@author AdaCore + +@sp 1 +@url{http://www.adacore.com} + +@vskip 0pt plus 1filll + +@page + +Copyright @copyright{} 2000-2014, AdaCore + +@end titlepage + +@ifhtml +@c title page for the HTML documentation +@html + +

AUnit Cookbook +

AUnit - version @value{VERSION} +

Configuration level $Revision: 314387 $ +

Date: @today{} +

AdaCore + + + +

@url{http://www.adacore.com} + + +@page + +

Copyright @copyright{} 2000-2014, AdaCore + +

This document is licensed under the GNU General Public License, +either version 3 of the License, or (at your option) any later version. + +@end html +@end ifhtml + +@finalout + +@ifnothtml +@contents +@end ifnothtml + +@ifinfo + +@node Top +@top AUnit + +@menu +* Introduction:: +* Overview:: +* Test Cases:: +* Fixture:: +* Suite:: +* Reporting:: +* Test Organization:: +* Using AUnit with Restricted Run-Time Libraries:: +* Installation and Use:: +* GPS Support:: +@end menu +@end ifinfo + +@c ====================================================================== + +@node Introduction +@chapter Introduction + +@noindent +This is a short guide for using the AUnit test framework. +AUnit is an adaptation of the Java JUnit (Kent Beck, Erich Gamma) and C++ +CppUnit (M. Feathers, J. Lacoste, E. Sommerlade, B. Lepilleur, B. Bakker, +S. Robbins) unit test frameworks for Ada code. + +@c --------------------------- +@section What's new in AUnit 3 + +AUnit 3 brings several enhancements over AUnit 2 and AUnit 1: +@itemize + +@item Removal of the genericity of the AUnit framework, making the AUnit 3 +API as close as possible to AUnit 1. + +@item Emulates dynamic memory management for limited run-time profiles. + +@item Provides a new XML reporter, and changes harness invocation to support +easy switching among text, XML and customized reporters. + +@item Provides new tagged types Simple_Test_Case, Test_Fixture and +Test_Caller that correspond to CppUnit's TestCase, TestFixture and TestCaller +classes. + +@item Emulates exception propagation for restricted run-time profiles +(e.g. ZFP), by using the gcc builtin setjmp/longjmp mechanism. + +@item Reports the source location of an error when possible. + +@end itemize + +@c -------------- +@section Examples + +With this version, we have provided new examples illustrating the enhanced +features of the framework. These examples are in the AUnit +installation directory: +/share/examples/aunit, and are also available in the source +distribution aunit-@value{VERSION}-src/examples. + +The following examples are provided: +@itemize +@item simple_test: shows use of AUnit.Simple_Test_Cases +(@pxref{AUnit.Simple_Test_Cases}). +@item test_caller: shows use of AUnit.Test_Caller (@pxref{AUnit.Test_Caller}). +@item test_fixture: example of a test fixture (@pxref{Fixture}). +@item liskov: This suite tests conformance to the Liskov Substitution Principle +of a pair of simple tagged types. (@pxref{OOP considerations}) +@item failures: example of handling and reporting failed tests +(@pxref{Reporting}). +@item calculator: a full example of test suite organization. +@end itemize + +@c ---------------------------------- +@section Note about limited run-times + +AUnit allows a great deal of flexibility as to the structure of test cases, +suites and harnesses. The templates and examples given in this document +illustrate how to use AUnit while staying within the constraints of the +GNAT Pro restricted and Zero Foot Print (ZFP) run-time libraries. Therefore, +they avoid the use of dynamic allocation and some other features that would +be outside of the profiles corresponding to these libraries. Tests targeted +to the full Ada run-time library need not comply with these constraints. + +@c ------------ +@section Thanks + +This document is adapted from the JUnit and CppUnit Cookbooks documents +contained in their respective release packages. + +Special thanks to Francois Brun of Thales Avionics for his ideas about +support for OOP testing. + +@c ====================================================================== + +@node Overview +@chapter Overview + +How do you write testing code? + +The simplest way is as an expression in a debugger. You can change +debug expressions without recompiling, and you can wait to decide +what to write until you have seen the running objects. You can also +write test expressions as statements that print to the standard +output stream. Both styles of tests are limited because they require +human judgment to analyze their results. Also, they don't compose +nicely - you can only execute one debug expression at a time and a +program with too many print statements causes the dreaded "Scroll +Blindness". + +AUnit tests do not require human judgment to interpret, and it is +easy to run many of them at the same time. When you need to test +something, here is what you do: + +@enumerate + +@item Derive a test case type from @code{AUnit.Simple_Test_Cases.Test_Case}. + +Several test case types are available: +@itemize +@item @code{AUnit.Simple_Test_Cases.Test_Case}: the base type for all test +cases. Needs overriding of @code{Name} and @code{Run_Test}. +@item @code{AUnit.Test_Cases.Test_Case}: the traditional AUnit test case type, +allowing multiple test routines registration, each being run and reported +independently. +@item @code{AUnit.Test_Fixtures.Test_Fixture}: used together with +@code{AUnit.Test_Caller}, this allows easy creation of test suites comprising +several test cases that share the same fixture (@pxref{Fixture}). +@end itemize + +@xref{Test Cases}, for simple examples of use of these types. + +@item When you want to check a value@footnote{While JUnit and some other +members of the xUnit family of unit test frameworks provide specialized forms +of assertions (e.g. @code{assertEqual}), we took a design decision in AUnit +not to provide such forms. Ada has a much more rich type system giving a +plethora of possible scalar types, and leading to an explosion of possible +special forms of assert routines. This is exacerbated by the lack of a single +root type for most types, as is found in Java. With the introduction of +AUnit 2 for use with restricted run-time profiles, where even 'Image is +missing, providing a comprehensive set of special assert routines in the +framework itself becomes even more unrealistic. Since AUnit is intended to +be an extensible toolkit, users can certainly write their own custom +collection of such assert routines to suit local usage.}, use one of the +following @code{Assert}@footnote{Note that in AUnit 3, and contrary to +AUnit 2, the procedural form of @code{Assert} has the same behavior whatever +the underlying Ada run-time library: a failed assertion will cause the +execution of the calling test routine to be abandoned. The functional form of +@code{Assert} always continues on a failed assertion, and provides you +with a choice of behaviors.} methods: + +@AEXP{AUnit.Assertions.Assert (@b{Boolean_Expression}, @b{String_Description});} +or: +@AEXP{if not AUnit.Assertions.Assert (@b{Boolean_Expression}, @b{String_Description}) then + return; +end if;} + +If you need to test that a method raises an expected exception, there +is the procedure @code{Assert_Exception} that takes an access value designating the procedure +to be tested as a parameter: + +@AEXP{ + type Throwing_Exception_Proc is access procedure; + + procedure Assert_Exception + (Proc : Throwing_Exception_Proc; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line); + -- Test that Proc throws an exception and record "Message" if not. +} + +Example: + +@AEXP{ + -- Declared at library level: + procedure Test_Raising_Exception is + begin + call_to_the_tested_method (some_args); + end Test_Raising_Exception; + +-- In test routine: +procedure My_Routine (...) is +begin + Assert_Exception (Test_Raising_Exception'Access, @b{String_Description}); +end;} + +This procedure can handle exceptions with all run-time profiles (including +zfp). If you are using a run-time library capable of propagating exceptions, +you can use the following idiom instead: + +@AEXP{ + procedure My_Routine (...) is + begin + ... + -- Call subprogram expected to raise an exception: + Call_To_The_Tested_Method (some_args); + Assert (False, ``exception not raised''); + exception + when desired_exception => + null; + end My_Procedure;} + +An unexpected exception will be recorded as such by the framework. If you want +your test routine to continue beyond verifying that an expected exception has +been raised, you can nest the call and handler in a block. + +@item Create a suite function inside a package to gather together test cases +and sub-suites@footnote{If using the ZFP or the 'cert' run-time profiles, test + cases and suites must be allocated using + @code{AUnit.Memory.Utils.Gen_Alloc}, @code{AUnit.Test_Caller.Create}, + @code{AUnit.Test_Suites.New_Suite}, or be statically allocated.}. + +@item At any level at which you wish to run tests, create a harness by +instantiating procedure @code{AUnit.Run.Test_Runner} or function +@code{AUnit.Run.Test_Runner_With_Status} with the top-level suite +function to be executed. This instantiation provides a routine +that executes all of the tests in the suite. We will call this +user-instantiated routine @code{@b{Run}} in the text for backward compatibility +to tests developed for AUnit 1. Note that only one instance of @code{@b{Run}} +can execute at a time. This is a tradeoff made to reduce the stack requirement +of the framework by allocating test result reporting data structures +statically. + +It is possible to pass a filter to a @code{Test_Runner}, so that only a +subset of the tests run. In particular, this filter could be initialized from +a command line parameter. See the package @code{AUnit.Test_Filters} for an +example of such a filter. AUnit does not automatically initialize this filter +from the command line both because it would not be supported with some of the +limited runtimes (zero footprint for instance), and because you might want to +pass the argument through different ways (as a parameter to switch, or a stand-alone +command line argument for instance). + +It is also possible to control the contents of the output report by passing an +object of type @code{AUnit_Options} to the @code{Test_Runner}. See package +@code{AUnit.Options} for details. + +@item Build the code that calls the harness @code{@b{Run}} routine using +gnatmake or gprbuild. The GNAT project file @i{aunit.gpr} contains all +necessary switches, and should be imported into your root project file. + +@end enumerate + +@c ====================================================================== + +@node Test Cases +@chapter Test Case + +@menu +* AUnit.Simple_Test_Cases:: +* AUnit.Test_Cases:: +* AUnit.Test_Caller:: +@end menu + +@noindent +In this chapter, we will introduce how to use the various forms of Test +Cases. We will illustrate with a very simple test routine, that verifies +that the sum of two Moneys with the same currency result in a value +which is the sum of the values of the two Moneys: + +@AEXP{declare + X, Y: Some_Currency; +begin + X := 12; Y := 14; + Assert (X + Y = 26, "Addition is incorrect"); +end;} + +The following sections will show how to use this test method using the +different test case types available in AUnit. + +@c ----------------------------- +@node AUnit.Simple_Test_Cases +@section AUnit.Simple_Test_Cases + +@noindent +@code{AUnit.Simple_Test_Cases.Test_Case} is the root type of all test + cases. Although generally not meant to be used directly, it provides a + simple and quick way to run a test. + +This tagged type has several methods that need to be defined, or may be +overridden. + +@itemize +@item @code{function Name (T : Test_Case) return Message_String is abstract}: + +This function returns the Test name. You can easily translate regular +strings to Message_String using @code{AUnit.Format}. For example: + +@AEXP{function Name (@b{T} : @b{Money_Test}) return Message_String is +begin + return Format (@b{"Money Tests"}); +end Name;} + +@item @code{procedure Run_Test (T : in out Test_Case) is abstract}: + +This procedure contains the test code. For example: +@AEXP{procedure Run_Test (@b{T} : in out @b{Money_Test}) is + @b{X, Y: Some_Currency;} +begin + @b{X := 12; Y := 14;} + @b{Assert (X + Y = 26, "Addition is incorrect");} +end Run_Test;} + +@item @code{procedure Set_Up (T : in out Test_Case);} and @code{procedure +Tear_Down (T : in out Test_Case);} (default implementations do nothing): + +These procedures are meant to respectively set up or tear down the +environment before running the test case. @xref{Fixture}, for examples +of how to use these methods. + +@end itemize + +You can find a compilable example of +@code{AUnit.Simple_Test_Cases.Test_Case} usage in your AUnit installation +directory: /share/examples/aunit/simple_test/ or from the +source distribution aunit-@value{VERSION}-src/examples/simple_test/ + +@c ---------------------- +@node AUnit.Test_Cases +@section AUnit.Test_Cases + +@code{AUnit.Test_Cases.Test_Case} is derived from +@code{AUnit.Simple_Test_Cases.Test_Case} and defines its +@code{Run_Test} procedure. + +It allows a very flexible composition of Test routines inside a single +test case, each being reported independently. + +The following subprograms must be considered for inheritance, overriding or +completion: + +@itemize + +@item @code{function Name (T : Test_Case) return Message_String is abstract;} +Inherited. @xref{AUnit.Simple_Test_Cases}. + +@item @code{procedure Set_Up (T : in out Test_Case)} and @code{procedure +Tear_Down (T : in out Test_Case)} +Inherited. @xref{AUnit.Simple_Test_Cases}. + +@item @code{procedure Set_Up_Case (T : in out Test_Case)} and +@code{procedure Tear_Down_Case (T : in out Test_Case)} +Default implementation does nothing. + + +The latter procedures provide an opportunity to Set Up and Tear Down the test +case before and after all test routines have been executed. In contrast, the +inherited @code{Set_Up} and @code{Tear_Down} are called before and after the +execution of each individual test routine. + +@item @code{procedure Register_Tests (T : in out Test_Case) is +abstract} +This procedure must be overridden. It is responsible for registering all +the test routines that will be run. You need to use either +@code{Registration.Register_Routine} or the generic +@code{Specific_Test_Case.Register_Wrapper} methods defined in +@code{AUnit.Test_Cases} to register a routine. A test routine has the +form: +@AEXP{procedure Test_Routine (T : in out Test_Case'Class);} +or +@AEXP{procedure Test_Wrapper (T : in out Specific_Test_Case'Class);} + +The former procedure is used mainly for dispatching calls +(@pxref{OOP considerations}). + +@end itemize + +Using this type to test our money addition, the package spec is: + +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Cases; use AUnit.Test_Cases; + +package @b{Money_Tests} is + + type @b{Money_Test} is new Test_Cases.Test_Case with @b{null record}; + + procedure Register_Tests (@b{T}: in out @b{Money_Test}); + -- Register routines to be run + + function Name (@b{T}: @b{Money_Test}) return Message_String; + -- Provide name identifying the test case + + -- Test Routines: + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class); +end @b{Money_Tests};} + +The package body is: + +@AEXP{with AUnit.Assertions; use AUnit.Assertions; + +package body @b{Money_Tests} is + + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class) is + @b{X, Y : Some_Currency;} + begin + @b{X := 12; Y := 14;} + @b{Assert (X + Y = 26, "Addition is incorrect");} + end @b{Test_Simple_Add}; + + -- Register test routines to call + procedure Register_Tests (@b{T}: in out @b{Money_Test}) is + + use AUnit.Test_Cases.Registration; + + begin + -- Repeat for each test routine: + Register_Routine (@b{T}, @b{Test_Simple_Add}'Access, @b{"Test Addition"}); + end Register_Tests; + + -- Identifier of test case + + function Name (@b{T}: @b{Money_Test}) return Test_String is + begin + return Format (@b{"Money Tests"}); + end Name; + +end @b{Money_Tests};} + +@c ----------------------- +@node AUnit.Test_Caller +@section AUnit.Test_Caller + +@noindent +@code{Test_Caller} is a generic package that is used with +@code{AUnit.Test_Fixtures.Test_Fixture}. @code{Test_Fixture} is a very +simple type that provides only the @code{Set_Up} and @code{Tear_Down} +procedures. This type is meant to contain a set of user-defined test +routines, all using the same Set up and Tear down mechanisms. Once those +routines are defined, the Test_Caller package is used to incorporate them +directly into a test suite. + +With our money example, the Test_Fixture is: + +@AEXP{with AUnit.Test_Fixtures; +package @b{Money_Tests} is + type @b{Money_Test} is new AUnit.Test_Fixtures.Test_Fixture @b{with null record}; + + procedure @b{Test_Simple_Add} (@b{T} : in out @b{Money_Test}); + +end @b{Money_Tests};} + +The test suite (@pxref{Suite}) calling the test cases created from +this Test_Fixture is: + +@AEXP{with AUnit.Test_Suites; + +package Money_Suite is + function Suite return AUnit.Test_Suites.Access_Test_Suite; +end Money_Suite;} + +With the corresponding body: + +@AEXP{with AUnit.Test_Caller; +with Money_Tests; + +package body Money_Suite is + + package Money_Caller is new AUnit.Test_Caller + (Money_Tests.Money_Test); + + function Suite return Aunit.Test_Suites.Access_Test_Suite is + Ret : AUnit.Test_Suites.Access_Test_Suite := + AUnit.Test_Suites.New_Suite; + begin + Ret.Add_Test + (Money_Caller.Create + (@b{"Money Test : Test Addition"}, + @b{Money_Tests.Test_Simple_Add}'Access)); + return Ret; + end Suite; + +end Money_Suite;} + +Note that @code{New_Suite} and @code{Create} are fully compatible with +limited run-times (in particular, those without dynamic allocation support). +Note, however, that for non-native run-time libraries, you cannot extend +@code{Test_Fixture} with a controlled component. + +You can find a compilable example of +@code{AUnit.Test_Caller} use in the AUnit installation +directory: /share/examples/aunit/test_caller/ or from the +source distribution aunit-@value{VERSION}-src/examples/test_caller/ + +@c ====================================================================== + +@node Fixture +@chapter Fixture + +@noindent +Tests need to run against the background of a set of known entities. +This set is called a test fixture. When you are +writing tests you will often find that you spend more time writing +code to set up the fixture than you do in actually testing values. + +You can make writing fixture code easier by sharing it. +Often you will be able to use the same fixture for several different +tests. Each case will send slightly different messages or parameters to the +fixture and will check for different results. + +When you have a common fixture, here is what you do: + +@enumerate +@item Create a Test Case package as in previous section. + +@item Declare variables or components for elements of the fixture either +as part of the test case type or in the package body. + +@item According to the Test_Case type used, override its @code{Set_Up} +and/or @code{Set_Up_Case} method: + +@itemize +@item @code{AUnit.Simple_Test_Cases}: @code{Set_Up} is called before +@code{Run_Test}. + +@item @code{AUnit.Test_Cases}: @code{Set_Up} is called before each test +routine while @code{Set_Up_Case} is called once before the routines are run. + +@item @code{AUnit.Test_Fixture}: @code{Set_Up} is called before each +test case created using @code{Aunit.Test_Caller}. +@end itemize + +@item You can also override @code{Tear_Down} and/or +@code{Tear_Down_Case} that are executed after the test is run. + +@end enumerate + +@noindent +For example, to write several test cases that want to work with +different combinations of 12 Euros, 14 Euros, and 26 US Dollars, first +create a fixture. The package spec is now: + +@AEXP{with @b{AUnit}; use @b{AUnit}; + +package @b{Money_Tests} is + use Test_Results; + + type @b{Money_Test} is new Test_Cases.Test_Case with @b{null record}; + + procedure Register_Tests (@b{T}: in out @b{Money_Test}); + -- Register routines to be run + + function Name (@b{T} : @b{Money_Test}) return Test_String; + -- Provide name identifying the test case + + procedure Set_Up (@b{T} : in out @b{Money_Test}); + -- Set up performed before each test routine + + -- Test Routines: + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class); +end @b{Money_Tests};} + +The body becomes: + +@AEXP{package body @b{Money_Tests} is + + use Assertions; + + -- Fixture elements + + @b{EU_12, EU_14 : Euro; + US_26 : US_Dollar;} + + -- Preparation performed before each routine + + procedure Set_Up (@b{T}: in out @b{Money_Test}) is + begin + @b{EU_12 := 12; EU_14 := 14; + US_26 := 26;} + end Set_Up; + + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class) is + @b{X, Y : Some_Currency;} + begin + @b{Assert + (EU_12 + EU_14 /= US_26, + "US and EU currencies not differentiated");} + end @b{Test_Simple_Add}; + + -- Register test routines to call + procedure Register_Tests (@b{T}: in out @b{Money_Test}) is + + use @b{Test_Cases.Registration}; + + begin + -- Repeat for each test routine: + Register_Routine (@b{T}, @b{Test_Simple_Add}'Access, @b{"Test Addition"}); + end Register_Tests; + + -- Identifier of test case + function Name (@b{T}: @b{Money_Test}) return Test_String is + begin + return Format (@b{"Money Tests"}); + end Name; + +end @b{Money_Tests};} + +@noindent +Once you have the fixture in place, you can write as many test +routines as you like. Calls to @code{Set_Up} and @code{Tear_Down} +bracket the invocation of each test routine. + +Once you have several test cases, organize them into a Suite. + +You can find a compilable example of fixture set up using +@code{AUnit.Test_Fixture} in your AUnit installation +directory: /share/examples/aunit/test_fixture/ or from the +AUnit source distribution aunit-@value{VERSION}-src/examples/test_fixture/. + +@c ====================================================================== + +@node Suite +@chapter Suite + +@c --------------------------- +@section Creating a Test Suite + +How do you run several test cases at once? + +As soon as you have two tests, you'll want to run them together. +You could run the tests one at a time yourself, but you would quickly +grow tired of that. Instead, AUnit provides an object, @code{Test_Suite}, +that runs any number of test cases together. + +@noindent +To create a suite of two test cases and run them together, first create +a test suite: + +@AEXP{with AUnit.Test_Suites; +package @b{My_Suite} is + function @b{Suite} return AUnit.Test_Suites.Access_Test_Suite; +end @b{My_Suite};} + +@AEXP{-- Import tests and sub-suites to run +with @b{Test_Case_1, Test_Case_2}; + +package body @b{My_Suite} is + use AUnit.Test_Suites; + + -- Statically allocate test suite: + @b{Result} : aliased Test_Suite; + + -- Statically allocate test cases: + @b{Test_1 : aliased Test_Case_1.Test_Case;} + @b{Test_2 : aliased Test_Case_2.Test_Case;} + + function @b{Suite} return Access_Test_Suite is + begin + Add_Test (@b{Result'Access, Test_Case_1'Access}); + Add_Test (@b{Result'Access, Test_Case_2'Access}); + return @b{Result'Access}; + end @b{Suite}; +end @b{My_Suite};} + +Instead of statically allocating test cases and suites, +you can also use @code{AUnit.Test_Suites.New_Suite} and/or +@code{AUnit.Memory.Utils.Gen_Alloc}. These routines emulate dynamic +memory management (@pxref{Using AUnit with Restricted Run-Time Libraries}). +Similarly, if you know that the tests will always be executed for a run-time +profile that supports dynamic memory management, you can allocate these +objects directly with the Ada @code{"new"} operator. + +@noindent +The harness is: +@AEXP{with @b{My_Suite}; +with AUnit.Run; +with AUnit.Reporter.Text; + +procedure @b{My_Tests} is + procedure @b{Run} is new AUnit.Run.Test_Runner (@b{My_Suite.Suite}); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + @b{Run} (Reporter); +end @b{My_Tests};} + +@c --------------------------- +@section Composition of Suites + +@noindent +Typically, one will want the flexibility to execute a complete set +of tests, or some subset of them. In order to facilitate this, we can +compose both suites and test cases, and provide a harness for any given +suite: + +@AEXP{-- Composition package: +with @b{AUnit}; use @b{AUnit}; +package @b{Composite_Suite} is + function @b{Suite} return Test_Suites.Access_Test_Suite; +end @b{Composite_Suite}; + +-- Import tests and suites to run +with @b{This_Suite, That_Suite}; +with AUnit.Tests; + +package body @b{Composite_Suite} is + use Test_Suites; + + -- Here we dynamically allocate the suite using the New_Suite function + -- We use the 'Suite' functions provided in This_Suite and That_Suite + -- We also use Ada 2005 distinguished receiver notation to call Add_Test + + function @b{Suite} return Access_Test_Suite is + @b{Result} : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + @b{Result}.Add_Test (@b{This_Suite.Suite}); + @b{Result}.Add_Test (@b{That_Suite.Suite}); + return @b{Result}; + end @b{Suite}; +end @b{Composite_Suite};} + +@noindent +The harness remains the same: + +@AEXP{with @b{Composite_Suite}; +with AUnit.Run; + +procedure @b{My_Tests} is + procedure @b{Run} is new AUnit.Run.Test_Runner (@b{Composite_Suite.Suite}); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + @b{Run} (Reporter); +end @b{My_Tests};} + +@noindent +As can be seen, this is a very flexible way of composing test cases +into execution runs: any combination of test cases and sub-suites can +be collected into a suite. + +@c ====================================================================== + +@node Reporting +@chapter Reporting + +Test results can be reported using several 'Reporters'. By default, two +reporters are available in AUnit: +@code{AUnit.Reporter.Text.Text_Reporter} and +@code{AUnit.Reporter.XML.XML_Reporter}. The first one is a simple +console reporting routine, while the second one outputs the result using +an XML format. These are invoked when the @code{Run} routine of an +instantiation of @code{AUnit.Run.Test_Runner} is called. + +@noindent +New reporters can be created using children of +@code{AUnit.Reporter.Reporter}. + +@noindent +The Reporter is selected by specifying it when calling @b{Run}: + +@AEXP{with A_Suite; +with AUnit.Run; +@b{with AUnit.Reporter.Text;} + +procedure My_Tests is + procedure Run is new AUnit.Run.Test_Runner (A_Suite.Suite); + @b{Reporter : AUnit.Reporter.Text.Text_Reporter;} +begin + Run (@b{Reporter}); +end My_Tests;} + +The final report is output once all tests have been run, so that they can be +grouped depending on their status (passed or fail). If you need to output the +tests as they are run, you should consider extending the @code{Test_Result} +type and do some output every time a success or failure is registered. + +@section Text output + +Here is an example where the test harness runs 4 tests, one reporting an +assertion failure, one reporting an unexpected error (exception): + +@smallexample +-------------------- + + Total Tests Run: 4 + + Successful Tests: 2 + Test addition + Test subtraction + + Failed Assertions: 1 + + Test addition (failure expected) + Test should fail this assertion, as 5+3 /= 9 + at math-test.adb:29 + + + Unexpected Errors: 1 + + Test addition (error expected) + CONSTRAINT_ERROR + + + +Time: 2.902E-4 seconds +@end smallexample + +@cindex colors +This reporter can optionally use colors (green to report success, red to report +errors). Since not all consoles support it, this is off by default, but you can +call @code{Set_Use_ANSI_Colors} to activate support for colors. + +@section XML output + +Following is the same harness run using XML output. The XML format used +matches the one used by CppUnit. + +Note that text set in the Assert methods, or as test case names should +be compatible with utf-8 character encoding, or the XML will not be +correctly formatted. + +@smallexample + + + + 4 + 2 + 1 + 1 + + + + Test addition + + + Test subtraction + + + + + Test addition (failure expected) + Assertion + Test should fail this assertion, as 5+3 /= 9 + + math-test.adb + 29 + + + + Test addition (error expected) + Error + CONSTRAINT_ERROR + + + +@end smallexample + +@c ====================================================================== + +@node Test Organization +@chapter Test Organization + +@menu +* General considerations:: +* OOP considerations:: +* Testing generic units:: +@end menu + +@c --------------------------- +@node General considerations +@section General considerations + +This section will discuss an approach to organizing an AUnit test harness, +considering some possibilities offered by Ada language features. + +The general idea behind this approach to test organization is that making the +test case a child of the unit under test gives some useful facilities. +The test case gains visibility to the private part of the unit under test. +This offers a more ``white box'' approach to examining the state of the unit +under test than would, for instance, accessor functions defined in a separate +fixture that is a child of the unit under test. Making the test case a child of +the unit under test also provides a way to make the test case share certain +characteristics of the unit under test. For instance, if the unit under test +is generic, then any child package (here the test case) must be also generic: +any instantiation of the parent package will require an instantiation of the +test case in order to accomplish its aims. + +Another useful concept is matching the test case type to that of the unit +under test: + +@itemize +@item When testing a generic package, the test package should also be +generic. +@item When testing a tagged type, then test routines should be +dispatching, and the test case type for a derived tagged type should be a +derivation of the test case type for the parent. +@item etc. +@end itemize + +Maintaining such similarity of properties between the test case and unit under +test can facilitate the testing of units derived in various ways. + +The following sections will concentrate on applying these concepts to +the testing of tagged type hierarchies and to the testing of generic units. + +A full example of this kind of test organization is available in the AUnit +installation directory: /share/examples/aunit/calculator, or +from the AUnit source distribution +aunit-@value{VERSION}-src/examples/calculator. + +@c --------------------------- +@node OOP considerations +@section OOP considerations + +When testing a hierarchy of tagged types, one will often want to run tests +for parent types against their derivations without rewriting those tests. + +We will illustrate some of the possible solutions available in AUnit, +using the following simple example that we want to test: + +First we consider a @code{Root} package defining the @code{Parent} +tagged type, with two procedures P1 and P2. + +@AEXP{package Root is + type Parent is tagged private; + + procedure P1 (P : in out Parent); + procedure P2 (P : in out Parent); +private + type Parent is tagged record + Some_Value : Some_Type; + end record; +end Root;} + +We will also consider a derivation of type @code{Parent}: + +@AEXP{with Root; +package Branch is + type Child is new Root.Parent with private; + + procedure P2 (C : in out Child); + procedure P3 (C : in out Child); +private + type Child is new Root.Parent with null record; +end Branch;} + +@noindent +Note that @code{Child} retains the parent implementation of @code{P1}, +overrides @code{P2} and adds @code{P3}. Its test will override +@code{Test_P2} when we override @code{P2} (not necessary, but certainly +possible). + +@subsection Using AUnit.Test_Fixtures + +@noindent +Using @code{Test_Fixture} type, we first test @code{Parent} using the +following test case: +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Fixtures; use AUnit.Test_Fixtures; + +-- We make this package a child package of Parent so that it can have +-- visibility to its private part +package @b{Root.Tests} is + + type @b{Parent_Access} is access all @b{Root.Parent'Class}; + + -- Reference an object of type Parent'Class in the test object, so + -- that test procedures can have access to it. + type @b{Parent_Test} is new Test_Fixture @b{with record} + @b{Fixture : Parent_Access;} + @b{end record}; + + -- This will initialize P. + procedure Set_Up (@b{P} : in out @b{Parent_Test}); + + -- Test routines. If derived types are declared in child packages, + -- these can be in the private part. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}); + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}); + +end @b{Root.Tests}; + +package body @b{Root.Tests} is + + @b{Fixture : aliased Parent;} + + -- We set Fixture in Parent_Test to an object of type Parent. + procedure Set_Up (@b{P} : in out @b{Parent_Test}) is + begin + @b{P.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up; + + -- Test routines: References to the Parent object are made via + -- P.Fixture.all, and are thus dispatching. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}) is ...; + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}) is ...; + +end @b{Root.Tests};} + +@noindent +The associated test suite will be: + +@AEXP{with AUnit.Test_Caller; +with @b{Root.Tests}; + +package body @b{Root_Suite} is + package @b{Caller} is new AUnit.Test_Caller with (@b{Root.Tests.Parent_Test}); + + function Suite return AUnit.Test_Suites.Access_Test_Suite is + @b{Ret} : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + AUnit.Test_Suites.Add_Test + (@b{Ret}, Caller.Create (@b{"Test Parent : P1"}, @b{Root.Tests.Test_P1'Access})); + AUnit.Test_Suites.Add_Test + (@b{Ret}, Caller.Create (@b{"Test Parent : P2"}, @b{Root.Tests.Test_P2'Access})); + return @b{Ret}; + end Suite; +end @b{Root_Suite};} + +@noindent +Now we define the test suite for the @code{Child} type. To do this, +we inherit a test fixture from @code{Parent_Test}, +overriding the @code{Set_Up} procedure to initialize @code{Fixture} with +a @code{Child} object. We also override @code{Test_P2} to adapt it +to the new implementation. We define a new @code{Test_P3} to test +@code{P3}. And we inherit @code{Test_P1}, since @code{P1} is unchanged. + +@AEXP{with @b{Root.Tests}; use @b{Root.Tests}; +with AUnit; use AUnit; +with AUnit.Test_Fixtures; use AUnit.Test_Fixtures; + +package @b{Branch.Tests} is + + type @b{Child_Test} is new @b{Parent_Test} @b{with null record}; + + procedure Set_Up (@b{C} : in out @b{Child_Test}); + + -- Test routines: + -- Test_P2 is overridden + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}); + -- Test_P3 is new + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}); + +end @b{Branch.Tests}; + +package body @b{Branch.Tests} is + use Assertions; + + @b{Fixture : Child;} + -- This could also be a field of Child_Test + + procedure Set_Up (@b{C} : in out @b{Child_Test}) is + begin + -- The Fixture for this test will now be a Child + @b{C.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up; + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}) is ...; + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}) is ...; + +end @b{Branch.Tests};} + +The suite for Branch.Tests will now be: + +@AEXP{with AUnit.Test_Caller; +with @b{Branch.Tests}; + +package body @b{Branch_Suite} is + package @b{Caller} is new AUnit.Test_Caller with (@b{Branch.Tests.Parent_Test}); + + -- In this suite, we use Ada 2005 distinguished receiver notation to + -- simplify the code. + + function Suite return Access_Test_Suite is + Ret : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + -- We use the inherited Test_P1. Note that it is + -- Branch.Tests.Set_Up that will be called, and so Test_P1 will be run + -- against an object of type Child + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P1"}, @b{Branch.Tests.Test_P1'Access})); + -- We use the overridden Test_P2 + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P2"}, @b{Branch.Tests.Test_P2'Access})); + -- We use the new Test_P2 + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P3"}, @b{Branch.Tests.Test_P3'Access})); + return @b{Ret}; + end Suite; +end @b{Branch_Suite};} + +@subsection Using AUnit.Test_Cases + +@noindent +Using an @code{AUnit.Test_Cases.Test_Case} derived type, we obtain the +following code for testing @code{Parent}: + +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Cases; +package @b{Root.Tests} is + + type @b{Parent_Access} is access all @b{Root.Parent'Class}; + + type @b{Parent_Test} is new AUnit.Test_Cases.Test_Case @b{with record} + @b{Fixture : Parent_Access;} + @b{end record}; + + function Name (@b{P} : @b{Parent_Test}) return Message_String; + procedure Register_Tests (@b{P} : in out @b{Parent_Test}); + + procedure Set_Up_Case (@b{P} : in out @b{Parent_Test}); + + -- Test routines. If derived types are declared in child packages, + -- these can be in the private part. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}); + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}); + +end @b{Root.Tests};} + +@noindent +The body of the test case will follow the usual pattern, declaring one or +more objects of type @code{@b{Parent}}, and executing statements in the +test routines against them. However, in order to support dispatching to +overriding routines of derived test cases, we need to introduce class-wide +wrapper routines for each primitive test routine of the parent type that +we anticipate may be overridden. Instead of registering the parent's +overridable primitive operations directly using @code{Register_Routine}, +we register the wrapper using @code{Register_Wrapper}. This latter routine +is exported by instantiating +@code{@b{AUnit}.Test_Cases.Specific_Test_Case_Registration} with the actual +parameter being the parent test case type. + +@AEXP{with AUnit.Assertions; use AUnit.Assertions +package body @b{Root.Tests} is + + -- Declare class-wide wrapper routines for any test routines that will be + -- overridden: + procedure @b{Test_P1_Wrapper} (@b{P} : in out @b{Parent_Test}'Class); + procedure @b{Test_P2_Wrapper} (@b{P} : in out @b{Parent_Test}'Class); + + function Name (@b{P} : @b{Parent_Test}) return Message_String is ...; + + -- Set the fixture in P + @b{Fixture : aliased Parent;} + procedure Set_Up_Case (@b{P} : in out @b{Parent_Test}) is + begin + @b{P.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up_Case; + + -- Register Wrappers: + procedure Register_Tests (@b{P} : in out @b{Parent_Test}) is + + package @b{Register_Specific} is + new Test_Cases.Specific_Test_Case_Registration (@b{Parent_Test}); + + use Register_Specific; + + begin + Register_Wrapper (@b{P}, @b{Test_P1_Wrapper}'Access, @b{"Test P1"}); + Register_Wrapper (@b{P}, @b{Test_P2_Wrapper}'Access, @b{"Test P2"}); + end Register_Tests; + + -- Test routines: + procedure @b{Test_P1} (@b{P} : in out Parent_Test) is ...; + procedure @b{Test_P2} (@b{C} : in out Parent_Test) is ...; + + -- Wrapper routines. These dispatch to the corresponding primitive + -- test routines of the specific types. + procedure @b{Test_P1_Wrapper} (@b{P} : in out @b{Parent_Test}'Class) is + begin + @b{Test_P1} (@b{P}); + end @b{Test_P1_Wrapper}; + + procedure @b{Test_P2_Wrapper} (@b{P} : in out @b{Parent_Test}'Class) is + begin + @b{Test_P2} (@b{P}); + end @b{Test_P2_Wrapper}; + +end @b{Root.Tests};} + +@noindent +The code for testing the @code{Child} type will now be: + +@AEXP{with @b{Parent_Tests}; use @b{Parent_Tests}; +with AUnit; use AUnit; +package @b{Branch.Tests} is + + type @b{Child_Test} is new @b{Parent_Test} @b{with private}; + + function Name (@b{C} : @b{Child_Test}) return Message_String; + procedure Register_Tests (@b{C} : in out @b{Child_Test}); + + -- Override Set_Up_Case so that the fixture changes. + procedure Set_Up_Case (@b{C} : in out @b{Child_Test}); + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}); + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}); + +private + type @b{Child_Test} is new @b{Parent_Test} @b{with null record}; +end @b{Branch.Tests}; + +with AUnit.Assertions; use AUnit.Assertions; +package body @b{Branch.Tests} is + + -- Declare wrapper for Test_P3: + procedure @b{Test_P3_Wrapper} (@b{C} : in out @b{Child_Test}'Class); + + function Name (@b{C} : @b{Child_Test}) return Test_String is ...; + + procedure Register_Tests (@b{C} : in out @b{Child_Test}) is + + package @b{Register_Specific} is + new Test_Cases.Specific_Test_Case_Registration (@b{Child_Test}); + use @b{Register_Specific}; + + begin + -- Register parent tests for P1 and P2: + @b{Parent_Tests}.Register_Tests (@b{Parent_Test} (@b{C})); + + -- Repeat for each new test routine (Test_P3 in this case): + @b{Register_Wrapper} (@b{C}, @b{Test_P3_Wrapper}'Access, @b{"Test P3"}); + end Register_Tests; + + -- Set the fixture in P + @b{Fixture : aliased Child;} + procedure Set_Up_Case (@b{C} : in out @b{Child_Test}) is + begin + @b{C.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up_Case; + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}) is ...; + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}) is ...; + + -- Wrapper for new routine: + procedure @b{Test_P3_Wrapper} (@b{C} : in out @b{Child_Test}'Class) is + begin + @b{Test_P3} (@b{C}); + end @b{Test_P3_Wrapper}; + +end @b{Branch.Tests};} + +@noindent +Note that inherited and overridden tests do not need to be explicitly +re-registered in derived test cases - one just calls the parent version of +@code{Register_Tests}. If the application tagged type hierarchy is organized +into parent and child units, one could also organize the test cases into a +hierarchy that reflects that of the units under test. + +@c --------------------------- +@node Testing generic units +@section Testing generic units + +When testing generic units, one would like to apply the same generic tests +to all instantiations in an application. A simple approach is to make the +test case a child package of the unit under test (which then must also be +generic). + +For instance, suppose the generic unit under test is a package (it could +be a subprogram, and the same principle would apply): +@AEXP{generic + -- Formal parameter list +package Template is + -- Declarations +end Template;} + +@noindent +The corresponding test case would be: +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Fixtures; +generic +package @b{Template.Gen_Tests} is + + type @b{Template_Test} is new AUnit.Test_Fixtures.Test_Fixture with @b{...}; + + -- Declare test routines + +end @b{Template.Gen_Tests};} + +The body will follow the usual patterns with the fixture based on the +parent package @code{Template}. Note that due to an Ada AI, accesses to +test routines, along with the test routine specifications, must be defined +in the package specification rather than in its body. + +Instances of @code{Template} will define automatically the Tests child +package that can be directly instantiated as follow: + +@AEXP{with Template.Gen_Test; +with Instance_Of_Template; +package Instance_Of_Template.Tests is new Instance_Of_Template.Gen_Test;} + +The instantiated test case objects are added to a suite in the usual manner. + +@c ================================================================= + +@node Using AUnit with Restricted Run-Time Libraries +@chapter Using AUnit with Restricted Run-Time Libraries + +@noindent +AUnit 3 - like AUnit 2 - is designed so that it can be used in +environments with restricted Ada run-time libraries, such as ZFP and the cert +run-time profile on Wind River Systems' VxWorks 653. The patterns given in +this document for writing tests, suites and harnesses are not the only +patterns that can be used with AUnit, but they are compatible with the +restricted run-time libraries provided with GNAT Pro. + +In general, dynamic allocation and deallocation must be used carefully in test +code. For the cert profile on VxWorks 653, all dynamic allocation must be +done prior to setting the application partition into ``normal'' mode. +Deallocation is prohibited in this profile. For the default ZFP profile, +dynamic memory management is not provided as part of the run-time, as it is +not available on a bare board environment, and should not be used unless +you have provided implementations as described in the GNAT Pro High Integrity +User Guide. + +Starting with AUnit 3, a simple memory management mechanism has been +included in the framework, using a kind of storage pool. This memory +management mechanism uses a static array allocated at startup, and simulates +dynamic allocation afterwards by allocating parts of this array upon request. +Deallocation is not permitted. + +By default, the allocated array is a 100 KB array. This value can be changed +by modifying its size in the file: +@file{aunit-@value{VERSION}-src/aunit/framework/staticmemory/aunit-memory.adb} + +To allocate a new object, you use @code{AUnit.Memory.Utils.Gen_Alloc}. + +Additional restrictions relevant to the default ZFP profile include: +@enumerate +@item +Normally the ZFP profile requires a user-defined +@code{__gnat_last_chance_handler} routine +to handle raised exceptions. However, AUnit now provides a mechanism to +simulate exception propagation using gcc builtin setjmp/longjmp mechanism. +This mechanism defines the @code{__gnat_last_chance_handler} routine, so it +should not be redefined elsewhere. In order to be compatible with this +restriction, the user-defined last chance handler routine can be defined as a +"weak" symbol; this way, it will still be linked into the standalone executable, +but will be replaced by the AUnit implementation when linked with the harness. +The pragma Weak_External can be used for that, e.g.: + +@smallexample +pragma Weak_External (Last_Chance_Handler); +@end smallexample + +@item +AUnit requires @code{GNAT.IO} provided in @file{g-io.ad?} in the full or cert +profile run-time library sources (or as implemented by the user). Since this +is a run-time library unit it must be compiled with the gnatmake ``-a'' +switch. + +@item +The AUnit framework has been modified so that no call to the secondary +stack is performed, nor any call to memcpy or memset. However, if the unit +under test, or the tests themselves require use of those routines, then the +application or test framework must define those symbols and provide the +requisite implementations. + +@item +The timed parameter of the Harness @code{Run} routine has no effect when used +with the ZFP profile, and on profiles not supporting Ada.Calendar. +@end enumerate + +@node Installation and Use +@chapter Installation and Use + +@menu +* Note on gprbuild:: +* Support for other platforms/run-times:: +* Installing AUnit:: +* Installed files:: +@end menu + +@noindent +AUnit 3 contains support for limited run-times such as zero-foot-print +(ZFP) and certified run-time (cert). It can now be installed simultaneously +for several targets and run-times. + +@c -------------------------------------- +@node Note on gprbuild +@section Note on gprbuild + +@noindent +In order to compile, install and use AUnit, you need gprbuild and gprinstall +version 2.2.0 or above. + +@c --------------------------------------------------------- +@node Support for other platforms/run-times +@section Support for other platforms/run-times + +AUnit should be built and installed separately for each target and run-time +it is meant to be used with. The necessary customizations are performed at +AUnit build time, so once the framework is installed, it is always referenced +simply by adding the line + +@smallexample +with "aunit"; +@end smallexample + +to your project. + +@c -------------------------------------- +@node Installing AUnit +@section Installing AUnit + +@noindent +Normally AUnit comes preinstalled and ready-to-use for all runtimes in +your GNAT distribution. The following instructions are for rebuilding it from +sources for the custom configuration that the user may have. + +@itemize +@item +Extract the archive: +@smallexample + $ gunzip -dc aunit-@value{VERSION}-src.tgz | tar xf - +@end smallexample + +@item +To build AUnit for a full Ada run-time: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make +@end smallexample + +To build AUnit for a zfp run-time targeting powerpc-elf platform: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make TARGET=powerpc-elf RTS=zfp +@end smallexample + +To build AUnit for a reconfigurable runtime zfp-leon3 targeting leon3-elf +platform: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make TARGET=leon3-elf RTS=zfp RTS_CONF="--RTS=zfp-leon3" +@end smallexample + + +Once the above build procedure has been performed for the desired platform, you +can install AUnit: +@smallexample + $ make install INSTALL= +@end smallexample + +We recommend that you install AUnit into the standard location used by gprbuild +to find the libraries for a given configuration. For example for the case above +(runtime zfp-leon3 targeting leon3-elf), the default location is +/leon3-elf/zfp-leon3. If the runtime is located in a custom +directory and specified by the full path, using this exact path also as + is a sensible choice. + +If INSTALL is not specified, then AUnit will use the root directory where +gprbuild is installed. + +@item +Specific installation: + + The AUnit makefile supports some specific options, activated using + environment variables. The following options are defined: + +@itemize +@item @b{INSTALL}: defines the AUnit base installation directory, set to +gprbuild's base installation directory as found in the PATH. + +@item @b{TARGET}: defines the gnat tools prefix to use. For example, to compile +AUnit for powerpc VxWorks, TARGET should be set to powerpc-wrs-vxworks. If not +set, the native compiler will be used. + +@item @b{RTS}: defines both the run-time used to compile AUnit and the value +given to the AUnit project as RUNTIME scenario variable. + +@item @b{RTS_CONF}: defines the gprbuild Runtime config flag. The value is +set to "--RTS=$(RTS)" by default. Can be used when compiling AUnit for a +configurable run-time. +@end itemize + +@item +To test AUnit: + + The AUnit test suite is in the test subdirectory of the source package. +@smallexample + $ cd test + $ make +@end smallexample + The test suite's makefile supports the following variables: + @itemize + @item @b{RTS} + @item @b{TARGET} + @end itemize +@end itemize + + +@c --------------------- +@node Installed files +@section Installed files + +@noindent +The AUnit library is installed in the specified directory ( +identifies the root installation directory as specified during the installation +procedures above): + +@itemize +@item + the aunit.gpr project is installed in /lib/gnat +@item + the AUnit source files are installed in /include/aunit +@item + the AUnit library files are installed in /lib/aunit +@item + the AUnit documentation is installed in /share/doc/aunit +@item + the AUnit examples are installed in /share/examples/aunit +@end itemize + +@node GPS Support +@chapter GPS Support + +@noindent +GPS IDE relies on gnattest tool that creates unit-test skeletons as well as +a test driver infrastructure (harness). Harness can be generated for project +hierarchy, single project or a package. Generation process can be launched +from @b{Tools -> GNATtest} menu or from contextual menu. + +@bye diff --git a/ada/libaunit-3.7.2/.pc/style_warnings.diff/include/aunit/containers/ada_containers-aunit_lists.adb b/ada/libaunit-3.7.2/.pc/style_warnings.diff/include/aunit/containers/ada_containers-aunit_lists.adb new file mode 100644 index 000000000..b70b24b15 --- /dev/null +++ b/ada/libaunit-3.7.2/.pc/style_warnings.diff/include/aunit/containers/ada_containers-aunit_lists.adb @@ -0,0 +1,1569 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT LIBRARY COMPONENTS -- +-- -- +-- A D A _ C O N T A I N E R S . A U N I T _ L I S T S -- +-- -- +-- B o d y -- +-- -- +-- Copyright (C) 2004-2007, Free Software Foundation, Inc. -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- This unit was originally developed by Matthew J Heaney. -- +------------------------------------------------------------------------------ + +pragma Ada_2005; + +with System; use type System.Address; + +with AUnit.Memory; use AUnit.Memory; +with AUnit.Memory.Utils; use AUnit.Memory.Utils; + +package body Ada_Containers.AUnit_Lists is + + ----------------------- + -- Local Subprograms -- + ----------------------- + + function New_Node_Type is new AUnit.Memory.Utils.Gen_Alloc + (Node_Type, Node_Access); + + function New_Node_Type + (Element : Element_Type; + Next : Node_Access; + Prev : Node_Access) + return Node_Access; + + procedure Insert_Internal + (Container : in out List; + Before : Node_Access; + New_Node : Node_Access); + + function Vet (Position : Cursor) return Boolean; + + -------------- + -- New_Node -- + -------------- + + function New_Node_Type + (Element : Element_Type; + Next : Node_Access; + Prev : Node_Access) return Node_Access + is + Res : Node_Access := New_Node_Type; + begin + Res.Element := Element; + Res.Next := Next; + Res.Prev := Prev; + return Res; + end New_Node_Type; + + --------- + -- "=" -- + --------- + + function "=" (Left, Right : List) return Boolean is + L : Node_Access := Left.First; + R : Node_Access := Right.First; + + begin + if Left'Address = Right'Address then + return True; + end if; + + if Left.Length /= Right.Length then + return False; + end if; + + for J in 1 .. Left.Length loop + if L.Element /= R.Element then + return False; + end if; + + L := L.Next; + R := R.Next; + end loop; + + return True; + end "="; + + ------------ + -- Append -- + ------------ + + procedure Append + (Container : in out List; + New_Item : Element_Type; + Count : Count_Type := 1) + is + begin + Insert (Container, No_Element, New_Item, Count); + end Append; + + ----------- + -- Clear -- + ----------- + + procedure Clear (Container : in out List) is + X : Node_Access; + + begin + if Container.Length = 0 then + pragma Assert (Container.First = null); + pragma Assert (Container.Last = null); + pragma Assert (Container.Busy = 0); + pragma Assert (Container.Lock = 0); + return; + end if; + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + + if Container.Busy > 0 then + raise Program_Error; + end if; + + while Container.Length > 1 loop + X := Container.First; + pragma Assert (X.Next.Prev = Container.First); + + Container.First := X.Next; + Container.First.Prev := null; + + Container.Length := Container.Length - 1; + + AUnit_Free (X.all'Address); + end loop; + + X := Container.First; + pragma Assert (X = Container.Last); + + Container.First := null; + Container.Last := null; + Container.Length := 0; + + AUnit_Free (X.all'Address); + end Clear; + + -------------- + -- Contains -- + -------------- + + function Contains + (Container : List; + Item : Element_Type) return Boolean + is + begin + return Find (Container, Item) /= No_Element; + end Contains; + + ------------ + -- Delete -- + ------------ + + procedure Delete + (Container : in out List; + Position : in out Cursor; + Count : Count_Type := 1) + is + X : Node_Access; + + begin + if Position.Node = null then + raise Constraint_Error; + end if; + + if Position.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad cursor in Delete"); + + if Position.Node = Container.First then + Delete_First (Container, Count); + Position := No_Element; -- Post-York behavior + return; + end if; + + if Count = 0 then + Position := No_Element; -- Post-York behavior + return; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + for Index in 1 .. Count loop + X := Position.Node; + Container.Length := Container.Length - 1; + + if X = Container.Last then + Position := No_Element; + + Container.Last := X.Prev; + Container.Last.Next := null; + + AUnit_Free (X.all'Address); + return; + end if; + + Position.Node := X.Next; + + X.Next.Prev := X.Prev; + X.Prev.Next := X.Next; + + AUnit_Free (X.all'Address); + end loop; + + Position := No_Element; -- Post-York behavior + end Delete; + + ------------------ + -- Delete_First -- + ------------------ + + procedure Delete_First + (Container : in out List; + Count : Count_Type := 1) + is + X : Node_Access; + + begin + if Count >= Container.Length then + Clear (Container); + return; + end if; + + if Count = 0 then + return; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + for I in 1 .. Count loop + X := Container.First; + pragma Assert (X.Next.Prev = Container.First); + + Container.First := X.Next; + Container.First.Prev := null; + + Container.Length := Container.Length - 1; + + AUnit_Free (X.all'Address); + end loop; + end Delete_First; + + ----------------- + -- Delete_Last -- + ----------------- + + procedure Delete_Last + (Container : in out List; + Count : Count_Type := 1) + is + X : Node_Access; + + begin + if Count >= Container.Length then + Clear (Container); + return; + end if; + + if Count = 0 then + return; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + for I in 1 .. Count loop + X := Container.Last; + pragma Assert (X.Prev.Next = Container.Last); + + Container.Last := X.Prev; + Container.Last.Next := null; + + Container.Length := Container.Length - 1; + + AUnit_Free (X.all'Address); + end loop; + end Delete_Last; + + ------------- + -- Element -- + ------------- + + function Element (Position : Cursor) return Element_Type is + begin + if Position.Node = null then + raise Constraint_Error; + end if; + + pragma Assert (Vet (Position), "bad cursor in Element"); + + return Position.Node.Element; + end Element; + + ---------- + -- Find -- + ---------- + + function Find + (Container : List; + Item : Element_Type; + Position : Cursor := No_Element) return Cursor + is + Node : Node_Access := Position.Node; + + begin + if Node = null then + Node := Container.First; + + else + if Position.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad cursor in Find"); + end if; + + while Node /= null loop + if Node.Element = Item then + return Cursor'(Container'Unchecked_Access, Node); + end if; + + Node := Node.Next; + end loop; + + return No_Element; + end Find; + + ----------- + -- First -- + ----------- + + function First (Container : List) return Cursor is + begin + if Container.First = null then + return No_Element; + end if; + + return Cursor'(Container'Unchecked_Access, Container.First); + end First; + + ------------------- + -- First_Element -- + ------------------- + + function First_Element (Container : List) return Element_Type is + begin + if Container.First = null then + raise Constraint_Error; + end if; + + return Container.First.Element; + end First_Element; + + --------------------- + -- Generic_Sorting -- + --------------------- + + package body Generic_Sorting is + + --------------- + -- Is_Sorted -- + --------------- + + function Is_Sorted (Container : List) return Boolean is + Node : Node_Access := Container.First; + + begin + for I in 2 .. Container.Length loop + if Node.Next.Element < Node.Element then + return False; + end if; + + Node := Node.Next; + end loop; + + return True; + end Is_Sorted; + + ----------- + -- Merge -- + ----------- + + procedure Merge + (Target : in out List; + Source : in out List) + is + LI, RI : Cursor; + + begin + if Target'Address = Source'Address then + return; + end if; + + if Target.Busy > 0 then + raise Program_Error; + end if; + + if Source.Busy > 0 then + raise Program_Error; + end if; + + LI := First (Target); + RI := First (Source); + while RI.Node /= null loop + pragma Assert (RI.Node.Next = null + or else not (RI.Node.Next.Element < + RI.Node.Element)); + + if LI.Node = null then + Splice (Target, No_Element, Source); + return; + end if; + + pragma Assert (LI.Node.Next = null + or else not (LI.Node.Next.Element < + LI.Node.Element)); + + if RI.Node.Element < LI.Node.Element then + declare + RJ : Cursor := RI; + pragma Warnings (Off, RJ); + begin + RI.Node := RI.Node.Next; + Splice (Target, LI, Source, RJ); + end; + + else + LI.Node := LI.Node.Next; + end if; + end loop; + end Merge; + + ---------- + -- Sort -- + ---------- + + procedure Sort (Container : in out List) is + + procedure Partition (Pivot : Node_Access; Back : Node_Access); + + procedure Sort (Front, Back : Node_Access); + + --------------- + -- Partition -- + --------------- + + procedure Partition (Pivot : Node_Access; Back : Node_Access) is + Node : Node_Access := Pivot.Next; + + begin + while Node /= Back loop + if Node.Element < Pivot.Element then + declare + Prev : constant Node_Access := Node.Prev; + Next : constant Node_Access := Node.Next; + + begin + Prev.Next := Next; + + if Next = null then + Container.Last := Prev; + else + Next.Prev := Prev; + end if; + + Node.Next := Pivot; + Node.Prev := Pivot.Prev; + + Pivot.Prev := Node; + + if Node.Prev = null then + Container.First := Node; + else + Node.Prev.Next := Node; + end if; + + Node := Next; + end; + + else + Node := Node.Next; + end if; + end loop; + end Partition; + + ---------- + -- Sort -- + ---------- + + procedure Sort (Front, Back : Node_Access) is + Pivot : Node_Access; + + begin + if Front = null then + Pivot := Container.First; + else + Pivot := Front.Next; + end if; + + if Pivot /= Back then + Partition (Pivot, Back); + Sort (Front, Pivot); + Sort (Pivot, Back); + end if; + end Sort; + + -- Start of processing for Sort + + begin + if Container.Length <= 1 then + return; + end if; + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + + if Container.Busy > 0 then + raise Program_Error; + end if; + + Sort (Front => null, Back => null); + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + end Sort; + + end Generic_Sorting; + + ----------------- + -- Has_Element -- + ----------------- + + function Has_Element (Position : Cursor) return Boolean is + begin + pragma Assert (Vet (Position), "bad cursor in Has_Element"); + return Position.Node /= null; + end Has_Element; + + ------------ + -- Insert -- + ------------ + + procedure Insert + (Container : in out List; + Before : Cursor; + New_Item : Element_Type; + Position : out Cursor; + Count : Count_Type := 1) + is + New_Node : Node_Access; + + begin + if Before.Container /= null then + if Before.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Before), "bad cursor in Insert"); + end if; + + if Count = 0 then + Position := Before; + return; + end if; + + if Container.Length > Count_Type'Last - Count then + raise Constraint_Error; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + New_Node := New_Node_Type (New_Item, null, null); + Insert_Internal (Container, Before.Node, New_Node); + + Position := Cursor'(Container'Unchecked_Access, New_Node); + + for J in Count_Type'(2) .. Count loop + New_Node := New_Node_Type (New_Item, null, null); + Insert_Internal (Container, Before.Node, New_Node); + end loop; + end Insert; + + procedure Insert + (Container : in out List; + Before : Cursor; + New_Item : Element_Type; + Count : Count_Type := 1) + is + Position : Cursor; + pragma Unreferenced (Position); + begin + Insert (Container, Before, New_Item, Position, Count); + end Insert; + + procedure Insert + (Container : in out List; + Before : Cursor; + Position : out Cursor; + Count : Count_Type := 1) + is + New_Node : Node_Access; + + begin + if Before.Container /= null then + if Before.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Before), "bad cursor in Insert"); + end if; + + if Count = 0 then + Position := Before; + return; + end if; + + if Container.Length > Count_Type'Last - Count then + raise Constraint_Error; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + New_Node := New_Node_Type; + Insert_Internal (Container, Before.Node, New_Node); + + Position := Cursor'(Container'Unchecked_Access, New_Node); + + for J in Count_Type'(2) .. Count loop + New_Node := New_Node_Type; + Insert_Internal (Container, Before.Node, New_Node); + end loop; + end Insert; + + --------------------- + -- Insert_Internal -- + --------------------- + + procedure Insert_Internal + (Container : in out List; + Before : Node_Access; + New_Node : Node_Access) + is + begin + if Container.Length = 0 then + pragma Assert (Before = null); + pragma Assert (Container.First = null); + pragma Assert (Container.Last = null); + + Container.First := New_Node; + Container.Last := New_Node; + + elsif Before = null then + pragma Assert (Container.Last.Next = null); + + Container.Last.Next := New_Node; + New_Node.Prev := Container.Last; + + Container.Last := New_Node; + + elsif Before = Container.First then + pragma Assert (Container.First.Prev = null); + + Container.First.Prev := New_Node; + New_Node.Next := Container.First; + + Container.First := New_Node; + + else + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + + New_Node.Next := Before; + New_Node.Prev := Before.Prev; + + Before.Prev.Next := New_Node; + Before.Prev := New_Node; + end if; + + Container.Length := Container.Length + 1; + end Insert_Internal; + + -------------- + -- Is_Empty -- + -------------- + + function Is_Empty (Container : List) return Boolean is + begin + return Container.Length = 0; + end Is_Empty; + + ------------- + -- Iterate -- + ------------- + + procedure Iterate + (Container : List; + Process : Iterator) + is + C : List renames Container'Unrestricted_Access.all; + B : Natural renames C.Busy; + + Node : Node_Access := Container.First; + + begin + B := B + 1; + + begin + while Node /= null loop + Process (Cursor'(Container'Unchecked_Access, Node)); + Node := Node.Next; + end loop; + end; + + B := B - 1; + end Iterate; + + ---------- + -- Last -- + ---------- + + function Last (Container : List) return Cursor is + begin + if Container.Last = null then + return No_Element; + end if; + + return Cursor'(Container'Unchecked_Access, Container.Last); + end Last; + + ------------------ + -- Last_Element -- + ------------------ + + function Last_Element (Container : List) return Element_Type is + begin + if Container.Last = null then + raise Constraint_Error; + end if; + + return Container.Last.Element; + end Last_Element; + + ------------ + -- Length -- + ------------ + + function Length (Container : List) return Count_Type is + begin + return Container.Length; + end Length; + + ---------- + -- Move -- + ---------- + + procedure Move + (Target : in out List; + Source : in out List) + is + begin + if Target'Address = Source'Address then + return; + end if; + + if Source.Busy > 0 then + raise Program_Error; + end if; + + Clear (Target); + + Target.First := Source.First; + Source.First := null; + + Target.Last := Source.Last; + Source.Last := null; + + Target.Length := Source.Length; + Source.Length := 0; + end Move; + + ---------- + -- Next -- + ---------- + + procedure Next (Position : in out Cursor) is + begin + Position := Next (Position); + end Next; + + function Next (Position : Cursor) return Cursor is + begin + if Position.Node = null then + return No_Element; + end if; + + pragma Assert (Vet (Position), "bad cursor in Next"); + + declare + Next_Node : constant Node_Access := Position.Node.Next; + begin + if Next_Node = null then + return No_Element; + end if; + + return Cursor'(Position.Container, Next_Node); + end; + end Next; + + ------------- + -- Prepend -- + ------------- + + procedure Prepend + (Container : in out List; + New_Item : Element_Type; + Count : Count_Type := 1) + is + begin + Insert (Container, First (Container), New_Item, Count); + end Prepend; + + -------------- + -- Previous -- + -------------- + + procedure Previous (Position : in out Cursor) is + begin + Position := Previous (Position); + end Previous; + + function Previous (Position : Cursor) return Cursor is + begin + if Position.Node = null then + return No_Element; + end if; + + pragma Assert (Vet (Position), "bad cursor in Previous"); + + declare + Prev_Node : constant Node_Access := Position.Node.Prev; + begin + if Prev_Node = null then + return No_Element; + end if; + + return Cursor'(Position.Container, Prev_Node); + end; + end Previous; + + --------------------- + -- Replace_Element -- + --------------------- + + procedure Replace_Element + (Container : in out List; + Position : Cursor; + New_Item : Element_Type) + is + begin + if Position.Container = null then + raise Constraint_Error; + end if; + + if Position.Container /= Container'Unchecked_Access then + raise Program_Error; + end if; + + if Container.Lock > 0 then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad cursor in Replace_Element"); + + Position.Node.Element := New_Item; + end Replace_Element; + + ---------------------- + -- Reverse_Elements -- + ---------------------- + + procedure Reverse_Elements (Container : in out List) is + I : Node_Access := Container.First; + J : Node_Access := Container.Last; + + procedure Swap (L, R : Node_Access); + + ---------- + -- Swap -- + ---------- + + procedure Swap (L, R : Node_Access) is + LN : constant Node_Access := L.Next; + LP : constant Node_Access := L.Prev; + + RN : constant Node_Access := R.Next; + RP : constant Node_Access := R.Prev; + + begin + if LP /= null then + LP.Next := R; + end if; + + if RN /= null then + RN.Prev := L; + end if; + + L.Next := RN; + R.Prev := LP; + + if LN = R then + pragma Assert (RP = L); + + L.Prev := R; + R.Next := L; + + else + L.Prev := RP; + RP.Next := L; + + R.Next := LN; + LN.Prev := R; + end if; + end Swap; + + -- Start of processing for Reverse_Elements + + begin + if Container.Length <= 1 then + return; + end if; + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + + if Container.Busy > 0 then + raise Program_Error; + end if; + + Container.First := J; + Container.Last := I; + loop + Swap (L => I, R => J); + + J := J.Next; + exit when I = J; + + I := I.Prev; + exit when I = J; + + Swap (L => J, R => I); + + I := I.Next; + exit when I = J; + + J := J.Prev; + exit when I = J; + end loop; + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + end Reverse_Elements; + + ------------------ + -- Reverse_Find -- + ------------------ + + function Reverse_Find + (Container : List; + Item : Element_Type; + Position : Cursor := No_Element) return Cursor + is + Node : Node_Access := Position.Node; + + begin + if Node = null then + Node := Container.Last; + + else + if Position.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad cursor in Reverse_Find"); + end if; + + while Node /= null loop + if Node.Element = Item then + return Cursor'(Container'Unchecked_Access, Node); + end if; + + Node := Node.Prev; + end loop; + + return No_Element; + end Reverse_Find; + + ------------ + -- Splice -- + ------------ + + procedure Splice + (Target : in out List; + Before : Cursor; + Source : in out List) + is + begin + if Before.Container /= null then + if Before.Container /= Target'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Before), "bad cursor in Splice"); + end if; + + if Target'Address = Source'Address + or else Source.Length = 0 + then + return; + end if; + + pragma Assert (Source.First.Prev = null); + pragma Assert (Source.Last.Next = null); + + if Target.Length > Count_Type'Last - Source.Length then + raise Constraint_Error; + end if; + + if Target.Busy > 0 then + raise Program_Error; + end if; + + if Source.Busy > 0 then + raise Program_Error; + end if; + + if Target.Length = 0 then + pragma Assert (Target.First = null); + pragma Assert (Target.Last = null); + pragma Assert (Before = No_Element); + + Target.First := Source.First; + Target.Last := Source.Last; + + elsif Before.Node = null then + pragma Assert (Target.Last.Next = null); + + Target.Last.Next := Source.First; + Source.First.Prev := Target.Last; + + Target.Last := Source.Last; + + elsif Before.Node = Target.First then + pragma Assert (Target.First.Prev = null); + + Source.Last.Next := Target.First; + Target.First.Prev := Source.Last; + + Target.First := Source.First; + + else + pragma Assert (Target.Length >= 2); + + Before.Node.Prev.Next := Source.First; + Source.First.Prev := Before.Node.Prev; + + Before.Node.Prev := Source.Last; + Source.Last.Next := Before.Node; + end if; + + Source.First := null; + Source.Last := null; + + Target.Length := Target.Length + Source.Length; + Source.Length := 0; + end Splice; + + procedure Splice + (Container : in out List; + Before : Cursor; + Position : Cursor) + is + begin + if Before.Container /= null then + if Before.Container /= Container'Unchecked_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Before), "bad Before cursor in Splice"); + end if; + + if Position.Node = null then + raise Constraint_Error; + end if; + + if Position.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad Position cursor in Splice"); + + if Position.Node = Before.Node + or else Position.Node.Next = Before.Node + then + return; + end if; + + pragma Assert (Container.Length >= 2); + + if Container.Busy > 0 then + raise Program_Error; + end if; + + if Before.Node = null then + pragma Assert (Position.Node /= Container.Last); + + if Position.Node = Container.First then + Container.First := Position.Node.Next; + Container.First.Prev := null; + else + Position.Node.Prev.Next := Position.Node.Next; + Position.Node.Next.Prev := Position.Node.Prev; + end if; + + Container.Last.Next := Position.Node; + Position.Node.Prev := Container.Last; + + Container.Last := Position.Node; + Container.Last.Next := null; + + return; + end if; + + if Before.Node = Container.First then + pragma Assert (Position.Node /= Container.First); + + if Position.Node = Container.Last then + Container.Last := Position.Node.Prev; + Container.Last.Next := null; + else + Position.Node.Prev.Next := Position.Node.Next; + Position.Node.Next.Prev := Position.Node.Prev; + end if; + + Container.First.Prev := Position.Node; + Position.Node.Next := Container.First; + + Container.First := Position.Node; + Container.First.Prev := null; + + return; + end if; + + if Position.Node = Container.First then + Container.First := Position.Node.Next; + Container.First.Prev := null; + + elsif Position.Node = Container.Last then + Container.Last := Position.Node.Prev; + Container.Last.Next := null; + + else + Position.Node.Prev.Next := Position.Node.Next; + Position.Node.Next.Prev := Position.Node.Prev; + end if; + + Before.Node.Prev.Next := Position.Node; + Position.Node.Prev := Before.Node.Prev; + + Before.Node.Prev := Position.Node; + Position.Node.Next := Before.Node; + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + end Splice; + + procedure Splice + (Target : in out List; + Before : Cursor; + Source : in out List; + Position : in out Cursor) + is + begin + if Target'Address = Source'Address then + Splice (Target, Before, Position); + return; + end if; + + if Before.Container /= null then + if Before.Container /= Target'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Before), "bad Before cursor in Splice"); + end if; + + if Position.Node = null then + raise Constraint_Error; + end if; + + if Position.Container /= Source'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad Position cursor in Splice"); + + if Target.Length = Count_Type'Last then + raise Constraint_Error; + end if; + + if Target.Busy > 0 then + raise Program_Error; + end if; + + if Source.Busy > 0 then + raise Program_Error; + end if; + + if Position.Node = Source.First then + Source.First := Position.Node.Next; + + if Position.Node = Source.Last then + pragma Assert (Source.First = null); + pragma Assert (Source.Length = 1); + Source.Last := null; + + else + Source.First.Prev := null; + end if; + + elsif Position.Node = Source.Last then + pragma Assert (Source.Length >= 2); + Source.Last := Position.Node.Prev; + Source.Last.Next := null; + + else + pragma Assert (Source.Length >= 3); + Position.Node.Prev.Next := Position.Node.Next; + Position.Node.Next.Prev := Position.Node.Prev; + end if; + + if Target.Length = 0 then + pragma Assert (Target.First = null); + pragma Assert (Target.Last = null); + pragma Assert (Before = No_Element); + + Target.First := Position.Node; + Target.Last := Position.Node; + + Target.First.Prev := null; + Target.Last.Next := null; + + elsif Before.Node = null then + pragma Assert (Target.Last.Next = null); + Target.Last.Next := Position.Node; + Position.Node.Prev := Target.Last; + + Target.Last := Position.Node; + Target.Last.Next := null; + + elsif Before.Node = Target.First then + pragma Assert (Target.First.Prev = null); + Target.First.Prev := Position.Node; + Position.Node.Next := Target.First; + + Target.First := Position.Node; + Target.First.Prev := null; + + else + pragma Assert (Target.Length >= 2); + Before.Node.Prev.Next := Position.Node; + Position.Node.Prev := Before.Node.Prev; + + Before.Node.Prev := Position.Node; + Position.Node.Next := Before.Node; + end if; + + Target.Length := Target.Length + 1; + Source.Length := Source.Length - 1; + + Position.Container := Target'Unchecked_Access; + end Splice; + + ---------- + -- Swap -- + ---------- + + procedure Swap + (Container : in out List; + I, J : Cursor) + is + begin + if I.Node = null then + raise Constraint_Error; + end if; + + if J.Node = null then + raise Constraint_Error; + end if; + + if I.Container /= Container'Unchecked_Access then + raise Program_Error; + end if; + + if J.Container /= Container'Unchecked_Access then + raise Program_Error; + end if; + + if I.Node = J.Node then + return; + end if; + + if Container.Lock > 0 then + raise Program_Error; + end if; + + pragma Assert (Vet (I), "bad I cursor in Swap"); + pragma Assert (Vet (J), "bad J cursor in Swap"); + + declare + EI : Element_Type renames I.Node.Element; + EJ : Element_Type renames J.Node.Element; + + EI_Copy : constant Element_Type := EI; + + begin + EI := EJ; + EJ := EI_Copy; + end; + end Swap; + + ---------------- + -- Swap_Links -- + ---------------- + + procedure Swap_Links + (Container : in out List; + I, J : Cursor) + is + begin + if I.Node = null then + raise Constraint_Error; + end if; + + if J.Node = null then + raise Constraint_Error; + end if; + + if I.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + if J.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + if I.Node = J.Node then + return; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + pragma Assert (Vet (I), "bad I cursor in Swap_Links"); + pragma Assert (Vet (J), "bad J cursor in Swap_Links"); + + declare + I_Next : constant Cursor := Next (I); + + begin + if I_Next = J then + Splice (Container, Before => I, Position => J); + + else + declare + J_Next : constant Cursor := Next (J); + + begin + if J_Next = I then + Splice (Container, Before => J, Position => I); + + else + pragma Assert (Container.Length >= 3); + + Splice (Container, Before => I_Next, Position => J); + Splice (Container, Before => J_Next, Position => I); + end if; + end; + end if; + end; + end Swap_Links; + + --------- + -- Vet -- + --------- + + function Vet (Position : Cursor) return Boolean is + begin + if Position.Node = null then + return Position.Container = null; + end if; + + if Position.Container = null then + return False; + end if; + + if Position.Node.Next = Position.Node then + return False; + end if; + + if Position.Node.Prev = Position.Node then + return False; + end if; + + declare + L : List renames Position.Container.all; + begin + if L.Length = 0 then + return False; + end if; + + if L.First = null then + return False; + end if; + + if L.Last = null then + return False; + end if; + + if L.First.Prev /= null then + return False; + end if; + + if L.Last.Next /= null then + return False; + end if; + + if Position.Node.Prev = null + and then Position.Node /= L.First + then + return False; + end if; + + if Position.Node.Next = null + and then Position.Node /= L.Last + then + return False; + end if; + + if L.Length = 1 then + return L.First = L.Last; + end if; + + if L.First = L.Last then + return False; + end if; + + if L.First.Next = null then + return False; + end if; + + if L.Last.Prev = null then + return False; + end if; + + if L.First.Next.Prev /= L.First then + return False; + end if; + + if L.Last.Prev.Next /= L.Last then + return False; + end if; + + if L.Length = 2 then + if L.First.Next /= L.Last then + return False; + end if; + + if L.Last.Prev /= L.First then + return False; + end if; + + return True; + end if; + + if L.First.Next = L.Last then + return False; + end if; + + if L.Last.Prev = L.First then + return False; + end if; + + if Position.Node = L.First then + return True; + end if; + + if Position.Node = L.Last then + return True; + end if; + + if Position.Node.Next = null then + return False; + end if; + + if Position.Node.Prev = null then + return False; + end if; + + if Position.Node.Next.Prev /= Position.Node then + return False; + end if; + + if Position.Node.Prev.Next /= Position.Node then + return False; + end if; + + if L.Length = 3 then + if L.First.Next /= Position.Node then + return False; + end if; + + if L.Last.Prev /= Position.Node then + return False; + end if; + end if; + + return True; + end; + end Vet; + +end Ada_Containers.AUnit_Lists; diff --git a/ada/libaunit-3.7.2/CHANGES b/ada/libaunit-3.7.2/CHANGES new file mode 100644 index 000000000..405ce6748 --- /dev/null +++ b/ada/libaunit-3.7.2/CHANGES @@ -0,0 +1 @@ +{aunit: 314491, aunit.anod: 49d6b638e36f944967bf6a0d99872c4a4f6829c0} diff --git a/ada/libaunit-3.7.2/COPYING3 b/ada/libaunit-3.7.2/COPYING3 new file mode 100644 index 000000000..94a9ed024 --- /dev/null +++ b/ada/libaunit-3.7.2/COPYING3 @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program 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 3 of the License, or + (at your option) any later version. + + This program 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 more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/ada/libaunit-3.7.2/debian/README.Debian b/ada/libaunit-3.7.2/debian/README.Debian new file mode 100644 index 000000000..207bc478b --- /dev/null +++ b/ada/libaunit-3.7.2/debian/README.Debian @@ -0,0 +1,10 @@ +aunit for Debian +---------------- + +See the Debian Ada policy at +http://people.debian.org/~lbrenta/debian-ada-policy.html + +The template files mentioned in the documentation are in +/usr/share/doc/aunit-dev/examples. + + -- Nicolas Boulenguez , Sat, 30 Nov 2013 22:08:45 +0100 diff --git a/ada/libaunit-3.7.2/debian/README.source b/ada/libaunit-3.7.2/debian/README.source new file mode 100644 index 000000000..58aa9d160 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/README.source @@ -0,0 +1,39 @@ +The versions given here should be taken as examples. + +Major and minor versions are set manually from the version_information +file. When the file contains 3.8.0w, 3.7 has been released and 3.8 is +in preparation. Debian then uses something like 3.7.x. + +Use of the version control system +--------------------------------- + +You may either create an empty Monotone database +# mtn -d $db db init +or use an existing one. + +All work on this package is tracked in the +www.ada-france.org monotone repository. +# debian_branch=org.debian.libaws tracks the Debian packaging + +Download the branches from the server to your database. The first +time you contact this server, monotone will show its key. You should +check that it matches f8a11727e8983cf9083c08c6a2acaa27e439dd39. +# server=www.ada-france.org +# mtn -d $db pull mtn://$server?$debian_branch + +Inspect the unpatched source tree. +# tar xf libaunit_3.7.1.orig.tar.xz +# cd aunit-3.7.0w-src +# mtn -d $db checkout -r h:$debian_branch . + +Build the package +# debuild + +Beware that: +- mtn status does not list all changes. Try "mtn list missing", "mtn + list unknown", "mtn list ignored" and "mtn status" to get the + equivalent of "git status". +- Monotone will detect changes outside debian/ caused by patches. + Always "quilt pop -a" when preparing a commit. + + -- Nicolas Boulenguez , Sun, 24 Apr 2016 03:09:16 +0200 diff --git a/ada/libaunit-3.7.2/debian/ada_libraries b/ada/libaunit-3.7.2/debian/ada_libraries new file mode 100644 index 000000000..13f6e34ba --- /dev/null +++ b/ada/libaunit-3.7.2/debian/ada_libraries @@ -0,0 +1 @@ +LIBRARY_KIND=dynamic SOVERSION=ignored lib/gnat/aunit.gpr diff --git a/ada/libaunit-3.7.2/debian/changelog b/ada/libaunit-3.7.2/debian/changelog new file mode 100644 index 000000000..68c093257 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/changelog @@ -0,0 +1,168 @@ +libaunit (3.7.2-1) unstable; urgency=medium + + * New upstream release (GPL-2015, betwwen 3.7.1 and 3.8.0). + Rename lib (SO=3.7.2) and -dev (ALI=3.7.2) packages due to Ada policy. + Build with gnat-6, gprbuild and all hardening options. + * watch, README.source: use Adacore redirector. + * Switch from manual -dbg packages to automatic -dbgsym packages. + * Standards-Version: 3.9.8 (no changes), drop generated XS-Testsuite. + * rules: avoid timezone dependency when possible. + * patches/path_doc_gps_plugin.diff: typo in package name. + + -- Nicolas Boulenguez Tue, 26 Apr 2016 08:32:42 +0200 + +libaunit (3.7.1-2) unstable; urgency=medium + + * For reproducible PDF timestamps, set clock to the date of this entry. + Touch generated sources for deterministic ALI files and tar headers. + * Standards-Version: 3.9.6 (no changes). + + -- Nicolas Boulenguez Sun, 03 May 2015 16:49:18 +0200 + +libaunit (3.7.1-1) unstable; urgency=medium + + * New upstream release, built with gnat-4.9 (closes: #748998, #755078). + Per Ada policy, rename lib (ABI) and -dev (sources) packages. + * Because the generated doc is big, use Files-Excluded. + Because it and examples are -indep, add a -doc package. + * copyright: update to GPL-3+, repackage without generated files. + * rules: run-tests target is obsoleted by sadt from devscripts. + Now using upstream build system with a few patches. + * doc-base registration. Install all formats and examples. + * examples: deduplicate, link from doc, run as tests. + Some of them and upstream-tests freeze, commented. + * Fix dh_compress override. + + -- Nicolas Boulenguez Mon, 18 Aug 2014 16:39:25 +0200 + +libaunit (1.03-8) unstable; urgency=low + + * Adopting the package. Closes: #673752. + * Switch to debhelper 9, dpkg-dev and dh-ada-library helpers. + * Build-Depends: gnat in addition to gnat-4.6 to ensure default compiler. + * Standards-Version: 3.9.5. Vcs-*: correct field names. + * Stop depending on inexistant ada-compiler virtual package. + * Mark lib and -dev packages as Multiarch: same. + * copyright: update, machine-readable format 1.0. + * Move runtime tests to debian/tests. XS-Testsuite field accordingly. + * rules: inherit hardening flags. Do not compress examples. Implement clean. + * source.lintian overrides: -lib does Depend on -dbg. + * Empty but informative watch file. + + -- Nicolas Boulenguez Sat, 30 Nov 2013 22:30:03 +0100 + +libaunit (1.03-7) unstable; urgency=low + + * upgrade to build with gnat-4.6; bump aliversion + + -- Stephen Leake Tue, 12 Jul 2011 18:34:15 -0400 + +libaunit (1.03-6) unstable; urgency=low + + * debian/compat: bump to 7 + + * debian/control: add gnat, ada-compiler per Debian Ada Policy. + + * debian/source/format: switch to 3.0 (quilt) + + * debian/rules: don't install GPS plug-in aunit.xml; it's wrong. + + -- Stephen Leake Tue, 15 Jun 2010 03:31:31 -0400 + +libaunit (1.03-5) unstable; urgency=low + + [Stephen Leake] + * debian/control (Standards-Version): update to 3.8.4 + (Architecture): change to 'any', to match gnat-4.4. Closes: #568438 + + [Ludovic Brenta] + * debian/control (DM-Upload-Allowed): new. (Uploaders): remove myself. + + -- Stephen Leake Sun, 14 Feb 2010 08:23:32 -0500 + +libaunit (1.03-4) unstable; urgency=low + + [Stephen Leake] + * Change -dev package name to reflect the change in .ali files (see + extensive discussion at + http://people.debian.org/~lbrenta/debian-ada-policy.html): + - libaunit-dev -> libaunit1-dev + * NEW package libaunit-dbg + * Migrate to gnat-4.4 and change the soname to libaunit3. + * Update Standards-Version to 3.8.3 with no changes. + * debian/control (Architecture): add kfreebsd-amd64. Closes: #542414. + (Vcs-Mtn, Vcs-Browse): new. + (Maintainer): new maintainer Stephen Leake. + (Uploaders): add Ludovic Brenta as the sponsor. + (Suggests): new + (Conflicts, Replaces): new + * debian/test_installed.sh: New, for running tests against installed + package. + + [Ludovic Brenta] + * debian/control (Depends): add ${misc:Depends}, required by debhelper. + (Architectures): disable alpha due to http://gcc.gnu.org/PR42073. + * debian/aunit_ref.gpr: s/Object_Dir/Library_ALI_Dir/. + * debian/aunit_build.gpr: build without -fstack-check. + Eric Botcazou says: "-fstack-check is broken with GCC 4.4 on x86/x86-64 + Linux, it generates code that will easily segfault" + (http://gcc.gnu.org/PR20548). + + -- Ludovic Brenta Thu, 19 Nov 2009 23:46:01 +0100 + +libaunit (1.03-3) unstable; urgency=low + + * Migrate to gnat-4.3 and change the soname to libaunit2. + * Update Standards-Version to 3.8.0 with no changes. + * Add support for mips, mipsel and ppc64. + * Transform aunit.gpr into a library project file. + + -- Ludovic Brenta Thu, 24 Jul 2008 20:56:02 +0200 + +libaunit (1.03-2) unstable; urgency=low + + * debian/control (Maintainer): use my Debian email address. + + -- Ludovic Brenta Mon, 18 Sep 2006 23:09:04 +0200 + +libaunit (1.03-1) unstable; urgency=low + + * New upstream release. + * Compile with GCC 4.1; new ABI. + * debian/control (Maintainer): new email address, I'm now a full DD. + (Upoloaders): remove. + (Build-Depends): gnat (>= 4.1). + (Standards-Version): bump to 3.7.2 with no changes required. + (libaunit1): rename to libaunit1.03. + (Architecture): add alpha, amd64, hppa, ia64 and s390. + * debian/rules: bump the soname to libaunit.so.1.03. + + -- Ludovic Brenta Mon, 18 Sep 2006 00:15:11 +0200 + +libaunit (1.01-3) unstable; urgency=low + + * debian/rules (regexp): accept any character in the Debian upload + number. Closes: #359880. + + -- Ludovic Brenta Fri, 31 Mar 2006 08:08:36 +0200 + +libaunit (1.01-2) unstable; urgency=low + + * debian/control: enable support for GNU/kFreeBSD. Update + standards-version from 3.6.1 to 3.6.2 with no changes. Change + maintainer's email address. Add Alexander Wirt to the list of + uploaders. + (libaunit-dev): Depend on gnat, suggest gnat-gps. + * debian/libaunit-dev.postinst: remove, no longer needed. + + -- Ludovic Brenta Wed, 1 Mar 2006 20:23:20 +0100 + +libaunit (1.01-1) unstable; urgency=low + + * Initial Release. + + -- Ludovic Brenta Tue, 24 Feb 2004 02:33:37 +0100 + +Local variables: +left-margin: 2 +End: diff --git a/ada/libaunit-3.7.2/debian/compat b/ada/libaunit-3.7.2/debian/compat new file mode 100644 index 000000000..ec635144f --- /dev/null +++ b/ada/libaunit-3.7.2/debian/compat @@ -0,0 +1 @@ +9 diff --git a/ada/libaunit-3.7.2/debian/control b/ada/libaunit-3.7.2/debian/control new file mode 100644 index 000000000..26cf70ede --- /dev/null +++ b/ada/libaunit-3.7.2/debian/control @@ -0,0 +1,71 @@ +Source: libaunit +Section: libdevel +Priority: extra +Maintainer: Nicolas Boulenguez +Build-Depends: dpkg-dev (>= 1.16.1), debhelper (>= 9), + gnat, gnat-6, +# gprbuild compatible with gnat-6 + gprbuild (>= 2015-2), +# dh-ada-library knowing that -dbg packages are obsolete. + dh-ada-library (>= 6.7) +Build-Depends-Indep: +# To deduplicate examples in rules. + rdfind, symlinks, +# Called in rules for deterministic PDF timestamps. + faketime, + texinfo, texlive-latex-base +Standards-Version: 3.9.8 +Homepage: http://libre.adacore.com/libre/ +Vcs-Mtn: www.ada-france.org org.debian.libaunit +Vcs-Browser: http://www.ada-france.org:8081/branch/changes/org.debian.libaunit + +Package: libaunit3.7.2-dev +Architecture: any +Depends: ${misc:Depends}, ${ada:Depends} +Recommends: libaunit-doc (= ${source:Version}) +Description: AUnit, a unit testing framework for Ada: development + AUnit is a set of Ada packages based on the xUnit family of unit test + frameworks. It's intended as a developer's tool to facilitate + confident writing and evolution of Ada software. It is purposely + lightweight, as one of its main goals is to make it easy to develop + and run unit tests, rather than to generate artifacts for process + management. The framework supports easy composition of sets of unit + tests to provide flexibility in determining what tests to run for a + given purpose. + . + Install this package if you want to write programs that use AUnit. + +Package: libaunit3.7.2 +Section: libs +Architecture: any +Multi-Arch: same +Pre-Depends: ${misc:Pre-Depends} +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: AUnit, a unit testing framework for Ada: shared library + AUnit is a set of Ada packages based on the xUnit family of unit test + frameworks. It's intended as a developer's tool to facilitate + confident writing and evolution of Ada software. It is purposely + lightweight, as one of its main goals is to make it easy to develop + and run unit tests, rather than to generate artifacts for process + management. The framework supports easy composition of sets of unit + tests to provide flexibility in determining what tests to run for a + given purpose. + . + This package contains the runtime shared library. + +Package: libaunit-doc +Section: doc +Architecture: all +Depends: ${misc:Depends} +Suggests: gnat +Description: AUnit, a unit testing framework for Ada: documentation + AUnit is a set of Ada packages based on the xUnit family of unit test + frameworks. It's intended as a developer's tool to facilitate + confident writing and evolution of Ada software. It is purposely + lightweight, as one of its main goals is to make it easy to develop + and run unit tests, rather than to generate artifacts for process + management. The framework supports easy composition of sets of unit + tests to provide flexibility in determining what tests to run for a + given purpose. + . + This package contains documentation. diff --git a/ada/libaunit-3.7.2/debian/copyright b/ada/libaunit-3.7.2/debian/copyright new file mode 100644 index 000000000..0a91570fc --- /dev/null +++ b/ada/libaunit-3.7.2/debian/copyright @@ -0,0 +1,38 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: AUnit +Upstream-Contact: http://libre.adacore.com/contact +Source: http://libre.adacore.com/download +Files-Excluded: + docs/aunit.info + docs/aunit.pdf + docs/aunit.txt + docs/aunit.html + docs/version.texi + share +Comment: Without the generated docs, the archive is six times smaller. + Examples have moved from share/examples/aunit to examples, the old + directory only contains some unused duplicates. + +Files: * +Copyright: 2006-2015 AdaCore + : 2004-2008 Free Software Foundation +License: GPL-3+ + +Files: debian/* +Copyright: 2006-2012 Stephen Leake + : 2013-2016 Nicolas Boulenguez +License: GPL-3+ + +License: GPL-3+ + This program 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 3 of the License, or + (at your option) any later version. + . + This program 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 more details. + . + On Debian systems, the complete text of the GNU General Public + License can be found in /usr/share/common-licenses/GPL-3 file. diff --git a/ada/libaunit-3.7.2/debian/install b/ada/libaunit-3.7.2/debian/install new file mode 100644 index 000000000..a81c88a0d --- /dev/null +++ b/ada/libaunit-3.7.2/debian/install @@ -0,0 +1,4 @@ +# The name of this file does not mention the aliversion. +# Instead we use that -dev is the first package in debian/control. + +support/aunit.xml usr/share/gps/plug-ins diff --git a/ada/libaunit-3.7.2/debian/libaunit-doc.TODO b/ada/libaunit-3.7.2/debian/libaunit-doc.TODO new file mode 100644 index 000000000..53d7b3378 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/libaunit-doc.TODO @@ -0,0 +1 @@ +* Run tests after the build. diff --git a/ada/libaunit-3.7.2/debian/libaunit-doc.doc-base.ada-unit-tests b/ada/libaunit-3.7.2/debian/libaunit-doc.doc-base.ada-unit-tests new file mode 100644 index 000000000..af59eed2c --- /dev/null +++ b/ada/libaunit-3.7.2/debian/libaunit-doc.doc-base.ada-unit-tests @@ -0,0 +1,22 @@ +Document: ada-unit-tests +Title: Ada Unit test framework - User Guide +Author: AdaCore +Abstract: This manual documents the AUnit library, + The Ada unit test framework AUnit is derived from the JUnit/CPPUnit + frameworks for Java/C++. +Section: Programming + +Format: HTML +Index: /usr/share/doc/libaunit-doc/aunit.html +Files: /usr/share/doc/libaunit-doc/aunit.html + +Format: text +Index: /usr/share/doc/libaunit-doc/aunit.txt.gz +Files: /usr/share/doc/libaunit-doc/aunit.txt.gz + +Format: pdf +Files: /usr/share/doc/libaunit-doc/aunit.pdf.gz + +Format: info +Index : /usr/share/info/aunit.info.gz +Files: /usr/share/info/aunit.info.gz diff --git a/ada/libaunit-3.7.2/debian/libaunit-doc.docs b/ada/libaunit-3.7.2/debian/libaunit-doc.docs new file mode 100644 index 000000000..ebab5d65c --- /dev/null +++ b/ada/libaunit-3.7.2/debian/libaunit-doc.docs @@ -0,0 +1,5 @@ +docs/aunit.html +docs/aunit.pdf +docs/aunit.txt +features-* +known-problems-* diff --git a/ada/libaunit-3.7.2/debian/libaunit-doc.examples b/ada/libaunit-3.7.2/debian/libaunit-doc.examples new file mode 100644 index 000000000..c790d0cd0 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/libaunit-doc.examples @@ -0,0 +1,2 @@ +template +examples/* diff --git a/ada/libaunit-3.7.2/debian/libaunit-doc.info b/ada/libaunit-3.7.2/debian/libaunit-doc.info new file mode 100644 index 000000000..70923dd28 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/libaunit-doc.info @@ -0,0 +1 @@ +docs/aunit.info diff --git a/ada/libaunit-3.7.2/debian/patches/adapt_projects.diff b/ada/libaunit-3.7.2/debian/patches/adapt_projects.diff new file mode 100644 index 000000000..35d9a2604 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/patches/adapt_projects.diff @@ -0,0 +1,64 @@ +Description: allow build flags and dynamic linking. + Remove LIBDIR and OBJDIR, noone ever sets these variables. +Author: Nicolas Boulenguez +Forwarded: no + +--- a/lib/gnat/aunit.gpr ++++ b/lib/gnat/aunit.gpr +@@ -14,14 +14,26 @@ + "../../include/aunit/framework/" & AUnit_Shared.Calend, + "../../include/aunit/framework/" & AUnit_Shared.Memory); + +- for Library_Dir use AUnit_Shared.Library_Dir; +- +- Obj_Dir := external ("OBJDIR", "../aunit-obj/" +- & AUnit_Shared.Target & "-" & AUnit_Shared.Runtime); +- for Object_Dir use Obj_Dir; ++ for Library_Dir use "../aunit/" & ++ Aunit_Shared.Target & "-" ++ & Aunit_Shared.Runtime & "-" ++ & Aunit_Shared.Library_Kind; ++ ++ for Object_Dir use "../aunit-obj/" ++ & AUnit_Shared.Target & "-" ++ & AUnit_Shared.Runtime & "-" ++ & Aunit_Shared.Library_Kind; + + for Library_Name use "aunit"; +- for Library_Kind use "static"; ++ for Library_Kind use AUnit_Shared.Library_Kind; ++ case AUnit_Shared.Library_Kind is ++ when "dynamic" => ++ for Library_Version use "lib" & Project'Library_Name & ".so." ++ & Aunit_Shared.Soversion; ++ for Leading_Library_Options use Aunit_Shared.Ldflags; ++ when "static" => ++ null; ++ end case; + + -------------- + -- Compiler -- +@@ -38,6 +50,8 @@ + for Default_Switches ("ada") use + ("-O2", "-gnatp", "-gnatn", "-gnatwa.X"); + end case; ++ for Default_Switches ("ada") use Compiler'Default_Switches ("ada") ++ & Aunit_Shared.Adaflags; + + for Switches ("aunit.adb") use + Compiler'Default_Switches ("ada") & ("-fno-strict-aliasing"); +--- a/lib/gnat/aunit_shared.gpr ++++ b/lib/gnat/aunit_shared.gpr +@@ -10,7 +10,11 @@ + "rtp-smp", "soft-float", "xenomai", "zcx", "zfp", "minimal"); + Runtime : Runtime_Type := external ("RUNTIME", "full"); + +- Library_Dir := external ("LIBDIR", "../aunit/" & Target & "-" & Runtime); ++ type A_Library_Kind is ("dynamic", "static"); ++ Library_Kind : A_Library_Kind := External ("LIBRARY_KIND"); ++ Soversion := External ("SOVERSION"); ++ Adaflags := External_As_List ("ADAFLAGS", " "); ++ Ldflags := External_As_List ("LDFLAGS", " "); + + for Source_Dirs use (); + diff --git a/ada/libaunit-3.7.2/debian/patches/gpl.diff b/ada/libaunit-3.7.2/debian/patches/gpl.diff new file mode 100644 index 000000000..799a774a4 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/patches/gpl.diff @@ -0,0 +1,45 @@ +Description: remove ambiguity about GPL + All the content available on libre.adacore.com is licensed + under the terms of the pure GPL, despite the fact that AdaCore have + not yet adjusted the licensing boilerplate in documentation. + . + This is stated for example at + http://lists.adacore.com/pipermail/gtkada/2009-June/003789.html. The + actual license is a decision of AdaCore. Please contact them at + libre@adacore.com for any clarification. . + . + This is confirmed by the fact that COPYING3 exists in the top + directory. +Author: Nicolas Boulenguez +Forwarded: not-needed + +--- a/docs/aunit.texi ++++ b/docs/aunit.texi +@@ -58,13 +58,6 @@ + + Copyright @copyright{} 2000-2014, AdaCore + +-@* +- +-This document may be copied, in whole or in part, in any form or by any +-means, as is or with alterations, provided that (1) alterations are clearly +-marked as alterations and (2) this copyright notice is included +-unmodified in any copy. +- + @end titlepage + + @ifhtml +@@ -86,10 +79,9 @@ + +

Copyright @copyright{} 2000-2014, AdaCore + +-

This document may be copied, in whole or in part, in any form or by any +-means, as is or with alterations, provided that (1) alterations are clearly +-marked as alterations and (2) this copyright notice is included +-unmodified in any copy. ++

This document is licensed under the GNU General Public License, ++either version 3 of the License, or (at your option) any later version. ++ + @end html + @end ifhtml + diff --git a/ada/libaunit-3.7.2/debian/patches/info_directory_entry.diff b/ada/libaunit-3.7.2/debian/patches/info_directory_entry.diff new file mode 100644 index 000000000..54cbd4005 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/patches/info_directory_entry.diff @@ -0,0 +1,18 @@ +Description: add dircategory and direntry in Info manual per Debian policy. +Author: Nicolas Boulenguez +Forwarded: no + +--- a/docs/aunit.texi ++++ b/docs/aunit.texi +@@ -13,6 +13,11 @@ + @afourpaper + @end iftex + ++@dircategory Software development ++@direntry ++* AUnit: (aunit). Ada unit test framework, similar to the Java JUnit ++@end direntry ++ + @c ----------------------------------------- MACRO + + @c Macro used for all AUnit examples diff --git a/ada/libaunit-3.7.2/debian/patches/path_doc_gps_plugin.diff b/ada/libaunit-3.7.2/debian/patches/path_doc_gps_plugin.diff new file mode 100644 index 000000000..fe5d85321 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/patches/path_doc_gps_plugin.diff @@ -0,0 +1,14 @@ +Description: Adapt doc path in gnat-gps plugin. +Author: Nicolas Boulenguez +Forwarded: not-needed + +--- a/support/aunit.xml ++++ b/support/aunit.xml +@@ -1,6 +1,6 @@ + + +- share/doc/aunit ++ share/doc/libaunit-doc + + + /Help/AUnit diff --git a/ada/libaunit-3.7.2/debian/patches/paths_in_doc.diff b/ada/libaunit-3.7.2/debian/patches/paths_in_doc.diff new file mode 100644 index 000000000..f3d158133 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/patches/paths_in_doc.diff @@ -0,0 +1,51 @@ +Description: Adapt path to examples in documentation. +Author: Nicolas Boulenguez +Forwarded: not-needed + +--- a/docs/aunit.texi ++++ b/docs/aunit.texi +@@ -157,7 +157,7 @@ + With this version, we have provided new examples illustrating the enhanced + features of the framework. These examples are in the AUnit + installation directory: +-/share/examples/aunit, and are also available in the source ++/usr/share/doc/libaunit-doc/examples, and are also available in the source + distribution aunit-@value{VERSION}-src/examples. + + The following examples are provided: +@@ -414,7 +414,7 @@ + + You can find a compilable example of + @code{AUnit.Simple_Test_Cases.Test_Case} usage in your AUnit installation +-directory: /share/examples/aunit/simple_test/ or from the ++directory: /usr/share/doc/libaunit-doc/examples/simple_test/ or from the + source distribution aunit-@value{VERSION}-src/examples/simple_test/ + + @c ---------------------- +@@ -580,7 +580,7 @@ + + You can find a compilable example of + @code{AUnit.Test_Caller} use in the AUnit installation +-directory: /share/examples/aunit/test_caller/ or from the ++directory: /usr/share/doc/libaunit-doc/examples/test_caller/ or from the + source distribution aunit-@value{VERSION}-src/examples/test_caller/ + + @c ====================================================================== +@@ -705,7 +705,7 @@ + + You can find a compilable example of fixture set up using + @code{AUnit.Test_Fixture} in your AUnit installation +-directory: /share/examples/aunit/test_fixture/ or from the ++directory: /usr/share/doc/libaunit-doc/examples/test_fixture/ or from the + AUnit source distribution aunit-@value{VERSION}-src/examples/test_fixture/. + + @c ====================================================================== +@@ -993,7 +993,7 @@ + the testing of tagged type hierarchies and to the testing of generic units. + + A full example of this kind of test organization is available in the AUnit +-installation directory: /share/examples/aunit/calculator, or ++installation directory: /usr/share/doc/libaunit-doc/examples/calculator, or + from the AUnit source distribution + aunit-@value{VERSION}-src/examples/calculator. + diff --git a/ada/libaunit-3.7.2/debian/patches/series b/ada/libaunit-3.7.2/debian/patches/series new file mode 100644 index 000000000..6e66b3bdc --- /dev/null +++ b/ada/libaunit-3.7.2/debian/patches/series @@ -0,0 +1,6 @@ +gpl.diff +adapt_projects.diff +path_doc_gps_plugin.diff +style_warnings.diff +info_directory_entry.diff +paths_in_doc.diff diff --git a/ada/libaunit-3.7.2/debian/patches/style_warnings.diff b/ada/libaunit-3.7.2/debian/patches/style_warnings.diff new file mode 100644 index 000000000..e4e303a75 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/patches/style_warnings.diff @@ -0,0 +1,15 @@ +Description: Fix noisy style warnings. +Author: Nicolas Boulenguez +Forwarded: no + +--- a/include/aunit/containers/ada_containers-aunit_lists.adb ++++ b/include/aunit/containers/ada_containers-aunit_lists.adb +@@ -66,7 +66,7 @@ + Next : Node_Access; + Prev : Node_Access) return Node_Access + is +- Res : Node_Access := New_Node_Type; ++ Res : constant Node_Access := New_Node_Type; + begin + Res.Element := Element; + Res.Next := Next; diff --git a/ada/libaunit-3.7.2/debian/rules b/ada/libaunit-3.7.2/debian/rules new file mode 100755 index 000000000..63642e1f4 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/rules @@ -0,0 +1,100 @@ +#!/usr/bin/make -f +# +# Debian Makefile for AUnit +# Copyright (c) 2009 Stephen Leake +# Copyright (c) 2004-2006 Ludovic Brenta +# Copyright (c) 2013-2016 Nicolas Boulenguez +# +# This program 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 3 of the License, or +# (at your option) any later version. +# +# This program 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 more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# + +DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie +# PIE should only affect the static library. +include /usr/share/dpkg/default.mk +include /usr/share/ada/debian_packaging*.mk + +DEB_DATE := $(shell dpkg-parsechangelog -S date) + +ADAFLAGS += -gnatfno -gnatwa -gnatVa + +LIB_NAME := $(patsubst lib%,%,$(DEB_SOURCE)) + +SOVERSION := $(shell sed debian/control -ne \ + '/^Package: $(DEB_SOURCE)\([0-9.]\+\)$$/ { s//\1/; p; q}') +ifndef SOVERSION + $(warning Could not guess SOVERSION from debian/control) + # Not error. Policy defines targets that may be run from outside build dir. +endif + +###################################################################### +POLICY_TARGETS := binary binary-arch binary-indep build build-arch \ + build-indep clean +.PHONY: $(POLICY_TARGETS) +$(POLICY_TARGETS): + dh $@ --with ada-library + +###################################################################### +# Ignore upstream Makefile/configure. +.PHONY: $(addprefix override_dh_auto_,configure build-arch build-indep test install clean) + +override_dh_auto_build-arch: + $(MAKE) \ + GPRBUILD='gprbuild $(BUILDER_OPTIONS) -XLIBRARY_KIND=static "-XADAFLAGS=$(ADAFLAGS) -fPIE" "-XSOVERSION=$(SOVERSION)"' + + $(MAKE) \ + GPRBUILD='gprbuild $(BUILDER_OPTIONS) -XLIBRARY_KIND=dynamic $(foreach var,ADAFLAGS LDFLAGS SOVERSION,"-X$(var)=$($(var))")' + +TOUCHED_TOO_MUCH := \ + include/aunit/containers/ada_containers-aunit_lists.adb +override_dh_auto_build-arch: deterministic-timestamps-in-ali-files-stamp +deterministic-timestamps-in-ali-files-stamp: + touch --date='$(DEB_DATE)' $(TOUCHED_TOO_MUCH) + touch $@ + +# For the freeze option, the faketime API does not allow to explicit +# the time zone, introducing an implicit dependency on it. +DEB_DATE_FAKETIME := $(shell date "+%F %T" -d "$(DEB_DATE)") +override_dh_auto_build-indep: version_information.backup + # Freeze the clock for deterministic PDF timestamps. + faketime -f "$(DEB_DATE_FAKETIME)" \ + $(MAKE) -C docs +version_information.backup: %.backup: % + mv $* $@ + echo MAJOR_VERSION=$(DEB_VERSION_UPSTREAM) \ + | sed 's/\./.\nMINOR_VERSION=/' > $* + +override_dh_auto_clean:: + dh_auto_clean + if test -e version_information.backup; then \ + mv version_information.backup version_information; \ + fi + +###################################################################### +# The order in this list matters for rdfind. +EXAMPLES := simple_test test_caller test_fixture calculator failures liskov +INSTALLED_EXAMPLES := $(addprefix debian/libaunit-doc/usr/share/doc/libaunit-doc/examples/,$(EXAMPLES)) +.PHONY: override_dh_installexamples-indep +override_dh_installexamples-indep: + dh_installexamples --indep + # Replace duplicate files with symlinks. + rdfind -outputname /dev/null -makesymlinks true $(INSTALLED_EXAMPLES) + # symlinks to make them relative (only if -indep build). + symlinks -r -s -c $(INSTALLED_EXAMPLES) + +###################################################################### +.PHONY: override_dh_compress +override_dh_compress: + dh_compress --package=libaunit-doc --exclude=usr/share/doc/libaunit-doc/examples/ +# Check calculator/tests/stack-test.adb.gz + dh_compress --remaining-packages diff --git a/ada/libaunit-3.7.2/debian/source/format b/ada/libaunit-3.7.2/debian/source/format new file mode 100644 index 000000000..163aaf8d8 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/ada/libaunit-3.7.2/debian/tests/control b/ada/libaunit-3.7.2/debian/tests/control new file mode 100644 index 000000000..547ffdf48 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/tests/control @@ -0,0 +1,2 @@ +Tests: link-with-shared examples +Depends: @, gprbuild diff --git a/ada/libaunit-3.7.2/debian/tests/examples b/ada/libaunit-3.7.2/debian/tests/examples new file mode 100644 index 000000000..7c1a58554 --- /dev/null +++ b/ada/libaunit-3.7.2/debian/tests/examples @@ -0,0 +1,74 @@ +#!/bin/sh +set -C -e -f -u +cd "$ADTTMP" + +cp -r /usr/share/doc/libaunit-doc/examples . +cd examples +###################################################################### +cat > st < tc < tf < c < "$MAIN.adb" < p.gpr < +

AUnit Cookbook +

AUnit - version @value{VERSION} +

Configuration level $Revision: 314387 $ +

Date: @today{} +

AdaCore + + + +

@url{http://www.adacore.com} + + +@page + +

Copyright @copyright{} 2000-2014, AdaCore + +

This document is licensed under the GNU General Public License, +either version 3 of the License, or (at your option) any later version. + +@end html +@end ifhtml + +@finalout + +@ifnothtml +@contents +@end ifnothtml + +@ifinfo + +@node Top +@top AUnit + +@menu +* Introduction:: +* Overview:: +* Test Cases:: +* Fixture:: +* Suite:: +* Reporting:: +* Test Organization:: +* Using AUnit with Restricted Run-Time Libraries:: +* Installation and Use:: +* GPS Support:: +@end menu +@end ifinfo + +@c ====================================================================== + +@node Introduction +@chapter Introduction + +@noindent +This is a short guide for using the AUnit test framework. +AUnit is an adaptation of the Java JUnit (Kent Beck, Erich Gamma) and C++ +CppUnit (M. Feathers, J. Lacoste, E. Sommerlade, B. Lepilleur, B. Bakker, +S. Robbins) unit test frameworks for Ada code. + +@c --------------------------- +@section What's new in AUnit 3 + +AUnit 3 brings several enhancements over AUnit 2 and AUnit 1: +@itemize + +@item Removal of the genericity of the AUnit framework, making the AUnit 3 +API as close as possible to AUnit 1. + +@item Emulates dynamic memory management for limited run-time profiles. + +@item Provides a new XML reporter, and changes harness invocation to support +easy switching among text, XML and customized reporters. + +@item Provides new tagged types Simple_Test_Case, Test_Fixture and +Test_Caller that correspond to CppUnit's TestCase, TestFixture and TestCaller +classes. + +@item Emulates exception propagation for restricted run-time profiles +(e.g. ZFP), by using the gcc builtin setjmp/longjmp mechanism. + +@item Reports the source location of an error when possible. + +@end itemize + +@c -------------- +@section Examples + +With this version, we have provided new examples illustrating the enhanced +features of the framework. These examples are in the AUnit +installation directory: +/usr/share/doc/libaunit-doc/examples, and are also available in the source +distribution aunit-@value{VERSION}-src/examples. + +The following examples are provided: +@itemize +@item simple_test: shows use of AUnit.Simple_Test_Cases +(@pxref{AUnit.Simple_Test_Cases}). +@item test_caller: shows use of AUnit.Test_Caller (@pxref{AUnit.Test_Caller}). +@item test_fixture: example of a test fixture (@pxref{Fixture}). +@item liskov: This suite tests conformance to the Liskov Substitution Principle +of a pair of simple tagged types. (@pxref{OOP considerations}) +@item failures: example of handling and reporting failed tests +(@pxref{Reporting}). +@item calculator: a full example of test suite organization. +@end itemize + +@c ---------------------------------- +@section Note about limited run-times + +AUnit allows a great deal of flexibility as to the structure of test cases, +suites and harnesses. The templates and examples given in this document +illustrate how to use AUnit while staying within the constraints of the +GNAT Pro restricted and Zero Foot Print (ZFP) run-time libraries. Therefore, +they avoid the use of dynamic allocation and some other features that would +be outside of the profiles corresponding to these libraries. Tests targeted +to the full Ada run-time library need not comply with these constraints. + +@c ------------ +@section Thanks + +This document is adapted from the JUnit and CppUnit Cookbooks documents +contained in their respective release packages. + +Special thanks to Francois Brun of Thales Avionics for his ideas about +support for OOP testing. + +@c ====================================================================== + +@node Overview +@chapter Overview + +How do you write testing code? + +The simplest way is as an expression in a debugger. You can change +debug expressions without recompiling, and you can wait to decide +what to write until you have seen the running objects. You can also +write test expressions as statements that print to the standard +output stream. Both styles of tests are limited because they require +human judgment to analyze their results. Also, they don't compose +nicely - you can only execute one debug expression at a time and a +program with too many print statements causes the dreaded "Scroll +Blindness". + +AUnit tests do not require human judgment to interpret, and it is +easy to run many of them at the same time. When you need to test +something, here is what you do: + +@enumerate + +@item Derive a test case type from @code{AUnit.Simple_Test_Cases.Test_Case}. + +Several test case types are available: +@itemize +@item @code{AUnit.Simple_Test_Cases.Test_Case}: the base type for all test +cases. Needs overriding of @code{Name} and @code{Run_Test}. +@item @code{AUnit.Test_Cases.Test_Case}: the traditional AUnit test case type, +allowing multiple test routines registration, each being run and reported +independently. +@item @code{AUnit.Test_Fixtures.Test_Fixture}: used together with +@code{AUnit.Test_Caller}, this allows easy creation of test suites comprising +several test cases that share the same fixture (@pxref{Fixture}). +@end itemize + +@xref{Test Cases}, for simple examples of use of these types. + +@item When you want to check a value@footnote{While JUnit and some other +members of the xUnit family of unit test frameworks provide specialized forms +of assertions (e.g. @code{assertEqual}), we took a design decision in AUnit +not to provide such forms. Ada has a much more rich type system giving a +plethora of possible scalar types, and leading to an explosion of possible +special forms of assert routines. This is exacerbated by the lack of a single +root type for most types, as is found in Java. With the introduction of +AUnit 2 for use with restricted run-time profiles, where even 'Image is +missing, providing a comprehensive set of special assert routines in the +framework itself becomes even more unrealistic. Since AUnit is intended to +be an extensible toolkit, users can certainly write their own custom +collection of such assert routines to suit local usage.}, use one of the +following @code{Assert}@footnote{Note that in AUnit 3, and contrary to +AUnit 2, the procedural form of @code{Assert} has the same behavior whatever +the underlying Ada run-time library: a failed assertion will cause the +execution of the calling test routine to be abandoned. The functional form of +@code{Assert} always continues on a failed assertion, and provides you +with a choice of behaviors.} methods: + +@AEXP{AUnit.Assertions.Assert (@b{Boolean_Expression}, @b{String_Description});} +or: +@AEXP{if not AUnit.Assertions.Assert (@b{Boolean_Expression}, @b{String_Description}) then + return; +end if;} + +If you need to test that a method raises an expected exception, there +is the procedure @code{Assert_Exception} that takes an access value designating the procedure +to be tested as a parameter: + +@AEXP{ + type Throwing_Exception_Proc is access procedure; + + procedure Assert_Exception + (Proc : Throwing_Exception_Proc; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line); + -- Test that Proc throws an exception and record "Message" if not. +} + +Example: + +@AEXP{ + -- Declared at library level: + procedure Test_Raising_Exception is + begin + call_to_the_tested_method (some_args); + end Test_Raising_Exception; + +-- In test routine: +procedure My_Routine (...) is +begin + Assert_Exception (Test_Raising_Exception'Access, @b{String_Description}); +end;} + +This procedure can handle exceptions with all run-time profiles (including +zfp). If you are using a run-time library capable of propagating exceptions, +you can use the following idiom instead: + +@AEXP{ + procedure My_Routine (...) is + begin + ... + -- Call subprogram expected to raise an exception: + Call_To_The_Tested_Method (some_args); + Assert (False, ``exception not raised''); + exception + when desired_exception => + null; + end My_Procedure;} + +An unexpected exception will be recorded as such by the framework. If you want +your test routine to continue beyond verifying that an expected exception has +been raised, you can nest the call and handler in a block. + +@item Create a suite function inside a package to gather together test cases +and sub-suites@footnote{If using the ZFP or the 'cert' run-time profiles, test + cases and suites must be allocated using + @code{AUnit.Memory.Utils.Gen_Alloc}, @code{AUnit.Test_Caller.Create}, + @code{AUnit.Test_Suites.New_Suite}, or be statically allocated.}. + +@item At any level at which you wish to run tests, create a harness by +instantiating procedure @code{AUnit.Run.Test_Runner} or function +@code{AUnit.Run.Test_Runner_With_Status} with the top-level suite +function to be executed. This instantiation provides a routine +that executes all of the tests in the suite. We will call this +user-instantiated routine @code{@b{Run}} in the text for backward compatibility +to tests developed for AUnit 1. Note that only one instance of @code{@b{Run}} +can execute at a time. This is a tradeoff made to reduce the stack requirement +of the framework by allocating test result reporting data structures +statically. + +It is possible to pass a filter to a @code{Test_Runner}, so that only a +subset of the tests run. In particular, this filter could be initialized from +a command line parameter. See the package @code{AUnit.Test_Filters} for an +example of such a filter. AUnit does not automatically initialize this filter +from the command line both because it would not be supported with some of the +limited runtimes (zero footprint for instance), and because you might want to +pass the argument through different ways (as a parameter to switch, or a stand-alone +command line argument for instance). + +It is also possible to control the contents of the output report by passing an +object of type @code{AUnit_Options} to the @code{Test_Runner}. See package +@code{AUnit.Options} for details. + +@item Build the code that calls the harness @code{@b{Run}} routine using +gnatmake or gprbuild. The GNAT project file @i{aunit.gpr} contains all +necessary switches, and should be imported into your root project file. + +@end enumerate + +@c ====================================================================== + +@node Test Cases +@chapter Test Case + +@menu +* AUnit.Simple_Test_Cases:: +* AUnit.Test_Cases:: +* AUnit.Test_Caller:: +@end menu + +@noindent +In this chapter, we will introduce how to use the various forms of Test +Cases. We will illustrate with a very simple test routine, that verifies +that the sum of two Moneys with the same currency result in a value +which is the sum of the values of the two Moneys: + +@AEXP{declare + X, Y: Some_Currency; +begin + X := 12; Y := 14; + Assert (X + Y = 26, "Addition is incorrect"); +end;} + +The following sections will show how to use this test method using the +different test case types available in AUnit. + +@c ----------------------------- +@node AUnit.Simple_Test_Cases +@section AUnit.Simple_Test_Cases + +@noindent +@code{AUnit.Simple_Test_Cases.Test_Case} is the root type of all test + cases. Although generally not meant to be used directly, it provides a + simple and quick way to run a test. + +This tagged type has several methods that need to be defined, or may be +overridden. + +@itemize +@item @code{function Name (T : Test_Case) return Message_String is abstract}: + +This function returns the Test name. You can easily translate regular +strings to Message_String using @code{AUnit.Format}. For example: + +@AEXP{function Name (@b{T} : @b{Money_Test}) return Message_String is +begin + return Format (@b{"Money Tests"}); +end Name;} + +@item @code{procedure Run_Test (T : in out Test_Case) is abstract}: + +This procedure contains the test code. For example: +@AEXP{procedure Run_Test (@b{T} : in out @b{Money_Test}) is + @b{X, Y: Some_Currency;} +begin + @b{X := 12; Y := 14;} + @b{Assert (X + Y = 26, "Addition is incorrect");} +end Run_Test;} + +@item @code{procedure Set_Up (T : in out Test_Case);} and @code{procedure +Tear_Down (T : in out Test_Case);} (default implementations do nothing): + +These procedures are meant to respectively set up or tear down the +environment before running the test case. @xref{Fixture}, for examples +of how to use these methods. + +@end itemize + +You can find a compilable example of +@code{AUnit.Simple_Test_Cases.Test_Case} usage in your AUnit installation +directory: /usr/share/doc/libaunit-doc/examples/simple_test/ or from the +source distribution aunit-@value{VERSION}-src/examples/simple_test/ + +@c ---------------------- +@node AUnit.Test_Cases +@section AUnit.Test_Cases + +@code{AUnit.Test_Cases.Test_Case} is derived from +@code{AUnit.Simple_Test_Cases.Test_Case} and defines its +@code{Run_Test} procedure. + +It allows a very flexible composition of Test routines inside a single +test case, each being reported independently. + +The following subprograms must be considered for inheritance, overriding or +completion: + +@itemize + +@item @code{function Name (T : Test_Case) return Message_String is abstract;} +Inherited. @xref{AUnit.Simple_Test_Cases}. + +@item @code{procedure Set_Up (T : in out Test_Case)} and @code{procedure +Tear_Down (T : in out Test_Case)} +Inherited. @xref{AUnit.Simple_Test_Cases}. + +@item @code{procedure Set_Up_Case (T : in out Test_Case)} and +@code{procedure Tear_Down_Case (T : in out Test_Case)} +Default implementation does nothing. + + +The latter procedures provide an opportunity to Set Up and Tear Down the test +case before and after all test routines have been executed. In contrast, the +inherited @code{Set_Up} and @code{Tear_Down} are called before and after the +execution of each individual test routine. + +@item @code{procedure Register_Tests (T : in out Test_Case) is +abstract} +This procedure must be overridden. It is responsible for registering all +the test routines that will be run. You need to use either +@code{Registration.Register_Routine} or the generic +@code{Specific_Test_Case.Register_Wrapper} methods defined in +@code{AUnit.Test_Cases} to register a routine. A test routine has the +form: +@AEXP{procedure Test_Routine (T : in out Test_Case'Class);} +or +@AEXP{procedure Test_Wrapper (T : in out Specific_Test_Case'Class);} + +The former procedure is used mainly for dispatching calls +(@pxref{OOP considerations}). + +@end itemize + +Using this type to test our money addition, the package spec is: + +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Cases; use AUnit.Test_Cases; + +package @b{Money_Tests} is + + type @b{Money_Test} is new Test_Cases.Test_Case with @b{null record}; + + procedure Register_Tests (@b{T}: in out @b{Money_Test}); + -- Register routines to be run + + function Name (@b{T}: @b{Money_Test}) return Message_String; + -- Provide name identifying the test case + + -- Test Routines: + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class); +end @b{Money_Tests};} + +The package body is: + +@AEXP{with AUnit.Assertions; use AUnit.Assertions; + +package body @b{Money_Tests} is + + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class) is + @b{X, Y : Some_Currency;} + begin + @b{X := 12; Y := 14;} + @b{Assert (X + Y = 26, "Addition is incorrect");} + end @b{Test_Simple_Add}; + + -- Register test routines to call + procedure Register_Tests (@b{T}: in out @b{Money_Test}) is + + use AUnit.Test_Cases.Registration; + + begin + -- Repeat for each test routine: + Register_Routine (@b{T}, @b{Test_Simple_Add}'Access, @b{"Test Addition"}); + end Register_Tests; + + -- Identifier of test case + + function Name (@b{T}: @b{Money_Test}) return Test_String is + begin + return Format (@b{"Money Tests"}); + end Name; + +end @b{Money_Tests};} + +@c ----------------------- +@node AUnit.Test_Caller +@section AUnit.Test_Caller + +@noindent +@code{Test_Caller} is a generic package that is used with +@code{AUnit.Test_Fixtures.Test_Fixture}. @code{Test_Fixture} is a very +simple type that provides only the @code{Set_Up} and @code{Tear_Down} +procedures. This type is meant to contain a set of user-defined test +routines, all using the same Set up and Tear down mechanisms. Once those +routines are defined, the Test_Caller package is used to incorporate them +directly into a test suite. + +With our money example, the Test_Fixture is: + +@AEXP{with AUnit.Test_Fixtures; +package @b{Money_Tests} is + type @b{Money_Test} is new AUnit.Test_Fixtures.Test_Fixture @b{with null record}; + + procedure @b{Test_Simple_Add} (@b{T} : in out @b{Money_Test}); + +end @b{Money_Tests};} + +The test suite (@pxref{Suite}) calling the test cases created from +this Test_Fixture is: + +@AEXP{with AUnit.Test_Suites; + +package Money_Suite is + function Suite return AUnit.Test_Suites.Access_Test_Suite; +end Money_Suite;} + +With the corresponding body: + +@AEXP{with AUnit.Test_Caller; +with Money_Tests; + +package body Money_Suite is + + package Money_Caller is new AUnit.Test_Caller + (Money_Tests.Money_Test); + + function Suite return Aunit.Test_Suites.Access_Test_Suite is + Ret : AUnit.Test_Suites.Access_Test_Suite := + AUnit.Test_Suites.New_Suite; + begin + Ret.Add_Test + (Money_Caller.Create + (@b{"Money Test : Test Addition"}, + @b{Money_Tests.Test_Simple_Add}'Access)); + return Ret; + end Suite; + +end Money_Suite;} + +Note that @code{New_Suite} and @code{Create} are fully compatible with +limited run-times (in particular, those without dynamic allocation support). +Note, however, that for non-native run-time libraries, you cannot extend +@code{Test_Fixture} with a controlled component. + +You can find a compilable example of +@code{AUnit.Test_Caller} use in the AUnit installation +directory: /usr/share/doc/libaunit-doc/examples/test_caller/ or from the +source distribution aunit-@value{VERSION}-src/examples/test_caller/ + +@c ====================================================================== + +@node Fixture +@chapter Fixture + +@noindent +Tests need to run against the background of a set of known entities. +This set is called a test fixture. When you are +writing tests you will often find that you spend more time writing +code to set up the fixture than you do in actually testing values. + +You can make writing fixture code easier by sharing it. +Often you will be able to use the same fixture for several different +tests. Each case will send slightly different messages or parameters to the +fixture and will check for different results. + +When you have a common fixture, here is what you do: + +@enumerate +@item Create a Test Case package as in previous section. + +@item Declare variables or components for elements of the fixture either +as part of the test case type or in the package body. + +@item According to the Test_Case type used, override its @code{Set_Up} +and/or @code{Set_Up_Case} method: + +@itemize +@item @code{AUnit.Simple_Test_Cases}: @code{Set_Up} is called before +@code{Run_Test}. + +@item @code{AUnit.Test_Cases}: @code{Set_Up} is called before each test +routine while @code{Set_Up_Case} is called once before the routines are run. + +@item @code{AUnit.Test_Fixture}: @code{Set_Up} is called before each +test case created using @code{Aunit.Test_Caller}. +@end itemize + +@item You can also override @code{Tear_Down} and/or +@code{Tear_Down_Case} that are executed after the test is run. + +@end enumerate + +@noindent +For example, to write several test cases that want to work with +different combinations of 12 Euros, 14 Euros, and 26 US Dollars, first +create a fixture. The package spec is now: + +@AEXP{with @b{AUnit}; use @b{AUnit}; + +package @b{Money_Tests} is + use Test_Results; + + type @b{Money_Test} is new Test_Cases.Test_Case with @b{null record}; + + procedure Register_Tests (@b{T}: in out @b{Money_Test}); + -- Register routines to be run + + function Name (@b{T} : @b{Money_Test}) return Test_String; + -- Provide name identifying the test case + + procedure Set_Up (@b{T} : in out @b{Money_Test}); + -- Set up performed before each test routine + + -- Test Routines: + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class); +end @b{Money_Tests};} + +The body becomes: + +@AEXP{package body @b{Money_Tests} is + + use Assertions; + + -- Fixture elements + + @b{EU_12, EU_14 : Euro; + US_26 : US_Dollar;} + + -- Preparation performed before each routine + + procedure Set_Up (@b{T}: in out @b{Money_Test}) is + begin + @b{EU_12 := 12; EU_14 := 14; + US_26 := 26;} + end Set_Up; + + procedure @b{Test_Simple_Add} (@b{T} : in out Test_Cases.Test_Case'Class) is + @b{X, Y : Some_Currency;} + begin + @b{Assert + (EU_12 + EU_14 /= US_26, + "US and EU currencies not differentiated");} + end @b{Test_Simple_Add}; + + -- Register test routines to call + procedure Register_Tests (@b{T}: in out @b{Money_Test}) is + + use @b{Test_Cases.Registration}; + + begin + -- Repeat for each test routine: + Register_Routine (@b{T}, @b{Test_Simple_Add}'Access, @b{"Test Addition"}); + end Register_Tests; + + -- Identifier of test case + function Name (@b{T}: @b{Money_Test}) return Test_String is + begin + return Format (@b{"Money Tests"}); + end Name; + +end @b{Money_Tests};} + +@noindent +Once you have the fixture in place, you can write as many test +routines as you like. Calls to @code{Set_Up} and @code{Tear_Down} +bracket the invocation of each test routine. + +Once you have several test cases, organize them into a Suite. + +You can find a compilable example of fixture set up using +@code{AUnit.Test_Fixture} in your AUnit installation +directory: /usr/share/doc/libaunit-doc/examples/test_fixture/ or from the +AUnit source distribution aunit-@value{VERSION}-src/examples/test_fixture/. + +@c ====================================================================== + +@node Suite +@chapter Suite + +@c --------------------------- +@section Creating a Test Suite + +How do you run several test cases at once? + +As soon as you have two tests, you'll want to run them together. +You could run the tests one at a time yourself, but you would quickly +grow tired of that. Instead, AUnit provides an object, @code{Test_Suite}, +that runs any number of test cases together. + +@noindent +To create a suite of two test cases and run them together, first create +a test suite: + +@AEXP{with AUnit.Test_Suites; +package @b{My_Suite} is + function @b{Suite} return AUnit.Test_Suites.Access_Test_Suite; +end @b{My_Suite};} + +@AEXP{-- Import tests and sub-suites to run +with @b{Test_Case_1, Test_Case_2}; + +package body @b{My_Suite} is + use AUnit.Test_Suites; + + -- Statically allocate test suite: + @b{Result} : aliased Test_Suite; + + -- Statically allocate test cases: + @b{Test_1 : aliased Test_Case_1.Test_Case;} + @b{Test_2 : aliased Test_Case_2.Test_Case;} + + function @b{Suite} return Access_Test_Suite is + begin + Add_Test (@b{Result'Access, Test_Case_1'Access}); + Add_Test (@b{Result'Access, Test_Case_2'Access}); + return @b{Result'Access}; + end @b{Suite}; +end @b{My_Suite};} + +Instead of statically allocating test cases and suites, +you can also use @code{AUnit.Test_Suites.New_Suite} and/or +@code{AUnit.Memory.Utils.Gen_Alloc}. These routines emulate dynamic +memory management (@pxref{Using AUnit with Restricted Run-Time Libraries}). +Similarly, if you know that the tests will always be executed for a run-time +profile that supports dynamic memory management, you can allocate these +objects directly with the Ada @code{"new"} operator. + +@noindent +The harness is: +@AEXP{with @b{My_Suite}; +with AUnit.Run; +with AUnit.Reporter.Text; + +procedure @b{My_Tests} is + procedure @b{Run} is new AUnit.Run.Test_Runner (@b{My_Suite.Suite}); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + @b{Run} (Reporter); +end @b{My_Tests};} + +@c --------------------------- +@section Composition of Suites + +@noindent +Typically, one will want the flexibility to execute a complete set +of tests, or some subset of them. In order to facilitate this, we can +compose both suites and test cases, and provide a harness for any given +suite: + +@AEXP{-- Composition package: +with @b{AUnit}; use @b{AUnit}; +package @b{Composite_Suite} is + function @b{Suite} return Test_Suites.Access_Test_Suite; +end @b{Composite_Suite}; + +-- Import tests and suites to run +with @b{This_Suite, That_Suite}; +with AUnit.Tests; + +package body @b{Composite_Suite} is + use Test_Suites; + + -- Here we dynamically allocate the suite using the New_Suite function + -- We use the 'Suite' functions provided in This_Suite and That_Suite + -- We also use Ada 2005 distinguished receiver notation to call Add_Test + + function @b{Suite} return Access_Test_Suite is + @b{Result} : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + @b{Result}.Add_Test (@b{This_Suite.Suite}); + @b{Result}.Add_Test (@b{That_Suite.Suite}); + return @b{Result}; + end @b{Suite}; +end @b{Composite_Suite};} + +@noindent +The harness remains the same: + +@AEXP{with @b{Composite_Suite}; +with AUnit.Run; + +procedure @b{My_Tests} is + procedure @b{Run} is new AUnit.Run.Test_Runner (@b{Composite_Suite.Suite}); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + @b{Run} (Reporter); +end @b{My_Tests};} + +@noindent +As can be seen, this is a very flexible way of composing test cases +into execution runs: any combination of test cases and sub-suites can +be collected into a suite. + +@c ====================================================================== + +@node Reporting +@chapter Reporting + +Test results can be reported using several 'Reporters'. By default, two +reporters are available in AUnit: +@code{AUnit.Reporter.Text.Text_Reporter} and +@code{AUnit.Reporter.XML.XML_Reporter}. The first one is a simple +console reporting routine, while the second one outputs the result using +an XML format. These are invoked when the @code{Run} routine of an +instantiation of @code{AUnit.Run.Test_Runner} is called. + +@noindent +New reporters can be created using children of +@code{AUnit.Reporter.Reporter}. + +@noindent +The Reporter is selected by specifying it when calling @b{Run}: + +@AEXP{with A_Suite; +with AUnit.Run; +@b{with AUnit.Reporter.Text;} + +procedure My_Tests is + procedure Run is new AUnit.Run.Test_Runner (A_Suite.Suite); + @b{Reporter : AUnit.Reporter.Text.Text_Reporter;} +begin + Run (@b{Reporter}); +end My_Tests;} + +The final report is output once all tests have been run, so that they can be +grouped depending on their status (passed or fail). If you need to output the +tests as they are run, you should consider extending the @code{Test_Result} +type and do some output every time a success or failure is registered. + +@section Text output + +Here is an example where the test harness runs 4 tests, one reporting an +assertion failure, one reporting an unexpected error (exception): + +@smallexample +-------------------- + + Total Tests Run: 4 + + Successful Tests: 2 + Test addition + Test subtraction + + Failed Assertions: 1 + + Test addition (failure expected) + Test should fail this assertion, as 5+3 /= 9 + at math-test.adb:29 + + + Unexpected Errors: 1 + + Test addition (error expected) + CONSTRAINT_ERROR + + + +Time: 2.902E-4 seconds +@end smallexample + +@cindex colors +This reporter can optionally use colors (green to report success, red to report +errors). Since not all consoles support it, this is off by default, but you can +call @code{Set_Use_ANSI_Colors} to activate support for colors. + +@section XML output + +Following is the same harness run using XML output. The XML format used +matches the one used by CppUnit. + +Note that text set in the Assert methods, or as test case names should +be compatible with utf-8 character encoding, or the XML will not be +correctly formatted. + +@smallexample + + + + 4 + 2 + 1 + 1 + + + + Test addition + + + Test subtraction + + + + + Test addition (failure expected) + Assertion + Test should fail this assertion, as 5+3 /= 9 + + math-test.adb + 29 + + + + Test addition (error expected) + Error + CONSTRAINT_ERROR + + + +@end smallexample + +@c ====================================================================== + +@node Test Organization +@chapter Test Organization + +@menu +* General considerations:: +* OOP considerations:: +* Testing generic units:: +@end menu + +@c --------------------------- +@node General considerations +@section General considerations + +This section will discuss an approach to organizing an AUnit test harness, +considering some possibilities offered by Ada language features. + +The general idea behind this approach to test organization is that making the +test case a child of the unit under test gives some useful facilities. +The test case gains visibility to the private part of the unit under test. +This offers a more ``white box'' approach to examining the state of the unit +under test than would, for instance, accessor functions defined in a separate +fixture that is a child of the unit under test. Making the test case a child of +the unit under test also provides a way to make the test case share certain +characteristics of the unit under test. For instance, if the unit under test +is generic, then any child package (here the test case) must be also generic: +any instantiation of the parent package will require an instantiation of the +test case in order to accomplish its aims. + +Another useful concept is matching the test case type to that of the unit +under test: + +@itemize +@item When testing a generic package, the test package should also be +generic. +@item When testing a tagged type, then test routines should be +dispatching, and the test case type for a derived tagged type should be a +derivation of the test case type for the parent. +@item etc. +@end itemize + +Maintaining such similarity of properties between the test case and unit under +test can facilitate the testing of units derived in various ways. + +The following sections will concentrate on applying these concepts to +the testing of tagged type hierarchies and to the testing of generic units. + +A full example of this kind of test organization is available in the AUnit +installation directory: /usr/share/doc/libaunit-doc/examples/calculator, or +from the AUnit source distribution +aunit-@value{VERSION}-src/examples/calculator. + +@c --------------------------- +@node OOP considerations +@section OOP considerations + +When testing a hierarchy of tagged types, one will often want to run tests +for parent types against their derivations without rewriting those tests. + +We will illustrate some of the possible solutions available in AUnit, +using the following simple example that we want to test: + +First we consider a @code{Root} package defining the @code{Parent} +tagged type, with two procedures P1 and P2. + +@AEXP{package Root is + type Parent is tagged private; + + procedure P1 (P : in out Parent); + procedure P2 (P : in out Parent); +private + type Parent is tagged record + Some_Value : Some_Type; + end record; +end Root;} + +We will also consider a derivation of type @code{Parent}: + +@AEXP{with Root; +package Branch is + type Child is new Root.Parent with private; + + procedure P2 (C : in out Child); + procedure P3 (C : in out Child); +private + type Child is new Root.Parent with null record; +end Branch;} + +@noindent +Note that @code{Child} retains the parent implementation of @code{P1}, +overrides @code{P2} and adds @code{P3}. Its test will override +@code{Test_P2} when we override @code{P2} (not necessary, but certainly +possible). + +@subsection Using AUnit.Test_Fixtures + +@noindent +Using @code{Test_Fixture} type, we first test @code{Parent} using the +following test case: +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Fixtures; use AUnit.Test_Fixtures; + +-- We make this package a child package of Parent so that it can have +-- visibility to its private part +package @b{Root.Tests} is + + type @b{Parent_Access} is access all @b{Root.Parent'Class}; + + -- Reference an object of type Parent'Class in the test object, so + -- that test procedures can have access to it. + type @b{Parent_Test} is new Test_Fixture @b{with record} + @b{Fixture : Parent_Access;} + @b{end record}; + + -- This will initialize P. + procedure Set_Up (@b{P} : in out @b{Parent_Test}); + + -- Test routines. If derived types are declared in child packages, + -- these can be in the private part. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}); + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}); + +end @b{Root.Tests}; + +package body @b{Root.Tests} is + + @b{Fixture : aliased Parent;} + + -- We set Fixture in Parent_Test to an object of type Parent. + procedure Set_Up (@b{P} : in out @b{Parent_Test}) is + begin + @b{P.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up; + + -- Test routines: References to the Parent object are made via + -- P.Fixture.all, and are thus dispatching. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}) is ...; + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}) is ...; + +end @b{Root.Tests};} + +@noindent +The associated test suite will be: + +@AEXP{with AUnit.Test_Caller; +with @b{Root.Tests}; + +package body @b{Root_Suite} is + package @b{Caller} is new AUnit.Test_Caller with (@b{Root.Tests.Parent_Test}); + + function Suite return AUnit.Test_Suites.Access_Test_Suite is + @b{Ret} : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + AUnit.Test_Suites.Add_Test + (@b{Ret}, Caller.Create (@b{"Test Parent : P1"}, @b{Root.Tests.Test_P1'Access})); + AUnit.Test_Suites.Add_Test + (@b{Ret}, Caller.Create (@b{"Test Parent : P2"}, @b{Root.Tests.Test_P2'Access})); + return @b{Ret}; + end Suite; +end @b{Root_Suite};} + +@noindent +Now we define the test suite for the @code{Child} type. To do this, +we inherit a test fixture from @code{Parent_Test}, +overriding the @code{Set_Up} procedure to initialize @code{Fixture} with +a @code{Child} object. We also override @code{Test_P2} to adapt it +to the new implementation. We define a new @code{Test_P3} to test +@code{P3}. And we inherit @code{Test_P1}, since @code{P1} is unchanged. + +@AEXP{with @b{Root.Tests}; use @b{Root.Tests}; +with AUnit; use AUnit; +with AUnit.Test_Fixtures; use AUnit.Test_Fixtures; + +package @b{Branch.Tests} is + + type @b{Child_Test} is new @b{Parent_Test} @b{with null record}; + + procedure Set_Up (@b{C} : in out @b{Child_Test}); + + -- Test routines: + -- Test_P2 is overridden + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}); + -- Test_P3 is new + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}); + +end @b{Branch.Tests}; + +package body @b{Branch.Tests} is + use Assertions; + + @b{Fixture : Child;} + -- This could also be a field of Child_Test + + procedure Set_Up (@b{C} : in out @b{Child_Test}) is + begin + -- The Fixture for this test will now be a Child + @b{C.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up; + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}) is ...; + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}) is ...; + +end @b{Branch.Tests};} + +The suite for Branch.Tests will now be: + +@AEXP{with AUnit.Test_Caller; +with @b{Branch.Tests}; + +package body @b{Branch_Suite} is + package @b{Caller} is new AUnit.Test_Caller with (@b{Branch.Tests.Parent_Test}); + + -- In this suite, we use Ada 2005 distinguished receiver notation to + -- simplify the code. + + function Suite return Access_Test_Suite is + Ret : Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + -- We use the inherited Test_P1. Note that it is + -- Branch.Tests.Set_Up that will be called, and so Test_P1 will be run + -- against an object of type Child + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P1"}, @b{Branch.Tests.Test_P1'Access})); + -- We use the overridden Test_P2 + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P2"}, @b{Branch.Tests.Test_P2'Access})); + -- We use the new Test_P2 + @b{Ret}.Add_Test + (@b{Caller}.Create (@b{"Test Child : P3"}, @b{Branch.Tests.Test_P3'Access})); + return @b{Ret}; + end Suite; +end @b{Branch_Suite};} + +@subsection Using AUnit.Test_Cases + +@noindent +Using an @code{AUnit.Test_Cases.Test_Case} derived type, we obtain the +following code for testing @code{Parent}: + +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Cases; +package @b{Root.Tests} is + + type @b{Parent_Access} is access all @b{Root.Parent'Class}; + + type @b{Parent_Test} is new AUnit.Test_Cases.Test_Case @b{with record} + @b{Fixture : Parent_Access;} + @b{end record}; + + function Name (@b{P} : @b{Parent_Test}) return Message_String; + procedure Register_Tests (@b{P} : in out @b{Parent_Test}); + + procedure Set_Up_Case (@b{P} : in out @b{Parent_Test}); + + -- Test routines. If derived types are declared in child packages, + -- these can be in the private part. + procedure @b{Test_P1} (@b{P} : in out @b{Parent_Test}); + procedure @b{Test_P2} (@b{P} : in out @b{Parent_Test}); + +end @b{Root.Tests};} + +@noindent +The body of the test case will follow the usual pattern, declaring one or +more objects of type @code{@b{Parent}}, and executing statements in the +test routines against them. However, in order to support dispatching to +overriding routines of derived test cases, we need to introduce class-wide +wrapper routines for each primitive test routine of the parent type that +we anticipate may be overridden. Instead of registering the parent's +overridable primitive operations directly using @code{Register_Routine}, +we register the wrapper using @code{Register_Wrapper}. This latter routine +is exported by instantiating +@code{@b{AUnit}.Test_Cases.Specific_Test_Case_Registration} with the actual +parameter being the parent test case type. + +@AEXP{with AUnit.Assertions; use AUnit.Assertions +package body @b{Root.Tests} is + + -- Declare class-wide wrapper routines for any test routines that will be + -- overridden: + procedure @b{Test_P1_Wrapper} (@b{P} : in out @b{Parent_Test}'Class); + procedure @b{Test_P2_Wrapper} (@b{P} : in out @b{Parent_Test}'Class); + + function Name (@b{P} : @b{Parent_Test}) return Message_String is ...; + + -- Set the fixture in P + @b{Fixture : aliased Parent;} + procedure Set_Up_Case (@b{P} : in out @b{Parent_Test}) is + begin + @b{P.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up_Case; + + -- Register Wrappers: + procedure Register_Tests (@b{P} : in out @b{Parent_Test}) is + + package @b{Register_Specific} is + new Test_Cases.Specific_Test_Case_Registration (@b{Parent_Test}); + + use Register_Specific; + + begin + Register_Wrapper (@b{P}, @b{Test_P1_Wrapper}'Access, @b{"Test P1"}); + Register_Wrapper (@b{P}, @b{Test_P2_Wrapper}'Access, @b{"Test P2"}); + end Register_Tests; + + -- Test routines: + procedure @b{Test_P1} (@b{P} : in out Parent_Test) is ...; + procedure @b{Test_P2} (@b{C} : in out Parent_Test) is ...; + + -- Wrapper routines. These dispatch to the corresponding primitive + -- test routines of the specific types. + procedure @b{Test_P1_Wrapper} (@b{P} : in out @b{Parent_Test}'Class) is + begin + @b{Test_P1} (@b{P}); + end @b{Test_P1_Wrapper}; + + procedure @b{Test_P2_Wrapper} (@b{P} : in out @b{Parent_Test}'Class) is + begin + @b{Test_P2} (@b{P}); + end @b{Test_P2_Wrapper}; + +end @b{Root.Tests};} + +@noindent +The code for testing the @code{Child} type will now be: + +@AEXP{with @b{Parent_Tests}; use @b{Parent_Tests}; +with AUnit; use AUnit; +package @b{Branch.Tests} is + + type @b{Child_Test} is new @b{Parent_Test} @b{with private}; + + function Name (@b{C} : @b{Child_Test}) return Message_String; + procedure Register_Tests (@b{C} : in out @b{Child_Test}); + + -- Override Set_Up_Case so that the fixture changes. + procedure Set_Up_Case (@b{C} : in out @b{Child_Test}); + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}); + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}); + +private + type @b{Child_Test} is new @b{Parent_Test} @b{with null record}; +end @b{Branch.Tests}; + +with AUnit.Assertions; use AUnit.Assertions; +package body @b{Branch.Tests} is + + -- Declare wrapper for Test_P3: + procedure @b{Test_P3_Wrapper} (@b{C} : in out @b{Child_Test}'Class); + + function Name (@b{C} : @b{Child_Test}) return Test_String is ...; + + procedure Register_Tests (@b{C} : in out @b{Child_Test}) is + + package @b{Register_Specific} is + new Test_Cases.Specific_Test_Case_Registration (@b{Child_Test}); + use @b{Register_Specific}; + + begin + -- Register parent tests for P1 and P2: + @b{Parent_Tests}.Register_Tests (@b{Parent_Test} (@b{C})); + + -- Repeat for each new test routine (Test_P3 in this case): + @b{Register_Wrapper} (@b{C}, @b{Test_P3_Wrapper}'Access, @b{"Test P3"}); + end Register_Tests; + + -- Set the fixture in P + @b{Fixture : aliased Child;} + procedure Set_Up_Case (@b{C} : in out @b{Child_Test}) is + begin + @b{C.Fixture := Parent_Access (Fixture'Access)}; + end Set_Up_Case; + + -- Test routines: + procedure @b{Test_P2} (@b{C} : in out @b{Child_Test}) is ...; + procedure @b{Test_P3} (@b{C} : in out @b{Child_Test}) is ...; + + -- Wrapper for new routine: + procedure @b{Test_P3_Wrapper} (@b{C} : in out @b{Child_Test}'Class) is + begin + @b{Test_P3} (@b{C}); + end @b{Test_P3_Wrapper}; + +end @b{Branch.Tests};} + +@noindent +Note that inherited and overridden tests do not need to be explicitly +re-registered in derived test cases - one just calls the parent version of +@code{Register_Tests}. If the application tagged type hierarchy is organized +into parent and child units, one could also organize the test cases into a +hierarchy that reflects that of the units under test. + +@c --------------------------- +@node Testing generic units +@section Testing generic units + +When testing generic units, one would like to apply the same generic tests +to all instantiations in an application. A simple approach is to make the +test case a child package of the unit under test (which then must also be +generic). + +For instance, suppose the generic unit under test is a package (it could +be a subprogram, and the same principle would apply): +@AEXP{generic + -- Formal parameter list +package Template is + -- Declarations +end Template;} + +@noindent +The corresponding test case would be: +@AEXP{with AUnit; use AUnit; +with AUnit.Test_Fixtures; +generic +package @b{Template.Gen_Tests} is + + type @b{Template_Test} is new AUnit.Test_Fixtures.Test_Fixture with @b{...}; + + -- Declare test routines + +end @b{Template.Gen_Tests};} + +The body will follow the usual patterns with the fixture based on the +parent package @code{Template}. Note that due to an Ada AI, accesses to +test routines, along with the test routine specifications, must be defined +in the package specification rather than in its body. + +Instances of @code{Template} will define automatically the Tests child +package that can be directly instantiated as follow: + +@AEXP{with Template.Gen_Test; +with Instance_Of_Template; +package Instance_Of_Template.Tests is new Instance_Of_Template.Gen_Test;} + +The instantiated test case objects are added to a suite in the usual manner. + +@c ================================================================= + +@node Using AUnit with Restricted Run-Time Libraries +@chapter Using AUnit with Restricted Run-Time Libraries + +@noindent +AUnit 3 - like AUnit 2 - is designed so that it can be used in +environments with restricted Ada run-time libraries, such as ZFP and the cert +run-time profile on Wind River Systems' VxWorks 653. The patterns given in +this document for writing tests, suites and harnesses are not the only +patterns that can be used with AUnit, but they are compatible with the +restricted run-time libraries provided with GNAT Pro. + +In general, dynamic allocation and deallocation must be used carefully in test +code. For the cert profile on VxWorks 653, all dynamic allocation must be +done prior to setting the application partition into ``normal'' mode. +Deallocation is prohibited in this profile. For the default ZFP profile, +dynamic memory management is not provided as part of the run-time, as it is +not available on a bare board environment, and should not be used unless +you have provided implementations as described in the GNAT Pro High Integrity +User Guide. + +Starting with AUnit 3, a simple memory management mechanism has been +included in the framework, using a kind of storage pool. This memory +management mechanism uses a static array allocated at startup, and simulates +dynamic allocation afterwards by allocating parts of this array upon request. +Deallocation is not permitted. + +By default, the allocated array is a 100 KB array. This value can be changed +by modifying its size in the file: +@file{aunit-@value{VERSION}-src/aunit/framework/staticmemory/aunit-memory.adb} + +To allocate a new object, you use @code{AUnit.Memory.Utils.Gen_Alloc}. + +Additional restrictions relevant to the default ZFP profile include: +@enumerate +@item +Normally the ZFP profile requires a user-defined +@code{__gnat_last_chance_handler} routine +to handle raised exceptions. However, AUnit now provides a mechanism to +simulate exception propagation using gcc builtin setjmp/longjmp mechanism. +This mechanism defines the @code{__gnat_last_chance_handler} routine, so it +should not be redefined elsewhere. In order to be compatible with this +restriction, the user-defined last chance handler routine can be defined as a +"weak" symbol; this way, it will still be linked into the standalone executable, +but will be replaced by the AUnit implementation when linked with the harness. +The pragma Weak_External can be used for that, e.g.: + +@smallexample +pragma Weak_External (Last_Chance_Handler); +@end smallexample + +@item +AUnit requires @code{GNAT.IO} provided in @file{g-io.ad?} in the full or cert +profile run-time library sources (or as implemented by the user). Since this +is a run-time library unit it must be compiled with the gnatmake ``-a'' +switch. + +@item +The AUnit framework has been modified so that no call to the secondary +stack is performed, nor any call to memcpy or memset. However, if the unit +under test, or the tests themselves require use of those routines, then the +application or test framework must define those symbols and provide the +requisite implementations. + +@item +The timed parameter of the Harness @code{Run} routine has no effect when used +with the ZFP profile, and on profiles not supporting Ada.Calendar. +@end enumerate + +@node Installation and Use +@chapter Installation and Use + +@menu +* Note on gprbuild:: +* Support for other platforms/run-times:: +* Installing AUnit:: +* Installed files:: +@end menu + +@noindent +AUnit 3 contains support for limited run-times such as zero-foot-print +(ZFP) and certified run-time (cert). It can now be installed simultaneously +for several targets and run-times. + +@c -------------------------------------- +@node Note on gprbuild +@section Note on gprbuild + +@noindent +In order to compile, install and use AUnit, you need gprbuild and gprinstall +version 2.2.0 or above. + +@c --------------------------------------------------------- +@node Support for other platforms/run-times +@section Support for other platforms/run-times + +AUnit should be built and installed separately for each target and run-time +it is meant to be used with. The necessary customizations are performed at +AUnit build time, so once the framework is installed, it is always referenced +simply by adding the line + +@smallexample +with "aunit"; +@end smallexample + +to your project. + +@c -------------------------------------- +@node Installing AUnit +@section Installing AUnit + +@noindent +Normally AUnit comes preinstalled and ready-to-use for all runtimes in +your GNAT distribution. The following instructions are for rebuilding it from +sources for the custom configuration that the user may have. + +@itemize +@item +Extract the archive: +@smallexample + $ gunzip -dc aunit-@value{VERSION}-src.tgz | tar xf - +@end smallexample + +@item +To build AUnit for a full Ada run-time: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make +@end smallexample + +To build AUnit for a zfp run-time targeting powerpc-elf platform: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make TARGET=powerpc-elf RTS=zfp +@end smallexample + +To build AUnit for a reconfigurable runtime zfp-leon3 targeting leon3-elf +platform: +@smallexample + $ cd aunit-@value{VERSION}-src + $ make TARGET=leon3-elf RTS=zfp RTS_CONF="--RTS=zfp-leon3" +@end smallexample + + +Once the above build procedure has been performed for the desired platform, you +can install AUnit: +@smallexample + $ make install INSTALL= +@end smallexample + +We recommend that you install AUnit into the standard location used by gprbuild +to find the libraries for a given configuration. For example for the case above +(runtime zfp-leon3 targeting leon3-elf), the default location is +/leon3-elf/zfp-leon3. If the runtime is located in a custom +directory and specified by the full path, using this exact path also as + is a sensible choice. + +If INSTALL is not specified, then AUnit will use the root directory where +gprbuild is installed. + +@item +Specific installation: + + The AUnit makefile supports some specific options, activated using + environment variables. The following options are defined: + +@itemize +@item @b{INSTALL}: defines the AUnit base installation directory, set to +gprbuild's base installation directory as found in the PATH. + +@item @b{TARGET}: defines the gnat tools prefix to use. For example, to compile +AUnit for powerpc VxWorks, TARGET should be set to powerpc-wrs-vxworks. If not +set, the native compiler will be used. + +@item @b{RTS}: defines both the run-time used to compile AUnit and the value +given to the AUnit project as RUNTIME scenario variable. + +@item @b{RTS_CONF}: defines the gprbuild Runtime config flag. The value is +set to "--RTS=$(RTS)" by default. Can be used when compiling AUnit for a +configurable run-time. +@end itemize + +@item +To test AUnit: + + The AUnit test suite is in the test subdirectory of the source package. +@smallexample + $ cd test + $ make +@end smallexample + The test suite's makefile supports the following variables: + @itemize + @item @b{RTS} + @item @b{TARGET} + @end itemize +@end itemize + + +@c --------------------- +@node Installed files +@section Installed files + +@noindent +The AUnit library is installed in the specified directory ( +identifies the root installation directory as specified during the installation +procedures above): + +@itemize +@item + the aunit.gpr project is installed in /lib/gnat +@item + the AUnit source files are installed in /include/aunit +@item + the AUnit library files are installed in /lib/aunit +@item + the AUnit documentation is installed in /share/doc/aunit +@item + the AUnit examples are installed in /share/examples/aunit +@end itemize + +@node GPS Support +@chapter GPS Support + +@noindent +GPS IDE relies on gnattest tool that creates unit-test skeletons as well as +a test driver infrastructure (harness). Harness can be generated for project +hierarchy, single project or a package. Generation process can be launched +from @b{Tools -> GNATtest} menu or from contextual menu. + +@bye diff --git a/ada/libaunit-3.7.2/docs/makefile b/ada/libaunit-3.7.2/docs/makefile new file mode 100644 index 000000000..64b5ef0c7 --- /dev/null +++ b/ada/libaunit-3.7.2/docs/makefile @@ -0,0 +1,83 @@ +.SILENT: + +MAKEINFO = $(shell which makeinfo 2> /dev/null) +DVIPS = $(shell which dvips 2> /dev/null) +TEXI2DVI = $(shell which texi2dvi 2> /dev/null) +PDFTEX = $(shell which pdftex 2> /dev/null) + +aunit_docs: version aunit.pdf aunit.html aunit.txt aunit.info + echo "" + echo Documentation built with success. + +version: + sed 's/^/@set /g;s/=/ /g' ../version_information > version.texi + +%.dvi: %.texi +ifneq (${TEXI2DVI},) + echo Building $@ + ${TEXI2DVI} --expand --clean --quiet $< +else + @echo "--------------------------------------------------------" + @echo "texi2dvi not found, cannot build DVI or PS documentation" + @echo "--------------------------------------------------------" +endif + +%.ps: %.dvi +ifneq (${DVIPS},) + echo Building $@ + ${DVIPS} -q $< -o $@ +else + @echo "------------------------------------------------------" + @echo "dvips not found, cannot build POSTSCRIPT documentation" + @echo "------------------------------------------------------" +endif + +%.pdf: %.texi +ifneq (${TEXI2DVI},) +ifneq (${PDFTEX},) + echo Building $@ + ${TEXI2DVI} -p --expand --clean --quiet $< +else + @echo "-----------------------------------------------" + @echo "pdftex not found, cannot build PDF documentation" + @echo "-----------------------------------------------" +endif +else + @echo "--------------------------------------------------" + @echo "texi2dvi not found, cannot build PDF documentation" + @echo "--------------------------------------------------" +endif + +%.info: %.texi +ifneq (${MAKEINFO},) + echo Building $@ + ${MAKEINFO} $< +else + @echo "---------------------------------------------------" + @echo "makeinfo not found, cannot build INFO documentation" + @echo "---------------------------------------------------" +endif + +%.html: %.texi +ifneq (${MAKEINFO},) + echo Building $@ + ${MAKEINFO} --html --no-split --css-include=aunit.css --ifinfo $< +else + @echo "---------------------------------------------------" + @echo "makeinfo not found, cannot build HTML documentation" + @echo "---------------------------------------------------" +endif + +%.txt: %.texi +ifneq (${MAKEINFO},) + echo Building $@ + ${MAKEINFO} --plaintext --no-headers $< --output $@ +else + @echo "---------------------------------------------------" + @echo "makeinfo not found, cannot build TEXT documentation" + @echo "---------------------------------------------------" +endif + +clean: + -$(RM) -f aunit.dvi aunit.html aunit.info* aunit.log + -$(RM) -f aunit.ps aunit.pdf aunit.txt *~ version.texi diff --git a/ada/libaunit-3.7.2/examples/calculator/fixture/main_suite.adb b/ada/libaunit-3.7.2/examples/calculator/fixture/main_suite.adb new file mode 100644 index 000000000..266e1b327 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/fixture/main_suite.adb @@ -0,0 +1,21 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Stack.Test.Suite; +with Operations.Addition.Test.Suite; +with Operations.Subtraction.Test.Suite; +with Operands.Ints.Test.Suite; + +package body Main_Suite is + + function Suite return Access_Test_Suite is + Ret : constant Access_Test_Suite := new Test_Suite; + begin + Ret.Add_Test (Stack.Test.Suite.Suite); + Ret.Add_Test (Operations.Addition.Test.Suite.Suite); + Ret.Add_Test (Operations.Subtraction.Test.Suite.Suite); + Ret.Add_Test (Operands.Ints.Test.Suite.Suite); + return Ret; + end Suite; + +end Main_Suite; diff --git a/ada/libaunit-3.7.2/examples/calculator/fixture/main_suite.ads b/ada/libaunit-3.7.2/examples/calculator/fixture/main_suite.ads new file mode 100644 index 000000000..6752380c5 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/fixture/main_suite.ads @@ -0,0 +1,10 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Suites; use AUnit.Test_Suites; + +package Main_Suite is + + function Suite return Access_Test_Suite; + +end Main_Suite; diff --git a/ada/libaunit-3.7.2/examples/calculator/fixture/operands-ints-test-suite.adb b/ada/libaunit-3.7.2/examples/calculator/fixture/operands-ints-test-suite.adb new file mode 100644 index 000000000..dfc591bed --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/fixture/operands-ints-test-suite.adb @@ -0,0 +1,22 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Caller; + +package body Operands.Ints.Test.Suite is + + package Caller is new AUnit.Test_Caller (Operands.Ints.Test.Test); + + function Suite return Access_Test_Suite is + Ret : constant Access_Test_Suite := new Test_Suite; + begin + Ret.Add_Test + (Caller.Create ("Test Operands.Ints.Image", Test_Image'Access)); + Ret.Add_Test + (Caller.Create ("Test Operands.Ints.Value", Test_Value'Access)); + Ret.Add_Test + (Caller.Create ("Test Operands.Ints.Set", Test_Set'Access)); + return Ret; + end Suite; + +end Operands.Ints.Test.Suite; diff --git a/ada/libaunit-3.7.2/examples/calculator/fixture/operands-ints-test-suite.ads b/ada/libaunit-3.7.2/examples/calculator/fixture/operands-ints-test-suite.ads new file mode 100644 index 000000000..8cf8b1584 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/fixture/operands-ints-test-suite.ads @@ -0,0 +1,10 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Suites; use AUnit.Test_Suites; + +package Operands.Ints.Test.Suite is + + function Suite return Access_Test_Suite; + +end Operands.Ints.Test.Suite; diff --git a/ada/libaunit-3.7.2/examples/calculator/fixture/operations-addition-test-suite.ads b/ada/libaunit-3.7.2/examples/calculator/fixture/operations-addition-test-suite.ads new file mode 100644 index 000000000..01dbff63d --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/fixture/operations-addition-test-suite.ads @@ -0,0 +1,7 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Operations.Binary.Gen_Test.Gen_Suite; +with Operations.Addition.Test; +package Operations.Addition.Test.Suite is new + Operations.Addition.Test.Gen_Suite ("Operations.Addition"); diff --git a/ada/libaunit-3.7.2/examples/calculator/fixture/operations-binary-gen_test-gen_suite.adb b/ada/libaunit-3.7.2/examples/calculator/fixture/operations-binary-gen_test-gen_suite.adb new file mode 100644 index 000000000..170897272 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/fixture/operations-binary-gen_test-gen_suite.adb @@ -0,0 +1,19 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Operations.Binary.Gen_Test.Gen_Suite is + + function Suite return Access_Test_Suite is + Ret : constant Access_Test_Suite := new Test_Suite; + begin + Ret.Add_Test + (Caller.Create ("Test " & Instance_Name & ".Pop", Test_Pop_Access)); + Ret.Add_Test + (Caller.Create ("Test " & Instance_Name & ".Push", Test_Push_Access)); + Ret.Add_Test + (Caller.Create + ("Test " & Instance_Name & ".Execute", Test_Execute_Access)); + return Ret; + end Suite; + +end Operations.Binary.Gen_Test.Gen_Suite; diff --git a/ada/libaunit-3.7.2/examples/calculator/fixture/operations-binary-gen_test-gen_suite.ads b/ada/libaunit-3.7.2/examples/calculator/fixture/operations-binary-gen_test-gen_suite.ads new file mode 100644 index 000000000..753b2a89a --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/fixture/operations-binary-gen_test-gen_suite.ads @@ -0,0 +1,20 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Suites; use AUnit.Test_Suites; +with AUnit.Test_Caller; + +generic + Instance_Name : String; +package Operations.Binary.Gen_Test.Gen_Suite is + + function Suite return Access_Test_Suite; + +private + + package Caller is new AUnit.Test_Caller (Operations.Binary.Gen_Test.Test); + Test_Pop_Access : constant Caller.Test_Method := Test_Pop'Access; + Test_Push_Access : constant Caller.Test_Method := Test_Push'Access; + Test_Execute_Access : constant Caller.Test_Method := Test_Execute'Access; + +end Operations.Binary.Gen_Test.Gen_Suite; diff --git a/ada/libaunit-3.7.2/examples/calculator/fixture/operations-subtraction-test-suite.ads b/ada/libaunit-3.7.2/examples/calculator/fixture/operations-subtraction-test-suite.ads new file mode 100644 index 000000000..3cc99d1b1 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/fixture/operations-subtraction-test-suite.ads @@ -0,0 +1,6 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Operations.Binary.Gen_Test.Gen_Suite; +package Operations.Subtraction.Test.Suite is new + Operations.Subtraction.Test.Gen_Suite ("Operations.Subtraction"); diff --git a/ada/libaunit-3.7.2/examples/calculator/fixture/stack-test-suite.adb b/ada/libaunit-3.7.2/examples/calculator/fixture/stack-test-suite.adb new file mode 100644 index 000000000..af33d0ecd --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/fixture/stack-test-suite.adb @@ -0,0 +1,26 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Caller; + +package body Stack.Test.Suite is + + package Caller is new AUnit.Test_Caller (Stack.Test.Test); + + function Suite return Access_Test_Suite is + Ret : constant Access_Test_Suite := new Test_Suite; + begin + Ret.Add_Test + (Caller.Create ("Test Stack.Push", Test_Push'Access)); + Ret.Add_Test + (Caller.Create ("Test Stack.Pop", Test_Pop'Access)); + Ret.Add_Test + (Caller.Create ("Test Stack.Length", Test_Length'Access)); + Ret.Add_Test + (Caller.Create ("Test Stack.Top", Test_Top'Access)); + Ret.Add_Test + (Caller.Create ("Test Stack.Next_To_Top", Test_Next_To_Top'Access)); + return Ret; + end Suite; + +end Stack.Test.Suite; diff --git a/ada/libaunit-3.7.2/examples/calculator/fixture/stack-test-suite.ads b/ada/libaunit-3.7.2/examples/calculator/fixture/stack-test-suite.ads new file mode 100644 index 000000000..5a86d9406 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/fixture/stack-test-suite.ads @@ -0,0 +1,10 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Suites; use AUnit.Test_Suites; + +package Stack.Test.Suite is + + function Suite return Access_Test_Suite; + +end Stack.Test.Suite; diff --git a/ada/libaunit-3.7.2/examples/calculator/fixture/test_calculator.adb b/ada/libaunit-3.7.2/examples/calculator/fixture/test_calculator.adb new file mode 100644 index 000000000..ec22190c6 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/fixture/test_calculator.adb @@ -0,0 +1,13 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Reporter.Text; +with AUnit.Run; +with Main_Suite; use Main_Suite; + +procedure Test_Calculator is + procedure Runner is new AUnit.Run.Test_Runner (Suite); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + Runner (Reporter); +end Test_Calculator; diff --git a/ada/libaunit-3.7.2/examples/calculator/harness.gpr b/ada/libaunit-3.7.2/examples/calculator/harness.gpr new file mode 100644 index 000000000..69f5c01f1 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/harness.gpr @@ -0,0 +1,33 @@ +with "aunit"; +with "tested_lib/testlib"; + +project Harness is + + for Languages use ("Ada"); + for Main use ("test_calculator.adb"); + for Source_Dirs use ("fixture", "tests"); + for Exec_Dir use "."; + for Object_Dir use "obj"; + + package Linker is + for Default_Switches ("ada") use ("-g"); + case TestLib.Coverage is + when "yes" => + for Default_Switches ("ada") use Linker'Default_Switches("ada") & + "-fprofile-arcs"; + when others => + end case; + end Linker; + + package Binder is + for Default_Switches ("ada") use ("-E", "-static"); + end Binder; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-gnatQ", "-O1", "-gnatf", "-gnato", + "-gnatwa.Xe", "-gnaty", "-gnat05"); + end Compiler; + +end Harness; + diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operands-ints.adb b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operands-ints.adb new file mode 100644 index 000000000..d76779178 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operands-ints.adb @@ -0,0 +1,21 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Operands.Ints is + + function Image (Opnd : Int) return String is + begin + return Integer'Image (Opnd.Value); + end Image; + + function Value (Opnd : Int) return Integer is + begin + return Opnd.Value; + end Value; + + procedure Set (Opnd : in out Int; Value : Integer) is + begin + Opnd.Value := Value; + end Set; + +end Operands.Ints; diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operands-ints.ads b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operands-ints.ads new file mode 100644 index 000000000..33aa04a5a --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operands-ints.ads @@ -0,0 +1,20 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package Operands.Ints is + + type Int is new Operand with private; + + function Image (Opnd : Int) return String; + + function Value (Opnd : Int) return Integer; + + procedure Set (Opnd : in out Int; Value : Integer); + +private + + type Int is new Operand with record + Value : Integer; + end record; + +end Operands.Ints; diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operands.ads b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operands.ads new file mode 100644 index 000000000..92e5df61e --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operands.ads @@ -0,0 +1,11 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package Operands is + + type Operand is abstract tagged null record; + type Operand_Access is access all Operand'Class; + + function Image (Opnd : Operand) return String is abstract; + +end Operands; diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-addition.ads b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-addition.ads new file mode 100644 index 000000000..ee6ada17e --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-addition.ads @@ -0,0 +1,11 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Operands.Ints; +with Operations.Binary; +with Operations.Ints; + +package Operations.Addition is new Operations.Binary + (T => Operands.Ints.Int, + T_Ret => Operands.Ints.Int, + The_Operation => Operations.Ints."+"); diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-binary.adb b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-binary.adb new file mode 100644 index 000000000..7f10cf671 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-binary.adb @@ -0,0 +1,34 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Operations.Binary is + + --------- + -- Pop -- + --------- + + procedure Pop (Op : in out Binary_Operation) is + begin + Op.Op2 := T (Stack.Pop); + Op.Op1 := T (Stack.Pop); + end Pop; + + ---------- + -- Push -- + ---------- + + procedure Push (Op : in out Binary_Operation) is + begin + Stack.Push (Op.Res); + end Push; + + ------------- + -- Execute -- + ------------- + + procedure Execute (Op : in out Binary_Operation) is + begin + Op.Res := The_Operation (Op.Op1, Op.Op2); + end Execute; + +end Operations.Binary; diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-binary.ads b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-binary.ads new file mode 100644 index 000000000..4daae64f9 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-binary.ads @@ -0,0 +1,46 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Operands; use Operands; +with Stack; + +generic + type T is new Operands.Operand with private; + type T_Ret is new Operands.Operand with private; + with function The_Operation (T1, T2 : T) return T_Ret; +package Operations.Binary is + + type Binary_Operation is new Operation with private; + + procedure Pop (Op : in out Binary_Operation); + pragma Precondition + (Stack.Length >= 2 + and then Stack.Top in T'Class + and then Stack.Next_To_Top in T'Class, + "precondition for Operations.Binary.Pop"); + pragma Postcondition + (Stack.Length = Stack.Length'Old - 2, + "postcondition for Operations.Binary.Pop"); + -- Pops the operands from the stack + + procedure Push (Op : in out Binary_Operation); + pragma Precondition + (Stack.Length < Stack.Max_Stack_Size, + "precondition for Operations.Binary.Push"); + pragma Postcondition + (Stack.Length = Stack.Length'Old + 1, + "postcondition for Operations.Binary.Push"); + -- Pushes the operands in the stack + + procedure Execute (Op : in out Binary_Operation); + -- Execute the operation + +private + + type Binary_Operation is new Operation with record + Op1 : T; + Op2 : T; + Res : T_Ret; + end record; + +end Operations.Binary; diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-ints.adb b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-ints.adb new file mode 100644 index 000000000..8d82bc9df --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-ints.adb @@ -0,0 +1,20 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Operations.Ints is + + function "+" (Op1, Op2 : Int) return Int is + Ret : Int; + begin + Ret.Set (Op1.Value + Op2.Value); + return Ret; + end "+"; + + function "-" (Op1, Op2 : Int) return Int is + Ret : Int; + begin + Ret.Set (Op1.Value - Op2.Value); + return Ret; + end "-"; + +end Operations.Ints; diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-ints.ads b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-ints.ads new file mode 100644 index 000000000..19e009472 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-ints.ads @@ -0,0 +1,12 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Operands.Ints; use Operands.Ints; + +package Operations.Ints is + + function "+" (Op1, Op2 : Int) return Int; + + function "-" (Op1, Op2 : Int) return Int; + +end Operations.Ints; diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-subtraction.ads b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-subtraction.ads new file mode 100644 index 000000000..8d11e272a --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations-subtraction.ads @@ -0,0 +1,11 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Operands.Ints; +with Operations.Binary; +with Operations.Ints; + +package Operations.Subtraction is new Operations.Binary + (T => Operands.Ints.Int, + T_Ret => Operands.Ints.Int, + The_Operation => Operations.Ints."-"); diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations.ads b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations.ads new file mode 100644 index 000000000..a29ebdcfb --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/operations.ads @@ -0,0 +1,17 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package Operations is + + type Operation is abstract tagged null record; + + procedure Pop (Op : in out Operation) is abstract; + -- Pops the operands from the stack + + procedure Push (Op : in out Operation) is abstract; + -- Pushes the operands in the stack + + procedure Execute (Op : in out Operation) is abstract; + -- Execute the operation + +end Operations; diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/stack.adb b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/stack.adb new file mode 100644 index 000000000..b0412999b --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/stack.adb @@ -0,0 +1,75 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Stack is + + ---------- + -- Push -- + ---------- + + procedure Push (Op : Operands.Operand'Class) is + begin + if The_Stack_Index = Stack_Index'Last then + raise Stack_Overflow; + end if; + + The_Stack_Index := The_Stack_Index + 1; + The_Stack (The_Stack_Index) := new Operands.Operand'Class'(Op); + end Push; + + --------- + -- Pop -- + --------- + + function Pop return Operands.Operand'Class is + begin + if The_Stack_Index = Empty_Stack then + raise Stack_Empty; + end if; + + declare + Op : constant Operands.Operand'Class := + The_Stack (The_Stack_Index).all; + begin + Free (The_Stack (The_Stack_Index)); + The_Stack_Index := The_Stack_Index - 1; + return Op; + end; + end Pop; + + ------------ + -- Length -- + ------------ + + function Length return Natural is + begin + return Natural (The_Stack_Index); + end Length; + + -------------- + -- Top_Type -- + -------------- + + function Top return Operands.Operand'Class is + begin + if The_Stack_Index = 0 then + raise Stack_Empty; + end if; + + return The_Stack (The_Stack_Index).all; + end Top; + + ---------------------- + -- Next_To_Top_Type -- + ---------------------- + + function Next_To_Top return Operands.Operand'Class is + begin + if The_Stack_Index < 2 then + raise Stack_Empty; + end if; + + return The_Stack (The_Stack_Index - 1).all; + end Next_To_Top; + +end Stack; diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/stack.ads b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/stack.ads new file mode 100644 index 000000000..f6f3f43d2 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/src/stack.ads @@ -0,0 +1,45 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Ada.Unchecked_Deallocation; +with Operands; use Operands; + +package Stack is + + Stack_Overflow : exception; + Stack_Empty : exception; + + Max_Stack_Size : constant Natural := 128; + + procedure Push (Op : Operands.Operand'Class); + -- Push an operand on the stack + -- Raises Stack_Overflow if the stack is full + + function Pop return Operands.Operand'Class; + -- Pop an operand from the stack + -- Raises Stack_Empty if the stack is empty + + function Length return Natural; + -- Return the number of objects in the stack + + function Top return Operands.Operand'Class; + -- Return the operand on the top of the stack without removing it from the + -- stack. + + function Next_To_Top return Operands.Operand'Class; + -- Return he operand on the next to top of the stack without removing it + -- from the stack + +private + + type Stack_Index is new Natural range 0 .. Max_Stack_Size; + Empty_Stack : constant Stack_Index := 0; + + The_Stack : array (Stack_Index range 1 .. Stack_Index'Last) + of Operand_Access; + The_Stack_Index : Stack_Index := Empty_Stack; + + procedure Free is new Ada.Unchecked_Deallocation + (Operands.Operand'Class, Operand_Access); + +end Stack; diff --git a/ada/libaunit-3.7.2/examples/calculator/tested_lib/testlib.gpr b/ada/libaunit-3.7.2/examples/calculator/tested_lib/testlib.gpr new file mode 100644 index 000000000..744fc22d0 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tested_lib/testlib.gpr @@ -0,0 +1,26 @@ +project TestLib is + + type Yes_No is ("yes", "no"); + Coverage : Yes_No := External ("COVERAGE", "no"); + + for Source_Dirs use ("src"); + + for Languages use ("Ada"); + for Object_Dir use "obj"; + for Library_Dir use "lib"; + for Library_Name use "testlib"; + for Library_Kind use "static"; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-O0", "-gnat05", "-gnatwae", "-gnaty", "-gnata"); + case Coverage is + when "yes" => + for Default_Switches ("ada") use Compiler'Default_Switches ("ada") & + ("-fprofile-arcs", "-ftest-coverage"); + when others => + end case; + end Compiler; + +end TestLib; + diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/operands-ints-test.adb b/ada/libaunit-3.7.2/examples/calculator/tests/operands-ints-test.adb new file mode 100644 index 000000000..04bcf9c4a --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/operands-ints-test.adb @@ -0,0 +1,32 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Assertions; use AUnit.Assertions; + +package body Operands.Ints.Test is + + procedure Test_Image (T : in out Test) is + pragma Unreferenced (T); + I : Int; + begin + I.Value := 0; + Assert (I.Image = " 0", "Wrong image for 0"); + I.Value := 9657; + Assert (I.Image = " 9657", "Wrong image for 9657"); + I.Value := -45879876; + Assert (I.Image = "-45879876", "Wrong image for -45879876"); + end Test_Image; + + procedure Test_Value (T : in out Test) is + pragma Unreferenced (T); + begin + Assert (False, "test not implemented"); + end Test_Value; + + procedure Test_Set (T : in out Test) is + pragma Unreferenced (T); + begin + Assert (False, "test not implemented"); + end Test_Set; + +end Operands.Ints.Test; diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/operands-ints-test.ads b/ada/libaunit-3.7.2/examples/calculator/tests/operands-ints-test.ads new file mode 100644 index 000000000..bf0d209b8 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/operands-ints-test.ads @@ -0,0 +1,16 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Fixtures; + +package Operands.Ints.Test is + + type Test is new AUnit.Test_Fixtures.Test_Fixture with null record; + + procedure Test_Image (T : in out Test); + + procedure Test_Value (T : in out Test); + + procedure Test_Set (T : in out Test); + +end Operands.Ints.Test; diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/operations-addition-test.ads b/ada/libaunit-3.7.2/examples/calculator/tests/operations-addition-test.ads new file mode 100644 index 000000000..c4adb59d3 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/operations-addition-test.ads @@ -0,0 +1,8 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Operations.Binary.Gen_Test; +with Operations.Addition; +with Operations.Addition_Test_Fixture; use Operations.Addition_Test_Fixture; +package Operations.Addition.Test is new Operations.Addition.Gen_Test + (Set_Up); diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/operations-addition_test_fixture.adb b/ada/libaunit-3.7.2/examples/calculator/tests/operations-addition_test_fixture.adb new file mode 100644 index 000000000..20a7d6fd5 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/operations-addition_test_fixture.adb @@ -0,0 +1,19 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Operations.Addition_Test_Fixture is + + procedure Set_Up + (Op : out Operations.Addition.Binary_Operation; + Test_Op1 : out Int; + Test_Op2 : out Int; + Exp_Res : out Int) + is + pragma Unreferenced (Op); + begin + Test_Op1.Set (4); + Test_Op2.Set (6); + Exp_Res.Set (10); + end Set_Up; + +end Operations.Addition_Test_Fixture; diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/operations-addition_test_fixture.ads b/ada/libaunit-3.7.2/examples/calculator/tests/operations-addition_test_fixture.ads new file mode 100644 index 000000000..8a22855e4 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/operations-addition_test_fixture.ads @@ -0,0 +1,15 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Operands.Ints; use Operands.Ints; +with Operations.Addition; + +package Operations.Addition_Test_Fixture is + + procedure Set_Up + (Op : out Operations.Addition.Binary_Operation; + Test_Op1 : out Int; + Test_Op2 : out Int; + Exp_Res : out Int); + +end Operations.Addition_Test_Fixture; diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/operations-binary-gen_test.adb b/ada/libaunit-3.7.2/examples/calculator/tests/operations-binary-gen_test.adb new file mode 100644 index 000000000..2d166a23e --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/operations-binary-gen_test.adb @@ -0,0 +1,102 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Ada.Exceptions; +with System.Assertions; +with AUnit.Assertions; use AUnit.Assertions; +with Stack; use Stack; +package body Operations.Binary.Gen_Test is + + ------------ + -- Set_Up -- + ------------ + + procedure Set_Up (T : in out Test) is + begin + Set_Up (T.Op, T.Test_Op1, T.Test_Op2, T.Exp_Res); + end Set_Up; + + --------------- + -- Tear_Down -- + --------------- + + procedure Tear_Down (T : in out Test) is + pragma Unreferenced (T); + begin + -- Make sure the stack is empty after each test. + while Stack.Length > 0 loop + declare + Op : constant Operands.Operand'Class := Stack.Pop; + pragma Unreferenced (Op); + begin + null; + end; + end loop; + end Tear_Down; + + -------------- + -- Test_Pop -- + -------------- + + procedure Test_Pop (T : in out Test) is + begin + begin + Pop (T.Op); + Assert (False, "stack is empty, it should have raised an exception"); + exception + when System.Assertions.Assert_Failure => + -- Precondition failed. OK + null; + when E : others => + Assert (False, "Wrong exception raised: " & + Ada.Exceptions.Exception_Name (E)); + end; + + Stack.Push (T.Test_Op1); + Stack.Push (T.Test_Op2); + Pop (T.Op); + Assert (Stack.Length = 0, "Wrong pop operation"); + Assert (T.Op.Op1 = T.Test_Op1, "Wrong first value poped"); + Assert (T.Op.Op2 = T.Test_Op2, "Wrong 2nd value poped"); + end Test_Pop; + + --------------- + -- Test_Push -- + --------------- + + procedure Test_Push (T : in out Test) is + begin + T.Op.Res := T.Exp_Res; + T.Op.Push; + Assert (Stack.Length = 1, "Wrong push on stack"); + Assert (Stack.Top = Operands.Operand'Class (T.Exp_Res), + "Wrong value pushed"); + for J in 2 .. Stack.Max_Stack_Size loop + Stack.Push (T.Test_Op1); + end loop; + + begin + T.Op.Push; + Assert (False, "stack is full, it should have raised an exception"); + exception + when System.Assertions.Assert_Failure => + null; -- Expected + when E : others => + Assert (False, "Wrong exception raised: " & + Ada.Exceptions.Exception_Name (E)); + end; + end Test_Push; + + ------------------ + -- Test_Execute -- + ------------------ + + procedure Test_Execute (T : in out Test) is + begin + T.Op.Op1 := T.Test_Op1; + T.Op.Op2 := T.Test_Op2; + T.Op.Execute; + Assert (T.Op.Res = T.Exp_Res, "Incorrect result set after Execute"); + end Test_Execute; + +end Operations.Binary.Gen_Test; diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/operations-binary-gen_test.ads b/ada/libaunit-3.7.2/examples/calculator/tests/operations-binary-gen_test.ads new file mode 100644 index 000000000..a89a09939 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/operations-binary-gen_test.ads @@ -0,0 +1,34 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Fixtures; + +generic + + with procedure Set_Up + (The_Op : out Binary_Operation; + Test_Op1 : out T; + Test_Op2 : out T; + Exp_Res : out T_Ret); + +package Operations.Binary.Gen_Test is + + type Test is new AUnit.Test_Fixtures.Test_Fixture with private; + + procedure Set_Up (T : in out Test); + procedure Tear_Down (T : in out Test); + + procedure Test_Pop (T : in out Test); + procedure Test_Push (T : in out Test); + procedure Test_Execute (T : in out Test); + +private + + type Test is new AUnit.Test_Fixtures.Test_Fixture with record + Op : Operations.Binary.Binary_Operation; + Test_Op1 : T; + Test_Op2 : T; + Exp_Res : T_Ret; + end record; + +end Operations.Binary.Gen_Test; diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/operations-subtraction-test.ads b/ada/libaunit-3.7.2/examples/calculator/tests/operations-subtraction-test.ads new file mode 100644 index 000000000..434863fbc --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/operations-subtraction-test.ads @@ -0,0 +1,9 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Operations.Binary.Gen_Test; +with Operations.Subtraction; +with Operations.Subtraction_Test_Fixture; +use Operations.Subtraction_Test_Fixture; +package Operations.Subtraction.Test is new Operations.Subtraction.Gen_Test + (Set_Up); diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/operations-subtraction_test_fixture.adb b/ada/libaunit-3.7.2/examples/calculator/tests/operations-subtraction_test_fixture.adb new file mode 100644 index 000000000..f7a7524b4 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/operations-subtraction_test_fixture.adb @@ -0,0 +1,19 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Operations.Subtraction_Test_Fixture is + + procedure Set_Up + (Op : out Operations.Subtraction.Binary_Operation; + Test_Op1 : out Int; + Test_Op2 : out Int; + Exp_Res : out Int) + is + pragma Unreferenced (Op); + begin + Test_Op1.Set (4); + Test_Op2.Set (6); + Exp_Res.Set (-2); + end Set_Up; + +end Operations.Subtraction_Test_Fixture; diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/operations-subtraction_test_fixture.ads b/ada/libaunit-3.7.2/examples/calculator/tests/operations-subtraction_test_fixture.ads new file mode 100644 index 000000000..4e61d0577 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/operations-subtraction_test_fixture.ads @@ -0,0 +1,14 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Operands.Ints; use Operands.Ints; +with Operations.Subtraction; +package Operations.Subtraction_Test_Fixture is + + procedure Set_Up + (Op : out Operations.Subtraction.Binary_Operation; + Test_Op1 : out Int; + Test_Op2 : out Int; + Exp_Res : out Int); + +end Operations.Subtraction_Test_Fixture; diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/stack-test.adb b/ada/libaunit-3.7.2/examples/calculator/tests/stack-test.adb new file mode 100644 index 000000000..6cf90c7d8 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/stack-test.adb @@ -0,0 +1,214 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Assertions; use AUnit.Assertions; +with Ada.Exceptions; +with Operands.Ints; use Operands.Ints; + +package body Stack.Test is + + --------------- + -- Tear_Down -- + --------------- + + procedure Tear_Down (T : in out Test) is + pragma Unreferenced (T); + begin + -- Make sure the stack is empty after each test. + while Stack.The_Stack_Index > 0 loop + Free (Stack.The_Stack (Stack.The_Stack_Index)); + The_Stack_Index := The_Stack_Index - 1; + end loop; + end Tear_Down; + + --------------- + -- Test_Push -- + --------------- + + procedure Test_Push (T : in out Test) is + pragma Unreferenced (T); + I1, I2 : Int; + begin + I1.Set (3); + I2.Set (-4); + + -- Test single push + Stack.Push (I1); + Assert (Stack.The_Stack_Index = 1, "Wrong stack index after push"); + Assert (Stack.The_Stack (1).all = Operand'Class (I1), + "Wrong value pushed on the stack"); + + -- Test second push + Stack.Push (I2); + Assert (Stack.The_Stack_Index = 2, "Wrong stack index after 2nd push"); + Assert (Stack.The_Stack (1).all = Operand'Class (I1) + and then Stack.The_Stack (2).all = Operand'Class (I2), + "Wrong value order after two pushes on the stack"); + + -- Test overflow + begin + for J in The_Stack_Index .. The_Stack'Last loop + Stack.Push (I2); + end loop; + + Assert (False, "Stack_Overflow should have been raised"); + exception + when Stack.Stack_Overflow => + null; + when E : others => + Assert (False, "Wrong exception raised : " & + Ada.Exceptions.Exception_Name (E)); + end; + end Test_Push; + + -------------- + -- Test_Pop -- + -------------- + + procedure Test_Pop (T : in out Test) is + pragma Unreferenced (T); + I1, I2 : Int; + I3 : Int; + pragma Unreferenced (I3); + begin + I1.Set (3); + I2.Set (-4); + + The_Stack (1) := new Operand'Class'(Operand'Class (I1)); + The_Stack (2) := new Operand'Class'(Operand'Class (I2)); + The_Stack_Index := 2; + + Assert (Stack.Pop = Operand'Class (I2), + "Wrong value poped with 2 values on the stack"); + Assert (The_Stack_Index = 1, + "Wrong stack index after pop"); + Assert (Stack.Pop = Operand'Class (I1), + "Wrong value poped with 1 value on the stack"); + Assert (The_Stack_Index = 0, + "Wrong stack index after 2nd pop"); + begin + I3 := Int (Stack.Pop); + Assert (False, "Stack_Empty should have been raised"); + + exception + when Stack.Stack_Empty => + -- Expected exception + null; + when E : others => + Assert (False, "Wrong exception raised : " & + Ada.Exceptions.Exception_Name (E)); + end; + end Test_Pop; + + ----------------- + -- Test_Length -- + ----------------- + + procedure Test_Length (T : in out Test) is + pragma Unreferenced (T); + I1, I2 : Int; + I3 : Int; + pragma Unreferenced (I3); + begin + I1.Set (3); + I2.Set (-4); + + Stack.Push (I1); + Assert (Stack.Length = 1, "Wrong length after 1 push"); + Stack.Push (I2); + Assert (Stack.Length = 2, "Wrong length after 2 push"); + I3 := Int (Stack.Pop); + Assert (Stack.Length = 1, "Wrong length after 2 pushes and 1 pop"); + + begin + for J in 1 .. Stack.The_Stack'Last loop + Stack.Push (I2); + end loop; + exception + when Stack_Overflow => + Assert (Stack.Length = Natural (Stack.The_Stack'Last), + "Stack.Length incorrect after Stack_Overflow exception"); + end; + + begin + for J in 0 .. Stack.The_Stack'Last loop + I3 := Int (Stack.Pop); + end loop; + exception + when Stack_Empty => + Assert (Stack.Length = 0, + "Stack.Length incorrect after Stack_Empty exception"); + end; + end Test_Length; + + -------------- + -- Test_Top -- + -------------- + + procedure Test_Top (T : in out Test) is + pragma Unreferenced (T); + I1, I2 : Int; + I3 : Int; + pragma Unreferenced (I3); + begin + I1.Set (3); + I2.Set (-4); + + Stack.Push (I1); + Assert (Stack.Top = Operand'Class (I1), + "Wrong value returned by Top after 1 push"); + Assert (Stack.Length = 1, "Top modified the length"); + Stack.Push (I2); + Assert (Stack.Top = Operand'Class (I2), + "Wrong value returned by Top after 2 pushes"); + Assert (Stack.Length = 2, "Top modified the length"); + I3 := Int (Stack.Pop); + I3 := Int (Stack.Pop); + begin + I3 := Int (Stack.Top); + Assert + (False, + "Top should have raised Emtpy_Stack when the stack is empty"); + exception + when Stack.Stack_Empty => + null; + when E : others => + Assert (False, "Wrong exception raised : " & + Ada.Exceptions.Exception_Name (E)); + end; + end Test_Top; + + ---------------------- + -- Test_Next_To_Top -- + ---------------------- + + procedure Test_Next_To_Top (T : in out Test) is + pragma Unreferenced (T); + I1, I2 : Int; + I3 : Int; + pragma Unreferenced (I3); + begin + I1.Set (3); + I2.Set (-4); + + Stack.Push (I1); + Stack.Push (I2); + Assert (Stack.Next_To_Top = Operand'Class (I1), + "Wrong value returned by Next_To_Top after 2 pushes"); + Assert (Stack.Length = 2, "Next_To_Top modified the length"); + I3 := Int (Stack.Pop); + begin + I3 := Int (Stack.Next_To_Top); + Assert + (False, + "Top should have raised Emtpy_Stack when the stack's length is 1"); + exception + when Stack.Stack_Empty => + null; + when E : others => + Assert (False, "Wrong exception raised : " & + Ada.Exceptions.Exception_Name (E)); + end; + end Test_Next_To_Top; + +end Stack.Test; diff --git a/ada/libaunit-3.7.2/examples/calculator/tests/stack-test.ads b/ada/libaunit-3.7.2/examples/calculator/tests/stack-test.ads new file mode 100644 index 000000000..e3f2ae08e --- /dev/null +++ b/ada/libaunit-3.7.2/examples/calculator/tests/stack-test.ads @@ -0,0 +1,27 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Fixtures; + +package Stack.Test is + + type Test is new AUnit.Test_Fixtures.Test_Fixture with null record; + + procedure Tear_Down (T : in out Test); + + procedure Test_Push (T : in out Test); + -- Test for Stack.Push + + procedure Test_Pop (T : in out Test); + -- Test for Stack.Pop + + procedure Test_Length (T : in out Test); + -- Test for Stack.Length + + procedure Test_Top (T : in out Test); + -- Test for Stack.Top + + procedure Test_Next_To_Top (T : in out Test); + -- Test for Stack.Next_To_Top + +end Stack.Test; diff --git a/ada/libaunit-3.7.2/examples/failures/harness.gpr b/ada/libaunit-3.7.2/examples/failures/harness.gpr new file mode 100644 index 000000000..1aabc563c --- /dev/null +++ b/ada/libaunit-3.7.2/examples/failures/harness.gpr @@ -0,0 +1,27 @@ +with "aunit"; +with "tested_lib/testlib"; + +project Harness is + + for Languages use ("Ada"); + for Main use ("test_math.adb"); + for Source_Dirs use ("tests"); + for Exec_Dir use "."; + for Object_Dir use "obj"; + + package Linker is + for Default_Switches ("ada") use ("-g"); + end Linker; + + package Binder is + for Default_Switches ("ada") use ("-E", "-static"); + end Binder; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-gnatQ", "-O1", "-gnatf", "-gnato", + "-gnatwa.Xe", "-gnaty", "-gnat05"); + end Compiler; + +end Harness; + diff --git a/ada/libaunit-3.7.2/examples/failures/tested_lib/src/math.adb b/ada/libaunit-3.7.2/examples/failures/tested_lib/src/math.adb new file mode 100644 index 000000000..a37afe920 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/failures/tested_lib/src/math.adb @@ -0,0 +1,16 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Math is + + function "+" (I1, I2 : Int) return Int is + begin + return Int (Integer (I1) + Integer (I2)); + end "+"; + + function "-" (I1, I2 : Int) return Int is + begin + return Int (Integer (I1) - Integer (I2)); + end "-"; + +end Math; diff --git a/ada/libaunit-3.7.2/examples/failures/tested_lib/src/math.ads b/ada/libaunit-3.7.2/examples/failures/tested_lib/src/math.ads new file mode 100644 index 000000000..b3bf1c3b7 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/failures/tested_lib/src/math.ads @@ -0,0 +1,12 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package Math is + + type Int is new Integer; + + function "+" (I1, I2 : Int) return Int; + + function "-" (I1, I2 : Int) return Int; + +end Math; diff --git a/ada/libaunit-3.7.2/examples/failures/tested_lib/testlib.gpr b/ada/libaunit-3.7.2/examples/failures/tested_lib/testlib.gpr new file mode 100644 index 000000000..5c49bf0bd --- /dev/null +++ b/ada/libaunit-3.7.2/examples/failures/tested_lib/testlib.gpr @@ -0,0 +1,17 @@ +project TestLib is + + for Source_Dirs use ("src"); + + for Languages use ("Ada"); + for Object_Dir use "obj"; + for Library_Dir use "lib"; + for Library_Name use "testlib"; + for Library_Kind use "static"; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-O1", "-gnat05", "-gnatwa.Xe", "-gnaty", "-gnato", "-gnatf"); + end Compiler; + +end TestLib; + diff --git a/ada/libaunit-3.7.2/examples/failures/tests/math-test.adb b/ada/libaunit-3.7.2/examples/failures/tests/math-test.adb new file mode 100644 index 000000000..15dfafd69 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/failures/tests/math-test.adb @@ -0,0 +1,40 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Assertions; use AUnit.Assertions; + +package body Math.Test is + + procedure Test_Addition (T : in out Test) is + pragma Unreferenced (T); + I1 : constant Int := 5; + I2 : constant Int := 3; + begin + Assert (I1 + I2 = 8, "Incorrect result after addition"); + end Test_Addition; + + procedure Test_Subtraction (T : in out Test) is + pragma Unreferenced (T); + I1 : constant Int := 5; + I2 : constant Int := 3; + begin + Assert (I1 - I2 = 2, "Incorrect result after subtraction"); + end Test_Subtraction; + + procedure Test_Addition_Failure (T : in out Test) is + pragma Unreferenced (T); + I1 : constant Int := 5; + I2 : constant Int := 3; + begin + Assert (I1 + I2 = 9, "Test should fail this assertion, as 5+3 /= 9"); + end Test_Addition_Failure; + + procedure Test_Addition_Error (T : in out Test) is + pragma Unreferenced (T); + I1 : constant Int := Int'Last; + I2 : constant Int := Int'Last; + begin + Assert (I1 + I2 = I1, "This raises a constraint error"); + end Test_Addition_Error; + +end Math.Test; diff --git a/ada/libaunit-3.7.2/examples/failures/tests/math-test.ads b/ada/libaunit-3.7.2/examples/failures/tests/math-test.ads new file mode 100644 index 000000000..af39c41bb --- /dev/null +++ b/ada/libaunit-3.7.2/examples/failures/tests/math-test.ads @@ -0,0 +1,20 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit; +with AUnit.Test_Fixtures; + +package Math.Test is + + type Test is new AUnit.Test_Fixtures.Test_Fixture with null record; + + procedure Test_Addition (T : in out Test); + procedure Test_Subtraction (T : in out Test); + + procedure Test_Addition_Failure (T : in out Test); + -- This test will do a failed assertion + + procedure Test_Addition_Error (T : in out Test); + -- This test will raise an exception + +end Math.Test; diff --git a/ada/libaunit-3.7.2/examples/failures/tests/math_suite.adb b/ada/libaunit-3.7.2/examples/failures/tests/math_suite.adb new file mode 100644 index 000000000..e55f3e14e --- /dev/null +++ b/ada/libaunit-3.7.2/examples/failures/tests/math_suite.adb @@ -0,0 +1,29 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Math.Test; use Math.Test; +with AUnit.Test_Caller; + +package body Math_Suite is + + package Caller is new AUnit.Test_Caller (Math.Test.Test); + + function Suite return Access_Test_Suite is + Ret : constant Access_Test_Suite := new Test_Suite; + begin + Ret.Add_Test + (Caller.Create ("Test addition", Test_Addition'Access)); + Ret.Add_Test + (Caller.Create ("Test subtraction", Test_Subtraction'Access)); + Ret.Add_Test + (Caller.Create + ("Test addition (failure expected)", + Test_Addition_Failure'Access)); + Ret.Add_Test + (Caller.Create + ("Test addition (error expected)", + Test_Addition_Error'Access)); + return Ret; + end Suite; + +end Math_Suite; diff --git a/ada/libaunit-3.7.2/examples/failures/tests/math_suite.ads b/ada/libaunit-3.7.2/examples/failures/tests/math_suite.ads new file mode 100644 index 000000000..871544697 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/failures/tests/math_suite.ads @@ -0,0 +1,10 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Suites; use AUnit.Test_Suites; + +package Math_Suite is + + function Suite return Access_Test_Suite; + +end Math_Suite; diff --git a/ada/libaunit-3.7.2/examples/failures/tests/test_math.adb b/ada/libaunit-3.7.2/examples/failures/tests/test_math.adb new file mode 100644 index 000000000..5745278f2 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/failures/tests/test_math.adb @@ -0,0 +1,13 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Reporter.Text; +with AUnit.Run; +with Math_Suite; use Math_Suite; + +procedure Test_Math is + procedure Runner is new AUnit.Run.Test_Runner (Suite); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + Runner (Reporter); +end Test_Math; diff --git a/ada/libaunit-3.7.2/examples/liskov/harness.gpr b/ada/libaunit-3.7.2/examples/liskov/harness.gpr new file mode 100644 index 000000000..28a67393d --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/harness.gpr @@ -0,0 +1,27 @@ +with "aunit"; +with "tested_lib/testlib"; + +project Harness is + + for Languages use ("Ada"); + for Main use ("test_liskov.adb"); + for Source_Dirs use ("tests"); + for Exec_Dir use "."; + for Object_Dir use "obj"; + + package Linker is + for Default_Switches ("ada") use ("-g"); + end Linker; + + package Binder is + for Default_Switches ("ada") use ("-E", "-static"); + end Binder; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-gnatQ", "-O1", "-gnatf", "-gnato", + "-gnatwa.Xe", "-gnaty", "-gnat05"); + end Compiler; + +end Harness; + diff --git a/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/rectangle.adb b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/rectangle.adb new file mode 100644 index 000000000..06949476d --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/rectangle.adb @@ -0,0 +1,11 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Rectangle is + + function Area (Obj : Rectangle_Type) return Natural is + begin + return Obj.Width * Obj.Height; + end Area; + +end Rectangle; diff --git a/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/rectangle.ads b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/rectangle.ads new file mode 100644 index 000000000..82b354892 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/rectangle.ads @@ -0,0 +1,18 @@ +-- +-- Copyright (C) 2008, AdaCore +-- + +with Shape; + +package Rectangle is + + type Rectangle_Type is new Shape.Shape_Type with private; + + function Area (Obj : Rectangle_Type) return Natural; +-- pragma Postcondition (Area'Result = Width (Obj) * Height (Obj)); + +private + + type Rectangle_Type is new Shape.Shape_Type with null record; + +end Rectangle; diff --git a/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/shape.adb b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/shape.adb new file mode 100644 index 000000000..16342ee2e --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/shape.adb @@ -0,0 +1,26 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Shape is + + procedure Set_Width (Obj : in out Shape_Type; W : Natural) is + begin + Obj.Width := W; + end Set_Width; + + procedure Set_Height (Obj : in out Shape_Type; H : Natural) is + begin + Obj.Height := H; + end Set_Height; + + function Width (Obj : in Shape_Type) return Natural is + begin + return Obj.Width; + end Width; + + function Height (Obj : in Shape_Type) return Natural is + begin + return Obj.Height; + end Height; + +end Shape; diff --git a/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/shape.ads b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/shape.ads new file mode 100644 index 000000000..99ac5f207 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/shape.ads @@ -0,0 +1,43 @@ +-- +-- Copyright (C) 2008, AdaCore +-- + +package Shape is + + type Shape_Type is abstract tagged private; + type Shape_Access is access all Shape_Type'Class; + + -- Additional functional API for expressing pre/postconditions + -- & invariants: + -- function New_Shape (W, H : Natural) return Shape; + -- function Set_Width (S : Shape; W : Natural) return Shape; + -- function Set_Height (S : Shape; H : Natural) return Shape; + -- + -- Class invariants: + -- for_all W, H in Natural: + -- Set_Width (New_Shape (W, H), X) = New_Shape (X, H)) + -- Set_Height (New_Shape (W, H), X) = New_Shape (W, X)) + + function Width (Obj : Shape_Type) return Natural; + function Height (Obj : Shape_Type) return Natural; + + procedure Set_Width (Obj : in out Shape_Type; W : Natural); +-- pragma Postcondition +-- (Width (Obj) = W -- expected result +-- and Height (Obj) = Height (Obj'Old) -- independence +-- ); + + procedure Set_Height (Obj : in out Shape_Type; H : Natural); +-- pragma Postcondition +-- (Height (Obj) = H -- expected result +-- and Width (Obj) = Width (Obj'Old) -- independence +-- ); + + function Area (Obj : Shape_Type) return Natural is abstract; + +private + type Shape_Type is abstract tagged record + Width : Natural; + Height : Natural; + end record; +end Shape; diff --git a/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/square.adb b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/square.adb new file mode 100644 index 000000000..b6b0da9f1 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/square.adb @@ -0,0 +1,16 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Rectangle; use Rectangle; +package body Square is + + procedure Set_Width (Obj : in out Square_Type; W : Natural) is + begin + Rectangle_Type (Obj).Set_Width (W); + Rectangle_Type (Obj).Set_Height (W); + end Set_Width; + + procedure Set_Height (Obj : in out Square_Type; H : Natural) + renames Set_Width; + +end Square; diff --git a/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/square.ads b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/square.ads new file mode 100644 index 000000000..018dad31b --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tested_lib/src/square.ads @@ -0,0 +1,27 @@ +-- +-- Copyright (C) 2008, AdaCore +-- + +with Rectangle; + +package Square is + + type Square_Type is new Rectangle.Rectangle_Type with private; + -- class invariant + -- for all Obj : Eight (Obj) = Width (Obj) + + procedure Set_Width (Obj : in out Square_Type; W : Natural); +-- pragma Postcondition +-- (Height (Obj) = Width (Obj) -- this is the class invariant +-- ); + + procedure Set_Height (Obj : in out Square_Type; H : Natural); +-- pragma Postcondition +-- (Height (Obj) = Width (Obj) -- this is the class invariant +-- ); + +private + + type Square_Type is new Rectangle.Rectangle_Type with null record; + +end Square; diff --git a/ada/libaunit-3.7.2/examples/liskov/tested_lib/testlib.gpr b/ada/libaunit-3.7.2/examples/liskov/tested_lib/testlib.gpr new file mode 100644 index 000000000..12042e15e --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tested_lib/testlib.gpr @@ -0,0 +1,17 @@ +project TestLib is + + for Source_Dirs use ("src"); + + for Languages use ("Ada"); + for Object_Dir use "obj"; + for Library_Dir use "lib"; + for Library_Name use "testlib"; + for Library_Kind use "static"; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-O1", "-gnat05", "-gnatwa.Xe", "-gnaty", "-gnata", "-gnatf"); + end Compiler; + +end TestLib; + diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/my_suite.adb b/ada/libaunit-3.7.2/examples/liskov/tests/my_suite.adb new file mode 100644 index 000000000..fc0b5b3dd --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/my_suite.adb @@ -0,0 +1,22 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +-- with AUnit.Test_Caller; + +with Rectangle.Tests.Suite; +with Square.Tests.Suite; +with Square.Tests.Suite_Liskov; + +package body My_Suite is + + Result : aliased AUnit.Test_Suites.Test_Suite; + + function Suite return AUnit.Test_Suites.Access_Test_Suite is + begin + Result.Add_Test (Rectangle.Tests.Suite.Suite); + Result.Add_Test (Square.Tests.Suite.Suite); + Result.Add_Test (Square.Tests.Suite_Liskov.Suite); + return Result'Access; + end Suite; + +end My_Suite; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/my_suite.ads b/ada/libaunit-3.7.2/examples/liskov/tests/my_suite.ads new file mode 100644 index 000000000..8d39ae3bd --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/my_suite.ads @@ -0,0 +1,10 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Suites; + +package My_Suite is + + function Suite return AUnit.Test_Suites.Access_Test_Suite; + +end My_Suite; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests-suite.adb b/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests-suite.adb new file mode 100644 index 000000000..b1726fa1c --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests-suite.adb @@ -0,0 +1,41 @@ +-- +-- Copyright (C) 2008, AdaCore +-- + +with AUnit.Test_Caller; + +package body Rectangle.Tests.Suite is + + package Runner is new AUnit.Test_Caller + (Rectangle.Tests.Test); + + Result : aliased AUnit.Test_Suites.Test_Suite; + + Test_Width : aliased Runner.Test_Case; + Test_Height : aliased Runner.Test_Case; + Test_Area : aliased Runner.Test_Case; + + ----------- + -- Suite -- + ----------- + + function Suite return AUnit.Test_Suites.Access_Test_Suite + is + begin + Runner.Create (Test_Width, + "Rectangle : Test width", + Test_Set_Width'Access); + Runner.Create (Test_Height, + "Rectangle : Test height", + Test_Set_Height'Access); + Runner.Create (Test_Area, + "Rectangle : Test area", + Test_Get_Area'Access); + Result.Add_Test (Test_Width'Access); + Result.Add_Test (Test_Height'Access); + Result.Add_Test (Test_Area'Access); + + return Result'Access; + end Suite; + +end Rectangle.Tests.Suite; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests-suite.ads b/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests-suite.ads new file mode 100644 index 000000000..44519af44 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests-suite.ads @@ -0,0 +1,11 @@ +-- +-- Copyright (C) 2008, AdaCore +-- + +with AUnit.Test_Suites; + +package Rectangle.Tests.Suite is + + function Suite return AUnit.Test_Suites.Access_Test_Suite; + +end Rectangle.Tests.Suite; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests.adb b/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests.adb new file mode 100644 index 000000000..ea6257970 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests.adb @@ -0,0 +1,32 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Assertions; use AUnit.Assertions; + +with Shape; + +package body Rectangle.Tests is + + ----------------- + -- Set_Up_Case -- + ----------------- + + Local_Rectangle : aliased Rectangle_Type; + procedure Set_Up (T : in out Test) is + begin + T.The_Shape := Local_Rectangle'Access; + end Set_Up; + + ------------------- + -- Test_Get_Area -- + ------------------- + + procedure Test_Get_Area (T : in out Test) is + begin + Shape.Set_Width (T.The_Shape.all, 3); + Shape.Set_Height (T.The_Shape.all, 5); + Assert (Shape.Area (T.The_Shape.all) = 15, + "Wrong area returned for object rectangle"); + end Test_Get_Area; + +end Rectangle.Tests; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests.ads b/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests.ads new file mode 100644 index 000000000..00885f775 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/rectangle-tests.ads @@ -0,0 +1,14 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Shape.Tests; + +package Rectangle.Tests is + + type Test is new Shape.Tests.Test with null record; + + procedure Set_Up (T : in out Test); + + procedure Test_Get_Area (T : in out Test); + +end Rectangle.Tests; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/shape-tests.adb b/ada/libaunit-3.7.2/examples/liskov/tests/shape-tests.adb new file mode 100644 index 000000000..0a62410eb --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/shape-tests.adb @@ -0,0 +1,38 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Assertions; use AUnit.Assertions; + +package body Shape.Tests is + + -------------------- + -- Test_Set_Width -- + -------------------- + + procedure Test_Set_Width (T : in out Test) is + begin + T.The_Shape.Set_Width (3); + Assert + (T.The_Shape.Width = 3, + "Width did not return the correct value after a Set_Width"); + + T.The_Shape.Set_Width (7); + Assert + (T.The_Shape.Width = 7, + "Width did not return the correct value after a 2nd Set_Width"); + end Test_Set_Width; + + procedure Test_Set_Height (T : in out Test) is + begin + T.The_Shape.Set_Height (3); + Assert + (T.The_Shape.Height = 3, + "Height did not return the correct value after a Set_Height"); + + T.The_Shape.Set_Height (7); + Assert + (T.The_Shape.Height = 7, + "Height did not return the correct value after a 2nd Set_Height"); + end Test_Set_Height; + +end Shape.Tests; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/shape-tests.ads b/ada/libaunit-3.7.2/examples/liskov/tests/shape-tests.ads new file mode 100644 index 000000000..9f2e830a6 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/shape-tests.ads @@ -0,0 +1,17 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Fixtures; + +package Shape.Tests is + + type Test is abstract new AUnit.Test_Fixtures.Test_Fixture + with record + The_Shape : Shape_Access; + end record; + + procedure Test_Set_Width (T : in out Test); + procedure Test_Set_Height (T : in out Test); + procedure Test_Get_Area (T : in out Test) is abstract; + +end Shape.Tests; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite.adb b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite.adb new file mode 100644 index 000000000..df7cdb422 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite.adb @@ -0,0 +1,36 @@ +-- +-- Copyright (C) 2008, AdaCore +-- + +with AUnit.Test_Caller; + +package body Square.Tests.Suite is + + package Runner is new AUnit.Test_Caller + (Square.Tests.Test); + + Result : aliased AUnit.Test_Suites.Test_Suite; + + Test_Width : aliased Runner.Test_Case; + Test_Height : aliased Runner.Test_Case; + Test_Area : aliased Runner.Test_Case; + + function Suite return AUnit.Test_Suites.Access_Test_Suite is + begin + Runner.Create (Test_Width, + "Square : Test width", + Test_Set_Width'Access); + Runner.Create (Test_Height, + "Square : Test height", + Test_Set_Height'Access); + Runner.Create (Test_Area, + "Square : Test area", + Test_Get_Area'Access); + Result.Add_Test (Test_Width'Access); + Result.Add_Test (Test_Height'Access); + Result.Add_Test (Test_Area'Access); + + return Result'Access; + end Suite; + +end Square.Tests.Suite; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite.ads b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite.ads new file mode 100644 index 000000000..fe25d3db5 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite.ads @@ -0,0 +1,11 @@ +-- +-- Copyright (C) 2008, AdaCore +-- + +with AUnit.Test_Suites; + +package Square.Tests.Suite is + + function Suite return AUnit.Test_Suites.Access_Test_Suite; + +end Square.Tests.Suite; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite_liskov.adb b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite_liskov.adb new file mode 100644 index 000000000..396a09084 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite_liskov.adb @@ -0,0 +1,50 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Ada.Unchecked_Conversion; +with AUnit.Test_Caller; +with Rectangle.Tests; + +package body Square.Tests.Suite_Liskov is + + package Runner is new AUnit.Test_Caller + (Square.Tests.Test); + package Rectangle_Runner is new AUnit.Test_Caller + (Rectangle.Tests.Test); + + Result : aliased AUnit.Test_Suites.Test_Suite; + + Test_Width : aliased Runner.Test_Case; + Test_Height : aliased Runner.Test_Case; + Test_Area : aliased Runner.Test_Case; + + function Suite return AUnit.Test_Suites.Access_Test_Suite is + function Convert is new Ada.Unchecked_Conversion + (Rectangle_Runner.Test_Method, Runner.Test_Method); + begin + Runner.Create + (Test_Width, + "Square as Rectangle (liskov) : Test width", + Convert + (Rectangle_Runner.Test_Method' + (Rectangle.Tests.Test_Set_Width'Access))); + Runner.Create + (Test_Height, + "Square as Rectangle (liskov) : Test height", + Convert + (Rectangle_Runner.Test_Method' + (Rectangle.Tests.Test_Set_Height'Access))); + Runner.Create + (Test_Area, + "Square as Rectangle (liskov) : Test area", + Convert + (Rectangle_Runner.Test_Method' + (Rectangle.Tests.Test_Get_Area'Access))); + Result.Add_Test (Test_Width'Access); + Result.Add_Test (Test_Height'Access); + Result.Add_Test (Test_Area'Access); + + return Result'Access; + end Suite; + +end Square.Tests.Suite_Liskov; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite_liskov.ads b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite_liskov.ads new file mode 100644 index 000000000..b6cff5599 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests-suite_liskov.ads @@ -0,0 +1,11 @@ +-- +-- Copyright (C) 2008, AdaCore +-- + +with AUnit.Test_Suites; + +package Square.Tests.Suite_Liskov is + + function Suite return AUnit.Test_Suites.Access_Test_Suite; + +end Square.Tests.Suite_Liskov; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/square-tests.adb b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests.adb new file mode 100644 index 000000000..f0a5b775c --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests.adb @@ -0,0 +1,33 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Assertions; use AUnit.Assertions; + +package body Square.Tests is + + ----------------- + -- Set_Up_Case -- + ----------------- + + Local_Square : aliased Square_Type; + + procedure Set_Up (T : in out Test) is + begin + T.The_Shape := Local_Square'Access; + end Set_Up; + + ------------------- + -- Test_Get_Area -- + ------------------- + + procedure Test_Get_Area (T : in out Test) is + begin + T.The_Shape.Set_Width (3); + Assert (T.The_Shape.Area = 9, + "Wrong area returned for object square"); + T.The_Shape.Set_Height (5); + Assert (T.The_Shape.Area = 25, + "Wrong area returned for object square"); + end Test_Get_Area; + +end Square.Tests; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/square-tests.ads b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests.ads new file mode 100644 index 000000000..958cd7978 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/square-tests.ads @@ -0,0 +1,15 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Rectangle.Tests; + +package Square.Tests is + + type Test is new Rectangle.Tests.Test with + null record; + + procedure Set_Up (T : in out Test); + + procedure Test_Get_Area (T : in out Test); + +end Square.Tests; diff --git a/ada/libaunit-3.7.2/examples/liskov/tests/test_liskov.adb b/ada/libaunit-3.7.2/examples/liskov/tests/test_liskov.adb new file mode 100644 index 000000000..9b16acf0a --- /dev/null +++ b/ada/libaunit-3.7.2/examples/liskov/tests/test_liskov.adb @@ -0,0 +1,13 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Reporter.Text; +with AUnit.Run; +with My_Suite; use My_Suite; + +procedure Test_Liskov is + procedure Runner is new AUnit.Run.Test_Runner (Suite); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + Runner (Reporter); +end Test_Liskov; diff --git a/ada/libaunit-3.7.2/examples/simple_test/harness.gpr b/ada/libaunit-3.7.2/examples/simple_test/harness.gpr new file mode 100644 index 000000000..1aabc563c --- /dev/null +++ b/ada/libaunit-3.7.2/examples/simple_test/harness.gpr @@ -0,0 +1,27 @@ +with "aunit"; +with "tested_lib/testlib"; + +project Harness is + + for Languages use ("Ada"); + for Main use ("test_math.adb"); + for Source_Dirs use ("tests"); + for Exec_Dir use "."; + for Object_Dir use "obj"; + + package Linker is + for Default_Switches ("ada") use ("-g"); + end Linker; + + package Binder is + for Default_Switches ("ada") use ("-E", "-static"); + end Binder; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-gnatQ", "-O1", "-gnatf", "-gnato", + "-gnatwa.Xe", "-gnaty", "-gnat05"); + end Compiler; + +end Harness; + diff --git a/ada/libaunit-3.7.2/examples/simple_test/tested_lib/src/math.adb b/ada/libaunit-3.7.2/examples/simple_test/tested_lib/src/math.adb new file mode 100644 index 000000000..a37afe920 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/simple_test/tested_lib/src/math.adb @@ -0,0 +1,16 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Math is + + function "+" (I1, I2 : Int) return Int is + begin + return Int (Integer (I1) + Integer (I2)); + end "+"; + + function "-" (I1, I2 : Int) return Int is + begin + return Int (Integer (I1) - Integer (I2)); + end "-"; + +end Math; diff --git a/ada/libaunit-3.7.2/examples/simple_test/tested_lib/src/math.ads b/ada/libaunit-3.7.2/examples/simple_test/tested_lib/src/math.ads new file mode 100644 index 000000000..b3bf1c3b7 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/simple_test/tested_lib/src/math.ads @@ -0,0 +1,12 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package Math is + + type Int is new Integer; + + function "+" (I1, I2 : Int) return Int; + + function "-" (I1, I2 : Int) return Int; + +end Math; diff --git a/ada/libaunit-3.7.2/examples/simple_test/tested_lib/testlib.gpr b/ada/libaunit-3.7.2/examples/simple_test/tested_lib/testlib.gpr new file mode 100644 index 000000000..12042e15e --- /dev/null +++ b/ada/libaunit-3.7.2/examples/simple_test/tested_lib/testlib.gpr @@ -0,0 +1,17 @@ +project TestLib is + + for Source_Dirs use ("src"); + + for Languages use ("Ada"); + for Object_Dir use "obj"; + for Library_Dir use "lib"; + for Library_Name use "testlib"; + for Library_Kind use "static"; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-O1", "-gnat05", "-gnatwa.Xe", "-gnaty", "-gnata", "-gnatf"); + end Compiler; + +end TestLib; + diff --git a/ada/libaunit-3.7.2/examples/simple_test/tests/math-test.adb b/ada/libaunit-3.7.2/examples/simple_test/tests/math-test.adb new file mode 100644 index 000000000..feb3765b7 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/simple_test/tests/math-test.adb @@ -0,0 +1,23 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Assertions; use AUnit.Assertions; + +package body Math.Test is + + function Name (T : Test) return AUnit.Message_String is + pragma Unreferenced (T); + begin + return AUnit.Format ("Test Math package"); + end Name; + + procedure Run_Test (T : in out Test) is + pragma Unreferenced (T); + I1 : constant Int := 5; + I2 : constant Int := 3; + begin + Assert (I1 + I2 = 8, "Incorrect result after addition"); + Assert (I1 - I2 = 2, "Incorrect result after subtraction"); + end Run_Test; + +end Math.Test; diff --git a/ada/libaunit-3.7.2/examples/simple_test/tests/math-test.ads b/ada/libaunit-3.7.2/examples/simple_test/tests/math-test.ads new file mode 100644 index 000000000..c0b2dc47e --- /dev/null +++ b/ada/libaunit-3.7.2/examples/simple_test/tests/math-test.ads @@ -0,0 +1,15 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit; +with AUnit.Simple_Test_Cases; + +package Math.Test is + + type Test is new AUnit.Simple_Test_Cases.Test_Case with null record; + + function Name (T : Test) return AUnit.Message_String; + + procedure Run_Test (T : in out Test); + +end Math.Test; diff --git a/ada/libaunit-3.7.2/examples/simple_test/tests/math_suite.adb b/ada/libaunit-3.7.2/examples/simple_test/tests/math_suite.adb new file mode 100644 index 000000000..67a9b18f5 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/simple_test/tests/math_suite.adb @@ -0,0 +1,15 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Math.Test; + +package body Math_Suite is + + function Suite return Access_Test_Suite is + Ret : constant Access_Test_Suite := new Test_Suite; + begin + Ret.Add_Test (new Math.Test.Test); + return Ret; + end Suite; + +end Math_Suite; diff --git a/ada/libaunit-3.7.2/examples/simple_test/tests/math_suite.ads b/ada/libaunit-3.7.2/examples/simple_test/tests/math_suite.ads new file mode 100644 index 000000000..871544697 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/simple_test/tests/math_suite.ads @@ -0,0 +1,10 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Suites; use AUnit.Test_Suites; + +package Math_Suite is + + function Suite return Access_Test_Suite; + +end Math_Suite; diff --git a/ada/libaunit-3.7.2/examples/simple_test/tests/test_math.adb b/ada/libaunit-3.7.2/examples/simple_test/tests/test_math.adb new file mode 100644 index 000000000..5745278f2 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/simple_test/tests/test_math.adb @@ -0,0 +1,13 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Reporter.Text; +with AUnit.Run; +with Math_Suite; use Math_Suite; + +procedure Test_Math is + procedure Runner is new AUnit.Run.Test_Runner (Suite); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + Runner (Reporter); +end Test_Math; diff --git a/ada/libaunit-3.7.2/examples/test_caller/harness/harness.gpr b/ada/libaunit-3.7.2/examples/test_caller/harness/harness.gpr new file mode 100644 index 000000000..ed04a21fc --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_caller/harness/harness.gpr @@ -0,0 +1,27 @@ +with "aunit"; +with "../tested_lib/testlib"; + +project Harness is + + for Languages use ("Ada"); + for Main use ("test_math.adb"); + for Source_Dirs use ("src"); + for Exec_Dir use ".."; + for Object_Dir use "obj"; + + package Linker is + for Default_Switches ("ada") use ("-g"); + end Linker; + + package Binder is + for Default_Switches ("ada") use ("-E", "-static"); + end Binder; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-gnatQ", "-O1", "-gnatf", "-gnato", + "-gnatwa.Xe", "-gnaty", "-gnat05"); + end Compiler; + +end Harness; + diff --git a/ada/libaunit-3.7.2/examples/test_caller/harness/src/math-test.adb b/ada/libaunit-3.7.2/examples/test_caller/harness/src/math-test.adb new file mode 100644 index 000000000..07b402c8b --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_caller/harness/src/math-test.adb @@ -0,0 +1,24 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Assertions; use AUnit.Assertions; + +package body Math.Test is + + procedure Test_Addition (T : in out Test) is + pragma Unreferenced (T); + I1 : constant Int := 5; + I2 : constant Int := 3; + begin + Assert (I1 + I2 = 8, "Incorrect result after addition"); + end Test_Addition; + + procedure Test_Subtraction (T : in out Test) is + pragma Unreferenced (T); + I1 : constant Int := 5; + I2 : constant Int := 3; + begin + Assert (I1 - I2 = 2, "Incorrect result after subtraction"); + end Test_Subtraction; + +end Math.Test; diff --git a/ada/libaunit-3.7.2/examples/test_caller/harness/src/math-test.ads b/ada/libaunit-3.7.2/examples/test_caller/harness/src/math-test.ads new file mode 100644 index 000000000..a5a88ac56 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_caller/harness/src/math-test.ads @@ -0,0 +1,14 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit; +with AUnit.Test_Fixtures; + +package Math.Test is + + type Test is new AUnit.Test_Fixtures.Test_Fixture with null record; + + procedure Test_Addition (T : in out Test); + procedure Test_Subtraction (T : in out Test); + +end Math.Test; diff --git a/ada/libaunit-3.7.2/examples/test_caller/harness/src/math_suite.adb b/ada/libaunit-3.7.2/examples/test_caller/harness/src/math_suite.adb new file mode 100644 index 000000000..376193727 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_caller/harness/src/math_suite.adb @@ -0,0 +1,21 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Math.Test; use Math.Test; +with AUnit.Test_Caller; + +package body Math_Suite is + + package Caller is new AUnit.Test_Caller (Math.Test.Test); + + function Suite return Access_Test_Suite is + Ret : constant Access_Test_Suite := AUnit.Test_Suites.New_Suite; + begin + Ret.Add_Test + (Caller.Create ("Test addition", Test_Addition'Access)); + Ret.Add_Test + (Caller.Create ("Test subtraction", Test_Subtraction'Access)); + return Ret; + end Suite; + +end Math_Suite; diff --git a/ada/libaunit-3.7.2/examples/test_caller/harness/src/math_suite.ads b/ada/libaunit-3.7.2/examples/test_caller/harness/src/math_suite.ads new file mode 100644 index 000000000..871544697 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_caller/harness/src/math_suite.ads @@ -0,0 +1,10 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Suites; use AUnit.Test_Suites; + +package Math_Suite is + + function Suite return Access_Test_Suite; + +end Math_Suite; diff --git a/ada/libaunit-3.7.2/examples/test_caller/harness/src/test_math.adb b/ada/libaunit-3.7.2/examples/test_caller/harness/src/test_math.adb new file mode 100644 index 000000000..5745278f2 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_caller/harness/src/test_math.adb @@ -0,0 +1,13 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Reporter.Text; +with AUnit.Run; +with Math_Suite; use Math_Suite; + +procedure Test_Math is + procedure Runner is new AUnit.Run.Test_Runner (Suite); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + Runner (Reporter); +end Test_Math; diff --git a/ada/libaunit-3.7.2/examples/test_caller/tested_lib/src/math.adb b/ada/libaunit-3.7.2/examples/test_caller/tested_lib/src/math.adb new file mode 100644 index 000000000..a37afe920 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_caller/tested_lib/src/math.adb @@ -0,0 +1,16 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Math is + + function "+" (I1, I2 : Int) return Int is + begin + return Int (Integer (I1) + Integer (I2)); + end "+"; + + function "-" (I1, I2 : Int) return Int is + begin + return Int (Integer (I1) - Integer (I2)); + end "-"; + +end Math; diff --git a/ada/libaunit-3.7.2/examples/test_caller/tested_lib/src/math.ads b/ada/libaunit-3.7.2/examples/test_caller/tested_lib/src/math.ads new file mode 100644 index 000000000..b3bf1c3b7 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_caller/tested_lib/src/math.ads @@ -0,0 +1,12 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package Math is + + type Int is new Integer; + + function "+" (I1, I2 : Int) return Int; + + function "-" (I1, I2 : Int) return Int; + +end Math; diff --git a/ada/libaunit-3.7.2/examples/test_caller/tested_lib/testlib.gpr b/ada/libaunit-3.7.2/examples/test_caller/tested_lib/testlib.gpr new file mode 100644 index 000000000..12042e15e --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_caller/tested_lib/testlib.gpr @@ -0,0 +1,17 @@ +project TestLib is + + for Source_Dirs use ("src"); + + for Languages use ("Ada"); + for Object_Dir use "obj"; + for Library_Dir use "lib"; + for Library_Name use "testlib"; + for Library_Kind use "static"; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-O1", "-gnat05", "-gnatwa.Xe", "-gnaty", "-gnata", "-gnatf"); + end Compiler; + +end TestLib; + diff --git a/ada/libaunit-3.7.2/examples/test_fixture/harness.gpr b/ada/libaunit-3.7.2/examples/test_fixture/harness.gpr new file mode 100644 index 000000000..1aabc563c --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_fixture/harness.gpr @@ -0,0 +1,27 @@ +with "aunit"; +with "tested_lib/testlib"; + +project Harness is + + for Languages use ("Ada"); + for Main use ("test_math.adb"); + for Source_Dirs use ("tests"); + for Exec_Dir use "."; + for Object_Dir use "obj"; + + package Linker is + for Default_Switches ("ada") use ("-g"); + end Linker; + + package Binder is + for Default_Switches ("ada") use ("-E", "-static"); + end Binder; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-gnatQ", "-O1", "-gnatf", "-gnato", + "-gnatwa.Xe", "-gnaty", "-gnat05"); + end Compiler; + +end Harness; + diff --git a/ada/libaunit-3.7.2/examples/test_fixture/tested_lib/src/math.adb b/ada/libaunit-3.7.2/examples/test_fixture/tested_lib/src/math.adb new file mode 100644 index 000000000..a37afe920 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_fixture/tested_lib/src/math.adb @@ -0,0 +1,16 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package body Math is + + function "+" (I1, I2 : Int) return Int is + begin + return Int (Integer (I1) + Integer (I2)); + end "+"; + + function "-" (I1, I2 : Int) return Int is + begin + return Int (Integer (I1) - Integer (I2)); + end "-"; + +end Math; diff --git a/ada/libaunit-3.7.2/examples/test_fixture/tested_lib/src/math.ads b/ada/libaunit-3.7.2/examples/test_fixture/tested_lib/src/math.ads new file mode 100644 index 000000000..b3bf1c3b7 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_fixture/tested_lib/src/math.ads @@ -0,0 +1,12 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +package Math is + + type Int is new Integer; + + function "+" (I1, I2 : Int) return Int; + + function "-" (I1, I2 : Int) return Int; + +end Math; diff --git a/ada/libaunit-3.7.2/examples/test_fixture/tested_lib/testlib.gpr b/ada/libaunit-3.7.2/examples/test_fixture/tested_lib/testlib.gpr new file mode 100644 index 000000000..12042e15e --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_fixture/tested_lib/testlib.gpr @@ -0,0 +1,17 @@ +project TestLib is + + for Source_Dirs use ("src"); + + for Languages use ("Ada"); + for Object_Dir use "obj"; + for Library_Dir use "lib"; + for Library_Name use "testlib"; + for Library_Kind use "static"; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-O1", "-gnat05", "-gnatwa.Xe", "-gnaty", "-gnata", "-gnatf"); + end Compiler; + +end TestLib; + diff --git a/ada/libaunit-3.7.2/examples/test_fixture/tests/math-test.adb b/ada/libaunit-3.7.2/examples/test_fixture/tests/math-test.adb new file mode 100644 index 000000000..c21a61b23 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_fixture/tests/math-test.adb @@ -0,0 +1,24 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Assertions; use AUnit.Assertions; + +package body Math.Test is + + procedure Set_Up (T : in out Test) is + begin + T.I1 := 5; + T.I2 := 3; + end Set_Up; + + procedure Test_Addition (T : in out Test) is + begin + Assert (T.I1 + T.I2 = 8, "Incorrect result after addition"); + end Test_Addition; + + procedure Test_Subtraction (T : in out Test) is + begin + Assert (T.I1 - T.I2 = 2, "Incorrect result after subtraction"); + end Test_Subtraction; + +end Math.Test; diff --git a/ada/libaunit-3.7.2/examples/test_fixture/tests/math-test.ads b/ada/libaunit-3.7.2/examples/test_fixture/tests/math-test.ads new file mode 100644 index 000000000..05ac3e483 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_fixture/tests/math-test.ads @@ -0,0 +1,19 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit; +with AUnit.Test_Fixtures; + +package Math.Test is + + type Test is new AUnit.Test_Fixtures.Test_Fixture with record + I1 : Int; + I2 : Int; + end record; + + procedure Set_Up (T : in out Test); + + procedure Test_Addition (T : in out Test); + procedure Test_Subtraction (T : in out Test); + +end Math.Test; diff --git a/ada/libaunit-3.7.2/examples/test_fixture/tests/math_suite.adb b/ada/libaunit-3.7.2/examples/test_fixture/tests/math_suite.adb new file mode 100644 index 000000000..83c432f62 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_fixture/tests/math_suite.adb @@ -0,0 +1,21 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with Math.Test; use Math.Test; +with AUnit.Test_Caller; + +package body Math_Suite is + + package Caller is new AUnit.Test_Caller (Math.Test.Test); + + function Suite return Access_Test_Suite is + Ret : constant Access_Test_Suite := new Test_Suite; + begin + Ret.Add_Test + (Caller.Create ("Test addition", Test_Addition'Access)); + Ret.Add_Test + (Caller.Create ("Test subtraction", Test_Subtraction'Access)); + return Ret; + end Suite; + +end Math_Suite; diff --git a/ada/libaunit-3.7.2/examples/test_fixture/tests/math_suite.ads b/ada/libaunit-3.7.2/examples/test_fixture/tests/math_suite.ads new file mode 100644 index 000000000..871544697 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_fixture/tests/math_suite.ads @@ -0,0 +1,10 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Test_Suites; use AUnit.Test_Suites; + +package Math_Suite is + + function Suite return Access_Test_Suite; + +end Math_Suite; diff --git a/ada/libaunit-3.7.2/examples/test_fixture/tests/test_math.adb b/ada/libaunit-3.7.2/examples/test_fixture/tests/test_math.adb new file mode 100644 index 000000000..5745278f2 --- /dev/null +++ b/ada/libaunit-3.7.2/examples/test_fixture/tests/test_math.adb @@ -0,0 +1,13 @@ +-- +-- Copyright (C) 2008, AdaCore +-- +with AUnit.Reporter.Text; +with AUnit.Run; +with Math_Suite; use Math_Suite; + +procedure Test_Math is + procedure Runner is new AUnit.Run.Test_Runner (Suite); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + Runner (Reporter); +end Test_Math; diff --git a/ada/libaunit-3.7.2/features-32 b/ada/libaunit-3.7.2/features-32 new file mode 100644 index 000000000..69cf85298 --- /dev/null +++ b/ada/libaunit-3.7.2/features-32 @@ -0,0 +1,19 @@ +=========================== +AUnit 3.2 NEW FEATURES LIST +=========================== + +Copyright (C) 2008-2009, AdaCore + +This file contains a complete list of new features in version 3.2 of AUnit. A +full description of all AUnit features can be found in the AUnit Cookbook. + +An ISO date (YYYY-MM-DD) appears in parentheses after the description line. +This date shows the implementation date of the feature. Any 3.2.0w wavefront +subsequent to this date will contain the indicated feature, as will any +subsequent 3.2 or later releases. + +NF-32-I302-012 Add support for expected exceptions (2009-03-02) + + A new procedure Assert_Exception has been added to the AUnit.Assertions + package to handle expected exceptions. + diff --git a/ada/libaunit-3.7.2/features-33 b/ada/libaunit-3.7.2/features-33 new file mode 100644 index 000000000..d7192511c --- /dev/null +++ b/ada/libaunit-3.7.2/features-33 @@ -0,0 +1,30 @@ +=========================== +AUnit 3.3 NEW FEATURES LIST +=========================== + +Copyright (C) 2008-2010, AdaCore + +This file contains a complete list of new features in version 3.3 of AUnit. A +full description of all AUnit features can be found in the AUnit Cookbook. + +An ISO date (YYYY-MM-DD) appears in parentheses after the description line. +This date shows the implementation date of the feature. Any 3.3.0w wavefront +subsequent to this date will contain the indicated feature, as will any +subsequent 3.3 or later releases. + +NF-33-IC16-035 Add timing of individual tests (2010-01-08) + + Users can select for timing of individual tests as well as cumulative time. + This is specified in AUnit.Options. + +NF-33-IA08-009 General AUnit improvements (2009-10-09) + + Some new functionalities have been implemented in AUnit: + * The Text reporter now allows colored output on ANSI terminals. + * Unexpected exceptions are now reported with their message and symbolic + traceback when available. + * It is now possible to run a subset of the tests + This requires initializing and passing a Test_Filter object + * Test_Result is now extensible by the user + In particular, this means you can do postprocessing after each test has + been run, like synchronous output for instance. diff --git a/ada/libaunit-3.7.2/features-34 b/ada/libaunit-3.7.2/features-34 new file mode 100644 index 000000000..acf14b4af --- /dev/null +++ b/ada/libaunit-3.7.2/features-34 @@ -0,0 +1,14 @@ +=========================== +AUnit 3.4 NEW FEATURES LIST +=========================== + +Copyright (C) 2008-2014, AdaCore + +This file contains a complete list of new features in version 3.4 of AUnit. A +full description of all AUnit features can be found in the AUnit Cookbook. + +An ISO date (YYYY-MM-DD) appears in parentheses after the description line. +This date shows the implementation date of the feature. Any 3.4.0w wavefront +subsequent to this date will contain the indicated feature, as will any +subsequent 3.4 or later releases. + diff --git a/ada/libaunit-3.7.2/features-35 b/ada/libaunit-3.7.2/features-35 new file mode 100644 index 000000000..2af1f0327 --- /dev/null +++ b/ada/libaunit-3.7.2/features-35 @@ -0,0 +1,14 @@ +=========================== +AUnit 3.5 NEW FEATURES LIST +=========================== + +Copyright (C) 2008-2014, AdaCore + +This file contains a complete list of new features in version 3.5 of AUnit. A +full description of all AUnit features can be found in the AUnit Cookbook. + +An ISO date (YYYY-MM-DD) appears in parentheses after the description line. +This date shows the implementation date of the feature. Any 3.5.0w wavefront +subsequent to this date will contain the indicated feature, as will any +subsequent 3.5 or later releases. + diff --git a/ada/libaunit-3.7.2/features-36 b/ada/libaunit-3.7.2/features-36 new file mode 100644 index 000000000..09b1258f2 --- /dev/null +++ b/ada/libaunit-3.7.2/features-36 @@ -0,0 +1,14 @@ +=========================== +AUnit 3.6 NEW FEATURES LIST +=========================== + +Copyright (C) 2008-2014, AdaCore + +This file contains a complete list of new features in version 3.6 of AUnit. A +full description of all AUnit features can be found in the AUnit Cookbook. + +An ISO date (YYYY-MM-DD) appears in parentheses after the description line. +This date shows the implementation date of the feature. Any 3.6.0w wavefront +subsequent to this date will contain the indicated feature, as will any +subsequent 3.6 or later releases. + diff --git a/ada/libaunit-3.7.2/features-37 b/ada/libaunit-3.7.2/features-37 new file mode 100644 index 000000000..cdcb5adfe --- /dev/null +++ b/ada/libaunit-3.7.2/features-37 @@ -0,0 +1,14 @@ +=========================== +AUnit 3.7 NEW FEATURES LIST +=========================== + +Copyright (C) 2008-2013, AdaCore + +This file contains a complete list of new features in version 3.7 of AUnit. A +full description of all AUnit features can be found in the AUnit Cookbook. + +An ISO date (YYYY-MM-DD) appears in parentheses after the description line. +This date shows the implementation date of the feature. Any 3.7.0w wavefront +subsequent to this date will contain the indicated feature, as will any +subsequent 3.7 or later releases. + diff --git a/ada/libaunit-3.7.2/include/aunit/containers/ada_containers-aunit_lists.adb b/ada/libaunit-3.7.2/include/aunit/containers/ada_containers-aunit_lists.adb new file mode 100644 index 000000000..9bb6abcb4 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/containers/ada_containers-aunit_lists.adb @@ -0,0 +1,1569 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT LIBRARY COMPONENTS -- +-- -- +-- A D A _ C O N T A I N E R S . A U N I T _ L I S T S -- +-- -- +-- B o d y -- +-- -- +-- Copyright (C) 2004-2007, Free Software Foundation, Inc. -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- This unit was originally developed by Matthew J Heaney. -- +------------------------------------------------------------------------------ + +pragma Ada_2005; + +with System; use type System.Address; + +with AUnit.Memory; use AUnit.Memory; +with AUnit.Memory.Utils; use AUnit.Memory.Utils; + +package body Ada_Containers.AUnit_Lists is + + ----------------------- + -- Local Subprograms -- + ----------------------- + + function New_Node_Type is new AUnit.Memory.Utils.Gen_Alloc + (Node_Type, Node_Access); + + function New_Node_Type + (Element : Element_Type; + Next : Node_Access; + Prev : Node_Access) + return Node_Access; + + procedure Insert_Internal + (Container : in out List; + Before : Node_Access; + New_Node : Node_Access); + + function Vet (Position : Cursor) return Boolean; + + -------------- + -- New_Node -- + -------------- + + function New_Node_Type + (Element : Element_Type; + Next : Node_Access; + Prev : Node_Access) return Node_Access + is + Res : constant Node_Access := New_Node_Type; + begin + Res.Element := Element; + Res.Next := Next; + Res.Prev := Prev; + return Res; + end New_Node_Type; + + --------- + -- "=" -- + --------- + + function "=" (Left, Right : List) return Boolean is + L : Node_Access := Left.First; + R : Node_Access := Right.First; + + begin + if Left'Address = Right'Address then + return True; + end if; + + if Left.Length /= Right.Length then + return False; + end if; + + for J in 1 .. Left.Length loop + if L.Element /= R.Element then + return False; + end if; + + L := L.Next; + R := R.Next; + end loop; + + return True; + end "="; + + ------------ + -- Append -- + ------------ + + procedure Append + (Container : in out List; + New_Item : Element_Type; + Count : Count_Type := 1) + is + begin + Insert (Container, No_Element, New_Item, Count); + end Append; + + ----------- + -- Clear -- + ----------- + + procedure Clear (Container : in out List) is + X : Node_Access; + + begin + if Container.Length = 0 then + pragma Assert (Container.First = null); + pragma Assert (Container.Last = null); + pragma Assert (Container.Busy = 0); + pragma Assert (Container.Lock = 0); + return; + end if; + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + + if Container.Busy > 0 then + raise Program_Error; + end if; + + while Container.Length > 1 loop + X := Container.First; + pragma Assert (X.Next.Prev = Container.First); + + Container.First := X.Next; + Container.First.Prev := null; + + Container.Length := Container.Length - 1; + + AUnit_Free (X.all'Address); + end loop; + + X := Container.First; + pragma Assert (X = Container.Last); + + Container.First := null; + Container.Last := null; + Container.Length := 0; + + AUnit_Free (X.all'Address); + end Clear; + + -------------- + -- Contains -- + -------------- + + function Contains + (Container : List; + Item : Element_Type) return Boolean + is + begin + return Find (Container, Item) /= No_Element; + end Contains; + + ------------ + -- Delete -- + ------------ + + procedure Delete + (Container : in out List; + Position : in out Cursor; + Count : Count_Type := 1) + is + X : Node_Access; + + begin + if Position.Node = null then + raise Constraint_Error; + end if; + + if Position.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad cursor in Delete"); + + if Position.Node = Container.First then + Delete_First (Container, Count); + Position := No_Element; -- Post-York behavior + return; + end if; + + if Count = 0 then + Position := No_Element; -- Post-York behavior + return; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + for Index in 1 .. Count loop + X := Position.Node; + Container.Length := Container.Length - 1; + + if X = Container.Last then + Position := No_Element; + + Container.Last := X.Prev; + Container.Last.Next := null; + + AUnit_Free (X.all'Address); + return; + end if; + + Position.Node := X.Next; + + X.Next.Prev := X.Prev; + X.Prev.Next := X.Next; + + AUnit_Free (X.all'Address); + end loop; + + Position := No_Element; -- Post-York behavior + end Delete; + + ------------------ + -- Delete_First -- + ------------------ + + procedure Delete_First + (Container : in out List; + Count : Count_Type := 1) + is + X : Node_Access; + + begin + if Count >= Container.Length then + Clear (Container); + return; + end if; + + if Count = 0 then + return; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + for I in 1 .. Count loop + X := Container.First; + pragma Assert (X.Next.Prev = Container.First); + + Container.First := X.Next; + Container.First.Prev := null; + + Container.Length := Container.Length - 1; + + AUnit_Free (X.all'Address); + end loop; + end Delete_First; + + ----------------- + -- Delete_Last -- + ----------------- + + procedure Delete_Last + (Container : in out List; + Count : Count_Type := 1) + is + X : Node_Access; + + begin + if Count >= Container.Length then + Clear (Container); + return; + end if; + + if Count = 0 then + return; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + for I in 1 .. Count loop + X := Container.Last; + pragma Assert (X.Prev.Next = Container.Last); + + Container.Last := X.Prev; + Container.Last.Next := null; + + Container.Length := Container.Length - 1; + + AUnit_Free (X.all'Address); + end loop; + end Delete_Last; + + ------------- + -- Element -- + ------------- + + function Element (Position : Cursor) return Element_Type is + begin + if Position.Node = null then + raise Constraint_Error; + end if; + + pragma Assert (Vet (Position), "bad cursor in Element"); + + return Position.Node.Element; + end Element; + + ---------- + -- Find -- + ---------- + + function Find + (Container : List; + Item : Element_Type; + Position : Cursor := No_Element) return Cursor + is + Node : Node_Access := Position.Node; + + begin + if Node = null then + Node := Container.First; + + else + if Position.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad cursor in Find"); + end if; + + while Node /= null loop + if Node.Element = Item then + return Cursor'(Container'Unchecked_Access, Node); + end if; + + Node := Node.Next; + end loop; + + return No_Element; + end Find; + + ----------- + -- First -- + ----------- + + function First (Container : List) return Cursor is + begin + if Container.First = null then + return No_Element; + end if; + + return Cursor'(Container'Unchecked_Access, Container.First); + end First; + + ------------------- + -- First_Element -- + ------------------- + + function First_Element (Container : List) return Element_Type is + begin + if Container.First = null then + raise Constraint_Error; + end if; + + return Container.First.Element; + end First_Element; + + --------------------- + -- Generic_Sorting -- + --------------------- + + package body Generic_Sorting is + + --------------- + -- Is_Sorted -- + --------------- + + function Is_Sorted (Container : List) return Boolean is + Node : Node_Access := Container.First; + + begin + for I in 2 .. Container.Length loop + if Node.Next.Element < Node.Element then + return False; + end if; + + Node := Node.Next; + end loop; + + return True; + end Is_Sorted; + + ----------- + -- Merge -- + ----------- + + procedure Merge + (Target : in out List; + Source : in out List) + is + LI, RI : Cursor; + + begin + if Target'Address = Source'Address then + return; + end if; + + if Target.Busy > 0 then + raise Program_Error; + end if; + + if Source.Busy > 0 then + raise Program_Error; + end if; + + LI := First (Target); + RI := First (Source); + while RI.Node /= null loop + pragma Assert (RI.Node.Next = null + or else not (RI.Node.Next.Element < + RI.Node.Element)); + + if LI.Node = null then + Splice (Target, No_Element, Source); + return; + end if; + + pragma Assert (LI.Node.Next = null + or else not (LI.Node.Next.Element < + LI.Node.Element)); + + if RI.Node.Element < LI.Node.Element then + declare + RJ : Cursor := RI; + pragma Warnings (Off, RJ); + begin + RI.Node := RI.Node.Next; + Splice (Target, LI, Source, RJ); + end; + + else + LI.Node := LI.Node.Next; + end if; + end loop; + end Merge; + + ---------- + -- Sort -- + ---------- + + procedure Sort (Container : in out List) is + + procedure Partition (Pivot : Node_Access; Back : Node_Access); + + procedure Sort (Front, Back : Node_Access); + + --------------- + -- Partition -- + --------------- + + procedure Partition (Pivot : Node_Access; Back : Node_Access) is + Node : Node_Access := Pivot.Next; + + begin + while Node /= Back loop + if Node.Element < Pivot.Element then + declare + Prev : constant Node_Access := Node.Prev; + Next : constant Node_Access := Node.Next; + + begin + Prev.Next := Next; + + if Next = null then + Container.Last := Prev; + else + Next.Prev := Prev; + end if; + + Node.Next := Pivot; + Node.Prev := Pivot.Prev; + + Pivot.Prev := Node; + + if Node.Prev = null then + Container.First := Node; + else + Node.Prev.Next := Node; + end if; + + Node := Next; + end; + + else + Node := Node.Next; + end if; + end loop; + end Partition; + + ---------- + -- Sort -- + ---------- + + procedure Sort (Front, Back : Node_Access) is + Pivot : Node_Access; + + begin + if Front = null then + Pivot := Container.First; + else + Pivot := Front.Next; + end if; + + if Pivot /= Back then + Partition (Pivot, Back); + Sort (Front, Pivot); + Sort (Pivot, Back); + end if; + end Sort; + + -- Start of processing for Sort + + begin + if Container.Length <= 1 then + return; + end if; + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + + if Container.Busy > 0 then + raise Program_Error; + end if; + + Sort (Front => null, Back => null); + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + end Sort; + + end Generic_Sorting; + + ----------------- + -- Has_Element -- + ----------------- + + function Has_Element (Position : Cursor) return Boolean is + begin + pragma Assert (Vet (Position), "bad cursor in Has_Element"); + return Position.Node /= null; + end Has_Element; + + ------------ + -- Insert -- + ------------ + + procedure Insert + (Container : in out List; + Before : Cursor; + New_Item : Element_Type; + Position : out Cursor; + Count : Count_Type := 1) + is + New_Node : Node_Access; + + begin + if Before.Container /= null then + if Before.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Before), "bad cursor in Insert"); + end if; + + if Count = 0 then + Position := Before; + return; + end if; + + if Container.Length > Count_Type'Last - Count then + raise Constraint_Error; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + New_Node := New_Node_Type (New_Item, null, null); + Insert_Internal (Container, Before.Node, New_Node); + + Position := Cursor'(Container'Unchecked_Access, New_Node); + + for J in Count_Type'(2) .. Count loop + New_Node := New_Node_Type (New_Item, null, null); + Insert_Internal (Container, Before.Node, New_Node); + end loop; + end Insert; + + procedure Insert + (Container : in out List; + Before : Cursor; + New_Item : Element_Type; + Count : Count_Type := 1) + is + Position : Cursor; + pragma Unreferenced (Position); + begin + Insert (Container, Before, New_Item, Position, Count); + end Insert; + + procedure Insert + (Container : in out List; + Before : Cursor; + Position : out Cursor; + Count : Count_Type := 1) + is + New_Node : Node_Access; + + begin + if Before.Container /= null then + if Before.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Before), "bad cursor in Insert"); + end if; + + if Count = 0 then + Position := Before; + return; + end if; + + if Container.Length > Count_Type'Last - Count then + raise Constraint_Error; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + New_Node := New_Node_Type; + Insert_Internal (Container, Before.Node, New_Node); + + Position := Cursor'(Container'Unchecked_Access, New_Node); + + for J in Count_Type'(2) .. Count loop + New_Node := New_Node_Type; + Insert_Internal (Container, Before.Node, New_Node); + end loop; + end Insert; + + --------------------- + -- Insert_Internal -- + --------------------- + + procedure Insert_Internal + (Container : in out List; + Before : Node_Access; + New_Node : Node_Access) + is + begin + if Container.Length = 0 then + pragma Assert (Before = null); + pragma Assert (Container.First = null); + pragma Assert (Container.Last = null); + + Container.First := New_Node; + Container.Last := New_Node; + + elsif Before = null then + pragma Assert (Container.Last.Next = null); + + Container.Last.Next := New_Node; + New_Node.Prev := Container.Last; + + Container.Last := New_Node; + + elsif Before = Container.First then + pragma Assert (Container.First.Prev = null); + + Container.First.Prev := New_Node; + New_Node.Next := Container.First; + + Container.First := New_Node; + + else + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + + New_Node.Next := Before; + New_Node.Prev := Before.Prev; + + Before.Prev.Next := New_Node; + Before.Prev := New_Node; + end if; + + Container.Length := Container.Length + 1; + end Insert_Internal; + + -------------- + -- Is_Empty -- + -------------- + + function Is_Empty (Container : List) return Boolean is + begin + return Container.Length = 0; + end Is_Empty; + + ------------- + -- Iterate -- + ------------- + + procedure Iterate + (Container : List; + Process : Iterator) + is + C : List renames Container'Unrestricted_Access.all; + B : Natural renames C.Busy; + + Node : Node_Access := Container.First; + + begin + B := B + 1; + + begin + while Node /= null loop + Process (Cursor'(Container'Unchecked_Access, Node)); + Node := Node.Next; + end loop; + end; + + B := B - 1; + end Iterate; + + ---------- + -- Last -- + ---------- + + function Last (Container : List) return Cursor is + begin + if Container.Last = null then + return No_Element; + end if; + + return Cursor'(Container'Unchecked_Access, Container.Last); + end Last; + + ------------------ + -- Last_Element -- + ------------------ + + function Last_Element (Container : List) return Element_Type is + begin + if Container.Last = null then + raise Constraint_Error; + end if; + + return Container.Last.Element; + end Last_Element; + + ------------ + -- Length -- + ------------ + + function Length (Container : List) return Count_Type is + begin + return Container.Length; + end Length; + + ---------- + -- Move -- + ---------- + + procedure Move + (Target : in out List; + Source : in out List) + is + begin + if Target'Address = Source'Address then + return; + end if; + + if Source.Busy > 0 then + raise Program_Error; + end if; + + Clear (Target); + + Target.First := Source.First; + Source.First := null; + + Target.Last := Source.Last; + Source.Last := null; + + Target.Length := Source.Length; + Source.Length := 0; + end Move; + + ---------- + -- Next -- + ---------- + + procedure Next (Position : in out Cursor) is + begin + Position := Next (Position); + end Next; + + function Next (Position : Cursor) return Cursor is + begin + if Position.Node = null then + return No_Element; + end if; + + pragma Assert (Vet (Position), "bad cursor in Next"); + + declare + Next_Node : constant Node_Access := Position.Node.Next; + begin + if Next_Node = null then + return No_Element; + end if; + + return Cursor'(Position.Container, Next_Node); + end; + end Next; + + ------------- + -- Prepend -- + ------------- + + procedure Prepend + (Container : in out List; + New_Item : Element_Type; + Count : Count_Type := 1) + is + begin + Insert (Container, First (Container), New_Item, Count); + end Prepend; + + -------------- + -- Previous -- + -------------- + + procedure Previous (Position : in out Cursor) is + begin + Position := Previous (Position); + end Previous; + + function Previous (Position : Cursor) return Cursor is + begin + if Position.Node = null then + return No_Element; + end if; + + pragma Assert (Vet (Position), "bad cursor in Previous"); + + declare + Prev_Node : constant Node_Access := Position.Node.Prev; + begin + if Prev_Node = null then + return No_Element; + end if; + + return Cursor'(Position.Container, Prev_Node); + end; + end Previous; + + --------------------- + -- Replace_Element -- + --------------------- + + procedure Replace_Element + (Container : in out List; + Position : Cursor; + New_Item : Element_Type) + is + begin + if Position.Container = null then + raise Constraint_Error; + end if; + + if Position.Container /= Container'Unchecked_Access then + raise Program_Error; + end if; + + if Container.Lock > 0 then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad cursor in Replace_Element"); + + Position.Node.Element := New_Item; + end Replace_Element; + + ---------------------- + -- Reverse_Elements -- + ---------------------- + + procedure Reverse_Elements (Container : in out List) is + I : Node_Access := Container.First; + J : Node_Access := Container.Last; + + procedure Swap (L, R : Node_Access); + + ---------- + -- Swap -- + ---------- + + procedure Swap (L, R : Node_Access) is + LN : constant Node_Access := L.Next; + LP : constant Node_Access := L.Prev; + + RN : constant Node_Access := R.Next; + RP : constant Node_Access := R.Prev; + + begin + if LP /= null then + LP.Next := R; + end if; + + if RN /= null then + RN.Prev := L; + end if; + + L.Next := RN; + R.Prev := LP; + + if LN = R then + pragma Assert (RP = L); + + L.Prev := R; + R.Next := L; + + else + L.Prev := RP; + RP.Next := L; + + R.Next := LN; + LN.Prev := R; + end if; + end Swap; + + -- Start of processing for Reverse_Elements + + begin + if Container.Length <= 1 then + return; + end if; + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + + if Container.Busy > 0 then + raise Program_Error; + end if; + + Container.First := J; + Container.Last := I; + loop + Swap (L => I, R => J); + + J := J.Next; + exit when I = J; + + I := I.Prev; + exit when I = J; + + Swap (L => J, R => I); + + I := I.Next; + exit when I = J; + + J := J.Prev; + exit when I = J; + end loop; + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + end Reverse_Elements; + + ------------------ + -- Reverse_Find -- + ------------------ + + function Reverse_Find + (Container : List; + Item : Element_Type; + Position : Cursor := No_Element) return Cursor + is + Node : Node_Access := Position.Node; + + begin + if Node = null then + Node := Container.Last; + + else + if Position.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad cursor in Reverse_Find"); + end if; + + while Node /= null loop + if Node.Element = Item then + return Cursor'(Container'Unchecked_Access, Node); + end if; + + Node := Node.Prev; + end loop; + + return No_Element; + end Reverse_Find; + + ------------ + -- Splice -- + ------------ + + procedure Splice + (Target : in out List; + Before : Cursor; + Source : in out List) + is + begin + if Before.Container /= null then + if Before.Container /= Target'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Before), "bad cursor in Splice"); + end if; + + if Target'Address = Source'Address + or else Source.Length = 0 + then + return; + end if; + + pragma Assert (Source.First.Prev = null); + pragma Assert (Source.Last.Next = null); + + if Target.Length > Count_Type'Last - Source.Length then + raise Constraint_Error; + end if; + + if Target.Busy > 0 then + raise Program_Error; + end if; + + if Source.Busy > 0 then + raise Program_Error; + end if; + + if Target.Length = 0 then + pragma Assert (Target.First = null); + pragma Assert (Target.Last = null); + pragma Assert (Before = No_Element); + + Target.First := Source.First; + Target.Last := Source.Last; + + elsif Before.Node = null then + pragma Assert (Target.Last.Next = null); + + Target.Last.Next := Source.First; + Source.First.Prev := Target.Last; + + Target.Last := Source.Last; + + elsif Before.Node = Target.First then + pragma Assert (Target.First.Prev = null); + + Source.Last.Next := Target.First; + Target.First.Prev := Source.Last; + + Target.First := Source.First; + + else + pragma Assert (Target.Length >= 2); + + Before.Node.Prev.Next := Source.First; + Source.First.Prev := Before.Node.Prev; + + Before.Node.Prev := Source.Last; + Source.Last.Next := Before.Node; + end if; + + Source.First := null; + Source.Last := null; + + Target.Length := Target.Length + Source.Length; + Source.Length := 0; + end Splice; + + procedure Splice + (Container : in out List; + Before : Cursor; + Position : Cursor) + is + begin + if Before.Container /= null then + if Before.Container /= Container'Unchecked_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Before), "bad Before cursor in Splice"); + end if; + + if Position.Node = null then + raise Constraint_Error; + end if; + + if Position.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad Position cursor in Splice"); + + if Position.Node = Before.Node + or else Position.Node.Next = Before.Node + then + return; + end if; + + pragma Assert (Container.Length >= 2); + + if Container.Busy > 0 then + raise Program_Error; + end if; + + if Before.Node = null then + pragma Assert (Position.Node /= Container.Last); + + if Position.Node = Container.First then + Container.First := Position.Node.Next; + Container.First.Prev := null; + else + Position.Node.Prev.Next := Position.Node.Next; + Position.Node.Next.Prev := Position.Node.Prev; + end if; + + Container.Last.Next := Position.Node; + Position.Node.Prev := Container.Last; + + Container.Last := Position.Node; + Container.Last.Next := null; + + return; + end if; + + if Before.Node = Container.First then + pragma Assert (Position.Node /= Container.First); + + if Position.Node = Container.Last then + Container.Last := Position.Node.Prev; + Container.Last.Next := null; + else + Position.Node.Prev.Next := Position.Node.Next; + Position.Node.Next.Prev := Position.Node.Prev; + end if; + + Container.First.Prev := Position.Node; + Position.Node.Next := Container.First; + + Container.First := Position.Node; + Container.First.Prev := null; + + return; + end if; + + if Position.Node = Container.First then + Container.First := Position.Node.Next; + Container.First.Prev := null; + + elsif Position.Node = Container.Last then + Container.Last := Position.Node.Prev; + Container.Last.Next := null; + + else + Position.Node.Prev.Next := Position.Node.Next; + Position.Node.Next.Prev := Position.Node.Prev; + end if; + + Before.Node.Prev.Next := Position.Node; + Position.Node.Prev := Before.Node.Prev; + + Before.Node.Prev := Position.Node; + Position.Node.Next := Before.Node; + + pragma Assert (Container.First.Prev = null); + pragma Assert (Container.Last.Next = null); + end Splice; + + procedure Splice + (Target : in out List; + Before : Cursor; + Source : in out List; + Position : in out Cursor) + is + begin + if Target'Address = Source'Address then + Splice (Target, Before, Position); + return; + end if; + + if Before.Container /= null then + if Before.Container /= Target'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Before), "bad Before cursor in Splice"); + end if; + + if Position.Node = null then + raise Constraint_Error; + end if; + + if Position.Container /= Source'Unrestricted_Access then + raise Program_Error; + end if; + + pragma Assert (Vet (Position), "bad Position cursor in Splice"); + + if Target.Length = Count_Type'Last then + raise Constraint_Error; + end if; + + if Target.Busy > 0 then + raise Program_Error; + end if; + + if Source.Busy > 0 then + raise Program_Error; + end if; + + if Position.Node = Source.First then + Source.First := Position.Node.Next; + + if Position.Node = Source.Last then + pragma Assert (Source.First = null); + pragma Assert (Source.Length = 1); + Source.Last := null; + + else + Source.First.Prev := null; + end if; + + elsif Position.Node = Source.Last then + pragma Assert (Source.Length >= 2); + Source.Last := Position.Node.Prev; + Source.Last.Next := null; + + else + pragma Assert (Source.Length >= 3); + Position.Node.Prev.Next := Position.Node.Next; + Position.Node.Next.Prev := Position.Node.Prev; + end if; + + if Target.Length = 0 then + pragma Assert (Target.First = null); + pragma Assert (Target.Last = null); + pragma Assert (Before = No_Element); + + Target.First := Position.Node; + Target.Last := Position.Node; + + Target.First.Prev := null; + Target.Last.Next := null; + + elsif Before.Node = null then + pragma Assert (Target.Last.Next = null); + Target.Last.Next := Position.Node; + Position.Node.Prev := Target.Last; + + Target.Last := Position.Node; + Target.Last.Next := null; + + elsif Before.Node = Target.First then + pragma Assert (Target.First.Prev = null); + Target.First.Prev := Position.Node; + Position.Node.Next := Target.First; + + Target.First := Position.Node; + Target.First.Prev := null; + + else + pragma Assert (Target.Length >= 2); + Before.Node.Prev.Next := Position.Node; + Position.Node.Prev := Before.Node.Prev; + + Before.Node.Prev := Position.Node; + Position.Node.Next := Before.Node; + end if; + + Target.Length := Target.Length + 1; + Source.Length := Source.Length - 1; + + Position.Container := Target'Unchecked_Access; + end Splice; + + ---------- + -- Swap -- + ---------- + + procedure Swap + (Container : in out List; + I, J : Cursor) + is + begin + if I.Node = null then + raise Constraint_Error; + end if; + + if J.Node = null then + raise Constraint_Error; + end if; + + if I.Container /= Container'Unchecked_Access then + raise Program_Error; + end if; + + if J.Container /= Container'Unchecked_Access then + raise Program_Error; + end if; + + if I.Node = J.Node then + return; + end if; + + if Container.Lock > 0 then + raise Program_Error; + end if; + + pragma Assert (Vet (I), "bad I cursor in Swap"); + pragma Assert (Vet (J), "bad J cursor in Swap"); + + declare + EI : Element_Type renames I.Node.Element; + EJ : Element_Type renames J.Node.Element; + + EI_Copy : constant Element_Type := EI; + + begin + EI := EJ; + EJ := EI_Copy; + end; + end Swap; + + ---------------- + -- Swap_Links -- + ---------------- + + procedure Swap_Links + (Container : in out List; + I, J : Cursor) + is + begin + if I.Node = null then + raise Constraint_Error; + end if; + + if J.Node = null then + raise Constraint_Error; + end if; + + if I.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + if J.Container /= Container'Unrestricted_Access then + raise Program_Error; + end if; + + if I.Node = J.Node then + return; + end if; + + if Container.Busy > 0 then + raise Program_Error; + end if; + + pragma Assert (Vet (I), "bad I cursor in Swap_Links"); + pragma Assert (Vet (J), "bad J cursor in Swap_Links"); + + declare + I_Next : constant Cursor := Next (I); + + begin + if I_Next = J then + Splice (Container, Before => I, Position => J); + + else + declare + J_Next : constant Cursor := Next (J); + + begin + if J_Next = I then + Splice (Container, Before => J, Position => I); + + else + pragma Assert (Container.Length >= 3); + + Splice (Container, Before => I_Next, Position => J); + Splice (Container, Before => J_Next, Position => I); + end if; + end; + end if; + end; + end Swap_Links; + + --------- + -- Vet -- + --------- + + function Vet (Position : Cursor) return Boolean is + begin + if Position.Node = null then + return Position.Container = null; + end if; + + if Position.Container = null then + return False; + end if; + + if Position.Node.Next = Position.Node then + return False; + end if; + + if Position.Node.Prev = Position.Node then + return False; + end if; + + declare + L : List renames Position.Container.all; + begin + if L.Length = 0 then + return False; + end if; + + if L.First = null then + return False; + end if; + + if L.Last = null then + return False; + end if; + + if L.First.Prev /= null then + return False; + end if; + + if L.Last.Next /= null then + return False; + end if; + + if Position.Node.Prev = null + and then Position.Node /= L.First + then + return False; + end if; + + if Position.Node.Next = null + and then Position.Node /= L.Last + then + return False; + end if; + + if L.Length = 1 then + return L.First = L.Last; + end if; + + if L.First = L.Last then + return False; + end if; + + if L.First.Next = null then + return False; + end if; + + if L.Last.Prev = null then + return False; + end if; + + if L.First.Next.Prev /= L.First then + return False; + end if; + + if L.Last.Prev.Next /= L.Last then + return False; + end if; + + if L.Length = 2 then + if L.First.Next /= L.Last then + return False; + end if; + + if L.Last.Prev /= L.First then + return False; + end if; + + return True; + end if; + + if L.First.Next = L.Last then + return False; + end if; + + if L.Last.Prev = L.First then + return False; + end if; + + if Position.Node = L.First then + return True; + end if; + + if Position.Node = L.Last then + return True; + end if; + + if Position.Node.Next = null then + return False; + end if; + + if Position.Node.Prev = null then + return False; + end if; + + if Position.Node.Next.Prev /= Position.Node then + return False; + end if; + + if Position.Node.Prev.Next /= Position.Node then + return False; + end if; + + if L.Length = 3 then + if L.First.Next /= Position.Node then + return False; + end if; + + if L.Last.Prev /= Position.Node then + return False; + end if; + end if; + + return True; + end; + end Vet; + +end Ada_Containers.AUnit_Lists; diff --git a/ada/libaunit-3.7.2/include/aunit/containers/ada_containers-aunit_lists.ads b/ada/libaunit-3.7.2/include/aunit/containers/ada_containers-aunit_lists.ads new file mode 100644 index 000000000..fee331990 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/containers/ada_containers-aunit_lists.ads @@ -0,0 +1,243 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT LIBRARY COMPONENTS -- +-- -- +-- A D A _ C O N T A I N E R S . A U N I T _ L I S T S -- +-- -- +-- S p e c -- +-- -- +-- Copyright (C) 2004-2008, Free Software Foundation, Inc. -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- This specification is derived from the Ada Reference Manual for use with -- +-- GNAT. The copyright notice above, and the license provisions that follow -- +-- apply solely to the contents of the part following the private keyword. -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- This unit was originally developed by Matthew J Heaney. -- +------------------------------------------------------------------------------ + +-- This unit is an adaptation of the Ada2005 runtime's +-- Ada.Containers.Doubly_Linked_Lists with modifications to make this package +-- compatible with the ZFP profiles and also compatible with AUnit's memory +-- management. + +-- Some Ada2005 constructs have also been removed so that user tests can be +-- compiled in Ada95. + +generic + type Element_Type is private; + + with function "=" (Left, Right : Element_Type) + return Boolean is <>; + +package Ada_Containers.AUnit_Lists is + + type List is tagged limited private; + + type Cursor is private; + +-- Empty_List : constant List; + + No_Element : constant Cursor; + + function "=" (Left, Right : List) return Boolean; + + function Length (Container : List) return Count_Type; + + function Is_Empty (Container : List) return Boolean; + + procedure Clear (Container : in out List); + + function Element (Position : Cursor) return Element_Type; + + procedure Replace_Element + (Container : in out List; + Position : Cursor; + New_Item : Element_Type); + +-- procedure Query_Element +-- (Position : Cursor; +-- Process : not null access procedure (Element : Element_Type)); + +-- procedure Update_Element +-- (Container : in out List; +-- Position : Cursor; +-- Process : not null access procedure (Element : in out Element_Type)); + + procedure Move + (Target : in out List; + Source : in out List); + + procedure Insert + (Container : in out List; + Before : Cursor; + New_Item : Element_Type; + Count : Count_Type := 1); + + procedure Insert + (Container : in out List; + Before : Cursor; + New_Item : Element_Type; + Position : out Cursor; + Count : Count_Type := 1); + + procedure Insert + (Container : in out List; + Before : Cursor; + Position : out Cursor; + Count : Count_Type := 1); + + procedure Prepend + (Container : in out List; + New_Item : Element_Type; + Count : Count_Type := 1); + + procedure Append + (Container : in out List; + New_Item : Element_Type; + Count : Count_Type := 1); + + procedure Delete + (Container : in out List; + Position : in out Cursor; + Count : Count_Type := 1); + + procedure Delete_First + (Container : in out List; + Count : Count_Type := 1); + + procedure Delete_Last + (Container : in out List; + Count : Count_Type := 1); + + procedure Reverse_Elements (Container : in out List); + + procedure Swap + (Container : in out List; + I, J : Cursor); + + procedure Swap_Links + (Container : in out List; + I, J : Cursor); + + procedure Splice + (Target : in out List; + Before : Cursor; + Source : in out List); + + procedure Splice + (Target : in out List; + Before : Cursor; + Source : in out List; + Position : in out Cursor); + + procedure Splice + (Container : in out List; + Before : Cursor; + Position : Cursor); + + function First (Container : List) return Cursor; + + function First_Element (Container : List) return Element_Type; + + function Last (Container : List) return Cursor; + + function Last_Element (Container : List) return Element_Type; + + function Next (Position : Cursor) return Cursor; + + procedure Next (Position : in out Cursor); + + function Previous (Position : Cursor) return Cursor; + + procedure Previous (Position : in out Cursor); + + function Find + (Container : List; + Item : Element_Type; + Position : Cursor := No_Element) return Cursor; + + function Reverse_Find + (Container : List; + Item : Element_Type; + Position : Cursor := No_Element) return Cursor; + + function Contains + (Container : List; + Item : Element_Type) return Boolean; + + function Has_Element (Position : Cursor) return Boolean; + + type Iterator is access procedure (Position : Cursor); + + procedure Iterate + (Container : List; + Process : Iterator); + +-- procedure Reverse_Iterate +-- (Container : List; +-- Process : not null access procedure (Position : Cursor)); + + generic + with function "<" (Left, Right : Element_Type) return Boolean is <>; + package Generic_Sorting is + + function Is_Sorted (Container : List) return Boolean; + + procedure Sort (Container : in out List); + + procedure Merge (Target, Source : in out List); + + end Generic_Sorting; + +private + + pragma Inline (Next); + pragma Inline (Previous); + + type Node_Type; + type Node_Access is access Node_Type; + pragma No_Strict_Aliasing (Node_Access); + + type Node_Type is limited record + Element : Element_Type; + Next : Node_Access; + Prev : Node_Access; + end record; + + type List is tagged limited record + First : Node_Access := null; + Last : Node_Access := null; + Length : Count_Type := 0; + Busy : Natural := 0; + Lock : Natural := 0; + end record; + + type List_Access is access constant List; + + type Cursor is record + Container : List_Access; + Node : Node_Access; + end record; + + -- Empty_List : constant List := (Controlled with null, null, 0, 0, 0); + + No_Element : constant Cursor := (null, null); + +end Ada_Containers.AUnit_Lists; diff --git a/ada/libaunit-3.7.2/include/aunit/containers/ada_containers.ads b/ada/libaunit-3.7.2/include/aunit/containers/ada_containers.ads new file mode 100644 index 000000000..e9a284851 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/containers/ada_containers.ads @@ -0,0 +1,22 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT LIBRARY COMPONENTS -- +-- -- +-- A D A . C O N T A I N E R S -- +-- -- +-- S p e c -- +-- -- +-- This specification is adapted from the Ada Reference Manual for use with -- +-- GNAT. In accordance with the copyright of that document, you can freely -- +-- copy and modify this specification, provided that if you redistribute a -- +-- modified version, any changes that you have made are clearly indicated. -- +-- -- +------------------------------------------------------------------------------ + +package Ada_Containers is + pragma Pure; + + type Hash_Type is mod 2**32; + type Count_Type is range 0 .. 2**31 - 1; + +end Ada_Containers; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-assertions.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit-assertions.adb new file mode 100644 index 000000000..287d504d1 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-assertions.adb @@ -0,0 +1,226 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . A S S E R T I O N S -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +package body AUnit.Assertions is + + Failures : Failure_Lists.List; + -- ??? Calls to Failures should be protected, so that we can use + -- multitasking + + Current_Id : Test_Id := 1; + + procedure Init_Test (T : in out Test) is + begin + if T.Id = Null_Id then + T.Id := Current_Id; + Current_Id := Current_Id + 1; + end if; + end Init_Test; + + The_Current_Test : Test_Access := null; + + ------------ + -- Assert -- + ------------ + + procedure Assert + (Condition : Boolean; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line) is + begin + if not Assert (Condition, Message, Source, Line) then + raise Assertion_Error; + end if; + end Assert; + + ------------ + -- Assert -- + ------------ + + function Assert + (Condition : Boolean; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line) return Boolean is + begin + if not Condition then + Failure_Lists.Append + (Failures, + (Failure => (Format (Message), Format (Source), Line), + Id => The_Current_Test.Id)); + end if; + + return Condition; + end Assert; + + ---------------------- + -- Assert_Exception -- + ---------------------- + + procedure Assert_Exception + (Proc : Throwing_Exception_Proc; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line) is separate; + + ------------ + -- Assert -- + ------------ + + procedure Assert + (Actual : String; + Expected : String; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line) is + begin + if Actual /= Expected then + Assert + (False, + Message & " - got '" & Actual & "', expecting '" & Expected & "'", + Source, + Line); + end if; + end Assert; + + -------------------- + -- Clear_Failures -- + -------------------- + + procedure Clear_Failures (T : Test) is + C, N : Failure_Lists.Cursor; + begin + C := Failure_Lists.First (Failures); + + while Failure_Lists.Has_Element (C) loop + N := Failure_Lists.Next (C); + + if Failure_Lists.Element (C).Id = T.Id then + Failure_Lists.Delete (Failures, C); + end if; + + C := N; + end loop; + end Clear_Failures; + + ------------------ + -- Has_Failures -- + ------------------ + + function Has_Failures (T : Test) return Boolean is + begin + return Has_Failure (First_Failure (T)); + end Has_Failures; + + ------------------- + -- First_Failure -- + ------------------- + + function First_Failure (T : Test) return Failure_Iter is + C : Failure_Lists.Cursor; + begin + C := Failure_Lists.First (Failures); + + while Failure_Lists.Has_Element (C) loop + if Failure_Lists.Element (C).Id = T.Id then + return Failure_Iter (C); + end if; + + Failure_Lists.Next (C); + end loop; + + return Failure_Iter (Failure_Lists.No_Element); + end First_Failure; + + ----------------- + -- Has_Failure -- + ----------------- + + function Has_Failure (I : Failure_Iter) return Boolean is + begin + return Failure_Lists.Has_Element (Failure_Lists.Cursor (I)); + end Has_Failure; + + function Get_Failure + (I : Failure_Iter) return AUnit.Test_Results.Test_Failure is + begin + return Failure_Lists.Element (Failure_Lists.Cursor (I)).Failure; + end Get_Failure; + + ---------- + -- Next -- + ---------- + + procedure Next (I : in out Failure_Iter) is + Id : Test_Id; + begin + if not Has_Failure (I) then + return; + end if; + + Id := Failure_Lists.Element (Failure_Lists.Cursor (I)).Id; + Failure_Lists.Next (Failure_Lists.Cursor (I)); + + while Failure_Lists.Has_Element (Failure_Lists.Cursor (I)) loop + exit when Failure_Lists.Element (Failure_Lists.Cursor (I)).Id = Id; + Failure_Lists.Next (Failure_Lists.Cursor (I)); + end loop; + end Next; + + ------------------ + -- Current_Test -- + ------------------ + + function Current_Test return Test_Access is + begin + return The_Current_Test; + end Current_Test; + + ---------------------- + -- Set_Current_Test -- + ---------------------- + + procedure Set_Current_Test (T : Test_Access) is + begin + The_Current_Test := T; + end Set_Current_Test; + + ------------- + -- Copy_Id -- + ------------- + + procedure Copy_Id (From : Test'Class; To : in out Test'Class) is + begin + To.Id := From.Id; + end Copy_Id; + +end AUnit.Assertions; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-assertions.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-assertions.ads new file mode 100644 index 000000000..6809a2f3b --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-assertions.ads @@ -0,0 +1,155 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . A S S E R T I O N S -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- +-- This package provides the Assert methods used by the user to verify test +-- results. +-- Those methods are used to report errors within AUnit tests when a result +-- does not match an expected value. +-- + +with GNAT.Source_Info; +with AUnit.Tests; +with AUnit.Test_Results; +with Ada_Containers.AUnit_Lists; + +package AUnit.Assertions is + + type Throwing_Exception_Proc is access procedure; + + procedure Assert + (Condition : Boolean; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line); + -- Test "Condition" and record "Message" if false. + -- If the condition is false, an exception is then raised and the running + -- test is aborted. + + function Assert + (Condition : Boolean; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line) return Boolean; + -- Functional version to allow the calling routine to decide whether to + -- continue or abandon the execution. + + ----------------------- + -- Simple assertions -- + ----------------------- + -- The following subprograms provide specialized version of Assert + -- to compare simple types. In case of failure, the error message will + -- contain both the expected and actual values. + + procedure Assert + (Actual : String; + Expected : String; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line); + -- Specialized versions of Assert, they call the general version that + -- takes a Condition as a parameter + + procedure Assert_Exception + (Proc : Throwing_Exception_Proc; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line); + -- Test that Proc throws an exception and record "Message" if not. + + ------------------------------------------------------------ + -- The following declarations are for internal use only -- + ------------------------------------------------------------ + + Assertion_Error : exception; + -- For run-time libraries that support exception handling, raised when an + -- assertion fails in order to abandon execution of a test routine. + + type Test is abstract new AUnit.Tests.Test with private; + -- Test is used as root type for all Test cases, but also for Test fixtures + -- This allows easy access to all Assert procedures from user tests. + type Test_Access is access all Test'Class; + + procedure Init_Test (T : in out Test); + -- Init a new test + + procedure Clear_Failures (T : Test); + -- Clear all failures related to T + + function Has_Failures (T : Test) return Boolean; + -- The number of failures reported by test + + type Failure_Iter is private; + -- Iterator used to retrieve failures. + + function First_Failure (T : Test) return Failure_Iter; + function Has_Failure (I : Failure_Iter) return Boolean; + function Get_Failure + (I : Failure_Iter) return AUnit.Test_Results.Test_Failure; + procedure Next (I : in out Failure_Iter); + -- Failures list handling + + -- The following is used for the non-dispatching Assert methods. + -- This uses global variables, and thus is incompatible with multitasking. + function Current_Test return Test_Access; + procedure Set_Current_Test (T : Test_Access); + + procedure Copy_Id (From : Test'Class; To : in out Test'Class); + -- Copy From's Id to To so that failures reported via To are identified as + -- belonging to From. + +private + use AUnit.Test_Results; + + -- We can't set the results directly within the test as the result list is + -- limited and we don't want Test to be limited. + -- Instead, we initialize tests with a unique id that we use when putting + -- a new error in this global list. + + type Test_Id is new Natural; + Null_Id : constant Test_Id := 0; + + type Failure_Elt is record + Failure : Test_Failure; + Id : Test_Id := Null_Id; + end record; + + package Failure_Lists is + new Ada_Containers.AUnit_Lists (Failure_Elt); + -- Container for failed assertion messages per routine + + type Failure_Iter is new Failure_Lists.Cursor; + + type Test is abstract new AUnit.Tests.Test with record + Id : Test_Id := Null_Id; + end record; + +end AUnit.Assertions; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-environments.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-environments.ads new file mode 100644 index 000000000..487c1088d --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-environments.ads @@ -0,0 +1,40 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . E N V I R O N M E N T S -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2017, Victor Porton -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Test Suite Framework + +package AUnit.Environments is + + type Environment is tagged null record; + + type Environment_Access is access all Environment'Class; + +end AUnit.Environments; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-memory-utils.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-memory-utils.ads new file mode 100644 index 000000000..39da06d8e --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-memory-utils.ads @@ -0,0 +1,42 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . M E M O R Y . U T I L S -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Provides Gen_Alloc, easing the allocation of objects within AUnit. + +package AUnit.Memory.Utils is + + generic + type Object is limited private; + type Name is access Object; + pragma No_Strict_Aliasing (Name); + function Gen_Alloc return Name; + +end AUnit.Memory.Utils; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-memory.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-memory.ads new file mode 100644 index 000000000..9bdf11216 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-memory.ads @@ -0,0 +1,53 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . M E M O R Y -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Provides the memory handling mechanism used by AUnit. This allows in +-- particular AUnit to use dynamic allocation even on limited run-times that +-- do not provide memory management. +-- See also AUnit.Memory.Utils that provides an easy to use allocator for +-- complex objects. + +with System; + +package AUnit.Memory is + + type size_t is mod 2 ** Standard'Address_Size; + + function AUnit_Alloc (Size : size_t) return System.Address; + + procedure AUnit_Free (Obj : System.Address); + +private + + pragma Inline (AUnit_Alloc); + pragma Inline (AUnit_Free); + +end AUnit.Memory; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-options.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-options.ads new file mode 100644 index 000000000..061d03b51 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-options.ads @@ -0,0 +1,50 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . O P T I O N S -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2009-2013, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with AUnit.Test_Filters; + +package AUnit.Options is + + type AUnit_Options is record + Global_Timer : Boolean := False; + Test_Case_Timer : Boolean := False; + Report_Successes : Boolean := True; + Filter : AUnit.Test_Filters.Test_Filter_Access := null; + end record; + -- Options used to determine how a test should be run. + + Default_Options : constant AUnit_Options := + (Global_Timer => False, + Test_Case_Timer => False, + Report_Successes => True, + Filter => null); + +end AUnit.Options; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-reporter.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-reporter.ads new file mode 100644 index 000000000..6809b8c03 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-reporter.ads @@ -0,0 +1,46 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . R E P O R T E R -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2008-2013, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with AUnit.Options; use AUnit.Options; +with AUnit.Test_Results; use AUnit.Test_Results; + +package AUnit.Reporter is + + type Reporter is abstract tagged null record; + + procedure Report + (Engine : Reporter; + R : in out Result'Class; + Options : AUnit_Options := Default_Options) is abstract; + -- This procedure is called by AUnit.Run to report the result after running + -- the whole testsuite (or the selected subset of tests). + +end AUnit.Reporter; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-run.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit-run.adb new file mode 100644 index 000000000..0936cb88b --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-run.adb @@ -0,0 +1,123 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . R U N -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2006-2013, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with AUnit.Time_Measure; +with AUnit.Test_Suites; use AUnit.Test_Suites; + +package body AUnit.Run is + + procedure Run + (Suite : Access_Test_Suite; + Results : in out Test_Results.Result'Class; + Options : AUnit.Options.AUnit_Options; + Reporter : AUnit.Reporter.Reporter'Class; + Outcome : out Status); + -- Run a specific testsuite and return its status + + --------- + -- Run -- + --------- + + procedure Run + (Suite : Access_Test_Suite; + Results : in out Test_Results.Result'Class; + Options : AUnit.Options.AUnit_Options; + Reporter : AUnit.Reporter.Reporter'Class; + Outcome : out Status) + is + Time : Time_Measure.Time; + + begin + if Options.Global_Timer then + Time_Measure.Start_Measure (Time); + end if; + + pragma Warnings (Off); + AUnit.Test_Suites.Run (Suite, Options, Results, Outcome); + pragma Warnings (On); + + if Options.Global_Timer then + Time_Measure.Stop_Measure (Time); + Test_Results.Set_Elapsed (Results, Time); + end if; + + AUnit.Reporter.Report (Reporter, Results, Options); + end Run; + + ----------------- + -- Test_Runner -- + ----------------- + + procedure Test_Runner + (Reporter : AUnit.Reporter.Reporter'Class; + Options : AUnit.Options.AUnit_Options := AUnit.Options.Default_Options) + is + Results : Test_Results.Result; + Outcome : Status; + pragma Unreferenced (Outcome); + begin + Test_Results.Clear (Results); + Run (Suite, Results, Options, Reporter, Outcome); + end Test_Runner; + + ----------------------------- + -- Test_Runner_With_Status -- + ----------------------------- + + function Test_Runner_With_Status + (Reporter : AUnit.Reporter.Reporter'Class; + Options : AUnit.Options.AUnit_Options := AUnit.Options.Default_Options) + return Status + is + Results : Test_Results.Result; + Outcome : Status; + begin + Test_Results.Clear (Results); + Run (Suite, Results, Options, Reporter, Outcome); + return Outcome; + end Test_Runner_With_Status; + + ------------------------------ + -- Test_Runner_With_Results -- + ------------------------------ + + procedure Test_Runner_With_Results + (Reporter : AUnit.Reporter.Reporter'Class; + Results : in out AUnit.Test_Results.Result'Class; + Options : AUnit.Options.AUnit_Options := AUnit.Options.Default_Options) + is + Outcome : Status; + pragma Unreferenced (Outcome); + begin + Run (Suite, Results, Options, Reporter, Outcome); + end Test_Runner_With_Results; + +end AUnit.Run; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-run.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-run.ads new file mode 100644 index 000000000..7b799d9b3 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-run.ads @@ -0,0 +1,65 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . R U N -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2006-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with AUnit.Options; +with AUnit.Reporter; +with AUnit.Test_Results; +with AUnit.Test_Suites; + +-- Framework using text reporter +package AUnit.Run is + + generic + with function Suite return AUnit.Test_Suites.Access_Test_Suite; + procedure Test_Runner + (Reporter : AUnit.Reporter.Reporter'Class; + Options : AUnit.Options.AUnit_Options := AUnit.Options.Default_Options); + + generic + with function Suite return AUnit.Test_Suites.Access_Test_Suite; + procedure Test_Runner_With_Results + (Reporter : AUnit.Reporter.Reporter'Class; + Results : in out AUnit.Test_Results.Result'Class; + Options : AUnit.Options.AUnit_Options := AUnit.Options.Default_Options); + -- In this version, you can pass your own Result class. In particular, this + -- can be used to extend the Result type so that for instance you can + -- output information every time a test passed or fails. + -- Results is not cleared before running the tests, this is your + -- responsibility, so that you can for instance cumulate results as needed. + + generic + with function Suite return AUnit.Test_Suites.Access_Test_Suite; + function Test_Runner_With_Status + (Reporter : AUnit.Reporter.Reporter'Class; + Options : AUnit.Options.AUnit_Options := AUnit.Options.Default_Options) + return Status; + +end AUnit.Run; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-simple_test_cases.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit-simple_test_cases.adb new file mode 100644 index 000000000..343ac6898 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-simple_test_cases.adb @@ -0,0 +1,113 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . S I M P L E _ T E S T _ C A S E S -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2008-2012, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with AUnit.Assertions; use AUnit.Assertions; +with AUnit.Options; use AUnit.Options; +with AUnit.Test_Filters; use AUnit.Test_Filters; + +package body AUnit.Simple_Test_Cases is + + procedure Run_Routine + (Test : access Test_Case'Class; + Options : AUnit_Options; + R : in out Result'Class; + Outcome : out Status); + -- Run one test routine + + ----------------- + -- Run_Routine -- + ----------------- + + procedure Run_Routine + (Test : access Test_Case'Class; + Options : AUnit_Options; + R : in out Result'Class; + Outcome : out Status) is separate; + + ------------------ + -- Routine_Name -- + ------------------ + + function Routine_Name (Test : Test_Case) return Message_String is + pragma Unreferenced (Test); + begin + return null; + end Routine_Name; + + ------------ + -- Set_Up -- + ------------ + + procedure Set_Up (Test : in out Test_Case) is + pragma Unreferenced (Test); + begin + null; + end Set_Up; + + --------------- + -- Tear_Down -- + --------------- + + procedure Tear_Down (Test : in out Test_Case) is + pragma Unreferenced (Test); + begin + null; + end Tear_Down; + + --------- + -- Run -- + --------- + + procedure Run + (Test : access Test_Case; + Options : AUnit_Options; + R : in out Result'Class; + Outcome : out Status) + is + Old : constant Test_Access := AUnit.Assertions.Current_Test; + begin + Outcome := Success; + if Options.Filter = null + or else Is_Active (Options.Filter.all, Test.all) + then + AUnit.Assertions.Set_Current_Test (Test_Access (Test)); + Init_Test (Test.all); + Start_Test (R, 1); + + -- Run test routine + Set_Up (Test_Case'Class (Test.all)); + Run_Routine (Test, Options, R, Outcome); + Tear_Down (Test_Case'Class (Test.all)); + AUnit.Assertions.Set_Current_Test (Old); + end if; + end Run; + +end AUnit.Simple_Test_Cases; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-simple_test_cases.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-simple_test_cases.ads new file mode 100644 index 000000000..8fa7655a7 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-simple_test_cases.ads @@ -0,0 +1,77 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . S I M P L E _ T E S T _ C A S E S -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- This type is used to implement a simple test case: define a derived type +-- that overrides the Run_Test and Name methods. +-- +-- You don't usually need to use that type, but Test_Fixture/Test_Caller +-- or Test_Case instead. + +with AUnit.Assertions; +with AUnit.Options; +with AUnit.Test_Results; use AUnit.Test_Results; + +package AUnit.Simple_Test_Cases is + + type Test_Case is abstract new AUnit.Assertions.Test with private; + type Test_Case_Access is access all Test_Case'Class; + + function Name (Test : Test_Case) return Message_String is abstract; + -- Test case name + + function Routine_Name (Test : Test_Case) return Message_String; + -- Routine name. By default return a null Message_String + + procedure Run_Test + (Test : in out Test_Case) is abstract; + -- Perform the test. + + procedure Set_Up (Test : in out Test_Case); + -- Set up performed before each test + + procedure Tear_Down (Test : in out Test_Case); + -- Tear down performed after each test + + ---------------------------------------------- + -- Below are internal routines. Do not use -- + ---------------------------------------------- + + procedure Run (Test : access Test_Case; + Options : AUnit.Options.AUnit_Options; + R : in out Result'Class; + Outcome : out Status); + -- Run test case. Do not override + +private + + type Test_Case is abstract new AUnit.Assertions.Test with null record; + +end AUnit.Simple_Test_Cases; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_caller.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_caller.adb new file mode 100644 index 000000000..cca16bdd7 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_caller.adb @@ -0,0 +1,117 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ C A L L E R -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Unchecked_Conversion; +with AUnit.Assertions; +with AUnit.Memory.Utils; + +package body AUnit.Test_Caller is + + function New_Fixture is new AUnit.Memory.Utils.Gen_Alloc + (Test_Fixture, Fixture_Access); + + The_Fixture_Object : constant Fixture_Access := New_Fixture; + + ------------ + -- Create -- + ------------ + + procedure Create + (TC : out Test_Case'Class; + Name : String; + Test : Test_Method) + is + begin + TC.Name := Format (Name); + TC.Method := Test; + TC.Fixture := The_Fixture_Object; + end Create; + + ------------ + -- Create -- + ------------ + + function Create + (Name : String; + Test : Test_Method) return Test_Case_Access + is + type Access_Type is access all Test_Case; + function Alloc is new AUnit.Memory.Utils.Gen_Alloc + (Test_Case, Access_Type); + function Convert is new Ada.Unchecked_Conversion + (Access_Type, Test_Case_Access); + Ret : constant Test_Case_Access := Convert (Alloc); + begin + Create (Ret.all, Name, Test); + return Ret; + end Create; + + ---------- + -- Name -- + ---------- + + function Name (Test : Test_Case) return Message_String is + begin + return Test.Name; + end Name; + + -------------- + -- Run_Test -- + -------------- + + procedure Run_Test (Test : in out Test_Case) is + begin + -- Before running the fixture's method, we need to make sure that + -- the test Ids correspond so that a failure reported via Fixture is + -- correctly understood as being part of Test. + AUnit.Assertions.Copy_Id (Test, Test.Fixture.all); + Test.Method (Test_Fixture (Test.Fixture.all)); + end Run_Test; + + ------------ + -- Set_Up -- + ------------ + + procedure Set_Up (Test : in out Test_Case) is + begin + Set_Up (Test.Fixture.all); + end Set_Up; + + --------------- + -- Tear_Down -- + --------------- + + procedure Tear_Down (Test : in out Test_Case) is + begin + Tear_Down (Test.Fixture.all); + end Tear_Down; + +end AUnit.Test_Caller; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_caller.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_caller.ads new file mode 100644 index 000000000..71dd35361 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_caller.ads @@ -0,0 +1,121 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ C A L L E R -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- +-- A Test caller provides access to a test case type based on a test fixture. +-- Test callers are useful when you want to run individual test or add it to +-- a suite. +-- Test callers invoke only one Test (i.e. test method) on one Fixture of a +-- AUnit.Test_Fixtures.Test_Fixture. +-- +-- Here is an example: +-- +-- +-- package Math_Test is +-- Type Test is new AUnit.Test_Fixtures.Test_Fixture with record +-- M_Value1 : Integer; +-- M_Value2 : Integer; +-- end record; +-- +-- procedure Set_Up (T : in out Test); +-- +-- procedure Test_Addition (T : in out Test); +-- procedure Test_Subtraction (T : in out Test); +-- +-- end Math_Test; +-- +-- function Suite return AUnit.Test_Suites.Test_Suite_Access is +-- package Caller is new AUnit.Test_Caller (Math_Test.Test); +-- The_Suite : AUnit.Test_Suites.Test_Suite_Access := +-- new AUnit.Test_Suites.Test_Suite; +-- begin +-- The_Suite.Add_Test +-- (Caller.Create ("Test Addition on integers", +-- Math_Test.Test_Addition'Access)); +-- The_Suite.Add_Test +-- (Caller.Create ("Test Subtraction on integers", +-- Math_Test.Test_Subtraction'Access)); +-- return The_Suite; +-- end Suite; +-- +-- + +with AUnit.Simple_Test_Cases; +with AUnit.Test_Fixtures; + +generic + + type Test_Fixture is new AUnit.Test_Fixtures.Test_Fixture with private; + +package AUnit.Test_Caller is + + type Test_Case is new AUnit.Simple_Test_Cases.Test_Case with private; + type Test_Case_Access is access all Test_Case'Class; + + type Test_Method is access procedure (Test : in out Test_Fixture); + + function Create + (Name : String; + Test : Test_Method) return Test_Case_Access; + -- Return a test case from a test fixture method, reporting the result + -- of the test using the Name parameter. + + procedure Create + (TC : out Test_Case'Class; + Name : String; + Test : Test_Method); + -- Initialize a test case from a test fixture method, reporting the result + -- of the test using the Name parameter. + + function Name (Test : Test_Case) return Message_String; + -- Test case name + + procedure Run_Test (Test : in out Test_Case); + -- Perform the test. + + procedure Set_Up (Test : in out Test_Case); + -- Set up performed before each test case + + procedure Tear_Down (Test : in out Test_Case); + -- Tear down performed after each test case + +private + + type Fixture_Access is access all Test_Fixture; + pragma No_Strict_Aliasing (Fixture_Access); + + type Test_Case is new AUnit.Simple_Test_Cases.Test_Case with record + Fixture : Fixture_Access; + Name : Message_String; + Method : Test_Method; + end record; + +end AUnit.Test_Caller; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_cases-registration.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_cases-registration.adb new file mode 100644 index 000000000..4cc526177 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_cases-registration.adb @@ -0,0 +1,64 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ C A S E S . R E G I S T R A T I O N -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Test routine registration + +separate (AUnit.Test_Cases) +package body Registration is + + ---------------------- + -- Register_Routine -- + ---------------------- + + procedure Register_Routine + (Test : in out Test_Case'Class; + Routine : Test_Routine; + Name : String) is + + Formatted_Name : constant Message_String := Format (Name); + Val : Routine_Spec; + use Routine_Lists; + + begin + Val := (Routine, Formatted_Name); + Add_Routine (Test, Val); + end Register_Routine; + + ------------------- + -- Routine_Count -- + ------------------- + + function Routine_Count (Test : Test_Case'Class) return Count_Type is + begin + return Routine_Lists.Length (Test.Routines); + end Routine_Count; + +end Registration; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_cases.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_cases.adb new file mode 100644 index 000000000..5f971872e --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_cases.adb @@ -0,0 +1,151 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ C A S E S -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Unchecked_Conversion; +with AUnit.Options; use AUnit.Options; +with AUnit.Test_Filters; use AUnit.Test_Filters; + +package body AUnit.Test_Cases is + + package body Registration is separate; + + ----------------- + -- Add_Routine -- + ----------------- + + procedure Add_Routine (T : in out Test_Case'Class; Val : Routine_Spec) is + begin + Routine_Lists.Append (T.Routines, Val); + end Add_Routine; + + -------------- + -- Run_Test -- + -------------- + + procedure Run_Test (Test : in out Test_Case) is + begin + Test.Routine.Routine (Test); + end Run_Test; + + --------- + -- Run -- + --------- + + procedure Run + (Test : access Test_Case; + Options : AUnit.Options.AUnit_Options; + R : in out Result'Class; + Outcome : out Status) + is + use Routine_Lists; + Result : Status; + C : Cursor; + begin + Outcome := Success; + Routine_Lists.Clear (Test.Routines); + Register_Tests (Test_Case'Class (Test.all)); + + Set_Up_Case (Test_Case'Class (Test.all)); + C := First (Test.Routines); + + while Has_Element (C) loop + Test.Routine := Element (C); + if Options.Filter = null + or else Is_Active (Options.Filter.all, Test.all) + then + AUnit.Simple_Test_Cases.Run + (AUnit.Simple_Test_Cases.Test_Case (Test.all)'Access, + Options, R, Result); + + if Result = Failure then + Outcome := Failure; + end if; + end if; + + Next (C); + end loop; + + Tear_Down_Case (Test_Case'Class (Test.all)); + end Run; + + ------------------ + -- Routine_Name -- + ------------------ + + function Routine_Name (Test : Test_Case) return Message_String is + begin + return Test.Routine.Routine_Name; + end Routine_Name; + + ------------------ + -- Set_Up_Case -- + ------------------ + + procedure Set_Up_Case (Test : in out Test_Case) is + -- Default + pragma Unreferenced (Test); + begin + null; + end Set_Up_Case; + + -------------------- + -- Tear_Down_Case -- + -------------------- + + procedure Tear_Down_Case (Test : in out Test_Case) is + pragma Unreferenced (Test); + begin + null; + end Tear_Down_Case; + + package body Specific_Test_Case_Registration is + + ---------------------- + -- Register_Wrapper -- + ---------------------- + + procedure Register_Wrapper + (Test : in out Specific_Test_Case'Class; + Routine : Specific_Test_Routine; + Name : String) + is + function Conv is + new Ada.Unchecked_Conversion (Specific_Test_Routine, Test_Routine); + begin + Registration.Register_Routine + (Test_Case'Class (Test), + Conv (Routine), + Name); + end Register_Wrapper; + + end Specific_Test_Case_Registration; + +end AUnit.Test_Cases; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_cases.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_cases.ads new file mode 100644 index 000000000..849a0e4a9 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_cases.ads @@ -0,0 +1,121 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ C A S E S -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with Ada_Containers; use Ada_Containers; +with Ada_Containers.AUnit_Lists; +with AUnit.Options; +with AUnit.Simple_Test_Cases; +with AUnit.Test_Results; use AUnit.Test_Results; + +-- Test case: a collection of test routines +package AUnit.Test_Cases is + + type Test_Case is abstract new AUnit.Simple_Test_Cases.Test_Case with + private; + type Test_Case_Access is access all Test_Case'Class; + + type Test_Routine is access procedure (Test : in out Test_Case'Class); + + type Routine_Spec is record + Routine : Test_Routine; + Routine_Name : Message_String; + end record; + + procedure Add_Routine (T : in out Test_Case'Class; Val : Routine_Spec); + + procedure Register_Tests (Test : in out Test_Case) is abstract; + -- Register test methods with test suite + + procedure Set_Up_Case (Test : in out Test_Case); + -- Set up performed before each test case (set of test routines) + + procedure Tear_Down_Case (Test : in out Test_Case); + -- Tear down performed after each test case + + package Registration is + + procedure Register_Routine + (Test : in out Test_Case'Class; + Routine : Test_Routine; + Name : String); + -- Add test routine to test case + + function Routine_Count (Test : Test_Case'Class) return Count_Type; + -- Count of registered routines in test case + + end Registration; + + generic + type Specific_Test_Case is abstract new Test_Case with private; + package Specific_Test_Case_Registration is + -- Specific Test Case registration + + type Specific_Test_Routine is access procedure + (Test : in out Specific_Test_Case'Class); + + procedure Register_Wrapper + (Test : in out Specific_Test_Case'Class; + Routine : Specific_Test_Routine; + Name : String); + -- Add test routine for a specific test case + end Specific_Test_Case_Registration; + + procedure Run + (Test : access Test_Case; + Options : AUnit.Options.AUnit_Options; + R : in out Result'Class; + Outcome : out Status); + -- Run test case. Do not override. + + procedure Run_Test (Test : in out Test_Case); + -- Perform the current test procedure. Do not override. + + function Routine_Name (Test : Test_Case) return Message_String; + -- Routine name. Returns the routine under test. Do not override. + +private + + type Routine_Access is access all Routine_Spec; + -- Test routine description + + package Routine_Lists is new Ada_Containers.AUnit_Lists (Routine_Spec); + -- Container for test routines + + package Failure_Lists is + new Ada_Containers.AUnit_Lists (Message_String); + -- Container for failed assertion messages per routine + + type Test_Case is abstract new AUnit.Simple_Test_Cases.Test_Case with record + Routines : aliased Routine_Lists.List; + Routine : Routine_Spec; + end record; + +end AUnit.Test_Cases; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_filters.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_filters.adb new file mode 100644 index 000000000..015177875 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_filters.adb @@ -0,0 +1,95 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T S -- +-- -- +-- S p e c -- +-- -- +-- Copyright (C) 2009-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com). -- +-- -- +------------------------------------------------------------------------------ + +with AUnit.Simple_Test_Cases; use AUnit.Simple_Test_Cases; + +package body AUnit.Test_Filters is + + function Starts_With (Str : String; Prefix : String) return Boolean; + -- Whether Str starts with Prefix + + ----------------- + -- Starts_With -- + ----------------- + + function Starts_With (Str : String; Prefix : String) return Boolean is + begin + if Str'Length < Prefix'Length then + return False; + end if; + + return Str (Str'First .. Str'First + Prefix'Length - 1) = Prefix; + end Starts_With; + + -------------- + -- Set_Name -- + -------------- + + procedure Set_Name (Filter : in out Name_Filter; Name : String) is + begin + Message_Free (Filter.Name); + Filter.Name := Format (Name); + end Set_Name; + + --------------- + -- Is_Active -- + --------------- + + function Is_Active + (Filter : Name_Filter; + T : AUnit.Tests.Test'Class) return Boolean is + begin + if Filter.Name = null + or else Filter.Name.all = "" + then + return True; + end if; + + if T not in AUnit.Simple_Test_Cases.Test_Case'Class + or else Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)) = null + then + -- There is no name, so it doesn't match the filter + return False; + end if; + + if Routine_Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)) = null then + return Starts_With + (Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all, + Filter.Name.all); + else + return Starts_With + (Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all + & " : " + & Routine_Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all, + Filter.Name.all); + end if; + end Is_Active; + +end AUnit.Test_Filters; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_filters.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_filters.ads new file mode 100644 index 000000000..b89649220 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_filters.ads @@ -0,0 +1,76 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ F I L T E R S -- +-- -- +-- S p e c -- +-- -- +-- Copyright (C) 2009-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com). -- +-- -- +------------------------------------------------------------------------------ + +-- An instance of a test filter. +-- This can be created from command line arguments, for instance, so that +-- users can decide to run specific tests only, as opposed to the whole +-- test suite. + +with AUnit.Tests; + +package AUnit.Test_Filters is + + type Test_Filter is abstract tagged limited private; + type Test_Filter_Access is access all Test_Filter'Class; + function Is_Active + (Filter : Test_Filter; + T : AUnit.Tests.Test'Class) return Boolean is abstract; + -- Whether we should run the given test. If this function returns False, + -- the test is not run. + + type Name_Filter is new Test_Filter with private; + -- A filter based on the name of the test and/or routine. + + procedure Set_Name + (Filter : in out Name_Filter; Name : String); + -- Set the name of the test(s) to run. + -- The name can take several forms: + -- * Either the fully qualified name of the test (including routine). + -- For instance, if you have an instance of + -- AUnit.Test_Cases.Test_Case, the name could be: + -- Name (Test) & " : " & Routine_Name (Test) + -- * Or a partial name, that matches the start of the test_name. With + -- the example above, you could chose to omit the routine_name to run + -- all routines for instance + -- If the name is the empty string, all tests will be run + + function Is_Active + (Filter : Name_Filter; + T : AUnit.Tests.Test'Class) return Boolean; + -- See inherited documentation + +private + type Test_Filter is abstract tagged limited null record; + + type Name_Filter is new Test_Filter with record + Name : Message_String; + end record; + +end AUnit.Test_Filters; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_fixtures.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_fixtures.adb new file mode 100644 index 000000000..42bdd2fee --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_fixtures.adb @@ -0,0 +1,54 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ F I X T U R E S -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +package body AUnit.Test_Fixtures is + + ------------ + -- Set_Up -- + ------------ + + procedure Set_Up (Test : in out Test_Fixture) is + pragma Unreferenced (Test); + begin + null; + end Set_Up; + + --------------- + -- Tear_Down -- + --------------- + + procedure Tear_Down (Test : in out Test_Fixture) is + pragma Unreferenced (Test); + begin + null; + end Tear_Down; + +end AUnit.Test_Fixtures; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_fixtures.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_fixtures.ads new file mode 100644 index 000000000..183e53b82 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_fixtures.ads @@ -0,0 +1,90 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ F I X T U R E S -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- +-- A Test_Fixture is used to provide a common environment for a set of test +-- cases. +-- +-- To define a test case from a test fixture, see AUnit.Test_Caller. +-- +-- Each test runs in its own fixture so there can be no side effects among +-- test runs. +-- +-- Here is an example: +-- +-- +-- package Math_Test is +-- Type Test is new AUnit.Test_Fixtures.Test_Fixture with record +-- M_Value1 : Integer; +-- M_Value2 : Integer; +-- end record; +-- +-- procedure Set_Up (T : in out Test); +-- +-- procedure Test_Addition (T : in out Test); +-- +-- end Math_Test; +-- +-- package body Math_Test is +-- +-- procedure Set_Up (T : in out Test) is +-- begin +-- T.M_Value1 := 2; +-- T.M_Value2 := 3; +-- end Set_Up; +-- +-- procedure Test_Addition (T : in out Test) is +-- begin +-- Assert (T.M_Value1 + T.M_Value2 = 5, +-- "Incorrect addition for integers"); +-- end Test_Addition; +-- +-- end Math_Test; +-- +-- + +with AUnit.Assertions; + +package AUnit.Test_Fixtures is + + type Test_Fixture is new AUnit.Assertions.Test with private; + + procedure Set_Up (Test : in out Test_Fixture); + -- Set up performed before each test case + + procedure Tear_Down (Test : in out Test_Fixture); + -- Tear down performed after each test case + +private + + type Test_Fixture is new AUnit.Assertions.Test with null record; + +end AUnit.Test_Fixtures; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_results.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_results.adb new file mode 100644 index 000000000..299992f6b --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_results.adb @@ -0,0 +1,348 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ R E S U L T S -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with AUnit.Memory.Utils; + +-- Record test results. + +package body AUnit.Test_Results is + + ----------------------- + -- Local Subprograms -- + ----------------------- + + function Alloc_Failure is new AUnit.Memory.Utils.Gen_Alloc + (Test_Failure, Test_Failure_Access); + + function Alloc_Error is new AUnit.Memory.Utils.Gen_Alloc + (Test_Error, Test_Error_Access); + + E_Count : Count_Type; + F_Count : Count_Type; + S_Count : Count_Type; + + procedure Iterate_Error (Position : Result_Lists.Cursor); + procedure Iterate_Failure (Position : Result_Lists.Cursor); + procedure Iterate_Success (Position : Result_Lists.Cursor); + + function Is_Error (Position : Result_Lists.Cursor) return Boolean; + function Is_Failure (Position : Result_Lists.Cursor) return Boolean; + function Is_Success (Position : Result_Lists.Cursor) return Boolean; + + generic + with function Test (Position : Result_Lists.Cursor) return Boolean; + procedure Gen_Extract (R : in out Result; + E : in out Result_Lists.List); + + ------------------- + -- Iterate_Error -- + ------------------- + + procedure Iterate_Error (Position : Result_Lists.Cursor) is + begin + if Result_Lists.Element (Position).Error /= null then + E_Count := E_Count + 1; + end if; + end Iterate_Error; + + --------------------- + -- Iterate_Failure -- + --------------------- + + procedure Iterate_Failure (Position : Result_Lists.Cursor) is + begin + if Result_Lists.Element (Position).Failure /= null then + F_Count := F_Count + 1; + end if; + end Iterate_Failure; + + --------------------- + -- Iterate_Success -- + --------------------- + + procedure Iterate_Success (Position : Result_Lists.Cursor) is + begin + if Result_Lists.Element (Position).Error = null + and then Result_Lists.Element (Position).Failure = null + then + S_Count := S_Count + 1; + end if; + end Iterate_Success; + + ----------------- + -- Gen_Extract -- + ----------------- + + procedure Gen_Extract + (R : in out Result; + E : in out Result_Lists.List) + is + C : Result_Lists.Cursor; + Prev : Result_Lists.Cursor; + use Result_Lists; + begin + C := First (R.Result_List); + Prev := No_Element; + + while Has_Element (C) loop + if Test (C) then + Splice (Target => E, + Before => No_Element, + Source => R.Result_List, + Position => C); + + if Prev = No_Element then + C := First (R.Result_List); + else + C := Next (Prev); + end if; + else + Prev := C; + Next (C); + end if; + end loop; + end Gen_Extract; + + -------------- + -- Is_Error -- + -------------- + + function Is_Error (Position : Result_Lists.Cursor) return Boolean is + begin + return Result_Lists.Element (Position).Error /= null; + end Is_Error; + + ---------------- + -- Is_Failure -- + ---------------- + + function Is_Failure (Position : Result_Lists.Cursor) return Boolean is + begin + return Result_Lists.Element (Position).Failure /= null; + end Is_Failure; + + ---------------- + -- Is_Success -- + ---------------- + + function Is_Success (Position : Result_Lists.Cursor) return Boolean is + begin + return not Is_Error (Position) and then not Is_Failure (Position); + end Is_Success; + + --------------- + -- Add_Error -- + --------------- + + procedure Add_Error + (R : in out Result; + Test_Name : Message_String; + Routine_Name : Message_String; + Error : Test_Error; + Elapsed : Time) + is + Val : constant Test_Result := (Test_Name, Routine_Name, + Failure => null, + Error => Alloc_Error, + Elapsed => Elapsed); + use Result_Lists; + begin + + Val.Error.all := Error; + Append (R.Result_List, Val); + end Add_Error; + + ----------------- + -- Add_Failure -- + ----------------- + + procedure Add_Failure + (R : in out Result; + Test_Name : Message_String; + Routine_Name : Message_String; + Failure : Test_Failure; + Elapsed : Time) is + + Val : constant Test_Result := (Test_Name, Routine_Name, + Failure => Alloc_Failure, + Error => null, + Elapsed => Elapsed); + use Result_Lists; + begin + + Val.Failure.all := Failure; + Append (R.Result_List, Val); + end Add_Failure; + + ----------------- + -- Add_Success -- + ----------------- + + procedure Add_Success + (R : in out Result; + Test_Name : Message_String; + Routine_Name : Message_String; + Elapsed : Time) is + + Val : constant Test_Result := + (Test_Name, Routine_Name, null, null, Elapsed); + use Result_Lists; + + begin + Append (R.Result_List, Val); + end Add_Success; + + ----------------- + -- Set_Elapsed -- + ----------------- + + procedure Set_Elapsed (R : in out Result; + T : Time_Measure.Time) is + begin + R.Elapsed_Time := T; + end Set_Elapsed; + + ----------------- + -- Error_Count -- + ----------------- + + function Error_Count (R : Result) return Count_Type is + use Result_Lists; + begin + E_Count := 0; + Iterate (R.Result_List, Iterate_Error'Access); + return E_Count; + end Error_Count; + + ------------ + -- Errors -- + ------------ + + procedure Errors (R : in out Result; + E : in out Result_Lists.List) is + procedure Extract is new Gen_Extract (Is_Error); + begin + Extract (R, E); + end Errors; + + ------------------- + -- Failure_Count -- + ------------------- + + function Failure_Count (R : Result) return Count_Type is + use Result_Lists; + begin + F_Count := 0; + Iterate (R.Result_List, Iterate_Failure'Access); + return F_Count; + end Failure_Count; + + -------------- + -- Failures -- + -------------- + + procedure Failures (R : in out Result; + F : in out Result_Lists.List) is + procedure Extract is new Gen_Extract (Is_Failure); + begin + Extract (R, F); + end Failures; + + ------------- + -- Elapsed -- + ------------- + + function Elapsed (R : Result) return Time_Measure.Time is + begin + return R.Elapsed_Time; + end Elapsed; + + ---------------- + -- Start_Test -- + ---------------- + + procedure Start_Test (R : in out Result; Subtest_Count : Count_Type) is + begin + R.Tests_Run := R.Tests_Run + Subtest_Count; + end Start_Test; + + ------------------- + -- Success_Count -- + ------------------- + + function Success_Count (R : Result) return Count_Type is + begin + S_Count := 0; + Result_Lists.Iterate (R.Result_List, Iterate_Success'Access); + return S_Count; + end Success_Count; + + --------------- + -- Successes -- + --------------- + + procedure Successes (R : in out Result; + S : in out Result_Lists.List) is + procedure Extract is new Gen_Extract (Is_Success); + begin + Extract (R, S); + end Successes; + + ---------------- + -- Successful -- + ---------------- + + function Successful (R : Result) return Boolean is + begin + return Success_Count (R) = Test_Count (R); + end Successful; + + ---------------- + -- Test_Count -- + ---------------- + + function Test_Count (R : Result) return Ada_Containers.Count_Type is + begin + return R.Tests_Run; + end Test_Count; + + ----------- + -- Clear -- + ----------- + + procedure Clear (R : in out Result) is + begin + R.Tests_Run := 0; + R.Elapsed_Time := Time_Measure.Null_Time; + Result_Lists.Clear (R.Result_List); + end Clear; + +end AUnit.Test_Results; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_results.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_results.ads new file mode 100644 index 000000000..f70193179 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_results.ads @@ -0,0 +1,146 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ R E S U L T S -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with Ada_Containers.AUnit_Lists; + +with AUnit.Time_Measure; use AUnit.Time_Measure; + +-- Test reporting. +-- +package AUnit.Test_Results is + + type Result is tagged limited private; + -- Record result. A result object is associated with the execution of a + -- top-level test suite. + + type Test_Failure is record + Message : Message_String; + Source_Name : Message_String; + Line : Natural; + end record; + type Test_Failure_Access is access all Test_Failure; + pragma No_Strict_Aliasing (Test_Failure_Access); + -- Description of a test routine failure + + type Test_Error is record + Exception_Name : Message_String; + Exception_Message : Message_String; + Traceback : Message_String; + end record; + type Test_Error_Access is access all Test_Error; + pragma No_Strict_Aliasing (Test_Error_Access); + -- Description of unexpected exceptions + + type Test_Result is record + Test_Name : Message_String; + Routine_Name : Message_String; + Failure : Test_Failure_Access; + Error : Test_Error_Access; + Elapsed : Time := Null_Time; + end record; + -- Decription of a test routine result + + use Ada_Containers; + + package Result_Lists is new Ada_Containers.AUnit_Lists (Test_Result); + -- Containers for all test results + + procedure Add_Error + (R : in out Result; + Test_Name : Message_String; + Routine_Name : Message_String; + Error : Test_Error; + Elapsed : Time); + -- Record an unexpected exception + + procedure Add_Failure + (R : in out Result; + Test_Name : Message_String; + Routine_Name : Message_String; + Failure : Test_Failure; + Elapsed : Time); + -- Record a test routine failure + + procedure Add_Success + (R : in out Result; + Test_Name : Message_String; + Routine_Name : Message_String; + Elapsed : Time); + -- Record a test routine success + + procedure Set_Elapsed (R : in out Result; T : Time); + -- Set Elapsed time for reporter + + function Error_Count (R : Result) return Count_Type; + -- Number of routines with unexpected exceptions + + procedure Errors (R : in out Result; + E : in out Result_Lists.List); + -- List of routines with unexpected exceptions. This resets the list. + + function Failure_Count (R : Result) return Count_Type; + -- Number of failed routines + + procedure Failures (R : in out Result; F : in out Result_Lists.List); + -- List of failed routines. This resets the list. + + function Elapsed (R : Result) return Time; + -- Elapsed time for test execution + + procedure Start_Test (R : in out Result; Subtest_Count : Count_Type); + -- Set count for a test run + + function Success_Count (R : Result) return Count_Type; + -- Number of successful routines + + procedure Successes (R : in out Result; S : in out Result_Lists.List); + -- List of successful routines. This resets the list. + + function Successful (R : Result) return Boolean; + -- All routines successful? + + function Test_Count (R : Result) return Ada_Containers.Count_Type; + -- Number of routines run + + procedure Clear (R : in out Result); + -- Clear the results + +private + + pragma Inline (Errors, Failures, Successes); + + type Result is tagged limited record + Tests_Run : Count_Type := 0; + Result_List : Result_Lists.List; + Elapsed_Time : Time := Null_Time; + end record; + +end AUnit.Test_Results; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_suites.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_suites.adb new file mode 100644 index 000000000..7b3e5a5ac --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_suites.adb @@ -0,0 +1,128 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ S U I T E S -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Unchecked_Conversion; +with AUnit.Memory.Utils; + +package body AUnit.Test_Suites is + + -------------- + -- Add_Test -- + -------------- + + procedure Add_Test + (S : access Test_Suite'Class; + T : access Test_Suite'Class; + E : Environment_Access := null) + is + begin + if E = null then + Set_Environment(T.all, Get_Environment(S.all)); + else + Set_Environment(T.all, E); + end if; + Append + (S.Tests, + (Kind => TS_Elt, + TS => Access_Test_Suite'(T.all'Unchecked_Access))); + end Add_Test; + + -------------- + -- Add_Test -- + -------------- + + procedure Add_Test + (S : access Test_Suite'Class; + T : access Test_Case'Class; + E : Environment_Access := null) + is + begin + if E = null then + Set_Environment(T.all, Get_Environment(S.all)); + else + Set_Environment(T.all, E); + end if; + Append + (S.Tests, + (Kind => TC_Elt, + TC => Test_Case_Access'(T.all'Unchecked_Access))); + end Add_Test; + + --------- + -- Run -- + --------- + + procedure Run (Suite : access Test_Suite; + Options : AUnit_Options; + R : in out Result'Class; + Outcome : out Status) + is + C : Cursor := First (Suite.Tests); + Result : Status := Success; + + begin + Outcome := Success; + while Has_Element (C) loop + case Element (C).Kind is + when TC_Elt => + Run (Element (C).TC, Options, R, Result); + when TS_Elt => + Run (Element (C).TS, Options, R, Result); + end case; + + if Result = Failure then + Outcome := Failure; + end if; + + Next (C); + end loop; + end Run; + + --------------- + -- New_Suite -- + --------------- + + function New_Suite return Access_Test_Suite is + type Access_Type is access all Test_Suite; + pragma No_Strict_Aliasing (Access_Type); + function Alloc is new AUnit.Memory.Utils.Gen_Alloc + (Test_Suite, Access_Type); + function Convert is new Ada.Unchecked_Conversion + (Access_Type, Access_Test_Suite); + Ret : constant Access_Type := Alloc; + Obj : Test_Suite; + for Obj'Address use Ret.all'Address; + pragma Warnings (Off, Obj); + begin + return Convert (Ret); + end New_Suite; + +end AUnit.Test_Suites; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_suites.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_suites.ads new file mode 100644 index 000000000..e56bd77c0 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-test_suites.ads @@ -0,0 +1,89 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ S U I T E S -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- A collection of test cases. + +with Ada_Containers; +with Ada_Containers.AUnit_Lists; +with AUnit.Options; use AUnit.Options; +with AUnit.Simple_Test_Cases; use AUnit.Simple_Test_Cases; +with AUnit.Tests; +with AUnit.Test_Results; use AUnit.Test_Results; +with AUnit.Environments; use AUnit.Environments; + +package AUnit.Test_Suites is + + type Test_Suite is new AUnit.Tests.Test with private; + type Access_Test_Suite is access all Test_Suite'Class; + + procedure Add_Test (S : access Test_Suite'Class; + T : access Test_Suite'Class; + E : Environment_Access := null); + procedure Add_Test (S : access Test_Suite'Class; + T : access Test_Case'Class; + E : Environment_Access := null); + -- Add a test case or suite to this suite + + procedure Run (Suite : access Test_Suite; + Options : AUnit_Options; + R : in out Result'Class; + Outcome : out Status); + -- Run all tests collected into this suite + + function New_Suite return Access_Test_Suite; + -- Create a new test suite + +private + + type Test_Suite_Elt_Kind is + (TC_Elt, + TS_Elt); + + type Test_Suite_Element (Kind : Test_Suite_Elt_Kind := TC_Elt) is record + case Kind is + when TC_Elt => + TC : Test_Case_Access; + when TS_Elt => + TS : Access_Test_Suite; + end case; + end record; + + use Ada_Containers; + + package Test_Lists is new Ada_Containers.AUnit_Lists (Test_Suite_Element); + use Test_Lists; + -- Containers for test cases and sub-suites + + type Test_Suite is new AUnit.Tests.Test with record + Tests : aliased Test_Lists.List; + end record; + +end AUnit.Test_Suites; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-tests.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit-tests.adb new file mode 100644 index 000000000..d59aa7919 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-tests.adb @@ -0,0 +1,54 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T S -- +-- -- +-- B o d y -- +-- -- +-- Copyright (C) 2017, Victor Porton -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com). -- +-- -- +------------------------------------------------------------------------------ + +package body AUnit.Tests is + + --------------------- + -- Set_Environment -- + --------------------- + + procedure Set_Environment + (T: in out Test; + E: Environment_Access) + is + begin + T.Environment := E; + end Set_Environment; + + --------------------- + -- Get_Environment -- + --------------------- + + function Get_Environment (T: Test) return Environment_Access is + begin + return T.Environment; + end Get_Environment; + +end AUnit.Tests; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit-tests.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit-tests.ads new file mode 100644 index 000000000..2936b352f --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit-tests.ads @@ -0,0 +1,55 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T S -- +-- -- +-- S p e c -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com). -- +-- -- +------------------------------------------------------------------------------ + +-- Base Test Case or Test Suite +-- +-- This base type allows composition of both test cases and sub-suites into a +-- test suite (Composite pattern) + +with AUnit.Environments; use AUnit.Environments; + +package AUnit.Tests is + + type Test is abstract tagged limited private; + type Test_Access is access all Test'Class; + + procedure Set_Environment (T: in out Test; + E: Environment_Access); + + function Get_Environment (T: Test) return Environment_Access; + +private + + type Test is abstract tagged limited + record + Environment: Environment_Access; + end record; + +end AUnit.Tests; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit.adb b/ada/libaunit-3.7.2/include/aunit/framework/aunit.adb new file mode 100644 index 000000000..a2cacaf9d --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit.adb @@ -0,0 +1,98 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Unchecked_Conversion; +with System.Storage_Elements; use System.Storage_Elements; +with AUnit.Memory; use AUnit.Memory; + +package body AUnit is + + type Bounds is record + First : Natural; + Last : Natural; + end record; + type Bounds_Access is access all Bounds; + + type Fat_Pointer is record + Address : System.Address; + Bound_Address : Bounds_Access; + end record; + pragma Pack (Fat_Pointer); + + ------------------- + -- Message_Alloc -- + ------------------- + + function Message_Alloc (Length : Natural) return Message_String is + function To_Message is new Ada.Unchecked_Conversion + (Fat_Pointer, Message_String); + function To_Bounds_Access is new Ada.Unchecked_Conversion + (System.Address, Bounds_Access); + function To_Address is new Ada.Unchecked_Conversion + (Bounds_Access, System.Address); + Ret : Fat_Pointer; + begin + Ret.Bound_Address := To_Bounds_Access + (AUnit.Memory.AUnit_Alloc + (size_t (Length + (Bounds'Object_Size / 8)))); + Ret.Bound_Address.First := 1; + Ret.Bound_Address.Last := Length; + Ret.Address := To_Address (Ret.Bound_Address) + (Bounds'Size / 8); + return To_Message (Ret); + end Message_Alloc; + + ------------------ + -- Message_Free -- + ------------------ + + procedure Message_Free (Msg : in out Message_String) is + begin + if Msg /= null then + AUnit.Memory.AUnit_Free (Msg.all'Address); + Msg := null; + end if; + end Message_Free; + + ------------ + -- Format -- + ------------ + + function Format (S : String) return Message_String is + Ptr : constant Message_String := Message_Alloc (S'Length); + begin + for J in S'Range loop + Ptr (J - S'First + 1) := S (J); + end loop; + + return Ptr; + end Format; + +end AUnit; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/aunit.ads b/ada/libaunit-3.7.2/include/aunit/framework/aunit.ads new file mode 100644 index 000000000..f43b553d4 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/aunit.ads @@ -0,0 +1,48 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2006-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Test Suite Framework + +package AUnit is + + type Message_String is access String; + + subtype Test_String is Message_String; + + type Status is (Success, Failure); + + -- String manipulation functions. + + function Format (S : String) return Message_String; + function Message_Alloc (Length : Natural) return Message_String; + procedure Message_Free (Msg : in out Message_String); + +end AUnit; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/calendar/aunit-time_measure.adb b/ada/libaunit-3.7.2/include/aunit/framework/calendar/aunit-time_measure.adb new file mode 100644 index 000000000..1cfccd70a --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/calendar/aunit-time_measure.adb @@ -0,0 +1,175 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T I M E _ M E A S U R E -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2006-2014, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +package body AUnit.Time_Measure is + + ------------------- + -- Start_Measure -- + ------------------- + + procedure Start_Measure (T : in out Time) is + begin + T.Start := Ada.Calendar.Clock; + end Start_Measure; + + ------------------ + -- Stop_Measure -- + ------------------ + + procedure Stop_Measure (T : in out Time) is + begin + T.Stop := Ada.Calendar.Clock; + end Stop_Measure; + + ----------------- + -- Get_Measure -- + ----------------- + + function Get_Measure (T : Time) return AUnit_Duration is + use type Ada.Calendar.Time; + begin + return AUnit_Duration (T.Stop - T.Start); + end Get_Measure; + + --------------------- + -- Gen_Put_Measure -- + --------------------- + + procedure Gen_Put_Measure (Measure : AUnit_Duration) is + H, M, S : Integer := 0; + T : Duration := Duration (Measure); + Force : Boolean; + + procedure Put (N : Integer; Length : Integer); + -- Put N using at least Length digits. + + procedure Put (N : Integer; Length : Integer) is + begin + for Dig in reverse 1 .. Length - 1 loop + if N < 10**Dig then + Put ("0"); + else + exit; + end if; + end loop; + + Put (N); + end Put; + + begin + -- Calculate the number of hours, minutes and seconds + while T >= 3600.0 loop + H := H + 1; + T := T - 3600.0; + end loop; + + while T >= 60.0 loop + M := M + 1; + T := T - 60.0; + end loop; + + while T >= 1.0 loop + S := S + 1; + T := T - 1.0; + end loop; + + -- Now display the result + Force := False; + + if H > 0 then + Put (H); + Put ("h"); + Force := True; + end if; + + if M > 0 or else Force then + if not Force then + Put (M); + else + -- In case some output is already done, then we force a 2 digits + -- output so that the output is normalized. + Put (M, 2); + end if; + + Put ("min. "); + Force := True; + end if; + + if not Force then + Put (S); + else + Put (S, 2); + end if; + + Put ("."); + Put (Integer (T * 1_000_000.0), 6); + Put (" sec."); + end Gen_Put_Measure; + + -------------------------------- + -- Gen_Put_Measure_In_Seconds -- + -------------------------------- + + procedure Gen_Put_Measure_In_Seconds (Measure : AUnit_Duration) is + S : Integer := 0; + T : Duration := Duration (Measure); + + procedure Put (N : Integer; Length : Integer); + -- Put N using at least Length digits. + + procedure Put (N : Integer; Length : Integer) is + begin + for Dig in reverse 1 .. Length - 1 loop + if N < 10**Dig then + Put ("0"); + else + exit; + end if; + end loop; + + Put (N); + end Put; + + begin + + while T >= 1.0 loop + S := S + 1; + T := T - 1.0; + end loop; + + Put (S); + + Put ("."); + Put (Integer (T * 1_000_000.0), 9); + Put ("s"); + end Gen_Put_Measure_In_Seconds; + +end AUnit.Time_Measure; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/calendar/aunit-time_measure.ads b/ada/libaunit-3.7.2/include/aunit/framework/calendar/aunit-time_measure.ads new file mode 100644 index 000000000..c91e18357 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/calendar/aunit-time_measure.ads @@ -0,0 +1,72 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T I M E _ M E A S U R E -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2006-2014, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Calendar; + +package AUnit.Time_Measure is + + type Time is record + Start : Ada.Calendar.Time; + Stop : Ada.Calendar.Time; + end record; + + type AUnit_Duration is private; + + Null_Time : constant Time := (Start => Ada.Calendar.Time_Of (1901, 1, 1), + Stop => Ada.Calendar.Time_Of (1901, 1, 1)); + + procedure Start_Measure (T : in out Time); + -- Start a new measure + + procedure Stop_Measure (T : in out Time); + -- Stop the measure + + function Get_Measure (T : Time) return AUnit_Duration; + -- Get the measure + + generic + with procedure Put (I : Integer) is <>; + with procedure Put (S : String) is <>; + procedure Gen_Put_Measure (Measure : AUnit_Duration); + -- Put the image of the measure + + generic + with procedure Put (I : Integer) is <>; + with procedure Put (S : String) is <>; + procedure Gen_Put_Measure_In_Seconds (Measure : AUnit_Duration); + -- Unlike Gen_Put_Measure, puts the measure in seconds only, also puts + -- 9 digits after decimal point. + +private + + type AUnit_Duration is new Duration; + +end AUnit.Time_Measure; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/certexception/aunit-assertions-assert_exception.adb b/ada/libaunit-3.7.2/include/aunit/framework/certexception/aunit-assertions-assert_exception.adb new file mode 100644 index 000000000..6056edd2c --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/certexception/aunit-assertions-assert_exception.adb @@ -0,0 +1,48 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . A S S E R T I O N S -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Version for cert run-time libraries that support exception handling +separate (AUnit.Assertions) +procedure Assert_Exception + (Proc : Throwing_Exception_Proc; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line) +is +begin + Proc.all; + -- No exception raised: register the failure message + Assert (False, Message, Source, Line); + +exception + when others => + null; +end Assert_Exception; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/certexception/aunit-simple_test_cases-run_routine.adb b/ada/libaunit-3.7.2/include/aunit/framework/certexception/aunit-simple_test_cases-run_routine.adb new file mode 100644 index 000000000..a4df5cab8 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/certexception/aunit-simple_test_cases-run_routine.adb @@ -0,0 +1,107 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ C A S E S . R U N _ R O U T I N E -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2006-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Exceptions; use Ada.Exceptions; +with AUnit.Time_Measure; + +separate (AUnit.Simple_Test_Cases) + +-- Version for cert run-time libraries +procedure Run_Routine + (Test : access Test_Case'Class; + Options : AUnit.Options.AUnit_Options; + R : in out Result'Class; + Outcome : out Status) +is + Unexpected_Exception : Boolean := False; + Time : Time_Measure.Time := Time_Measure.Null_Time; + + use Time_Measure; + +begin + + -- Reset failure list to capture failed assertions for one routine + + Clear_Failures (Test.all); + + begin + if Options.Test_Case_Timer then + Start_Measure (Time); + end if; + + Run_Test (Test.all); + + if Options.Test_Case_Timer then + Stop_Measure (Time); + end if; + + exception + when Assertion_Error => + if Options.Test_Case_Timer then + Stop_Measure (Time); + end if; + + when E : others => + if Options.Test_Case_Timer then + Stop_Measure (Time); + end if; + + Unexpected_Exception := True; + Add_Error + (R, + Name (Test.all), + Routine_Name (Test.all), + Error => (Exception_Name => Format (Exception_Name (E)), + Exception_Message => null, + Traceback => null), + Elapsed => Time); + end; + + if not Unexpected_Exception and then not Has_Failures (Test.all) then + Outcome := Success; + Add_Success (R, Name (Test.all), Routine_Name (Test.all), Time); + else + Outcome := Failure; + declare + C : Failure_Iter := First_Failure (Test.all); + begin + while Has_Failure (C) loop + Add_Failure (R, + Name (Test.all), + Routine_Name (Test.all), + Get_Failure (C), + Time); + Next (C); + end loop; + end; + end if; + +end Run_Routine; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/fullexception/aunit-assertions-assert_exception.adb b/ada/libaunit-3.7.2/include/aunit/framework/fullexception/aunit-assertions-assert_exception.adb new file mode 100644 index 000000000..e705f6e5f --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/fullexception/aunit-assertions-assert_exception.adb @@ -0,0 +1,52 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . A S S E R T I O N S -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Version for run-time libraries that support exception handling + +separate (AUnit.Assertions) +procedure Assert_Exception + (Proc : Throwing_Exception_Proc; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line) +is +begin + begin + Proc.all; + exception + when others => + return; + end; + + -- No exception raised: register the failure message + Assert (False, Message, Source, Line); + +end Assert_Exception; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/fullexception/aunit-simple_test_cases-run_routine.adb b/ada/libaunit-3.7.2/include/aunit/framework/fullexception/aunit-simple_test_cases-run_routine.adb new file mode 100644 index 000000000..b18b51d40 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/fullexception/aunit-simple_test_cases-run_routine.adb @@ -0,0 +1,110 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ C A S E S . R U N _ R O U T I N E -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2006-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Exceptions; use Ada.Exceptions; + +with GNAT.Traceback.Symbolic; use GNAT.Traceback.Symbolic; + +with AUnit.Time_Measure; + +separate (AUnit.Simple_Test_Cases) + +-- Version for run-time libraries that support exception handling +procedure Run_Routine + (Test : access Test_Case'Class; + Options : AUnit.Options.AUnit_Options; + R : in out Result'Class; + Outcome : out Status) +is + Unexpected_Exception : Boolean := False; + Time : Time_Measure.Time := Time_Measure.Null_Time; + + use Time_Measure; + +begin + + -- Reset failure list to capture failed assertions for one routine + + Clear_Failures (Test.all); + + begin + if Options.Test_Case_Timer then + Start_Measure (Time); + end if; + + Run_Test (Test.all); + + if Options.Test_Case_Timer then + Stop_Measure (Time); + end if; + + exception + when Assertion_Error => + if Options.Test_Case_Timer then + Stop_Measure (Time); + end if; + + when E : others => + if Options.Test_Case_Timer then + Stop_Measure (Time); + end if; + + Unexpected_Exception := True; + Add_Error + (R, + Name (Test.all), + Routine_Name (Test.all), + Error => (Exception_Name => Format (Exception_Name (E)), + Exception_Message => Format (Exception_Message (E)), + Traceback => Format (Symbolic_Traceback (E))), + Elapsed => Time); + end; + + if not Unexpected_Exception and then not Has_Failures (Test.all) then + Outcome := Success; + Add_Success (R, Name (Test.all), Routine_Name (Test.all), Time); + else + Outcome := Failure; + declare + C : Failure_Iter := First_Failure (Test.all); + begin + while Has_Failure (C) loop + Add_Failure (R, + Name (Test.all), + Routine_Name (Test.all), + Get_Failure (C), + Time); + Next (C); + end loop; + end; + end if; + +end Run_Routine; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/nativememory/aunit-memory-utils.adb b/ada/libaunit-3.7.2/include/aunit/framework/nativememory/aunit-memory-utils.adb new file mode 100644 index 000000000..12727d774 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/nativememory/aunit-memory-utils.adb @@ -0,0 +1,43 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . M E M O R Y . U T I L S -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2008-2012, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +package body AUnit.Memory.Utils is + + --------------- + -- Gen_Alloc -- + --------------- + + function Gen_Alloc return Name is + begin + return new Object; + end Gen_Alloc; + +end AUnit.Memory.Utils; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/nativememory/aunit-memory.adb b/ada/libaunit-3.7.2/include/aunit/framework/nativememory/aunit-memory.adb new file mode 100644 index 000000000..9c36d5bc9 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/nativememory/aunit-memory.adb @@ -0,0 +1,58 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT RUN-TIME COMPONENTS -- +-- -- +-- A U N I T . M E M O R Y -- +-- -- +-- B o d y -- +-- -- +-- Copyright (C) 2001-2003 Free Software Foundation, Inc. -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Memory allocation implementation using the gnat runtime methods. + +package body AUnit.Memory is + + ----------- + -- Alloc -- + ----------- + + function AUnit_Alloc (Size : size_t) return System.Address is + function RT_Malloc (Size : size_t) return System.Address; + pragma Import (C, RT_Malloc, "__gnat_malloc"); + begin + return RT_Malloc (Size); + end AUnit_Alloc; + + ---------- + -- Free -- + ---------- + + procedure AUnit_Free (Obj : System.Address) is + procedure RT_Free (Obj : System.Address); + pragma Import (C, RT_Free, "__gnat_free"); + begin + RT_Free (Obj); + end AUnit_Free; + +end AUnit.Memory; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/nocalendar/aunit-time_measure.adb b/ada/libaunit-3.7.2/include/aunit/framework/nocalendar/aunit-time_measure.adb new file mode 100644 index 000000000..06e5fe19e --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/nocalendar/aunit-time_measure.adb @@ -0,0 +1,84 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T I M E _ M E A S U R E -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2006-2014, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +package body AUnit.Time_Measure is + + ------------------- + -- Start_Measure -- + ------------------- + + procedure Start_Measure (T : in out Time) is + pragma Unreferenced (T); + begin + null; + end Start_Measure; + + ------------------ + -- Stop_Measure -- + ------------------ + + procedure Stop_Measure (T : in out Time) is + pragma Unreferenced (T); + begin + null; + end Stop_Measure; + + ----------------- + -- Get_Measure -- + ----------------- + + function Get_Measure (T : Time) return AUnit_Duration is + pragma Unreferenced (T); + begin + return 0; + end Get_Measure; + + --------------------- + -- Gen_Put_Measure -- + --------------------- + + procedure Gen_Put_Measure (Measure : AUnit_Duration) is + pragma Unreferenced (Measure); + begin + null; + end Gen_Put_Measure; + + -------------------------------- + -- Gen_Put_Measure_In_Seconds -- + -------------------------------- + + procedure Gen_Put_Measure_In_Seconds (Measure : AUnit_Duration) is + pragma Unreferenced (Measure); + begin + null; + end Gen_Put_Measure_In_Seconds; + +end AUnit.Time_Measure; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/nocalendar/aunit-time_measure.ads b/ada/libaunit-3.7.2/include/aunit/framework/nocalendar/aunit-time_measure.ads new file mode 100644 index 000000000..c8eb8b3a8 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/nocalendar/aunit-time_measure.ads @@ -0,0 +1,64 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T I M E _ M E A S U R E -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2006-2014, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Dummy package when Ada.Calendar is not supported + +package AUnit.Time_Measure is + + type Time is null record; + + type AUnit_Duration is private; + + Null_Time : Time; + + procedure Start_Measure (T : in out Time); + -- Start a new measure + + procedure Stop_Measure (T : in out Time); + -- Stop the measure + + function Get_Measure (T : Time) return AUnit_Duration; + -- Get the measure + + generic + procedure Gen_Put_Measure (Measure : AUnit_Duration); + -- Put the image of the measure + + generic + procedure Gen_Put_Measure_In_Seconds (Measure : AUnit_Duration); + -- Unlike Gen_Put_Measure, puts the measure in seconds only, also puts + -- 9 digits after decimal point. + +private + + type AUnit_Duration is new Integer; + +end AUnit.Time_Measure; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/staticmemory/aunit-memory-utils.adb b/ada/libaunit-3.7.2/include/aunit/framework/staticmemory/aunit-memory-utils.adb new file mode 100644 index 000000000..4f5b9eb1f --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/staticmemory/aunit-memory-utils.adb @@ -0,0 +1,52 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . M E M O R Y . U T I L S -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2008-2012, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Unchecked_Conversion; + +package body AUnit.Memory.Utils is + + --------------- + -- Gen_Alloc -- + --------------- + + function Gen_Alloc return Name is + function To_Name is new Ada.Unchecked_Conversion (System.Address, Name); + Ret : constant System.Address := AUnit_Alloc (Object'Object_Size / 8); + -- Declare an actual object at Ret Address so that the default + -- initialisation is performed. + Obj : Object; + for Obj'Address use Ret; + pragma Warnings (Off, Obj); + begin + return To_Name (Ret); + end Gen_Alloc; + +end AUnit.Memory.Utils; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/staticmemory/aunit-memory.adb b/ada/libaunit-3.7.2/include/aunit/framework/staticmemory/aunit-memory.adb new file mode 100644 index 000000000..5b962f74a --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/staticmemory/aunit-memory.adb @@ -0,0 +1,93 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT RUN-TIME COMPONENTS -- +-- -- +-- A U N I T . M E M O R Y -- +-- -- +-- B o d y -- +-- -- +-- Copyright (C) 2001-2003 Free Software Foundation, Inc. -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Dummy implementation. + +with System.Storage_Elements; +with Unchecked_Conversion; + +package body AUnit.Memory is + + package SSE renames System.Storage_Elements; + + Default_Size : constant := 100 * 1_024; + + type Mark_Id is new SSE.Integer_Address; + + type Memory is array (Mark_Id range <>) of SSE.Storage_Element; + for Memory'Alignment use Standard'Maximum_Alignment; + + Mem : Memory (1 .. Default_Size); + + Top : Mark_Id := Mem'First; + + function To_Mark_Id is new Unchecked_Conversion + (size_t, Mark_Id); + + ----------- + -- Alloc -- + ----------- + + function AUnit_Alloc (Size : size_t) return System.Address is + Max_Align : constant Mark_Id := Mark_Id (Standard'Maximum_Alignment); + Max_Size : Mark_Id := + ((To_Mark_Id (Size) + Max_Align - 1) / Max_Align) + * Max_Align; + Location : constant Mark_Id := Top; + begin + if Max_Size = 0 then + Max_Size := Max_Align; + end if; + + if Size = size_t'Last then + raise Storage_Error; + end if; + + Top := Top + Max_Size; + + if Top > Default_Size then + raise Storage_Error; + end if; + + return Mem (Location)'Address; + end AUnit_Alloc; + + ---------- + -- Free -- + ---------- + + procedure AUnit_Free (Obj : System.Address) is + pragma Unreferenced (Obj); + begin + null; + end AUnit_Free; + +end AUnit.Memory; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-assertions-assert_exception.adb b/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-assertions-assert_exception.adb new file mode 100644 index 000000000..6a22eca58 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-assertions-assert_exception.adb @@ -0,0 +1,57 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . A S S E R T I O N S -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2000-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Version for run-time libraries that support exception handling via +-- gcc builtin setjmp/longjmp + +with AUnit.Last_Chance_Handler; + +separate (AUnit.Assertions) +procedure Assert_Exception + (Proc : Throwing_Exception_Proc; + Message : String; + Source : String := GNAT.Source_Info.File; + Line : Natural := GNAT.Source_Info.Line) +is + procedure Exec; + + procedure Exec is + begin + Proc.all; + end Exec; + + function My_Setjmp is new AUnit.Last_Chance_Handler.Gen_Setjmp (Exec); +begin + if My_Setjmp = 0 then + -- Result is 0 when no exception has been raised. + Assert (False, Message, Source, Line); + end if; +end Assert_Exception; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-last_chance_handler.adb b/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-last_chance_handler.adb new file mode 100644 index 000000000..21dd575dd --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-last_chance_handler.adb @@ -0,0 +1,249 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- L A S T _ C H A N C E _ H A N D L E R -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with System; +with System.Storage_Elements; use System.Storage_Elements; +with Interfaces.C; +with Ada.Unchecked_Conversion; + +package body AUnit.Last_Chance_Handler is + + Exception_Name : Message_String := null; + Exception_Message : Message_String := null; + + type Jmp_Buff is array (1 .. 5) of System.Address; + type Jmp_Buff_Address is access all Jmp_Buff; + -- type expected by setjmp call + + function Builtin_Setjmp (Buff : Jmp_Buff_Address) return Integer; + pragma Import (Intrinsic, Builtin_Setjmp, "__builtin_setjmp"); + + procedure Builtin_Longjmp (Buff : Jmp_Buff_Address; Flag : Integer); + pragma Import (Intrinsic, Builtin_Longjmp, "__builtin_longjmp"); + pragma No_Return (Builtin_Longjmp); + + -- handle at most 5 handlers at the same time + Jmp_Buffer : array (1 .. 5) of aliased Jmp_Buff; + Jmp_Buff_Idx : Integer := Jmp_Buffer'First; + + --------------------------- + -- C Strings management -- + --------------------------- + + type chars_ptr is access all Character; + pragma No_Strict_Aliasing (chars_ptr); + + function To_chars_ptr is + new Ada.Unchecked_Conversion (System.Address, chars_ptr); + + function To_Address is + new Ada.Unchecked_Conversion (chars_ptr, System.Address); + + function To_Ada + (Item : chars_ptr; Line : Integer := 0) return Message_String; + + ---------------- + -- Gen_Setjmp -- + ---------------- + + function Gen_Setjmp return Integer + is + Ret : Integer; + begin + Ret := Builtin_Setjmp (Jmp_Buffer (Jmp_Buff_Idx)'Access); + + if Ret = 0 then + Jmp_Buff_Idx := Jmp_Buff_Idx + 1; + Proc; + Jmp_Buff_Idx := Jmp_Buff_Idx - 1; + end if; + + return Ret; + end Gen_Setjmp; + + ------------------------ + -- Get_Exception_Name -- + ------------------------ + + function Get_Exception_Name return Message_String is + begin + if Exception_Message = null then + return AUnit.Message_Alloc (0); + else + return Exception_Name; + end if; + end Get_Exception_Name; + + --------------------------- + -- Get_Exception_Message -- + --------------------------- + + function Get_Exception_Message return Message_String is + begin + if Exception_Message = null then + return AUnit.Message_Alloc (0); + else + return Exception_Message; + end if; + end Get_Exception_Message; + + ------------ + -- To_Ada -- + ------------ + + function To_Ada + (Item : chars_ptr; Line : Integer := 0) return Message_String + is + use Interfaces.C; + Result : Message_String; + Length : size_t := 0; + Line_Img : String (1 .. Integer'Width); + First : Natural := Line_Img'Last + 1; + + function "+" (Left : chars_ptr; Right : size_t) return chars_ptr; + -- Return the address Right character right of address Left. + + function Peek (From : chars_ptr) return char; + -- Return the character at address From + + function To_Ada (Item : char) return Character; + -- Translate char to an Ada Character + + --------- + -- "+" -- + --------- + + function "+" (Left : chars_ptr; Right : size_t) return chars_ptr is + begin + return To_chars_ptr (To_Address (Left) + Storage_Offset (Right)); + end "+"; + + ---------- + -- Peek -- + ---------- + + function Peek (From : chars_ptr) return char is + begin + return char (From.all); + end Peek; + + ------------ + -- To_Ada -- + ------------ + + function To_Ada (Item : char) return Character is + begin + return Character'Val (char'Pos (Item)); + end To_Ada; + + begin + if Item = null then + return null; + end if; + + -- Compute the Length of "Item" + loop + if Peek (Item + Length) = nul then + exit; + end if; + + Length := Length + 1; + end loop; + + -- Compute the image of Line + if Line /= 0 then + declare + Int : Integer; + Val : Natural; + + begin + Int := Line; + + loop + Val := Int mod 10; + Int := (Int - Val) / 10; + First := First - 1; + Line_Img (First) := Character'Val (Val + Character'Pos ('0')); + exit when Int = 0; + end loop; + end; + end if; + + if Line /= 0 then + Result := AUnit.Message_Alloc + (Natural (Length) + Line_Img'Last - First + 2); + else + Result := AUnit.Message_Alloc (Natural (Length)); + end if; + + for J in 1 .. Integer (Length) loop + Result (J) := To_Ada (Peek (Item + size_t (J - 1))); + end loop; + + if Line /= 0 then + Result (Integer (Length + 1)) := ':'; + for J in First .. Line_Img'Last loop + Result (Integer (Length + 2) + J - First) := Line_Img (J); + end loop; + end if; + + return Result; + end To_Ada; + + ------------------------- + -- Last_Chance_Handler -- + ------------------------- + + procedure Last_Chance_Handler (Msg : System.Address; Line : Integer) is + procedure OS_Exit (Status : Integer); + pragma Import (C, OS_Exit, "exit"); + pragma No_Return (OS_Exit); + + begin + -- Save the exception message before performing the longjmp + Exception_Name := Format ("Unexpected exception in zfp profile"); + if Line = 0 then + Exception_Message := To_Ada (To_chars_ptr (Msg)); + else + Exception_Message := To_Ada (To_chars_ptr (Msg), Line); + end if; + + Jmp_Buff_Idx := Jmp_Buff_Idx - 1; + + if Jmp_Buff_Idx >= Jmp_Buffer'First then + -- No return procedure. + Builtin_Longjmp (Jmp_Buffer (Jmp_Buff_Idx)'Access, 1); + else + OS_Exit (1); + end if; + end Last_Chance_Handler; + +end AUnit.Last_Chance_Handler; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-last_chance_handler.ads b/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-last_chance_handler.ads new file mode 100644 index 000000000..c104ef362 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-last_chance_handler.ads @@ -0,0 +1,53 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- L A S T _ C H A N C E _ H A N D L E R -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2008-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- This last chance handler implementation performs a longjmp using gcc +-- builtin to allow exception simulation on platforms where the run-time does +-- not allow exception propagation. + +with System; + +package AUnit.Last_Chance_Handler is + + function Get_Exception_Name return Message_String; + function Get_Exception_Message return Message_String; + -- Return the last exception message + + generic + with procedure Proc; + function Gen_Setjmp return Integer; + -- Setjmp: init the handler, and call Proc. + + procedure Last_Chance_Handler (Msg : System.Address; Line : Integer); + pragma Export (C, Last_Chance_Handler, "__gnat_last_chance_handler"); + pragma No_Return (Last_Chance_Handler); + +end AUnit.Last_Chance_Handler; diff --git a/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-simple_test_cases-run_routine.adb b/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-simple_test_cases-run_routine.adb new file mode 100644 index 000000000..d13b7b5d9 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/framework/zfpexception/aunit-simple_test_cases-run_routine.adb @@ -0,0 +1,148 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . T E S T _ C A S E S . R U N _ R O U T I N E -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2006-2011, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with AUnit.Last_Chance_Handler; use AUnit.Last_Chance_Handler; +with AUnit.Time_Measure; + +separate (AUnit.Simple_Test_Cases) + +-- Version for run-time libraries that support exception handling via gcc +-- builtin setjmp/longjmp mechanism. + +procedure Run_Routine + (Test : access Test_Case'Class; + Options : AUnit.Options.AUnit_Options; + R : in out Result'Class; + Outcome : out Status) is + + Unexpected_Exception : Boolean := False; + Time : Time_Measure.Time := Time_Measure.Null_Time; + Res : Integer; + + use Time_Measure; + + function String_Compare (Str1, Str2 : String) return Boolean; + -- Compares two strings. + + procedure Internal_Run_Test; + -- Wrapper for running the test case + + -------------------- + -- String_Compare -- + -------------------- + + function String_Compare (Str1, Str2 : String) return Boolean is + begin + if Str1'Length /= Str2'Length then + return False; + end if; + for J in Str1'Range loop + if Str1 (J) /= Str2 (J - Str1'First + Str2'First) then + return False; + end if; + end loop; + return True; + end String_Compare; + + ----------------------- + -- Internal_Run_Test -- + ----------------------- + + procedure Internal_Run_Test is + begin + if Options.Test_Case_Timer then + Start_Measure (Time); + end if; + + AUnit.Simple_Test_Cases.Run_Test (Test.all); + + if Options.Test_Case_Timer then + Stop_Measure (Time); + end if; + end Internal_Run_Test; + + function Internal_Setjmp is new AUnit.Last_Chance_Handler.Gen_Setjmp + (Internal_Run_Test); + +begin + + -- Reset failure list to capture failed assertions for one routine + + Clear_Failures (Test.all); + + begin + Res := Internal_Setjmp; + + if Res /= 0 then + if Options.Test_Case_Timer then + Stop_Measure (Time); + end if; + + declare + Src : constant Message_String := + AUnit.Last_Chance_Handler.Get_Exception_Message; + begin + if not String_Compare (Src.all, "aunit-assertions.adb:61") then + Unexpected_Exception := True; + Add_Error + (R, + Name (Test.all), + Routine_Name (Test.all), + Error => + (Exception_Name => Get_Exception_Name, + Exception_Message => Src, + Traceback => null), + Elapsed => Time); + end if; + end; + end if; + end; + + if not Unexpected_Exception and then not Has_Failures (Test.all) then + Outcome := Success; + Add_Success (R, Name (Test.all), Routine_Name (Test.all), Time); + else + Outcome := Failure; + declare + C : Failure_Iter := First_Failure (Test.all); + begin + while Has_Failure (C) loop + Add_Failure + (R, + Name (Test.all), + Routine_Name (Test.all), + Get_Failure (C), + Time); + Next (C); + end loop; + end; + end if; +end Run_Routine; diff --git a/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-gnattest.adb b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-gnattest.adb new file mode 100644 index 000000000..5138fb9c0 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-gnattest.adb @@ -0,0 +1,253 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . R E P O R T E R . G N A T T E S T -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2012-2014, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with GNAT.IO; use GNAT.IO; +with AUnit.Time_Measure; use AUnit.Time_Measure; + +-- Reporter intended to be used by test drivers generated by gnattest. + +package body AUnit.Reporter.GNATtest is + + procedure Dump_Result_List (L : Result_Lists.List); + -- List failed assertions + + procedure Report_Test (Test : Test_Result); + -- Report a single assertion failure or unexpected exception + + procedure Put_Measure is new Gen_Put_Measure_In_Seconds; + -- Output elapsed time + + procedure Indent (N : Natural); + -- Print N indentations to output + + ------------------------ + -- Dump_Result_List -- + ------------------------ + + procedure Dump_Result_List (L : Result_Lists.List) is + + use Result_Lists; + + C : Cursor := First (L); + + begin + + -- Note: can't use Iterate because it violates restriction + -- No_Implicit_Dynamic_Code + + while Has_Element (C) loop + Report_Test (Element (C)); + Next (C); + end loop; + end Dump_Result_List; + + ------------ + -- Indent -- + ------------ + + procedure Indent (N : Natural) is + begin + for J in 1 .. N loop + Put (" "); + end loop; + end Indent; + + ------------ + -- Report -- + ------------ + + procedure Report (Engine : GNATtest_Reporter; + R : in out Result'Class; + Options : AUnit_Options := Default_Options) + is + pragma Unreferenced (Engine); + + Failures_Count : Integer; + Crashes_Count : Integer; + Passed_Count : Integer; + Tests_Count : Integer; + begin + + Tests_Count := Integer (Test_Count (R)); + Crashes_Count := Integer (Error_Count (R)); + Passed_Count := Integer (Success_Count (R)); + Failures_Count := Tests_Count - (Passed_Count + Crashes_Count); + + if Options.Report_Successes then + declare + S : Result_Lists.List; + begin + Successes (R, S); + Dump_Result_List (S); + end; + end if; + + declare + F : Result_Lists.List; + begin + Failures (R, F); + Dump_Result_List (F); + end; + + declare + E : Result_Lists.List; + begin + Errors (R, E); + Dump_Result_List (E); + end; + + Put (Tests_Count); + Put (" tests run: "); + Put (Passed_Count); + Put (" passed; "); + Put (Failures_Count); + Put (" failed; "); + Put (Crashes_Count); + Put_Line (" crashed."); + + end Report; + + ------------------ + -- Report_Test -- + ------------------ + + procedure Report_Test (Test : Test_Result) is + Is_Assert : Boolean; + Is_Condition : Boolean := False; + + T : AUnit_Duration; + N : Integer; + begin + + Put (Test.Test_Name.all); + + if Test.Failure /= null or else Test.Error /= null then + if Test.Failure /= null then + Is_Assert := True; + else + Is_Assert := False; + end if; + + if Is_Assert then + Put (" error: corresponding test FAILED: "); + else + Put (" error: corresponding test CRASHED: "); + end if; + + if Is_Assert then + + if Test.Failure.Message'Length > 9 then + N := Test.Failure.Message'First; + if + Test.Failure.Message.all (N .. N + 8) = "req_sloc(" + or else Test.Failure.Message.all (N .. N + 8) = "ens_sloc(" + then + for I in N + 9 .. Test.Failure.Message'Last - 2 loop + if Test.Failure.Message.all (I + 1 .. I + 2) = "):" then + Put (Test.Failure.Message.all + (I + 3 .. Test.Failure.Message'Last)); + + Put (" ("); + Put (Test.Failure.Message.all (N + 9 .. I)); + Put_Line (")"); + Is_Condition := True; + exit; + end if; + end loop; + end if; + end if; + + if not Is_Condition then + Put (Test.Failure.Message.all); + Put (" ("); + Put (Test.Failure.Source_Name.all); + Put (":"); + Put (Test.Failure.Line); + Put (")"); + end if; + if Test.Elapsed /= Time_Measure.Null_Time then + Put (" ("); + T := Get_Measure (Test.Elapsed); + Put_Measure (T); + Put (")"); + end if; + New_Line; + + else + Put (Test.Error.Exception_Name.all); + + if Test.Error.Exception_Message /= null then + Put (" : "); + Put (Test.Error.Exception_Message.all); + end if; + if Test.Elapsed /= Time_Measure.Null_Time then + Put (" ("); + T := Get_Measure (Test.Elapsed); + Put_Measure (T); + Put (")"); + end if; + New_Line; + + if Test.Error.Traceback /= null then + Put_Line (" Traceback:"); + + declare + From, To : Natural := Test.Error.Traceback'First; + begin + while From <= Test.Error.Traceback'Last loop + To := From; + while To <= Test.Error.Traceback'Last + and then Test.Error.Traceback (To) /= ASCII.LF + loop + To := To + 1; + end loop; + + Indent (2); + Put_Line (Test.Error.Traceback (From .. To - 1)); + From := To + 1; + end loop; + end; + end if; + + end if; + else + Put (" info: corresponding test PASSED"); + if Test.Elapsed /= Time_Measure.Null_Time then + Put (" ("); + T := Get_Measure (Test.Elapsed); + Put_Measure (T); + Put (")"); + end if; + New_Line; + end if; + + end Report_Test; +end AUnit.Reporter.GNATtest; diff --git a/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-gnattest.ads b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-gnattest.ads new file mode 100644 index 000000000..9f58b1db0 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-gnattest.ads @@ -0,0 +1,41 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . R E P O R T E R . G N A T T E S T -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2012-2013, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Reporter intended to be used by test drivers generated by gnattest. + +package AUnit.Reporter.GNATtest is + + type GNATtest_Reporter is new Reporter with null record; + + procedure Report (Engine : GNATtest_Reporter; + R : in out Result'Class; + Options : AUnit_Options := Default_Options); +end AUnit.Reporter.GNATtest; diff --git a/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-text.adb b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-text.adb new file mode 100644 index 000000000..51d66b45c --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-text.adb @@ -0,0 +1,278 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . R E P O R T E R . T E X T -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2000-2013, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with GNAT.IO; use GNAT.IO; +with AUnit.Time_Measure; use AUnit.Time_Measure; + +-- Very simple reporter to console +package body AUnit.Reporter.Text is + + procedure Indent (N : Natural); + -- Print N indentations to output + + procedure Dump_Result_List (L : Result_Lists.List; Prefix : String); + -- Dump a result list + + procedure Put_Measure is new Gen_Put_Measure; + -- Output elapsed time + + procedure Report_Test (Test : Test_Result; Prefix : String); + -- Report a single assertion failure or unexpected exception + + generic + with procedure Get (R : in out Result; L : in out Result_Lists.List); + Label : String; + Color : String; + procedure Report_Tests + (Engine : Text_Reporter; + R : in out Result'Class); + -- Report a series of tests + + ANSI_Def : constant String := ASCII.ESC & "[0m"; + ANSI_Green : constant String := ASCII.ESC & "[32m"; + ANSI_Purple : constant String := ASCII.ESC & "[35m"; + ANSI_Red : constant String := ASCII.ESC & "[31m"; + + ------------------------- + -- Set_Use_ANSI_Colors -- + ------------------------- + + procedure Set_Use_ANSI_Colors + (Engine : in out Text_Reporter; + Value : Boolean) is + begin + Engine.Use_ANSI := Value; + end Set_Use_ANSI_Colors; + + ------------ + -- Indent -- + ------------ + + procedure Indent (N : Natural) is + begin + for J in 1 .. N loop + Put (" "); + end loop; + end Indent; + + ---------------------- + -- Dump_Result_List -- + ---------------------- + + procedure Dump_Result_List (L : Result_Lists.List; Prefix : String) is + + use Result_Lists; + + C : Cursor := First (L); + begin + if Has_Element (C) then + New_Line; + end if; + + -- Note: can't use Iterate because it violates restriction + -- No_Implicit_Dynamic_Code + + while Has_Element (C) loop + Report_Test (Element (C), Prefix); + Next (C); + end loop; + end Dump_Result_List; + + --------- + -- Get -- + --------- + + procedure Report_Tests + (Engine : Text_Reporter; + R : in out Result'Class) + is + S : Result_Lists.List; + begin + Get (Result (R), S); + if Engine.Use_ANSI then + Put (Color); + end if; + + Dump_Result_List (S, Label); + + if Engine.Use_ANSI then + Put (ANSI_Def); + end if; + end Report_Tests; + + --------------------- + -- Report_OK_Tests -- + --------------------- + + procedure Report_OK_Tests + (Engine : Text_Reporter; + R : in out Result'Class) + is + procedure Internal is new Report_Tests (Successes, "OK", ANSI_Green); + begin + Internal (Engine, R); + end Report_OK_Tests; + + procedure Report_Fail_Tests + (Engine : Text_Reporter; + R : in out Result'Class) + is + procedure Internal is new Report_Tests (Failures, "FAIL", ANSI_Purple); + begin + Internal (Engine, R); + end Report_Fail_Tests; + + procedure Report_Error_Tests + (Engine : Text_Reporter; + R : in out Result'Class) + is + procedure Internal is new Report_Tests (Errors, "ERROR", ANSI_Red); + begin + Internal (Engine, R); + end Report_Error_Tests; + + ------------ + -- Report -- + ------------ + + procedure Report + (Engine : Text_Reporter; + R : in out Result'Class; + Options : AUnit_Options := Default_Options) + is + S_Count : constant Integer := Integer (Success_Count (R)); + F_Count : constant Integer := Integer (Failure_Count (R)); + E_Count : constant Integer := Integer (Error_Count (R)); + T : AUnit_Duration; + begin + + if Options.Report_Successes then + Report_OK_Tests (Text_Reporter'Class (Engine), R); + end if; + + Report_Fail_Tests (Text_Reporter'Class (Engine), R); + Report_Error_Tests (Text_Reporter'Class (Engine), R); + + New_Line; + Put ("Total Tests Run: "); + Put (Integer (Test_Count (R))); + New_Line; + Put ("Successful Tests: "); + Put (S_Count); + New_Line; + Put ("Failed Assertions: "); + Put (F_Count); + New_Line; + Put ("Unexpected Errors: "); + Put (E_Count); + New_Line; + + if Elapsed (R) /= Time_Measure.Null_Time then + T := Get_Measure (Elapsed (R)); + + Put ("Cumulative Time: "); + Put_Measure (T); + Put_Line (" seconds"); + end if; + end Report; + + ----------------- + -- Report_Test -- + ----------------- + + procedure Report_Test (Test : Test_Result; Prefix : String) is + T : AUnit_Duration; + begin + Put (Prefix); + Put (" "); + Put (Test.Test_Name.all); + + if Test.Routine_Name /= null then + Put (" : "); + Put (Test.Routine_Name.all); + end if; + + if Test.Elapsed /= Time_Measure.Null_Time then + Put (" (in "); + T := Get_Measure (Test.Elapsed); + Put_Measure (T); + Put (")"); + end if; + + New_Line; + + if Test.Failure /= null then + Indent (1); + Put_Line (Test.Failure.Message.all); + Indent (1); + Put ("at "); + Put (Test.Failure.Source_Name.all); + Put (":"); + Put (Test.Failure.Line); + New_Line; + + elsif Test.Error /= null then + Indent (1); + Put_Line (Test.Error.Exception_Name.all); + + if Test.Error.Exception_Message /= null then + Indent (1); + Put ("Exception Message: "); + Put_Line (Test.Error.Exception_Message.all); + end if; + + if Test.Error.Traceback /= null then + Indent (1); + Put_Line ("Traceback:"); + + declare + From, To : Natural := Test.Error.Traceback'First; + begin + while From <= Test.Error.Traceback'Last loop + To := From; + while To <= Test.Error.Traceback'Last + and then Test.Error.Traceback (To) /= ASCII.LF + loop + To := To + 1; + end loop; + + Indent (2); + Put_Line (Test.Error.Traceback (From .. To - 1)); + From := To + 1; + end loop; + end; + end if; + + New_Line; + end if; + end Report_Test; + +end AUnit.Reporter.Text; diff --git a/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-text.ads b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-text.ads new file mode 100644 index 000000000..8da20ab1b --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-text.ads @@ -0,0 +1,66 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . R E P O R T E R . T E X T -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2000-2013, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Very simple reporter to console +package AUnit.Reporter.Text is + + type Text_Reporter is new Reporter with private; + + procedure Set_Use_ANSI_Colors + (Engine : in out Text_Reporter; + Value : Boolean); + -- Setting this value will enable colors output on an ANSI compatible + -- terminal. + -- By default, no color is used. + + procedure Report (Engine : Text_Reporter; + R : in out Result'Class; + Options : AUnit_Options := Default_Options); + + procedure Report_OK_Tests (Engine : Text_Reporter; + R : in out Result'Class); + procedure Report_Fail_Tests (Engine : Text_Reporter; + R : in out Result'Class); + procedure Report_Error_Tests (Engine : Text_Reporter; + R : in out Result'Class); + -- These subprograms implement the various parts of the Report. You + -- can therefore chose in which order to report the various categories, + -- and whether or not to report them. + -- After calling any of these, the list of results has been modified in + -- R, so you should get the counts first. + +private + + type Text_Reporter is new Reporter with record + Use_ANSI : Boolean := False; + end record; + +end AUnit.Reporter.Text; diff --git a/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-xml.adb b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-xml.adb new file mode 100644 index 000000000..463b7897d --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-xml.adb @@ -0,0 +1,226 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . R E P O R T E R . X M L -- +-- -- +-- B o d y -- +-- -- +-- -- +-- Copyright (C) 2000-2013, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +with GNAT.IO; use GNAT.IO; +with AUnit.Time_Measure; use AUnit.Time_Measure; + +-- Very simple reporter to console +package body AUnit.Reporter.XML is + + procedure Dump_Result_List (L : Result_Lists.List); + -- List failed assertions + + procedure Put_Measure is new Gen_Put_Measure; + -- Output elapsed time + + procedure Report_Test (Test : Test_Result); + -- Report a single assertion failure or unexpected exception + + ---------------------- + -- Dump_Result_List -- + ---------------------- + + procedure Dump_Result_List (L : Result_Lists.List) is + + use Result_Lists; + + C : Cursor := First (L); + + begin + + -- Note: can't use Iterate because it violates restriction + -- No_Implicit_Dynamic_Code + + while Has_Element (C) loop + Report_Test (Element (C)); + Next (C); + end loop; + end Dump_Result_List; + + ------------ + -- Report -- + ------------ + + procedure Report (Engine : XML_Reporter; + R : in out Result'Class; + Options : AUnit_Options := Default_Options) + is + pragma Unreferenced (Engine); + T : AUnit_Duration; + begin + Put_Line (""); + Put (""); + else + Put_Line (">"); + end if; + + Put_Line (" "); + Put (" "); + Put (Integer (Test_Count (R))); + Put_Line (""); + Put (" "); + Put (Integer (Failure_Count (R)) + Integer (Error_Count (R))); + Put_Line (""); + Put (" "); + Put (Integer (Failure_Count (R))); + Put_Line (""); + Put (" "); + Put (Integer (Error_Count (R))); + Put_Line (""); + Put_Line (" "); + + declare + S : Result_Lists.List; + begin + Put_Line (" "); + if Options.Report_Successes then + Successes (R, S); + Dump_Result_List (S); + end if; + Put_Line (" "); + end; + + Put_Line (" "); + declare + F : Result_Lists.List; + begin + Failures (R, F); + Dump_Result_List (F); + end; + + declare + E : Result_Lists.List; + begin + Errors (R, E); + Dump_Result_List (E); + end; + Put_Line (" "); + + Put_Line (""); + end Report; + + ------------------ + -- Report_Error -- + ------------------ + + procedure Report_Test (Test : Test_Result) is + Is_Assert : Boolean; + T : AUnit_Duration; + begin + Put (" "); + else + Put_Line (">"); + end if; + + Put (" "); + Put (Test.Test_Name.all); + + if Test.Routine_Name /= null then + Put (" : "); + Put (Test.Routine_Name.all); + end if; + + Put_Line (""); + + if Test.Failure /= null or else Test.Error /= null then + if Test.Failure /= null then + Is_Assert := True; + else + Is_Assert := False; + end if; + + Put (" "); + + if Is_Assert then + Put ("Assertion"); + else + Put ("Error"); + end if; + + Put_Line (""); + Put (" "); + if Is_Assert then + Put (Test.Failure.Message.all); + else + Put (Test.Error.Exception_Name.all); + end if; + Put_Line (""); + + if Is_Assert then + Put_Line (" "); + Put (" "); + Put (Test.Failure.Source_Name.all); + Put_Line (""); + Put (" "); + Put (Test.Failure.Line); + Put_Line (""); + Put_Line (" "); + + else + Put_Line (" "); + Put (" "); + Put (Test.Error.Exception_Name.all); + Put_Line (""); + + if Test.Error.Exception_Message /= null then + Put (" "); + Put (Test.Error.Exception_Message.all); + Put_Line (""); + end if; + + if Test.Error.Traceback /= null then + Put (" "); + Put (Test.Error.Traceback.all); + Put_Line (""); + end if; + + Put_Line (" "); + end if; + end if; + + Put_Line (" "); + end Report_Test; + +end AUnit.Reporter.XML; diff --git a/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-xml.ads b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-xml.ads new file mode 100644 index 000000000..41c583727 --- /dev/null +++ b/ada/libaunit-3.7.2/include/aunit/reporters/aunit-reporter-xml.ads @@ -0,0 +1,40 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT COMPILER COMPONENTS -- +-- -- +-- A U N I T . R E P O R T E R . X M L -- +-- -- +-- S p e c -- +-- -- +-- -- +-- Copyright (C) 2000-2013, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- -- +-- -- +-- -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- . -- +-- -- +-- GNAT is maintained by AdaCore (http://www.adacore.com) -- +-- -- +------------------------------------------------------------------------------ + +-- Very simple reporter to console +package AUnit.Reporter.XML is + + type XML_Reporter is new Reporter with null record; + + procedure Report (Engine : XML_Reporter; + R : in out Result'Class; + Options : AUnit_Options := Default_Options); +end AUnit.Reporter.XML; diff --git a/ada/libaunit-3.7.2/known-problems-31 b/ada/libaunit-3.7.2/known-problems-31 new file mode 100644 index 000000000..137a67858 --- /dev/null +++ b/ada/libaunit-3.7.2/known-problems-31 @@ -0,0 +1,31 @@ +=================================== +Known problems in AUnit version 3.1 +=================================== + +Copyright (c) 2008-2009, AdaCore + +The following is a listing of known problems in release 3.1.1. Except where +specifically noted, all these problems have been corrected in the development +tree of the 3.2 technology. This means they are corrected in any 3.2.0w +wavefront issued subsequent to the date specified (in ISO format YYYY-MM-DD) +in the status line. This can be used to determine if a given wavefront has +the fix identified in the entry. + +KP-31-I814-014 AUnit fails to install for LynxOS + + Problem: The pthread run-time library was not included as an option in + the AUnit shared project file template. + + Status: This was fixed in 3.2 on 2009-08-14 + + Workaround: Manual build of AUnit from sources + +KP-31-I803-020 Installation failure on Solaris + + Problem: On Solaris, 'make install' fails to install AUnit. This is due + to 'sed' not being able to work on files not terminated by a + trailing LF character. + + Status: This was fixed in 3.2 on 2009-08-04 + + Workaround: Use GNU sed for Solaris and retry installing. diff --git a/ada/libaunit-3.7.2/known-problems-32 b/ada/libaunit-3.7.2/known-problems-32 new file mode 100644 index 000000000..065ad707c --- /dev/null +++ b/ada/libaunit-3.7.2/known-problems-32 @@ -0,0 +1,18 @@ +=================================== +Known problems in AUnit version 3.2 +=================================== + +Copyright (C) 2014, AdaCore + +The following is a listing of known problems in release 3.2.1. +Each entry contains a status line stating when the problem was fixed, and on +which release(s). In addition, any wavefront issued subsequent to the date +specified (in ISO format YYYY-MM-DD) also contains the fix. This can be used +to determine if a given release or wavefront has the fix identified in the +entry. + +Note that older releases might or might not be affected by the problems listed +in this document. + +Known problems fixed in 3.2.1 and above +--------------------------------------- diff --git a/ada/libaunit-3.7.2/known-problems-34 b/ada/libaunit-3.7.2/known-problems-34 new file mode 100644 index 000000000..6e0f61e65 --- /dev/null +++ b/ada/libaunit-3.7.2/known-problems-34 @@ -0,0 +1,31 @@ +=================================== +Known problems in AUnit version 3.4 +=================================== + +Copyright (C) 2001-2012, AdaCore + +The following is a listing of known problems in release 3.4.1. Except where +specifically noted, all these problems have been corrected in the development +tree of the 3.5 technology. This means they are corrected in any 3.5.0w +wavefront issued subsequent to the date specified (in ISO format YYYY-MM-DD) +in the status line. This can be used to determine if a given wavefront has +the fix identified in the entry. + +KP-34-L306-042 Installer issues on Windows + + Problem: It happens on rare occasions that the Windows installer cannot + find any compiler on your system, even if the PATH environment + variable is correctly set and gprbuild is present. + + Status: This was fixed in 3.5 on 2012-03-12 + + Workaround: Use the source package and install AUnit using the Makefile. + +KP-34-L326-023 Incorrect XML generated + + Problem: The XML output is incorrect + + Status: This was fixed in 3.5 on 2012-03-27 + + Workaround: Use the text output, or rebuild AUnit with aunit-reporter-xml.adb + from a more recent release. diff --git a/ada/libaunit-3.7.2/known-problems-35 b/ada/libaunit-3.7.2/known-problems-35 new file mode 100644 index 000000000..634beb7ba --- /dev/null +++ b/ada/libaunit-3.7.2/known-problems-35 @@ -0,0 +1,18 @@ +=================================== +Known problems in AUnit version 3.5 +=================================== + +Copyright (C) 2014, AdaCore + +The following is a listing of known problems in release 3.5.1. +Each entry contains a status line stating when the problem was fixed, and on +which release(s). In addition, any wavefront issued subsequent to the date +specified (in ISO format YYYY-MM-DD) also contains the fix. This can be used +to determine if a given release or wavefront has the fix identified in the +entry. + +Note that older releases might or might not be affected by the problems listed +in this document. + +Known problems fixed in 3.5.1 and above +--------------------------------------- diff --git a/ada/libaunit-3.7.2/known-problems-36 b/ada/libaunit-3.7.2/known-problems-36 new file mode 100644 index 000000000..f0c8757a9 --- /dev/null +++ b/ada/libaunit-3.7.2/known-problems-36 @@ -0,0 +1,18 @@ +=================================== +Known problems in AUnit version 3.6 +=================================== + +Copyright (C) 2013-2014, AdaCore + +The following is a listing of known problems in release 3.6.1. +Each entry contains a status line stating when the problem was fixed, and on +which release(s). In addition, any wavefront issued subsequent to the date +specified (in ISO format YYYY-MM-DD) also contains the fix. This can be used +to determine if a given release or wavefront has the fix identified in the +entry. + +Note that older releases might or might not be affected by the problems listed +in this document. + +Known problems fixed in 3.7.1 and above +--------------------------------------- diff --git a/ada/libaunit-3.7.2/lib/gnat/aunit.gpr b/ada/libaunit-3.7.2/lib/gnat/aunit.gpr new file mode 100644 index 000000000..fca9674b3 --- /dev/null +++ b/ada/libaunit-3.7.2/lib/gnat/aunit.gpr @@ -0,0 +1,72 @@ + +with "aunit_shared"; + +project AUnit is + + type Compilation_Mode_Type is ("Devel", "Install"); + Mode : Compilation_Mode_Type := external ("MODE", "Install"); + + for Source_Dirs use + ("../../include/aunit/framework", + "../../include/aunit/containers", + "../../include/aunit/reporters", + "../../include/aunit/framework/" & AUnit_Shared.Except, + "../../include/aunit/framework/" & AUnit_Shared.Calend, + "../../include/aunit/framework/" & AUnit_Shared.Memory); + + for Library_Dir use "../aunit/" & + Aunit_Shared.Target & "-" + & Aunit_Shared.Runtime & "-" + & Aunit_Shared.Library_Kind; + + for Object_Dir use "../aunit-obj/" + & AUnit_Shared.Target & "-" + & AUnit_Shared.Runtime & "-" + & Aunit_Shared.Library_Kind; + + for Library_Name use "aunit"; + for Library_Kind use AUnit_Shared.Library_Kind; + case AUnit_Shared.Library_Kind is + when "dynamic" => + for Library_Version use "lib" & Project'Library_Name & ".so." + & Aunit_Shared.Soversion; + for Leading_Library_Options use Aunit_Shared.Ldflags; + when "static" => + null; + end case; + + -------------- + -- Compiler -- + -------------- + + package Compiler is + case Mode is + when "Devel" => + for Default_Switches ("ada") use + ("-g", "-gnatQ", "-O1", "-gnatf", "-gnato", + "-gnatwa.Xe", "-gnaty"); + + when "Install" => + for Default_Switches ("ada") use + ("-O2", "-gnatp", "-gnatn", "-gnatwa.X"); + end case; + for Default_Switches ("ada") use Compiler'Default_Switches ("ada") + & Aunit_Shared.Adaflags; + + for Switches ("aunit.adb") use + Compiler'Default_Switches ("ada") & ("-fno-strict-aliasing"); + end Compiler; + + ------------- + -- Install -- + ------------- + + package Install is + for Artifacts ("share/doc/aunit") use + ("../../docs/*.html", "../../docs/*.info", + "../../docs/*.pdf", "../../docs/*.txt"); + for Artifacts ("share/gps/plug-ins") use ("../../support/aunit.xml"); + for Artifacts ("share/examples/aunit") use ("../../examples/*"); + end Install; + +end AUnit; diff --git a/ada/libaunit-3.7.2/lib/gnat/aunit_shared.gpr b/ada/libaunit-3.7.2/lib/gnat/aunit_shared.gpr new file mode 100644 index 000000000..799ebf287 --- /dev/null +++ b/ada/libaunit-3.7.2/lib/gnat/aunit_shared.gpr @@ -0,0 +1,47 @@ +project AUnit_Shared is + + Target := external ("PLATFORM", "native"); + + type Runtime_Type is + ("cert", "default", "full", "hi", "kernel", "kernel-sjlj", "kernel-smp", + "pthread", "sjlj", "ravenscar", "ravenscar-apex", "ravenscar-full", + "ravenscar-cert", "ravenscar-cert-rci", "ravenscar-cert-rtp", + "ravenscar-sfp", "rtp", + "rtp-smp", "soft-float", "xenomai", "zcx", "zfp", "minimal"); + Runtime : Runtime_Type := external ("RUNTIME", "full"); + + type A_Library_Kind is ("dynamic", "static"); + Library_Kind : A_Library_Kind := External ("LIBRARY_KIND"); + Soversion := External ("SOVERSION", "3.7.2"); + Adaflags := External_As_List ("ADAFLAGS", " "); + Ldflags := External_As_List ("LDFLAGS", " "); + + for Source_Dirs use (); + + type Exception_Type is ("fullexception", "certexception", "zfpexception"); + type Calendar_Type is ("calendar", "nocalendar"); + type Memory_type is ("nativememory", "staticmemory"); + + Except : Exception_Type := "fullexception"; + Calend : Calendar_Type := "calendar"; + Memory : Memory_Type := "nativememory"; + + case Runtime is + when "hi" | "ravenscar-sfp" | "zfp" | "minimal" => + Except := "zfpexception"; + Calend := "nocalendar"; + Memory := "staticmemory"; + when "ravenscar-full" | "ravenscar" => + Except := "certexception"; + Calend := "nocalendar"; + when "ravenscar-cert" | "ravenscar-cert-rci" | "ravenscar-cert-rtp" => + Except := "certexception"; + Calend := "nocalendar"; + Memory := "staticmemory"; + when "cert" => + Except := "certexception"; + Memory := "staticmemory"; + when others => + end case; + +end AUnit_Shared; diff --git a/ada/libaunit-3.7.2/support/aunit.xml b/ada/libaunit-3.7.2/support/aunit.xml new file mode 100644 index 000000000..a9a81e01f --- /dev/null +++ b/ada/libaunit-3.7.2/support/aunit.xml @@ -0,0 +1,15 @@ + + + share/doc/libaunit-doc + + + /Help/AUnit + + + + aunit.html + AUnit User's Guide + AUnit +

/Help/AUnit/AUnit User's Guide + + diff --git a/ada/libaunit-3.7.2/support/exclude.txt b/ada/libaunit-3.7.2/support/exclude.txt new file mode 100644 index 000000000..90ec22bee --- /dev/null +++ b/ada/libaunit-3.7.2/support/exclude.txt @@ -0,0 +1 @@ +.svn diff --git a/ada/libaunit-3.7.2/template/harness.adb b/ada/libaunit-3.7.2/template/harness.adb new file mode 100644 index 000000000..6102c875c --- /dev/null +++ b/ada/libaunit-3.7.2/template/harness.adb @@ -0,0 +1,14 @@ +with AUnit.Reporter.Text; +with AUnit.Run; + +-- Suite for this level of tests: +with Sample_Suite; + +procedure Harness is + + procedure Run is new AUnit.Run.Test_Runner (Sample_Suite.Suite); + Reporter : AUnit.Reporter.Text.Text_Reporter; + +begin + Run (Reporter); +end Harness; diff --git a/ada/libaunit-3.7.2/template/pr_xxxx_xxx.adb b/ada/libaunit-3.7.2/template/pr_xxxx_xxx.adb new file mode 100644 index 000000000..70754ff4b --- /dev/null +++ b/ada/libaunit-3.7.2/template/pr_xxxx_xxx.adb @@ -0,0 +1,53 @@ +with AUnit.Assertions; use AUnit.Assertions; + +-- Template for test case body. +package body PR_XXXX_XXX is + + -- Example test routine. Provide as many as are needed: + procedure Test1 (R : in out AUnit.Test_Cases.Test_Case'Class); + + procedure Set_Up (T : in out Test_Case) is + begin + -- Do any necessary set ups. If there are none, + -- omit from both spec and body, as a default + -- version is provided in Test_Cases. + null; + end Set_Up; + + procedure Tear_Down (T : in out Test_Case) is + begin + -- Do any necessary cleanups, so the next test + -- has a clean environment. If there is no + -- cleanup, omit spec and body, as default is + -- provided in Test_Cases. + null; + end Tear_Down; + + + -- Example test routine. Provide as many as are needed: + procedure Test1 (R : in out AUnit.Test_Cases.Test_Case'Class) is + begin + -- Do something: + null; + + -- Test for expected conditions. Multiple assertions + -- and actions are ok: + Assert (True, "Indication of what failed"); + end Test1; + + + -- Register test routines to call: + procedure Register_Tests (T : in out Test_Case) is + use Test_Cases, Test_Cases.Registration; + begin + -- Repeat for each test routine. + Register_Routine (T, Test1'Access, "Description of test routine"); + end Register_Tests; + + -- Identifier of test case: + function Name (T : Test_Case) return Message_String is + begin + return Format ("Test case name"); + end Name; + +end PR_XXXX_XXX; diff --git a/ada/libaunit-3.7.2/template/pr_xxxx_xxx.ads b/ada/libaunit-3.7.2/template/pr_xxxx_xxx.ads new file mode 100644 index 000000000..5e4e5a5d3 --- /dev/null +++ b/ada/libaunit-3.7.2/template/pr_xxxx_xxx.ads @@ -0,0 +1,23 @@ +with AUnit; use AUnit; +with AUnit.Test_Cases; + +package PR_XXXX_XXX is + type Test_Case is new AUnit.Test_Cases.Test_Case with null record; + + -- Override: + + -- Register routines to be run: + procedure Register_Tests (T : in out Test_Case); + + -- Provide name identifying the test case: + function Name (T : Test_Case) return Message_String; + + -- Override if needed. Default empty implementations provided: + + -- Preparation performed before each routine: + procedure Set_Up (T : in out Test_Case); + + -- Cleanup performed after each routine: + procedure Tear_Down (T : in out Test_Case); + +end PR_XXXX_XXX; diff --git a/ada/libaunit-3.7.2/template/sample.gpr b/ada/libaunit-3.7.2/template/sample.gpr new file mode 100644 index 000000000..63f7b8f44 --- /dev/null +++ b/ada/libaunit-3.7.2/template/sample.gpr @@ -0,0 +1,29 @@ +with "aunit.gpr"; + +project Sample is + + for Languages use ("Ada"); + for Source_Dirs use ("./"); + for Object_Dir use "./"; + for Exec_Dir use "./"; + for Main use ("harness.adb"); + + package Builder is + for Default_Switches ("ada") use ("-g", "-gnatQ"); + for Executable ("harness.adb") use "harness"; + end Builder; + + package Linker is + for Default_Switches ("ada") use ("-g"); + end Linker; + + package Compiler is + for Default_Switches ("ada") use ("-gnatf", "-g"); + end Compiler; + + package Binder is + for Default_Switches ("ada") use ("-E", "-static"); + end Binder; + +end Sample; + diff --git a/ada/libaunit-3.7.2/template/sample_suite.adb b/ada/libaunit-3.7.2/template/sample_suite.adb new file mode 100644 index 000000000..ed003b9fa --- /dev/null +++ b/ada/libaunit-3.7.2/template/sample_suite.adb @@ -0,0 +1,15 @@ +with PR_XXXX_XXX; + +package body Sample_Suite is + + Result : aliased Test_Suite; + + Test_Case : aliased PR_XXXX_XXX.Test_Case; + + function Suite return Access_Test_Suite is + begin + Add_Test (Result'Access, Test_Case'Access); + return Result'Access; + end Suite; + +end Sample_Suite; diff --git a/ada/libaunit-3.7.2/template/sample_suite.ads b/ada/libaunit-3.7.2/template/sample_suite.ads new file mode 100644 index 000000000..b31cbd76a --- /dev/null +++ b/ada/libaunit-3.7.2/template/sample_suite.ads @@ -0,0 +1,5 @@ +with AUnit.Test_Suites; use AUnit.Test_Suites; + +package Sample_Suite is + function Suite return Access_Test_Suite; +end Sample_Suite; diff --git a/ada/libaunit-3.7.2/test/aunit_tests.gpr b/ada/libaunit-3.7.2/test/aunit_tests.gpr new file mode 100644 index 000000000..82e7b6d61 --- /dev/null +++ b/ada/libaunit-3.7.2/test/aunit_tests.gpr @@ -0,0 +1,25 @@ +with "aunit"; + +project Aunit_Tests is + + for Languages use ("Ada"); + for Main use ("aunit_harness.adb"); + for Source_Dirs use ("src"); + for Exec_Dir use "exe"; + for Object_Dir use "obj"; + + package Linker is + for Default_Switches ("ada") use ("-g"); + end Linker; + + package Binder is + for Default_Switches ("ada") use ("-E", "-static"); + end Binder; + + package Compiler is + for Default_Switches ("ada") use + ("-g", "-gnatQ", "-O1", "-gnatf", "-gnato", "-gnatwa.Xe", "-gnaty"); + end Compiler; + +end Aunit_Tests; + diff --git a/ada/libaunit-3.7.2/test/expected.out b/ada/libaunit-3.7.2/test/expected.out new file mode 100644 index 000000000..1fde09fb0 --- /dev/null +++ b/ada/libaunit-3.7.2/test/expected.out @@ -0,0 +1,8 @@ +Total Tests Run: 15 +Successful Tests: 15 +Failed Assertions: 0 +Unexpected Errors: 0 +Total Tests Run: 1 +Successful Tests: 1 +Failed Assertions: 0 +Unexpected Errors: 0 diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests-suite.adb b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests-suite.adb new file mode 100644 index 000000000..7e1db2d6a --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests-suite.adb @@ -0,0 +1,39 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Test_Caller; + +package body AUnit.Test_Cases.Tests.Suite is + + package Caller is new AUnit.Test_Caller + (AUnit.Test_Cases.Tests.Fixture); + + function Test_Suite return AUnit.Test_Suites.Access_Test_Suite is + S : constant AUnit.Test_Suites.Access_Test_Suite := + AUnit.Test_Suites.New_Suite; + begin + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(test_case) Test routines registration", + Test_Register_Tests'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(test_case) Test set_up phase", + Test_Set_Up'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(test_case) Test tear_down phase", + Test_Torn_Down'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(test_case) Test run phase", + Test_Run'Access)); + return S; + end Test_Suite; + +end AUnit.Test_Cases.Tests.Suite; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests-suite.ads b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests-suite.ads new file mode 100644 index 000000000..d76f2e0fb --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests-suite.ads @@ -0,0 +1,11 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Test_Suites; + +package AUnit.Test_Cases.Tests.Suite is + + function Test_Suite return AUnit.Test_Suites.Access_Test_Suite; + +end AUnit.Test_Cases.Tests.Suite; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests.adb b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests.adb new file mode 100644 index 000000000..4587556a5 --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests.adb @@ -0,0 +1,90 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Assertions; use AUnit.Assertions; + +package body AUnit.Test_Cases.Tests is + + ------------------------- + -- Test_Register_Tests -- + ------------------------- + + procedure Test_Register_Tests (T : in out Fixture) + is + Old_Count : constant Count_Type := + Registration.Routine_Count (T.TC); + Routines_In_Simple : constant := 4; + begin + Register_Tests (T.TC); + + Assert + (Test_Cases.Registration.Routine_Count (T.TC) = + Old_Count + Routines_In_Simple, + "Routine not properly registered"); + end Test_Register_Tests; + + ----------------- + -- Test_Set_Up -- + ----------------- + + procedure Test_Set_Up (T : in out Fixture) is + Was_Reset : constant Boolean := not Is_Set_Up (T.TC); + begin + Set_Up (T.TC); + + Assert + (Was_Reset and Is_Set_Up (T.TC), + "Not set up correctly"); + end Test_Set_Up; + + -------------------- + -- Test_Torn_Down -- + -------------------- + + procedure Test_Torn_Down (T : in out Fixture) is + Was_Reset : constant Boolean := not Is_Torn_Down (T.TC); + begin + Tear_Down (T.TC); + + Assert + (Was_Reset and Is_Torn_Down (T.TC), + "Not torn down correctly"); + end Test_Torn_Down; + + -------------- + -- Test_Run -- + -------------- + + procedure Test_Run (T : in out Fixture) is + Count : constant Count_Type := + Test_Cases.Registration.Routine_Count (T.TC); + Outcome : AUnit.Status; + R : Result; + + begin + Run (T.TC'Access, AUnit.Options.Default_Options, R, Outcome); + + Assert + (Count = 4, + "Not enough routines in simple test case"); + + Assert + (Test_Count (R) = Count, + "Not all requested routines were run"); + + -- There are supposed to be two failed assertions for one routine + -- in R, so we expect Count + Old_Count + 1: + Assert + (Success_Count (R) + Failure_Count (R) + Error_Count (R) + = Count + 1, + "Not all requested routines are recorded"); + + Assert (Is_Torn_Down (T.TC), "Not torn down correctly"); + Assert (Success_Count (R) = 1, "Wrong success count"); + Assert (Failure_Count (R) = 3, "Wrong failures count"); + Assert (Error_Count (R) = 1, "Wrong errors count"); + Assert (Outcome = Failure, "Result flag incorrect"); + end Test_Run; + +end AUnit.Test_Cases.Tests; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests.ads b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests.ads new file mode 100644 index 000000000..b8dc5229e --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests.ads @@ -0,0 +1,19 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Test_Fixtures; +with AUnit.Test_Cases.Tests_Fixtures; use AUnit.Test_Cases.Tests_Fixtures; + +package AUnit.Test_Cases.Tests is + + type Fixture is new AUnit.Test_Fixtures.Test_Fixture with record + TC : aliased The_Test_Case; + end record; + + procedure Test_Register_Tests (T : in out Fixture); + procedure Test_Set_Up (T : in out Fixture); + procedure Test_Torn_Down (T : in out Fixture); + procedure Test_Run (T : in out Fixture); + +end AUnit.Test_Cases.Tests; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests_fixtures.adb b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests_fixtures.adb new file mode 100644 index 000000000..4c915bc17 --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests_fixtures.adb @@ -0,0 +1,137 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Assertions; use AUnit.Assertions; + +package body AUnit.Test_Cases.Tests_Fixtures is + + procedure Double_Failure_Wrapper (T : in out The_Test_Case'Class); + + use AUnit.Test_Cases.Registration; + + ------------ + -- Set_Up -- + ------------ + + procedure Set_Up (T : in out The_Test_Case) is + begin + T.Is_Set_Up := True; + end Set_Up; + + --------------- + -- Tear_Down -- + --------------- + + procedure Tear_Down (T : in out The_Test_Case) is + begin + T.Is_Torn_Down := True; + end Tear_Down; + + ------------- + -- Succeed -- + ------------- + + procedure Succeed (T : in out Test_Cases.Test_Case'Class) is + pragma Unreferenced (T); + begin + null; + end Succeed; + + ---------- + -- Fail -- + ---------- + + procedure Fail (T : in out Test_Cases.Test_Case'Class) is + pragma Unreferenced (T); + begin + Assert (False, "Failure test failed"); + end Fail; + + ---------------------------- + -- Double_Failure_Wrapper -- + ---------------------------- + + procedure Double_Failure_Wrapper (T : in out The_Test_Case'Class) is + begin + Double_Failure (T); + end Double_Failure_Wrapper; + + -------------------- + -- Double_Failure -- + -------------------- + + procedure Double_Failure (T : in out The_Test_Case) is + Dummy : Boolean; + pragma Unreferenced (T, Dummy); + begin + -- Fail two assertions. Will be checked in Test_Test_Case.Test_Run + Dummy := Assert (False, "first failure"); + Assert (False, "second failure"); + end Double_Failure; + + ------------ + -- Except -- + ------------ + + procedure Except (T : in out Test_Cases.Test_Case'Class) is + pragma Unreferenced (T); + begin + raise Constraint_Error; + end Except; + + -------------------- + -- Register_Tests -- + -------------------- + + procedure Register_Tests (T : in out The_Test_Case) is + package Register_Specific is + new AUnit.Test_Cases.Specific_Test_Case_Registration + (The_Test_Case); + use Register_Specific; + begin + + Register_Routine + (T, Succeed'Access, "Success Test"); + + Register_Routine + (T, Fail'Access, "Failure Test"); + + Register_Wrapper + (T, + Double_Failure_Wrapper'Access, + "Multiple assertion failures"); + + Register_Routine + (T, Except'Access, "Exception Test"); + end Register_Tests; + + ---------- + -- Name -- + ---------- + + function Name (T : The_Test_Case) return Test_String is + pragma Unreferenced (T); + begin + return Format ("Dummy Test Case"); + end Name; + + --------------- + -- Is_Set_Up -- + --------------- + + function Is_Set_Up (T : The_Test_Case) return Boolean is + begin + return T.Is_Set_Up; + end Is_Set_Up; + + ------------------ + -- Is_Torn_Down -- + ------------------ + + function Is_Torn_Down (T : The_Test_Case) return Boolean is + begin + return T.Is_Torn_Down; + end Is_Torn_Down; + +end AUnit.Test_Cases.Tests_Fixtures; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests_fixtures.ads b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests_fixtures.ads new file mode 100644 index 000000000..5a9e0ee9a --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_cases-tests_fixtures.ads @@ -0,0 +1,47 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +package AUnit.Test_Cases.Tests_Fixtures is + + type The_Test_Case is new Test_Cases.Test_Case with record + Is_Set_Up, + Is_Torn_Down : Boolean := False; + end record; + type The_Test_Case_Access is access all The_Test_Case'Class; + + procedure Register_Tests (T : in out The_Test_Case); + -- Register routines to be run + + function Name (T : The_Test_Case) return Test_String; + -- Provide name identifying the test case + + procedure Set_Up (T : in out The_Test_Case); + -- Preparation performed before each routine + + procedure Tear_Down (T : in out The_Test_Case); + -- Cleanup performed after each routine + + function Is_Set_Up (T : The_Test_Case) return Boolean; + -- Set up? + + function Is_Torn_Down (T : The_Test_Case) return Boolean; + -- Torn down? + + -------------------- + -- Test Routines -- + -------------------- + + procedure Fail (T : in out Test_Cases.Test_Case'Class); + -- This routine produces a failure + + procedure Succeed (T : in out Test_Cases.Test_Case'Class); + -- This routine does nothing, so succeeds + + procedure Double_Failure (T : in out The_Test_Case); + -- This routine produces two failrues + + procedure Except (T : in out Test_Cases.Test_Case'Class); + -- This routine raises an exception + +end AUnit.Test_Cases.Tests_Fixtures; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests-suite.adb b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests-suite.adb new file mode 100644 index 000000000..909111257 --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests-suite.adb @@ -0,0 +1,39 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Test_Caller; + +package body AUnit.Test_Fixtures.Tests.Suite is + + package Caller is new AUnit.Test_Caller + (AUnit.Test_Fixtures.Tests.Fixture); + + function Test_Suite return AUnit.Test_Suites.Access_Test_Suite is + S : constant AUnit.Test_Suites.Access_Test_Suite := + AUnit.Test_Suites.New_Suite; + begin + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(test_fixture) Test Set_Up call", + Test_Set_Up'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(test_fixture) Test Tear_Down call (the called test is success)", + Test_Tear_Down_Success'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(test_fixture) Test Tear_Down call (the called test is failure)", + Test_Tear_Down_Failure'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(test_fixture) Test Tear_Down call (the called test is error)", + Test_Tear_Down_Error'Access)); + return S; + end Test_Suite; + +end AUnit.Test_Fixtures.Tests.Suite; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests-suite.ads b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests-suite.ads new file mode 100644 index 000000000..d555b59e6 --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests-suite.ads @@ -0,0 +1,11 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Test_Suites; + +package AUnit.Test_Fixtures.Tests.Suite is + + function Test_Suite return AUnit.Test_Suites.Access_Test_Suite; + +end AUnit.Test_Fixtures.Tests.Suite; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests.adb b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests.adb new file mode 100644 index 000000000..f5e72e5fe --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests.adb @@ -0,0 +1,106 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with Ada_Containers; use Ada_Containers; +with AUnit.Assertions; use AUnit.Assertions; +with AUnit.Options; +with AUnit.Test_Results; + +with AUnit.Test_Fixtures.Tests_Fixtures; +use AUnit.Test_Fixtures.Tests_Fixtures; + +package body AUnit.Test_Fixtures.Tests is + + use AUnit.Test_Fixtures.Tests_Fixtures.Caller; + + ----------------- + -- Test_Set_Up -- + ----------------- + + procedure Test_Set_Up (T : in out Fixture) is + R : AUnit.Test_Results.Result; + Outcome : AUnit.Status; + Old : constant Natural := Get_Nb_Set_Up_Called; + pragma Unreferenced (T); + + begin + Run (TC_Success, AUnit.Options.Default_Options, R, Outcome); + Run (TC_Failure, AUnit.Options.Default_Options, R, Outcome); + Assert (Get_Nb_Set_Up_Called = Old + 2, + "Incorrect number of calls to set_up"); + end Test_Set_Up; + + ---------------------------- + -- Test_Tear_Down_Success -- + ---------------------------- + + procedure Test_Tear_Down_Success (T : in out Fixture) is + R : AUnit.Test_Results.Result; + Outcome : AUnit.Status; + Old : constant Natural := Get_Nb_Tear_Down_Called; + pragma Unreferenced (T); + + begin + Run (TC_Success, AUnit.Options.Default_Options, R, Outcome); + Assert (Get_Nb_Tear_Down_Called = Old + 1, + "Incorrect number of calls to tear_down"); + Assert (Outcome = Success, + "Outcome value is incorrect"); + Assert (AUnit.Test_Results.Test_Count (R) = 1, + "Incorrect number of tests reported"); + Assert (AUnit.Test_Results.Failure_Count (R) = 0, + "Incorrect number of failures reported"); + Assert (AUnit.Test_Results.Error_Count (R) = 0, + "Incorrect number of errors reported"); + end Test_Tear_Down_Success; + + ---------------------------- + -- Test_Tear_Down_Failure -- + ---------------------------- + + procedure Test_Tear_Down_Failure (T : in out Fixture) is + R : AUnit.Test_Results.Result; + Outcome : AUnit.Status; + Old : constant Natural := Get_Nb_Tear_Down_Called; + pragma Unreferenced (T); + + begin + Run (TC_Failure, AUnit.Options.Default_Options, R, Outcome); + Assert (Get_Nb_Tear_Down_Called = Old + 1, + "Incorrect number of calls to tear_down"); + Assert (Outcome = Failure, + "Outcome value is incorrect"); + Assert (AUnit.Test_Results.Test_Count (R) = 1, + "Incorrect number of tests reported"); + Assert (AUnit.Test_Results.Failure_Count (R) = 1, + "Incorrect number of failures reported"); + Assert (AUnit.Test_Results.Error_Count (R) = 0, + "Incorrect number of errors reported"); + end Test_Tear_Down_Failure; + + -------------------------- + -- Test_Tear_Down_Error -- + -------------------------- + + procedure Test_Tear_Down_Error (T : in out Fixture) is + R : AUnit.Test_Results.Result; + Outcome : AUnit.Status; + Old : constant Natural := Get_Nb_Tear_Down_Called; + pragma Unreferenced (T); + + begin + Run (TC_Error, AUnit.Options.Default_Options, R, Outcome); + Assert (Get_Nb_Tear_Down_Called = Old + 1, + "Incorrect number of calls to tear_down"); + Assert (Outcome = Failure, + "Outcome value is incorrect"); + Assert (AUnit.Test_Results.Test_Count (R) = 1, + "Incorrect number of tests reported"); + Assert (AUnit.Test_Results.Failure_Count (R) = 0, + "Incorrect number of failures reported"); + Assert (AUnit.Test_Results.Error_Count (R) = 1, + "Incorrect number of errors reported"); + end Test_Tear_Down_Error; + +end AUnit.Test_Fixtures.Tests; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests.ads b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests.ads new file mode 100644 index 000000000..864f8564c --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests.ads @@ -0,0 +1,25 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +package AUnit.Test_Fixtures.Tests is + + type Fixture is new AUnit.Test_Fixtures.Test_Fixture with null record; + + procedure Test_Set_Up (T : in out Fixture); + -- Test that Set_Up is correctly called when running a test, and that the + -- same fixture object is used for different tests. + + procedure Test_Tear_Down_Success (T : in out Fixture); + -- Test that Tear_Down is correctly called when running a test that + -- succeeds, and that test result is correct. + + procedure Test_Tear_Down_Failure (T : in out Fixture); + -- Test that Tear_Down is correctly called when running a test that + -- fails, and that test result is correct. + + procedure Test_Tear_Down_Error (T : in out Fixture); + -- Test that Tear_Down is correctly called when running a test with + -- an error, and that test result is correct. + +end AUnit.Test_Fixtures.Tests; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests_fixtures.adb b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests_fixtures.adb new file mode 100644 index 000000000..31cbdc6f8 --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests_fixtures.adb @@ -0,0 +1,80 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Assertions; use AUnit.Assertions; + +package body AUnit.Test_Fixtures.Tests_Fixtures is + + Nb_Set_Up_Called : Natural := 0; + Nb_Tear_Down_Called : Natural := 0; + + ------------ + -- Set_Up -- + ------------ + + procedure Set_Up (T : in out Fix) is + begin + T.Set_Up_Called := T.Set_Up_Called + 1; + Nb_Set_Up_Called := T.Set_Up_Called; + end Set_Up; + + --------------- + -- Tear_Down -- + --------------- + + procedure Tear_Down (T : in out Fix) is + begin + T.Tear_Down_Called := T.Tear_Down_Called + 1; + Nb_Tear_Down_Called := T.Tear_Down_Called; + end Tear_Down; + + ------------------ + -- Test_Success -- + ------------------ + + procedure Test_Success (T : in out Fix) is + pragma Unreferenced (T); + begin + null; + end Test_Success; + + ------------------ + -- Test_Failure -- + ------------------ + + procedure Test_Failure (T : in out Fix) is + pragma Unreferenced (T); + begin + Assert (False, "Failure"); + end Test_Failure; + + ---------------- + -- Test_Error -- + ---------------- + + procedure Test_Error (T : in out Fix) is + pragma Unreferenced (T); + begin + raise Constraint_Error; + end Test_Error; + + -------------------------- + -- Get_Nb_Set_Up_Called -- + -------------------------- + + function Get_Nb_Set_Up_Called return Natural is + begin + return Nb_Set_Up_Called; + end Get_Nb_Set_Up_Called; + + ----------------------------- + -- Get_Nb_Tear_Down_Called -- + ----------------------------- + + function Get_Nb_Tear_Down_Called return Natural is + begin + return Nb_Tear_Down_Called; + end Get_Nb_Tear_Down_Called; + +end AUnit.Test_Fixtures.Tests_Fixtures; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests_fixtures.ads b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests_fixtures.ads new file mode 100644 index 000000000..789c68108 --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_fixtures-tests_fixtures.ads @@ -0,0 +1,33 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Test_Caller; + +package AUnit.Test_Fixtures.Tests_Fixtures is + + type Fix is new AUnit.Test_Fixtures.Test_Fixture with record + Set_Up_Called : Natural := 0; + Tear_Down_Called : Natural := 0; + end record; + + procedure Set_Up (T : in out Fix); + procedure Tear_Down (T : in out Fix); + + procedure Test_Success (T : in out Fix); + procedure Test_Failure (T : in out Fix); + procedure Test_Error (T : in out Fix); + + package Caller is new AUnit.Test_Caller (Fix); + + TC_Success : constant Caller.Test_Case_Access := + Caller.Create ("Test Success", Test_Success'Access); + TC_Failure : constant Caller.Test_Case_Access := + Caller.Create ("Test Failure", Test_Failure'Access); + TC_Error : constant Caller.Test_Case_Access := + Caller.Create ("Test Error", Test_Error'Access); + + function Get_Nb_Set_Up_Called return Natural; + function Get_Nb_Tear_Down_Called return Natural; + +end AUnit.Test_Fixtures.Tests_Fixtures; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests-suite.adb b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests-suite.adb new file mode 100644 index 000000000..686cbfbc4 --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests-suite.adb @@ -0,0 +1,54 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Test_Caller; + +package body AUnit.Test_Suites.Tests.Suite is + + package Caller is new AUnit.Test_Caller + (AUnit.Test_Suites.Tests.Fixture); + + function Test_Suite return AUnit.Test_Suites.Access_Test_Suite is + S : constant AUnit.Test_Suites.Access_Test_Suite := + AUnit.Test_Suites.New_Suite; + begin + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(suite) Add test case", + Test_Add_Test_Case'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(suite) Run empty suite", + Test_Run_Empty'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(suite) Run suite with a successful test", + Test_Run_With_Success'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(suite) Run suite with a failing test", + Test_Run_With_Failure'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(suite) Run suite with a test raising an exception", + Test_Run_With_Exception'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(suite) Run suite with various tests", + Test_Run_With_All'Access)); + AUnit.Test_Suites.Add_Test + (S, + Caller.Create + ("(suite) Verify Set_Up/Tear_Down are called", + Test_Run_With_Setup'Access)); + return S; + end Test_Suite; + +end AUnit.Test_Suites.Tests.Suite; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests-suite.ads b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests-suite.ads new file mode 100644 index 000000000..4e881f400 --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests-suite.ads @@ -0,0 +1,9 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +package AUnit.Test_Suites.Tests.Suite is + + function Test_Suite return AUnit.Test_Suites.Access_Test_Suite; + +end AUnit.Test_Suites.Tests.Suite; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests.adb b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests.adb new file mode 100644 index 000000000..e34689c72 --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests.adb @@ -0,0 +1,254 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Options; use AUnit.Options; +with AUnit.Assertions; use AUnit.Assertions; +with AUnit.Test_Results; use AUnit.Test_Results; +with AUnit.Time_Measure; use AUnit.Time_Measure; + +with AUnit.Test_Suites.Tests_Fixtures; use AUnit.Test_Suites.Tests_Fixtures; + +package body AUnit.Test_Suites.Tests is + + ------------ + -- Set_Up -- + ------------ + + procedure Set_Up (Test : in out Fixture) is + begin + AUnit.Test_Results.Clear (Test.Res); + Test.Suite := AUnit.Test_Suites.New_Suite; + end Set_Up; + + --------------- + -- Tear_Down -- + --------------- + + procedure Tear_Down (Test : in out Fixture) is +-- -- ??? incompatible with zfp. Should we remove it ? +-- procedure Free is new Ada.Unchecked_Deallocation +-- (Access_Test_Suite, Test_Suite); + pragma Unreferenced (Test); + begin + null; +-- Free (Test.Suite); + end Tear_Down; + + ------------------------ + -- Test_Add_Test_Case -- + ------------------------ + + procedure Test_Add_Test_Case (T : in out Fixture) is + begin + Assert (Test_Lists.Is_Empty (T.Suite.Tests), + "Suite is not empty when initialized"); + AUnit.Test_Suites.Add_Test (T.Suite, A_Simple_Test_Case'Access); + Assert (Test_Lists.Length (T.Suite.Tests) = 1, + "Suite length after inserting a test case is not 1"); + end Test_Add_Test_Case; + + -------------------- + -- Test_Run_Empty -- + -------------------- + + procedure Test_Run_Empty (T : in out Fixture) is + Outcome : AUnit.Status; + Option : constant AUnit.Options.AUnit_Options := Default_Options; + begin + Run (T.Suite, Option, T.Res, Outcome); + + Assert (Successful (T.Res), "Suite did not report success correctly"); + Assert (Test_Count (T.Res) = 0, "Wrong number of tests recorded"); + Assert (Outcome = Success, "Result flag incorrect"); + end Test_Run_Empty; + + --------------------------- + -- Test_Run_With_Success -- + --------------------------- + + procedure Test_Run_With_Success (T : in out Fixture) is + Outcome : AUnit.Status; + Option : constant AUnit_Options := Default_Options; + begin + AUnit.Test_Suites.Add_Test (T.Suite, A_Simple_Test_Case'Access); + Run (T.Suite, Option, T.Res, Outcome); + + Assert (Successful (T.Res), "Suite did not report success correctly"); + Assert (Success_Count (T.Res) = 1, + "Number of reported successes is wrong"); + Assert (Failure_Count (T.Res) = 0, + "Number of reported failures is wrong"); + Assert (Error_Count (T.Res) = 0, + "Number of reported errors is wrong"); + Assert (Test_Count (T.Res) = 1, "Wrong number of tests recorded"); + Assert (Outcome = Success, "Result flag incorrect"); + end Test_Run_With_Success; + + --------------------------- + -- Test_Run_With_Failure -- + --------------------------- + + procedure Test_Run_With_Failure (T : in out Fixture) is + Outcome : AUnit.Status; + Option : constant AUnit_Options := Default_Options; + begin + AUnit.Test_Suites.Add_Test (T.Suite, A_TC_With_Failure'Access); + Run (T.Suite, Option, T.Res, Outcome); + + Assert (not Successful (T.Res), + "Suite did not report success correctly"); + Assert (Success_Count (T.Res) = 0, + "Number of reported successes is wrong"); + Assert (Failure_Count (T.Res) = 1, + "Number of reported failures is wrong"); + Assert (Error_Count (T.Res) = 0, + "Number of reported errors is wrong"); + Assert (Test_Count (T.Res) = 1, "Wrong number of tests recorded"); + Assert (Outcome = Failure, "Result flag incorrect"); + end Test_Run_With_Failure; + + ----------------------------- + -- Test_Run_With_Exception -- + ----------------------------- + + procedure Test_Run_With_Exception (T : in out Fixture) is + Outcome : AUnit.Status; + Option : constant AUnit_Options := Default_Options; + begin + AUnit.Test_Suites.Add_Test (T.Suite, A_TC_With_Exception'Access); + Run (T.Suite, Option, T.Res, Outcome); + + Assert (not Successful (T.Res), + "Suite did not report success correctly"); + Assert (Success_Count (T.Res) = 0, + "Number of reported successes is wrong"); + Assert (Failure_Count (T.Res) = 0, + "Number of reported failures is wrong"); + Assert (Error_Count (T.Res) = 1, + "Number of reported errors is wrong"); + Assert (Test_Count (T.Res) = 1, "Wrong number of tests recorded"); + Assert (Outcome = Failure, "Result flag incorrect"); + end Test_Run_With_Exception; + + ----------------------------- + -- Test_Run_With_Exception -- + ----------------------------- + + procedure Test_Run_With_All (T : in out Fixture) is + Outcome : AUnit.Status; + Option : constant AUnit_Options := Default_Options; + begin + AUnit.Test_Suites.Add_Test (T.Suite, A_Simple_Test_Case'Access); + AUnit.Test_Suites.Add_Test (T.Suite, A_TC_With_Two_Failures'Access); + AUnit.Test_Suites.Add_Test (T.Suite, A_TC_With_Exception'Access); + Run (T.Suite, Option, T.Res, Outcome); + + Assert (not Successful (T.Res), + "Suite did not report success correctly"); + Assert (Success_Count (T.Res) = 1, + "Number of reported successes is wrong"); + Assert (Failure_Count (T.Res) = 2, + "Number of reported failures is wrong"); + Assert (Error_Count (T.Res) = 1, + "Number of reported errors is wrong"); + Assert (Test_Count (T.Res) = 3, "Wrong number of tests recorded"); + Assert (Outcome = Failure, "Result flag incorrect"); + + declare + List : Result_Lists.List; + Elem : Test_Result; + begin + Successes (T.Res, List); + Assert (Result_Lists.Length (List) = 1, + "Unexpected number of successful results"); + Elem := Result_Lists.First_Element (List); + Assert (Elem.Test_Name.all = "Simple test case", + "Incorrect test name in result: '" & + Elem.Test_Name.all & "'"); + + -- Do not use Elem.Routine_Name.all as test result string, as this + -- would be elaborated even in the normal case where null is + -- expected. + + Assert (Elem.Routine_Name = null, + "Incorrect routine name for result: expected null"); + Assert (Elem.Failure = null, + "Unexpected failure value for a successful run"); + Assert (Elem.Error = null, + "Unexpected error value for a successful run"); + Assert (Elem.Elapsed = Null_Time, + "Unexpected elapsed value with run option set to No_Time"); + Result_Lists.Clear (List); + + Failures (T.Res, List); + Assert (Result_Lists.Length (List) = 2, + "Unexpected number of failure results"); + Elem := Result_Lists.First_Element (List); + Assert (Elem.Test_Name.all = "Test case with 2 failures", + "Incorrect test name for result: '" & + Elem.Test_Name.all & "'"); + Assert (Elem.Routine_Name = null, + "Incorrect routine name for result: expected null"); + Assert (Elem.Failure /= null, + "Unexpected failure value for a failed run"); + Assert (Elem.Error = null, + "Unexpected error value for a failed run"); + Assert (Elem.Elapsed = Null_Time, + "Unexpected elapsed value with run option set to No_Time"); + Assert (Elem.Failure.Message.all = "A first failure", + "Incorrect message reported in Failure"); + Assert (Elem.Failure.Source_Name.all, + "aunit-test_suites-tests_fixtures.adb", + "Incorrect filename reported in Failure"); + Result_Lists.Clear (List); + + Errors (T.Res, List); + Assert (Result_Lists.Length (List) = 1, + "Unexpected number of error results"); + Elem := Result_Lists.First_Element (List); + Assert (Elem.Test_Name.all = "Test case with exception", + "Incorrect test name for result: '" & + Elem.Test_Name.all & "'"); + Assert (Elem.Routine_Name = null, + "Incorrect routine name for result: expected null"); + Assert (Elem.Failure = null, + "Unexpected failure value for a run with exception raised"); + Assert (Elem.Error /= null, + "Unexpected error value for a run with exception raised"); + Assert (Elem.Elapsed = Null_Time, + "Unexpected elapsed value with run option set to No_Time"); + Assert (Elem.Error.Exception_Name.all = + "AUNIT.TEST_SUITES.TESTS_FIXTURES.MY_EXCEPTION" + or else Elem.Error.Exception_Name.all = + "Unexpected exception in zfp profile", + "Exeption name is incorrect in error: '" & + Elem.Error.Exception_Name.all & "'"); + + -- Incompatible with certexceptions + -- Assert (Elem.Error.Exception_Message.all = "A message", + -- "Exception message not correctly set: " & + -- Elem.Error.Exception_Message.all); + end; + end Test_Run_With_All; + + ------------------------- + -- Test_Run_With_Setup -- + ------------------------- + + procedure Test_Run_With_Setup (T : in out Fixture) is + Outcome : AUnit.Status; + Option : constant AUnit_Options := Default_Options; + begin + AUnit.Test_Suites.Add_Test (T.Suite, A_TC_With_Setup'Access); + Run (T.Suite, Option, T.Res, Outcome); + + Assert (Successful (T.Res), + "Suite did not run successfully: setup not called"); + Assert (A_TC_With_Setup.Setup = False, + "Tear down not called"); + Assert (A_TC_With_Setup.Error = False, + "Tear down did not receive the expected value"); + end Test_Run_With_Setup; + +end AUnit.Test_Suites.Tests; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests.ads b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests.ads new file mode 100644 index 000000000..0d3ea330e --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests.ads @@ -0,0 +1,27 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Test_Fixtures; +with AUnit.Test_Results; +with AUnit.Test_Suites; + +package AUnit.Test_Suites.Tests is + + type Fixture is new AUnit.Test_Fixtures.Test_Fixture with record + Suite : AUnit.Test_Suites.Access_Test_Suite; + Res : AUnit.Test_Results.Result; + end record; + + procedure Set_Up (Test : in out Fixture); + procedure Tear_Down (Test : in out Fixture); + + procedure Test_Add_Test_Case (T : in out Fixture); + procedure Test_Run_Empty (T : in out Fixture); + procedure Test_Run_With_Success (T : in out Fixture); + procedure Test_Run_With_Failure (T : in out Fixture); + procedure Test_Run_With_Exception (T : in out Fixture); + procedure Test_Run_With_All (T : in out Fixture); + procedure Test_Run_With_Setup (T : in out Fixture); + +end AUnit.Test_Suites.Tests; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests_fixtures.adb b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests_fixtures.adb new file mode 100644 index 000000000..50cbadf5f --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests_fixtures.adb @@ -0,0 +1,135 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with Ada.Exceptions; +with AUnit.Assertions; use AUnit.Assertions; + +package body AUnit.Test_Suites.Tests_Fixtures is + + ---------- + -- Name -- + ---------- + + function Name (Test : Simple_Test_Case) return Message_String is + pragma Unreferenced (Test); + begin + return AUnit.Format ("Simple test case"); + end Name; + + -------------- + -- Run_Test -- + -------------- + + procedure Run_Test (Test : in out Simple_Test_Case) is + pragma Unreferenced (Test); + begin + null; + end Run_Test; + + function Name (Test : TC_With_Failure) return Message_String is + pragma Unreferenced (Test); + begin + return AUnit.Format ("Test case with failure"); + end Name; + + -------------- + -- Run_Test -- + -------------- + + procedure Run_Test (Test : in out TC_With_Failure) is + pragma Unreferenced (Test); + begin + Assert (False, "A failed assertion"); + end Run_Test; + + ---------- + -- Name -- + ---------- + + function Name (Test : TC_With_Two_Failures) return Message_String is + pragma Unreferenced (Test); + begin + return AUnit.Format ("Test case with 2 failures"); + end Name; + + -------------- + -- Run_Test -- + -------------- + + procedure Run_Test (Test : in out TC_With_Two_Failures) is + pragma Unreferenced (Test); + begin + if not Assert (False, "A first failure") then + Assert (False, "A second failure"); + Assert (False, "Third failure, should not appear"); + end if; + end Run_Test; + + ---------- + -- Name -- + ---------- + + function Name (Test : TC_With_Exception) return Message_String is + pragma Unreferenced (Test); + begin + return AUnit.Format ("Test case with exception"); + end Name; + + -------------- + -- Run_Test -- + -------------- + + procedure Run_Test (Test : in out TC_With_Exception) is + pragma Unreferenced (Test); + begin + Ada.Exceptions.Raise_Exception + (My_Exception'Identity, "A message"); + end Run_Test; + + ---------- + -- Name -- + ---------- + + function Name (Test : TC_With_Setup) return Message_String is + pragma Unreferenced (Test); + begin + return AUnit.Format ("Test case with set_up/tear_down defined)"); + end Name; + + ------------ + -- Set_Up -- + ------------ + + procedure Set_Up (Test : in out TC_With_Setup) is + begin + if Test.Setup then + Test.Error := True; + end if; + + Test.Setup := True; + end Set_Up; + + --------------- + -- Tear_Down -- + --------------- + + procedure Tear_Down (Test : in out TC_With_Setup) is + begin + if not Test.Setup then + Test.Error := True; + end if; + + Test.Setup := False; + end Tear_Down; + + -------------- + -- Run_Test -- + -------------- + + procedure Run_Test (Test : in out TC_With_Setup) is + begin + Assert (Test.Setup, "Set up not done correctly"); + end Run_Test; + +end AUnit.Test_Suites.Tests_Fixtures; diff --git a/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests_fixtures.ads b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests_fixtures.ads new file mode 100644 index 000000000..fd1535dee --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit-test_suites-tests_fixtures.ads @@ -0,0 +1,54 @@ +-- +-- Copyright (C) 2009-2010, AdaCore +-- + +with AUnit.Simple_Test_Cases; + +package AUnit.Test_Suites.Tests_Fixtures is + + -- A very simple minded test case + type Simple_Test_Case is new AUnit.Simple_Test_Cases.Test_Case with + null record; + function Name (Test : Simple_Test_Case) return Message_String; + procedure Run_Test (Test : in out Simple_Test_Case); + + A_Simple_Test_Case : aliased Simple_Test_Case; + + -- A test case raising a failure + type TC_With_Failure is new AUnit.Simple_Test_Cases.Test_Case with + null record; + function Name (Test : TC_With_Failure) return Message_String; + procedure Run_Test (Test : in out TC_With_Failure); + + A_TC_With_Failure : aliased TC_With_Failure; + + -- A test case raising two failures + type TC_With_Two_Failures is new AUnit.Simple_Test_Cases.Test_Case with + null record; + function Name (Test : TC_With_Two_Failures) return Message_String; + procedure Run_Test (Test : in out TC_With_Two_Failures); + + A_TC_With_Two_Failures : aliased TC_With_Two_Failures; + + -- A test case raising an exception + type TC_With_Exception is new AUnit.Simple_Test_Cases.Test_Case with + null record; + function Name (Test : TC_With_Exception) return Message_String; + procedure Run_Test (Test : in out TC_With_Exception); + + A_TC_With_Exception : aliased TC_With_Exception; + + -- A test case using set_up and tear_down + type TC_With_Setup is new AUnit.Simple_Test_Cases.Test_Case with record + Setup : Boolean := False; + Error : Boolean := False; + end record; + function Name (Test : TC_With_Setup) return Message_String; + procedure Set_Up (Test : in out TC_With_Setup); + procedure Tear_Down (Test : in out TC_With_Setup); + procedure Run_Test (Test : in out TC_With_Setup); + A_TC_With_Setup : aliased TC_With_Setup; + + My_Exception : exception; + +end AUnit.Test_Suites.Tests_Fixtures; diff --git a/ada/libaunit-3.7.2/test/src/aunit_harness.adb b/ada/libaunit-3.7.2/test/src/aunit_harness.adb new file mode 100644 index 000000000..9e3ad2f97 --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit_harness.adb @@ -0,0 +1,37 @@ +-- +-- Copyright (C) 2009-2013, AdaCore +-- + +with AUnit.Options; +with AUnit.Reporter.Text; +with AUnit.Run; +with AUnit.Test_Filters; use AUnit.Test_Filters; + +with AUnit_Suite; use AUnit_Suite; + +procedure AUnit_Harness is + + procedure Harness is new AUnit.Run.Test_Runner (Suite); + -- The full test harness + + Reporter : AUnit.Reporter.Text.Text_Reporter; + Filter : aliased AUnit.Test_Filters.Name_Filter; + Options : AUnit.Options.AUnit_Options := + (Global_Timer => False, + Test_Case_Timer => True, + Report_Successes => True, + Filter => null); +begin + AUnit.Reporter.Text.Set_Use_ANSI_Colors (Reporter, True); + Harness (Reporter, Options); + + -- Test the filter + -- This filter should be initialized from the command line arguments. In + -- this example, we don't do it to support limited runtimes with no support + -- for Ada.Command_Line + + Options.Filter := Filter'Unchecked_Access; + Set_Name (Filter, "(test_case) Test routines registration"); + Harness (Reporter, Options); + +end AUnit_Harness; diff --git a/ada/libaunit-3.7.2/test/src/aunit_suite.adb b/ada/libaunit-3.7.2/test/src/aunit_suite.adb new file mode 100644 index 000000000..8bc208709 --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit_suite.adb @@ -0,0 +1,26 @@ +-- +-- Copyright (C) 2008-2010, AdaCore +-- + +with AUnit.Test_Suites.Tests.Suite; +with AUnit.Test_Cases.Tests.Suite; +with AUnit.Test_Fixtures.Tests.Suite; + +package body AUnit_Suite is + use Test_Suites; + + function Suite return Access_Test_Suite is + S : constant AUnit.Test_Suites.Access_Test_Suite := + AUnit.Test_Suites.New_Suite; + begin + Add_Test + (S, AUnit.Test_Suites.Tests.Suite.Test_Suite); + Add_Test + (S, AUnit.Test_Cases.Tests.Suite.Test_Suite); + Add_Test + (S, AUnit.Test_Fixtures.Tests.Suite.Test_Suite); + + return S; + end Suite; + +end AUnit_Suite; diff --git a/ada/libaunit-3.7.2/test/src/aunit_suite.ads b/ada/libaunit-3.7.2/test/src/aunit_suite.ads new file mode 100644 index 000000000..4c6a98acb --- /dev/null +++ b/ada/libaunit-3.7.2/test/src/aunit_suite.ads @@ -0,0 +1,5 @@ +with AUnit; use AUnit; +with AUnit.Test_Suites; +package AUnit_Suite is + function Suite return Test_Suites.Access_Test_Suite; +end AUnit_Suite; diff --git a/ada/libaunit-3.7.2/test/support/run-ppc-elf b/ada/libaunit-3.7.2/test/support/run-ppc-elf new file mode 100755 index 000000000..69901b2f8 --- /dev/null +++ b/ada/libaunit-3.7.2/test/support/run-ppc-elf @@ -0,0 +1,23 @@ +#!/bin/sh + +if [ $# -ne 1 ]; then + echo "Usage: $0 obj" + exit 2 +fi + +obj=$1 + +# Generate the simple script +cat > gdb.run << EOF +# Load binary +target sim -e bug -r 0x400000 +load $obj +set confirm off +run +quit +EOF + +# Run gdb on it +powerpc-elf-gdb -n --batch --command=gdb.run $obj +rm -f gdb.run + diff --git a/ada/libaunit-3.7.2/test/zfp.adc b/ada/libaunit-3.7.2/test/zfp.adc new file mode 100644 index 000000000..237a60caa --- /dev/null +++ b/ada/libaunit-3.7.2/test/zfp.adc @@ -0,0 +1,2 @@ +pragma Restrictions (No_Fixed_Point); +pragma Restrictions (No_Implementation_Attributes); diff --git a/ada/libaunit-3.7.2/version_information b/ada/libaunit-3.7.2/version_information new file mode 100644 index 000000000..7d26a443f --- /dev/null +++ b/ada/libaunit-3.7.2/version_information @@ -0,0 +1,2 @@ +MAJOR_VERSION=3. +MINOR_VERSION=8.0w diff --git a/ada/librdf.gpr b/ada/librdf.gpr new file mode 100644 index 000000000..eb90817c1 --- /dev/null +++ b/ada/librdf.gpr @@ -0,0 +1,67 @@ +library project Librdf is + type Library_Kind_Type is ("static", "dynamic"); + Library_Kind : Library_Kind_Type := external ("LIBRARY_KIND", "static"); + + type Debug_Mode_Type is ("debug", "release", "check"); + Debug_Mode : Debug_Mode_Type := external ("DEBUG_MODE", "debug"); + + type Compilation_Mode_Type is + ("Devel", "Install"); + type Runtime_Type is + ("cert", "default", "full", "hi", "kernel", "kernel-sjlj", "kernel-smp", "pthread", "sjlj", "ravenscar", "ravenscar-apex", "ravenscar-full", "ravenscar-cert", "ravenscar-cert-rci", "ravenscar-cert-rtp", "ravenscar-sfp", "rtp", "rtp-smp", + "soft-float", "xenomai", "zcx", "zfp", "minimal"); + for Library_Name use "rdf-ada"; + for Library_Dir use "lib"; + for Library_Kind use Library_Kind; + for Library_Version use external ("soversion", "default"); + for Source_Dirs use ("src"); + case LIBRARY_KIND is + when "dynamic" => + for Object_Dir use "obj-dynamic"; + for Library_Ali_Dir use "ali-dynamic"; + when others => + for Object_Dir use "obj-static"; + for Library_Ali_Dir use "ali-static"; + end case; + RUNTIME : Runtime_Type := external ("RUNTIME", "default"); + MODE : Compilation_Mode_Type := external ("MODE"); + + + package Compiler is + Common_Ada_Flags := ("-gnat2012", + "-gnaty3", "-gnatya", "-gnatyA", "-gnatyb", "-gnatyd", "-gnatyf", "-gnatyh", "-gnatyi", "-gnatyl", "-gnatyp", "-gnatyx", + "-gnatwe", "-gnatwa", "-gnatwF"); + + Debug_Flags := (); + case Debug_Mode is + when "debug" => + Debug_Flags := ("-g", "-gnata"); + when "release" => + Debug_Flags := ("-O2"); + when "check" => + Debug_Flags := ("-gnatc"); + end case; + + case LIBRARY_KIND is + when "dynamic" => + for Default_Switches ("ada") use Common_Ada_Flags & Debug_Flags & ("-fpic"); + when "static" => + for Default_Switches ("ada") use Common_Ada_Flags & Debug_Flags & (); + end case; + end Compiler; + + package Linker is + for Linker_Options use ("-lraptor2", "-lrasqal", "-lrdf"); + end Linker; + + package Builder is + case Debug_Mode is + when "check" => + for Default_Switches ("Ada") use ("-gnatc"); + when others => + null; + end case; + end Builder; + +end Librdf; + diff --git a/ada/main_test.adb b/ada/main_test.adb new file mode 100644 index 000000000..02b62a5da --- /dev/null +++ b/ada/main_test.adb @@ -0,0 +1,54 @@ +-- TODO: Do Adjust as in this file + +with Ada.Finalization; +with Ada.Text_IO; + +procedure Main_Test is + + package A_Pkg is + + type A is new Ada.Finalization.Controlled with null record; + + not overriding procedure Do_It(Object: A); + + overriding procedure Adjust(Object: in out A); + + end A_Pkg; + + package body A_Pkg is + + procedure Do_It(Object: A) is + begin + Ada.Text_IO.Put_Line("A"); + end; + + procedure Adjust(Object: in out A) is + begin + Do_It(A'Class(Object)); + end; + + end A_Pkg; + + package B_Pkg is + + type B is new A_Pkg.A with null record; + + overriding procedure Do_It(Object: B); + + end B_Pkg; + + package body B_Pkg is + + procedure Do_It(Object: B) is + begin + Ada.Text_IO.Put_Line("B"); + end; + + end B_Pkg; + + X: B_Pkg.B; + Y: B_Pkg.B; + +begin + Y := X; +end Main_Test; diff --git a/ada/src/rdf-auxiliary-c_pointers.ads b/ada/src/rdf-auxiliary-c_pointers.ads new file mode 100644 index 000000000..a550668e1 --- /dev/null +++ b/ada/src/rdf-auxiliary-c_pointers.ads @@ -0,0 +1,8 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Pointers; + +package RDF.Auxiliary.C_Pointers is + new Interfaces.C.Pointers(Index => size_t, + Element => char, + Element_Array => char_array, + Default_Terminator => nul); diff --git a/ada/src/rdf-auxiliary-c_string_holders.adb b/ada/src/rdf-auxiliary-c_string_holders.adb new file mode 100644 index 000000000..dc46152b4 --- /dev/null +++ b/ada/src/rdf-auxiliary-c_string_holders.adb @@ -0,0 +1,47 @@ +package body RDF.Auxiliary.C_String_Holders is + + use String_Holders, Char_Array_Holders; + + function Length (Object: C_String_Holder) return size_t is + begin + if Is_Empty(Object) then + return 0; + else + return Element(Object)'Length - 1; -- minus NULL at the end of the string + end if; + end; + + -- FIXME: Erroneously used when allocating Raptor/Rasqal/... strings + function New_String (Value: String_Holders.Holder) return chars_ptr is + begin + return (if Is_Empty(Value) then Null_Ptr else New_String(Element(Value))); + end; + + function To_C_String_Holder (Item: String_Holders.Holder) return C_String_Holder is + begin + return Result: C_String_Holder do + if not Is_Empty(Item) then + Replace_Element(Result, To_C(Element(Item), Append_Nul=>True) ); + end if; + end return; + end; + + function C_String (Object: C_String_Holder) return chars_ptr is + begin + if Is_Empty(Object) then + return Null_Ptr; + else + return To_Chars_Ptr(Constant_Reference(Object).Element); + end if; + end; + + function New_Holder (Ptr: chars_ptr) return String_Holders.Holder is + begin + if Ptr = Null_Ptr then + return String_Holders.Empty_Holder; + else + return String_Holders.To_Holder(Value(Ptr)); + end if; + end; + +end RDF.Auxiliary.C_String_Holders; diff --git a/ada/src/rdf-auxiliary-c_string_holders.ads b/ada/src/rdf-auxiliary-c_string_holders.ads new file mode 100644 index 000000000..84167387d --- /dev/null +++ b/ada/src/rdf-auxiliary-c_string_holders.ads @@ -0,0 +1,20 @@ +with Ada.Containers.Indefinite_Holders; +with Interfaces.C.Strings; use Interfaces.C.Strings; + +package RDF.Auxiliary.C_String_Holders is + + package Char_Array_Holders is new Ada.Containers.Indefinite_Holders(char_array); + + type C_String_Holder is new Char_Array_Holders.Holder with null record; + + function Length (Object: C_String_Holder) return size_t; + + function New_String (Value: String_Holders.Holder) return chars_ptr; + + function New_Holder (Ptr: chars_ptr) return String_Holders.Holder; + + function To_C_String_Holder (Item: String_Holders.Holder) return C_String_Holder; + + function C_String (Object: C_String_Holder) return chars_ptr; + +end RDF.Auxiliary.C_String_Holders; diff --git a/ada/src/rdf-auxiliary-convert.adb b/ada/src/rdf-auxiliary-convert.adb new file mode 100644 index 000000000..96373d434 --- /dev/null +++ b/ada/src/rdf-auxiliary-convert.adb @@ -0,0 +1,19 @@ +with Interfaces.C; use Interfaces.C; + +package body RDF.Auxiliary.Convert is + + function My_To_C_Without_Nul (Item : in String) return char_array is + begin + if Item'Length = 0 then + return (1..0 => NUL); + end if; + -- Append_Nul is False and Item'Length is 0, then To_C propagates Constraint_Error. + return To_C(Item, Append_Nul=>False); + end; + + function Value_With_Possible_NULs (Item: RDF.Auxiliary.C_Pointers.Pointer; Length: size_t) return String is + begin + return To_Ada(RDF.Auxiliary.C_Pointers.Value(Item, Interfaces.C.ptrdiff_t(Length)), Trim_Nul=>False); + end; + +end RDF.Auxiliary.Convert; diff --git a/ada/src/rdf-auxiliary-convert.ads b/ada/src/rdf-auxiliary-convert.ads new file mode 100644 index 000000000..1bbb1d32e --- /dev/null +++ b/ada/src/rdf-auxiliary-convert.ads @@ -0,0 +1,15 @@ +with Ada.Unchecked_Conversion; +with Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.C_Pointers; + +package RDF.Auxiliary.Convert is + + function My_To_C_Without_Nul (Item : in String) return char_array; + + function Value_With_Possible_NULs (Item: RDF.Auxiliary.C_Pointers.Pointer; Length: size_t) return String; + + function Convert is new Ada.Unchecked_Conversion(RDF.Auxiliary.C_Pointers.Pointer, chars_ptr); + function Convert is new Ada.Unchecked_Conversion(chars_ptr, RDF.Auxiliary.C_Pointers.Pointer); + +end RDF.Auxiliary.Convert; diff --git a/ada/src/rdf-auxiliary-convert_void.adb b/ada/src/rdf-auxiliary-convert_void.adb new file mode 100644 index 000000000..8513e08dc --- /dev/null +++ b/ada/src/rdf-auxiliary-convert_void.adb @@ -0,0 +1,28 @@ +with Ada.Unchecked_Conversion; + +package body RDF.Auxiliary.Convert_Void is + + type My_Char_Pointer is access all char with Convention=>C; + + function From_My_Char_Pointer is new Ada.Unchecked_Conversion(My_Char_Pointer, chars_ptr); + function From_Chars_Ptr is new Ada.Unchecked_Conversion(chars_ptr, My_Char_Pointer); + + package Char_Address_Conversions is new System.Address_To_Access_Conversions(char); + + function To_Access (Void_Pointer: chars_ptr) return Object_Pointer is + P: constant My_Char_Pointer := From_Chars_Ptr(Void_Pointer); + A: constant System.Address := + Char_Address_Conversions.To_Address(Char_Address_Conversions.Object_Pointer(P)); + begin + return Address_Conversions.To_Pointer(A); + end; + + function To_C_Pointer (Pointer: Object_Pointer) return chars_ptr is + A: constant System.Address := Address_Conversions.To_Address(Pointer); + P: constant My_Char_Pointer := + My_Char_Pointer(Char_Address_Conversions.To_Pointer(A)); + begin + return From_My_Char_Pointer(P); + end; + +end RDF.Auxiliary.Convert_Void; diff --git a/ada/src/rdf-auxiliary-convert_void.ads b/ada/src/rdf-auxiliary-convert_void.ads new file mode 100644 index 000000000..b0891808f --- /dev/null +++ b/ada/src/rdf-auxiliary-convert_void.ads @@ -0,0 +1,20 @@ +with System.Address_To_Access_Conversions; +with Interfaces.C.Strings; use Interfaces.C.Strings; + +-- C11, 6.2.5, 28 (draft N1548): +-- A pointer to void shall have the same representation and alignment requirements as a pointer to a character type. +-- So we can use chars_ptr to mean void pointer in C. + +generic + type Object(<>) is limited private; +package RDF.Auxiliary.Convert_Void is + + package Address_Conversions is new System.Address_To_Access_Conversions(Object); + + subtype Object_Pointer is Address_Conversions.Object_Pointer; + + function To_Access (Void_Pointer: chars_ptr) return Object_Pointer; + + function To_C_Pointer (Pointer: Object_Pointer) return chars_ptr; + +end RDF.Auxiliary.Convert_Void; diff --git a/ada/src/rdf-auxiliary-handled_record.adb b/ada/src/rdf-auxiliary-handled_record.adb new file mode 100644 index 000000000..6d7103e6a --- /dev/null +++ b/ada/src/rdf-auxiliary-handled_record.adb @@ -0,0 +1,74 @@ +package body RDF.Auxiliary.Handled_Record is + + procedure Set_Handle_Hack(Object: in out Base_Object; Handle: Access_Type) is + begin + Object.Handle := Handle; + end; + + function Get_Handle(Object: Base_Object) return Access_Type is (Object.Handle); + + function From_Handle(Handle: Access_Type) return Base_Object is + (Ada.Finalization.Controlled with Handle=>Handle); + + function From_Non_Null_Handle(Handle: Access_Type) return Base_Object is + begin + if Handle = null then + raise Null_Handle; + end if; + return From_Handle(Handle); + end; + + function Default_Handle(Object: Base_Object) return Access_Type is (null); + + procedure Initialize (Object: in out Base_Object) is + begin + Object.Handle := Default_Handle(Base_Object'Class(Object)); + end Initialize; + + procedure Do_Finalize (Object : in out Base_Object) is + begin + if Object.Handle /= null then + Finalize_Handle(Base_Object'Class(Object), Object.Handle); + Object.Handle := null; + end if; + end; + + procedure Do_Adjust(Object: in out Base_Object) is + begin + if Object.Handle /= null then + Object.Handle := Adjust_Handle(Base_Object'Class(Object), Object.Handle); + end if; + end; + + function Adjust_Handle(Object: Base_Object; Handle: Access_Type) return Access_Type is + begin + return Handle; -- default for _Without_Finalize + end; + + function Is_Null (Object: Base_Object) return Boolean is + begin + return Object.Handle = null; + end; + + package body Common_Handlers is + + function Copy(Object: Base'Class) return Base_With_Finalization is + begin + return From_Handle(Adjust_Handle(Object, Get_Handle(Object))); + end; + + procedure Detach(Object: in out Base_With_Finalization) is + begin + Set_Handle_Hack(Object, null); + end; + + function Detach(Object: in out Base_With_Finalization) return Base is + Handle: constant Access_Type := Get_Handle(Object); + begin + Set_Handle_Hack(Object, null); + return From_Handle(Handle); + end; + + end; + +end RDF.Auxiliary.Handled_Record; diff --git a/ada/src/rdf-auxiliary-handled_record.ads b/ada/src/rdf-auxiliary-handled_record.ads new file mode 100644 index 000000000..4c28f1930 --- /dev/null +++ b/ada/src/rdf-auxiliary-handled_record.ads @@ -0,0 +1,77 @@ +with Ada.Finalization; + +generic + type Record_Type; -- It should be a convention C record + type Record_Type_Access is access Record_Type; -- It should be a convention C access type +package RDF.Auxiliary.Handled_Record is + + -- Does not compile because https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62235 + -- subtype Access_Type is access Record_Type + -- with Convention=>C; + + subtype Access_Type is Record_Type_Access; + +-- type Finalization_Procedures is interface; +-- +-- procedure Do_Finalize(Object: in out Finalization_Procedures) is null; +-- procedure Do_Adjust(Object: in out Finalization_Procedures) is null; + + -- It is logically abstract, but not exactly abstract in Ada sense. + -- It can't be abstract because the function From_Handle returns this type. + -- + -- When extending this type, it is recommended: + -- 1. Create a type T_Without_Finalize for which do NOT override Finalize_Handle and Adjust. + -- 2. Create T extending T_Without_Finalize for which do override Finalize_Handle and Adjust. + -- 3. Routines returning newly created objects of this type should return T. + -- 4. The rest routines should operate on T or T_Without_Finalize'Class, as appropriate. + -- + -- Note: T_Without_Finalize is useful for objects which are logically a part of on other object + -- and thus should be finalized only as a part of finalization of the container. + type Base_Object is new Ada.Finalization.Controlled with private; + + overriding procedure Initialize(Object: in out Base_Object); + + procedure Do_Finalize(Object: in out Base_Object); + + procedure Do_Adjust(Object: in out Base_Object); + + -- Don't call this procedure unless you really need it. + not overriding procedure Set_Handle_Hack(Object: in out Base_Object; Handle: Access_Type); + + not overriding function Get_Handle(Object: Base_Object) return Access_Type; + + not overriding function From_Handle(Handle: Access_Type) return Base_Object; + + not overriding function From_Non_Null_Handle(Handle: Access_Type) return Base_Object; + + not overriding function Default_Handle(Object: Base_Object) return Access_Type; + + not overriding procedure Finalize_Handle(Object: Base_Object; Handle: Access_Type) is null; + + not overriding function Adjust_Handle(Object: Base_Object; Handle: Access_Type) return Access_Type; + + not overriding function Is_Null (Object: Base_Object) return Boolean; + + generic + type Base is new Base_Object with private; + package Common_Handlers is + type User_Type is new Base with null record; + overriding procedure Finalize(Object: in out User_Type) + renames Do_Finalize; + overriding procedure Adjust(Object: in out User_Type) + renames Do_Adjust; + type Base_With_Finalization is new User_Type with null record; + not overriding function Copy(Object: Base'Class) return Base_With_Finalization; + -- "Detach" API is experimental + procedure Detach(Object: in out Base_With_Finalization); + function Detach(Object: in out Base_With_Finalization) return Base; + end; + +private + + type Base_Object is new Ada.Finalization.Controlled with + record + Handle: Access_Type; + end record; + +end RDF.Auxiliary.Handled_Record; diff --git a/ada/src/rdf-auxiliary-limited_handled_record.adb b/ada/src/rdf-auxiliary-limited_handled_record.adb new file mode 100644 index 000000000..5d6486718 --- /dev/null +++ b/ada/src/rdf-auxiliary-limited_handled_record.adb @@ -0,0 +1,57 @@ +package body RDF.Auxiliary.Limited_Handled_Record is + + procedure Set_Handle_Hack(Object: in out Base_Object; Handle: Access_Type) is + begin + Object.Handle := Handle; + end; + + function Get_Handle(Object: Base_Object) return Access_Type is (Object.Handle); + + function From_Handle(Handle: Access_Type) return Base_Object is + (Ada.Finalization.Limited_Controlled with Handle=>Handle); + + function From_Non_Null_Handle(Handle: Access_Type) return Base_Object is + begin + if Handle = null then + raise Null_Handle; + end if; + return From_Handle(Handle); + end; + + function Default_Handle(Object: Base_Object) return Access_Type is (null); + + procedure Initialize (Object: in out Base_Object) is + begin + Object.Handle := Default_Handle(Base_Object'Class(Object)); + end Initialize; + + procedure Do_Finalize (Object : in out Base_Object) is + begin + if Object.Handle /= null then + Finalize_Handle(Base_Object'Class(Object), Object.Handle); + Object.Handle := null; + end if; + end; + + function Is_Null (Object: Base_Object) return Boolean is + begin + return Object.Handle = null; + end; + + package body Common_Handlers is + + procedure Detach(Object: in out Base_With_Finalization) is + begin + Set_Handle_Hack(Object, null); + end; + + function Detach(Object: in out Base_With_Finalization) return Base is + Handle: constant Access_Type := Get_Handle(Object); + begin + Set_Handle_Hack(Object, null); + return From_Handle(Handle); + end; + + end; + +end RDF.Auxiliary.Limited_Handled_Record; diff --git a/ada/src/rdf-auxiliary-limited_handled_record.ads b/ada/src/rdf-auxiliary-limited_handled_record.ads new file mode 100644 index 000000000..4f0e81983 --- /dev/null +++ b/ada/src/rdf-auxiliary-limited_handled_record.ads @@ -0,0 +1,56 @@ +with Ada.Finalization; + +generic + type Record_Type; -- It should be a convention C record + type Record_Type_Access is access Record_Type; -- It should be a convention C access type +package RDF.Auxiliary.Limited_Handled_Record is + + -- Does not compile because https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62235 + -- subtype Access_Type is access Record_Type + -- with Convention=>C; + + subtype Access_Type is Record_Type_Access; + + -- It is logically abstract, but not exactly abstract in Ada sense. + -- It can't be abstract because the function From_Handle returns this type. + type Base_Object is new Ada.Finalization.Limited_Controlled with private; + + overriding procedure Initialize(Object: in out Base_Object); + + not overriding procedure Do_Finalize(Object: in out Base_Object); + + -- Don't call this procedure unless you really need it. + not overriding procedure Set_Handle_Hack(Object: in out Base_Object; Handle: Access_Type); + + not overriding function Get_Handle(Object: Base_Object) return Access_Type; + + not overriding function From_Handle(Handle: Access_Type) return Base_Object; + + not overriding function From_Non_Null_Handle(Handle: Access_Type) return Base_Object; + + not overriding function Default_Handle(Object: Base_Object) return Access_Type; + + not overriding procedure Finalize_Handle(Object: Base_Object; Handle: Access_Type) is null; + + not overriding function Is_Null (Object: Base_Object) return Boolean; + + generic + type Base is new Base_Object with private; + package Common_Handlers is + type User_Type is new Base with null record; + overriding procedure Finalize(Object: in out User_Type) + renames Do_Finalize; + type Base_With_Finalization is new User_Type with null record; + -- "Detach" API is experimental + procedure Detach(Object: in out Base_With_Finalization); + function Detach(Object: in out Base_With_Finalization) return Base; + end; + +private + + type Base_Object is new Ada.Finalization.Limited_Controlled with + record + Handle: Access_Type; + end record; + +end RDF.Auxiliary.Limited_Handled_Record; diff --git a/ada/src/rdf-auxiliary.adb b/ada/src/rdf-auxiliary.adb new file mode 100644 index 000000000..616f31ac4 --- /dev/null +++ b/ada/src/rdf-auxiliary.adb @@ -0,0 +1,22 @@ +package body RDF.Auxiliary is + + function Length (Object: String_Holders.Holder) return size_t is + use String_Holders; + begin + if Is_Empty(Object) then + return 0; + else + return Element(Object)'Length; + end if; + end; + + function Sign (Value: Interfaces.C.int) return Comparison_Result is + begin + if Value < 0 then + return -1; + else + return (if Value > 0 then 1 else 0); + end if; + end; + +end RDF.Auxiliary; diff --git a/ada/src/rdf-auxiliary.ads b/ada/src/rdf-auxiliary.ads new file mode 100644 index 000000000..cc86116b1 --- /dev/null +++ b/ada/src/rdf-auxiliary.ads @@ -0,0 +1,31 @@ +with Interfaces.C; use Interfaces.C; +with Ada.Containers.Indefinite_Holders; + +package RDF.Auxiliary is + + -- Internal + type Dummy_Record is null record + with Convention=>C; + + type Dummy_Record_Access is access Dummy_Record + with Convention=>C; + + type C_File_Record is null record + with Convention=>C; + + -- Represents C FILE* record + type C_File_Access is access C_File_Record + with Convention=>C; + + type Comparison_Result is range -1..1; + + function Sign (Value: Interfaces.C.int) return Comparison_Result; + + package String_Holders is new Ada.Containers.Indefinite_Holders(String); + + function Length (Object: String_Holders.Holder) return size_t; + + Null_Handle : exception; + RDF_Exception: exception; -- all other librdf exceptions + +end RDF.Auxiliary; diff --git a/ada/src/rdf-raptor-bnode.adb b/ada/src/rdf-raptor-bnode.adb new file mode 100644 index 000000000..e98fa7f83 --- /dev/null +++ b/ada/src/rdf-raptor-bnode.adb @@ -0,0 +1,64 @@ +with Ada.Unchecked_Conversion; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.Convert_Void; +with RDF.Auxiliary.C_String_Holders; use RDF.Auxiliary.C_String_Holders; +with RDF.Raptor.Memory; + +package body RDF.Raptor.Bnode is + + function raptor_world_generate_bnodeid (World: Raptor_World_Handle) return Chars_Ptr + with Import, Convention=>C; + + function Generate_Bnodeid (World: Raptor_World_Type_Without_Finalize'Class) return String is + C_Str: constant chars_ptr := raptor_world_generate_bnodeid(Get_Handle(World)); -- FIXME: May return null + Result: constant String := Value(C_Str); + begin + RDF.Raptor.Memory.raptor_free_memory(C_Str); + return Result; + end; + + procedure raptor_world_set_generate_bnodeid_parameters (World: Raptor_World_Handle; Prefix: chars_ptr; Base: int) + with Import, Convention=>C; + + procedure Set_Generate_Bnodeid_Parameters (World: Raptor_World_Type_Without_Finalize'Class; + Prefix: String_Holders.Holder; + Base: int) is + Prefix_N: constant C_String_Holder := To_C_String_Holder(Prefix); + begin + raptor_world_set_generate_bnodeid_parameters(Get_Handle(World), C_String(Prefix_N), Base); + end; + + type C_BNode_ID_Handler is access function (Data: chars_ptr; User_ID: chars_ptr) return Chars_Ptr + with Convention=>C; + +-- type User_Defined_Access is access constant BNode_ID_Handler'Class; + package My_Conv is new RDF.Auxiliary.Convert_Void(BNode_ID_Handler'Class); + + function C_BNode_ID_Handle_Impl(Data: chars_ptr; User_ID: chars_ptr) return Chars_Ptr + with Convention=>C; + + function C_BNode_ID_Handle_Impl(Data: chars_ptr; User_ID: chars_ptr) return Chars_Ptr is + use RDF.Auxiliary.String_Holders; + User_ID2: RDF.Auxiliary.String_Holders.Holder; + begin + if User_ID /= Null_Ptr then + Replace_Element(User_ID2, Value(User_ID)); + end if; + declare + -- TODO: Do this without dynamic allocation + Result: constant Chars_Ptr := New_String(Do_Handle(My_Conv.To_Access(Data).all, User_ID2)); + begin + RDF.Raptor.Memory.raptor_free_memory(User_ID); + return Result; + end; + end; + + procedure raptor_world_set_generate_bnodeid_handler (World: Raptor_World_Handle; Data: chars_ptr; Handler: C_BNode_ID_Handler) + with Import, Convention=>C; + + procedure Set_BNode_ID_Handler (World: in out Raptor_World_Type_Without_Finalize'Class; Handler: access BNode_ID_Handler'Class) is + begin + raptor_world_set_generate_bnodeid_handler(Get_Handle(World), My_Conv.To_C_Pointer(Handler), C_BNode_ID_Handle_Impl'Access); + end; + +end RDF.Raptor.Bnode; diff --git a/ada/src/rdf-raptor-bnode.ads b/ada/src/rdf-raptor-bnode.ads new file mode 100644 index 000000000..82d8ac716 --- /dev/null +++ b/ada/src/rdf-raptor-bnode.ads @@ -0,0 +1,26 @@ +with RDF.Raptor.World; use RDF.Raptor.World; +with Interfaces.C; use Interfaces.C; +with RDF.Auxiliary; use RDF.Auxiliary; + +package RDF.Raptor.Bnode is + + function Generate_Bnodeid (World: Raptor_World_Type_Without_Finalize'Class) return String; + + procedure Set_Generate_Bnodeid_Parameters (World: Raptor_World_Type_Without_Finalize'Class; + Prefix: String_Holders.Holder; + Base: int); + + -- Should we derive it from Limited_Controlled? + type BNode_ID_Handler is abstract tagged limited private; + + function Do_Handle (Handler: BNode_ID_Handler; User_ID: RDF.Auxiliary.String_Holders.Holder) + return String is abstract; + + procedure Set_BNode_ID_Handler (World: in out Raptor_World_Type_Without_Finalize'Class; + Handler: access BNode_ID_Handler'Class); + +private + + type BNode_ID_Handler is abstract tagged limited null record; + +end RDF.Raptor.Bnode; diff --git a/ada/src/rdf-raptor-constants.adb b/ada/src/rdf-raptor-constants.adb new file mode 100644 index 000000000..262bc59d0 --- /dev/null +++ b/ada/src/rdf-raptor-constants.adb @@ -0,0 +1,33 @@ +with Interfaces.C.Strings; + +package body RDF.Raptor.Constants is + + subtype chars_ptr is Interfaces.C.Strings.chars_ptr; + function Value(Item : in chars_ptr) return String renames Interfaces.C.Strings.Value; + + raptor_copyright_string: constant chars_ptr with Import, Convention=>C; + raptor_home_url_string: constant chars_ptr with Import, Convention=>C; + raptor_license_string: constant chars_ptr with Import, Convention=>C; + raptor_short_copyright_string: constant chars_ptr with Import, Convention=>C; + raptor_version_string: constant chars_ptr with Import, Convention=>C; + raptor_owl_namespace_uri: constant chars_ptr with Import, Convention=>C; + raptor_rdf_namespace_uri: constant chars_ptr with Import, Convention=>C; + raptor_rdf_schema_namespace_uri: constant chars_ptr with Import, Convention=>C; + raptor_xml_literal_datatype_uri_string: constant chars_ptr with Import, Convention=>C; + raptor_xml_namespace_uri: constant chars_ptr with Import, Convention=>C; + raptor_xmlschema_datatypes_namespace_uri: constant chars_ptr with Import, Convention=>C; + + function copyright_string return String is (Value(Raptor_copyright_string)); + function home_url_string return String is (Value(Raptor_home_url_string)); + function license_string return String is (Value(Raptor_license_string)); + function short_copyright_string return String is (Value(Raptor_short_copyright_string)); + function version_string return String is (Value(Raptor_version_string)); + function owl_namespace_uri return String is (Value(Raptor_owl_namespace_uri)); + function rdf_namespace_uri return String is (Value(Raptor_rdf_namespace_uri)); + function rdf_schema_namespace_uri return String is (Value(Raptor_rdf_schema_namespace_uri)); + function xml_literal_datatype_uri_string return String is (Value(Raptor_xml_literal_datatype_uri_string)); + function xml_namespace_uri return String is (Value(Raptor_xml_namespace_uri)); + function xmlschema_datatypes_namespace_uri return String is (Value(Raptor_xmlschema_datatypes_namespace_uri)); + + +end RDF.Raptor.Constants; diff --git a/ada/src/rdf-raptor-constants.ads b/ada/src/rdf-raptor-constants.ads new file mode 100644 index 000000000..6b565d7f5 --- /dev/null +++ b/ada/src/rdf-raptor-constants.ads @@ -0,0 +1,31 @@ +with Interfaces.C; + +package RDF.Raptor.Constants is + + version_major: constant Interfaces.C.unsigned + with Import, Convention=>C, External_Name=>"raptor_version_major"; + version_minor: constant Interfaces.C.unsigned + with Import, Convention=>C, External_Name=>"raptor_version_minor"; + version_release: constant Interfaces.C.unsigned + with Import, Convention=>C, External_Name=>"raptor_version_release"; + version_decimal: constant Interfaces.C.unsigned + with Import, Convention=>C, External_Name=>"raptor_version_decimal"; + + function copyright_string return String; + function home_url_string return String; + function license_string return String; + function short_copyright_string return String; + function version_string return String; + function owl_namespace_uri return String; + function rdf_namespace_uri return String; + function rdf_schema_namespace_uri return String; + function xml_literal_datatype_uri_string return String; + function xml_namespace_uri return String; + function xmlschema_datatypes_namespace_uri return String; + + Rdf_Namespace_Uri_Len: constant Interfaces.C.unsigned + with Import, Convention=>C; + Xml_Literal_Datatype_Uri_String_Len: constant Interfaces.C.unsigned + with Import, Convention=>C; + +end RDF.Raptor.Constants; diff --git a/ada/src/rdf-raptor-iostream.adb b/ada/src/rdf-raptor-iostream.adb new file mode 100644 index 000000000..a11c12de4 --- /dev/null +++ b/ada/src/rdf-raptor-iostream.adb @@ -0,0 +1,483 @@ +with Ada.Unchecked_Conversion; +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with RDF.Auxiliary.Convert_Void; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.Term; use RDF.Raptor.Term; + +package body RDF.Raptor.IOStream is + + function raptor_new_iostream_from_sink (World: Raptor_World_Handle) return IOStream_Handle + with Import, Convention=>C; + + function From_Sink (World: Raptor_World_Type_Without_Finalize'Class) return IOStream_Type is + begin + return From_Non_Null_Handle( raptor_new_iostream_from_sink (Get_Handle (World)) ); + end; + + function raptor_new_iostream_from_filename (World: Raptor_World_Handle; filename: char_array) return IOStream_Handle + with Import, Convention=>C; + + function From_Filename (World: Raptor_World_Type_Without_Finalize'Class; Filename: String) + return IOStream_Type is + begin + return From_Non_Null_Handle( raptor_new_iostream_from_filename (Get_Handle (World), To_C (Filename)) ); + end; + + function raptor_new_iostream_from_file_handle (World: Raptor_World_Handle; File: RDF.Auxiliary.C_File_Access) + return IOStream_Handle + with Import, Convention=>C; + + function From_File_Handle (World: Raptor_World_Type_Without_Finalize'Class; File: RDF.Auxiliary.C_File_Access) + return IOStream_Type is + begin + return From_Non_Null_Handle( raptor_new_iostream_from_file_handle (Get_Handle (World), File) ); + end; + + function raptor_new_iostream_to_sink (World: Raptor_World_Handle) return IOStream_Handle + with Import, Convention=>C; + + function To_Sink (World: Raptor_World_Type_Without_Finalize'Class) return IOStream_Type is + begin + return From_Non_Null_Handle( raptor_new_iostream_to_sink (Get_Handle (World)) ); + end; + + function raptor_new_iostream_to_filename (World: Raptor_World_Handle; filename: char_array) + return IOStream_Handle + with Import, Convention=>C; + + function To_Filename (World: Raptor_World_Type_Without_Finalize'Class; Filename: String) + return IOStream_Type is + begin + return From_Non_Null_Handle( raptor_new_iostream_to_filename (Get_Handle (World), To_C (Filename)) ); + end; + + -- function raptor_new_iostream_to_string (World: Raptor_World_Handle; str: char_array; length: size_t) return Handle_Type + -- with Import, Convention=>C; + -- + -- function To_String (World: Raptor_World_Type_Without_Finalize'Class; Str: String) + -- return IOStream_Type_Without_Finalize is + -- Handle: constant Handle_Type := raptor_new_iostream_to_string (Get_Handle (World), To_C (Str), Str'Length); + -- begin + -- return From_Handle (Handle); + -- end; + + function raptor_new_iostream_to_file_handle (World: Raptor_World_Handle; File: RDF.Auxiliary.C_File_Access) + return IOStream_Handle + with Import, Convention=>C; + + function To_File_Handle (World: Raptor_World_Type_Without_Finalize'Class; File: RDF.Auxiliary.C_File_Access) + return IOStream_Type is + begin + return From_Non_Null_Handle( raptor_new_iostream_to_file_handle (Get_Handle (World), File) ); + end; + + function raptor_iostream_hexadecimal_write (value: unsigned; width: int; Stream: IOStream_Handle) + return int + with Import, Convention=>C; + + procedure Hexadecimal_Write (Value: Natural; Width: Natural; Stream: IOStream_Type_Without_Finalize) is + begin + if raptor_iostream_hexadecimal_write(unsigned (Value), int(Width), Get_Handle (Stream)) < 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_iostream_read_bytes (Ptr: chars_ptr; size, nmemb: size_t; Stream: IOStream_Handle) + return int + with Import, Convention=>C; + + function Read_Bytes (Ptr: chars_ptr; size, nmemb: size_t; Stream: IOStream_Type_Without_Finalize) return size_t is + Result: constant int := raptor_iostream_read_bytes (Ptr, size, nmemb, Get_Handle (Stream)); + begin + if Result < 0 then + raise IOStream_Exception; + end if; + return size_t(Result); + end; + + function raptor_iostream_read_eof (Stream: IOStream_Handle) return int + with Import, Convention=>C; + + function Read_Eof (Stream: IOStream_Type_Without_Finalize) return Boolean is + begin + return raptor_iostream_read_eof (Get_Handle (Stream)) /= 0; + end; + + function raptor_iostream_tell (Stream: IOStream_Handle) return unsigned_long + with Import, Convention=>C; + + function Tell (Stream: IOStream_Type_Without_Finalize) return unsigned_long is + begin + return raptor_iostream_tell (Get_Handle (Stream)); + end; + + function raptor_iostream_counted_string_write (str: char_array; len: size_t; Stream: IOStream_Handle) + return unsigned_long + with Import, Convention=>C; + + procedure Write (Value: String; Stream: IOStream_Type_Without_Finalize) is + begin + if raptor_iostream_counted_string_write (My_To_C_Without_Nul(Value), size_t (Value'Length), Get_Handle (Stream)) /= 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_iostream_decimal_write (Value: int; Stream: IOStream_Handle) return int + with Import, Convention=>C; + + procedure Decimal_Write (Value: int; Stream: IOStream_Type_Without_Finalize) is + begin + if raptor_iostream_decimal_write (Value, Get_Handle (Stream)) < 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_iostream_write_byte (byte: int; Stream: IOStream_Handle) return int + with Import, Convention=>C; + + procedure Write (Value: char; Stream: IOStream_Type_Without_Finalize) is + begin + if raptor_iostream_write_byte (char'Pos(Value), Get_Handle (Stream)) /= 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_iostream_write_bytes (Ptr: chars_ptr; size, nmemb: size_t; Stream: IOStream_Handle) + return int + with Import, Convention=>C; + + function Write_Bytes (Ptr: chars_ptr; size, nmemb: size_t; Stream: IOStream_Type_Without_Finalize) return int is + Result: constant int := raptor_iostream_write_bytes (Ptr, size, nmemb, Get_Handle (Stream)); + begin + if Result < 0 then + raise IOStream_Exception; + end if; + return Result; + end; + + function raptor_iostream_write_end (Stream: IOStream_Handle) return int + with Import, Convention=>C; + + procedure Write_End (Stream: IOStream_Type_Without_Finalize) is + begin + if raptor_iostream_write_end (Get_Handle (Stream)) /= 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_bnodeid_ntriples_write (bnode: char_array; len: size_t; Stream: IOStream_Handle) + return int + with Import, Convention=>C; + + procedure Bnodeid_Ntriples_Write (bnode: String; Stream: IOStream_Type_Without_Finalize) is + begin + if raptor_bnodeid_ntriples_write (To_C (bnode, Append_Nul=>False), bnode'Length, Get_Handle (Stream)) /= 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_string_escaped_write (Str: char_array; + Len: size_t; + Delim: char; + Flags: unsigned; + Stream: IOStream_Handle) + return int + with Import, Convention=>C; + + procedure Escaped_Write (Value: String; + Delim: Character; + Flags: Escaped_Write_Bitflags.Bitflags; + Stream: IOStream_Type_Without_Finalize) is + begin + if raptor_string_escaped_write (My_To_C_Without_Nul(Value), + Value'Length, To_C (Delim), + unsigned (Flags), + Get_Handle (Stream)) /= 0 + then + raise IOStream_Exception; + end if; + end; + + function raptor_string_ntriples_write (Str: char_array; Len: size_t; Delim: char; Stream: IOStream_Handle) + return int + with Import, Convention=>C; + + procedure Ntriples_Write (Value: String; Delim: Character; Stream: IOStream_Type_Without_Finalize) is + begin + if raptor_string_ntriples_write (My_To_C_Without_Nul(Value), Value'Length, To_C (Delim), Get_Handle (Stream)) /= 0 then + raise IOStream_Exception; + end if; + end; + + -- TODO: This function is deprecated + function raptor_string_python_write (ptr: char_array; + len: size_t; + delim: char; + mode: Python_Write_Mode; + Stream: IOStream_Handle) + return int + with Import, Convention=>C; + + procedure String_Python_Write (Value: String; + Delim: Character; + Mode: Python_Write_Mode; + Stream: IOStream_Type_Without_Finalize) is + begin + if raptor_string_python_write (My_To_C_Without_Nul(Value), Value'Length, To_C (Delim), Mode, Get_Handle (Stream)) /= 0 then + raise IOStream_Exception; + end if; + end; + + procedure raptor_free_iostream(Handle: IOStream_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: IOStream_Type_Without_Finalize; Handle: IOStream_Handle) is + begin + raptor_free_iostream (Handle); + end; + + type raptor_iostream_init_func is access function (context: chars_ptr) return int + with Convention=>C; + type raptor_iostream_finish_func is access procedure (context: chars_ptr) + with Convention=>C; + type raptor_iostream_write_byte_func is access function (context: chars_ptr; byte: int) return int + with Convention=>C; + type raptor_iostream_write_bytes_func is access function (context: chars_ptr; + ptr: chars_ptr; + size, nmemb: size_t) + return int + with Convention=>C; + type raptor_iostream_write_end_func is access function (context: chars_ptr) return int + with Convention=>C; + type raptor_iostream_read_bytes_func is access function (context: chars_ptr; + ptr: chars_ptr; + size, nmemb: size_t) + return int + with Convention=>C; + type raptor_iostream_read_eof_func is access function (context: chars_ptr) return int + with Convention=>C; + + type Dispatcher_Type is + record + version : int := 2; + -- V1 functions + init : raptor_iostream_init_func := null; + finish : raptor_iostream_finish_func := null; + write_byte : raptor_iostream_write_byte_func; + write_bytes: raptor_iostream_write_bytes_func; + write_end : raptor_iostream_write_end_func; + -- V2 functions + read_bytes : raptor_iostream_read_bytes_func; + read_eof : raptor_iostream_read_eof_func; + end record + with Convention=>C; + +-- type User_Defined_Access is access all IOStream_Type_User'Class; + package My_Conv is new RDF.Auxiliary.Convert_Void(Handled_IOStream_Type_User'Class); + + -- function raptor_iostream_init_impl (context: chars_ptr) return int + -- with Convention=>C; + -- procedure raptor_iostream_finish_impl (context: chars_ptr) + -- with Convention=>C; + function raptor_iostream_write_byte_impl (context: chars_ptr; byte: int) return int + with Convention=>C; + function raptor_iostream_write_bytes_impl (context: chars_ptr; ptr: chars_ptr; size, nmemb: size_t) return int + with Convention=>C; + function raptor_iostream_write_end_impl (context: chars_ptr) return int + with Convention=>C; + function raptor_iostream_read_bytes_impl (context: chars_ptr; ptr: chars_ptr; size, nmemb: size_t) return int + with Convention=>C; + function raptor_iostream_read_eof_impl (context: chars_ptr) return int + with Convention=>C; + + function raptor_iostream_write_byte_impl (context: chars_ptr; byte: int) return int is + begin + Do_Write_Byte (My_Conv.To_Access (context).all, char'Val(byte)); + return 0; + exception + when others => + return 1; + end; + + function raptor_iostream_write_bytes_impl (context: chars_ptr; ptr: chars_ptr; size, nmemb: size_t) + return int is + begin + declare + Result: constant int := Do_Write_Bytes (My_Conv.To_Access (context).all, ptr, size, nmemb); + begin + return Result; + end; + exception + when others => + return -1; + end; + + function raptor_iostream_write_end_impl (context: chars_ptr) return int is + begin + Do_Write_End (My_Conv.To_Access (context).all); + return 0; + exception + when others => + return 1; + end; + + function raptor_iostream_read_bytes_impl (context: chars_ptr; ptr: chars_ptr; size, nmemb: size_t) + return int is + begin + declare + Ret: constant size_t := Do_Read_Bytes (My_Conv.To_Access (context).all, ptr, size, nmemb); + begin + return int(Ret); + end; + exception + when others => + return -1; + end; + + function raptor_iostream_read_eof_impl (context: chars_ptr) return int is + begin + return (if Do_Read_Eof (My_Conv.To_Access (context).all) then 1 else 0); + end; + + Dispatch: aliased constant Dispatcher_Type := + (version => 2, + init => null, + finish => null, + write_byte => raptor_iostream_write_byte_impl'Access, + write_bytes=> raptor_iostream_write_bytes_impl'Access, + write_end => raptor_iostream_write_end_impl'Access, + read_bytes => raptor_iostream_read_bytes_impl'Access, + read_eof => raptor_iostream_read_eof_impl'Access); + + function raptor_new_iostream_from_handler(world: Raptor_World_Handle; + user_data: chars_ptr; + Dispatcher: access constant Dispatcher_Type) + return IOStream_Handle + with Import, Convention=>C; + + function Open (World: Raptor_World_Type_Without_Finalize'Class) return Handled_IOStream_Type_User is + Handle: IOStream_Handle; + begin + return Stream: Handled_IOStream_Type_User do + Handle := raptor_new_iostream_from_handler (Get_Handle (World), + My_Conv.To_C_Pointer (Handled_IOStream_Type_User'Class(Stream)'Unchecked_Access), + Dispatch'Access); + Set_Handle_Hack (Stream, Handle); + end return; + end; + + procedure Do_Write_Byte (Stream: in out Handled_IOStream_Type_User; Byte: char) is + Byte2: aliased char_array := (1=>Byte); + begin + if Do_Write_Bytes (Stream, To_Chars_Ptr (Byte2'Unchecked_Access), 1, 1) /= 1 then + raise IOStream_exception; + end if; + end; + + function Do_Write_Bytes (Stream: in out Handled_IOStream_Type_User; Data: chars_ptr; Size, Count: size_t) + return int is + begin + raise Program_Error; + return 0; + end; + + procedure Do_Write_End (Stream: in out Handled_IOStream_Type_User) is + begin + raise Program_Error; + end; + + function Do_Read_Bytes (Stream: in out Handled_IOStream_Type_User; Data: chars_ptr; Size, Count: size_t) + return size_t is + begin + raise Program_Error; + return 0; + end; + + function Do_Read_Eof (Stream: in out Handled_IOStream_Type_User) return Boolean is + begin + raise Program_Error; + return False; + end; + + function From_Handle(Handle: IOStream_Handle) return Stream_From_String is + begin + raise Program_Error; + return (IOStream_Type_Without_Finalize'(From_Handle (Handle)) with Length=>0, Str=>""); + end; + + function From_Non_Null_Handle(Handle: IOStream_Handle) return Stream_From_String is + begin + raise Program_Error; + return (IOStream_Type_Without_Finalize'(From_Handle (Handle)) with Length=>0, Str=>""); + end; + + function raptor_new_iostream_from_string (World: Raptor_World_Handle; str: char_array; length: size_t) + return IOStream_Handle + with Import, Convention=>C; + + function Open_From_String (World: Raptor_World_Type_Without_Finalize'Class; Value: String) + return Stream_From_String is + begin + return Stream: Stream_From_String(Value'Length) do + Stream.Str := My_To_C_Without_Nul(Value); + Set_Handle_Hack (Stream, raptor_new_iostream_from_string (Get_Handle (World), Stream.Str, Value'Length)); + end return; + end; + + function From_Handle(Handle: IOStream_Handle) return Stream_To_String is + begin + raise Program_Error; + return (IOStream_Type_Without_Finalize'(From_Handle (Handle)) with Str=>Ada.Strings.Unbounded.Null_Unbounded_String); + end; + + function From_Non_Null_Handle(Handle: IOStream_Handle) return Stream_To_String is + begin + raise Program_Error; + return (IOStream_Type_Without_Finalize'(From_Handle (Handle)) with Str=>Ada.Strings.Unbounded.Null_Unbounded_String); + end; + + function Open (World: Raptor_World_Type_Without_Finalize'Class) return Stream_To_String is + begin + return (Handled_IOStream_Type_User'(Open (World)) with Str=>Ada.Strings.Unbounded.Null_Unbounded_String); + end; + + function Value (Stream: Stream_To_String) return String is + begin + return To_String (Stream.Str); + end; + + function Do_Write_Bytes (Stream: in out Stream_To_String; Data: chars_ptr; Size, Count: size_t) + return int is + begin + Append(Stream.Str, Value (Data, Size*Count)); + return int(Size*Count); + end; + + function raptor_term_escaped_write (Term: RDF.Raptor.Term.Term_Handle; Flags: unsigned; Stream: IOStream_Handle) + return int + with Import, Convention=>C; + + procedure Term_Escaped_Write (Term: RDF.Raptor.Term.Term_Type_Without_Finalize'Class; + Flags: Escaped_Write_Bitflags.Bitflags; + Stream: IOStream_Type_Without_Finalize) is + begin + if raptor_term_escaped_write(Get_Handle(Term), Unsigned(Flags), Get_Handle(Stream)) /= 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_uri_escaped_write (URI, Base_URI: URI_Handle; Flags: unsigned; Stream: IOStream_Handle) + return int + with Import, Convention=>C; + + procedure URI_Escaped_Write (URI, Base_URI: URI_Type_Without_Finalize'Class; + Flags: Escaped_Write_Bitflags.Bitflags; + Stream: IOStream_Type_Without_Finalize) is + begin + if raptor_uri_escaped_write(Get_Handle(URI), Get_Handle(Base_URI), Unsigned(Flags), Get_Handle(Stream)) /= 0 then + raise IOStream_Exception; + end if; + end; + +end RDF.Raptor.IOStream; diff --git a/ada/src/rdf-raptor-iostream.ads b/ada/src/rdf-raptor-iostream.ads new file mode 100644 index 000000000..106fbafb0 --- /dev/null +++ b/ada/src/rdf-raptor-iostream.ads @@ -0,0 +1,197 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with Ada.Strings.Unbounded; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Auxiliary; +with RDF.Raptor.World; use RDF.Raptor.World; +limited with RDF.Raptor.URI; +limited with RDF.Raptor.Term; + +package RDF.Raptor.IOStream is + + -- It is impossible to make this as a wrapper around Ada.Streams.Root_IOStream_Type, + -- because Root_IOStream_Type does not provide End_Of_File function. + + -- However, we can wrap this in Ada.Streams.Root_IOStream_Type + -- But this probably makes no sense for a user of our code. + + IOStream_Exception: exception; + + package IOStream_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + subtype IOStream_Handle is IOStream_Handled_Record.Access_Type; + + type IOStream_Type_Without_Finalize is new IOStream_Handled_Record.Base_Object with null record; + + overriding procedure Finalize_Handle (Object: IOStream_Type_Without_Finalize; Handle: IOStream_Handle); + + procedure Hexadecimal_Write (Value: Natural; Width: Natural; Stream: IOStream_Type_Without_Finalize); + + function Read_Bytes (Ptr: chars_ptr; size, nmemb: size_t; Stream: IOStream_Type_Without_Finalize) return size_t; + + function Read_Eof (Stream: IOStream_Type_Without_Finalize) return Boolean; + + function Tell (Stream: IOStream_Type_Without_Finalize) return unsigned_long; + + procedure Write (Value: String; Stream: IOStream_Type_Without_Finalize); + + procedure Decimal_Write (Value: int; Stream: IOStream_Type_Without_Finalize); + + procedure Write (Value: char; Stream: IOStream_Type_Without_Finalize); + + function Write_Bytes (Ptr: chars_ptr; size, nmemb: size_t; Stream: IOStream_Type_Without_Finalize) return int; + + procedure Write_End (Stream: IOStream_Type_Without_Finalize); + + procedure Bnodeid_Ntriples_Write (bnode: String; Stream: IOStream_Type_Without_Finalize); + + package Escaped_Write_Bitflags is + + type Bitflags is mod 256; -- the number may change in a future version + + BITFLAG_BS_ESCAPES_BF: constant Bitflags := 1; + BITFLAG_BS_ESCAPES_TNRU: constant Bitflags := 2; + BITFLAG_UTF8: constant Bitflags := 4; + BITFLAG_SPARQL_URI_ESCAPES: constant Bitflags := 8; + + -- N-Triples - favour writing \u, \U over UTF8 + NTRIPLES_LITERAL: constant Bitflags := BITFLAG_BS_ESCAPES_TNRU or BITFLAG_BS_ESCAPES_BF; + NTRIPLES_URI : constant Bitflags := BITFLAG_SPARQL_URI_ESCAPES; + + -- SPARQL literal: allows raw UTF8 for printable literals + SPARQL_LITERAL: constant Bitflags := BITFLAG_UTF8; + + -- SPARQL long literal: no BS-escapes allowe + SPARQL_LONG_LITERAL: constant Bitflags := BITFLAG_UTF8; + + -- SPARQL uri: have to escape certain characters + SPARQL_URI: constant Bitflags := BITFLAG_UTF8 or BITFLAG_SPARQL_URI_ESCAPES; + + -- Turtle (2013) escapes are like SPARQL + TURTLE_URI: constant Bitflags := SPARQL_URI; + TURTLE_LITERAL: constant Bitflags := SPARQL_LITERAL; + TURTLE_LONG_LITERAL: constant Bitflags := SPARQL_LONG_LITERAL; + + --- JSON literals: \b \f \t \r \n and \u \U + JSON_LITERAL: constant Bitflags := BITFLAG_BS_ESCAPES_TNRU or BITFLAG_BS_ESCAPES_BF; + + end Escaped_Write_Bitflags; + + procedure Escaped_Write (Value: String; Delim: Character; + Flags: Escaped_Write_Bitflags.Bitflags; + Stream: IOStream_Type_Without_Finalize); + + procedure URI_Escaped_Write (URI, Base_URI: RDF.Raptor.URI.URI_Type_Without_Finalize'Class; + Flags: Escaped_Write_Bitflags.Bitflags; + Stream: IOStream_Type_Without_Finalize); + + procedure Term_Escaped_Write (Term: RDF.Raptor.Term.Term_Type_Without_Finalize'Class; + Flags: Escaped_Write_Bitflags.Bitflags; + Stream: IOStream_Type_Without_Finalize); + + procedure Ntriples_Write (Value: String; Delim: Character; Stream: IOStream_Type_Without_Finalize); + + type Python_Write_Mode is (NTriples, Turtle, Turtle_Long_String, JSON) + with Convention => C; + for Python_Write_Mode use (NTriples=>0, Turtle=>1, Turtle_Long_String=>2, JSON=>3); + + procedure String_Python_Write (Value: String; + Delim: Character; + Mode: Python_Write_Mode; + Stream: IOStream_Type_Without_Finalize); + + package Handlers is new IOStream_Handled_Record.Common_Handlers(IOStream_Type_Without_Finalize); + + type IOStream_Type is new Handlers.Base_With_Finalization with null record; + + type IOStream_Type_User is new Handlers.User_Type with null record; + + function From_Sink (World: Raptor_World_Type_Without_Finalize'Class) return IOStream_Type; + + function From_Filename (World: Raptor_World_Type_Without_Finalize'Class; Filename: String) + return IOStream_Type; + + function From_File_Handle (World: Raptor_World_Type_Without_Finalize'Class; + File: RDF.Auxiliary.C_File_Access) + return IOStream_Type; + + -- See below type Stream_From_String instead + -- function From_String (World: Raptor_World_Type_Without_Finalize; Str: String) + -- return IOStream_Type_Without_Finalize; + + function To_Sink (World: Raptor_World_Type_Without_Finalize'Class) return IOStream_Type; + + function To_Filename (World: Raptor_World_Type_Without_Finalize'Class; Filename: String) + return IOStream_Type; + + function To_File_Handle (World: Raptor_World_Type_Without_Finalize'Class; File: RDF.Auxiliary.C_File_Access) + return IOStream_Type; + + -- See below type Stream_To_String instead + -- function To_String (World: Raptor_World_Type_Without_Finalize; Str: String) + -- return IOStream_Type_Without_Finalize; + + type Handled_IOStream_Type_User is new IOStream_Type_User with null record; + + --overriding function Default_Handle(Object: IOStream_Type_User) return Handle_Type; + not overriding function Open (World: Raptor_World_Type_Without_Finalize'Class) + return Handled_IOStream_Type_User; + + -- We can do initizization and finalization on Ada level. + -- No need to provide such callbacks to the underlying C library + + --overriding procedure Initialize(Object: in out IOStream_Type_User); + + --overriding procedure Finalize(Object: in out IOStream_Type_User); + + not overriding procedure Do_Write_Byte (Stream: in out Handled_IOStream_Type_User; Byte: char); + + not overriding function Do_Write_Bytes (Stream: in out Handled_IOStream_Type_User; + Data: chars_ptr; + Size, Count: size_t) + return int; + + not overriding procedure Do_Write_End (Stream: in out Handled_IOStream_Type_User); + + not overriding function Do_Read_Bytes (Stream: in out Handled_IOStream_Type_User; + Data: chars_ptr; + Size, Count: size_t) return size_t; + + not overriding function Do_Read_Eof (Stream: in out Handled_IOStream_Type_User) return Boolean; + + type Stream_From_String(<>) is new IOStream_Type_User with private; + + -- Hack to prevent compilation error: + overriding function From_Handle(Handle: IOStream_Handle) return Stream_From_String; + overriding function From_Non_Null_Handle(Handle: IOStream_Handle) return Stream_From_String; + + not overriding function Open_From_String (World: Raptor_World_Type_Without_Finalize'Class; Value: String) + return Stream_From_String; + + -- I decided to implement it in Ada instead of using corresponding C functions + type Stream_To_String is new IOStream_Type_User with private; + + function Open (World: Raptor_World_Type_Without_Finalize'Class) return Stream_To_String; + + not overriding function Value (Stream: Stream_To_String) return String; + +private + + type Stream_From_String(Length: size_t) is new IOStream_Type_User with + record + Str: char_array(1..Length); + end record; + + type Stream_To_String is new Handled_IOStream_Type_User with + record + Str: Ada.Strings.Unbounded.Unbounded_String; + end record; + + -- Hack to prevent compilation error: + overriding function From_Handle(Handle: IOStream_Handle) return Stream_To_String; + overriding function From_Non_Null_Handle(Handle: IOStream_Handle) return Stream_To_String; + + overriding function Do_Write_Bytes (Stream: in out Stream_To_String; Data: chars_ptr; Size, Count: size_t) + return int; + +end RDF.Raptor.IOStream; diff --git a/ada/src/rdf-raptor-log.adb b/ada/src/rdf-raptor-log.adb new file mode 100644 index 000000000..a9a4ae3bf --- /dev/null +++ b/ada/src/rdf-raptor-log.adb @@ -0,0 +1,213 @@ +with Ada.Unchecked_Conversion; +with RDF.Auxiliary.Convert_Void; +with RDF.Raptor.Memory; +with System; use System; + +package body RDF.Raptor.Log is + + function Get_URI (Locator: Locator_Type) return URI_Type_Without_Finalize is + begin + return From_Handle(Get_Handle(Locator).URI); + end; + + function Get_File (Locator: Locator_Type) return String is + begin + return Value(Get_Handle(Locator).File); + end; + + function Get_Line (Locator: Locator_Type) return Natural is + begin + return Integer(Get_Handle(Locator).Line); + end; + + function Get_Column (Locator: Locator_Type) return Natural is + begin + return Integer(Get_Handle(Locator).Column); + end; + + function Get_Byte (Locator: Locator_Type) return Natural is + begin + return Integer(Get_Handle(Locator).Byte); + end; + + function Get_Error_Code (Message: Log_Message_Type) return int is + begin + return Get_Handle(Message).Code; + end; + + function Get_Domain (Message: Log_Message_Type) return Domain_Type is + begin + return Get_Handle(Message).Domain; + end; + + function Get_Log_Level (Message: Log_Message_Type) return Log_Level_Type is + begin + return Get_Handle(Message).Log_Level; + end; + + function Get_Text (Message: Log_Message_Type) return String is + begin + return Value(Get_Handle(Message).Text); + end; + + function Get_Locator (Message: Log_Message_Type'Class) return Locator_Type is + begin + return From_Non_Null_Handle(Get_Handle(Message).Locator); + end; + +-- type User_Defined_Access is access constant Log_Handler'Class; + package My_Conv is new RDF.Auxiliary.Convert_Void(Log_Handler'Class); + + procedure Our_Raptor_Log_Handler(Data: chars_ptr; Msg: Log_Message_Type) is + begin + Log_Message(My_Conv.To_Access(Data).all, Msg); + end; + + function raptor_world_set_log_handler(World: Raptor_World_Handle; + Data: chars_ptr; + Handler: Log_Handler_Procedure_Type) + return int + with Import, Convention=>C; + + procedure Set_Log_Handler(World: in out Raptor_World_Type_Without_Finalize'Class; Handler: access Log_Handler) is + begin + if raptor_world_set_log_handler(Get_Handle(World), My_Conv.To_C_Pointer(Handler), Our_Raptor_Log_Handler'Access) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_log_level_get_label(Level: Log_Level_Type) return chars_ptr + with Import, Convention=>C; + + function Get_Label (Level: Log_Level_Type) return String is + begin + return Value(raptor_log_level_get_label(Level)); + end; + + function raptor_domain_get_label (Level: Domain_Type) return chars_ptr + with Import, Convention=>C; + + function Get_Label (Level: Domain_Type) return String is + begin + return Value(raptor_domain_get_label(Level)); + end; + + function raptor_locator_print (Locator: Locator_Handle; Stream: RDF.Auxiliary.C_File_Access) return int + with Import, Convention=>C; + + procedure Print (Locator: Locator_Type; File: RDF.Auxiliary.C_File_Access) is + begin + if raptor_locator_print(Get_Handle(Locator), File) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_locator_format (Buffer: chars_ptr; Length: size_t; Locator: Locator_Handle) return int + with Import, Convention=>C; + + function Format (Locator: Locator_Type) return String is + Res1: constant int := raptor_locator_format(Null_Ptr, 0, Get_Handle(Locator)); + begin + if Res1 < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Buffer: aliased char_array := (1..size_t(Res1) => Interfaces.C.Nul); + begin + if raptor_locator_format(To_Chars_Ptr(Buffer'Unchecked_Access, Nul_Check=>False), 0, Get_Handle(Locator)) < 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + return To_Ada(Buffer); + end; + end; + + procedure raptor_free_uri (Handle: URI_Handle) + with Import, Convention=>C; + + function raptor_uri_copy (Handle: URI_Handle) + return URI_Handle + with Import, Convention=>C; + + procedure Finalize_Locator (Handle: Locator_Handle) is + package My_Conv is new RDF.Auxiliary.Convert_Void(Locator_Type_Record); + begin + raptor_free_uri(Handle.URI); + RDF.Raptor.Memory.Raptor_Free_Memory(Handle.File); + RDF.Raptor.Memory.Raptor_Free_Memory(My_Conv.To_C_Pointer(My_Conv.Object_Pointer(Handle))); + end; + + procedure Finalize_Handle (Object: Locator_Type; Handle: Locator_Handle) is + begin + Finalize_Locator(Handle); + end; + + package Locator_Conv is new RDF.Auxiliary.Convert_Void(Locator_Type_Record); + + -- FIXME: handle allocation errors (see D code for an example) + function Copy_Locator (Handle: Locator_Handle) return Locator_Handle is + Size: constant size_t := size_t((Locator_Type'Max_Size_In_Storage_Elements * Storage_Unit + (char'Size-1)) / char'Size); + Result2: constant chars_ptr := RDF.Raptor.Memory.raptor_alloc_memory(Size); + Result: constant Locator_Handle := Locator_Handle(Locator_Conv.To_Access(Result2)); + use RDF.Auxiliary; + function URI_To_Access is new Ada.Unchecked_Conversion(URI_Handle, chars_ptr); + begin + if Result = null then + return null; + end if; + Result.all := Handle.all; + Result.URI := raptor_uri_copy(Handle.URI); + if Result.URI = null then + RDF.Raptor.Memory.raptor_free_memory(Result2); + return null; + end if; + Result.File := RDF.Raptor.Memory.Copy_C_String(Handle.File); + if Result.File = Null_Ptr then + RDF.Raptor.Memory.raptor_free_memory(URI_To_Access(Result.URI)); + RDF.Raptor.Memory.raptor_free_memory(Result2); + return null; + end if; + return Result; + end; + + function Adjust_Handle (Object: Locator_Type; Handle: Locator_Handle) return Locator_Handle is + begin + return Copy_Locator(Handle); + end; + + procedure Finalize_Handle (Object: Log_Message_Type; Handle: Log_Message_Handle) is + package My_Conv is new RDF.Auxiliary.Convert_Void(Log_Message_Record); + begin + RDF.Raptor.Memory.Raptor_Free_Memory(Handle.Text); + Finalize_Locator(Handle.Locator); + RDF.Raptor.Memory.Raptor_Free_Memory(My_Conv.To_C_Pointer(My_Conv.Object_Pointer(Handle))); + end; + + package Log_Message_Conv is new RDF.Auxiliary.Convert_Void(Log_Message_Record); + + function Copy_Log_Message (Handle: Log_Message_Handle) return Log_Message_Handle is + Size: constant size_t := size_t((Log_Message_Type'Max_Size_In_Storage_Elements * Storage_Unit + (char'Size-1)) / char'Size); + Result2: constant chars_ptr := RDF.Raptor.Memory.raptor_alloc_memory(Size); + Result: constant Log_Message_Handle := Log_Message_Handle(Log_Message_Conv.To_Access(Result2)); + begin + Result.all := Handle.all; + Result.Text := RDF.Raptor.Memory.Copy_C_String(Handle.Text); + if Result.Text = Null_Ptr then + RDF.Raptor.Memory.raptor_free_memory(Result2); + end if; + Result.Locator := Copy_Locator(Handle.Locator); + if Result.Locator = null then + RDF.Raptor.Memory.raptor_free_memory(Result.Text); + RDF.Raptor.Memory.raptor_free_memory(Result2); + return null; + end if; + return Result; + end; + + function Adjust_Handle (Object: Log_Message_Type; Handle: Log_Message_Handle) + return Log_Message_Handle is + begin + return Copy_Log_Message(Handle); + end; + +end RDF.Raptor.Log; diff --git a/ada/src/rdf-raptor-log.ads b/ada/src/rdf-raptor-log.ads new file mode 100644 index 000000000..06984707a --- /dev/null +++ b/ada/src/rdf-raptor-log.ads @@ -0,0 +1,99 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary; +with RDF.Auxiliary.Handled_Record; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.World; use RDF.Raptor.World; + +package RDF.Raptor.Log is + + type Log_Level_Type is (None, Trace, Debug, Info, Warn, Error, Fatal) + with Convention => C; + for Log_Level_Type use (None => 0, + Trace => 1, + Debug => 2, + Info => 3, + Warn => 4, + Error => 5, + Fatal => 6); + function Last return Log_Level_Type renames Fatal; + + type Locator_Type_Record is private; + type Log_Message_Record is private; + + type Locator_Type_Record_Access is access all Locator_Type_Record with Convention=>C; + type Log_Message_Record_Access is access all Log_Message_Record with Convention=>C; + + package Locator_Handled_Record is new RDF.Auxiliary.Handled_Record(Locator_Type_Record, Locator_Type_Record_Access); + subtype Locator_Handle is Locator_Handled_Record.Access_Type; + type Locator_Type is new Locator_Handled_Record.Base_Object with null record; + + overriding procedure Finalize_Handle (Object: Locator_Type; Handle: Locator_Handle); + overriding function Adjust_Handle (Object: Locator_Type; Handle: Locator_Handle) return Locator_Handle; + + package Log_Message_Handled_Record is new RDF.Auxiliary.Handled_Record(Log_Message_Record, Log_Message_Record_Access); + subtype Log_Message_Handle is Log_Message_Handled_Record.Access_Type; + type Log_Message_Type is new Log_Message_Handled_Record.Base_Object with null record; + + -- FIXME: Log_Message_Type should NOT be finalized! + overriding procedure Finalize_Handle (Object: Log_Message_Type; Handle: Log_Message_Handle); + overriding function Adjust_Handle (Object: Log_Message_Type; Handle: Log_Message_Handle) + return Log_Message_Handle; + + not overriding function Get_URI (Locator: Locator_Type) return URI_Type_Without_Finalize; + + not overriding function Get_File (Locator: Locator_Type) return String; + + not overriding function Get_Line (Locator: Locator_Type) return Natural; + not overriding function Get_Column (Locator: Locator_Type) return Natural; + not overriding function Get_Byte (Locator: Locator_Type) return Natural; + + not overriding procedure Print (Locator: Locator_Type; File: RDF.Auxiliary.C_File_Access); + + not overriding function Format (Locator: Locator_Type) return String; + + not overriding function Get_Error_Code (Message: Log_Message_Type) return int; + not overriding function Get_Domain (Message: Log_Message_Type) return Domain_Type; + not overriding function Get_Log_Level (Message: Log_Message_Type) return Log_Level_Type; + not overriding function Get_Text (Message: Log_Message_Type) return String; + not overriding function Get_Locator (Message: Log_Message_Type'Class) return Locator_Type; -- FIXME: Locator_Without_Finalie + + type Log_Handler is abstract tagged null record; + + type Log_Handler_Procedure_Type is access procedure (Data: Chars_Ptr; Msg: Log_Message_Type) + with Convention=>C; + + -- Internal + procedure Our_Raptor_Log_Handler(Data: chars_ptr; Msg: Log_Message_Type) + with Convention=>C; + + not overriding procedure Log_Message(Handler: Log_Handler; Info: Log_Message_Type'Class) is abstract; + + not overriding procedure Set_Log_Handler(World: in out Raptor_World_Type_Without_Finalize'Class; + Handler: access Log_Handler); + + not overriding function Get_Label (Level: Log_Level_Type) return String; + function Get_Label (Level: Domain_Type) return String; + +private + + type Locator_Type_Record is + record + URI: URI_Handle; + File: chars_ptr; + Line, Column, Byte: int; + end record + with Convention => C; + + type Log_Message_Record is + record + Code: Interfaces.C.int; + Domain: Domain_Type; + Log_Level: Log_Level_Type; + -- Locator: access Locator_Type; + Locator: Locator_Handle; + Text: chars_ptr; + end record + with Convention => C; + +end RDF.Raptor.Log; diff --git a/ada/src/rdf-raptor-memory.adb b/ada/src/rdf-raptor-memory.adb new file mode 100644 index 000000000..46fdb5a34 --- /dev/null +++ b/ada/src/rdf-raptor-memory.adb @@ -0,0 +1,20 @@ +package body RDF.Raptor.Memory is + + function C_Strncpy (Target, Source: Chars_Ptr; Len: size_t) return chars_ptr + with Import, Convention=>C, External_Name=>"strncpy"; + + procedure C_Strncpy (Target, Source: chars_ptr; Len: size_t) is + Dummy: chars_ptr := C_Strncpy(Target, Source, Len); + begin + null; + end; + + function Copy_C_String (Str: chars_ptr) return Chars_Ptr is + Len: constant size_t := Strlen(Str) + 1; + New_Str: constant Chars_Ptr := Raptor_Alloc_Memory(Len); + begin + C_Strncpy(New_Str, Str, Len); + return New_Str; + end; + +end RDF.Raptor.Memory; diff --git a/ada/src/rdf-raptor-memory.ads b/ada/src/rdf-raptor-memory.ads new file mode 100644 index 000000000..69408f921 --- /dev/null +++ b/ada/src/rdf-raptor-memory.ads @@ -0,0 +1,19 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; + +-- This are thin bindings +package RDF.Raptor.Memory is + + procedure raptor_free_memory (ptr: chars_ptr) + with Import, Convention=>C; + + function raptor_alloc_memory (size: size_t) return chars_ptr + with Import, Convention=>C; + + function raptor_calloc_memory (nmemb: size_t; size: size_t) return chars_ptr + with Import, Convention=>C; + + -- Missing in C code, so I implement it in Ada + function Copy_C_String (Str: chars_ptr) return chars_ptr; + +end RDF.Raptor.Memory; diff --git a/ada/src/rdf-raptor-namespace.adb b/ada/src/rdf-raptor-namespace.adb new file mode 100644 index 000000000..9b8c5c284 --- /dev/null +++ b/ada/src/rdf-raptor-namespace.adb @@ -0,0 +1,151 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Raptor.Namespace_Stack; use RDF.Raptor.Namespace_Stack; +with RDF.Raptor.Memory; + +package body RDF.Raptor.Namespace is + + function raptor_new_namespace (Stack: Namespace_Stack_Handle; + Prefix: Char_Array; + NS: Char_Array; + Depth: Int) + return Namespace_Handle + with Import, Convention=>C; + + function Create (Stack: Namespace_Stack_Type_Without_Finalize'Class; + Prefix: String; + NS: String; + Depth: Natural) + return Namespace_Type is + Handle: constant Namespace_Handle := + raptor_new_namespace(Get_Handle(Stack), + To_C(Prefix, Append_Nul=>True), + To_C(NS, Append_Nul=>True), + Int(Depth)); + begin + return From_Non_Null_Handle(Handle); + end; + + function raptor_new_namespace_from_uri (Stack: Namespace_Stack_Handle; + Prefix: char_array; + URI: URI_Handle) + return Namespace_Handle + with Import, Convention=>C; + + -- FIXME: Forgotten to pass `depth` argument + function From_URI (Stack: Namespace_Stack_Type_Without_Finalize'Class; + Prefix: String; + URI: URI_Type_Without_Finalize'Class; + Depth: Integer) + return Namespace_Type is + Handle: constant Namespace_Handle := + raptor_new_namespace_from_uri (Get_Handle(Stack), + To_C(Prefix, Append_Nul=>True), + Get_Handle(URI)); + begin + return From_Non_Null_Handle(Handle); + end; + + procedure raptor_free_namespace (Handle: Namespace_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Namespace_Type_Without_Finalize; Handle: Namespace_Handle) is + begin + raptor_free_namespace(Handle); + end; + + function raptor_namespace_get_uri (Handle: Namespace_Handle) return URI_Handle + with Import, Convention=>C; + + -- raptor_namespace_get_uri() may return NULL (for xmlns="") + function Get_URI (NS: Namespace_Type_Without_Finalize) return URI_Type_Without_Finalize is + begin + return From_Handle( raptor_namespace_get_uri(Get_Handle(NS)) ); + end; + + function raptor_namespace_get_prefix (Handle: Namespace_Handle) return chars_ptr + with Import, Convention=>C; + + function Get_Prefix (NS: Namespace_Type_Without_Finalize) return String is + begin + return Value( raptor_namespace_get_prefix(Get_Handle(NS)) ); + end; + + function raptor_namespace_write (NS: Namespace_Handle; Stream: IOStream_Handle) return int + with Import, Convention=>C; + + procedure Write (NS: Namespace_Type_Without_Finalize; Stream: IOStream_Type_Without_Finalize'Class) is + begin + if raptor_namespace_write(Get_Handle(NS), Get_Handle(Stream)) /= 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_namespace_format_as_xml (NS: Namespace_Handle; Stream: access size_t) return chars_ptr + with Import, Convention=>C; + + function Format_As_XML (NS: Namespace_Type_Without_Finalize) return String is + C_Str: constant chars_ptr := raptor_namespace_format_as_xml(Get_Handle(NS), null); + begin + if C_Str = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Result: constant String := Value(C_Str); + begin + RDF.Raptor.Memory.Raptor_Free_Memory(C_Str); + return Result; + end; + end; + + function Get_Prefix (Object: Prefix_And_URI) return String is (Object.Prefix); + function Get_URI (Object: Prefix_And_URI) return URI_String is (Object.URI); + + function raptor_xml_namespace_string_parse (Str: char_array; Prefix, URI: access chars_ptr) return int + with Import, Convention=>C; + + function String_Parse (NS: String) return Prefix_And_URI is + C_Prefix, C_URI: aliased chars_ptr; + begin + if raptor_xml_namespace_string_parse(To_C(NS), C_Prefix'Access, C_URI'Access) /= 0 then + raise RDF_Exception; + end if; + declare + Prefix: constant String := Value(C_Prefix); + URI: constant URI_String := URI_String(String'(Value(C_URI))); + begin + RDF.Raptor.Memory.raptor_free_memory(C_Prefix); + RDF.Raptor.Memory.raptor_free_memory(C_URI ); + return (Prefix_Length=>Prefix'Length, URI_Length=>URI'Length, Prefix=>Prefix, URI=>URI); + end; + end; + + function Extract_Prefix (NS: String) return String is + C_Prefix: aliased chars_ptr; + begin + if raptor_xml_namespace_string_parse(To_C(NS), C_Prefix'Access, null) /= 0 then + raise RDF_Exception; + end if; + declare + Prefix: constant String := Value(C_Prefix); + begin + RDF.Raptor.Memory.raptor_free_memory(C_Prefix); + return Prefix; + end; + end; + + function Extract_URI (NS: String) return URI_String is + C_URI: aliased chars_ptr; + begin + if raptor_xml_namespace_string_parse(To_C(NS), null, C_URI'Access) /= 0 then + raise RDF_Exception; + end if; + declare + URI: constant URI_String := URI_String(String'(Value(C_URI))); + begin + RDF.Raptor.Memory.raptor_free_memory(C_URI); + return URI; + end; + end; + +end RDF.Raptor.Namespace; diff --git a/ada/src/rdf-raptor-namespace.ads b/ada/src/rdf-raptor-namespace.ads new file mode 100644 index 000000000..1ee4fa819 --- /dev/null +++ b/ada/src/rdf-raptor-namespace.ads @@ -0,0 +1,62 @@ +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Auxiliary; use RDF.Auxiliary; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; +limited with RDF.Raptor.Namespace_Stack; + +package RDF.Raptor.Namespace is + + package Namespace_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + subtype Namespace_Handle is Namespace_Handled_Record.Access_Type; + + type Namespace_Type_Without_Finalize is new Namespace_Handled_Record.Base_Object with null record; + + overriding procedure Finalize_Handle (Object: Namespace_Type_Without_Finalize; Handle: Namespace_Handle); + + not overriding function Get_URI (NS: Namespace_Type_Without_Finalize) return URI_Type_Without_Finalize; + + not overriding function Get_Prefix (NS: Namespace_Type_Without_Finalize) return String; + + not overriding procedure Write (NS: Namespace_Type_Without_Finalize; Stream: IOStream_Type_Without_Finalize'Class); + + not overriding function Format_As_XML (NS: Namespace_Type_Without_Finalize) return String; + + package Handlers is new Namespace_Handled_Record.Common_Handlers(Namespace_Type_Without_Finalize); + + type Namespace_Type is new Handlers.Base_With_Finalization with null record; + + type Namespace_Type_User is new Handlers.User_Type with null record; + + not overriding function Create (Stack: RDF.Raptor.Namespace_Stack.Namespace_Stack_Type_Without_Finalize'Class; + Prefix: String; + NS: String; + Depth: Natural) + return Namespace_Type; + + not overriding function From_URI (Stack: RDF.Raptor.Namespace_Stack.Namespace_Stack_Type_Without_Finalize'Class; + Prefix: String; + URI: URI_Type_Without_Finalize'Class; + Depth: Integer) + return Namespace_Type; + + type Prefix_And_URI(<>) is private; + + function Get_Prefix (Object: Prefix_And_URI) return String; + function Get_URI (Object: Prefix_And_URI) return URI_String; + + -- See also Extract_Prefix and Extract_URI + function String_Parse (NS: String) return Prefix_And_URI; + + function Extract_Prefix (NS: String) return String; + function Extract_URI (NS: String) return URI_String; + +private + + type Prefix_And_URI (Prefix_Length, URI_Length: Natural) is + record + Prefix: String(1..Prefix_Length); + URI: URI_String(1..URI_Length); + end record; + +end RDF.Raptor.Namespace; diff --git a/ada/src/rdf-raptor-namespace_stack.adb b/ada/src/rdf-raptor-namespace_stack.adb new file mode 100644 index 000000000..5c907168c --- /dev/null +++ b/ada/src/rdf-raptor-namespace_stack.adb @@ -0,0 +1,142 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.C_String_Holders; use RDF.Auxiliary.C_String_Holders; +with RDF.Raptor.Namespace; use RDF.Raptor.Namespace; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; + +package body RDF.Raptor.Namespace_Stack is + + procedure raptor_namespaces_clear (Stack: Namespace_Stack_Handle) + with Import, Convention=>C; + + procedure Clear (Stack: in out Namespace_Stack_Type_Without_Finalize) is + begin + raptor_namespaces_clear(Get_Handle(Stack)); + end; + + procedure raptor_free_namespaces (Stack: Namespace_Stack_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Namespace_Stack_Type_Without_Finalize; Handle: Namespace_Stack_Handle) is + begin + raptor_free_namespaces(Handle); + end; + + function raptor_namespaces_start_namespace_full (Stack: Namespace_Stack_Handle; + Prefix: chars_ptr; + URI: chars_ptr; + Depth: int) + return Int + with Import, Convention=>C; + + procedure Start_Namespace (Stack: in out Namespace_Stack_Type_Without_Finalize; + Prefix: String_Holders.Holder; + NS_URI: String_Holders.Holder; + Depth: Natural) is + Prefix_N: constant C_String_Holder := To_C_String_Holder(Prefix); + URI_N : constant C_String_Holder := To_C_String_Holder(NS_URI); + begin + if raptor_namespaces_start_namespace_full(Get_Handle(Stack), + C_String(Prefix_N), + C_String(URI_N), + int(Depth)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + procedure raptor_namespaces_end_for_depth (Stack: Namespace_Stack_Handle; Depth: int) + with Import, Convention=>C; + + procedure End_For_Depth (Stack: in out Namespace_Stack_Type_Without_Finalize; Depth: Natural) is + begin + raptor_namespaces_end_for_depth(Get_Handle(Stack), Int(Depth)); + end; + + function raptor_namespaces_get_default_namespace (Stack: Namespace_Stack_Handle) return Namespace_Handle + with Import, Convention=>C; + + function Get_Default_Namespace (Stack: Namespace_Stack_Type_Without_Finalize) return Namespace_Type_Without_Finalize is + begin + return From_Non_Null_Handle( raptor_namespaces_get_default_namespace(Get_Handle(Stack)) ); + end; + + procedure raptor_namespaces_start_namespace (Stack: Namespace_Stack_Handle; Namespace: Namespace_Handle) + with Import, Convention=>C; + + procedure Start_Namespace (Stack: in out Namespace_Stack_Type_Without_Finalize; Namespace: Namespace_Type'Class) is + begin + raptor_namespaces_start_namespace(Get_Handle(Stack), Get_Handle(Namespace)); + end; + + function raptor_new_namespaces (World: Raptor_World_Handle; + Defaults: Defaults_Type) + return Namespace_Stack_Handle + with Import, Convention=>C; + + function Create_Stack (World: Raptor_World_Type_Without_Finalize'Class; Defaults: Defaults_Type) + return Namespace_Stack_Type is + begin + return From_Non_Null_Handle( raptor_new_namespaces(Get_Handle(World), Defaults) ); + end; + + function raptor_namespaces_find_namespace (Stack: Namespace_Stack_Handle; + Prefix: chars_ptr; + Len: int) + return Namespace_Handle + with Import, Convention=>C; + + function Find_Namespace (Stack: Namespace_Stack_Type_Without_Finalize; Prefix: String) return Namespace_Type_Without_Finalize is + C_Prefix: aliased char_array := My_To_C_Without_Nul(Prefix); + Handle: constant Namespace_Handle := + raptor_namespaces_find_namespace(Get_Handle(Stack), + To_Chars_Ptr(C_Prefix'Unchecked_Access), + Prefix'Length); + begin + return From_Non_Null_Handle(Handle); + end; + + function Find_Default_Namespace (Stack: Namespace_Stack_Type_Without_Finalize) return Namespace_Type_Without_Finalize is + begin + return From_Non_Null_Handle( raptor_namespaces_find_namespace(Get_Handle(Stack), Null_Ptr, 0) ); + end; + + function raptor_namespaces_find_namespace_by_uri (Stack: Namespace_Stack_Handle; + URI: URI_Handle) + return Namespace_Handle + with Import, Convention=>C; + + function Find_Namespace_By_URI (Stack: Namespace_Stack_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class) + return Namespace_Type_Without_Finalize is + begin + return From_Non_Null_Handle( raptor_namespaces_find_namespace_by_uri(Get_Handle(Stack), Get_Handle(URI)) ) ; + end; + + function raptor_namespaces_namespace_in_scope (Stack: Namespace_Stack_Handle; + NS: Namespace_Handle) + return int + with Import, Convention=>C; + + function In_Scope (Stack: Namespace_Stack_Type_Without_Finalize; NS: Namespace_Type'Class) + return Boolean is + begin + return raptor_namespaces_namespace_in_scope(Get_Handle(Stack), Get_Handle(NS)) /= 0; + end; + + function raptor_namespace_stack_start_namespace (Stack: Namespace_Stack_Handle; + NS: Namespace_Handle; + New_Depth: int) + return Int + with Import, Convention=>C; + + procedure Start_Namespace (Stack: in out Namespace_Stack_Type_Without_Finalize; + NS: Namespace_Type_Without_Finalize'Class; + New_Depth: Natural) is + begin + if raptor_namespace_stack_start_namespace(Get_Handle(Stack), Get_Handle(NS), int(New_Depth)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + +end RDF.Raptor.Namespace_Stack; diff --git a/ada/src/rdf-raptor-namespace_stack.ads b/ada/src/rdf-raptor-namespace_stack.ads new file mode 100644 index 000000000..c7f7720da --- /dev/null +++ b/ada/src/rdf-raptor-namespace_stack.ads @@ -0,0 +1,68 @@ +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Auxiliary; use RDF.Auxiliary; +with RDF.Raptor.Namespace; + +package RDF.Raptor.Namespace_Stack is + + package Namespace_Stack_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + subtype Namespace_Stack_Handle is Namespace_Stack_Handled_Record.Access_Type; + + type Namespace_Stack_Type_Without_Finalize is new Namespace_Stack_Handled_Record.Base_Object with null record; + + overriding procedure Finalize_Handle (Object: Namespace_Stack_Type_Without_Finalize; Handle: Namespace_Stack_Handle); + + not overriding procedure Clear (Stack: in out Namespace_Stack_Type_Without_Finalize); + + -- See also below + -- FIXME: Shouldn't it be Namespace_Type_Without_Finalize'Class? + not overriding procedure Start_Namespace (Stack: in out Namespace_Stack_Type_Without_Finalize; + Namespace: RDF.Raptor.Namespace.Namespace_Type'Class); + + not overriding procedure Start_Namespace (Stack: in out Namespace_Stack_Type_Without_Finalize; + Prefix: String_Holders.Holder; + NS_URI: String_Holders.Holder; + Depth: Natural); + + not overriding procedure End_For_Depth (Stack: in out Namespace_Stack_Type_Without_Finalize; Depth: Natural); + + not overriding function Get_Default_Namespace (Stack: Namespace_Stack_Type_Without_Finalize) + return RDF.Raptor.Namespace.Namespace_Type_Without_Finalize; + + not overriding function Find_Namespace (Stack: Namespace_Stack_Type_Without_Finalize; Prefix: String) + return RDF.Raptor.Namespace.Namespace_Type_Without_Finalize; + + not overriding function Find_Default_Namespace (Stack: Namespace_Stack_Type_Without_Finalize) + return RDF.Raptor.Namespace.Namespace_Type_Without_Finalize; + + not overriding function Find_Namespace_By_URI (Stack: Namespace_Stack_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class) + return RDF.Raptor.Namespace.Namespace_Type_Without_Finalize; + + not overriding function In_Scope (Stack: Namespace_Stack_Type_Without_Finalize; + NS: RDF.Raptor.Namespace.Namespace_Type'Class) + return Boolean; + + not overriding procedure Start_Namespace (Stack: in out Namespace_Stack_Type_Without_Finalize; + NS: RDF.Raptor.Namespace.Namespace_Type_Without_Finalize'Class; + New_Depth: Natural); + + package Handlers is new Namespace_Stack_Handled_Record.Common_Handlers(Namespace_Stack_Type_Without_Finalize); + + type Namespace_Stack_Type is new Handlers.Base_With_Finalization with null record; + + type Namespace_Stack_Type_User is new Handlers.User_Type with null record; + + type Defaults_Type is (None_Type, XML_Type, RDF_Type, Undefined_Type) + with Convention => C; + for Defaults_Type use (None_Type=>0, XML_Type=>1, RDF_Type=>2, Undefined_Type=>3); + + not overriding function Create_Stack (World: Raptor_World_Type_Without_Finalize'Class; + Defaults: Defaults_Type) + return Namespace_Stack_Type; + + -- raptor_namespaces_init() not bound (it seems that function is internal for Raptor implementation). + +end RDF.Raptor.Namespace_Stack; diff --git a/ada/src/rdf-raptor-options.adb b/ada/src/rdf-raptor-options.adb new file mode 100644 index 000000000..61e38d02c --- /dev/null +++ b/ada/src/rdf-raptor-options.adb @@ -0,0 +1,102 @@ +with RDF.Auxiliary; + +package body RDF.Raptor.Options is + + function Get_Domain (Description: Option_Description_Type_Without_Finalize) return Domain_Type is + begin + return Get_Handle(Description).Domain; + end; + + function Get_Option (Description: Option_Description_Type_Without_Finalize) return Raptor_Option is + begin + return Get_Handle(Description).Option; + end; + + function Get_Value_Type (Description: Option_Description_Type_Without_Finalize) return Value_Type_Type is + begin + return Get_Handle(Description).Value_Type; + end; + + function Get_Name (Description: Option_Description_Type_Without_Finalize) return String is + Handle: constant Option_Description_Handle := Get_Handle(Description); + begin + return Value(Handle.Name, Handle.Len); + end; + + function Get_Label (Description: Option_Description_Type_Without_Finalize) return String is + begin + return Value(Get_Handle(Description).Name); + end; + + function Get_URI (Description: Option_Description_Type_Without_Finalize) return URI_Type_Without_Finalize is + begin + return From_Handle(Get_Handle(Description).URI); + end; + + function raptor_option_get_count return unsigned + with Import, Convention=>C; + + function Get_Options_Count return Natural is + begin + return Natural(raptor_option_get_count); + end; + + function raptor_option_get_value_type_label (Value_Type: Value_Type_Type) return chars_ptr + with Import, Convention=>C; + + function Value_Type_Label (Value_Type: Value_Type_Type) return String is + Ptr: constant chars_ptr := raptor_option_get_value_type_label(Value_Type); + begin + if Ptr = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Value(Ptr); + end; + + function raptor_world_get_option_description (World: Raptor_World_Handle; + Domain: Domain_Type; + Option: Raptor_Option) + return Option_Description_Handle + with Import, Convention=>C; + + function Get_Option_Description (World: Raptor_World_Type_Without_Finalize'Class; + Domain: Domain_Type; + Option: Natural) + return Option_Description_Type is + begin + return Get_Option_Description(World, Domain, Raptor_Option'Val(Option)); + end; + + function Get_Option_Description (World: Raptor_World_Type_Without_Finalize'Class; + Domain: Domain_Type; + Option: Raptor_Option) + return Option_Description_Type is + begin + return From_Non_Null_Handle( raptor_world_get_option_description(Get_Handle(World), Domain, Option) ); + end; + + procedure raptor_world_get_option_description (Descrition: Option_Description_Handle) + with Import, Convention=>C; + + -- FIXME: Seems a nonsense + procedure Finalize_Handle (Object: Option_Description_Type_Without_Finalize; Handle: Option_Description_Handle) is + begin + raptor_world_get_option_description(Handle); + end; + + function raptor_world_get_option_from_uri (World: Raptor_World_Handle; URI: URI_Handle) + return Raptor_Option + with Import, Convention=>C; + + -- Crude hack + -- FIXME: URI_Type_Without_Finalize? + function Option_From_URI (World: Raptor_World_Type_Without_Finalize'Class; URI: URI_Type'Class) return Raptor_Option is + Result: constant Raptor_Option := raptor_world_get_option_from_uri(Get_Handle(World), Get_Handle(URI)); + begin + if not Result'Valid then + raise Constraint_Error; + end if; + return Result; + end; + +end RDF.Raptor.Options; diff --git a/ada/src/rdf-raptor-options.ads b/ada/src/rdf-raptor-options.ads new file mode 100644 index 000000000..820d9c715 --- /dev/null +++ b/ada/src/rdf-raptor-options.ads @@ -0,0 +1,169 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.World; use RDF.Raptor.World; + +package RDF.Raptor.Options is + + -- Limit to these options which are explicitly specified below. + -- If you try to do with an other option, it can lead to Constraint_Error in Ada :-( + -- Thus we need maintain updating this list, when the corresponding enum in C changes. + type Raptor_Option is (SCANNING, + ALLOW_NON_NS_ATTRIBUTES, + ALLOW_OTHER_PARSETYPES, + ALLOW_BAGID, + ALLOW_RDF_TYPE_RDF_LIST, + NORMALIZE_LANGUAGE, + NON_NFC_FATAL, + WARN_OTHER_PARSETYPES, + CHECK_RDF_ID, + RELATIVE_URIS, + WRITER_AUTO_INDENT, + WRITER_AUTO_EMPTY, + WRITER_INDENT_WIDTH, + WRITER_XML_VERSION, + WRITER_XML_DECLARATION, + NO_NET, + RESOURCE_BORDER, + LITERAL_BORDER, + BNODE_BORDER, + RESOURCE_FILL, + LITERAL_FILL, + BNODE_FILL, + HTML_TAG_SOUP, + MICROFORMATS, + HTML_LINK, + WWW_TIMEOUT, + WRITE_BASE_URI, + WWW_HTTP_CACHE_CONTROL, + WWW_HTTP_USER_AGENT, + JSON_CALLBACK, + JSON_EXTRA_DATA, + RSS_TRIPLES, + ATOM_ENTRY_URI, + PREFIX_ELEMENTS, + STRICT, + WWW_CERT_FILENAME, + WWW_CERT_TYPE, + WWW_CERT_PASSPHRASE, + NO_FILE, + WWW_SSL_VERIFY_PEER, + WWW_SSL_VERIFY_HOST, + LOAD_EXTERNAL_ENTITIES) + with Convention => C; + -- Use the default representation (it may probably be faster) + -- for Raptor_Option use (SCANNING => 0, + -- ALLOW_NON_NS_ATTRIBUTES => 1, + -- ALLOW_OTHER_PARSETYPES => 2, + -- ALLOW_BAGID => 3, + -- ALLOW_RDF_TYPE_RDF_LIST => 4, + -- NORMALIZE_LANGUAGE => 5, + -- NON_NFC_FATAL => 6, + -- WARN_OTHER_PARSETYPES => 7, + -- CHECK_RDF_ID => 8, + -- RELATIVE_URIS => 9, + -- WRITER_AUTO_INDENT => 10, + -- WRITER_AUTO_EMPTY => 11, + -- WRITER_INDENT_WIDTH => 12, + -- WRITER_XML_VERSION => 13, + -- WRITER_XML_DECLARATION => 14, + -- NO_NET => 15, + -- RESOURCE_BORDER => 16, + -- LITERAL_BORDER => 17, + -- BNODE_BORDER => 18, + -- RESOURCE_FILL => 19, + -- LITERAL_FILL => 20, + -- BNODE_FILL => 21, + -- HTML_TAG_SOUP => 22, + -- MICROFORMATS => 23, + -- HTML_LINK => 24, + -- WWW_TIMEOUT => 25, + -- WRITE_BASE_URI => 26, + -- WWW_HTTP_CACHE_CONTROL => 27, + -- WWW_HTTP_USER_AGENT => 28, + -- JSON_CALLBACK => 29, + -- JSON_EXTRA_DATA => 30, + -- RSS_TRIPLES => 31, + -- ATOM_ENTRY_URI => 32, + -- PREFIX_ELEMENTS => 33, + -- STRICT => 34, + -- WWW_CERT_FILENAME => 35, + -- WWW_CERT_TYPE => 36, + -- WWW_CERT_PASSPHRASE => 37, + -- NO_FILE => 38, + -- WWW_SSL_VERIFY_PEER => 39, + -- WWW_SSL_VERIFY_HOST => 40, + -- LOAD_EXTERNAL_ENTITIES => 41); + + function Last return Raptor_Option renames LOAD_EXTERNAL_ENTITIES; + + type Value_Type_Type is (TYPE_BOOL, TYPE_INT, TYPE_STRING, TYPE_URI) + with Convention => C; + + function Last return Value_Type_Type renames TYPE_URI; + + type Option_Description_Record is private; + + type Option_Description_Record_Access is access Option_Description_Record + with Convention => C; + + package Option_Description_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(Option_Description_Record, Option_Description_Record_Access); + + type Option_Description_Type_Without_Finalize is new Option_Description_Handled_Record.Base_Object with null record; + + subtype Option_Description_Handle is Option_Description_Handled_Record.Access_Type; + + overriding procedure Finalize_Handle (Object: Option_Description_Type_Without_Finalize; Handle: Option_Description_Handle); + + function Get_Domain (Description: Option_Description_Type_Without_Finalize) return Domain_Type; + + function Get_Option (Description: Option_Description_Type_Without_Finalize) return Raptor_Option; + + function Get_Value_Type (Description: Option_Description_Type_Without_Finalize) return Value_Type_Type; + + function Get_Name (Description: Option_Description_Type_Without_Finalize) return String; + + function Get_Label (Description: Option_Description_Type_Without_Finalize) return String; + + function Get_URI (Description: Option_Description_Type_Without_Finalize) return URI_Type_Without_Finalize; + + -- WARNING: Raptor_Option'Val(Get_Options_Count - 1) may throw Constraint_Error + function Get_Options_Count return Natural; + + function Value_Type_Label (Value_Type: Value_Type_Type) return String; + + package Handlers is new Option_Description_Handled_Record.Common_Handlers(Option_Description_Type_Without_Finalize); + + type Option_Description_Type is new Handlers.Base_With_Finalization with null record; + + type Option_Description_Type_User is new Handlers.User_Type with null record; + + not overriding function Get_Option_Description (World: Raptor_World_Type_Without_Finalize'Class; + Domain: Domain_Type; + Option: Natural) + return Option_Description_Type; + + not overriding function Get_Option_Description (World: Raptor_World_Type_Without_Finalize'Class; + Domain: Domain_Type; + Option: Raptor_Option) + return Option_Description_Type; + + function Option_From_URI (World: Raptor_World_Type_Without_Finalize'Class; URI: URI_Type'Class) + return Raptor_Option; + +private + + type Option_Description_Record is + record + Domain: Domain_Type; + Option: Raptor_Option; + Value_Type: Value_Type_Type; + Name: chars_ptr; + Len: size_t; + Label: chars_ptr; + URI: URI_Handle; + end record + with Convention => C; + +end RDF.Raptor.Options; diff --git a/ada/src/rdf-raptor-parser.adb b/ada/src/rdf-raptor-parser.adb new file mode 100644 index 000000000..da65c783f --- /dev/null +++ b/ada/src/rdf-raptor-parser.adb @@ -0,0 +1,378 @@ +with Ada.Unchecked_Conversion; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.Convert_Void; +with RDF.Auxiliary.C_String_Holders; use RDF.Auxiliary.C_String_Holders; +with RDF.Raptor.Memory; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; + +package body RDF.Raptor.Parser is + + -- use all type Parser_Type; + + function raptor_new_parser (World: Raptor_World_Handle; Name: char_array) return Parser_Handle + with Import, Convention=>C; + + function Create (World: Raptor_World_Type_Without_Finalize'Class; Name: String) return Parser_Type is + begin + return From_Non_Null_Handle( raptor_new_parser(Get_Handle(World), To_C(Name, Append_Nul=>True)) ); + end; + + function raptor_new_parser_for_content (World: Raptor_World_Handle; + URI: URI_Handle; + MIME_Type: chars_ptr; + Buffer: chars_ptr; + Len: size_t; + Identifier: chars_ptr) + return Parser_Handle + with Import, Convention=>C; + + function Create_From_Content (World: Raptor_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class; + Mime_Type : String_Holders.Holder; + Buffer : String_Holders.Holder; + Identifier: String_Holders.Holder) + return Parser_Type is + Mime_Type_N : constant C_String_Holder := To_C_String_Holder(Mime_Type); + Buffer_N : constant C_String_Holder := To_C_String_Holder(Buffer); + Identifier_N: constant C_String_Holder := To_C_String_Holder(Identifier); + begin + return From_Non_Null_Handle( raptor_new_parser_for_content(Get_Handle(World), + Get_Handle(URI), + C_String(Mime_Type_N), + C_String(Buffer_N), + Length(Buffer), + C_String(Identifier_N)) ); + end; + + function raptor_parser_get_locator (Parser: Parser_Handle) return Locator_Handle + with Import, Convention=>C; + + function Get_Locator (Parser: Parser_Type_Without_Finalize) return Locator_Type is + begin + return From_Handle(raptor_parser_get_locator(Get_Handle(Parser))); + end; + + procedure raptor_parser_parse_abort (Parser: Parser_Handle) + with Import, Convention=>C; + + procedure Parse_Abort (Parser: Parser_Type_Without_Finalize) is + begin + raptor_parser_parse_abort(Get_Handle(Parser)); + end; + + function raptor_parser_parse_chunk (Parser: Parser_Handle; Buffer: char_array; Len: size_t; Is_End: int) + return int + with Import, Convention=>C; + + procedure Parse_Chunk (Parser: Parser_Type_Without_Finalize; + Buffer: String; + Is_End: Boolean) is + begin + if raptor_parser_parse_chunk(Get_Handle(Parser), + My_To_C_Without_Nul(Buffer), + Buffer'Length, + (if Is_End then 1 else 0)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_parser_parse_file (Parser: Parser_Handle; URI, Base_URI: URI_Handle) return int + with Import, Convention=>C; + + procedure Parse_File (Parser: Parser_Type_Without_Finalize; + URI: URI_Type_Without_Finalize; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if raptor_parser_parse_file(Get_Handle(Parser), Get_Handle(URI), Get_Handle(Base_URI)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + procedure Parse_Stdin (Parser: Parser_Type_Without_Finalize; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + Parse_File (Parser, From_Handle(null), Base_URI); + end; + + function raptor_parser_parse_file_stream (Parser: Parser_Handle; + Stream: RDF.Auxiliary.C_File_Access; + Filename: char_array; + Base_URI: URI_Handle) return int + with Import, Convention=>C; + + procedure Parse_File_Stream (Parser: Parser_Type_Without_Finalize; + Stream: RDF.Auxiliary.C_File_Access; + Filename: String; + Base_URI: URI_Type_Without_Finalize'Class) is + begin + if raptor_parser_parse_file_stream(Get_Handle(Parser), Stream, To_C(Filename), Get_Handle(Base_URI)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_parser_parse_iostream (Parser: Parser_Handle; + Stream: IOStream_Handle; + Base_URI: URI_Handle) return int + with Import, Convention=>C; + + procedure Parse_IOStream (Parser: Parser_Type_Without_Finalize; + Stream: IOStream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class) is + begin + if raptor_parser_parse_iostream(Get_Handle(Parser), Get_Handle(Stream), Get_Handle(Base_URI)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_parser_parse_start (Parser: Parser_Handle; URI: URI_Handle) return int + with Import, Convention=>C; + + procedure Parse_Start (Parser: Parser_Type_Without_Finalize; URI: URI_Type_Without_Finalize'Class) is + begin + if raptor_parser_parse_start(Get_Handle(Parser), Get_Handle(URI)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_parser_parse_uri (Parser: Parser_Handle; + URI, Base_URI: URI_Handle) return int + with Import, Convention=>C; + + procedure Parse_URI (Parser: Parser_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if raptor_parser_parse_uri(Get_Handle(Parser), Get_Handle(URI), Get_Handle(Base_URI)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_parser_parse_uri_with_connection (Parser: Parser_Handle; + URI, Base_URI: URI_Handle; + Connection: Connection_Type) + return int + with Import, Convention=>C; + + procedure Parse_URI_With_Connection (Parser: Parser_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null)); + Connection: Connection_Type := null) is + begin + if raptor_parser_parse_uri_with_connection(Get_Handle(Parser), + Get_Handle(URI), + Get_Handle(Base_URI), + Connection) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_parser_get_graph (Parser: Parser_Handle) return URI_Handle + with Import, Convention=>C; + + function Get_Graph (Parser: Parser_Type_Without_Finalize) return URI_Type is + begin + return From_Handle(raptor_parser_get_graph(Get_Handle(Parser))); + end; + + function raptor_parser_get_description (Parser: Parser_Handle) return Raptor_Syntax_Description_Type + with Import, Convention=>C; + + function Get_Description (Parser: Parser_Type_Without_Finalize) return Raptor_Syntax_Description_Type is + begin + return raptor_parser_get_description(Get_Handle(Parser)); + end; + + function raptor_parser_get_name (Parser: Parser_Handle) return chars_ptr + with Import, Convention=>C; + + function Get_Name (Parser: Parser_Type_Without_Finalize) return String is + begin + return Value(raptor_parser_get_name(Get_Handle(Parser))); + end; + + function raptor_parser_set_option (Parser: Parser_Handle; Option: Raptor_Option; Value: chars_ptr; Int_Value: int) + return int + with Import, Convention=>C; + + procedure Set_Option (Parser: in out Parser_Type_Without_Finalize; Option: Raptor_Option; Value: String) is + Value2: aliased char_array := To_C(Value); + begin + if raptor_parser_set_option(Get_Handle(Parser), Option, To_Chars_Ptr(Value2'Unchecked_Access), 0) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + procedure Set_Option (Parser: in out Parser_Type_Without_Finalize; Option: Raptor_Option; Value: int) is + begin + if raptor_parser_set_option(Get_Handle(Parser), Option, Null_Ptr, Value) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + type String_P_Type is access all chars_ptr with Convention=>C; + type Int_P_Type is access all int with Convention=>C; + + function raptor_parser_get_option (Parser: Parser_Handle; + Option: Raptor_Option; + String_P: String_P_Type; + Integer_P: Int_P_Type) return int + with Import, Convention=>C; + + function Get_Numeric_Option (Parser: Parser_Type_Without_Finalize; Option: Raptor_Option) return Natural is + V: aliased int; + begin + if raptor_parser_get_option(Get_Handle(Parser), Option, null, V'Unchecked_Access) < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Natural(V); + end; + + function Get_String_Option (Parser: Parser_Type_Without_Finalize; Option: Raptor_Option) return String is + V: aliased chars_ptr; + begin + if raptor_parser_get_option(Get_Handle(Parser), Option, V'Unchecked_Access, null) < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Value(V); -- do NOT free it + end; + + function raptor_parser_get_accept_header (Parser: Parser_Handle) return chars_ptr + with Import, Convention=>C; + + function Get_Accept_Header (Parser: Parser_Type_Without_Finalize) return String is + V: constant chars_ptr := raptor_parser_get_accept_header(Get_Handle(Parser)); + begin + if V = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + S: constant String := Value(V); + begin + RDF.Raptor.Memory.raptor_free_memory(V); + return S; + end; + end; + + function raptor_parser_get_world (Parser: Parser_Handle) return Raptor_World_Handle + with Import, Convention=>C; + + function Get_World (Parser: Parser_Type_Without_Finalize) return Raptor_World_Type_Without_Finalize is + begin + return From_Handle(raptor_parser_get_world(Get_Handle(Parser))); + end; + + procedure raptor_free_parser (Handle: Parser_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Parser_Type_Without_Finalize; Handle: Parser_Handle) is + begin + raptor_free_parser(Handle); + end; + +-- type User_Defined_Access is access constant Parser_Type_Without_Finalize'Class; + package My_Conv is new RDF.Auxiliary.Convert_Void(Parser_Type_Without_Finalize'Class); + + type raptor_statement_handler is access procedure (Data: chars_ptr; Statement: Statement_Handle) + with Convention=>C; + + type raptor_graph_mark_handler is access procedure (Data: chars_ptr; URI: URI_Handle; Flags: int) + with Convention=>C; + + type raptor_namespace_handler is access procedure (Data: chars_ptr; NS: Namespace_Handle) + with Convention=>C; + + type raptor_uri_filter_func is access function (Data: chars_ptr; URI: URI_Handle) return int + with Convention=>C; + + procedure raptor_statement_handler_impl (Data: Chars_Ptr; Statement: Statement_Handle) + with Convention=>C; + + procedure raptor_graph_mark_handler_impl (Data: chars_ptr; URI: URI_Handle; Flags: int) + with Convention=>C; + + procedure raptor_namespace_handler_impl (Data: Chars_Ptr; NS: Namespace_Handle) + with Convention=>C; + + function raptor_uri_filter_impl (Data: chars_ptr; URI: URI_Handle) return int + with Convention=>C; + + procedure raptor_statement_handler_impl (Data: Chars_Ptr; Statement: Statement_Handle) is + begin + Statement_Handler(My_Conv.To_Access(Data).all, Statement_Type_Without_Finalize'(From_Non_Null_Handle(Statement))); + end; + + procedure raptor_graph_mark_handler_impl (Data: chars_ptr; URI: URI_Handle; Flags: int) is + function Conv is new Ada.Unchecked_Conversion(int, Graph_Mark_Flags); + begin + Graph_Mark_Handler(My_Conv.To_Access(Data).all, URI_Type_Without_Finalize'(From_Non_Null_Handle(URI)), Conv(Flags)); + end; + + procedure raptor_namespace_handler_impl (Data: Chars_Ptr; NS: Namespace_Handle) is + begin + Namespace_Handler(My_Conv.To_Access(Data).all, Namespace_Type_Without_Finalize'(From_Non_Null_Handle(NS))); + end; + + function raptor_uri_filter_impl (Data: chars_ptr; URI: URI_Handle) return int is + begin + return (if URI_Filter(My_Conv.To_Access(Data).all, URI_Type_Without_Finalize'(From_Non_Null_Handle(URI))) then 1 else 0); + end; + + procedure Initialize_All_Callbacks (Parser: in out Parser_Type_Without_Finalize) is + begin + Initialize_Graph_Mark_Handler(Parser); + Initialize_Statement_Handler (Parser); + Initialize_Namespace_Handler (Parser); + Initialize_URI_Filter (Parser); + end; + + procedure raptor_parser_set_statement_handler (Parser: Parser_Handle; + Data: chars_ptr; + Handler: raptor_statement_handler) + with Import, Convention=>C; + + procedure raptor_parser_set_graph_mark_handler (Parser: Parser_Handle; + Data: chars_ptr; + Handler: raptor_graph_mark_handler) + with Import, Convention=>C; + + procedure raptor_parser_set_namespace_handler (Parser: Parser_Handle; + Data: chars_ptr; + Handler: raptor_namespace_handler) + with Import, Convention=>C; + + procedure raptor_parser_set_uri_filter (Parser: Parser_Handle; + Handler: raptor_uri_filter_func; + Data: chars_ptr) + with Import, Convention=>C; + + procedure Initialize_Graph_Mark_Handler (Object: in out Parser_Type_Without_Finalize) is + begin + raptor_parser_set_graph_mark_handler(Get_Handle(Object), + My_Conv.To_C_Pointer(Object'Unchecked_Access), + raptor_graph_mark_handler_impl'Access); + end; + + procedure Initialize_Statement_Handler (Object: in out Parser_Type_Without_Finalize) is + begin + raptor_parser_set_statement_handler(Get_Handle(Object), + My_Conv.To_C_Pointer(Object'Unchecked_Access), + raptor_statement_handler_impl'Access); + end; + + procedure Initialize_Namespace_Handler (Object: in out Parser_Type_Without_Finalize) is + begin + raptor_parser_set_namespace_handler(Get_Handle(Object), + My_Conv.To_C_Pointer(Object'Unchecked_Access), + raptor_namespace_handler_impl'Access); + end; + + procedure Initialize_URI_Filter (Object: in out Parser_Type_Without_Finalize) is + begin + raptor_parser_set_uri_filter(Get_Handle(Object), + raptor_uri_filter_impl'Access, + My_Conv.To_C_Pointer(Object'Unchecked_Access)); + end; + +end RDF.Raptor.Parser; diff --git a/ada/src/rdf-raptor-parser.ads b/ada/src/rdf-raptor-parser.ads new file mode 100644 index 000000000..79521aa98 --- /dev/null +++ b/ada/src/rdf-raptor-parser.ads @@ -0,0 +1,133 @@ +with Interfaces.C; use Interfaces.C; +-- with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary; use RDF.Auxiliary; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; +with RDF.Raptor.Statement; use RDF.Raptor.Statement; +with RDF.Raptor.Namespace; use RDF.Raptor.Namespace; +with RDF.Raptor.Syntaxes; use RDF.Raptor.Syntaxes; +with RDF.Raptor.Log; use RDF.Raptor.Log; +with RDF.Raptor.WWW; use RDF.Raptor.WWW; +with RDF.Raptor.Options; use RDF.Raptor.Options; + +package RDF.Raptor.Parser is + + package Parser_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + subtype Parser_Handle is Parser_Handled_Record.Access_Type; + + type Parser_Type_Without_Finalize is new Parser_Handled_Record.Base_Object with null record; + + overriding procedure Finalize_Handle (Object: Parser_Type_Without_Finalize; Handle: Parser_Handle); + + type Graph_Mark_Flags is (Graph_Mark_Start, Graph_Mark_Declared); + for Graph_Mark_Flags'Size use int'Size; -- hack + for Graph_Mark_Flags use (Graph_Mark_Start=>1, Graph_Mark_Declared=>2); + + -- You can call this function or initialize only callbacks you need (below). + not overriding procedure Initialize_All_Callbacks (Parser: in out Parser_Type_Without_Finalize); + + not overriding procedure Initialize_Graph_Mark_Handler (Object: in out Parser_Type_Without_Finalize); + not overriding procedure Initialize_Statement_Handler (Object: in out Parser_Type_Without_Finalize); + not overriding procedure Initialize_Namespace_Handler (Object: in out Parser_Type_Without_Finalize); + not overriding procedure Initialize_URI_Filter (Object: in out Parser_Type_Without_Finalize); + + not overriding procedure Graph_Mark_Handler (Object: Parser_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Flags: Graph_Mark_Flags) is null; + + not overriding procedure Statement_Handler (Object: Parser_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class) is null; + + not overriding procedure Namespace_Handler (Object: Parser_Type_Without_Finalize; + Namespace: Namespace_Type_Without_Finalize'Class) is null; + + not overriding function URI_Filter (Object: Parser_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class) return Boolean is (True); + + -- FIXME: Should be Locator_Type_Without_Finalize + not overriding function Get_Locator (Parser: Parser_Type_Without_Finalize) return Locator_Type; + + not overriding procedure Parse_Abort (Parser: Parser_Type_Without_Finalize); + + not overriding procedure Parse_Chunk (Parser: Parser_Type_Without_Finalize; + Buffer: String; + Is_End: Boolean); + + not overriding procedure Parse_File (Parser: Parser_Type_Without_Finalize; + URI: URI_Type_Without_Finalize; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + not overriding procedure Parse_Stdin (Parser: Parser_Type_Without_Finalize; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + not overriding procedure Parse_File_Stream (Parser: Parser_Type_Without_Finalize; + Stream: RDF.Auxiliary.C_File_Access; + Filename: String; + Base_URI: URI_Type_Without_Finalize'Class); + + not overriding procedure Parse_IOStream (Parser: Parser_Type_Without_Finalize; + Stream: IOStream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class); + + not overriding procedure Parse_Start (Parser: Parser_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class); + + not overriding procedure Parse_URI (Parser: Parser_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + not overriding procedure Parse_URI_With_Connection (Parser: Parser_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null)); + Connection: Connection_Type := null); + + not overriding function Get_Graph (Parser: Parser_Type_Without_Finalize) return URI_Type; + + not overriding function Get_Description (Parser: Parser_Type_Without_Finalize) + return Raptor_Syntax_Description_Type; + + not overriding function Get_Name (Parser: Parser_Type_Without_Finalize) return String; + + not overriding procedure Set_Option (Parser: in out Parser_Type_Without_Finalize; + Option: Raptor_Option; + Value: String); + not overriding procedure Set_Option (Parser: in out Parser_Type_Without_Finalize; + Option: Raptor_Option; + Value: int); + + -- Not sure if we should be able to query here whether the option is numeric + not overriding function Get_Numeric_Option (Parser: Parser_Type_Without_Finalize; + Option: Raptor_Option) + return Natural; + not overriding function Get_String_Option (Parser: Parser_Type_Without_Finalize; + Option: Raptor_Option) + return String; + + not overriding function Get_Accept_Header (Parser: Parser_Type_Without_Finalize) return String; + + not overriding function Get_World (Parser: Parser_Type_Without_Finalize) + return Raptor_World_Type_Without_Finalize; + + -- This type can provide a small performance benefit over Parser_Type defined below. + -- However if your main concern is reliability, not performance, + -- you may wish use Parser_Type defined below. + package Handlers is new Parser_Handled_Record.Common_Handlers(Parser_Type_Without_Finalize); + + type Parser_Type is new Handlers.Base_With_Finalization with null record; + + type Parser_Type_User is new Handlers.User_Type with null record; + + not overriding function Create (World: Raptor_World_Type_Without_Finalize'Class; Name: String) + return Parser_Type; + + not overriding function Create_From_Content (World: Raptor_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class; + Mime_Type: String_Holders.Holder; + Buffer: String_Holders.Holder; + Identifier: String_Holders.Holder) + return Parser_Type; + +end RDF.Raptor.Parser; diff --git a/ada/src/rdf-raptor-serializer.adb b/ada/src/rdf-raptor-serializer.adb new file mode 100644 index 000000000..69bcc7992 --- /dev/null +++ b/ada/src/rdf-raptor-serializer.adb @@ -0,0 +1,235 @@ +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary; + +package body RDF.Raptor.Serializer is + + function raptor_serializer_start_to_iostream (Serializer: Serializer_Handle; + URI: URI_Handle; + IOStream: IOStream_Handle) + return int + with Import, Convention=>C; + + procedure Start_To_IOStream (Serializer: Serializer_Type_Without_Finalize; + IOStream: IOStream_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if raptor_serializer_start_to_iostream(Get_Handle(Serializer), Get_Handle(URI), Get_Handle(IOStream)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_serializer_start_to_filename (Serializer: Serializer_Handle; Filename: char_array) + return int + with Import, Convention=>C; + + procedure Start_To_Filename (Serializer: Serializer_Type_Without_Finalize; Filename: String) is + begin + if raptor_serializer_start_to_filename(Get_Handle(Serializer), To_C(Filename)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_serializer_start_to_file_handle (Serializer: Serializer_Handle; + URI: URI_Handle; + FH: RDF.Auxiliary.C_File_Access) + return int + with Import, Convention=>C; + + procedure Start_To_Filehandle (Serializer: Serializer_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + FH: RDF.Auxiliary.C_File_Access) is + begin + if raptor_serializer_start_to_file_handle(Get_Handle(Serializer), Get_Handle(URI), FH) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_serializer_set_namespace (Serializer: Serializer_Handle; URI: URI_Handle; Prefix: chars_ptr) + return int + with Import, Convention=>C; + + procedure Set_Namespace (Serializer: in out Serializer_Type_Without_Finalize; + Prefix: String; + URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + V: aliased char_array := To_C(Prefix); + begin + if raptor_serializer_set_namespace(Get_Handle(Serializer), Get_Handle(URI), To_Chars_Ptr(V'Unchecked_Access)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + procedure Set_Namespace_Without_Prefix (Serializer: in out Serializer_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if raptor_serializer_set_namespace(Get_Handle(Serializer), Get_Handle(URI), Null_Ptr) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_serializer_set_namespace_from_namespace (Serializer: Serializer_Handle; + Namespace: Namespace_Handle) + return int + with Import, Convention=>C; + + procedure Set_Namespace (Serializer: in out Serializer_Type_Without_Finalize; + Namespace: Namespace_Type_Without_Finalize'Class) is + begin + if raptor_serializer_set_namespace_from_namespace(Get_Handle(Serializer), Get_Handle(Namespace)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_serializer_serialize_statement (Serializer: Serializer_Handle; + Statement: Statement_Handle) + return int + with Import, Convention=>C; + + procedure Serialize_Statement (Serializer: Serializer_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class) is + begin + if raptor_serializer_serialize_statement(Get_Handle(Serializer), Get_Handle(Statement)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_serializer_serialize_end (Serializer: Serializer_Handle) return int + with Import, Convention=>C; + + procedure Serialize_End (Serializer: Serializer_Type_Without_Finalize) is + begin + if raptor_serializer_serialize_end(Get_Handle(Serializer)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + -- FIXME: raptor_serializer_flush + function raptor_serializer_serialize_flush (Serializer: Serializer_Handle) return int + with Import, Convention=>C; + + procedure Serialize_Flush (Serializer: Serializer_Type_Without_Finalize) is + begin + if raptor_serializer_serialize_flush(Get_Handle(Serializer)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_serializer_get_description (Serializer: Serializer_Handle) + return Raptor_Syntax_Description_Type + with Import, Convention=>C; + + function Get_Description (Serializer: Serializer_Type_Without_Finalize) + return Raptor_Syntax_Description_Type is + begin + return raptor_serializer_get_description(Get_Handle(Serializer)); + end; + + function raptor_serializer_get_iostream (Serializer: Serializer_Handle) return IOStream_Handle + with Import, Convention=>C; + + function Get_IOStream (Serializer: Serializer_Type_Without_Finalize) + return IOStream_Type_Without_Finalize is + begin + return From_Handle(raptor_serializer_get_iostream(Get_Handle(Serializer))); + end; + + function raptor_serializer_get_locator (Serializer: Serializer_Handle) return Locator_Handle + with Import, Convention=>C; + + function Get_Locator (Serializer: Serializer_Type_Without_Finalize) return Locator_Type is + begin + return From_Handle(raptor_serializer_get_locator(Get_Handle(Serializer))); + end; + + function raptor_parser_set_option (Serializer: Serializer_Handle; + Option: Raptor_Option; + Value: chars_ptr; + Int_Value: int) + return int + with Import, Convention=>C; + + procedure Set_Option (Serializer: in out Serializer_Type_Without_Finalize; + Option: Raptor_Option; + Value: String) is + Value2: aliased char_array := To_C(Value); + begin + -- FIXME: raptor_parser_set_option -> raptor_serializer_set_option + if raptor_parser_set_option(Get_Handle(Serializer), Option, To_Chars_Ptr(Value2'Unchecked_Access), 0) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + procedure Set_Option (Serializer: in out Serializer_Type_Without_Finalize; + Option: Raptor_Option; + Value: int) is + begin + -- FIXME: raptor_parser_set_option -> raptor_serializer_set_option + if raptor_parser_set_option(Get_Handle(Serializer), Option, Null_Ptr, Value) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + type String_P_Type is access all chars_ptr with Convention=>C; + type Int_P_Type is access all int with Convention=>C; + + function raptor_parser_get_option (Serializer: Serializer_Handle; + Option: Raptor_Option; + String_P: String_P_Type; + Integer_P: Int_P_Type) return int + with Import, Convention=>C; + + function Get_Numeric_Option (Serializer: Serializer_Type_Without_Finalize; Option: Raptor_Option) + return Natural is + V: aliased int; + begin + -- FIXME: raptor_parser_get_option -> raptor_serializer_get_option + if raptor_parser_get_option(Get_Handle(Serializer), Option, null, V'Unchecked_Access) < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Natural(V); + end; + + function Get_String_Option (Serializer: Serializer_Type_Without_Finalize; Option: Raptor_Option) + return String is + V: aliased chars_ptr; + begin + -- FIXME: raptor_parser_get_option -> raptor_serializer_get_option + if raptor_parser_get_option(Get_Handle(Serializer), Option, V'Unchecked_Access, null) < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Value(V); -- do NOT free it + end; + + function raptor_serializer_get_world (Serializer: Serializer_Handle) return Raptor_World_Handle + with Import, Convention=>C; + + function Get_World (Serializer: Serializer_Type_Without_Finalize) + return Raptor_World_Type_Without_Finalize is + begin + return From_Handle(raptor_serializer_get_world(Get_Handle(Serializer))); + end; + + function raptor_new_serializer (World: Raptor_World_Handle; Syntax_Name: chars_ptr) + return Serializer_Handle + with Import, Convention=>C; + + function Create (World: Raptor_World_Type_Without_Finalize'Class) return Serializer_Type is + begin + return From_Non_Null_Handle(raptor_new_serializer(Get_Handle(World), Null_Ptr)); + end; + + function Create (World: Raptor_World_Type_Without_Finalize'Class; Syntax_Name: String) + return Serializer_Type is + V: aliased char_array := To_C(Syntax_Name); + begin + return From_Non_Null_Handle(raptor_new_serializer(Get_Handle(World), To_Chars_Ptr(V'Unchecked_Access))); + end; + + procedure raptor_free_serializer (Serializer: Serializer_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Serializer: Serializer_Type_Without_Finalize; Handle: Serializer_Handle) is + begin + raptor_free_serializer(Handle); + end; + +end RDF.Raptor.Serializer; diff --git a/ada/src/rdf-raptor-serializer.ads b/ada/src/rdf-raptor-serializer.ads new file mode 100644 index 000000000..3ba728cb0 --- /dev/null +++ b/ada/src/rdf-raptor-serializer.ads @@ -0,0 +1,93 @@ +with Interfaces.C; use Interfaces.C; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.Namespace; use RDF.Raptor.Namespace; +with RDF.Raptor.Statement; use RDF.Raptor.Statement; +with RDF.Raptor.Syntaxes; use RDF.Raptor.Syntaxes; +with RDF.Raptor.Log; use RDF.Raptor.Log; +with RDF.Raptor.Options; use RDF.Raptor.Options; + +package RDF.Raptor.Serializer is + + package Serializer_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + subtype Serializer_Handle is Serializer_Handled_Record.Access_Type; + + type Serializer_Type_Without_Finalize is new Serializer_Handled_Record.Base_Object with null record; + + overriding procedure Finalize_Handle (Serializer: Serializer_Type_Without_Finalize; Handle: Serializer_Handle); + + -- WARNING: Other order of arguments than in C + not overriding procedure Start_To_IOStream (Serializer: Serializer_Type_Without_Finalize; + IOStream: IOStream_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + not overriding procedure Start_To_Filename (Serializer: Serializer_Type_Without_Finalize; Filename: String); + + -- raptor_serializer_start_to_string() is deliberately not used. + -- Use Stream_To_String instead. + + not overriding procedure Start_To_Filehandle (Serializer: Serializer_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + FH: RDF.Auxiliary.C_File_Access); + + -- WARNING: Other order of arguments than in C + not overriding procedure Set_Namespace (Serializer: in out Serializer_Type_Without_Finalize; + Prefix: String; + URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + not overriding procedure Set_Namespace_Without_Prefix (Serializer: in out Serializer_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + not overriding procedure Set_Namespace (Serializer: in out Serializer_Type_Without_Finalize; + Namespace: Namespace_Type_Without_Finalize'Class); + + not overriding procedure Serialize_Statement (Serializer: Serializer_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class); + + not overriding procedure Serialize_End (Serializer: Serializer_Type_Without_Finalize); + + not overriding procedure Serialize_Flush (Serializer: Serializer_Type_Without_Finalize); + + not overriding function Get_Description (Serializer: Serializer_Type_Without_Finalize) + return Raptor_Syntax_Description_Type; + + not overriding function Get_IOStream (Serializer: Serializer_Type_Without_Finalize) + return IOStream_Type_Without_Finalize; + + not overriding function Get_Locator (Serializer: Serializer_Type_Without_Finalize) + return Locator_Type; + + not overriding procedure Set_Option (Serializer: in out Serializer_Type_Without_Finalize; + Option: Raptor_Option; + Value: String); + not overriding procedure Set_Option (Serializer: in out Serializer_Type_Without_Finalize; + Option: Raptor_Option; + Value: int); + + -- Not sure if we should be able to query here whether the option is numeric + not overriding function Get_Numeric_Option (Serializer: Serializer_Type_Without_Finalize; + Option: Raptor_Option) + return Natural; + not overriding function Get_String_Option (Serializer: Serializer_Type_Without_Finalize; + Option: Raptor_Option) + return String; + + not overriding function Get_World (Serializer: Serializer_Type_Without_Finalize) + return Raptor_World_Type_Without_Finalize; + + package Handlers is new Serializer_Handled_Record.Common_Handlers(Serializer_Type_Without_Finalize); + + type Serializer_Type is new Handlers.Base_With_Finalization with null record; + + type Serializer_Type_User is new Handlers.User_Type with null record; + + not overriding function Create (World: Raptor_World_Type_Without_Finalize'Class) + return Serializer_Type; + not overriding function Create (World: Raptor_World_Type_Without_Finalize'Class; + Syntax_Name: String) + return Serializer_Type; + +end RDF.Raptor.Serializer; diff --git a/ada/src/rdf-raptor-statement.adb b/ada/src/rdf-raptor-statement.adb new file mode 100644 index 000000000..376a57d5e --- /dev/null +++ b/ada/src/rdf-raptor-statement.adb @@ -0,0 +1,124 @@ +with Interfaces.C; use Interfaces.C; + +package body RDF.Raptor.Statement is + + function Get_World (Statement: Statement_Type_Without_Finalize) return Raptor_World_Type_Without_Finalize is + begin + return From_Non_Null_Handle(Get_Handle(Statement).World); + end; + + function Get_Subject (Statement: Statement_Type_Without_Finalize) return Term_Type_Without_Finalize is + (From_Handle(Get_Handle(Statement).Subject)); + function Get_Predicate (Statement: Statement_Type_Without_Finalize) return Term_Type_Without_Finalize is + (From_Handle(Get_Handle(Statement).Predicate)); + function Get_Object (Statement: Statement_Type_Without_Finalize) return Term_Type_Without_Finalize is + (From_Handle(Get_Handle(Statement).Object)); + function Get_Graph (Statement: Statement_Type_Without_Finalize) return Term_Type_Without_Finalize is + (From_Handle(Get_Handle(Statement).Graph)); -- may return null handle + + -- function No_Auto_Finalization (Term: Term_Type_Without_Finalize'Class) return Boolean is + -- begin + -- return Is_Null(Term) or not (Term in Term_Type'Class); + -- end; + + function raptor_new_statement (World: Raptor_World_Handle) return Statement_Handle + with Import, Convention=>C; + + function Create (World: Raptor_World_Type_Without_Finalize'Class) return Statement_Type is + begin + return From_Non_Null_Handle( raptor_new_statement(Get_Handle(World)) ); + end; + + function raptor_new_statement_from_nodes (World: Raptor_World_Handle; + Subject, Predicate, Object, Graph: Term_Handle) + return Statement_Handle + with Import, Convention=>C; + + function raptor_term_copy (Term: Term_Handle) return Term_Handle + with Import, Convention=>C; + + function Create (World: Raptor_World_Type_Without_Finalize'Class; + Subject, Predicate, Object: Term_Type_Without_Finalize'Class; + Graph: Term_Type_Without_Finalize'Class := Term_Type_Without_Finalize'(From_Handle(null))) + return Statement_Type is + Handle: constant Statement_Handle := + raptor_new_statement_from_nodes(Get_Handle(World), + raptor_term_copy(Get_Handle(Subject)), + raptor_term_copy(Get_Handle(Predicate)), + raptor_term_copy(Get_Handle(Object)), + raptor_term_copy(Get_Handle(Graph))); + begin + return From_Non_Null_Handle(Handle); + end; + + procedure raptor_free_statement (Statement: Statement_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Statement_Type_Without_Finalize; Handle: Statement_Handle) is + begin + raptor_free_statement(Handle); + end; + + function raptor_statement_copy (Term: Statement_Handle) return Statement_Handle + with Import, Convention=>C; + + function Adjust_Handle (Object: Statement_Type_Without_Finalize; Handle: Statement_Handle) return Statement_Handle is + begin + return raptor_statement_copy(Handle); + end; + + function raptor_statement_compare (Left, Right: Statement_Handle) return int + with Import, Convention=>C; + + function Compare (Left, Right: Statement_Type_Without_Finalize) return RDF.Auxiliary.Comparison_Result is + begin + return RDF.Auxiliary.Sign( raptor_statement_compare(Get_Handle(Left), Get_Handle(Right)) ); + end; + + function raptor_statement_equals (Left, Right: Statement_Handle) return int + with Import, Convention=>C; + + function Equals (Left, Right: Statement_Type_Without_Finalize) return Boolean is + begin + return raptor_statement_equals(Get_Handle(Left), Get_Handle(Right)) /= 0; + end; + + function raptor_statement_print (Statement: Statement_Handle; File: RDF.Auxiliary.C_File_Access) + return int + with Import, Convention=>C; + + procedure Print (Statement: Statement_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access) is + begin + if raptor_statement_print(Get_Handle(Statement), File) /= 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_statement_print_as_ntriples (Statement: Statement_Handle; File: RDF.Auxiliary.C_File_Access) + return int + with Import, Convention=>C; + + procedure Print_As_Ntriples (Statement: Statement_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access) is + begin + if raptor_statement_print_as_ntriples(Get_Handle(Statement), File) /= 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_statement_ntriples_write (Statement: Statement_Handle; + Stream: IOStream_Handle; + Write_Graph_Term: int) + return Int + with Import, Convention=>C; + + procedure Ntriples_Write (Statement: Statement_Type_Without_Finalize; + Stream: IOStream_Type_Without_Finalize'Class; + Write_Graph_Term: Boolean) is + Flag: constant int := (if Write_Graph_Term then 1 else 0); + begin + if raptor_statement_ntriples_write(Get_Handle(Statement), Get_Handle(Stream), Flag) /= 0 then + raise IOStream_Exception; + end if; + end; + +end RDF.Raptor.Statement; diff --git a/ada/src/rdf-raptor-statement.ads b/ada/src/rdf-raptor-statement.ads new file mode 100644 index 000000000..612ca0c4d --- /dev/null +++ b/ada/src/rdf-raptor-statement.ads @@ -0,0 +1,80 @@ +with Interfaces.C; +with RDF.Auxiliary.Handled_Record; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Raptor.Term; use RDF.Raptor.Term; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; + +package RDF.Raptor.Statement is + + type Statement_Record is private; + + type Statement_Record_Access is access Statement_Record with Convention=>C; + + package Statement_Handled_Record is new RDF.Auxiliary.Handled_Record(Statement_Record, Statement_Record_Access); + + type Statement_Type_Without_Finalize is new Statement_Handled_Record.Base_Object with null record; + + subtype Statement_Handle is Statement_Handled_Record.Access_Type; + + overriding function Adjust_Handle (Object: Statement_Type_Without_Finalize; Handle: Statement_Handle) return Statement_Handle; + + overriding procedure Finalize_Handle (Object: Statement_Type_Without_Finalize; Handle: Statement_Handle); + + not overriding function Get_World (Statement: Statement_Type_Without_Finalize) return Raptor_World_Type_Without_Finalize; + + not overriding function Get_Subject (Statement: Statement_Type_Without_Finalize) return Term_Type_Without_Finalize; + not overriding function Get_Predicate (Statement: Statement_Type_Without_Finalize) return Term_Type_Without_Finalize; + not overriding function Get_Object (Statement: Statement_Type_Without_Finalize) return Term_Type_Without_Finalize; + not overriding function Get_Graph (Statement: Statement_Type_Without_Finalize) return Term_Type_Without_Finalize; -- may return null handle + + not overriding function Compare (Left, Right: Statement_Type_Without_Finalize) return RDF.Auxiliary.Comparison_Result; + + not overriding function Equals (Left, Right: Statement_Type_Without_Finalize) return Boolean; + + overriding function "=" (Left, Right: Statement_Type_Without_Finalize) return Boolean renames Equals; + + not overriding procedure Print (Statement: Statement_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access); + + not overriding procedure Print_As_Ntriples (Statement: Statement_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access); + + -- raptor_statement_init(), raptor_statement_clear() are not boound, because they are probably internal + + not overriding procedure Ntriples_Write (Statement: Statement_Type_Without_Finalize; + Stream: IOStream_Type_Without_Finalize'Class; + Write_Graph_Term: Boolean); + + package Handlers is new Statement_Handled_Record.Common_Handlers(Statement_Type_Without_Finalize); + + type Statement_Type is new Handlers.Base_With_Finalization with null record; + + type Statement_Type_User is new Handlers.User_Type with null record; + + -- Returns False for certain types which automatically finalize handles and so are not appropriate for objects owned by a statement + -- function No_Auto_Finalization (Term: Term_Type_Without_Finalize'Class) return Boolean; + + not overriding function Create (World: Raptor_World_Type_Without_Finalize'Class) + return Statement_Type; + + -- Makes copies of the terms (unlike the C library) + not overriding function Create (World: Raptor_World_Type_Without_Finalize'Class; + Subject, Predicate, Object: Term_Type_Without_Finalize'Class; + Graph: Term_Type_Without_Finalize'Class := Term_Type_Without_Finalize'(From_Handle(null))) + return Statement_Type; + + -- not overriding function Create (World: Raptor_World_Type_Without_Finalize'Class; + -- Subject, Predicate, Object, Graph: Term_Type_Without_Finalize'Class) + -- return Statement_Type + -- with Pre => No_Auto_Finalization(Subject) and No_Auto_Finalization(Predicate) and No_Auto_Finalization(Object) and No_Auto_Finalization(Graph); + +private + + type Statement_Record is + record + World: Raptor_World_Handle; + usage: Interfaces.C.int; + Subject, Predicate, Object, Graph: Term_Handle; + end record + with Convention=>C; + +end RDF.Raptor.Statement; diff --git a/ada/src/rdf-raptor-syntaxes.adb b/ada/src/rdf-raptor-syntaxes.adb new file mode 100644 index 000000000..0c9eeee80 --- /dev/null +++ b/ada/src/rdf-raptor-syntaxes.adb @@ -0,0 +1,178 @@ +with Interfaces.C.Pointers; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; + +package body RDF.Raptor.Syntaxes is + + package String_Ptrs is new Interfaces.C.Pointers(size_t, chars_ptr, chars_ptr_array, Null_Ptr); + + use String_Ptrs; + + Mime_Type_Q_Default: constant Mime_Type_Q := Mime_Type_Q'(Mime_Type=>Null_Ptr, Mime_Type_Len=>0, Q=>0); -- hack + type Mime_Type_Q_Array is array (size_t range <>) of aliased Mime_Type_Q; + package Mime_Type_Q_Ptrs is new Interfaces.C.Pointers(size_t, Mime_Type_Q, Mime_Type_Q_Array, Mime_Type_Q_Default); + + use Mime_Type_Q_Ptrs; + + function Get_MIME_Type (Object: Mime_Type_Q) return String is + begin + return Value(Object.Mime_Type, Object.Mime_Type_Len); + end; + + function Get_Q (Object: Mime_Type_Q) return Q_Type is (Q_Type(Object.Q)); + + function Get_Name (Object: Raptor_Syntax_Description_Type; Index: Natural) return String is + Ptr: constant access chars_ptr := String_Ptrs.Pointer(Object.Names) + ptrdiff_t(Index); + begin + return Value(Ptr.all); + end; + + function Get_Names_Count (Object: Raptor_Syntax_Description_Type) return Natural is + (Natural(Object.Names_Count)); + + function Get_Label (Object: Raptor_Syntax_Description_Type) return String is + begin + return Value(Object.Label); + end; + + -- TODO: precondition + function Get_MIME_Type (Object: Raptor_Syntax_Description_Type; Index: Natural) return Mime_Type_Q is + Ptr: constant access Mime_Type_Q := Mime_Type_Q_Ptrs.Pointer(Object.Mime_Types) + ptrdiff_t(Index); + begin + return Ptr.all; + end; + + function Get_MIME_Types_Count (Object: Raptor_Syntax_Description_Type) return Natural is + (Natural(Object.Mime_Types_Count)); + + function Get_URI (Object: Raptor_Syntax_Description_Type; Index: Natural) return URI_String is + Ptr: constant access chars_ptr := String_Ptrs.Pointer(Object.URI_Strings) + ptrdiff_t(Index); + begin + return URI_String(String'(Value(Ptr.all))); + end; + + function Get_URIs_Count (Object: Raptor_Syntax_Description_Type) return Natural is + (Natural(Object.URI_Strings_Count)); + + function Get_Flags (Object: Raptor_Syntax_Description_Type) return Syntax_Bitflags is + begin + return Object.Flags; + end; + + function raptor_world_is_parser_name(World: Raptor_World_Handle; Name: char_array) return int + with Import, Convention=>C; + + function Is_Parser_Name (World: Raptor_World_Type_Without_Finalize'Class; Name: String) + return Boolean is + begin + return raptor_world_is_parser_name(Get_Handle(World), To_C(Name, Append_Nul=>True)) /= 0; + end; + + function raptor_world_guess_parser_name (World: Raptor_World_Handle; + URI: URI_Handle; + MIME_Type: Char_Array; + Buffer: Char_Array; + Len: Size_T; + Identifier: Char_Array) return chars_ptr + with Import, Convention=>C; + + + function Guess_Parser_Name (World: Raptor_World_Type_Without_Finalize'Class; + URI: URI_Type; + MIME_Type: String; + Buffer: String; + Identifier: String) + return String is + Str: constant chars_ptr := raptor_world_guess_parser_name(Get_Handle(World), + Get_Handle(URI), + To_C(MIME_Type, Append_Nul=>True), + My_To_C_Without_Nul(Buffer), + size_t(Buffer'Length), + To_C(Identifier, Append_Nul=>True)); + begin + return Value(Str); + end; + + function raptor_world_is_serializer_name(World: Raptor_World_Handle; Name: char_array) return int + with Import, Convention=>C; + + function Is_Serializer_Name (World: Raptor_World_Type_Without_Finalize'Class; Name: String) + return Boolean is + begin + return raptor_world_is_serializer_name(Get_Handle(World), To_C(Name, Append_Nul=>True)) /= 0; + end; + + function Get_Position (Cursor: Parser_Description_Cursor ) return Natural is (Cursor.Position); + function Get_Position (Cursor: Serializer_Description_Cursor) return Natural is (Cursor.Position); + + type Syntax_Description_Access is access all Raptor_Syntax_Description_Type + with Convention=>C; + + function raptor_world_get_parser_description (World: Raptor_World_Handle; Counter: unsigned) + return Syntax_Description_Access + with Import, Convention=>C; + + function raptor_world_get_serializer_description (World: Raptor_World_Handle; Counter: unsigned) + return Syntax_Description_Access + with Import, Convention=>C; + + function Get_Description (Cursor: Parser_Description_Cursor) + return Raptor_Syntax_Description_Type is + begin + return raptor_world_get_parser_description(Cursor.World, unsigned(Cursor.Position)).all; + end; + + function Get_Description (Cursor: Serializer_Description_Cursor) + return Raptor_Syntax_Description_Type is + begin + return raptor_world_get_serializer_description(Cursor.World, unsigned(Cursor.Position)).all; + end; + + function Has_Element (Position: Parser_Description_Cursor) return Boolean is + begin + return raptor_world_get_parser_description(Position.World, unsigned(Position.Position)) /= null; + end; + + function Has_Element (Position: Serializer_Description_Cursor) return Boolean is + begin + return raptor_world_get_serializer_description(Position.World, unsigned(Position.Position)) /= null; + end; + + function First (Object: Parser_Description_Iterator) return Parser_Description_Cursor is + begin + return (Position=>0, World=>Object.World); + end; + + function Next (Object: Parser_Description_Iterator; Position: Parser_Description_Cursor) + return Parser_Description_Cursor is + begin + return (Position=>Position.Position+1, World=>Position.World); + end; + + function First (Object: Serializer_Description_Iterator) return Serializer_Description_Cursor is + begin + return (Position=>0, World=>Object.World); + end; + + function Next (Object: Serializer_Description_Iterator; Position: Serializer_Description_Cursor) + return Serializer_Description_Cursor is + begin + return (Position=>Position.Position+1, World=>Position.World); + end; + + function Create_Parser_Descriptions_Iterator(World: Raptor_World_Type_Without_Finalize'Class) + return Parser_Description_Iterator is + begin + return (World=>Get_Handle(World)); + end; + + function Create_Serializer_Descriptions_Iterator (World: Raptor_World_Type_Without_Finalize'Class) + return Serializer_Description_Iterator is + begin + return (World=>Get_Handle(World)); + end; + + -- function Parser_Descriptions (World: Raptor_World_Type_Without_Finalize'Class) return Parser_Description_List is (World=>Get_Handle(World)); + -- + -- function Serializer_Descriptions (World: Raptor_World_Type_Without_Finalize'Class) return Serializer_Description_List is (World=>Get_Handle(World)); + +end RDF.Raptor.Syntaxes; diff --git a/ada/src/rdf-raptor-syntaxes.ads b/ada/src/rdf-raptor-syntaxes.ads new file mode 100644 index 000000000..85f2616dd --- /dev/null +++ b/ada/src/rdf-raptor-syntaxes.ads @@ -0,0 +1,148 @@ +with Ada.Iterator_Interfaces; +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Raptor.URI; use RDF.Raptor.URI; + +package RDF.Raptor.Syntaxes is + + type Syntax_Bitflags is (Need_Base_URI) with Convention=>C; + for Syntax_Bitflags use (Need_Base_URI => 1); + + type Mime_Type_Q is private; + + type Syntax_Description_Record is limited private; -- internal + + -- Internally represented as an access to a C record. (It is used for Ada.Unchecked_Conversion in some other packages.) + type Raptor_Syntax_Description_Type is access constant Syntax_Description_Record + with Convention => C; + + type Q_Type is range 0..10; + + function Get_MIME_Type (Object: Mime_Type_Q) return String; + + function Get_Q (Object: Mime_Type_Q) return Q_Type; + + function Get_Name (Object: Raptor_Syntax_Description_Type; Index: Natural) return String + with Pre => Index < Get_Names_Count(Object); + + function Get_Names_Count (Object: Raptor_Syntax_Description_Type) return Natural; + + function Get_Label (Object: Raptor_Syntax_Description_Type) return String; + + function Get_MIME_Type (Object: Raptor_Syntax_Description_Type; Index: Natural) return Mime_Type_Q + with Pre => Index < Get_MIME_Types_Count(Object); + + function Get_MIME_Types_Count (Object: Raptor_Syntax_Description_Type) return Natural; + + function Get_URI (Object: Raptor_Syntax_Description_Type; Index: Natural) return URI_String + with Pre => Index < Get_URIs_Count(Object); + + function Get_URIs_Count (Object: Raptor_Syntax_Description_Type) return Natural; + + function Get_Flags (Object: Raptor_Syntax_Description_Type) return Syntax_Bitflags; + + -- raptor_syntax_description_validate() deliberately not implemented + + type Parser_Description_Cursor is private; + type Serializer_Description_Cursor is private; + + function Get_Position (Cursor: Parser_Description_Cursor ) return Natural; + function Get_Position (Cursor: Serializer_Description_Cursor) return Natural; + + function Get_Description (Cursor: Parser_Description_Cursor ) return Raptor_Syntax_Description_Type; + function Get_Description (Cursor: Serializer_Description_Cursor) return Raptor_Syntax_Description_Type; + + function Has_Element (Position: Parser_Description_Cursor ) return Boolean; + function Has_Element (Position: Serializer_Description_Cursor) return Boolean; + + package Parser_Description_Iterators is new Ada.Iterator_Interfaces(Parser_Description_Cursor , Has_Element); + package Serializer_Description_Iterators is new Ada.Iterator_Interfaces(Serializer_Description_Cursor, Has_Element); + + type Parser_Description_Iterator is new Parser_Description_Iterators .Forward_Iterator with private; + type Serializer_Description_Iterator is new Serializer_Description_Iterators.Forward_Iterator with private; + + overriding function First (Object: Parser_Description_Iterator) return Parser_Description_Cursor; + overriding function Next (Object: Parser_Description_Iterator; Position: Parser_Description_Cursor) + return Parser_Description_Cursor; + + overriding function First (Object: Serializer_Description_Iterator) return Serializer_Description_Cursor; + overriding function Next (Object: Serializer_Description_Iterator; Position: Serializer_Description_Cursor) + return Serializer_Description_Cursor; + + not overriding function Create_Parser_Descriptions_Iterator (World: Raptor_World_Type_Without_Finalize'Class) + return Parser_Description_Iterator; + not overriding function Create_Serializer_Descriptions_Iterator (World: Raptor_World_Type_Without_Finalize'Class) + return Serializer_Description_Iterator; + + function Is_Parser_Name (World: Raptor_World_Type_Without_Finalize'Class; Name: String) return Boolean; + + function Guess_Parser_Name (World: Raptor_World_Type_Without_Finalize'Class; + URI: URI_Type; -- FIXME: WithoutFinalize + MIME_Type: String; + Buffer: String; + Identifier: String) + return String; + + function Is_Serializer_Name (World: Raptor_World_Type_Without_Finalize'Class; Name: String) + return Boolean; + +private + + type Mime_Type_Q is + record + Mime_Type: chars_ptr; + Mime_Type_Len: size_t; + Q: unsigned_char; + end record + with Convention => C; + + type Syntax_Description_Record is limited + record + Names: access chars_ptr; + Names_Count: unsigned; + Label: chars_ptr; + Mime_Types: access Mime_Type_Q; + Mime_Types_Count: unsigned; + URI_Strings: access chars_ptr; + URI_Strings_Count: unsigned; + Flags: Syntax_Bitflags; + end record + with Convention => C; + +-- type Raptor_Syntax_Description_Type is access constant Syntax_Description_Record +-- with Convention => C; + + type Parser_Description_Cursor is + record + World: Raptor_World_Handle; + Position: Natural; + end record; + + type Serializer_Description_Cursor is + record + World: Raptor_World_Handle; + Position: Natural; + end record; + + type Parser_Description_Iterator is new Parser_Description_Iterators.Forward_Iterator with + record + World: Raptor_World_Handle; + end record; + + type Serializer_Description_Iterator is new Serializer_Description_Iterators.Forward_Iterator with + record + World: Raptor_World_Handle; + end record; + +-- type Parser_Descriptions_List is tagged +-- record +-- World: Raptor_World_Handle; +-- end record; +-- +-- type Serializer_Descriptions_List is tagged +-- record +-- World: Raptor_World_Handle; +-- end record; + +end RDF.Raptor.Syntaxes; diff --git a/ada/src/rdf-raptor-term.adb b/ada/src/rdf-raptor-term.adb new file mode 100644 index 000000000..b431402af --- /dev/null +++ b/ada/src/rdf-raptor-term.adb @@ -0,0 +1,249 @@ +with RDF.Auxiliary.C_String_Holders; +with RDF.Raptor.Namespace_Stack; use RDF.Raptor.Namespace_Stack; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; +with RDF.Raptor.Memory; + +package body RDF.Raptor.Term is + + function Get_World (Term: Term_Type_Without_Finalize) return Raptor_World_Type_Without_Finalize is + begin + return From_Handle( Get_Handle(Term).World ); + end; + + function Get_Kind (Term: Term_Type_Without_Finalize) return Term_Kind is + begin + return Get_Handle(Term).Kind; + end; + + function Get_URI (Term: URI_Term_Type_Without_Finalize'Class) return URI_Type_Without_Finalize is + begin + return From_Handle( Get_Handle(Term).Value.URI ); + end; + + function Get_Literal (Term: Literal_Term_Type_Without_Finalize'Class) return Term_Literal_Value is + begin + return Get_Handle(Term).Value.Literal; + end; + + function Get_Blank (Term: Blank_Term_Type_Without_Finalize'Class) return Term_Blank_Value is + begin + return Get_Handle(Term).Value.Blank; + end; + + function Value (Literal: Term_Literal_Value) return String is + begin + return Value(Literal.Str, Size_T(Literal.Len)); + end; + + function Datatype (Literal: Term_Literal_Value) return URI_Type_Without_Finalize is + use type URI_Handle; + begin + -- TODO: Simplify + if Literal.Datatype = null then + return From_Handle(null); + end if; + return From_Handle(Literal.Datatype); + end; + + function Language (Literal: Term_Literal_Value) return String is + begin + if Literal.Language = Null_Ptr then + return ""; + end if; + return Value(Literal.Language, size_t(Literal.Language_Len)); + end; + + function Value (Blank: Term_Blank_Value) return String is + begin + return Value(Blank.Str, size_t(Blank.Len)); + end; + + function raptor_new_term_from_counted_blank (World: Raptor_World_Handle; + Blank: chars_ptr; + Length: size_t) + return Term_Handle + with Import, Convention=>C; + + function From_Blank (World: Raptor_World_Type_Without_Finalize'Class) return Term_Type is + begin + return From_Non_Null_Handle(raptor_new_term_from_counted_blank(Get_Handle(World), Null_Ptr, 0)); + end; + + function From_Blank (World: Raptor_World_Type_Without_Finalize'Class; ID: String) return Term_Type is + Str: aliased char_array := To_C(ID); + Handle: constant Term_Handle := + raptor_new_term_from_counted_blank(Get_Handle(World), + To_Chars_Ptr(Str'Unchecked_Access), + ID'Length); + begin + return From_Non_Null_Handle(Handle); + end; + + function From_Blank (World: Raptor_World_Type_Without_Finalize'Class; + ID: RDF.Auxiliary.String_Holders.Holder) + return Term_Type is + use RDF.Auxiliary.C_String_Holders; + ID_N: constant C_String_Holder := To_C_String_Holder(ID); + begin + return From_Non_Null_Handle(raptor_new_term_from_counted_blank(Get_Handle(World), C_String(ID_N), Length(ID_N))); + end; + + function raptor_new_term_from_counted_literal (World: Raptor_World_Handle; + Literal: chars_ptr; + Literal_Len: size_t; + Datatype: URI_Handle; + Language: chars_ptr; + Language_Len: size_t) + return Term_Handle + with Import, Convention=>C; + + function From_Literal (World : Raptor_World_Type_Without_Finalize'Class; + Literal : RDF.Auxiliary.String_Holders.Holder; + Datatype: URI_Type_Without_Finalize'Class; + Language: RDF.Auxiliary.String_Holders.Holder) + return Term_Type + is + use RDF.Auxiliary.C_String_Holders; + Literal_N : constant C_String_Holder := To_C_String_Holder(Literal ); + Language_N: constant C_String_Holder := To_C_String_Holder(Language); + begin + return From_Non_Null_Handle( raptor_new_term_from_counted_literal(Get_Handle(World), + C_String(Literal_N), + Length(Literal_N), + Get_Handle(Datatype), + C_String(Language_N), + Length(Language_N)) ); + end; + + function raptor_new_term_from_counted_uri_string (World: Raptor_World_Handle; + Str: char_array; + Str_Len: size_t) + return Term_Handle + with Import, Convention=>C; + + function From_URI_String (World: Raptor_World_Type_Without_Finalize'Class; URI: URI_String) + return Term_Type is + Handle: constant Term_Handle := + raptor_new_term_from_counted_uri_string(Get_Handle(World), My_To_C_Without_Nul(String(URI)), URI'Length); + begin + return From_Non_Null_Handle(Handle); + end; + + function raptor_new_term_from_uri (World: Raptor_World_Handle; URI: URI_Handle) return Term_Handle + with Import, Convention=>C; + + function From_URI (World: Raptor_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class) + return Term_Type is + begin + return From_Non_Null_Handle( raptor_new_term_from_uri(Get_Handle(World), Get_Handle(URI)) ); + end; + + function raptor_new_term_from_counted_string (World: Raptor_World_Handle; Str: char_array; Len: size_t) + return Term_Handle + with Import, Convention=>C; + + function From_String (World: Raptor_World_Type_Without_Finalize'Class; Value: String) + return Term_Type is + Handle: constant Term_Handle := + raptor_new_term_from_counted_string(Get_Handle(World), My_To_C_Without_Nul(Value), Value'Length); + begin + return From_Non_Null_Handle(Handle); + end; + + function raptor_term_copy (Term: Term_Handle) return Term_Handle + with Import, Convention=>C; + + function Adjust_Handle (Object: Term_Type_Without_Finalize; Handle: Term_Handle) return Term_Handle is + begin + return raptor_term_copy(Handle); + end; + + function raptor_term_compare (Left, Right: Term_Handle) return int + with Import, Convention=>C; + + function Compare (Left, Right: Term_Type_Without_Finalize) return RDF.Auxiliary.Comparison_Result is + begin + return RDF.Auxiliary.Sign( raptor_term_compare(Get_Handle(Left), Get_Handle(Right)) ); + end; + + function raptor_term_equals (Left, Right: Term_Handle) return int + with Import, Convention=>C; + + function Equals (Left, Right: Term_Type_Without_Finalize) return Boolean is + begin + return raptor_term_equals(Get_Handle(Left), Get_Handle(Right)) /= 0; + end; + + procedure raptor_free_term (Term: Term_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Term_Type_Without_Finalize; Handle: Term_Handle) is + begin + raptor_free_term(Handle); + end; + + function raptor_term_to_string (Term: Term_Handle) return chars_ptr + with Import, Convention=>C; + + function To_String (Term: Term_Type_Without_Finalize) return String is + Str: constant chars_ptr := raptor_term_to_string(Get_Handle(Term)); + begin + if Str = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Result: constant String := Value(Str); + begin + RDF.Raptor.Memory.Raptor_Free_Memory(Str); + return Result; + end; + end; + + function raptor_term_to_turtle_string (Term: Term_Handle; + Stack: Namespace_Stack_Handle; + Base_URI: URI_Handle) + return chars_ptr + with Import, Convention=>C; + + function To_Turtle_String(Term: Term_Type_Without_Finalize; + Stack: Namespace_Stack_Type'Class; + Base_URI: URI_Type'Class) + return String is + Str: constant chars_ptr := raptor_term_to_turtle_string(Get_Handle(Term), + Get_Handle(Stack), + Get_Handle(Base_URI)); + begin + if Str = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Result: constant String := Value(Str); + begin + RDF.Raptor.Memory.Raptor_Free_Memory(Str); + return Result; + end; + end; + + function raptor_term_turtle_write (Stream: IOStream_Handle; + Term: Term_Handle; + Stack: Namespace_Stack_Handle; + Base_URI: URI_Handle) + return Int + with Import, Convention=>C; + + procedure Turtle_Write (Stream: IOStream_Type_Without_Finalize'Class; + Term: Term_Type_Without_Finalize; + Stack: Namespace_Stack_Type'Class; + Base_URI: URI_Type'Class) is + begin + if raptor_term_turtle_write(Get_Handle(Stream), Get_Handle(Term), Get_Handle(Stack), Get_Handle(Base_URI)) /= 0 then + raise IOStream_Exception; + end if; + end; + + function Is_URI (Term: Term_Type_Without_Finalize) return Boolean is (Get_Kind(Term) = URI); + function Is_Literal (Term: Term_Type_Without_Finalize) return Boolean is (Get_Kind(Term) = Literal); + function Is_Blank (Term: Term_Type_Without_Finalize) return Boolean is (Get_Kind(Term) = Blank); + +end RDF.Raptor.Term; diff --git a/ada/src/rdf-raptor-term.ads b/ada/src/rdf-raptor-term.ads new file mode 100644 index 000000000..059de161f --- /dev/null +++ b/ada/src/rdf-raptor-term.ads @@ -0,0 +1,182 @@ +with RDF.Auxiliary.Handled_Record; +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.Namespace_Stack; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; + +package RDF.Raptor.Term is + + type Term_Record is private; + + type Term_Record_Access is access all Term_Record with Convention=>C; + + package Term_Handled_Record is new RDF.Auxiliary.Handled_Record(Term_Record, Term_Record_Access); + + type Term_Type_Without_Finalize is new Term_Handled_Record.Base_Object with null record; + + subtype URI_Term_Type_Without_Finalize is Term_Type_Without_Finalize + with Dynamic_Predicate => Is_URI(URI_Term_Type_Without_Finalize); + subtype Literal_Term_Type_Without_Finalize is Term_Type_Without_Finalize + with Dynamic_Predicate => Is_Literal(Literal_Term_Type_Without_Finalize); + subtype Blank_Term_Type_Without_Finalize is Term_Type_Without_Finalize + with Dynamic_Predicate => Is_Blank(Blank_Term_Type_Without_Finalize); + + subtype Term_Handle is Term_Handled_Record.Access_Type; + + overriding function Adjust_Handle (Object: Term_Type_Without_Finalize; Handle: Term_Handle) return Term_Handle; + + overriding procedure Finalize_Handle (Object: Term_Type_Without_Finalize; Handle: Term_Handle); + + type Term_Kind is (Unknown, + URI, + Literal, + Blank) + with Convention => C; + for Term_Kind use (Unknown => 0, + URI => 1, + Literal => 2, + -- unused type 3 + Blank => 4); + + not overriding function Get_World (Term: Term_Type_Without_Finalize) + return Raptor_World_Type_Without_Finalize; + + not overriding function Get_Kind (Term: Term_Type_Without_Finalize) return Term_Kind; + + not overriding function Is_URI (Term: Term_Type_Without_Finalize) return Boolean; + not overriding function Is_Literal (Term: Term_Type_Without_Finalize) return Boolean; + not overriding function Is_Blank (Term: Term_Type_Without_Finalize) return Boolean; + + function Get_URI (Term: URI_Term_Type_Without_Finalize'Class) return URI_Type_Without_Finalize; + + -- Should be private - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82639 + type Term_Literal_Value is + record + str: chars_ptr; + Len: unsigned; + Datatype: URI_Handle; + Language: chars_ptr; + Language_Len: unsigned; + end record + with Convention => C; + + -- Should be private - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82639 + type Term_Blank_Value is + record + str: chars_ptr; + Len: unsigned; + end record + with Convention => C; + + function Get_Literal (Term: Literal_Term_Type_Without_Finalize'Class) return Term_Literal_Value; + + function Get_Blank (Term: Blank_Term_Type_Without_Finalize'Class) return Term_Blank_Value; + + not overriding function Value (Literal: Term_Literal_Value) return String; + + -- The returned URI may be null. + not overriding function Datatype (Literal: Term_Literal_Value) return URI_Type_Without_Finalize; + + -- Return the language tag or empty string if there are none + not overriding function Language (Literal: Term_Literal_Value) return String; + + not overriding function Value (Blank: Term_Blank_Value) return String; + + not overriding function To_String (Term: Term_Type_Without_Finalize) return String; + + not overriding function Compare (Left, Right: Term_Type_Without_Finalize) + return RDF.Auxiliary.Comparison_Result; + + not overriding function Equals (Left, Right: Term_Type_Without_Finalize) return Boolean; + + overriding function "=" (Left, Right: Term_Type_Without_Finalize) return Boolean renames Equals; + + not overriding function To_Turtle_String(Term: Term_Type_Without_Finalize; + Stack: RDF.Raptor.Namespace_Stack.Namespace_Stack_Type'Class; -- FIXME: Without_Finalize + Base_URI: URI_Type'Class) -- FIXME: Without_Finalize + return String; + + not overriding procedure Turtle_Write (Stream: IOStream_Type_Without_Finalize'Class; + Term: Term_Type_Without_Finalize; + Stack: RDF.Raptor.Namespace_Stack.Namespace_Stack_Type'Class; -- FIXME: Without_Finalize + Base_URI: URI_Type'Class); -- FIXME: Without_Finalize + + package Handlers is new Term_Handled_Record.Common_Handlers(Term_Type_Without_Finalize); + + type Term_Type is new Handlers.Base_With_Finalization with null record; + + type Term_Type_User is new Handlers.User_Type with null record; + + not overriding function From_Blank (World: Raptor_World_Type_Without_Finalize'Class) + return Term_Type; + not overriding function From_Blank (World: Raptor_World_Type_Without_Finalize'Class; ID: String) + return Term_Type; + not overriding function From_Blank (World: Raptor_World_Type_Without_Finalize'Class; ID: RDF.Auxiliary.String_Holders.Holder) + return Term_Type; + + not overriding function From_Literal (World : Raptor_World_Type_Without_Finalize'Class; + Literal : RDF.Auxiliary.String_Holders.Holder; + Datatype: URI_Type_Without_Finalize'Class; + Language: RDF.Auxiliary.String_Holders.Holder) + return Term_Type; + + not overriding function From_URI_String (World: Raptor_World_Type_Without_Finalize'Class; URI: URI_String) + return Term_Type; + + not overriding function From_URI (World: Raptor_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class) + return Term_Type; + + not overriding function From_String (World: Raptor_World_Type_Without_Finalize'Class; Value: String) + return Term_Type; + + subtype URI_Term_Type is Term_Type + with Dynamic_Predicate => Is_URI(URI_Term_Type); + subtype Literal_Term_Type is Term_Type + with Dynamic_Predicate => Is_Literal(Literal_Term_Type); + subtype Blank_Term_Type is Term_Type + with Dynamic_Predicate => Is_Blank(Blank_Term_Type); + +private + +-- type Term_Literal_Value is +-- record +-- str: chars_ptr; +-- Len: unsigned; +-- Datatype: URI_Handle; +-- Language: chars_ptr; +-- Language_Len: unsigned; +-- end record +-- with Convention => C; + +-- type Term_Blank_Value is +-- record +-- str: chars_ptr; +-- Len: unsigned; +-- end record +-- with Convention => C; + + type Term_Value (Kind: Term_Kind := Term_Kind'First) is + record + case Kind is + when Unknown => null; + when URI => URI: URI_Handle; + when Literal => Literal: Term_Literal_Value; + when Blank => Blank: Term_Blank_Value; + end case; + end record + with Unchecked_Union, Convention => C; + + type Term_Record is + record + World: Raptor_World_Handle; + Usage: Interfaces.C.int; -- intentionally not accessible from our Ada bindings + Kind: Term_Kind; + Value: Term_Value; + end record + with Convention => C; + +end RDF.Raptor.Term; diff --git a/ada/src/rdf-raptor-uri.adb b/ada/src/rdf-raptor-uri.adb new file mode 100644 index 000000000..2a7f3c66b --- /dev/null +++ b/ada/src/rdf-raptor-uri.adb @@ -0,0 +1,382 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Raptor.Memory; +with RDF.Raptor.Namespace_Stack; use RDF.Raptor.Namespace_Stack; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; + +package body RDF.Raptor.URI is + + function raptor_new_uri_from_counted_string (World_Handle: Raptor_World_Handle; + URI_String: char_array; + Length: size_t) + return URI_Handle + with Import, Convention=>C; + + function From_String(World: Raptor_World_Type_Without_Finalize'Class; Arg: URI_String) + return URI_Type is + Handle: constant URI_Handle := + raptor_new_uri_from_counted_string (Get_Handle (World), My_To_C_Without_Nul(String(Arg)), Arg'Length); + begin + -- LD_LIBRARY_PATH="" ltrace -n4 -llibraptor2.so.0 ./obj/test/debug/run_all_tests 2>&1| egrep ^[a-z] + return From_Non_Null_Handle(Handle); + end; + + function raptor_new_uri_from_uri_local_name (World_Handle: Raptor_World_Handle; + URI: URI_Handle; + Local_Name: char_array) + return URI_Handle + with Import, Convention=>C; + + function From_URI_With_Local_Name(World: Raptor_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class; + Local_Name: String) + return URI_Type is + Handle: constant URI_Handle := + raptor_new_uri_from_uri_local_name (Get_Handle (World), Get_Handle (URI), To_C (Local_Name)); + begin + return From_Non_Null_Handle(Handle); + end; + + function raptor_new_uri_from_uri_or_file_string(World_Handle: Raptor_World_Handle; + Base_URI: URI_Handle; + uri_or_file_string: char_array) + return URI_Handle + with Import, Convention=>C; + + function From_URI_Or_File_String(World : Raptor_World_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class; + Uri_Or_File: String) + return URI_Type is + Handle: constant URI_Handle := + raptor_new_uri_from_uri_or_file_string (Get_Handle (World), Get_Handle (Base_URI), To_C (Uri_Or_File)); + begin + return From_Non_Null_Handle(Handle); + end; + + function raptor_new_uri_relative_to_base_counted(World_Handle: Raptor_World_Handle; + Base_URI: URI_Handle; + uri_string: char_array; + uri_len: size_t) + return URI_Handle + with Import, Convention=>C; + + function From_URI_Relative_To_Base(World: Raptor_World_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class; + URI: URI_String) + return URI_Type is + Handle: constant URI_Handle := + raptor_new_uri_relative_to_base_counted(Get_Handle (World), + Get_Handle (Base_URI), + My_To_C_Without_Nul(String(URI)), + URI'Length); + begin + return From_Non_Null_Handle(Handle); + end; + + function raptor_new_uri_from_id(World_Handle: Raptor_World_Handle; + Base_URI: URI_Handle; + ID: char_array) + return URI_Handle + with Import, Convention=>C; + + function From_ID(World: Raptor_World_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class; + ID: String) + return URI_Type is + Handle: constant URI_Handle := + raptor_new_uri_from_id (Get_Handle (World), Get_Handle (Base_URI), To_C (ID)); + begin + return From_Non_Null_Handle(Handle); + end; + + function raptor_new_uri_for_rdf_concept (World_Handle: Raptor_World_Handle; + Name: char_array) + return URI_Handle + with Import, Convention=>C; + + function From_RDF_Concept(World: Raptor_World_Type_Without_Finalize'Class; Name: String) + return URI_Type is + begin + return From_Non_Null_Handle(raptor_new_uri_for_rdf_concept(Get_Handle (World), To_C (Name))); + end; + + function raptor_new_uri_for_xmlbase (Old_URI: URI_Handle) return URI_Handle + with Import, Convention=>C; + + function For_XML_Base(Old_URI: URI_Type_Without_Finalize'Class) return URI_Type is + begin + return From_Non_Null_Handle (raptor_new_uri_for_xmlbase (Get_Handle(Old_URI))); + end; + + function raptor_new_uri_for_retrieval (Old_URI: URI_Handle) + return URI_Handle + with Import, Convention=>C; + + function For_Retrieval(Old_URI: URI_Type_Without_Finalize'Class) return URI_Type is + begin + return From_Non_Null_Handle (raptor_new_uri_for_retrieval (Get_Handle(Old_URI))); + end; + + function raptor_uri_compare (URI1, URI2: URI_Handle) return int + with Import, Convention=>C; + + function Compare(URI1, URI2: URI_Type_Without_Finalize) return RDF.Auxiliary.Comparison_Result is + begin + return RDF.Auxiliary.Comparison_Result (raptor_uri_compare (Get_Handle(URI1), Get_Handle(URI2))); + end; + + function raptor_uri_equals (URI1, URI2: URI_Handle) return int + with Import, Convention=>C; + + function Equals(URI1, URI2: URI_Type_Without_Finalize) return Boolean is + begin + return raptor_uri_equals (Get_Handle(URI1), Get_Handle(URI2)) /= 0; + end; + + function raptor_uri_as_string(URI: URI_Handle) + return chars_ptr + with Import, Convention=>C; + + -- raptor_uri_as_counted_string() or raptor_uri_to_counted_string() is faster. + -- But Ad2012 does not provide constructing strings of given length. + function To_String(URI: URI_Type_Without_Finalize) return URI_String is + begin + -- raptor_uri_as_string() returns a pointer which exists as long as the URI object. No need to free it. + return URI_String(String'(Value(raptor_uri_as_string(Get_Handle(URI))))); + end; + + function raptor_uri_to_relative_uri_string (Base_URI, Reference_URI: URI_Handle) return chars_ptr + with Import, Convention=>C; + + function To_Relative_URI_String(Base_URI, Reference_URI: URI_Type_Without_Finalize) return URI_String is + C_Str: constant chars_ptr := + raptor_uri_to_relative_uri_string (Get_Handle(Base_URI), Get_Handle(Reference_URI)); + Result: constant String := Value (C_Str); + begin + RDF.Raptor.Memory.raptor_free_memory (C_Str); + return URI_String(Result); + end; + + function raptor_uri_resolve_uri_reference(Base_URI, Reference_URI: char_array; + buffer: char_array; + length: size_t) return size_t + with Import, Convention=>C; + + function Resolve_URI_Reference (Base_URI, Reference_URI: URI_String) return URI_String is + Buffer_Length: constant size_t := Base_URI'Length + Reference_URI'Length + 1; + Buffer : constant char_array (1..Buffer_Length) := (others=>NUL); + Dummy : constant size_t := + raptor_uri_resolve_uri_reference(To_C(String(Base_URI)), + To_C(String(Reference_URI)), + Buffer, + Buffer_Length); + begin + return URI_String(To_Ada(Buffer)); + end; + + function raptor_uri_counted_filename_to_uri_string(filename: char_array; filename_len: size_t) + return chars_ptr + with Import, Convention=>C; + + function Filename_To_URI_String (Filename: String) return URI_String is + Result1: constant chars_ptr := + raptor_uri_counted_filename_to_uri_string(To_C(Filename, Append_Nul=>False), Filename'Length); + Result: constant String := Value (Result1); + begin + RDF.Raptor.Memory.raptor_free_memory (Result1); + return URI_String(Result); + end; + + function raptor_uri_uri_string_is_absolute (URI_String: char_array) return int + with Import, Convention=>C; + + function URI_String_Is_Absolute (Str: URI_String) return Boolean is + begin + return raptor_uri_uri_string_is_absolute(To_C(String(Str))) > 0; -- C sources show that <0 cannot be returned + end; + + function raptor_uri_uri_string_is_file_uri (URI_String: char_array) return int + with Import, Convention=>C; + + function URI_String_Is_File_URI (Str: URI_String) return Boolean is + begin + return raptor_uri_uri_string_is_file_uri(To_C(String(Str))) /= 0; + end; + + function raptor_uri_uri_string_to_filename (URI_String: char_array) return chars_ptr + with Import, Convention=>C; + + function URI_String_To_Filename (Str: URI_String) return String is + Result1: constant chars_ptr := raptor_uri_uri_string_to_filename(To_C(String(Str))); + Result: constant String := Value (Result1); + begin + RDF.Raptor.Memory.raptor_free_memory (Result1); + return Result; + end; + + type Fragment_P_Type is access all chars_ptr + with Convention=>C; + + function raptor_uri_uri_string_to_filename_fragment (URI_String: char_array; + Fragment_P: Fragment_P_Type) + return chars_ptr + with Import, Convention=>C; + + function URI_String_To_Filename_And_Fragment(Str: URI_String) return Filename_And_Fragment is + C_Filename : chars_ptr; + C_Fragment : aliased chars_ptr; + begin + C_Filename := raptor_uri_uri_string_to_filename_fragment(To_C(String(Str)), + C_Fragment'Unchecked_Access); + declare + Filename: constant String := Value (C_Filename); + Fragment: constant String := Value (C_Fragment); + Result : constant Filename_And_Fragment := + (Filename_Length => Filename'Length, + Fragment_Length => Fragment'Length, + Filename => Filename, + Fragment => Fragment); + begin + RDF.Raptor.Memory.raptor_free_memory (C_Filename); + if C_Fragment /= Null_Ptr then + RDF.Raptor.Memory.raptor_free_memory (C_Fragment); + end if; + return Result; + end; + end; + + function raptor_uri_print (URI: URI_Handle; File: RDF.Auxiliary.C_File_Access) return int + with Import, Convention=>C; + + procedure Print (URI: URI_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access) is + begin + if raptor_uri_print (Get_Handle (URI), File) /= 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_uri_get_world (URI: URI_Handle) return Raptor_World_Handle + with Import, Convention=>C; + + function Get_World (URI: URI_Type_Without_Finalize) return Raptor_World_Type_Without_Finalize is + begin + return From_Handle (raptor_uri_get_world (Get_Handle (URI))); + end; + + function raptor_uri_write (URI: URI_Handle; Stream: IOStream_Handle) return int + with Import, Convention=>C; + + procedure Write (URI: URI_Type_Without_Finalize; Stream: IOStream_Type_Without_Finalize'Class) is + begin + if raptor_uri_write (Get_Handle(URI), Get_Handle(Stream)) /= 0 then + raise IOStream_Exception; + end if; + end; + + function raptor_uri_file_exists (URI: URI_Handle) return int + with Import, Convention=>C; + + function URI_File_Exists (URI: URI_Type_Without_Finalize) return Boolean is + Result: constant int := raptor_uri_file_exists(Get_Handle(URI)); + begin + if Result < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Result /= 0; + end; + + function raptor_uri_filename_exists (Filename: char_array) return int + with Import, Convention=>C; + + function Filename_Exists (Filename: String) return Boolean is + Result: constant int := raptor_uri_filename_exists(To_C(Filename, Append_Nul=>True)); + begin + if Result < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Result /= 0; + end; + + procedure raptor_free_uri (Handle: URI_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: URI_Type_Without_Finalize; Handle: URI_Handle) is + begin + raptor_free_uri (Handle); + end; + + function raptor_uri_copy (Handle: URI_Handle) + return URI_Handle + with Import, Convention=>C; + + function Adjust_Handle (Object: URI_Type_Without_Finalize; Handle: URI_Handle) return URI_Handle is + begin + return raptor_uri_copy(Handle); + end; + + function Get_Filename (Pair: Filename_And_Fragment) return String is (Pair.Filename); + function Get_Fragment (Pair: Filename_And_Fragment) return String is (Pair.Fragment); + + function raptor_uri_to_turtle_string(Handle: Raptor_World_Handle; + URI: URI_Handle; + Stack: Namespace_Stack_Handle; + Base_URI: URI_Handle) + return Chars_Ptr + with Import, Convention=>C; + + function To_Turtle_String (World: Raptor_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize; + Stack: Namespace_Stack_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class) + return String is + C_Str: constant chars_ptr := raptor_uri_to_turtle_string(Get_Handle(World), + Get_Handle(URI), + Get_Handle(Stack), + Get_Handle(Base_URI)); + begin + if C_Str = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Result: constant String := Value(C_Str); + begin + RDF.Raptor.Memory.Raptor_Free_Memory(C_Str); + return Result; + end; + end; + + function raptor_uri_turtle_write(Handle: Raptor_World_Handle; + Stream: IOStream_Handle; + URI: URI_Handle; + Stack: Namespace_Stack_Handle; + Base_URI: URI_Handle) + return Int + with Import, Convention=>C; + + procedure Turtle_Write (World: Raptor_World_Type_Without_Finalize'Class; + Stream: IOStream_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize; + Stack: Namespace_Stack_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class) is + begin + if raptor_uri_turtle_write(Get_Handle(World), + Get_Handle(Stream), + Get_Handle(URI), + Get_Handle(Stack), + Get_Handle(Base_URI)) /= 0 + then + raise IOStream_Exception; + end if; + end; + + use type RDF.Auxiliary.Comparison_Result; + + function "<"(URI1, URI2: URI_Type_Without_Finalize) return Boolean is (Compare(URI1, URI2) < 0); + + function ">"(URI1, URI2: URI_Type_Without_Finalize) return Boolean is (Compare(URI1, URI2) > 0); + + function "<="(URI1, URI2: URI_Type_Without_Finalize) return Boolean is (Compare(URI1, URI2) <= 0); + + function ">="(URI1, URI2: URI_Type_Without_Finalize) return Boolean is (Compare(URI1, URI2) >= 0); + +end RDF.Raptor.URI; diff --git a/ada/src/rdf-raptor-uri.ads b/ada/src/rdf-raptor-uri.ads new file mode 100644 index 000000000..5d4d3ff35 --- /dev/null +++ b/ada/src/rdf-raptor-uri.ads @@ -0,0 +1,131 @@ +with RDF.Auxiliary.Handled_Record; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; +limited with RDF.Raptor.Namespace_Stack; + +package RDF.Raptor.URI is + + type URI_String is new String; + + package URI_Handled_Record is new RDF.Auxiliary.Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + subtype URI_Handle is URI_Handled_Record.Access_Type; + + -- Only absolute URIs! + type URI_Type_Without_Finalize is new URI_Handled_Record.Base_Object with null record; + + overriding function Adjust_Handle (Object: URI_Type_Without_Finalize; Handle: URI_Handle) return URI_Handle; + + overriding procedure Finalize_Handle (Object: URI_Type_Without_Finalize; Handle: URI_Handle); + + not overriding function Compare(URI1, URI2: URI_Type_Without_Finalize) return RDF.Auxiliary.Comparison_Result; + + not overriding function Equals(URI1, URI2: URI_Type_Without_Finalize) return Boolean; + + overriding function "="(URI1, URI2: URI_Type_Without_Finalize) return Boolean renames Equals; + + not overriding function "<"(URI1, URI2: URI_Type_Without_Finalize) return Boolean; + + not overriding function ">"(URI1, URI2: URI_Type_Without_Finalize) return Boolean; + + not overriding function "<="(URI1, URI2: URI_Type_Without_Finalize) return Boolean; + + not overriding function ">="(URI1, URI2: URI_Type_Without_Finalize) return Boolean; + + not overriding function To_String(URI: URI_Type_Without_Finalize) return URI_String; + + not overriding function To_Relative_URI_String(Base_URI, Reference_URI: URI_Type_Without_Finalize) + return URI_String; + + function Resolve_URI_Reference (Base_URI, Reference_URI: URI_String) return URI_String; + + function Filename_To_URI_String (Filename: String) return URI_String; + + function URI_String_Is_Absolute (Str: URI_String) return Boolean; + + function URI_String_Is_File_URI (Str: URI_String) return Boolean; + + -- ignores the fragment + function URI_String_To_Filename (Str: URI_String) return String; + + type Filename_And_Fragment(<>) is private; + + function Get_Filename (Pair: Filename_And_Fragment) return String; + function Get_Fragment (Pair: Filename_And_Fragment) return String; + + function URI_String_To_Filename_And_Fragment(Str: URI_String) return Filename_And_Fragment; + + -- Not supposed to be used, but included for completeness + not overriding procedure Print (URI: URI_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access); + + not overriding function Get_World (URI: URI_Type_Without_Finalize) + return Raptor_World_Type_Without_Finalize; + + not overriding procedure Write (URI: URI_Type_Without_Finalize; Stream: IOStream_Type_Without_Finalize'Class); + + not overriding function URI_File_Exists (URI: URI_Type_Without_Finalize) return Boolean; + + function Filename_Exists (Filename: String) return Boolean; + + not overriding function To_Turtle_String (World: Raptor_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize; + Stack: RDF.Raptor.Namespace_Stack.Namespace_Stack_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class) + return String; + + not overriding procedure Turtle_Write (World: Raptor_World_Type_Without_Finalize'Class; + Stream: IOStream_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize; + Stack: RDF.Raptor.Namespace_Stack.Namespace_Stack_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class); + + package Handlers is new URI_Handled_Record.Common_Handlers(URI_Type_Without_Finalize); + + type URI_Type is new Handlers.Base_With_Finalization with null record; + + type URI_Type_User is new Handlers.User_Type with null record; + + not overriding function From_String(World: Raptor_World_Type_Without_Finalize'Class; + Arg: URI_String) + return URI_Type; + + not overriding function From_URI_With_Local_Name(World: Raptor_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class; + Local_Name: String) + return URI_Type; + + not overriding function From_URI_Or_File_String(World: Raptor_World_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class; + uri_or_file: String) + return URI_Type; + + not overriding function From_URI_Relative_To_Base(World: Raptor_World_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class; + URI: URI_String) + return URI_Type; + + not overriding function From_ID(World: Raptor_World_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class; + ID: String) + return URI_Type; + + not overriding function From_RDF_Concept(World: Raptor_World_Type_Without_Finalize'Class; + Name: String) + return URI_Type; + + not overriding function For_XML_Base(Old_URI: URI_Type_Without_Finalize'Class) return URI_Type; + + not overriding function For_Retrieval(Old_URI: URI_Type_Without_Finalize'Class) return URI_Type; + + -- null + --overriding function Default_Handle(Object: URI_Type) return Handle_Type; + +private + + type Filename_And_Fragment (Filename_Length, Fragment_Length: Natural) is + record + Filename: String(1..Filename_Length); + Fragment: String(1..Fragment_Length); + end record; + +end RDF.Raptor.URI; diff --git a/ada/src/rdf-raptor-world.adb b/ada/src/rdf-raptor-world.adb new file mode 100644 index 000000000..b2201ccd5 --- /dev/null +++ b/ada/src/rdf-raptor-world.adb @@ -0,0 +1,67 @@ +with Interfaces.C; use Interfaces.C; +with RDF.Raptor.Constants; + +package body RDF.Raptor.World is + + function raptor_new_world_internal(Version: Interfaces.C.unsigned) return Raptor_World_Handle + with Import, Convention=>C; + + procedure raptor_world_open(Handle: Raptor_World_Handle) + with Import, Convention=>C; + + procedure raptor_world_set_flag(Handle: Raptor_World_Handle; Flag: Raptor_Flag_Type; Value: Interfaces.C.int) + with Import, Convention=>C; + + function Default_Handle(Object: Raptor_World_Type_Without_Finalize) return Raptor_World_Handle is + begin + return raptor_new_world_internal(RDF.Raptor.Constants.version_decimal); + end; + + procedure Open(Object: in out Raptor_World_Type_Without_Finalize) is + begin + raptor_world_open(Get_Handle(Object)); + end; + + procedure Open(Object: in out Raptor_World_Type_Without_Finalize; Flags: Flags_Array) is + begin + Set_Flags(Object, Flags); + Open(Object); + end; + + procedure Set_Flag(Object: in out Raptor_World_Type_Without_Finalize; + Flag: Raptor_Flag_Type; + Value: Boolean) is + begin + raptor_world_set_flag(Get_Handle(Object), Flag, (if Value then 1 else 0)); + end; + + procedure Set_Flags(Object: in out Raptor_World_Type_Without_Finalize; Flags: Flags_Array) is + begin + for Element of Flags loop + Set_Flag(Object, Element.Flag, Element.Value); + end loop; + end; + + function Open return Raptor_World_Type is + begin + return Object: Raptor_World_Type do + Open(Object); + end return; + end; + + function Open(Flags: Flags_Array) return Raptor_World_Type is + begin + return Object: Raptor_World_Type do + Open(Object, Flags); + end return; + end; + + procedure raptor_free_world(Handle: Raptor_World_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Raptor_World_Type_Without_Finalize; Handle: Raptor_World_Handle) is + begin + raptor_free_world(Handle); + end; + +end RDF.Raptor.World; diff --git a/ada/src/rdf-raptor-world.ads b/ada/src/rdf-raptor-world.ads new file mode 100644 index 000000000..84d65fe8b --- /dev/null +++ b/ada/src/rdf-raptor-world.ads @@ -0,0 +1,59 @@ +with RDF.Auxiliary; use RDF.Auxiliary; +with RDF.Auxiliary.Limited_Handled_Record; + +package RDF.Raptor.World is + + package Raptor_World_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + type Raptor_World_Type_Without_Finalize is new Raptor_World_Handled_Record.Base_Object with null record; + + subtype Raptor_World_Handle is Raptor_World_Handled_Record.Access_Type; + + type Raptor_Flag_Type is (Libxml_Error_Save, + Libxml_Structured_Error_Save, + URI_Interning, + WWW_Skip_Init_Finish) + with Convention => C; + for Raptor_Flag_Type use (Libxml_Error_Save => 1, + Libxml_Structured_Error_Save => 2, + URI_Interning => 3, + WWW_Skip_Init_Finish => 4); + + type Flag_And_Value is + record + Flag : Raptor_Flag_Type; + Value: Boolean; + end record; + + type Flags_Array is array(Integer range <>) of Flag_And_Value; + + overriding procedure Finalize_Handle (Object: Raptor_World_Type_Without_Finalize; Handle: Raptor_World_Handle); + + overriding function Default_Handle(Object: Raptor_World_Type_Without_Finalize) + return Raptor_World_Handle; + + not overriding procedure Open(Object: in out Raptor_World_Type_Without_Finalize); + + not overriding procedure Open(Object: in out Raptor_World_Type_Without_Finalize; Flags: Flags_Array); + + not overriding procedure Set_Flag(Object: in out Raptor_World_Type_Without_Finalize; + Flag: Raptor_Flag_Type; + Value: Boolean); + + not overriding procedure Set_Flags(Object: in out Raptor_World_Type_Without_Finalize; + Flags: Flags_Array); + + package Handlers is new Raptor_World_Handled_Record.Common_Handlers(Raptor_World_Type_Without_Finalize); + + type Raptor_World_Type is new Handlers.Base_With_Finalization with null record; + + type Raptor_World_Type_User is new Handlers.User_Type with null record; + + not overriding function Open return Raptor_World_Type; + + not overriding function Open(Flags: Flags_Array) return Raptor_World_Type; + + -- Not implemented + -- procedure Set_Libxslt_Security_Preferences + +end RDF.Raptor.World; diff --git a/ada/src/rdf-raptor-www.adb b/ada/src/rdf-raptor-www.adb new file mode 100644 index 000000000..a2dd1948c --- /dev/null +++ b/ada/src/rdf-raptor-www.adb @@ -0,0 +1,312 @@ +with Ada.Unchecked_Conversion; +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.Convert_Void; +with RDF.Auxiliary.C_Pointers; +with RDF.Raptor.Memory; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; + +package body RDF.Raptor.WWW is + + type C_Func is access procedure (WWW: WWW_Handle; Value: chars_ptr) + with Convention=>C; + + procedure Set_Or_Null (Func: C_Func; WWW: WWW_Type_Without_Finalize; Value: String) is + begin + if Value /= "" then + declare + Str: aliased char_array := To_C(Value); + begin + Func.all(Get_Handle(WWW), To_Chars_Ptr(Str'Unchecked_Access)); + end; + else + Func.all(Get_Handle(WWW), Null_Ptr); + end if; + end; + + procedure raptor_www_set_user_agent (WWW: WWW_Handle; User_Agent: chars_ptr) + with Import, Convention=>C; + + procedure Set_User_Agent (WWW: in out WWW_Type_Without_Finalize; User_Agent: String) is + begin + Set_Or_Null(raptor_www_set_user_agent'Access, WWW, User_Agent); + end; + + procedure raptor_www_set_proxy (WWW: WWW_Handle; Proxy: char_array) + with Import, Convention=>C; + + procedure Set_Proxy (WWW: in out WWW_Type_Without_Finalize; Proxy: String) is + begin + raptor_www_set_proxy(Get_Handle(WWW), To_C(Proxy)); + end; + + procedure raptor_www_set_http_accept (WWW: WWW_Handle; Value: chars_ptr) + with Import, Convention=>C; + + procedure Set_HTTP_Accept (WWW: in out WWW_Type_Without_Finalize; Value: String) is + begin + Set_Or_Null(raptor_www_set_http_accept'Access, WWW, Value); + end; + + -- FIXME: raptor_www_set_http_cache_control (with _www_ and _http_)? + procedure raptor_set_cache_control (WWW: WWW_Handle; Cache_Control: chars_ptr) + with Import, Convention=>C; + + -- FIXME: return value of raptor_set_cache_control() + procedure Set_Cache_Control (WWW: in out WWW_Type_Without_Finalize; Cache_Control: String) is + Str: aliased char_array := To_C(Cache_Control); + begin + raptor_set_cache_control(Get_Handle(WWW), To_Chars_Ptr(Str'Unchecked_Access)); + end; + + -- Remove Cache-Control: header altogether + procedure Unset_Cache_Control (WWW: in out WWW_Type_Without_Finalize) is + begin + raptor_set_cache_control(Get_Handle(WWW), Null_Ptr); + end; + + procedure raptor_www_set_connection_timeout (WWW: WWW_Handle; Timeout: int) + with Import, Convention=>C; + + procedure Set_Connection_Timeout (WWW: in out WWW_Type_Without_Finalize; Timeout: Natural) is + begin + raptor_www_set_connection_timeout(Get_Handle(WWW), int(Timeout)); + end; + + function raptor_www_get_final_uri (WWW: WWW_Handle) return URI_Handle + with Import, Convention=>C; + + function Get_Final_URI (WWW: WWW_Type_Without_Finalize) return URI_Type is + begin + -- may return object with NULL handle + return From_Handle(raptor_www_get_final_uri(Get_Handle(WWW))); + end; + + function raptor_www_fetch (WWW: WWW_Handle; URI: URI_Handle) return int + with Import, Convention=>C; + + procedure Fetch (WWW: WWW_Type_Without_Finalize; URI: URI_Type_Without_Finalize'Class) is + begin + if raptor_www_fetch(Get_Handle(WWW), Get_Handle(URI)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + type String_P_Type is access all chars_ptr with Convention=>C; + type String_P_Type2 is access all RDF.Auxiliary.C_Pointers.Pointer with Convention=>C; + + function Convert2 is new Ada.Unchecked_Conversion(String_P_Type, String_P_Type2); + + function raptor_www_fetch_to_string (WWW: WWW_Handle; + URI: URI_Handle; + String_P: access chars_ptr; + Length_P: access size_t; + Malloc_Handler: chars_ptr) return int + with Import, Convention=>C; + + function Fetch_To_String(WWW: WWW_Type_Without_Finalize; URI: URI_Type_Without_Finalize'Class) + return String is + String_P: aliased chars_ptr; + Length_P: aliased size_t; + begin + if raptor_www_fetch_to_string(Get_Handle(WWW), Get_Handle(URI), String_P'Access, Length_P'Access, Null_Ptr) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Result: constant String := Value_With_Possible_NULs(Convert2(String_P'Unchecked_Access).all, Length_P); + begin + RDF.Raptor.Memory.raptor_free_memory(String_P); + return Result; + end; + end; + + function raptor_www_get_connection (WWW: WWW_Handle) return Connection_Type + with Import, Convention=>C; + + function Get_Connection (WWW: WWW_Type_Without_Finalize) return Connection_Type is + begin + return raptor_www_get_connection(Get_Handle(WWW)); + end; + + function raptor_www_set_ssl_cert_options (WWW: WWW_Handle; + Cert_Filename, Cert_Type, Cert_Passphrase: char_array) + return int + with Import, Convention=>C; + + procedure Set_SSL_Cert_Options (WWW: in out WWW_Type_Without_Finalize; + Cert_Filename, Cert_Type, Cert_Passphrase: String) is + begin + if raptor_www_set_ssl_cert_options(Get_Handle(WWW), To_C(Cert_Filename), To_C(Cert_Type), To_C(Cert_Passphrase)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function raptor_www_set_ssl_verify_options (WWW: WWW_Handle; Verify_Peer, Verify_Host: int) return int + with Import, Convention=>C; + + procedure Set_SSL_Verify_Options (WWW: in out WWW_Type_Without_Finalize; + Verify_Peer, Verify_Host: Boolean) is + begin + if raptor_www_set_ssl_verify_options(Get_Handle(WWW), + (if Verify_Peer then 1 else 0), + (if Verify_Host then 1 else 0)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + procedure raptor_www_abort (WWW: WWW_Handle; Reason: char_array) + with Import, Convention=>C; + + procedure Abort_Operation (WWW: WWW_Type_Without_Finalize; Reason: String) is + begin + raptor_www_abort(Get_Handle(WWW), To_C(Reason)); + end; + + function raptor_new_www (World: Raptor_World_Handle) return WWW_Handle + with Import, Convention=>C; + + function Create (World: Raptor_World_Type'Class) return WWW_Type is + begin + return From_Non_Null_Handle(raptor_new_www(Get_Handle(World))); + end; + + function raptor_new_www_with_connection (World: Raptor_World_Handle; + Connection: Connection_Type) + return WWW_Handle + with Import, Convention=>C; + + function Create (World: Raptor_World_Type'Class; Connection: Connection_Type) return WWW_Type is + begin + return From_Non_Null_Handle(raptor_new_www_with_connection(Get_Handle(World), Connection)); + end; + + procedure raptor_free_www (Handle: WWW_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: WWW_Type_Without_Finalize; Handle: WWW_Handle) is + begin + raptor_free_www(Handle); + end; + +-- type User_Defined_Access is access constant WWW_Type_Without_Finalize'Class; + package My_Conv is new RDF.Auxiliary.Convert_Void(WWW_Type_Without_Finalize'Class); + + type raptor_www_write_bytes_handler is access procedure (WWW: WWW_Handle; + User_data: chars_ptr; + Ptr: RDF.Auxiliary.C_Pointers.Pointer; + Size, Nmemb: size_t) + with Convention=>C; + + type raptor_www_content_type_handler is access procedure (WWW: WWW_Handle; + User_data: chars_ptr; + Content_Type: chars_ptr) + with Convention=>C; + + type raptor_www_uri_filter_func is access function (User_data: chars_ptr; URI: URI_Handle) return int + with Convention=>C; + + type raptor_www_final_uri_handler is access procedure (WWW: WWW_Handle; + User_data: chars_ptr; + URI: URI_Handle) + with Convention=>C; + + procedure Write_Bytes_Handler_Impl (WWW: WWW_Handle; + User_data: chars_ptr; + Ptr: RDF.Auxiliary.C_Pointers.Pointer; + Size, Nmemb: size_t) + with Convention=>C; + + procedure Content_Type_Handler_Impl (WWW: WWW_Handle; User_data: chars_ptr; Content_Type: chars_ptr) + with Convention=>C; + + function URI_Filter_Impl (User_data: chars_ptr; URI: URI_Handle) return int + with Convention=>C; + + procedure Final_URI_Handler_Impl (WWW: WWW_Handle; User_data: chars_ptr; URI: URI_Handle) + with Convention=>C; + + procedure Write_Bytes_Handler_Impl (WWW: WWW_Handle; + User_data: chars_ptr; + Ptr: RDF.Auxiliary.C_Pointers.Pointer; + Size, Nmemb: size_t) is + begin + Write_Bytes_Handler(--WWW_Type_Without_Finalize'(From_Handle(WWW)), -- ignored + My_Conv.To_Access(User_Data).all, + Value_With_Possible_NULs(Ptr, Size*Nmemb)); + end; + + procedure Content_Type_Handler_Impl (WWW: WWW_Handle; User_data: chars_ptr; Content_Type: chars_ptr) is + begin + Content_Type_Handler(--WWW_Type_Without_Finalize'(From_Handle(WWW)), -- ignored + My_Conv.To_Access(User_Data).all, + Value(Content_Type)); + end; + + function URI_Filter_Impl (User_data: chars_ptr; URI: URI_Handle) return int is + Result: constant Boolean := URI_Filter(My_Conv.To_Access(User_Data).all, + URI_Type_Without_Finalize'(From_Non_Null_Handle(URI))); + begin + return (if Result then 0 else 1); + end; + + procedure Final_URI_Handler_Impl (WWW: WWW_Handle; User_Data: chars_ptr; URI: URI_Handle) is + begin + Final_URI_Handler(--WWW_Type_Without_Finalize'(From_Handle(WWW)), -- ignored + My_Conv.To_Access(User_Data).all, + URI_Type_Without_Finalize'(From_Handle(URI))); + end; + + procedure Initialize_All_Callbacks (WWW: in out WWW_Type_Without_Finalize) is + begin + Initialize_Write_Bytes_Handler(WWW); + Initialize_Content_Type_Handler(WWW); + Initialize_URI_Filter(WWW); + Initialize_Final_URI_Handler(WWW); + end; + + procedure raptor_www_set_write_bytes_handler(WWW: WWW_Handle; + Handler: raptor_www_write_bytes_handler; + User_Data: chars_ptr) + with Import, Convention=>C; + + procedure Initialize_Write_Bytes_Handler (WWW: in out WWW_Type_Without_Finalize) is + begin + raptor_www_set_write_bytes_handler(Get_Handle(WWW), + Write_Bytes_Handler_Impl'Access, + My_Conv.To_C_Pointer(WWW'Unchecked_Access)); + end; + + procedure raptor_www_set_content_type_handler (WWW: WWW_Handle; + Handler: raptor_www_content_type_handler; + User_Data: chars_ptr) + with Import, Convention=>C; + + procedure raptor_www_set_final_uri_handler (WWW: WWW_Handle; + Handler: raptor_www_final_uri_handler; + User_Data: chars_ptr) + with Import, Convention=>C; + + procedure Initialize_Content_Type_Handler (WWW: in out WWW_Type_Without_Finalize) is + begin + raptor_www_set_content_type_handler(Get_Handle(WWW), + Content_Type_Handler_Impl'Access, + My_Conv.To_C_Pointer(WWW'Unchecked_Access)); + end; + + procedure raptor_www_set_uri_filter (WWW: WWW_Handle; + Handler: raptor_www_uri_filter_func; + User_Data: chars_ptr) + with Import, Convention=>C; + + procedure Initialize_URI_Filter (WWW: in out WWW_Type_Without_Finalize) is + begin + raptor_www_set_uri_filter(Get_Handle(WWW), URI_Filter_Impl'Access, My_Conv.To_C_Pointer(WWW'Unchecked_Access)); + end; + + procedure Initialize_Final_URI_Handler (WWW: in out WWW_Type_Without_Finalize) is + begin + raptor_www_set_final_uri_handler(Get_Handle(WWW), Final_URI_Handler_Impl'Access, My_Conv.To_C_Pointer(WWW'Unchecked_Access)); + end; + +end RDF.Raptor.WWW; diff --git a/ada/src/rdf-raptor-www.ads b/ada/src/rdf-raptor-www.ads new file mode 100644 index 000000000..795e9ddb6 --- /dev/null +++ b/ada/src/rdf-raptor-www.ads @@ -0,0 +1,80 @@ +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Raptor.URI; use RDF.Raptor.URI; + +package RDF.Raptor.WWW is + + package WWW_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + subtype WWW_Handle is WWW_Handled_Record.Access_Type; + + -- I deliberately expose that it is an access type (not just a private type), + -- to simplify libcurl and libxml interaction + type Connection_Type is new RDF.Auxiliary.Dummy_Record_Access; + + type WWW_Type_Without_Finalize is new WWW_Handled_Record.Base_Object with null record; + + overriding procedure Finalize_Handle (Object: WWW_Type_Without_Finalize; Handle: WWW_Handle); + + -- You can call this function or initialize only callbacks you need (below). + -- TODO: Does it make sense for _Without_Finalize? + not overriding procedure Initialize_All_Callbacks (WWW: in out WWW_Type_Without_Finalize); + + not overriding procedure Initialize_Write_Bytes_Handler (WWW: in out WWW_Type_Without_Finalize); + not overriding procedure Initialize_Content_Type_Handler (WWW: in out WWW_Type_Without_Finalize); + not overriding procedure Initialize_URI_Filter (WWW: in out WWW_Type_Without_Finalize); + not overriding procedure Initialize_Final_URI_Handler (WWW: in out WWW_Type_Without_Finalize); + + not overriding procedure Write_Bytes_Handler (WWW: WWW_Type_Without_Finalize; Value: String) is null; + not overriding procedure Content_Type_Handler (WWW: WWW_Type_Without_Finalize; Content_Type: String) is null; + not overriding procedure Final_URI_Handler (WWW: WWW_Type_Without_Finalize; URI: URI_Type_Without_Finalize'Class) is null; + + -- Return False to disallow loading an URI + not overriding function URI_Filter (WWW: WWW_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class) + return Boolean is (True); + + -- Empty string means no User-Agent header (I make the behavior the same as --user-agent="" in Wget. + not overriding procedure Set_User_Agent (WWW: in out WWW_Type_Without_Finalize; User_Agent: String); + + not overriding procedure Set_Proxy (WWW: in out WWW_Type_Without_Finalize; Proxy: String); + + -- The same as for User-Agent + not overriding procedure Set_HTTP_Accept (WWW: in out WWW_Type_Without_Finalize; Value: String); + + -- Empty Cache_Control is not the same as Unset_Cache_Control + not overriding procedure Set_Cache_Control (WWW: in out WWW_Type_Without_Finalize; Cache_Control: String); + + -- Remove Cache-Control: header altogether + not overriding procedure Unset_Cache_Control (WWW: in out WWW_Type_Without_Finalize); + + not overriding procedure Set_Connection_Timeout (WWW: in out WWW_Type_Without_Finalize; Timeout: Natural); + + not overriding function Get_Final_URI (WWW: WWW_Type_Without_Finalize) return URI_Type; + + not overriding procedure Fetch (WWW: WWW_Type_Without_Finalize; URI: URI_Type_Without_Finalize'Class); + + not overriding function Fetch_To_String (WWW: WWW_Type_Without_Finalize; URI: URI_Type_Without_Finalize'Class) return String; + + not overriding function Get_Connection (WWW: WWW_Type_Without_Finalize) return Connection_Type; + + not overriding procedure Set_SSL_Cert_Options (WWW: in out WWW_Type_Without_Finalize; + Cert_Filename, Cert_Type, Cert_Passphrase: String); + + not overriding procedure Set_SSL_Verify_Options (WWW: in out WWW_Type_Without_Finalize; + Verify_Peer, Verify_Host: Boolean); + + not overriding procedure Abort_Operation (WWW: WWW_Type_Without_Finalize; Reason: String); + + package Handlers is new WWW_Handled_Record.Common_Handlers(WWW_Type_Without_Finalize); + + type WWW_Type is new Handlers.Base_With_Finalization with null record; + + type WWW_Type_User is new Handlers.User_Type with null record; + + not overriding function Create (World: Raptor_World_Type'Class) return WWW_Type; + + not overriding function Create (World: Raptor_World_Type'Class; Connection: Connection_Type) + return WWW_Type; + +end RDF.Raptor.WWW; diff --git a/ada/src/rdf-raptor.ads b/ada/src/rdf-raptor.ads new file mode 100644 index 000000000..c865d220d --- /dev/null +++ b/ada/src/rdf-raptor.ads @@ -0,0 +1,33 @@ +package RDF.Raptor is + pragma Pure; + + type Domain_Type is (None_Domain, + IOStream_Domain, + Namespace_Domain, + Parser_Domain, + Qname_Domain, + Sax2_Domain, + Serializer_Domain, + Term_Domain, + Turtle_Writer_Domain, + URI_Domain, + World_Domain, + WWW_Domain, + XML_Writer_Domain) + with Convention => C; + for Domain_Type use (None_Domain => 0, + IOStream_Domain => 1, + Namespace_Domain => 2, + Parser_Domain => 3, + Qname_Domain => 4, + Sax2_Domain => 5, + Serializer_Domain => 6, + Term_Domain => 7, + Turtle_Writer_Domain => 8, + URI_Domain => 9, + World_Domain => 10, + WWW_Domain => 11, + XML_Writer_Domain => 12); + function Last return Domain_Type renames XML_Writer_Domain; + +end RDF.Raptor; diff --git a/ada/src/rdf-rasqal-bnode.adb b/ada/src/rdf-rasqal-bnode.adb new file mode 100644 index 000000000..fb916c8b7 --- /dev/null +++ b/ada/src/rdf-rasqal-bnode.adb @@ -0,0 +1,75 @@ +with Ada.Unchecked_Conversion; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.Convert_Void; +with RDF.Auxiliary.C_String_Holders; +with RDF.Rasqal.Memory; + +package body RDF.Rasqal.Bnode is + + type C_BNode_ID_Handler is access function (World: Rasqal_World_Handle; + Data: chars_ptr; + User_ID: chars_ptr) + return Chars_Ptr + with Convention=>C; + +-- type User_Defined_Access is access constant BNode_ID_Handler'Class; + package My_Conv is new RDF.Auxiliary.Convert_Void(BNode_ID_Handler'Class); + + function C_BNode_ID_Handle_Impl(World: Rasqal_World_Handle; + Data: chars_ptr; + User_ID: chars_ptr) + return Chars_Ptr + with Convention=>C; + + function C_BNode_ID_Handle_Impl(World: Rasqal_World_Handle; + Data: chars_ptr; + User_ID: chars_ptr) return Chars_Ptr is + use RDF.Auxiliary.String_Holders; + User_ID2: RDF.Auxiliary.String_Holders.Holder; + begin + if User_ID /= Null_Ptr then + Replace_Element(User_ID2, Value(User_ID)); + end if; + declare + Result: constant Chars_Ptr := New_String(Do_Handle(Rasqal_World_Type_Without_Finalize'(From_Non_Null_Handle(World)), + My_Conv.To_Access(Data).all, + User_ID2)); + begin + RDF.Rasqal.Memory.rasqal_free_memory(User_ID); + return Result; + end; + end; + + procedure rasqal_world_set_generate_bnodeid_handler (World: Rasqal_World_Handle; + Data: chars_ptr; + Handler: C_BNode_ID_Handler) + with Import, Convention=>C; + + procedure Set_BNode_ID_Handler (World: in out Rasqal_World_Type_Without_Finalize'Class; + Handler: access BNode_ID_Handler'Class) is + begin + rasqal_world_set_generate_bnodeid_handler(Get_Handle(World), My_Conv.To_C_Pointer(Handler), C_BNode_ID_Handle_Impl'Access); + end; + + function rasqal_world_set_default_generate_bnodeid_parameters (World: Rasqal_World_Handle; + Prefix: Chars_Ptr; + Base: int) + return int + with Import, Convention=>C; + + procedure Set_Default_Generate_Bnodeid_Parameters (World: in out Rasqal_World_Type_Without_Finalize'Class; + Prefix: String_Holders.Holder; + Base: int) is + use RDF.Auxiliary.C_String_Holders; + -- TODO: Do this without dynamic allocation + C_Prefix: constant chars_ptr := New_String(Prefix); + Result: constant int := + rasqal_world_set_default_generate_bnodeid_parameters(Get_Handle(World), C_Prefix, Base); + begin + RDF.Rasqal.Memory.Rasqal_Free_Memory(C_Prefix); + if Result /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + +end RDF.Rasqal.Bnode; diff --git a/ada/src/rdf-rasqal-bnode.ads b/ada/src/rdf-rasqal-bnode.ads new file mode 100644 index 000000000..b2d2416b1 --- /dev/null +++ b/ada/src/rdf-rasqal-bnode.ads @@ -0,0 +1,31 @@ +with Interfaces.C; use Interfaces.C; +with RDF.Auxiliary; use RDF.Auxiliary; +with RDF.Rasqal.World; use RDF.Rasqal.World; + +package RDF.Rasqal.Bnode is + + -- Unfortunate code duplication with RDF.Raptor.Bnode + + -- Should we derive it from Limited_Controlled? + type BNode_ID_Handler is abstract tagged limited private; + + -- We pass to the underlying C library only a handle of a world, + -- not the entire object. So it does not behave well in Ada types. + -- So I recommend not to use World argument at all. + function Do_Handle (World: Rasqal_World_Type_Without_Finalize; + Handler: BNode_ID_Handler; + User_ID: RDF.Auxiliary.String_Holders.Holder) + return String is abstract; + + procedure Set_BNode_ID_Handler (World: in out Rasqal_World_Type_Without_Finalize'Class; + Handler: access BNode_ID_Handler'Class); + + procedure Set_Default_Generate_Bnodeid_Parameters (World: in out Rasqal_World_Type_Without_Finalize'Class; + Prefix: String_Holders.Holder; + Base: int); + +private + + type BNode_ID_Handler is abstract tagged limited null record; + +end RDF.Rasqal.Bnode; diff --git a/ada/src/rdf-rasqal-constants.adb b/ada/src/rdf-rasqal-constants.adb new file mode 100644 index 000000000..602f49339 --- /dev/null +++ b/ada/src/rdf-rasqal-constants.adb @@ -0,0 +1,20 @@ +with Interfaces.C.Strings; + +package body RDF.Rasqal.Constants is + + subtype chars_ptr is Interfaces.C.Strings.chars_ptr; + function Value(Item : in chars_ptr) return String renames Interfaces.C.Strings.Value; + + rasqal_copyright_string: constant chars_ptr with Import, Convention=>C; + rasqal_home_url_string: constant chars_ptr with Import, Convention=>C; + rasqal_license_string: constant chars_ptr with Import, Convention=>C; + rasqal_short_copyright_string: constant chars_ptr with Import, Convention=>C; + rasqal_version_string: constant chars_ptr with Import, Convention=>C; + + function copyright_string return String is (Value(rasqal_copyright_string)); + function home_url_string return String is (Value(rasqal_home_url_string)); + function license_string return String is (Value(rasqal_license_string)); + function short_copyright_string return String is (Value(rasqal_short_copyright_string)); + function version_string return String is (Value(rasqal_version_string)); + +end RDF.Rasqal.Constants; diff --git a/ada/src/rdf-rasqal-constants.ads b/ada/src/rdf-rasqal-constants.ads new file mode 100644 index 000000000..6d2a29e6c --- /dev/null +++ b/ada/src/rdf-rasqal-constants.ads @@ -0,0 +1,20 @@ +with Interfaces.C; + +package RDF.Rasqal.Constants is + + version_major: constant Interfaces.C.unsigned + with Import, Convention=>C, External_Name=>"rasqal_version_major"; + version_minor: constant Interfaces.C.unsigned + with Import, Convention=>C, External_Name=>"rasqal_version_minor"; + version_release: constant Interfaces.C.unsigned + with Import, Convention=>C, External_Name=>"rasqal_version_release"; + version_decimal: constant Interfaces.C.unsigned + with Import, Convention=>C, External_Name=>"rasqal_version_decimal"; + + function copyright_string return String; + function home_url_string return String; + function license_string return String; + function short_copyright_string return String; + function version_string return String; + +end RDF.Rasqal.Constants; diff --git a/ada/src/rdf-rasqal-data_graph.adb b/ada/src/rdf-rasqal-data_graph.adb new file mode 100644 index 000000000..4428e8ac3 --- /dev/null +++ b/ada/src/rdf-rasqal-data_graph.adb @@ -0,0 +1,179 @@ +with RDF.Auxiliary.C_String_Holders; + +package body RDF.Rasqal.Data_Graph is + + function Get_World (Graph: Data_Graph_Type_Without_Finalize) + return Rasqal_World_Type_Without_Finalize is + begin + return From_Handle(Get_Handle(Graph).World); + end; + + function Get_URI (Graph: Data_Graph_Type_Without_Finalize) + return URI_Type_Without_Finalize is + begin + return From_Handle(Get_Handle(Graph).URI); + end; + + function Get_Name_URI (Graph: Data_Graph_Type_Without_Finalize) + return URI_Type_Without_Finalize is + begin + return From_Handle(Get_Handle(Graph).Name_URI); + end; + + function Get_Flags (Graph: Data_Graph_Type_Without_Finalize) return Flags_Type is + (Flags_Type'Val(Get_Handle(Graph).Flags)); + + function Get_Format_Type (Graph: Data_Graph_Type_Without_Finalize) return String is + (Value(Get_Handle(Graph).Format_Type)); + + function Get_Format_Name (Graph: Data_Graph_Type_Without_Finalize) return String is + (Value(Get_Handle(Graph).Format_Name)); + + + function Get_Format_URI (Graph: Data_Graph_Type_Without_Finalize) return URI_Type is + begin + return From_Handle(Get_Handle(Graph).Format_URI); + end; + + function Get_IOStream (Graph: Data_Graph_Type_Without_Finalize) + return IOStream_Type_Without_Finalize is + begin + return From_Handle(Get_Handle(Graph).IOStr); + end; + + function Get_Base_URI (Graph: Data_Graph_Type_Without_Finalize) return URI_Type is + begin + return From_Handle(Get_Handle(Graph).Base_URI); + end; + + function Get_Usage_Count (Graph: Data_Graph_Type_Without_Finalize) return Natural is + (Natural(Get_Handle(Graph).Usage)); + + function rasqal_new_data_graph_from_data_graph (Graph: Data_Graph_Handle) + return Data_Graph_Handle + with Import, Convention=>C; + + function Adjust_Handle (Object: Data_Graph_Type_Without_Finalize; Handle: Data_Graph_Handle) + return Data_Graph_Handle is + begin + return rasqal_new_data_graph_from_data_graph(Handle); + end; + + procedure rasqal_free_data_graph (Handle: Data_Graph_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Data_Graph_Type_Without_Finalize; Handle: Data_Graph_Handle) is + begin + rasqal_free_data_graph(Handle); + end; + + function rasqal_new_data_graph_from_iostream (World: Rasqal_World_Handle; + IOStream: IOStream_Handle; + Base_URI, Name_URI: URI_Handle; + Flags: unsigned; + Format_Type, Format_Name: chars_ptr; + Format_URI: URI_Handle) + return Data_Graph_Handle + with Import, Convention=>C; + + function From_IOStream (World: Rasqal_World_Type_Without_Finalize'Class; + IOStream: IOStream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class; + Name_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null)); + Flags: Flags_Type := Background; + Format_Type, Format_Name: RDF.Auxiliary.String_Holders.Holder := RDF.Auxiliary.String_Holders.Empty_Holder; + Format_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null))) + return Data_Graph_Type is + use RDF.Auxiliary.C_String_Holders; + -- TODO: Do this without dynamic allocation + Format_Type2: chars_ptr := New_String(Format_Type); + Format_Name2: chars_ptr := New_String(Format_Name); + Result: constant Data_Graph_Handle := + rasqal_new_data_graph_from_iostream(Get_Handle(World), + Get_Handle(IOStream), + Get_Handle(Base_URI), + Get_Handle(Name_URI), + Flags_Type'Pos(Flags), + Format_Type2, + Format_Name2, + Get_Handle(Format_URI)); + begin + Free(Format_Type2); + Free(Format_Name2); + return From_Handle(Result); + end; + + function rasqal_new_data_graph_from_uri (World: Rasqal_World_Handle; + URI, Name_URI: URI_Handle; + Flags: Unsigned; + Format_Type, Format_Name: Chars_Ptr; + Format_URI: URI_Handle) + return Data_Graph_Handle + with Import, Convention=>C; + + function From_URI (World: Rasqal_World_Type_Without_Finalize'Class; + URI, Name_URI: URI_Type_Without_Finalize'Class; + Flags: Flags_Type; + Format_Type, Format_Name: RDF.Auxiliary.String_Holders.Holder; + Format_URI: URI_Type_Without_Finalize'Class) + return Data_Graph_Type is + use RDF.Auxiliary.C_String_Holders; + -- TODO: Do this without dynamic allocation + Format_Type2: chars_ptr := New_String(Format_Type); + Format_Name2: chars_ptr := New_String(Format_Name); + Result: constant Data_Graph_Handle := + rasqal_new_data_graph_from_uri(Get_Handle(World), + Get_Handle(URI), + Get_Handle(Name_URI), + Flags_Type'Pos(Flags), + Format_Type2, + Format_Name2, + Get_Handle(Format_URI)); + begin + Free(Format_Type2); + Free(Format_Name2); + return From_Handle(Result); + end; + + -- function From_File (World: Rasqal_World_Type_Without_Finalize'Class; + -- Filename: String; + -- Base_URI: URI_Type_Without_Finalize'Class; + -- Name_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null)); + -- Flags: Flags_Type := Background; + -- Format_Type, Format_Name: RDF.Auxiliary.String_Holders.Holder := RDF.Auxiliary.String_Holders.Empty_Holder; + -- Format_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null))) + -- return Data_Graph_Type is + -- use RDF.Rasqal.World; + -- -- Stream: Stream_From_String := Open_From_String(Get_Raptor(World), Str); + -- Str: String := TODO; + -- begin + -- return From_String (World, Str, Base_URI, Name_URI, Flags, Format_Type, Format_Name, Format_URI); + -- end; + -- + -- function From_String (World: Rasqal_World_Type_Without_Finalize'Class; + -- Str: String; + -- Base_URI: URI_Type_Without_Finalize'Class; + -- Name_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null)); + -- Flags: Flags_Type := Background; + -- Format_Type, Format_Name: RDF.Auxiliary.String_Holders.Holder := RDF.Auxiliary.String_Holders.Empty_Holder; + -- Format_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null))) + -- return Data_Graph_Type is + -- use RDF.Raptor.IOStream, RDF.Rasqal.World; + -- begin + -- -- Does not work if Stream variable is destroyed: + -- -- return From_IOStream(World, Stream, Base_URI, Name_URI, Flags, Format_Type, Format_Name, Format_URI); + -- -- return From_String(World, Str, Base_URI, Name_URI, Flags, Format_Type, Format_Name, Format_URI); + -- end; + + function rasqal_data_graph_print (Graph: Data_Graph_Handle; File: RDF.Auxiliary.C_File_Access) + return int + with Import, Convention=>C; + + procedure Print (Graph: Data_Graph_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access) is + begin + if rasqal_data_graph_print(Get_Handle(Graph), File) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + +end RDF.Rasqal.Data_Graph; diff --git a/ada/src/rdf-rasqal-data_graph.ads b/ada/src/rdf-rasqal-data_graph.ads new file mode 100644 index 000000000..62d4f11c4 --- /dev/null +++ b/ada/src/rdf-rasqal-data_graph.ads @@ -0,0 +1,123 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary; +with RDF.Auxiliary.Handled_Record; +with RDF.Rasqal.World; use RDF.Rasqal.World; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; + +package RDF.Rasqal.Data_Graph is + + type Data_Graph_Record is private; + + type Data_Graph_Record_Access is access Data_Graph_Record with Convention=>C; + + package Data_Graph_Handled_Record is new RDF.Auxiliary.Handled_Record(Data_Graph_Record, Data_Graph_Record_Access); + + type Data_Graph_Type_Without_Finalize is new Data_Graph_Handled_Record.Base_Object with null record; + + subtype Data_Graph_Handle is Data_Graph_Handled_Record.Access_Type; + + overriding function Adjust_Handle (Object: Data_Graph_Type_Without_Finalize; Handle: Data_Graph_Handle) return Data_Graph_Handle; + + overriding procedure Finalize_Handle (Object: Data_Graph_Type_Without_Finalize; Handle: Data_Graph_Handle); + + function Get_World (Graph: Data_Graph_Type_Without_Finalize) + return Rasqal_World_Type_Without_Finalize; + + function Get_URI (Graph: Data_Graph_Type_Without_Finalize) return URI_Type_Without_Finalize; + + function Get_Name_URI (Graph: Data_Graph_Type_Without_Finalize) + return URI_Type_Without_Finalize; + + type Flags_Type is (None, -- unused + Named, + Background) + with Convention=>C; + + function Get_Flags (Graph: Data_Graph_Type_Without_Finalize) return Flags_Type; + + function Get_Format_Type (Graph: Data_Graph_Type_Without_Finalize) return String; + + function Get_Format_Name (Graph: Data_Graph_Type_Without_Finalize) return String; + + function Get_Format_URI (Graph: Data_Graph_Type_Without_Finalize) return URI_Type; + + function Get_IOStream (Graph: Data_Graph_Type_Without_Finalize) return IOStream_Type_Without_Finalize; + + function Get_Base_URI (Graph: Data_Graph_Type_Without_Finalize) return URI_Type; + + function Get_Usage_Count (Graph: Data_Graph_Type_Without_Finalize) return Natural; + +-- not overriding function Copy (Object: Data_Graph_Type_Without_Finalize'Class) +-- return Data_Graph_Type_Without_Finalize; + + not overriding procedure Print (Graph: Data_Graph_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access); + + package Handlers is new Data_Graph_Handled_Record.Common_Handlers(Data_Graph_Type_Without_Finalize); + + type Data_Graph_Type is new Handlers.Base_With_Finalization with null record; + + type Data_Graph_Type_User is new Handlers.User_Type with null record; + + -- FIXME: URI_Type' vs URI_Type_Without_Finalize' + not overriding function From_IOStream (World: Rasqal_World_Type_Without_Finalize'Class; + IOStream: IOStream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class; + Name_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null)); + Flags: Flags_Type := Background; + Format_Type, Format_Name: RDF.Auxiliary.String_Holders.Holder := RDF.Auxiliary.String_Holders.Empty_Holder; + Format_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null))) + return Data_Graph_Type; + + not overriding function From_URI (World: Rasqal_World_Type_Without_Finalize'Class; + URI, Name_URI: URI_Type_Without_Finalize'Class; + Flags: Flags_Type; + Format_Type, Format_Name: RDF.Auxiliary.String_Holders.Holder; + Format_URI: URI_Type_Without_Finalize'Class) + return Data_Graph_Type; + + -- type Streamed_Data_Graph_Type is new Data_Graph_Type with private; + + -- -- Not binding, but a wrapper + -- not overriding function From_File (World: Rasqal_World_Type_Without_Finalize'Class; + -- Filename: String; + -- Base_URI: URI_Type_Without_Finalize'Class; + -- Name_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null)); + -- Flags: Flags_Type := Background; + -- Format_Type, Format_Name: RDF.Auxiliary.String_Holders.Holder := RDF.Auxiliary.String_Holders.Empty_Holder; + -- Format_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null))) + -- return Streamed_Data_Graph_Type; + -- + -- -- Not binding, but a wrapper + -- not overriding function From_String (World: Rasqal_World_Type_Without_Finalize'Class; + -- Str: String; + -- Base_URI: URI_Type_Without_Finalize'Class; + -- Name_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null)); + -- Flags: Flags_Type := Background; + -- Format_Type, Format_Name: RDF.Auxiliary.String_Holders.Holder := RDF.Auxiliary.String_Holders.Empty_Holder; + -- Format_URI: URI_Type_Without_Finalize'Class := URI_Type'(From_Handle(null))) + -- return Streamed_Data_Graph_Type; + +private + + type Data_Graph_Record is + record + World: Rasqal_World_Handle; + URI, Name_URI: URI_Handle; + Flags: unsigned; + Format_Type, Format_Name: chars_ptr; + Format_URI: URI_Handle; + IOStr: IOStream_Handle; + Base_URI: URI_Handle; + Usage: int; + end record + with Convention=>C; + + -- type Streamed_Data_Graph_Type is new Data_Graph_Type with + -- record + -- Stream: Base_Stream_Type'Class; + -- end record; + +end RDF.Rasqal.Data_Graph; diff --git a/ada/src/rdf-rasqal-features.adb b/ada/src/rdf-rasqal-features.adb new file mode 100644 index 000000000..4a20ff81e --- /dev/null +++ b/ada/src/rdf-rasqal-features.adb @@ -0,0 +1,110 @@ +with Ada.Unchecked_Conversion; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary; +with RDF.Raptor.World; use RDF.Raptor.World; + +package body RDF.Rasqal.Features is + + function rasqal_feature_from_uri (World: Rasqal_World_Handle; URI: URI_Handle) return Feature_Type + with Import, Convention=>C; + + function Feature_From_URI (World: Rasqal_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class) + return Feature_Type is + Value: constant Feature_Type := rasqal_feature_from_uri(Get_Handle(World), Get_Handle(URI)); + begin + return (if Value'Valid then Value else Unknown); + end; + + function rasqal_feature_value_type (Feature: Feature_Type) return int + with Import, Convention=>C; + + function Get_Type (Feature: Feature_Type) return Feature_Value_Type is + Value_Type: constant int := rasqal_feature_value_type(Feature); + begin + if Value_Type = 0 then + return Integer_Type; + elsif Value_Type = 1 then + return String_Type; + else + return Other; + end if; + end; + + type String_P_Type is access all chars_ptr with Convention=>C; + type URI_P_Type is access all URI_Handle with Convention=>C; + + function rasqal_features_enumerate (World: Raptor_World_Handle; + Feature: Feature_Type; + Name: String_P_Type; + URI: URI_P_Type; + Label: String_P_Type) + return Int + with Import, Convention=>C; + + function Get_Feature_Description (World: Rasqal_World_Type_Without_Finalize'Class; + Feature: Feature_Type) + return Feature_Description is + Name, Label: aliased chars_ptr; + URI: aliased URI_Handle; + begin + if rasqal_features_enumerate(Get_Handle(World), + Feature, + Name'Unchecked_Access, + URI'Unchecked_Access, + Label'Unchecked_Access) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Name2 : constant String := Value(Name ); + Label2: constant String := Value(Label); + begin + return (Name_Length => Name2'Length, + Label_Length => Label2'Length, + Name => Name2, + Label => Label2, + URI => From_Non_Null_Handle(URI)); + end; + end; + + function rasqal_get_feature_count return unsigned + with Import, Convention=>C; + + function Get_Feature_Count return unsigned is (Rasqal_Get_Feature_Count); + + type C_Features_Enum is range -(2**(Feature_Type'Size-1)) .. (2**(Feature_Type'Size-1))-1 + with Size => Feature_Type'Size, Convention => C; + + function Conv is new Ada.Unchecked_Conversion(C_Features_Enum, Feature_Type); + function Conv is new Ada.Unchecked_Conversion(Feature_Type, C_Features_Enum); + + function Get_Position (Cursor: Features_Cursor) return Feature_Type is (Cursor.Position); + + function Get_Description (Cursor: Features_Cursor) return Feature_Description is + begin + return Get_Feature_Description(Rasqal_World_Type_Without_Finalize'(From_Handle(Cursor.World)), Cursor.Position); + end; + + function Has_Element (Position: Features_Cursor) return Boolean is + begin + return Conv(Position.Position) < C_Features_Enum(Get_Feature_Count); + end; + + function First (Object: Features_Iterator) return Features_Cursor is + begin + return Features_Cursor'(World=>Object.World, Position=>Conv(0)); + end; + + function Next (Object: Features_Iterator; Position: Features_Cursor) return Features_Cursor is + begin + return (World=>Object.World, Position=>Conv(Conv(Position.Position) + 1)); + end; + + function Create_Features_Descriptions_Iterator(World: Rasqal_World_Type_Without_Finalize'Class) + return Features_Iterator is + begin + return Features_Iterator'(World => Get_Handle(World)); + end; + +end RDF.Rasqal.Features; diff --git a/ada/src/rdf-rasqal-features.ads b/ada/src/rdf-rasqal-features.ads new file mode 100644 index 000000000..7410b1079 --- /dev/null +++ b/ada/src/rdf-rasqal-features.ads @@ -0,0 +1,69 @@ +with Ada.Iterator_Interfaces; +with Interfaces.C; use Interfaces.C; +with RDF.Rasqal.World; use RDF.Rasqal.World; +with RDF.Raptor.URI; use RDF.Raptor.URI; + +package RDF.Rasqal.Features is + + type Feature_Type is (Unknown, No_Net, Rand_Seed) + with Convention=>C; + for Feature_Type use (Unknown=>-1, No_Net=>0, Rand_Seed=>1); + + function Feature_From_URI (World: Rasqal_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class) + return Feature_Type; + + type Feature_Value_Type is (Other, Integer_Type, String_Type) + with Convention=>C; + for Feature_Value_Type use (Other=>-1, Integer_Type=>0, String_Type=>1); + + function Get_Type (Feature: Feature_Type) return Feature_Value_Type; + + type Feature_Description (Name_Length, Label_Length: Natural) is + record + Name: String(1..Name_Length); + Label: String(1..Label_Length); + URI: URI_Type; -- with finalize + end record; + + -- For API simplicity, I don't support the C library feature to retrieve only a part of the data. + -- For API simplicity, we do not differentiate between failure and unknown feature. + function Get_Feature_Description (World: Rasqal_World_Type_Without_Finalize'Class; + Feature: Feature_Type) + return Feature_Description; + + function Get_Feature_Count return unsigned; + + type Features_Cursor is private; + + function Get_Position (Cursor: Features_Cursor) return Feature_Type; + + function Get_Description (Cursor: Features_Cursor) return Feature_Description; + + function Has_Element (Position: Features_Cursor) return Boolean; + + package Features_Iterators is new Ada.Iterator_Interfaces(Features_Cursor, Has_Element); + + type Features_Iterator is new Features_Iterators.Forward_Iterator with private; + + overriding function First (Object: Features_Iterator) return Features_Cursor; + overriding function Next (Object: Features_Iterator; Position: Features_Cursor) + return Features_Cursor; + + not overriding function Create_Features_Descriptions_Iterator(World: Rasqal_World_Type_Without_Finalize'Class) + return Features_Iterator; + +private + + type Features_Cursor is + record + World: Rasqal_World_Handle; + Position: Feature_Type; + end record; + + type Features_Iterator is new Features_Iterators.Forward_Iterator with + record + World: Rasqal_World_Handle; + end record; + +end RDF.Rasqal.Features; diff --git a/ada/src/rdf-rasqal-literal.adb b/ada/src/rdf-rasqal-literal.adb new file mode 100644 index 000000000..13df0cacf --- /dev/null +++ b/ada/src/rdf-rasqal-literal.adb @@ -0,0 +1,293 @@ +with Ada.Unchecked_Conversion; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.C_String_Holders; use RDF.Auxiliary.C_String_Holders; +with RDF.Auxiliary.C_Pointers; +with RDF.Auxiliary.Convert; + +package body RDF.Rasqal.Literal is + + function rasqal_new_typed_literal (World: Rasqal_World_Handle; + Type_Of_Literal: Literal_Type_Enum; + Value: char_array) + return Literal_Handle + with Import, Convention=>C; + + + function New_Typed_Literal (World: Rasqal_World_Type_Without_Finalize'Class; + Type_Of_Literal: Literal_Type_Enum; + Value: String) + return Literal_Type is + Handle: constant Literal_Handle := + rasqal_new_typed_literal(Get_Handle(World), Type_Of_Literal, To_C(Value)); + begin + return From_Non_Null_Handle(Handle); + end; + + function rasqal_new_boolean_literal (World: Rasqal_World_Handle; + Value: int) + return Literal_Handle + with Import, Convention=>C; + + function From_Boolean (World: Rasqal_World_Type_Without_Finalize'Class; + Value: Boolean) + return Literal_Type is + begin + return From_Non_Null_Handle(rasqal_new_boolean_literal(Get_Handle(World), Boolean'Pos(Value))); + end; + + function rasqal_new_decimal_literal (World: Rasqal_World_Handle; + Value: char_array) + return Literal_Handle + with Import, Convention=>C; + + function From_Decimal (World: Rasqal_World_Type_Without_Finalize'Class; + Value: String) + return Literal_Type is + begin + return From_Non_Null_Handle(rasqal_new_decimal_literal(Get_Handle(World), To_C(Value))); + end; + + function rasqal_new_double_literal (World: Rasqal_World_Handle; Value: double) + return Literal_Handle + with Import, Convention=>C; + + function rasqal_new_floating_literal (World: Rasqal_World_Handle; Kind: Literal_Type_Enum; Value: double) + return Literal_Handle + with Import, Convention=>C; + + function From_Float (World: Rasqal_World_Type_Without_Finalize'Class; + Value: Float) + return Literal_Type is + begin + return From_Non_Null_Handle(rasqal_new_floating_literal(Get_Handle(World), Literal_Float, double(Value))); + end; + + function From_Float (World: Rasqal_World_Type_Without_Finalize'Class; + Value: Long_Float) + return Literal_Type is + begin + return From_Non_Null_Handle(rasqal_new_floating_literal(Get_Handle(World), Literal_Float, double(Value))); + end; + + function From_Long_Float (World: Rasqal_World_Type_Without_Finalize'Class; + Value: Long_Float) + return Literal_Type is + begin + return From_Non_Null_Handle(rasqal_new_double_literal(Get_Handle(World), double(Value))); + end; + + function rasqal_new_numeric_literal_from_long (World: Rasqal_World_Handle; + Kind: Literal_Type_Enum; + Value: Long) + return Literal_Handle + with Import, Convention=>C; + + function From_Integer (World: Rasqal_World_Type_Without_Finalize'Class; Value: long) + return Literal_Type is + begin + return From_Non_Null_Handle(rasqal_new_numeric_literal_from_long(Get_Handle(World), Literal_Integer, Value)); + end; + + function rasqal_new_simple_literal (World: Rasqal_World_Handle; + Kind: Literal_Type_Enum_Simple; + Value: chars_ptr) + return Literal_Handle + with Import, Convention=>C; + + function New_Simple_Literal (World: Rasqal_World_Type_Without_Finalize'Class; + Kind: Literal_Type_Enum_Simple; + Value: String) + return Literal_Type is + Value2: constant chars_ptr := New_String(Value); -- freed by rasqal_new_simple_literal + begin + return From_Non_Null_Handle(rasqal_new_simple_literal(Get_Handle(World), Kind, Value2)); + end; + + function rasqal_new_string_literal (World: Rasqal_World_Handle; + Value: chars_ptr; + Language: chars_ptr; + Datatype: URI_Handle; + Datatype_Qname: chars_ptr) + return Literal_Handle + with Import, Convention=>C; + + function New_String_Literal (World: Rasqal_World_Type_Without_Finalize'Class; + Value: String; + Language: RDF.Auxiliary.String_Holders.Holder; + Datatype: URI_Type_Without_Finalize'Class) + return Literal_Type is + Handle: constant Literal_Handle := + rasqal_new_string_literal(Get_Handle(World), + New_String(Value), + New_String(Language), + Get_Handle(Datatype), + Null_Ptr); + begin + return From_Non_Null_Handle(Handle); + end; + + function New_String_Literal (World: Rasqal_World_Type_Without_Finalize'Class; + Value: String; + Language: RDF.Auxiliary.String_Holders.Holder; + Datatype_Qname: String) + return Literal_Type is + Handle: constant Literal_Handle := + rasqal_new_string_literal(Get_Handle(World), + New_String(Value), + New_String(Language), + null, + New_String(Datatype_Qname)); + begin + return From_Non_Null_Handle(Handle); + end; + + function New_String_Literal (World: Rasqal_World_Type_Without_Finalize'Class; + Value: String; + Language: RDF.Auxiliary.String_Holders.Holder := Empty_Holder) + return Literal_Type is + begin + return From_Non_Null_Handle(rasqal_new_string_literal( + Get_Handle(World), + New_String(Value), + New_String(Language), + null, + Null_Ptr)); + end; + + function rasqal_new_uri_literal (World: Rasqal_World_Handle; + Value: URI_Handle) + return Literal_Handle + with Import, Convention=>C; + + function From_URI (World: Rasqal_World_Type_Without_Finalize'Class; + Value: URI_Type_Without_Finalize) + return Literal_Type is + begin + return From_Non_Null_Handle(rasqal_new_uri_literal(Get_Handle(World), Get_Handle(Value))); + end; + + function rasqal_literal_same_term (Left, Right: Literal_Handle) return int + with Import, Convention=>C; + + function "=" (Left, Right: Literal_Type_Without_Finalize) return Boolean is + (rasqal_literal_same_term(Get_Handle(Left), Get_Handle(Right)) /= 0); + + procedure rasqal_free_literal (Handle: Literal_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Literal_Type_Without_Finalize; Handle: Literal_Handle) is + begin + rasqal_free_literal(Handle); + end; + + function rasqal_literal_as_node (Literal: Literal_Handle) return Literal_Handle + with Import, Convention=>C; + + function As_Node (Literal: Literal_Type_Without_Finalize'Class) return Literal_Type is + (From_Handle(rasqal_literal_as_node(Get_Handle(Literal)))); + + type Size_T_P is access all size_t with Convention=>C; + type Int_P is access all int with Convention=>C; + + function rasqal_literal_as_counted_string (Literal: Literal_Handle; + Len_P: Size_T_P; + Flags: int; + Error_P: Int_P) + return RDF.Auxiliary.C_Pointers.Pointer + with Import, Convention=>C; + + function As_String (Literal: Literal_Type_Without_Finalize; Flags: Compare_Flags := Compare_None) + return String is + Error: aliased Int := 0; + Length: aliased size_t; + Item: constant RDF.Auxiliary.C_Pointers.Pointer := + rasqal_literal_as_counted_string(Get_Handle(Literal), + Length'Unchecked_Access, + int(Flags), + Error'Unchecked_Access); + use RDF.Auxiliary.Convert; + begin + if Error /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Value_With_Possible_NULs(Item, Length); + end; + + function rasqal_literal_compare (Left, Right: Literal_Handle; Flags: int; Error_P: Int_P) + return int + with Import, Convention=>C; + + function Compare (Left, Right: Literal_Type_Without_Finalize; Flags: Compare_Flags) + return RDF.Auxiliary.Comparison_Result is + Error: aliased Int := 0; + begin + return Sign(rasqal_literal_compare(Get_Handle(Left), Get_Handle(Right), int(Flags), Error'Unchecked_Access)); + end; + + function rasqal_literal_datatype (Literal: Literal_Handle) return URI_Handle + with Import, Convention=>C; + + function Get_Datatype (Literal: Literal_Type_Without_Finalize) + return URI_Type_Without_Finalize is + begin + return From_Handle(rasqal_literal_datatype(Get_Handle(Literal))); + end; + + -- Not supported as of Rasqal 0.9.32 + -- function rasqal_literal_get_language (Literal: Literal_Handle) return Chars_Ptr + -- with Import, Convention=>C; + -- + -- function Get_Language (Literal: Literal_Type_Without_Finalize) return String_Holders.Holder is + -- begin + -- return New_Holder(rasqal_literal_get_language(Get_Handle(Literal))); + -- end; + + function rasqal_literal_get_rdf_term_type (Literal: Literal_Handle) return Literal_Type_Enum + with Import, Convention=>C; + + -- function rasqal_literal_get_type (Literal: Literal_Handle) return Literal_Type_Enum + -- with Import, Convention=>C; + + function Get_Rdf_Term_Type (Literal: Literal_Type_Without_Finalize) return Literal_Type_Enum is + (rasqal_literal_get_rdf_term_type(Get_Handle(Literal))); + + -- function Get_Type (Literal: Literal_Type_Without_Finalize) return Literal_Type_Enum is + -- (rasqal_literal_get_type(Get_Handle(Literal))); + + function rasqal_literal_is_rdf_literal (Literal: Literal_Handle) return int + with Import, Convention=>C; + + function Is_Rdf_Literal (Literal: Literal_Type_Without_Finalize) return Boolean is + (rasqal_literal_is_rdf_literal(Get_Handle(Literal)) /= 0); + + function rasqal_literal_print (Literal: Literal_Handle; File: RDF.Auxiliary.C_File_Access) return int + with Import, Convention=>C; + + procedure Print (Literal: Literal_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access) is + begin + if rasqal_literal_print (Get_Handle(Literal), File) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + procedure rasqal_literal_print_type (Literal: Literal_Handle; File: RDF.Auxiliary.C_File_Access) + with Import, Convention=>C; + + procedure Print_Type (Literal: Literal_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access) is + begin + rasqal_literal_print_type (Get_Handle(Literal), File); + end; + + function rasqal_literal_type_label (Kind: Literal_Type_Enum) return chars_ptr + with Import, Convention=>C; + + function Type_Label (Kind: Literal_Type_Enum) return String is + (Value(rasqal_literal_type_label(Kind))); + + function rasqal_literal_value (Literal: Literal_Handle) return Literal_Handle + with Import, Convention=>C; + + function Value (Literal: Literal_Type_Without_Finalize'Class) return Literal_Type is + (From_Handle(rasqal_literal_value(Get_Handle(Literal)))); + +end RDF.Rasqal.Literal; diff --git a/ada/src/rdf-rasqal-literal.ads b/ada/src/rdf-rasqal-literal.ads new file mode 100644 index 000000000..70f715a44 --- /dev/null +++ b/ada/src/rdf-rasqal-literal.ads @@ -0,0 +1,164 @@ +with Interfaces.C; use Interfaces.C; +with RDF.Auxiliary.Handled_Record; +with RDF.Rasqal.World; use RDF.Rasqal.World; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Auxiliary; use RDF.Auxiliary; +use RDF.Auxiliary.String_Holders; + +package RDF.Rasqal.Literal is + + package Literal_Handled_Record is new RDF.Auxiliary.Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + subtype Literal_Handle is Literal_Handled_Record.Access_Type; + + type Literal_Type_Without_Finalize is new Literal_Handled_Record.Base_Object with null record; + + overriding procedure Finalize_Handle (Object: Literal_Type_Without_Finalize; Handle: Literal_Handle); + + type Literal_Type_Enum is (Literal_Unknown, -- internal + Literal_Blank, + Literal_URI, + Literal_String, + Literal_Xsd_String, + Literal_Boolean, + Literal_Integer, + Literal_Float, + Literal_Double, + Literal_Decimal, + Literal_Datetime, + Literal_Udt, + Literal_Pattern, + Literal_Qname, + Literal_Variable, + Literal_Date); + + subtype Literal_Type_Enum_Simple is Literal_Type_Enum + with Static_Predicate => Literal_Type_Enum_Simple in Literal_Blank | Literal_Qname; + + overriding function "=" (Left, Right: Literal_Type_Without_Finalize) return Boolean; + + type Compare_Flags is mod 256; -- the number may change in a future version + + Compare_None: constant Compare_Flags := 0; + Compare_Nocase: constant Compare_Flags := 1; + Compare_XQuery: constant Compare_Flags := 2; + Compare_RDF: constant Compare_Flags := 4; + Compare_URI: constant Compare_Flags := 8; + Compare_Sameterm: constant Compare_Flags := 16; + + not overriding function As_String (Literal: Literal_Type_Without_Finalize; + Flags: Compare_Flags := Compare_None) + return String; + + not overriding function Compare (Left, Right: Literal_Type_Without_Finalize; + Flags: Compare_Flags) + return RDF.Auxiliary.Comparison_Result; + + not overriding function Get_Datatype (Literal: Literal_Type_Without_Finalize) + return URI_Type_Without_Finalize; + + -- Not supported as of Rasqal 0.9.32 + -- not overriding function Get_Language (Literal: Literal_Type_Without_Finalize) return String_Holders.Holder; + + not overriding function Get_Rdf_Term_Type (Literal: Literal_Type_Without_Finalize) + return Literal_Type_Enum; + + -- Not supported as of Rasqal 0.9.32 + -- not overriding function Get_Type (Literal: Literal_Type_Without_Finalize) return Literal_Type_Enum; + + not overriding function Is_Rdf_Literal (Literal: Literal_Type_Without_Finalize) return Boolean; + + not overriding procedure Print (Literal: Literal_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access); + + not overriding procedure Print_Type (Literal: Literal_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access); + + not overriding function Type_Label (Kind: Literal_Type_Enum) return String; + + package Handlers is new Literal_Handled_Record.Common_Handlers(Literal_Type_Without_Finalize); + + type Literal_Type is new Handlers.Base_With_Finalization with null record; + + type Literal_Type_User is new Handlers.User_Type with null record; + + not overriding function New_Typed_Literal (World: Rasqal_World_Type_Without_Finalize'Class; + Type_Of_Literal: Literal_Type_Enum; + Value: String) + return Literal_Type; + + not overriding function From_Boolean (World: Rasqal_World_Type_Without_Finalize'Class; + Value: Boolean) + return Literal_Type; + + -- Not implemented + -- not overriding function From_Datetime (World: Rasqal_World_Type_Without_Finalize; + -- Value: XSD_Datetime) + -- return Literal_Type; + + not overriding function From_Decimal (World: Rasqal_World_Type_Without_Finalize'Class; + Value: String) + return Literal_Type; + + -- Not implemented + -- not overriding function From_Decimal (World: Rasqal_World_Type_Without_Finalize; + -- Value: XSD_Decimal) + -- return Literal_Type; + + -- From_Float API is experimental + + not overriding function From_Float (World: Rasqal_World_Type_Without_Finalize'Class; + Value: Float) + return Literal_Type; + + -- WARNING: This takes a Long_Float value but silently rounds it to Float + not overriding function From_Float (World: Rasqal_World_Type_Without_Finalize'Class; + Value: Long_Float) + return Literal_Type; + + not overriding function From_Long_Float (World: Rasqal_World_Type_Without_Finalize'Class; + Value: Long_Float) + return Literal_Type; + + -- Deliberately accept only long integers, don't implement "Value: int". + not overriding function From_Integer (World: Rasqal_World_Type_Without_Finalize'Class; + Value: long) + return Literal_Type; + + not overriding function New_Simple_Literal (World: Rasqal_World_Type_Without_Finalize'Class; + Kind: Literal_Type_Enum_Simple; + Value: String) + return Literal_Type; + + -- overloaded + not overriding function New_String_Literal (World: Rasqal_World_Type_Without_Finalize'Class; + Value: String; + Language: RDF.Auxiliary.String_Holders.Holder; + Datatype: URI_Type_Without_Finalize'Class) + return Literal_Type; + + not overriding function New_String_Literal (World: Rasqal_World_Type_Without_Finalize'Class; + Value: String; + Language: RDF.Auxiliary.String_Holders.Holder; + Datatype_Qname: String) + return Literal_Type; + + not overriding function New_String_Literal (World: Rasqal_World_Type_Without_Finalize'Class; + Value: String; + Language: RDF.Auxiliary.String_Holders.Holder := Empty_Holder) + return Literal_Type; + + not overriding function From_String (World: Rasqal_World_Type_Without_Finalize'Class; + Value: String) + return Literal_Type + is (New_String_Literal(World, Value)); + + not overriding function From_URI (World: Rasqal_World_Type_Without_Finalize'Class; + Value: URI_Type_Without_Finalize) + return Literal_Type; + + not overriding function Value (Literal: Literal_Type_Without_Finalize'Class) return Literal_Type; + + not overriding function As_Node (Literal: Literal_Type_Without_Finalize'Class) return Literal_Type; + +end RDF.Rasqal.Literal; diff --git a/ada/src/rdf-rasqal-memory.adb b/ada/src/rdf-rasqal-memory.adb new file mode 100644 index 000000000..2b37d7178 --- /dev/null +++ b/ada/src/rdf-rasqal-memory.adb @@ -0,0 +1,20 @@ +package body RDF.Rasqal.Memory is + + function C_Strncpy (Target, Source: Chars_Ptr; Len: size_t) return chars_ptr + with Import, Convention=>C, External_Name=>"strncpy"; + + procedure C_Strncpy (Target, Source: chars_ptr; Len: size_t) is + Dummy: chars_ptr := C_Strncpy(Target, Source, Len); + begin + null; + end; + + function Copy_C_String (Str: chars_ptr) return Chars_Ptr is + Len: constant size_t := Strlen(Str) + 1; + New_Str: constant Chars_Ptr := rasqal_alloc_memory(Len); + begin + C_Strncpy(New_Str, Str, Len); + return New_Str; + end; + +end RDF.Rasqal.Memory; diff --git a/ada/src/rdf-rasqal-memory.ads b/ada/src/rdf-rasqal-memory.ads new file mode 100644 index 000000000..de93f2f85 --- /dev/null +++ b/ada/src/rdf-rasqal-memory.ads @@ -0,0 +1,19 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; + +-- This are thin bindings +package RDF.Rasqal.Memory is + + procedure rasqal_free_memory (ptr: chars_ptr) + with Import, Convention=>C; + + function rasqal_alloc_memory (size: size_t) return chars_ptr + with Import, Convention=>C; + + function rasqal_calloc_memory (nmemb: size_t; size: size_t) return chars_ptr + with Import, Convention=>C; + + -- Missing in C code, so I implement it in Ada + function Copy_C_String (Str: chars_ptr) return chars_ptr; + +end RDF.Rasqal.Memory; diff --git a/ada/src/rdf-rasqal-query.adb b/ada/src/rdf-rasqal-query.adb new file mode 100644 index 000000000..b8ff4a029 --- /dev/null +++ b/ada/src/rdf-rasqal-query.adb @@ -0,0 +1,249 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.C_String_Holders; +with RDF.Auxiliary.C_Pointers; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; +with RDF.Rasqal.Memory; + +package body RDF.Rasqal.Query is + + function rasqal_query_add_data_graph (Query: Query_Handle; Graph: Data_Graph_Handle) + return int + with Import, Convention=>C; + + function rasqal_new_data_graph_from_data_graph (Graph: Data_Graph_Handle) + return Data_Graph_Handle + with Import, Convention=>C; + + procedure Add_Data_Graph (Query: in out Query_Type_Without_Finalize; + Graph: Data_Graph_Type_Without_Finalize'Class) is + begin + if rasqal_query_add_data_graph (Get_Handle(Query), + rasqal_new_data_graph_from_data_graph(Get_Handle(Graph))) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + procedure Add_Data_Graph_Detach (Query: in out Query_Type_Without_Finalize; + Graph: in out Data_Graph_Type) is + begin + Add_Data_Graph(Query, Detach(Graph)); + end; + + procedure Add_Data_Graphs (Query: in out Query_Type_Without_Finalize; Graphs: Data_Graphs_Array) is + begin + for Graph of Graphs loop + Add_Data_Graph(Query, Graph); + end loop; + end; + + procedure Add_Data_Graphs_Detach (Query: in out Query_Type_Without_Finalize; Graphs: in out Data_Graphs_Array) is + begin + for Graph of Graphs loop + Add_Data_Graph_Detach(Query, Graph); + end loop; + end; + + function rasqal_query_execute (Query: Query_Handle) return Query_Results_Handle + with Import, Convention=>C; + + function Execute (Query: Query_Type_Without_Finalize) return Query_Results_Type is + begin + return From_Non_Null_Handle(rasqal_query_execute(Get_Handle(Query))); + end; + + function rasqal_query_prepare (Query: Query_Handle; Query_String: char_array; Base_URI: URI_Handle) + return int + with Import, Convention=>C; + + procedure Prepare (Query: in out Query_Type_Without_Finalize; + Query_String: String; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if rasqal_query_prepare(Get_Handle(Query), To_C(Query_String), Get_Handle(Base_URI)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function rasqal_query_set_store_results (Query: Query_Handle; Store: int) return int + with Import, Convention=>C; + + procedure Set_Store_Results (Query: in out Query_Type_Without_Finalize; Store: Boolean) is + begin + if rasqal_query_set_store_results(Get_Handle(Query), (if Store then 1 else 0)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + procedure rasqal_query_set_wildcard (Query: Query_Handle; Store: int) + with Import, Convention=>C; + + procedure Set_Wildcard (Query: in out Query_Type_Without_Finalize; Wilcard: Boolean) is + begin + rasqal_query_set_wildcard(Get_Handle(Query), (if Wilcard then 1 else 0)); + end; + + function rasqal_query_write (Stream: IOStream_Handle; + Query: Query_Handle; + Format_URI, Base_URI: URI_Handle) + return Int + with Import, Convention=>C; + + procedure Write_Query (Stream: IOStream_Type_Without_Finalize'Class; + Query: Query_Type_Without_Finalize; + Format_URI, Base_URI: URI_Type_Without_Finalize'Class) is + begin + if rasqal_query_write(Get_Handle(Stream), + Get_Handle(Query), + Get_Handle(Format_URI), + Get_Handle(Base_URI)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function rasqal_query_iostream_write_escaped_counted_string (Query: Query_Handle; + Stream: IOStream_Handle; + Str: char_array; + Len: size_t) + return int + with Import, Convention=>C; + + procedure Write_Escaped_String (Query: Query_Type_Without_Finalize; + Stream: IOStream_Type_Without_Finalize'Class; + Str: String) is + begin + if rasqal_query_iostream_write_escaped_counted_string(Get_Handle(Query), + Get_Handle(Stream), + To_C(Str, Append_Nul=>False), + Str'Length) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + type Size_T_P is access all size_t with Convention=>C; + + function Rasqal_Query_Escape_Counted_String (Query: Query_Handle; + Str: char_array; + Len: size_t; + Out_Len: Size_T_P) + return RDF.Auxiliary.C_Pointers.Pointer + with Import, Convention=>C; + + function Escape_String (Query: Query_Type_Without_Finalize; Str: String) return String is + In_Str2: constant char_array := My_To_C_Without_Nul(Str); + Out_Len: aliased size_t; + Result: constant RDF.Auxiliary.C_Pointers.Pointer := + rasqal_query_escape_counted_string(Get_Handle(Query), In_Str2, Str'Length, Out_Len'Unchecked_Access); + use RDF.Auxiliary.C_Pointers; + begin + if Result = null then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Out_Str: constant String := Value_With_Possible_NULs(Result, Out_Len); + begin + RDF.Rasqal.Memory.rasqal_free_memory(Convert(Result)); + return Out_Str; + end; + end; + + function rasqal_query_set_feature (Query: Query_Handle; + Feature: Feature_Type; + Value: int) + return int + with Import, Convention=>C; + + procedure Set_Feature (Query: in out Query_Type_Without_Finalize; + Feature: Feature_Type; + Value: Natural) is + begin + if rasqal_query_set_feature(Get_Handle(Query), Feature, int(Value)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function rasqal_query_set_feature_string (Query: Query_Handle; + Feature: Feature_Type; + Value: char_array) + return int + with Import, Convention=>C; + + procedure Set_Feature (Query: in out Query_Type_Without_Finalize; + Feature: Feature_Type; + Value: String) is + begin + if rasqal_query_set_feature_string(Get_Handle(Query), Feature, To_C(Value)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function rasqal_query_get_feature (Query: Query_Handle; Feature: Feature_Type) return int + with Import, Convention=>C; + + function Get_Feature (Query: Query_Type_Without_Finalize; Feature: Feature_Type) return Natural is + Result: constant int := rasqal_query_get_feature(Get_Handle(Query), Feature); + begin + if Result < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Natural(Result); + end; + + function rasqal_query_get_feature_string (Query: Query_Handle; Feature: Feature_Type) return chars_ptr + with Import, Convention=>C; + + function Get_Feature (Query: Query_Type_Without_Finalize; Feature: Feature_Type) return String is + Result: constant chars_ptr := rasqal_query_get_feature_string(Get_Handle(Query), Feature); + begin + if Result = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Result2: constant String := Value(Result); + begin + RDF.Rasqal.Memory.rasqal_free_memory(Result); + return Result2; + end; + end; + + function rasqal_query_get_result_type (Query: Query_Handle) return Query_Results_Type_Enum + with Import, Convention=>C; + + function Get_Result_Type (Query: Query_Type_Without_Finalize) return Query_Results_Type_Enum is + Result: constant Query_Results_Type_Enum := + rasqal_query_get_result_type(Get_Handle(Query)); + begin + if Result = Results_Unknown then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Result; + end; + + function rasqal_new_query (World: Rasqal_World_Handle; Name, URI: chars_ptr) return Query_Handle + with Import, Convention=>C; + + function Create (World: Rasqal_World_Type'Class; Name, URI: RDF.Auxiliary.String_Holders.Holder) + return Query_Type is + use RDF.Auxiliary.C_String_Holders; + -- TODO: Do this without dynamic allocation + Name2: chars_ptr := New_String(Name); + URI2 : chars_ptr := New_String(URI ); + Result: constant Query_Handle := rasqal_new_query(Get_Handle(World), Name2, URI2); + begin + Free(Name2); + Free(URI2); + return From_Non_Null_Handle(Result); + end; + + procedure rasqal_free_query (Handle: Query_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Query: Query_Type_Without_Finalize; Handle: Query_Handle) is + begin + rasqal_free_query(Handle); + end; + +end RDF.Rasqal.Query; diff --git a/ada/src/rdf-rasqal-query.ads b/ada/src/rdf-rasqal-query.ads new file mode 100644 index 000000000..621f09659 --- /dev/null +++ b/ada/src/rdf-rasqal-query.ads @@ -0,0 +1,90 @@ +with RDF.Auxiliary; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; +with RDF.Rasqal.World; use RDF.Rasqal.World; +with RDF.Rasqal.Features; use RDF.Rasqal.Features; +with RDF.Rasqal.Data_Graph; use RDF.Rasqal.Data_Graph; +with RDF.Rasqal.Query_Results; use RDF.Rasqal.Query_Results; + +package RDF.Rasqal.Query is + + -- This API is partial, as I consider many C functions as internals. + + package Query_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + subtype Query_Handle is Query_Handled_Record.Access_Type; + + type Query_Type_Without_Finalize is new Query_Handled_Record.Base_Object with null record; + + overriding procedure Finalize_Handle (Query: Query_Type_Without_Finalize; Handle: Query_Handle); + + not overriding procedure Add_Data_Graph (Query: in out Query_Type_Without_Finalize; + Graph: Data_Graph_Type_Without_Finalize'Class); + + not overriding procedure Add_Data_Graph_Detach (Query: in out Query_Type_Without_Finalize; + Graph: in out Data_Graph_Type); + + type Data_Graphs_Array is array(Integer range <>) of Data_Graph_Type; + + not overriding procedure Add_Data_Graphs (Query: in out Query_Type_Without_Finalize; + Graphs: Data_Graphs_Array); + + not overriding procedure Add_Data_Graphs_Detach (Query: in out Query_Type_Without_Finalize; + Graphs: in out Data_Graphs_Array); + + not overriding function Execute (Query: Query_Type_Without_Finalize) return Query_Results_Type; + + not overriding procedure Prepare (Query: in out Query_Type_Without_Finalize; + Query_String: String; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + not overriding procedure Set_Store_Results (Query: in out Query_Type_Without_Finalize; Store: Boolean); + + not overriding procedure Set_Wildcard (Query: in out Query_Type_Without_Finalize; Wilcard: Boolean); + + not overriding procedure Write_Query (Stream: IOStream_Type_Without_Finalize'Class; + Query: Query_Type_Without_Finalize; + Format_URI, Base_URI: URI_Type_Without_Finalize'Class); + + -- Is it really useful? Maybe remove from public API? + not overriding procedure Write_Escaped_String (Query: Query_Type_Without_Finalize; + Stream: IOStream_Type_Without_Finalize'Class; + Str: String); + + not overriding function Escape_String (Query: Query_Type_Without_Finalize; Str: String) + return String; + + not overriding procedure Set_Feature (Query: in out Query_Type_Without_Finalize; + Feature: Feature_Type; + Value: Natural); + not overriding procedure Set_Feature (Query: in out Query_Type_Without_Finalize; + Feature: Feature_Type; + Value: String); + + not overriding function Get_Feature (Query: Query_Type_Without_Finalize; Feature: Feature_Type) + return Natural; + + -- Currently it raises an exception, if there is no such feature. Is it correct? + not overriding function Get_Feature (Query: Query_Type_Without_Finalize; Feature: Feature_Type) + return String; + + not overriding function Get_Result_Type (Query: Query_Type_Without_Finalize) + return Query_Results_Type_Enum; + + -- Deliberately not implemented + -- function Get_Update_Operation; + -- function Get_Update_Operations_Sequence; + + package Handlers is new Query_Handled_Record.Common_Handlers(Query_Type_Without_Finalize); + + type Query_Type is new Handlers.Base_With_Finalization with null record; + + type Query_Type_User is new Handlers.User_Type with null record; + + -- FIXME: Rasqal_World_Type_Without_Finalize + not overriding function Create (World: Rasqal_World_Type'Class; + Name, URI: RDF.Auxiliary.String_Holders.Holder) + return Query_Type; + +end RDF.Rasqal.Query; diff --git a/ada/src/rdf-rasqal-query_results.adb b/ada/src/rdf-rasqal-query_results.adb new file mode 100644 index 000000000..dce75bcf5 --- /dev/null +++ b/ada/src/rdf-rasqal-query_results.adb @@ -0,0 +1,354 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Rasqal.Query; use RDF.Rasqal.Query; + +package body RDF.Rasqal.Query_Results is + + function rasqal_query_results_finished (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Finished (Results: Query_Results_Type_Without_Finalize) return Boolean is + (rasqal_query_results_finished(Get_Handle(Results)) /= 0); + + function rasqal_query_results_get_binding_name (Results: Query_Results_Handle; + Offset: int) + return chars_ptr + with Import, Convention=>C; + + function Get_Binding_Name (Results: Bindings_Query_Results_Type_Without_Finalize'Class; + Offset: Natural) + return String is + Ptr: constant chars_ptr := rasqal_query_results_get_binding_name(Get_Handle(Results), int(Offset)); + begin + if Ptr = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Value(Ptr); + end; + + function rasqal_query_results_get_binding_value (Results: Query_Results_Handle; + Offset: int) + return Literal_Handle + with Import, Convention=>C; + + function Get_Binding_Value (Results: Query_Results_Type_Without_Finalize'Class; + Offset: Natural) + return Literal_Type_Without_Finalize is + begin + return From_Non_Null_Handle(rasqal_query_results_get_binding_value(Get_Handle(Results), int(Offset))); + end; + + function rasqal_query_results_get_binding_value_by_name (Results: Query_Results_Handle; + Name: char_array) + return Literal_Handle + with Import, Convention=>C; + + function Get_Binding_Value_By_Name (Results: Query_Results_Type_Without_Finalize'Class; + Name: String) + return Literal_Type_Without_Finalize is + begin + return From_Non_Null_Handle(rasqal_query_results_get_binding_value_by_name(Get_Handle(Results), To_C(Name))); + end; + + function rasqal_query_results_get_bindings_count (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Get_Bindings_Count (Results: Bindings_Query_Results_Type_Without_Finalize'Class) return Natural is + Count: constant int := rasqal_query_results_get_bindings_count(Get_Handle(Results)); + begin + if Count < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Positive(Count); + end; + + function rasqal_query_results_get_boolean (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Get_Boolean (Results: Boolean_Query_Results_Type_Without_Finalize'Class) return Boolean is + Value: constant int := rasqal_query_results_get_boolean(Get_Handle(Results)); + begin + if Value < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Value /= 0; + end; + + function rasqal_query_results_get_count (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Get_Current_Count (Results: Query_Results_Type_Without_Finalize) return Natural is + Value: constant int := rasqal_query_results_get_count(Get_Handle(Results)); + begin + if Value < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Natural(Value); + end; + + function rasqal_query_results_get_query (Results: Query_Results_Handle) + return RDF.Rasqal.Query.Query_Handle + with Import, Convention=>C; + + function Get_Query (Results: Query_Results_Type_Without_Finalize) + return RDF.Rasqal.Query.Query_Type_Without_Finalize is + begin + return From_Non_Null_Handle(rasqal_query_results_get_query(Get_Handle(Results))); + end; + + function rasqal_query_results_get_triple (Results: Query_Results_Handle) + return Statement_Handle + with Import, Convention=>C; + + function Get_Triple (Results: Graph_Query_Results_Type_Without_Finalize'Class) + return Statement_Type_Without_Finalize is + begin + return From_Non_Null_Handle(rasqal_query_results_get_triple(Get_Handle(Results))); + end; + + function rasqal_query_results_get_type (Results: Query_Results_Handle) return Query_Results_Type_Enum + with Import, Convention=>C; + + function Get_Type (Results: Query_Results_Type_Without_Finalize) return Query_Results_Type_Enum is + begin + return rasqal_query_results_get_type(Get_Handle(Results)); + end; + + function rasqal_query_results_is_bindings (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Is_Bindings (Results: Query_Results_Type_Without_Finalize) return Boolean is + (rasqal_query_results_is_bindings(Get_Handle(Results)) /= 0); + + function rasqal_query_results_is_boolean (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Is_Boolean (Results: Query_Results_Type_Without_Finalize) return Boolean is + (rasqal_query_results_is_boolean(Get_Handle(Results)) /= 0); + + function rasqal_query_results_is_graph (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Is_Graph (Results: Query_Results_Type_Without_Finalize) return Boolean is + (rasqal_query_results_is_graph(Get_Handle(Results)) /= 0); + + function rasqal_query_results_is_syntax (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Is_Syntax (Results: Query_Results_Type_Without_Finalize) return Boolean is + (rasqal_query_results_is_syntax(Get_Handle(Results)) /= 0); + + function rasqal_query_results_next (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + procedure Next (Results: Bindings_Query_Results_Type_Without_Finalize'Class) is + begin + if rasqal_query_results_next(Get_Handle(Results)) /= 0 then + -- Check is done by Finished procedure, not here + null; -- raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function rasqal_query_results_next_triple (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + procedure Next_Triple (Results: Graph_Query_Results_Type_Without_Finalize'Class) is + begin + if rasqal_query_results_next_triple(Get_Handle(Results)) /= 0 then + -- Check is done by Finished procedure, not here + null; -- raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function rasqal_query_results_read (Stream: IOStream_Handle; + Results: Query_Results_Handle; + Name, Mime_Type: chars_ptr; + Format_URI, Base_URI: URI_Handle) + return Int + with Import, Convention=>C; + + procedure Read (Stream: IOStream_Type_Without_Finalize'Class; + Results: Query_Results_Type_Without_Finalize; + Format_Name: String; -- "" for no format name + Mime_Type: String; -- "" for no MIME type + Format_URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class) is + Format_Name2: aliased char_array := To_C(Format_Name); + Mime_Type2 : aliased char_array := To_C(Mime_Type); + begin + if rasqal_query_results_read(Get_Handle(Stream), + Get_Handle(Results), + (if Format_Name = "" then Null_Ptr else To_Chars_Ptr(Format_Name2'Unchecked_Access)), + (if Mime_Type = "" then Null_Ptr else To_Chars_Ptr(Mime_Type2'Unchecked_Access)), + Get_Handle(Format_URI), + Get_Handle(Base_URI)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function rasqal_query_results_write (Stream: IOStream_Handle; + Results: Query_Results_Handle; + Name, Mime_Type: Chars_Ptr; + Format_URI, Base_URI: URI_Handle) + return Int + with Import, Convention=>C; + + procedure Write (Stream: IOStream_Type_Without_Finalize'Class; + Results: Query_Results_Type_Without_Finalize; + Format_Name: String; -- "" for no format name + Mime_Type: String; -- "" for no MIME type + Format_URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class) is + Format_Name2: aliased char_array := To_C(Format_Name); + Mime_Type2 : aliased char_array := To_C(Mime_Type); + begin + if rasqal_query_results_write(Get_Handle(Stream), + Get_Handle(Results), + (if Format_Name = "" then Null_Ptr else To_Chars_Ptr(Format_Name2'Unchecked_Access)), + (if Mime_Type = "" then Null_Ptr else To_Chars_Ptr(Mime_Type2'Unchecked_Access)), + Get_Handle(Format_URI), + Get_Handle(Base_URI)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function rasqal_query_results_type_label (Kind: Query_Results_Type_Enum) return Chars_Ptr + with Import, Convention=>C; + + function Type_Label (Kind: Query_Results_Type_Enum) return String is + Ptr: constant chars_ptr := rasqal_query_results_type_label(Kind); + begin + if Ptr = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Value(Ptr); + end; + + function rasqal_query_results_rewind (Results: Query_Results_Handle) return Int + with Import, Convention=>C; + + procedure Rewind (Results: in out Query_Results_Type_Without_Finalize) is + begin + if rasqal_query_results_rewind(Get_Handle(Results)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + procedure rasqal_free_query_results (Handle: Query_Results_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Query_Results_Type_Without_Finalize; Handle: Query_Results_Handle) is + begin + rasqal_free_query_results(Handle); + end; + + -- Not supported as of Rasqal 0.9.32 + -- function rasqal_new_query_results2 (World: Rasqal_World_Handle; + -- Query: RDF.Rasqal.Query.Query_Handle; + -- Kind: Query_Results_Type_Enum) + -- return Query_Results_Handle + -- with Import, Convention=>C; + -- + -- function Create (World: Rasqal_World_Type_Without_Finalize'Class; + -- Query: RDF.Rasqal.Query.Query_Type_Without_Finalize'Class; + -- Kind: Query_Results_Type_Enum) + -- return Query_Results_Type is + -- begin + -- return From_Non_Null_Handle(rasqal_new_query_results2(Get_Handle(World), Get_Handle(Query), Kind)); + -- end; + + function rasqal_new_query_results (World: Rasqal_World_Handle; + Query: RDF.Rasqal.Query.Query_Handle; + Kind: Query_Results_Type_Enum; + Vars_Table: RDF.Auxiliary.Dummy_Record_Access) + return Query_Results_Handle + with Import, Convention=>C; + + function Create (World: Rasqal_World_Type_Without_Finalize'Class; + Query: RDF.Rasqal.Query.Query_Type_Without_Finalize; + Kind: Query_Results_Type_Enum) + return Query_Results_Type is + begin + return From_Non_Null_Handle(rasqal_new_query_results(Get_Handle(World), Get_Handle(Query), Kind, null)); + end; + + -- function rasqal_new_query_results_from_string (World: Rasqal_World_Handle; + -- Kind: Query_Results_Type_Enum; + -- Base_URI: Handle_Type; + -- Value: char_array; + -- Length: size_t) + -- return Query_Results_Handle + -- with Import, Convention=>C; + -- + -- function From_String (World: Rasqal_World_Type_Without_Finalize; + -- Kind: Query_Results_Type_Enum; + -- Base_URI: URI_Type_Without_Finalize; + -- Value: String) + -- return Query_Results_Type is + -- use RDF.Rasqal.World, RDF.Raptor.URI; + -- begin + -- return From_Non_Null_Handle(Rasqal_New_Query_Results_From_String( + -- Get_Handle(World), Kind, Get_Handle(Base_URI), My_To_C_Without_Nul(Value), Value'Length)); + -- end; + + function Has_Element (Position: Cursor) return Boolean is + (Not_Finished(Position.all)); + + function Create_Bindings_Iterator (Results: in out Bindings_Query_Results_Type_Without_Finalize'Class) + return Bindings_Iterator is + (Ref=>Results'Unchecked_Access); + + function First (Object: Bindings_Iterator) return Cursor is + (Object.Ref); + + function Next (Object: Bindings_Iterator; Position: Cursor) return Cursor is + begin + Next(Position.all); + return Position; + end; + + function Get_Binding_Value (Position: Cursor; + Offset: Natural) + return Literal_Type_Without_Finalize is + (Get_Binding_Value(Position.all, Offset)); + + function Get_Binding_Value_By_Name (Position: Cursor; + Name: String) + return Literal_Type_Without_Finalize is + (Get_Binding_Value_By_Name(Position.all, Name)); + + function Create_Triples_Iterator (Results: in out Graph_Query_Results_Type_Without_Finalize'Class) + return Bindings_Iterator is + (Ref=>Results'Unchecked_Access); + + function First (Object: Triples_Iterator) return Cursor is + (Object.Ref); + + function Next (Object: Triples_Iterator; Position: Cursor) return Cursor is + begin + Next_Triple(Position.all); + return Position; + end; + + function Get_Triple (Position: Cursor) return Statement_Type_Without_Finalize is + (Get_Triple(Position.all)); + + function Has_Element (Position: Variables_Cursor) return Boolean is + (Position.Count < Get_Bindings_Count(Position.Ref.all)); + + function Create_Variables_Iterator (Results: Bindings_Query_Results_Type_Without_Finalize'Class) + return Variables_Iterator is + (Ref=>Results'Unchecked_Access); + + function First (Object: Variables_Iterator) return Variables_Cursor is + (Ref=>Object.Ref, Count=>0); + + function Next (Object: Variables_Iterator; Position: Variables_Cursor) return Variables_Cursor is + (Position with delta Count=>Position.Count); + + function Get_Name (Position: Variables_Cursor) return String is + (Get_Binding_Name(Position.Ref.all, Position.Count)); + +end RDF.Rasqal.Query_Results; diff --git a/ada/src/rdf-rasqal-query_results.ads b/ada/src/rdf-rasqal-query_results.ads new file mode 100644 index 000000000..df629dd30 --- /dev/null +++ b/ada/src/rdf-rasqal-query_results.ads @@ -0,0 +1,212 @@ +with Ada.Iterator_Interfaces; +with RDF.Auxiliary; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.Statement; use RDF.Raptor.Statement; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; +with RDF.Rasqal.World; use RDF.Rasqal.World; +with RDF.Rasqal.Literal; use RDF.Rasqal.Literal; +limited with RDF.Rasqal.Query; + +package RDF.Rasqal.Query_Results is + + package Query_Results_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + subtype Query_Results_Handle is Query_Results_Handled_Record.Access_Type; + + type Query_Results_Type_Without_Finalize is new Query_Results_Handled_Record.Base_Object with null record; + + overriding procedure Finalize_Handle (Object: Query_Results_Type_Without_Finalize; Handle: Query_Results_Handle); + + type Query_Results_Type_Enum is (Results_Bindings, + Results_Boolean, + Results_Graph, + Results_Syntax, + Results_Unknown); + + not overriding function Get_Type (Results: Query_Results_Type_Without_Finalize) + return Query_Results_Type_Enum; + + not overriding function Is_Bindings (Results: Query_Results_Type_Without_Finalize) return Boolean; + not overriding function Is_Boolean (Results: Query_Results_Type_Without_Finalize) return Boolean; + not overriding function Is_Graph (Results: Query_Results_Type_Without_Finalize) return Boolean; + not overriding function Is_Syntax (Results: Query_Results_Type_Without_Finalize) return Boolean; + + subtype Bindings_Query_Results_Type_Without_Finalize is Query_Results_Type_Without_Finalize + with Dynamic_Predicate => Is_Bindings(Bindings_Query_Results_Type_Without_Finalize); + subtype Boolean_Query_Results_Type_Without_Finalize is Query_Results_Type_Without_Finalize + with Dynamic_Predicate => Is_Boolean(Boolean_Query_Results_Type_Without_Finalize); + subtype Graph_Query_Results_Type_Without_Finalize is Query_Results_Type_Without_Finalize + with Dynamic_Predicate => Is_Graph(Graph_Query_Results_Type_Without_Finalize); + subtype Syntax_Query_Results_Type_Without_Finalize is Query_Results_Type_Without_Finalize + with Dynamic_Predicate => Is_Syntax(Syntax_Query_Results_Type_Without_Finalize); + + -- function Add_Row is deliberately not implemented + + not overriding function Finished (Results: Query_Results_Type_Without_Finalize) return Boolean + with Pre => Is_Bindings(Results) or Is_Graph(Results); + + not overriding function Not_Finished (Results: Query_Results_Type_Without_Finalize) return Boolean is + (not Finished(Results)); + + function Get_Binding_Name (Results: Bindings_Query_Results_Type_Without_Finalize'Class; + Offset: Natural) + return String; + + function Get_Binding_Value (Results: Bindings_Query_Results_Type_Without_Finalize'Class; + Offset: Natural) + return Literal_Type_Without_Finalize; + + function Get_Binding_Value_By_Name (Results: Bindings_Query_Results_Type_Without_Finalize'Class; + Name: String) + return Literal_Type_Without_Finalize; + + -- rasqal_query_results_get_bindings() deliberately not implemented. + -- Use iterators instead. + + function Get_Bindings_Count (Results: Bindings_Query_Results_Type_Without_Finalize'Class) + return Natural; -- or Positive? + + function Get_Boolean (Results: Boolean_Query_Results_Type_Without_Finalize'Class) return Boolean; + + not overriding function Get_Current_Count (Results: Query_Results_Type_Without_Finalize) return Natural; + + not overriding function Get_Query (Results: Query_Results_Type_Without_Finalize) + return RDF.Rasqal.Query.Query_Type_Without_Finalize; + + function Get_Triple (Results: Graph_Query_Results_Type_Without_Finalize'Class) + return Statement_Type_Without_Finalize; + + -- Deliberately not implemented: + -- function Get_Row_By_Offset (Results: Query_Results_Type_Without_Finalize; Offset: Natural) return XXX; + + procedure Next (Results: Bindings_Query_Results_Type_Without_Finalize'Class); + + procedure Next_Triple (Results: Graph_Query_Results_Type_Without_Finalize'Class); + + not overriding procedure Read (Stream: IOStream_Type_Without_Finalize'Class; + Results: Query_Results_Type_Without_Finalize; + Format_Name: String; -- "" for no format name + Mime_Type: String; -- "" for no MIME type + Format_URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class); + + not overriding procedure Write (Stream: IOStream_Type_Without_Finalize'Class; + Results: Query_Results_Type_Without_Finalize; + Format_Name: String; -- "" for no format name + Mime_Type: String; -- "" for no MIME type + Format_URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class); + + not overriding function Type_Label (Kind: Query_Results_Type_Enum) return String; + + not overriding procedure Rewind (Results: in out Query_Results_Type_Without_Finalize); + + package Handlers is new Query_Results_Handled_Record.Common_Handlers(Query_Results_Type_Without_Finalize); + + type Query_Results_Type is new Handlers.Base_With_Finalization with null record; + + type Query_Results_Type_User is new Handlers.User_Type with null record; + + not overriding function Create (World: Rasqal_World_Type_Without_Finalize'Class; + Query: RDF.Rasqal.Query.Query_Type_Without_Finalize; + Kind: Query_Results_Type_Enum) + return Query_Results_Type; + + -- Not supported as of Rasqal 0.9.32 + -- not overriding function From_String (World: Rasqal_World_Type_Without_Finalize; + -- Kind: Query_Results_Type_Enum; + -- Base_URI: URI_Type_Without_Finalize; + -- Value: String) + -- return Query_Results_Type; + + -- The same cursor is used for bindings iterator and for triples iterator. + -- However, don't rely on using the same type. + -- Do not create more than one cursor for the same query results object. + type Cursor is private; + + not overriding function Has_Element (Position: Cursor) return Boolean; + + package Base_Iterators is new Ada.Iterator_Interfaces(Cursor, Has_Element); + + type Bindings_Iterator is new Base_Iterators.Forward_Iterator with private; + + not overriding function Create_Bindings_Iterator (Results: in out Bindings_Query_Results_Type_Without_Finalize'Class) + return Bindings_Iterator; + + overriding function First (Object: Bindings_Iterator) return Cursor; + + overriding function Next (Object: Bindings_Iterator; Position: Cursor) return Cursor; + + not overriding function Get_Binding_Value (Position: Cursor; + Offset: Natural) + return Literal_Type_Without_Finalize; + + not overriding function Get_Binding_Value_By_Name (Position: Cursor; + Name: String) + return Literal_Type_Without_Finalize; + + type Triples_Iterator is new Base_Iterators.Forward_Iterator with private; + + not overriding function Create_Triples_Iterator (Results: in out Graph_Query_Results_Type_Without_Finalize'Class) + return Bindings_Iterator; + + overriding function First (Object: Triples_Iterator) return Cursor; + + overriding function Next (Object: Triples_Iterator; Position: Cursor) return Cursor; + + not overriding function Get_Triple (Position: Cursor) return Statement_Type_Without_Finalize; + + type Variables_Cursor is private; + + not overriding function Has_Element (Position: Variables_Cursor) return Boolean; + + package Variables_Iterators is new Ada.Iterator_Interfaces(Variables_Cursor, Has_Element); + + -- We can also make backward iterator, but I see no use cases for this + type Variables_Iterator is new Variables_Iterators.Forward_Iterator with private; + + not overriding function Create_Variables_Iterator (Results: Bindings_Query_Results_Type_Without_Finalize'Class) + return Variables_Iterator; + + overriding function First (Object: Variables_Iterator) return Variables_Cursor; + + overriding function Next (Object: Variables_Iterator; Position: Variables_Cursor) return Variables_Cursor; + + not overriding function Get_Name (Position: Variables_Cursor) return String; + + subtype Bindings_Query_Results_Type is Query_Results_Type + with Dynamic_Predicate => Is_Bindings(Bindings_Query_Results_Type); + subtype Boolean_Query_Results_Type is Query_Results_Type + with Dynamic_Predicate => Is_Boolean(Boolean_Query_Results_Type); + subtype Graph_Query_Results_Type is Query_Results_Type + with Dynamic_Predicate => Is_Graph(Graph_Query_Results_Type); + subtype Syntax_Query_Results_Type is Query_Results_Type + with Dynamic_Predicate => Is_Syntax(Syntax_Query_Results_Type); + +private + + type Cursor is access constant Query_Results_Type_Without_Finalize'Class; + + type Bindings_Iterator is new Base_Iterators.Forward_Iterator with + record + Ref: Cursor; + end record; + + type Triples_Iterator is new Base_Iterators.Forward_Iterator with + record + Ref: Cursor; + end record; + + type Variables_Cursor is + record + Ref: Cursor; -- hack + Count: Natural; + end record; + + type Variables_Iterator is new Variables_Iterators.Forward_Iterator with + record + Ref: Cursor; + end record; + +end RDF.Rasqal.Query_Results; diff --git a/ada/src/rdf-rasqal-syntaxes.adb b/ada/src/rdf-rasqal-syntaxes.adb new file mode 100644 index 000000000..f18a3d6e4 --- /dev/null +++ b/ada/src/rdf-rasqal-syntaxes.adb @@ -0,0 +1,102 @@ +package body RDF.Rasqal.Syntaxes is + + type Rasqal_Syntax_Description_Access is access all Raptor_Syntax_Description_Type + with Convention=>C; + + function rasqal_world_get_query_language_description (World: Rasqal_World_Handle; Counter: unsigned) + return Rasqal_Syntax_Description_Access + with Import, Convention=>C; + + function rasqal_world_get_query_results_format_description (World: Rasqal_World_Handle; Counter: unsigned) + return Rasqal_Syntax_Description_Access + with Import, Convention=>C; + + function Get_Query_Language_Description (World: Rasqal_World_Type_Without_Finalize'Class; Counter: Unsigned) + return Raptor_Syntax_Description_Type is + begin + return rasqal_world_get_query_language_description(Get_Handle(World), Counter).all; + end; + + function Get_Query_Results_Format_Description (World: Rasqal_World_Type_Without_Finalize'Class; Counter: Unsigned) + return Raptor_Syntax_Description_Type is + begin + return rasqal_world_get_query_results_format_description(Get_Handle(World), Counter).all; + end; + + --package String_Ptrs is new Interfaces.C.Pointers(size_t, chars_ptr, chars_ptr_array, Null_Ptr); + + --use String_Ptrs; + + function Get_Position (Cursor: Query_Language_Description_Cursor ) return Natural is (Cursor.Position); + function Get_Position (Cursor: Query_Results_Format_Description_Cursor) return Natural is (Cursor.Position); + + function Get_Description (Cursor: Query_Language_Description_Cursor) + return Raptor_Syntax_Description_Type is + begin + return Get_Query_Language_Description (Rasqal_World_Type_Without_Finalize'(From_Handle(Cursor.World)), unsigned(Cursor.Position)); + end; + + function Get_Description (Cursor: Query_Results_Format_Description_Cursor) + return Raptor_Syntax_Description_Type is + begin + return Get_Query_Results_Format_Description(Rasqal_World_Type_Without_Finalize'(From_Handle(Cursor.World)), + unsigned(Cursor.Position)); + end; + + function Has_Element (Position: Query_Language_Description_Cursor) return Boolean is + begin + return rasqal_world_get_query_language_description(Position.World, unsigned(Position.Position)) /= null; + end; + + function Has_Element (Position: Query_Results_Format_Description_Cursor) return Boolean is + begin + return rasqal_world_get_query_results_format_description(Position.World, unsigned(Position.Position)) /= null; + end; + + function First (Object: Query_Language_Description_Iterator) + return Query_Language_Description_Cursor is + begin + return (Position=>0, World=>Object.World); + end; + + function Next (Object: Query_Language_Description_Iterator; Position: Query_Language_Description_Cursor) + return Query_Language_Description_Cursor is + begin + return (Position=>Position.Position+1, World=>Position.World); + end; + + function First (Object: Query_Results_Format_Description_Iterator) + return Query_Results_Format_Description_Cursor is + begin + return (Position=>0, World=>Object.World); + end; + + function Next (Object: Query_Results_Format_Description_Iterator; + Position: Query_Results_Format_Description_Cursor) + return Query_Results_Format_Description_Cursor is + begin + return (Position=>Position.Position+1, World=>Position.World); + end; + + function Create_Query_Language_Descriptions_Iterator(World: Rasqal_World_Type_Without_Finalize'Class) + return Query_Language_Description_Iterator is + begin + return (World=>Get_Handle(World)); + end; + + function Create_Query_Results_Format_Descriptions_Iterator (World: Rasqal_World_Type_Without_Finalize'Class) + return Query_Results_Format_Description_Iterator is + begin + return (World=>Get_Handle(World)); + end; + + function rasqal_language_name_check (World: Rasqal_World_Handle; Name: char_array) return int + with Import, Convention=>C; + + function Language_Name_Check (World: Rasqal_World_Type_Without_Finalize'Class; Name: String) + return Boolean is + begin + return rasqal_language_name_check(Get_Handle(World), To_C(Name)) /= 0; + end; + +end RDF.Rasqal.Syntaxes; diff --git a/ada/src/rdf-rasqal-syntaxes.ads b/ada/src/rdf-rasqal-syntaxes.ads new file mode 100644 index 000000000..b55c46088 --- /dev/null +++ b/ada/src/rdf-rasqal-syntaxes.ads @@ -0,0 +1,75 @@ +with Ada.Iterator_Interfaces; +with Interfaces.C; use Interfaces.C; +with RDF.Rasqal.World; use RDF.Rasqal.World; +with RDF.Raptor.Syntaxes; use RDF.Raptor.Syntaxes; + +package RDF.Rasqal.Syntaxes is + + function Get_Query_Language_Description (World: Rasqal_World_Type_Without_Finalize'Class; Counter: unsigned) + return Raptor_Syntax_Description_Type; + function Get_Query_Results_Format_Description (World: Rasqal_World_Type_Without_Finalize'Class; Counter: unsigned) + return Raptor_Syntax_Description_Type; + + type Query_Language_Description_Cursor is private; + type Query_Results_Format_Description_Cursor is private; + + function Get_Position (Cursor: Query_Language_Description_Cursor ) return Natural; + function Get_Position (Cursor: Query_Results_Format_Description_Cursor) return Natural; + + function Get_Description (Cursor: Query_Language_Description_Cursor ) return Raptor_Syntax_Description_Type; + function Get_Description (Cursor: Query_Results_Format_Description_Cursor) return Raptor_Syntax_Description_Type; + + function Has_Element (Position: Query_Language_Description_Cursor ) return Boolean; + function Has_Element (Position: Query_Results_Format_Description_Cursor) return Boolean; + + package Query_Language_Description_Iterators is new Ada.Iterator_Interfaces(Query_Language_Description_Cursor , Has_Element); + package Query_Results_Format_Description_Iterators is new Ada.Iterator_Interfaces(Query_Results_Format_Description_Cursor, Has_Element); + + type Query_Language_Description_Iterator is new Query_Language_Description_Iterators .Forward_Iterator with private; + type Query_Results_Format_Description_Iterator is new Query_Results_Format_Description_Iterators.Forward_Iterator with private; + + overriding function First (Object: Query_Language_Description_Iterator) + return Query_Language_Description_Cursor; + overriding function Next (Object: Query_Language_Description_Iterator; + Position: Query_Language_Description_Cursor) + return Query_Language_Description_Cursor; + + overriding function First (Object: Query_Results_Format_Description_Iterator) + return Query_Results_Format_Description_Cursor; + overriding function Next (Object: Query_Results_Format_Description_Iterator; + Position: Query_Results_Format_Description_Cursor) + return Query_Results_Format_Description_Cursor; + + not overriding function Create_Query_Language_Descriptions_Iterator (World: Rasqal_World_Type_Without_Finalize'Class) + return Query_Language_Description_Iterator; + not overriding function Create_Query_Results_Format_Descriptions_Iterator (World: Rasqal_World_Type_Without_Finalize'Class) + return Query_Results_Format_Description_Iterator; + + function Language_Name_Check (World: Rasqal_World_Type_Without_Finalize'Class; Name: String) + return Boolean; + +private + + type Query_Language_Description_Cursor is + record + World: Rasqal_World_Handle; + Position: Natural; + end record; + + type Query_Results_Format_Description_Cursor is + record + World: Rasqal_World_Handle; + Position: Natural; + end record; + + type Query_Language_Description_Iterator is new Query_Language_Description_Iterators.Forward_Iterator with + record + World: Rasqal_World_Handle; + end record; + + type Query_Results_Format_Description_Iterator is new Query_Results_Format_Description_Iterators.Forward_Iterator with + record + World: Rasqal_World_Handle; + end record; + +end RDF.Rasqal.Syntaxes; diff --git a/ada/src/rdf-rasqal-world.adb b/ada/src/rdf-rasqal-world.adb new file mode 100644 index 000000000..694607c89 --- /dev/null +++ b/ada/src/rdf-rasqal-world.adb @@ -0,0 +1,120 @@ +with Ada.Unchecked_Conversion; +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.Convert_Void; +with RDF.Auxiliary.C_String_Holders; use RDF.Auxiliary.C_String_Holders; +with RDF.Rasqal.Memory; + +package body RDF.Rasqal.World is + + function rasqal_new_world return Rasqal_World_Handle + with Import, Convention=>C; + + procedure rasqal_world_open(Handle: Rasqal_World_Handle) + with Import, Convention=>C; + + function Default_Handle(Object: Rasqal_World_Type_Without_Finalize) + return Rasqal_World_Handle is + begin + return rasqal_new_world; + end; + + procedure Open(Object: in out Rasqal_World_Type_Without_Finalize) is + begin + rasqal_world_open(Get_Handle(Object)); + end; + + function Open return Rasqal_World_Type is + begin + return Object: Rasqal_World_Type do + Open(Object); + end return; + end; + + function rasqal_world_set_warning_level (World: Rasqal_World_Handle; Level: unsigned) + return int + with Import, Convention=>C; + + procedure Set_Warning_Level (World: in out Rasqal_World_Type_Without_Finalize; + Level: Warning_Level) is + begin + if rasqal_world_set_warning_level(Get_Handle(World), unsigned(Level)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function rasqal_world_get_raptor (World: Rasqal_World_Handle) return Raptor_World_Handle + with Import, Convention=>C; + + function Get_Raptor (World: Rasqal_World_Type_Without_Finalize) + return Raptor_World_Type_Without_Finalize is + begin + return From_Non_Null_Handle(rasqal_world_get_raptor(Get_Handle(World))); + end; + + procedure rasqal_world_set_raptor (World: Rasqal_World_Handle; Raptor_World: Raptor_World_Handle) + with Import, Convention=>C; + + procedure Set_Raptor (World: in out Rasqal_World_Type_Without_Finalize; + Raptor_World: Raptor_World_Type_Without_Finalize'Class) is + begin + rasqal_world_set_raptor(Get_Handle(World), Get_Handle(Raptor_World)); + end; + + procedure rasqal_free_world (World: Rasqal_World_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Rasqal_World_Type_Without_Finalize; Handle: Rasqal_World_Handle) is + begin + rasqal_free_world(Handle); + end; + +-- type Log_Handler_Access is access constant Log_Handler'Class; + package My_Conv is new RDF.Auxiliary.Convert_Void(Log_Handler'Class); + + procedure rasqal_world_set_log_handler (World: Rasqal_World_Handle; + Data: chars_ptr; + Handler: Log_Handler_Procedure_Type) + with Import, Convention=>C; + + procedure Set_Log_Handler(World: in out Rasqal_World_Type_Without_Finalize; + Handler: access Log_Handler'Class) is + begin + rasqal_world_set_log_handler(Get_Handle(World), + My_Conv.To_C_Pointer(My_Conv.Object_Pointer(Handler)), + Our_Raptor_Log_Handler'Access); + end; + + function rasqal_world_guess_query_results_format_name (World: Rasqal_World_Handle; + URI: URI_Handle; + Mime_Type: chars_ptr; + Buffer: chars_ptr; + Len: size_t; + Identifier: chars_ptr) + return chars_ptr + with Import, Convention=>C; + + function Guess_Query_Results_Format_Name (World: Rasqal_World_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Mime_Type: String_Holders.Holder; + Buffer: String_Holders.Holder; + Identifier: String_Holders.Holder) + return String_Holders.Holder is + Buffer2: constant C_String_Holder := To_C_String_Holder(Buffer); + -- TODO: Do this without dynamic allocation + Mime_Type2 : constant chars_ptr := New_String(Mime_Type ); + Identifier2: constant chars_ptr := New_String(Identifier); + Result: constant chars_ptr := rasqal_world_guess_query_results_format_name(Get_Handle(World), + Get_Handle(URI), + Mime_Type2, + C_String(Buffer2), + Length(Buffer2), + Identifier2); + use String_Holders; + begin + RDF.Rasqal.Memory.rasqal_free_memory(Mime_Type2); + RDF.Rasqal.Memory.rasqal_free_memory(Identifier2); + return (if Result = Null_Ptr then Empty_Holder else To_Holder(Value(Result))); + end; + +end RDF.Rasqal.World; diff --git a/ada/src/rdf-rasqal-world.ads b/ada/src/rdf-rasqal-world.ads new file mode 100644 index 000000000..b94d0b27e --- /dev/null +++ b/ada/src/rdf-rasqal-world.ads @@ -0,0 +1,50 @@ +with RDF.Auxiliary; use RDF.Auxiliary; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Raptor.Log; use RDF.Raptor.Log; +with RDF.Raptor.URI; use RDF.Raptor.URI; + +package RDF.Rasqal.World is + + package Rasqal_World_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + type Rasqal_World_Type_Without_Finalize is new Rasqal_World_Handled_Record.Base_Object with null record; + + subtype Rasqal_World_Handle is Rasqal_World_Handled_Record.Access_Type; + + overriding function Default_Handle(Object: Rasqal_World_Type_Without_Finalize) return Rasqal_World_Handle; + + overriding procedure Finalize_Handle (Object: Rasqal_World_Type_Without_Finalize; Handle: Rasqal_World_Handle); + + not overriding procedure Open(Object: in out Rasqal_World_Type_Without_Finalize); + + not overriding procedure Set_Log_Handler(World: in out Rasqal_World_Type_Without_Finalize; + Handler: access Log_Handler'Class); + + type Warning_Level is range 0 .. 100; + + not overriding procedure Set_Warning_Level (World: in out Rasqal_World_Type_Without_Finalize; + Level: Warning_Level); + + not overriding function Get_Raptor (World: Rasqal_World_Type_Without_Finalize) + return Raptor_World_Type_Without_Finalize; + + not overriding procedure Set_Raptor (World: in out Rasqal_World_Type_Without_Finalize; + Raptor_World: Raptor_World_Type_Without_Finalize'Class); + + not overriding function Guess_Query_Results_Format_Name (World: Rasqal_World_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Mime_Type: String_Holders.Holder; + Buffer: String_Holders.Holder; + Identifier: String_Holders.Holder) + return String_Holders.Holder; + + package Handlers is new Rasqal_World_Handled_Record.Common_Handlers(Rasqal_World_Type_Without_Finalize); + + type Rasqal_World_Type is new Handlers.Base_With_Finalization with null record; + + type Rasqal_World_Type_User is new Handlers.User_Type with null record; + + not overriding function Open return Rasqal_World_Type; + +end RDF.Rasqal.World; diff --git a/ada/src/rdf-rasqal.ads b/ada/src/rdf-rasqal.ads new file mode 100644 index 000000000..7295876c4 --- /dev/null +++ b/ada/src/rdf-rasqal.ads @@ -0,0 +1,3 @@ +package RDF.Rasqal is + pragma Pure; +end RDF.Rasqal; diff --git a/ada/src/rdf-redland-iterator.adb b/ada/src/rdf-redland-iterator.adb new file mode 100644 index 000000000..62407e6fb --- /dev/null +++ b/ada/src/rdf-redland-iterator.adb @@ -0,0 +1,55 @@ +with Interfaces.C; use Interfaces.C; + +package body RDF.Redland.Iterator is + + procedure librdf_free_iterator (Handle: Iterator_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Iterator_Type_Without_Finalize; Handle: Iterator_Handle) is + begin + librdf_free_iterator(Handle); + end; + + function librdf_iterator_end (Iterator: Iterator_Handle) return int + with Import, Convention=>C; + + function Is_End (Iterator: Iterator_Type_Without_Finalize) return Boolean is + (librdf_iterator_end(Get_Handle(Iterator)) /= 0); + + function librdf_iterator_next (Iterator: Iterator_Handle) return int + with Import, Convention=>C; + + procedure Next (Iterator: in out Iterator_Type_Without_Finalize) is + Result: constant int := librdf_iterator_next(Get_Handle(Iterator)); + pragma Unreferenced(Result); + begin + null; + end; + + function librdf_iterator_get_object (Iterator: Iterator_Handle) return chars_ptr + with Import, Convention=>C; + function librdf_iterator_get_context (Iterator: Iterator_Handle) return chars_ptr + with Import, Convention=>C; + function librdf_iterator_get_key (Iterator: Iterator_Handle) return chars_ptr + with Import, Convention=>C; + function librdf_iterator_get_value (Iterator: Iterator_Handle) return chars_ptr + with Import, Convention=>C; + + function Get_Object_Internal (Iterator: Iterator_Type_Without_Finalize) return chars_ptr is + (librdf_iterator_get_object(Get_Handle(Iterator))); + function Get_Context_Internal (Iterator: Iterator_Type_Without_Finalize) return chars_ptr is + (librdf_iterator_get_context(Get_Handle(Iterator))); + function Get_Key_Internal (Iterator: Iterator_Type_Without_Finalize) return chars_ptr is + (librdf_iterator_get_key(Get_Handle(Iterator))); + function Get_Value_Internal (Iterator: Iterator_Type_Without_Finalize) return chars_ptr is + (librdf_iterator_get_value(Get_Handle(Iterator))); + + function librdf_new_empty_iterator return Iterator_Handle + with Import, Convention=>C; + + function Empty_Iterator return Iterator_Type is + begin + return From_Non_Null_Handle(librdf_new_empty_iterator); + end; + +end RDF.Redland.Iterator; diff --git a/ada/src/rdf-redland-iterator.ads b/ada/src/rdf-redland-iterator.ads new file mode 100644 index 000000000..d4ebdcaf7 --- /dev/null +++ b/ada/src/rdf-redland-iterator.ads @@ -0,0 +1,41 @@ +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.Limited_Handled_Record; + +package RDF.Redland.Iterator is + + -- Usually you should use Base_With_Finalization types, such as defined in RDF.Redland.Node_Iterator + + -- TODO: Necessarily test that it works as expected + + package Iterator_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + type Iterator_Type_Without_Finalize is new Iterator_Handled_Record.Base_Object with null record; + + subtype Iterator_Handle is Iterator_Handled_Record.Access_Type; + + overriding procedure Finalize_Handle (Object: Iterator_Type_Without_Finalize; Handle: Iterator_Handle); + + not overriding function Is_End (Iterator: Iterator_Type_Without_Finalize) return Boolean; + + not overriding procedure Next (Iterator: in out Iterator_Type_Without_Finalize); + + -- Internal functions + not overriding function Get_Object_Internal (Iterator: Iterator_Type_Without_Finalize) return chars_ptr; + not overriding function Get_Context_Internal (Iterator: Iterator_Type_Without_Finalize) return chars_ptr; + not overriding function Get_Key_Internal (Iterator: Iterator_Type_Without_Finalize) return chars_ptr; + not overriding function Get_Value_Internal (Iterator: Iterator_Type_Without_Finalize) return chars_ptr; + + -- librdf_iterator_add_map() not implemented + + package Handlers is new Iterator_Handled_Record.Common_Handlers(Iterator_Type_Without_Finalize); + + type Iterator_Type is new Handlers.Base_With_Finalization with null record; + + type Iterator_Type_User is new Handlers.User_Type with null record; + + not overriding function Empty_Iterator return Iterator_Type; + + -- Implementing Ada2012 iterators does not seem possible, because we start + -- iterators from a return value of a function, not from a "Forward_Iterator" object + +end RDF.Redland.Iterator; diff --git a/ada/src/rdf-redland-log.adb b/ada/src/rdf-redland-log.adb new file mode 100644 index 000000000..14e445f1d --- /dev/null +++ b/ada/src/rdf-redland-log.adb @@ -0,0 +1,62 @@ +with RDF.Auxiliary.Convert_Void; + +package body RDF.Redland.Log is + + function librdf_log_message_code (Message: Log_Message_Type) return int + with Import, Convention=>C; + + function Get_Code (Message: Log_Message_Type) return int is + begin + return librdf_log_message_code(Message); + end; + + function librdf_log_message_level (Message: Log_Message_Type) return Log_Level_Type + with Import, Convention=>C; + + function Get_Level (Message: Log_Message_Type) return Log_Level_Type is + begin + return librdf_log_message_level(Message); + end; + + function librdf_log_message_facility (Message: Log_Message_Type) return Log_Facility_Type + with Import, Convention=>C; + + function Get_Facility (Message: Log_Message_Type) return Log_Facility_Type is + begin + return librdf_log_message_facility(Message); + end; + + function librdf_log_message_message (Message: Log_Message_Type) return chars_ptr + with Import, Convention=>C; + + function Get_Message (Message: Log_Message_Type) return String is + begin + return Value(librdf_log_message_message(Message)); + end; + + function librdf_log_message_locator (Message: Log_Message_Type) return RDF.Raptor.Log.Locator_Handle + with Import, Convention=>C; + + function Get_Locator (Message: Log_Message_Type) return RDF.Raptor.Log.Locator_Type is + use RDF.Raptor.Log; + begin + return From_Handle(librdf_log_message_locator(Message)); + end; + +-- type User_Defined_Access is access constant Log_Handler'Class; + package My_Conv is new RDF.Auxiliary.Convert_Void(Log_Handler'Class); + + procedure Our_Raptor_Log_Handler(Data: chars_ptr; Msg: Log_Message_Type) is + begin + Log_Message(My_Conv.To_Access(Data).all, Msg); + end; + + procedure librdf_world_set_logger (World: Redland_World_Handle; Data: chars_ptr; Handler: Log_Handler_Procedure_Type) + with Import, Convention=>C; + + procedure Set_Log_Handler(World: in out Redland_World_Type_Without_Finalize'Class; Handler: access Log_Handler) is + begin + librdf_world_set_logger(Get_Handle(World), My_Conv.To_C_Pointer(Handler), Our_Raptor_Log_Handler'Access); + end; + +end RDF.Redland.Log; diff --git a/ada/src/rdf-redland-log.ads b/ada/src/rdf-redland-log.ads new file mode 100644 index 000000000..4c4adbbe9 --- /dev/null +++ b/ada/src/rdf-redland-log.ads @@ -0,0 +1,71 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary; +with RDF.Raptor.Log; +with RDF.Redland.World; use RDF.Redland.World; + +package RDF.Redland.Log is + + type Log_Level_Type is (None, Debug, Info, Warn, Error, Fatal) + with Convention => C; + for Log_Level_Type use (None => 0, + Debug => 1, + Info => 2, + Warn => 3, + Error => 4, + Fatal => 5); + function Last return Log_Level_Type renames Fatal; + + type Log_Facility_Type is (None, + Concepts, + Digest, + Files, + Hash, + Init, + Iterator, + List, + Model, + Node, + Parser, + Query, + Serializer, + Statement, + Storage, + Stream, + URI, + UTF8, + Memory, + Raptor) + with Convention => C; + function Last return Log_Facility_Type renames Raptor; + + type Log_Message_Type is private; +-- package Log_Message_Handled_Record is new RDF.Auxiliary.Handled_Record(Log_Message_Record, Log_Message_Record_Access); +-- subtype Log_Message_Handle is Log_Message_Handled_Record.Access_Type; +-- type Log_Message_Type is new Log_Message_Handled_Record.Base_Object with null record; + + function Get_Code (Message: Log_Message_Type) return int; + function Get_Level (Message: Log_Message_Type) return Log_Level_Type; + function Get_Facility (Message: Log_Message_Type) return Log_Facility_Type; + function Get_Message (Message: Log_Message_Type) return String; + function Get_Locator (Message: Log_Message_Type) return RDF.Raptor.Log.Locator_Type; + + type Log_Handler is abstract tagged null record; + + type Log_Handler_Procedure_Type is access procedure (Data: chars_ptr; Msg: Log_Message_Type) + with Convention=>C; + + -- Internal + procedure Our_Raptor_Log_Handler(Data: chars_ptr; Msg: Log_Message_Type) + with Convention=>C; + + not overriding procedure Log_Message(Handler: Log_Handler; Info: Log_Message_Type) is abstract; + + not overriding procedure Set_Log_Handler(World: in out Redland_World_Type_Without_Finalize'Class; + Handler: access Log_Handler); + +private + + type Log_Message_Type is new RDF.Auxiliary.Dummy_Record_Access; + +end RDF.Redland.Log; diff --git a/ada/src/rdf-redland-memory.adb b/ada/src/rdf-redland-memory.adb new file mode 100644 index 000000000..0cf01876a --- /dev/null +++ b/ada/src/rdf-redland-memory.adb @@ -0,0 +1,20 @@ +package body RDF.Redland.Memory is + + function C_Strncpy (Target, Source: Chars_Ptr; Len: size_t) return chars_ptr + with Import, Convention=>C, External_Name=>"strncpy"; + + procedure C_Strncpy (Target, Source: chars_ptr; Len: size_t) is + Dummy: chars_ptr := C_Strncpy(Target, Source, Len); + begin + null; + end; + + function Copy_C_String (Str: chars_ptr) return chars_ptr is + Len: constant size_t := Strlen(Str) + 1; + New_Str: constant chars_ptr := librdf_alloc_memory(Len); + begin + C_Strncpy(New_Str, Str, Len); + return New_Str; + end; + +end RDF.Redland.Memory; diff --git a/ada/src/rdf-redland-memory.ads b/ada/src/rdf-redland-memory.ads new file mode 100644 index 000000000..cb84ccaf5 --- /dev/null +++ b/ada/src/rdf-redland-memory.ads @@ -0,0 +1,19 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; + +-- This are thin bindings +package RDF.Redland.Memory is + + procedure librdf_free_memory (ptr: chars_ptr) + with Import, Convention=>C; + + function librdf_alloc_memory (size: size_t) return chars_ptr + with Import, Convention=>C; + + function librdf_calloc_memory (nmemb: size_t; size: size_t) return chars_ptr + with Import, Convention=>C; + + -- Missing in C code, so I implement it in Ada + function Copy_C_String (Str: chars_ptr) return chars_ptr; + +end RDF.Redland.Memory; diff --git a/ada/src/rdf-redland-model.adb b/ada/src/rdf-redland-model.adb new file mode 100644 index 000000000..dff74ac71 --- /dev/null +++ b/ada/src/rdf-redland-model.adb @@ -0,0 +1,557 @@ +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; + +package body RDF.Redland.Model is + + type String_P_Type is access all chars_ptr with Convention=>C; + + function librdf_model_enumerate (World: Redland_World_Handle; + Counter: unsigned; + Name, Label: String_P_Type) + return int + with Import, Convention=>C; + + function Enumerate_Models (World: Redland_World_Type_Without_Finalize'Class; + Counter: unsigned) + return Model_Info_Holders.Holder is + Name, Label: aliased chars_ptr; + Result: constant int := + librdf_model_enumerate(Get_Handle(World), Counter, Name'Unchecked_Access, Label'Unchecked_Access); + use Model_Info_Holders; + begin + if Result /= 0 then + return Empty_Holder; + end if; + declare + Name2 : constant String := Value(Name ); + Label2: constant String := Value(Label); + begin + return To_Holder((Name_Length => Name2 'Length, + Label_Length => Label2'Length, + Name => Name2, Label => Label2)); + end; + end; + + function Has_Element (Position: Enumerate_Models_Cursor) return Boolean is + begin + return librdf_model_enumerate(Position.World, Position.Counter, null, null) = 0; + end; + + function First (Object: Enumerate_Models_Iterator) return Enumerate_Models_Cursor is + begin + return (World => Object.World, Counter => 0); + end; + + function Next (Object: Enumerate_Models_Iterator; Position: Enumerate_Models_Cursor) + return Enumerate_Models_Cursor is + begin + return (World => Position.World, Counter => Position.Counter + 1); + end; + + function librdf_new_model (World: Redland_World_Handle; Storage: Storage_Handle; Options: char_array) + return Model_Handle + with Import, Convention=>C; + + function Create (World: Redland_World_Type_Without_Finalize'Class; + Storage: Storage_Type_Without_Finalize'Class; + Options: String := "") + return Model_Type is + Handle: constant Model_Handle := + librdf_new_model(Get_Handle(World), Get_Handle(Storage), To_C(Options)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_model_from_model (Model: Model_Handle) return Model_Handle + with Import, Convention=>C; + + function Copy (Model: Model_Type_Without_Finalize'Class) return Model_Type is + begin + return From_Non_Null_Handle(librdf_new_model_from_model(Get_Handle(Model))); + end; + + procedure librdf_free_model (Handle: Model_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Model_Type_Without_Finalize; Handle: Model_Handle) is + begin + librdf_free_model(Handle); + end; + + function librdf_model_size (Model: Model_Handle) return int + with Import, Convention=>C; + + function Size_Without_Exception (Model: Model_Type_Without_Finalize) + return Integer is + begin + return Integer(librdf_model_size(Get_Handle(Model))); + end; + + function Size (Model: Model_Type_Without_Finalize) return Natural is + Result: constant int := librdf_model_size(Get_Handle(Model)); + begin + if Result < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Natural(Result); + end; + + function librdf_model_add (Model: Model_Handle; Subject, Predicate, Object: Node_Handle) return int + with Import, Convention=>C; + + procedure Add (Model: in out Model_Type_Without_Finalize; + Subject, Predicate, Object: Node_Type_Without_Finalize'Class) is + begin + if librdf_model_add(Get_Handle(Model), Get_Handle(Subject), Get_Handle(Predicate), Get_Handle(Object)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_add_string_literal_statement (Model: Model_Handle; + Subject, Predicate: Node_Handle; + Literal: char_array; + Language: char_array; + Is_XML: int) + return int + with Import, Convention=>C; + + procedure Add_String_Literal_Statement (Model: Model_Type_Without_Finalize; + Subject, Predicate: Node_Type_Without_Finalize'Class; + Literal: String; + Language: String; + Is_XML: Boolean := False) is + begin + if librdf_model_add_string_literal_statement(Get_Handle(Model), + Get_Handle(Subject), + Get_Handle(Predicate), + To_C(Literal), + To_C(Language), + (if Is_XML then 1 else 0)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_add_typed_literal_statement (Model: Model_Handle; + Subject, Predicate: Node_Handle; + Literal: char_array; + Language: char_array; + Datatype: URI_Handle) + return int + with Import, Convention=>C; + + procedure Add_Typed_Literal_Statement (Model: Model_Type_Without_Finalize; + Subject, Predicate: Node_Type_Without_Finalize'Class; + Literal: String; + Language: String; + Datatype: URI_Type_Without_Finalize'Class) is + begin + if librdf_model_add_typed_literal_statement(Get_Handle(Model), + Get_Handle(Subject), + Get_Handle(Predicate), + To_C(Literal), + To_C(Language), + Get_Handle(Datatype)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_context_add_statement (Model: Model_Handle; + Context: Node_Handle; + Statement: Statement_Handle) + return int + with Import, Convention=>C; + + procedure Add (Model: in out Model_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class; + Context: Node_Type_Without_Finalize'Class := Node_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_model_context_add_statement(Get_Handle(Model), + Get_Handle(Context), + Get_Handle(Statement)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_context_add_statements (Model_Type: Model_Handle; + Context: Node_Handle; + Statements: Stream_Handle) + return int + with Import, Convention=>C; + + procedure Add (Model: in out Model_Type_Without_Finalize; + Statements: Stream_Type_Without_Finalize'Class; + Context: Node_Type_Without_Finalize'Class := Node_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_model_context_add_statements(Get_Handle(Model), + Get_Handle(Context), + Get_Handle(Statements)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_context_remove_statement (Model: Model_Handle; + Context: Node_Handle; + Statement: Statement_Handle) + return int + with Import, Convention=>C; + + procedure Remove (Model: in out Model_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class; + Context: Node_Type_Without_Finalize'Class := Node_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_model_context_remove_statement(Get_Handle(Model), + Get_Handle(Context), + Get_Handle(Statement)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_context_remove_statements (Model_Type: Model_Handle; + Context: Node_Handle; + Statements: Stream_Handle) + return int + with Import, Convention=>C; + + procedure Remove (Model: in out Model_Type_Without_Finalize; + Statements: Stream_Type_Without_Finalize'Class; + Context: Node_Type_Without_Finalize'Class := Node_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_model_context_remove_statements(Get_Handle(Model), + Get_Handle(Context), + Get_Handle(Statements)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_remove_statement (Model: Model_Handle; Statement: Statement_Handle) return int + with Import, Convention=>C; + + procedure Remove (Model: Model_Type_Without_Finalize; Statement: Statement_Type_Without_Finalize'Class) is + begin + if librdf_model_remove_statement(Get_Handle(Model), Get_Handle(Statement)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_contains_statement (Model: Model_Handle; Statement: Statement_Handle) return int + with Import, Convention=>C; + + function Contains (Model: Model_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class) + return Boolean is + Result: constant int := + librdf_model_contains_statement(Get_Handle(Model), Get_Handle(Statement)); + begin + if Result > 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Result /= 0; + end; + + function librdf_model_has_arc_in (Model: Model_Handle; Node, Property: Node_Handle) return int + with Import, Convention=>C; + + not overriding function Has_Arc_In (Model: Model_Type_Without_Finalize; + Node, Property: Node_Type_Without_Finalize'Class) + return Boolean is + begin + return librdf_model_has_arc_in(Get_Handle(Model), Get_Handle(Node), Get_Handle(Property)) /= 0; + end; + + function librdf_model_has_arc_out (Model: Model_Handle; Node, Property: Node_Handle) return int + with Import, Convention=>C; + + not overriding function Has_Arc_Out (Model: Model_Type_Without_Finalize; + Node, Property: Node_Type_Without_Finalize'Class) + return Boolean is + begin + return librdf_model_has_arc_out(Get_Handle(Model), Get_Handle(Node), Get_Handle(Property)) /= 0; + end; + + function librdf_model_as_stream (Model: Model_Handle) return Stream_Handle + with Import, Convention=>C; + + function As_Stream (Model: Model_Type_Without_Finalize) return Stream_Type is + begin + return From_Non_Null_Handle(librdf_model_as_stream(Get_Handle(Model))); + end; + + function librdf_model_find_statements (Model: Model_Handle; Statement: Statement_Handle) return Stream_Handle + with Import, Convention=>C; + + function Find (Model: Model_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class) + return Stream_Type is + begin + return From_Non_Null_Handle(librdf_model_find_statements(Get_Handle(Model), Get_Handle(Statement))); + end; + + function librdf_model_get_sources (Model: Model_Handle; Arc, Target: Node_Handle) + return Node_Iterator_Handle + with Import, Convention=>C; + + function Get_Sources (Model: Model_Type_Without_Finalize; + Arc, Target: Node_Type_Without_Finalize'Class) + return Node_Iterator_Type is + Handle: constant Node_Iterator_Handle := + librdf_model_get_sources(Get_Handle(Model), Get_Handle(Arc), Get_Handle(Target)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_model_get_arcs (Model: Model_Handle; Source, Target: Node_Handle) + return Node_Iterator_Handle + with Import, Convention=>C; + + function Get_Arcs (Model: Model_Type_Without_Finalize; + Source, Target: Node_Type_Without_Finalize'Class) + return Node_Iterator_Type is + Handle: constant Node_Iterator_Handle := + librdf_model_get_arcs(Get_Handle(Model), Get_Handle(Source), Get_Handle(Target)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_model_get_targets (Model: Model_Handle; Source, Arc: Node_Handle) + return Node_Iterator_Handle + with Import, Convention=>C; + + function Get_Targets (Model: Model_Type_Without_Finalize; + Source, Arc: Node_Type_Without_Finalize'Class) + return Node_Iterator_Type is + Handle: constant Node_Iterator_Handle := + librdf_model_get_targets(Get_Handle(Model), Get_Handle(Source), Get_Handle(Arc)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_model_get_source (Model: Model_Handle; Arc, Target: Node_Handle) return Node_Handle + with Import, Convention=>C; + + function Get_Source (Model: Model_Type_Without_Finalize; + Arc, Target: Node_Type_Without_Finalize'Class) + return Node_Type is + Handle: constant Node_Handle := + librdf_model_get_source(Get_Handle(Model), Get_Handle(Arc), Get_Handle(Target)); + begin + return From_Handle(Handle); + end; + + function librdf_model_get_arc (Model: Model_Handle; Source, Target: Node_Handle) return Node_Handle + with Import, Convention=>C; + + function Get_Arc (Model: Model_Type_Without_Finalize; + Source, Target: Node_Type_Without_Finalize'Class) + return Node_Type is + Handle: constant Node_Handle := + librdf_model_get_arc(Get_Handle(Model), Get_Handle(Source), Get_Handle(Target)); + begin + return From_Handle(Handle); + end; + + function librdf_model_get_target (Model: Model_Handle; Source, Arc: Node_Handle) return Node_Handle + with Import, Convention=>C; + + function Get_Target (Model: Model_Type_Without_Finalize; + Source, Arc: Node_Type_Without_Finalize'Class) + return Node_Type is + Handle: constant Node_Handle := + librdf_model_get_target(Get_Handle(Model), Get_Handle(Source), Get_Handle(Arc)); + begin + return From_Handle(Handle); + end; + + function librdf_model_add_submodel (Model, Submodel: Model_Handle) return int + with Import, Convention=>C; + + procedure Add_Submodel (Model: Model_Type_Without_Finalize; + Submodel: Model_Type_Without_Finalize'Class) is + begin + if librdf_model_add_submodel(Get_Handle(Model), Get_Handle(Submodel)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_remove_submodel (Model, Submodel: Model_Handle) return int + with Import, Convention=>C; + + procedure Remove_Submodel (Model: Model_Type_Without_Finalize; + Submodel: Model_Type_Without_Finalize'Class) is + begin + if librdf_model_remove_submodel(Get_Handle(Model), Get_Handle(Submodel)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_context_as_stream (Model: Model_Handle; Context: Node_Handle) return Stream_Handle + with Import, Convention=>C; + + function Context_As_Stream (Model: Model_Type_Without_Finalize; + Context: Node_Type_Without_Finalize'Class) + return Stream_Type is + begin + return From_Non_Null_Handle(librdf_model_context_as_stream(Get_Handle(Model), Get_Handle(Context))); + end; + + function librdf_model_contains_context (Model: Model_Handle; Context: Node_Handle) return int + with Import, Convention=>C; + + function Contains_Context (Model: Model_Type_Without_Finalize; + Context: Node_Type_Without_Finalize'Class) + return Boolean is + begin + return librdf_model_contains_context(Get_Handle(Model), Get_Handle(Context)) /= 0; + end; + + function librdf_model_supports_contexts (Model: Model_Handle) return int + with Import, Convention=>C; + + function Supports_Context (Model: Model_Type_Without_Finalize) return Boolean is + (librdf_model_supports_contexts(Get_Handle(Model)) /= 0); + + function librdf_model_query_execute (Model: Model_Handle; Query: Query_Handle) + return Query_Results_Handle + with Import, Convention=>C; + + function Query_Execute (Model: Model_Type_Without_Finalize; + Query: Query_Type_Without_Finalize'Class) + return Query_Results_Type is + begin + return From_Non_Null_Handle(librdf_model_query_execute(Get_Handle(Model), Get_Handle(Query))); + end; + + function librdf_model_sync (Model: Model_Handle) return int + with Import, Convention=>C; + + procedure Sync (Model: Model_Type_Without_Finalize) is + begin + if librdf_model_sync(Get_Handle(Model)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_get_storage (Model: Model_Handle) return Storage_Handle + with Import, Convention=>C; + + function Get_Storage (Model: Model_Type_Without_Finalize) return Storage_Type_Without_Finalize is + begin + return From_Handle(librdf_model_get_storage(Get_Handle(Model))); + end; + + function librdf_model_load (Model: Model_Handle; + URI: URI_Handle; + Name, Mime_Type: chars_ptr; + Type_URI: URI_Handle) + return int + with Import, Convention=>C; + + procedure Load (Model: Model_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Name, Mime_Type: String := ""; + Type_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + Name2: aliased char_array := To_C(Name); + Mime_Type2: aliased char_array := To_C(Mime_Type); + begin + if librdf_model_load(Get_Handle(Model), + Get_Handle(URI), + (if Name = "" then Null_Ptr else To_Chars_Ptr(Name2'Unchecked_Access)), + (if Mime_Type = "" then Null_Ptr else To_Chars_Ptr(Mime_Type2'Unchecked_Access)), + Get_Handle(Type_URI)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + type Size_T_P is access all size_t with Convention=>C; + + function librdf_model_to_counted_string (Model: Model_Handle; + URI: URI_Handle; + Name, Mime_Type: chars_ptr; + Type_URI: URI_Handle; + Length: Size_T_P) + return chars_ptr + with Import, Convention=>C; + + function To_String (Model: Model_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Name, Mime_Type: String := ""; + Type_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return String is + Name2: aliased char_array := To_C(Name); + Mime_Type2: aliased char_array := To_C(Mime_Type); + Length: aliased size_t; + Result: constant chars_ptr := + librdf_model_to_counted_string(Get_Handle(Model), + Get_Handle(URI), + (if Name = "" then Null_Ptr else To_Chars_Ptr(Name2'Unchecked_Access)), + (if Mime_Type = "" then Null_Ptr else To_Chars_Ptr(Mime_Type2'Unchecked_Access)), + Get_Handle(Type_URI), + Length'Unchecked_Access); + begin + return Value_With_Possible_NULs(Convert(Result), Length); + end; + + function librdf_model_find_statements_in_context (Model: Model_Handle; + Statement: Statement_Handle; + Context: Node_Handle) + return Stream_Handle + with Import, Convention=>C; + + function Find_In_Context (Model: Model_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class; + Context: Node_Type_Without_Finalize'Class) + return Stream_Type is + Handle: constant Stream_Handle := + librdf_model_find_statements_in_context(Get_Handle(Model), Get_Handle(Statement), Get_Handle(Context)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_model_get_contexts (Model: Model_Handle) return Node_Iterator_Handle + with Import, Convention=>C; + + function Get_Contexts (Model: Model_Type_Without_Finalize) return Node_Iterator_Type is + begin + return From_Non_Null_Handle(librdf_model_get_contexts(Get_Handle(Model))); + end; + + function librdf_model_get_feature (Model: Model_Handle; Feature: URI_Handle) return Node_Handle + with Import, Convention=>C; + + function Get_Feature (Model: Model_Type_Without_Finalize; + Feature: URI_Type_Without_Finalize'Class) + return Node_Type is + begin + return From_Handle(librdf_model_get_feature(Get_Handle(Model), Get_Handle(Feature))); + end; + + function librdf_model_set_feature (Model: Model_Handle; Feature: URI_Handle; Value: Node_Handle) + return int + with Import, Convention=>C; + + procedure Set_Feature (Model: in out Model_Type_Without_Finalize; + Feature: URI_Type_Without_Finalize'Class; + Value: Node_Type_Without_Finalize) is + begin + if librdf_model_set_feature(Get_Handle(Model), Get_Handle(Feature), Get_Handle(Value)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_model_write (Model: Model_Handle; Stream: IOStream_Handle) return int + with Import, Convention=>C; + + procedure Write (Model: Model_Type_Without_Finalize; Stream: IOStream_Type_Without_Finalize'Class) is + begin + if librdf_model_write(Get_Handle(Model), Get_Handle(Stream)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + +end RDF.Redland.Model; diff --git a/ada/src/rdf-redland-model.ads b/ada/src/rdf-redland-model.ads new file mode 100644 index 000000000..9135e806a --- /dev/null +++ b/ada/src/rdf-redland-model.ads @@ -0,0 +1,230 @@ +with Ada.Containers.Indefinite_Holders; +with Ada.Iterator_Interfaces; +with Interfaces.C; use Interfaces.C; +with RDF.Auxiliary; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Redland.World; use RDF.Redland.World; +with RDF.Redland.URI; use RDF.Redland.URI; +with RDF.Redland.Node; use RDF.Redland.Node; +with RDF.Redland.Statement; use RDF.Redland.Statement; +with RDF.Redland.Stream; use RDF.Redland.Stream; +with RDF.Redland.Storage; use RDF.Redland.Storage; +with RDF.Redland.Node_Iterator; use RDF.Redland.Node_Iterator; +with RDF.Redland.Query; use RDF.Redland.Query; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; +with RDF.Redland.Query_Results; use RDF.Redland.Query_Results; + +package RDF.Redland.Model is + + -- Use Limited_Handled_Record because despite a model can be copied, + -- copying may be a very expensive operation. Use Copy function instead. + -- See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62042 + package Model_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + type Model_Type_Without_Finalize is new Model_Handled_Record.Base_Object with null record; + + subtype Model_Handle is Model_Handled_Record.Access_Type; + + overriding procedure Finalize_Handle (Object: Model_Type_Without_Finalize; Handle: Model_Handle); + + type Model_Info (Name_Length, Label_Length: Natural) is + record + Name : String(1..Name_Length ); + Label: String(1..Label_Length); + end record; + + package Model_Info_Holders is new Ada.Containers.Indefinite_Holders(Model_Info); + + function Enumerate_Models (World: Redland_World_Type_Without_Finalize'Class; + Counter: unsigned) + return Model_Info_Holders.Holder; + + type Enumerate_Models_Cursor is private; + + function Has_Element (Position: Enumerate_Models_Cursor) return Boolean; + + package Enumerate_Models_Interfaces is + new Ada.Iterator_Interfaces(Enumerate_Models_Cursor, Has_Element); + + type Enumerate_Models_Iterator is new Enumerate_Models_Interfaces.Forward_Iterator with private; + + overriding function First (Object: Enumerate_Models_Iterator) return Enumerate_Models_Cursor; + + overriding function Next (Object: Enumerate_Models_Iterator; Position: Enumerate_Models_Cursor) + return Enumerate_Models_Cursor; + + -- FIXME: Forgotten to retrieve data from Enumerate_Models_Cursor (now this works only in D) + + not overriding function Size_Without_Exception (Model: Model_Type_Without_Finalize) + return Integer; + + not overriding function Size (Model: Model_Type_Without_Finalize) return Natural; + + not overriding procedure Add (Model: in out Model_Type_Without_Finalize; + Subject, Predicate, Object: Node_Type_Without_Finalize'Class); + + not overriding procedure Add (Model: in out Model_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class; + Context: Node_Type_Without_Finalize'Class := Node_Type_Without_Finalize'(From_Handle(null))) + with Pre => Is_Complete(Statement); + + not overriding procedure Add (Model: in out Model_Type_Without_Finalize; + Statements: Stream_Type_Without_Finalize'Class; + Context: Node_Type_Without_Finalize'Class := Node_Type_Without_Finalize'(From_Handle(null))); + + not overriding procedure Remove (Model: Model_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class); + + not overriding procedure Remove (Model: in out Model_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class; + Context: Node_Type_Without_Finalize'Class := Node_Type_Without_Finalize'(From_Handle(null))) + with Pre => Is_Complete(Statement); + + not overriding procedure Remove (Model: in out Model_Type_Without_Finalize; + Statements: Stream_Type_Without_Finalize'Class; + Context: Node_Type_Without_Finalize'Class := Node_Type_Without_Finalize'(From_Handle(null))); + + not overriding function Contains (Model: Model_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class) + return Boolean; + + not overriding function Has_Arc_In (Model: Model_Type_Without_Finalize; + Node, Property: Node_Type_Without_Finalize'Class) + return Boolean; + + not overriding function Has_Arc_Out (Model: Model_Type_Without_Finalize; + Node, Property: Node_Type_Without_Finalize'Class) + return Boolean; + + not overriding function As_Stream (Model: Model_Type_Without_Finalize) return Stream_Type; + + not overriding function Find (Model: Model_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class) + return Stream_Type; + + -- LIBRDF_MODEL_FIND_OPTION_MATCH_SUBSTRING_LITERAL not implemented. + + -- librdf_model_find_statements_with_options() not implemented as requires rdf_hash. + + not overriding function Get_Sources (Model: Model_Type_Without_Finalize; + Arc, Target: Node_Type_Without_Finalize'Class) + return Node_Iterator_Type; + + not overriding function Get_Arcs (Model: Model_Type_Without_Finalize; + Source, Target: Node_Type_Without_Finalize'Class) + return Node_Iterator_Type; + + not overriding function Get_Targets (Model: Model_Type_Without_Finalize; + Source, Arc: Node_Type_Without_Finalize'Class) + return Node_Iterator_Type; + + not overriding function Get_Source (Model: Model_Type_Without_Finalize; + Arc, Target: Node_Type_Without_Finalize'Class) + return Node_Type; + + not overriding function Get_Arc (Model: Model_Type_Without_Finalize; + Source, Target: Node_Type_Without_Finalize'Class) + return Node_Type; + + not overriding function Get_Target (Model: Model_Type_Without_Finalize; + Source, Arc: Node_Type_Without_Finalize'Class) + return Node_Type; + + -- TODO: Forgotten to implement librdf_model_get_arcs_in() & librdf_model_get_arcs_out() + + not overriding procedure Add_Submodel (Model: Model_Type_Without_Finalize; + Submodel: Model_Type_Without_Finalize'Class); + + not overriding procedure Remove_Submodel (Model: Model_Type_Without_Finalize; + Submodel: Model_Type_Without_Finalize'Class); + + not overriding function Context_As_Stream (Model: Model_Type_Without_Finalize; + Context: Node_Type_Without_Finalize'Class) + return Stream_Type; + + not overriding function Contains_Context (Model: Model_Type_Without_Finalize; + Context: Node_Type_Without_Finalize'Class) + return Boolean; + + not overriding function Supports_Context (Model: Model_Type_Without_Finalize) return Boolean; + + not overriding function Query_Execute (Model: Model_Type_Without_Finalize; + Query: Query_Type_Without_Finalize'Class) + return Query_Results_Type; + + not overriding procedure Sync (Model: Model_Type_Without_Finalize); + + not overriding function Get_Storage (Model: Model_Type_Without_Finalize) + return Storage_Type_Without_Finalize; + + not overriding procedure Load (Model: Model_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Name, Mime_Type: String := ""; + Type_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + not overriding function To_String (Model: Model_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Name, Mime_Type: String := ""; + Type_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return String; + + not overriding function Find_In_Context (Model: Model_Type_Without_Finalize; + Statement: Statement_Type_Without_Finalize'Class; + Context: Node_Type_Without_Finalize'Class) + return Stream_Type; + + not overriding function Get_Contexts (Model: Model_Type_Without_Finalize) return Node_Iterator_Type; + + Feature_Contexts: constant URI_String := "http://feature.librdf.org/model-contexts"; + + not overriding function Get_Feature (Model: Model_Type_Without_Finalize; + Feature: URI_Type_Without_Finalize'Class) + return Node_Type; + + not overriding procedure Set_Feature (Model: in out Model_Type_Without_Finalize; + Feature: URI_Type_Without_Finalize'Class; + Value: Node_Type_Without_Finalize); + + not overriding procedure Add_String_Literal_Statement (Model: Model_Type_Without_Finalize; + Subject, Predicate: Node_Type_Without_Finalize'Class; + Literal: String; + Language: String; + Is_XML: Boolean := False); + + not overriding procedure Add_Typed_Literal_Statement (Model: Model_Type_Without_Finalize; + Subject, Predicate: Node_Type_Without_Finalize'Class; + Literal: String; + Language: String; + Datatype: URI_Type_Without_Finalize'Class); + + not overriding procedure Write (Model: Model_Type_Without_Finalize; Stream: IOStream_Type_Without_Finalize'Class); + + package Handlers is new Model_Handled_Record.Common_Handlers(Model_Type_Without_Finalize); + + type Model_Type is new Handlers.Base_With_Finalization with null record; + + type Model_Type_User is new Handlers.User_Type with null record; + + not overriding function Create (World: Redland_World_Type_Without_Finalize'Class; + Storage: Storage_Type_Without_Finalize'Class; + Options: String := "") + return Model_Type; + + -- librdf_new_model_with_options() not implemented, because librdf_hash is not implemented + + not overriding function Copy (Model: Model_Type_Without_Finalize'Class) return Model_Type; + +private + + type Enumerate_Models_Cursor is + record + World: Redland_World_Handle; + Counter: unsigned; + end record; + + type Enumerate_Models_Iterator is new Enumerate_Models_Interfaces.Forward_Iterator with + record + World: Redland_World_Handle; + end record; + +end RDF.Redland.Model; diff --git a/ada/src/rdf-redland-node.adb b/ada/src/rdf-redland-node.adb new file mode 100644 index 000000000..62652c689 --- /dev/null +++ b/ada/src/rdf-redland-node.adb @@ -0,0 +1,346 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; +with RDF.Auxiliary.C_Pointers; + +package body RDF.Redland.Node is + + function To_Raptor (Node: Node_Type_Without_Finalize'Class) return Term_Type_Without_Finalize is + begin + return From_Handle(Get_Handle(Node)); + end; + + function From_Raptor (Term: Term_Type_Without_Finalize'Class) return Node_Type_Without_Finalize is + begin + return From_Handle(Get_Handle(Term)); + end; + + procedure librdf_free_node (Node: Node_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Node_Type_Without_Finalize; Handle: Node_Handle) is + begin + librdf_free_node(Handle); + end; + + function librdf_new_node (World: Redland_World_Handle) return Node_Handle + with Import, Convention=>C; + + function Create (World: Redland_World_Type_Without_Finalize'Class) return Node_Type is + begin + return From_Non_Null_Handle(librdf_new_node(Get_Handle(World))); + end; + +-- function librdf_new_node_from_blank_identifier (World: Redland_World_Handle; +-- Pointer: char_array_access) +-- return Node_Handle +-- with Import, Convention=>C; + + function librdf_new_node_from_counted_blank_identifier (World: Redland_World_Handle; + Pointer: char_array_access; + Len: size_t) + return Node_Handle + with Import, Convention=>C; + + function From_Blank_Identifier (World: Redland_World_Type_Without_Finalize'Class; + ID: String) + return Node_Type is + ID2: aliased char_array := My_To_C_Without_Nul(ID); + Pointer: constant char_array_access := (if ID = "" then null else ID2'Unchecked_Access); + Handle: constant Node_Handle := + librdf_new_node_from_counted_blank_identifier(Get_Handle(World), Pointer, ID'Length); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_node_from_counted_uri_string (World: Redland_World_Handle; + Pointer: char_array; + Len: size_t) + return Node_Handle + with Import, Convention=>C; + + function From_URI_String (World: Redland_World_Type_Without_Finalize'Class; + URI: URI_String) + return Node_Type is + Handle: constant Node_Handle := + librdf_new_node_from_counted_uri_string(Get_Handle(World), To_C(String(URI)), URI'Length); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_node_from_literal (World: Redland_World_Handle; + Text, Language: char_array; + Is_XML: int) + return Node_Handle + with Import, Convention=>C; + + function From_Literal (World: Redland_World_Type_Without_Finalize'Class; + Text: String; + Language: String; + Is_XML: Boolean := False) + return Node_Type is + Handle: constant Node_Handle := + librdf_new_node_from_literal(Get_Handle(World), + My_To_C_Without_Nul(Text), + My_To_C_Without_Nul(Language), + (if Is_XML then 1 else 0)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_node_from_node (Node: Node_Handle) return Node_Handle + with Import, Convention=>C; + + function Adjust_Handle (Object: Node_Type_Without_Finalize; Handle: Node_Handle) return Node_Handle is + begin + return librdf_new_node_from_node(Handle); + end; + + function librdf_new_node_from_normalised_uri_string (World: Redland_World_Handle; + URI_String: char_array; + Source_URI, Base_URI: URI_Handle) + return Node_Handle + with Import, Convention=>C; + + function From_Normalised_URI_String (World: Redland_World_Type_Without_Finalize'Class; + URI: URI_String; + Source_URI, Base_URI: URI_Type_Without_Finalize'Class) + return Node_Type is + Handle: constant Node_Handle := + librdf_new_node_from_normalised_uri_string(Get_Handle(World), + My_To_C_Without_Nul(String(URI)), + Get_Handle(Source_URI), + Get_Handle(Base_URI)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_node_from_typed_counted_literal (World: Redland_World_Handle; + Text: char_array; + Text_Len: size_t; + Language: char_array; + Language_Len: size_t; + Datatype: URI_Handle) + return Node_Handle + with Import, Convention=>C; + + function From_Typed_Literal (World: Redland_World_Type_Without_Finalize'Class; + Text: String; + Language: String; + Datatype: URI_Type_Without_Finalize'Class) + return Node_Type is + Handle: constant Node_Handle := + librdf_new_node_from_typed_counted_literal(Get_Handle(World), + My_To_C_Without_Nul(Text), + size_t(Text'Length), + My_To_C_Without_Nul(Language), + size_t(Language'Length), + Get_Handle(Datatype)); + + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_node_from_uri (World: Redland_World_Handle; URI: URI_Handle) + return Node_Handle + with Import, Convention=>C; + + function From_URI (World: Redland_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class) + return Node_Type is + begin + return From_Non_Null_Handle(librdf_new_node_from_uri(Get_Handle(World), Get_Handle(URI))); + end; + + function librdf_new_node_from_uri_local_name (World: Redland_World_Handle; + URI: URI_Handle; + Local_Name: char_array) + return Node_Handle + with Import, Convention=>C; + + function From_URI_Local_Name (World: Redland_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class; + Local_Name: String) + return Node_Type is + Handle: constant Node_Handle := + librdf_new_node_from_uri_local_name(Get_Handle(World), + Get_Handle(URI), + My_To_C_Without_Nul(Local_Name)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_node_decode (World: Redland_World_Handle; + Size_P: chars_ptr; + Buffer: char_array; + Length: size_t) + return Node_Handle + with Import, Convention=>C; + + function Decode (World: Redland_World_Type_Without_Finalize'Class; + Buffer: String) + return Node_Type is + Handle: constant Node_Handle := + librdf_node_decode(Get_Handle(World), Null_Ptr, My_To_C_Without_Nul(Buffer), Buffer'Length); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_node_encode (Node: Node_Handle; Buffer: char_array_access; Length: size_t) return size_t + with Import, Convention=>C; + + function Encode (Node: Node_Type_Without_Finalize) return String is + Length: constant size_t := librdf_node_encode(Get_Handle(Node), null, 0); +-- Buffer: aliased char_array(1..Length); -- GNAT 7.2.0 produces a warning + Buffer: aliased char_array := (1..Length => NUL); -- + Length2: constant size_t := librdf_node_encode(Get_Handle(Node), Buffer'Unchecked_Access, Length); + pragma Unreferenced(Length2); + begin + return To_Ada(Buffer, Trim_Nul=>False); + end; + + function librdf_node_equals (Left, Right: Node_Handle) return int + with Import, Convention=>C; + + function Equals (Left, Right: Node_Type_Without_Finalize) return Boolean is + begin + return librdf_node_equals(Get_Handle(Left), Get_Handle(Right)) /= 0; + end; + + type Size_T_P is access all size_t with Convention=>C; + + function librdf_node_get_counted_blank_identifier (Node: Node_Handle; Length: Size_T_P) + return RDF.Auxiliary.C_Pointers.Pointer + with Import, Convention=>C; + + function Get_Blank_Identifier (Node: Blank_Node_Type_Without_Finalize'Class) return String is + Length: aliased size_t; + Buffer: constant RDF.Auxiliary.C_Pointers.Pointer := + librdf_node_get_counted_blank_identifier(Get_Handle(Node), Length'Unchecked_Access); + begin + return Value_With_Possible_NULs(Buffer, Length); + end; + + function librdf_node_get_li_ordinal (Node: Node_Handle) return int + with Import, Convention=>C; + + function Get_Li_Ordinal (Node: Node_Type_Without_Finalize) return Positive is + Result: constant int := librdf_node_get_li_ordinal(Get_Handle(Node)); + begin + if Result <= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Positive(Result); + end; + + function librdf_node_get_literal_value_as_counted_string (Node: Node_Handle; + Length: Size_T_P) + return RDF.Auxiliary.C_Pointers.Pointer + with Import, Convention=>C; + + function As_String (Node: Node_Type_Without_Finalize) return String is + Length: aliased size_t; + Buffer: constant RDF.Auxiliary.C_Pointers.Pointer := + librdf_node_get_literal_value_as_counted_string(Get_Handle(Node), Length'Unchecked_Access); + use RDF.Auxiliary.C_Pointers; + begin + if Buffer = null then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Value_With_Possible_NULs(Buffer, Length); + end; + + function librdf_node_get_literal_value_as_latin1 (Node: Node_Handle) return chars_ptr + with Import, Convention=>C; + + function As_Latin1 (Node: Node_Type_Without_Finalize) return String is + Result: constant chars_ptr := librdf_node_get_literal_value_as_latin1(Get_Handle(Node)); + begin + if Result = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Value(Result); + end; + + function librdf_node_get_literal_value_datatype_uri (Node: Node_Handle) return URI_Handle + with Import, Convention=>C; + + function Get_Datatype_URI (Node: Node_Type_Without_Finalize) return URI_Type_Without_Finalize is + begin + return From_Handle(librdf_node_get_literal_value_datatype_uri(Get_Handle(Node))); + end; + + function librdf_node_get_literal_value_is_wf_xml (Node: Node_Handle) return int + with Import, Convention=>C; + + function Is_WF_XML (Node: Node_Type_Without_Finalize) return Boolean is + begin + return librdf_node_get_literal_value_is_wf_xml(Get_Handle(Node)) /= 0; + end; + + function librdf_node_get_literal_value_language (Node: Node_Handle) return chars_ptr + with Import, Convention=>C; + + function Get_Language (Node: Node_Type_Without_Finalize) return String is + Ptr: constant chars_ptr := librdf_node_get_literal_value_language(Get_Handle(Node)); + begin + return (if Ptr /= Null_Ptr then Value(Ptr) else ""); + end; + + function librdf_node_get_type (Node: Node_Handle) return Node_Kind + with Import, Convention=>C; + + function Get_Type (Node: Node_Type_Without_Finalize) return Node_Kind is + begin + return librdf_node_get_type(Get_Handle(Node)); + end; + + function librdf_node_get_uri (Node: Node_Handle) return URI_Handle + with Import, Convention=>C; + + function Get_URI (Node: Node_Type_Without_Finalize) return URI_Type_Without_Finalize is + begin + return From_Non_Null_Handle(librdf_node_get_uri(Get_Handle(Node))); + end; + + function librdf_node_is_blank (Node: Node_Handle) return int + with Import, Convention=>C; + function librdf_node_is_literal (Node: Node_Handle) return int + with Import, Convention=>C; + function librdf_node_is_resource (Node: Node_Handle) return int + with Import, Convention=>C; + + function Is_Blank (Node: Node_Type_Without_Finalize) return Boolean is + (librdf_node_is_blank(Get_Handle(Node)) /= 0); + function Is_Literal (Node: Node_Type_Without_Finalize) return Boolean is + (librdf_node_is_literal(Get_Handle(Node)) /= 0); + function Is_Resource (Node: Node_Type_Without_Finalize) return Boolean is + (librdf_node_is_resource(Get_Handle(Node)) /= 0); + + -- FIXME: File argument forgotten + procedure librdf_node_print (Node: Node_Handle) + with Import, Convention=>C; + + procedure Print (Node: Node_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access) is + begin + librdf_node_print(Get_Handle(Node)); + end; + + function librdf_node_write (Node: Node_Handle; Stream: IOStream_Handle) return int + with Import, Convention=>C; + + procedure Write (Node: Node_Type_Without_Finalize; Stream: IOStream_Type_Without_Finalize'Class) is + begin + if librdf_node_write(Get_Handle(Node), Get_Handle(Stream)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function Format_As_String (Node: Node_Type_Without_Finalize) return String is + Stream: RDF.Raptor.IOStream.Stream_To_String; + begin + Write(Node, Stream); + return Value(Stream); + end; + +end RDF.Redland.Node; diff --git a/ada/src/rdf-redland-node.ads b/ada/src/rdf-redland-node.ads new file mode 100644 index 000000000..67e8821b7 --- /dev/null +++ b/ada/src/rdf-redland-node.ads @@ -0,0 +1,123 @@ +with RDF.Redland.World; use RDF.Redland.World; +with RDF.Redland.URI; use RDF.Redland.URI; +with RDF.Auxiliary; +with RDF.Raptor.Term; use RDF.Raptor.Term; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; + +package RDF.Redland.Node is + + subtype Node_Kind is RDF.Raptor.Term.Term_Kind; + + subtype Node_Handle is RDF.Raptor.Term.Term_Handle; + + type Node_Type_Without_Finalize is new RDF.Raptor.Term.Term_Handled_Record.Base_Object with null record; + + subtype Blank_Node_Type_Without_Finalize is Node_Type_Without_Finalize + with Dynamic_Predicate => Is_Blank(Blank_Node_Type_Without_Finalize); + subtype Literal_Node_Type_Without_Finalize is Node_Type_Without_Finalize + with Dynamic_Predicate => Is_Literal(Literal_Node_Type_Without_Finalize); + subtype Resource_Node_Type_Without_Finalize is Node_Type_Without_Finalize + with Dynamic_Predicate => Is_Resource(Resource_Node_Type_Without_Finalize); + + overriding procedure Finalize_Handle (Object: Node_Type_Without_Finalize; Handle: Node_Handle); + + overriding function Adjust_Handle (Object: Node_Type_Without_Finalize; Handle: Node_Handle) return Node_Handle; + + function To_Raptor (Node: Node_Type_Without_Finalize'Class) return Term_Type_Without_Finalize; + + not overriding function From_Raptor (Term: Term_Type_Without_Finalize'Class) return Node_Type_Without_Finalize; + + not overriding function Encode (Node: Node_Type_Without_Finalize) return String; + + not overriding function Equals (Left, Right: Node_Type_Without_Finalize) return Boolean; + + overriding function "=" (Left, Right: Node_Type_Without_Finalize) return Boolean + renames Equals; + + function Get_Blank_Identifier (Node: Blank_Node_Type_Without_Finalize'Class) return String; + + not overriding function Get_Li_Ordinal (Node: Node_Type_Without_Finalize) return Positive; + + not overriding function As_String (Node: Node_Type_Without_Finalize) return String; + + not overriding function As_Latin1 (Node: Node_Type_Without_Finalize) return String; + + not overriding function Get_Datatype_URI (Node: Node_Type_Without_Finalize) return URI_Type_Without_Finalize; + + not overriding function Is_WF_XML (Node: Node_Type_Without_Finalize) return Boolean; + + -- Return "" if no language + not overriding function Get_Language (Node: Node_Type_Without_Finalize) return String; + + not overriding function Get_Type (Node: Node_Type_Without_Finalize) return Node_Kind; + + not overriding function Get_URI (Node: Node_Type_Without_Finalize) return URI_Type_Without_Finalize; + + not overriding function Is_Blank (Node: Node_Type_Without_Finalize) return Boolean; + not overriding function Is_Literal (Node: Node_Type_Without_Finalize) return Boolean; + not overriding function Is_Resource (Node: Node_Type_Without_Finalize) return Boolean; + + -- librdf_node_write() deliberately not bound + + not overriding procedure Print (Node: Node_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access); + + not overriding procedure Write (Node: Node_Type_Without_Finalize; Stream: IOStream_Type_Without_Finalize'Class); + + -- Not a binding, but our own implementation + not overriding function Format_As_String (Node: Node_Type_Without_Finalize) return String; + + package Handlers is new RDF.Raptor.Term.Term_Handled_Record.Common_Handlers(Node_Type_Without_Finalize); + + type Node_Type is new Handlers.Base_With_Finalization with null record; + + type Node_Type_User is new Handlers.User_Type with null record; + + not overriding function Create (World: Redland_World_Type_Without_Finalize'Class) return Node_Type; + + -- "No identifier" is signified by empty string + not overriding function From_Blank_Identifier (World: Redland_World_Type_Without_Finalize'Class; + ID: String) + return Node_Type; + + not overriding function From_URI_String (World: Redland_World_Type_Without_Finalize'Class; + URI: URI_String) + return Node_Type; + + not overriding function From_Literal (World: Redland_World_Type_Without_Finalize'Class; + Text: String; + Language: String; + Is_XML: Boolean := False) + return Node_Type; + + not overriding function From_Normalised_URI_String (World: Redland_World_Type_Without_Finalize'Class; + URI: URI_String; + Source_URI, Base_URI: URI_Type_Without_Finalize'Class) + return Node_Type; + + -- FIXME: It does not correspond to .adb file + not overriding function From_Typed_Literal (World: Redland_World_Type_Without_Finalize'Class; Text: String; + Language: String; + Datatype: URI_Type_Without_Finalize'Class) + return Node_Type; + + not overriding function From_URI (World: Redland_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class) + return Node_Type; + + not overriding function From_URI_Local_Name (World: Redland_World_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class; + Local_Name: String) + return Node_Type; + + not overriding function Decode (World: Redland_World_Type_Without_Finalize'Class; + Buffer: String) + return Node_Type; + + subtype Blank_Node_Type is Node_Type + with Dynamic_Predicate => Is_Blank(Blank_Node_Type); + subtype Literal_Node_Type is Node_Type + with Dynamic_Predicate => Is_Literal(Literal_Node_Type); + subtype Resource_Node_Type is Node_Type + with Dynamic_Predicate => Is_Resource(Resource_Node_Type); + +end RDF.Redland.Node; diff --git a/ada/src/rdf-redland-node_iterator.adb b/ada/src/rdf-redland-node_iterator.adb new file mode 100644 index 000000000..0b61cf05d --- /dev/null +++ b/ada/src/rdf-redland-node_iterator.adb @@ -0,0 +1,34 @@ +with Ada.Containers.Vectors; +with RDF.Auxiliary.Convert_Void; +with RDF.Raptor.Term; use RDF.Raptor.Term; + +package body RDF.Redland.Node_Iterator is + + package My_Conv is new RDF.Auxiliary.Convert_Void(Term_Record); + + function Get_Node (Iterator: Node_Iterator_Type_Without_Finalize) + return Node_Type_Without_Finalize is + Ptr: constant My_Conv.Object_Pointer := My_Conv.To_Access(Get_Object_Internal(Iterator)); + begin + return From_Non_Null_Handle(Node_Handle(Ptr)); + end; + + function To_Array (Iterator: in out Node_Iterator_Type_Without_Finalize) return Node_Array is + package V is new Ada.Containers.Vectors(Ada.Containers.Count_Type, Node_Type); + Result: V.Vector; + begin + while not Is_End(Iterator) loop + V.Append(Result, Copy(Get_Node(Iterator))); + Next(Iterator); + end loop; + declare + Result2: Node_Array(1..V.Length(Result)); + begin + for I in Result2'Range loop + Result2(I) := Result.Element(I); + end loop; + return Result2; + end; + end; + +end RDF.Redland.Node_Iterator; diff --git a/ada/src/rdf-redland-node_iterator.ads b/ada/src/rdf-redland-node_iterator.ads new file mode 100644 index 000000000..9a0dc247c --- /dev/null +++ b/ada/src/rdf-redland-node_iterator.ads @@ -0,0 +1,26 @@ +with Ada.Containers; +with RDF.Redland.Iterator; use RDF.Redland.Iterator; +with RDF.Redland.Node; use RDF.Redland.Node; + +package RDF.Redland.Node_Iterator is + + type Node_Iterator_Type_Without_Finalize is new Iterator_Type_Without_Finalize with null record; + + subtype Node_Iterator_Handle is Iterator_Handle; + + not overriding function Get_Node (Iterator: Node_Iterator_Type_Without_Finalize) + return Node_Type_Without_Finalize; + + type Node_Array is array (Ada.Containers.Count_Type range <>) of Node_Type; + + -- Note that after this operation Iterator is not usable + not overriding function To_Array (Iterator: in out Node_Iterator_Type_Without_Finalize) + return Node_Array; + + package Handlers is new Iterator_Handled_Record.Common_Handlers(Node_Iterator_Type_Without_Finalize); + + type Node_Iterator_Type is new Handlers.Base_With_Finalization with null record; + + type Node_Iterator_Type_User is new Handlers.User_Type with null record; + +end RDF.Redland.Node_Iterator; diff --git a/ada/src/rdf-redland-parser.adb b/ada/src/rdf-redland-parser.adb new file mode 100644 index 000000000..f71292fe4 --- /dev/null +++ b/ada/src/rdf-redland-parser.adb @@ -0,0 +1,308 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.C_String_Holders; use RDF.Auxiliary.C_String_Holders; +with RDF.Redland.Memory; + +package body RDF.Redland.Parser is + + function librdf_parser_check_name (World: Redland_World_Handle; Name: char_array) return int + with Import, Convention=>C; + + function Parser_Check_Name (World: Redland_World_Type_Without_Finalize'Class; Name: String) + return Boolean is + begin + return librdf_parser_check_name(Get_Handle(World), To_C(Name)) /= 0; + end; + + function librdf_parser_guess_name2 (World: Redland_World_Handle; + Mime_Type, Buffer, Identifier: chars_ptr) + return chars_ptr + with Import, Convention=>C; + + function Parser_Guess_Name (World: Redland_World_Type_Without_Finalize'Class; + Mime_Type, Identifier: String; + Buffer: String_Holders.Holder := String_Holders.Empty_Holder) + return String is + Mime_Type2 : aliased char_array := To_C(Mime_Type ); + Identifier2: aliased char_array := To_C(Identifier); + Result: constant chars_ptr := + librdf_parser_guess_name2(Get_Handle(World), + (if Mime_Type = "" then Null_Ptr else To_Chars_Ptr(Mime_Type2'Unchecked_Access)), + C_String(To_C_String_Holder(Buffer)), + (if Identifier = "" then Null_Ptr else To_Chars_Ptr(Identifier2'Unchecked_Access))); + begin + return (if Result = Null_Ptr then "" else Value(Result)); + end; + + function librdf_parser_get_description (World: Redland_World_Handle; Counter: unsigned) + return Raptor_Syntax_Description_Type + with Import, Convention=>C; + + function Get_Parser_Description (World: Redland_World_Type_Without_Finalize'Class; + Counter: Natural) + return Raptor_Syntax_Description_Type is + begin + return librdf_parser_get_description(Get_Handle(World), unsigned(Counter)); + end; + + function Has_Element (Position: Parser_Description_Cursor) return Boolean is + begin + return librdf_parser_get_description(Position.World, unsigned(Position.Position)) /= null; + end; + + function First (Object: Parser_Description_Iterator) return Parser_Description_Cursor is + begin + return (Position=>0, World=>Object.World); + end; + + function Next (Object: Parser_Description_Iterator; Position: Parser_Description_Cursor) + return Parser_Description_Cursor is + begin + return (Position=>Position.Position+1, World=>Position.World); + end; + + function Get_Description (Cursor: Parser_Description_Cursor) + return Raptor_Syntax_Description_Type is + begin + return librdf_parser_get_description(Cursor.World, unsigned(Cursor.Position)); + end; + + function Get_Position (Cursor: Parser_Description_Cursor) return Natural is + begin + return Cursor.Position; + end; + + function Create_Parser_Descriptions_Iterator(World: Redland_World_Type_Without_Finalize'Class) + return Parser_Description_Iterator is + begin + return (World=>Get_Handle(World)); + end; + + function librdf_new_parser (World: Redland_World_Handle; + Name: char_array; + Mime_Type: chars_ptr; + Type_URI: URI_Handle) + return Parser_Handle + with Import, Convention=>C; + + function Create (World: Redland_World_Type_Without_Finalize'Class; + Name, Mime_Type: String := ""; + Type_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Parser_Type is + Mime_Type2: aliased char_array := To_C(Mime_Type); + Handle: constant Parser_Handle := + librdf_new_parser(Get_Handle(World), + To_C(Name), + (if Mime_Type = "" then Null_Ptr else To_Chars_Ptr(Mime_Type2'Unchecked_Access)), + Get_Handle(Type_URI)); + begin + return From_Handle(Handle); + end; + + procedure librdf_free_parser (Handle: Parser_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Parser_Type_Without_Finalize; Handle: Parser_Handle) is + begin + librdf_free_parser(Handle); + end; + + function librdf_parser_parse_as_stream (Parser: Parser_Handle; URI, Base_URI: URI_Handle) + return Stream_Handle + with Import, Convention=>C; + + function As_Stream (Parser: Parser_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Stream_Type is + Handle: constant Stream_Handle := + librdf_parser_parse_as_stream(Get_Handle(Parser), Get_Handle(URI), Get_Handle(Base_URI)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_parser_parse_into_model (Parser: Parser_Handle; + URI, Base_URI: URI_Handle; + Model: Model_Handle) + return int + with Import, Convention=>C; + + procedure Parse_Into_Model (Parser: Parser_Type_Without_Finalize; + Model: in out Model_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_parser_parse_into_model(Get_Handle(Parser), + Get_Handle(URI), + Get_Handle(Base_URI), + Get_Handle(Model)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_parser_parse_file_handle_as_stream (Parser: Parser_Handle; + File: RDF.Auxiliary.C_File_Access; + Close: int; + Base_URI: URI_Handle) + return Stream_Handle + with Import, Convention=>C; + + function Parse_File_Handle_As_Stream (Parser: Parser_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access; + Close: Boolean; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Stream_Type is + Handle: constant Stream_Handle := + librdf_parser_parse_file_handle_as_stream(Get_Handle(Parser), + File, + (if Close then 1 else 0), + Get_Handle(Base_URI)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_parser_parse_file_handle_into_model (Parser: Parser_Handle; + File: RDF.Auxiliary.C_File_Access; + Close: int; + Base_URI: URI_Handle; + Model: Model_Handle) + return int + with Import, Convention=>C; + + procedure Parse_File_Handle_Into_Model (Parser: Parser_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access; + Close: Boolean; + Model: in out Model_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_parser_parse_file_handle_into_model(Get_Handle(Parser), + File, + (if Close then 1 else 0), + Get_Handle(Base_URI), + Get_Handle(Model)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_parser_parse_counted_string_as_stream (Parser: Parser_Handle; Text: char_array; Length: size_t; Base_URI: URI_Handle) + return Stream_Handle + with Import, Convention=>C; + + function Parse_String_As_Stream (Parser: Parser_Type_Without_Finalize; + Text: String; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Stream_Type is + Handle: constant Stream_Handle := + librdf_parser_parse_counted_string_as_stream(Get_Handle(Parser), + To_C(Text, Append_Nul=>False), + size_t(Text'Length), + Get_Handle(Base_URI)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_parser_parse_counted_string_into_model (Parser: Parser_Handle; + Text: char_array; + Length: size_t; + Base_URI: URI_Handle; + Model: Model_Handle) + return int + with Import, Convention=>C; + + procedure Parse_String_Into_Model (Parser: Parser_Type_Without_Finalize; + Model: Model_Type_Without_Finalize'Class; + Text: String; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_parser_parse_counted_string_into_model(Get_Handle(Parser), + To_C(Text, Append_Nul=>False), + Text'Length, + Get_Handle(Base_URI), + Get_Handle(Model)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_parser_parse_iostream_as_stream (Parser: Parser_Handle; + IOStream: IOStream_Handle; + Base_URI: URI_Handle) + return Stream_Handle + with Import, Convention=>C; + + function Parse_IOStream_As_Stream (Parser: Parser_Type_Without_Finalize; + IOStream: IOStream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Stream_Type is + Handle: constant Stream_Handle := + librdf_parser_parse_iostream_as_stream(Get_Handle(Parser), Get_Handle(IOStream), Get_Handle(Base_URI)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_parser_parse_iostream_into_model (Parser: Parser_Handle; + IOStream: IOStream_Handle; + Base_URI: URI_Handle; + Model: Model_Handle) + return int + with Import, Convention=>C; + + procedure Parse_IOStream_Into_Model (Parser: Parser_Type_Without_Finalize; + Model: Model_Type_Without_Finalize'Class; + IOStream: IOStream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_parser_parse_iostream_into_model(Get_Handle(Parser), + Get_Handle(IOStream), + Get_Handle(Base_URI), + Get_Handle(Model)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_parser_get_feature (Parser: Parser_Handle; Feature: URI_Handle) + return Node_Handle + with Import, Convention=>C; + + function Get_Feature (Parser: Parser_Type_Without_Finalize; Feature: URI_Type_Without_Finalize'Class) + return Node_Type is + begin + return From_Handle(librdf_parser_get_feature(Get_Handle(Parser), Get_Handle(Feature))); + end; + + function librdf_parser_set_feature (Parser: Parser_Handle; + Feature: URI_Handle; + Value: Node_Handle) + return int + with Import, Convention=>C; + + procedure Set_Feature (Parser: Parser_Type_Without_Finalize; + Feature: URI_Type_Without_Finalize'Class; + Value: Node_Type'Class) is + begin + if librdf_parser_set_feature(Get_Handle(Parser), Get_Handle(Feature), Get_Handle(Value)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_parser_get_accept_header (Parser: Parser_Handle) return chars_ptr + with Import, Convention=>C; + + function Get_Accept_Header (Parser: Parser_Type_Without_Finalize) return String is + Ptr: constant chars_ptr := librdf_parser_get_accept_header(Get_Handle(Parser)); + begin + if Ptr = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Result: constant String := Value(Ptr); + begin + RDF.Redland.Memory.librdf_free_memory(Ptr); + return Result; + end; + end; + +end RDF.Redland.Parser; diff --git a/ada/src/rdf-redland-parser.ads b/ada/src/rdf-redland-parser.ads new file mode 100644 index 000000000..df46be5a1 --- /dev/null +++ b/ada/src/rdf-redland-parser.ads @@ -0,0 +1,151 @@ +with Ada.Iterator_Interfaces; +with RDF.Auxiliary; use RDF.Auxiliary; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; +with RDF.Raptor.Syntaxes; use RDF.Raptor.Syntaxes; +with RDF.Redland.World; use RDF.Redland.World; +with RDF.Redland.URI; use RDF.Redland.URI; +with RDF.Redland.Node; use RDF.Redland.Node; +with RDF.Redland.Stream; use RDF.Redland.Stream; +with RDF.Redland.Model; use RDF.Redland.Model; + +package RDF.Redland.Parser is + + package Parser_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + type Parser_Type_Without_Finalize is new Parser_Handled_Record.Base_Object with null record; + + subtype Parser_Handle is Parser_Handled_Record.Access_Type; + + overriding procedure Finalize_Handle (Object: Parser_Type_Without_Finalize; Handle: Parser_Handle); + + function Parser_Check_Name (World: Redland_World_Type_Without_Finalize'Class; Name: String) + return Boolean; + + -- Order of arguments not the same as in C + function Parser_Guess_Name (World: Redland_World_Type_Without_Finalize'Class; + Mime_Type, Identifier: String; + Buffer: String_Holders.Holder := String_Holders.Empty_Holder) + return String; + + function Get_Parser_Description (World: Redland_World_Type_Without_Finalize'Class; + Counter: Natural) + return Raptor_Syntax_Description_Type; + + type Parser_Description_Cursor is private; + + function Get_Position (Cursor: Parser_Description_Cursor) return Natural; + + function Get_Description (Cursor: Parser_Description_Cursor) return Raptor_Syntax_Description_Type; + + function Has_Element (Position: Parser_Description_Cursor) return Boolean; + + package Parser_Description_Iterators is new Ada.Iterator_Interfaces(Parser_Description_Cursor, Has_Element); + + type Parser_Description_Iterator is new Parser_Description_Iterators.Forward_Iterator with private; + + overriding function First (Object: Parser_Description_Iterator) return Parser_Description_Cursor; + overriding function Next (Object: Parser_Description_Iterator; Position: Parser_Description_Cursor) + return Parser_Description_Cursor; + + function Create_Parser_Descriptions_Iterator (World: Redland_World_Type_Without_Finalize'Class) + return Parser_Description_Iterator; + + not overriding function As_Stream (Parser: Parser_Type_Without_Finalize; + URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Stream_Type; + + -- order of arguments differs of C function + not overriding procedure Parse_Into_Model (Parser: Parser_Type_Without_Finalize; + Model: in out Model_Type_Without_Finalize'Class; + URI: URI_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + not overriding + function Parse_File_Handle_As_Stream (Parser: Parser_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access; + Close: Boolean; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Stream_Type; + + -- order of arguments differs of C function + not overriding + procedure Parse_File_Handle_Into_Model (Parser: Parser_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access; + Close: Boolean; + Model: in out Model_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + not overriding + function Parse_String_As_Stream (Parser: Parser_Type_Without_Finalize; + Text: String; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Stream_Type + with Pre => (Text /= ""); + + -- order of arguments differs of C function + not overriding + procedure Parse_String_Into_Model (Parser: Parser_Type_Without_Finalize; + Model: Model_Type_Without_Finalize'Class; + Text: String; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + not overriding + function Parse_IOStream_As_Stream (Parser: Parser_Type_Without_Finalize; + IOStream: IOStream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Stream_Type; + + -- order of arguments differs of C function + not overriding + procedure Parse_IOStream_Into_Model (Parser: Parser_Type_Without_Finalize; + Model: Model_Type_Without_Finalize'Class; + IOStream: IOStream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + FEATURE_ERROR_COUNT : URI_String := "http://feature.librdf.org/parser-error-count"; + FEATURE_WARNING_COUNT: URI_String := "http://feature.librdf.org/parser-warning-count"; + + not overriding + function Get_Feature (Parser: Parser_Type_Without_Finalize; Feature: URI_Type_Without_Finalize'Class) + return Node_Type; + + not overriding procedure Set_Feature (Parser: Parser_Type_Without_Finalize; + Feature: URI_Type_Without_Finalize'Class; + Value: Node_Type'Class); -- FIXME: Without_Finalize + + not overriding function Get_Accept_Header (Parser: Parser_Type_Without_Finalize) return String; + + -- librdf_parser_get_namespaces_seen_count(), + -- librdf_parser_get_namespaces_seen_prefix(), + -- librdf_parser_get_namespaces_seen_uri() + -- not bound as internals + + -- librdf_parser_get_uri_filter() and librdf_parser_set_uri_filter() + + package Handlers is new Parser_Handled_Record.Common_Handlers(Parser_Type_Without_Finalize); + + type Parser_Type is new Handlers.Base_With_Finalization with null record; + + type Parser_Type_User is new Handlers.User_Type with null record; + + not overriding function Create (World: Redland_World_Type_Without_Finalize'Class; + Name, Mime_Type: String := ""; + Type_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Parser_Type; + +private + + type Parser_Description_Cursor is + record + World: Redland_World_Handle; + Position: Natural; + end record; + + type Parser_Description_Iterator is new Parser_Description_Iterators.Forward_Iterator with + record + World: Redland_World_Handle; + end record; + +end RDF.Redland.Parser; diff --git a/ada/src/rdf-redland-query.adb b/ada/src/rdf-redland-query.adb new file mode 100644 index 000000000..dbc3a6dad --- /dev/null +++ b/ada/src/rdf-redland-query.adb @@ -0,0 +1,103 @@ +with Interfaces.C; use Interfaces.C; + +package body RDF.Redland.Query is + + function librdf_query_language_get_description (World: Redland_World_Handle; Counter: unsigned) + return Raptor_Syntax_Description_Type + with Import, Convention=>C; + + function Get_Query_Language_Description (World: Redland_World_Type_Without_Finalize'Class; + Counter: Natural) + return Raptor_Syntax_Description_Type is + begin + return librdf_query_language_get_description(Get_Handle(World), unsigned(Counter)); + end; + + function Has_Element (Position: Query_Language_Description_Cursor) return Boolean is + begin + return librdf_query_language_get_description(Position.World, unsigned(Position.Position)) /= null; + end; + + function First (Object: Query_Language_Description_Iterator) return Query_Language_Description_Cursor is + begin + return (Position=>0, World=>Object.World); + end; + + function Next (Object: Query_Language_Description_Iterator; Position: Query_Language_Description_Cursor) + return Query_Language_Description_Cursor is + begin + return (Position=>Position.Position+1, World=>Position.World); + end; + + function Get_Description (Cursor: Query_Language_Description_Cursor) + return Raptor_Syntax_Description_Type is + begin + return librdf_query_language_get_description(Cursor.World, unsigned(Cursor.Position)); + end; + + function Get_Position (Cursor: Query_Language_Description_Cursor) return Natural is + begin + return Cursor.Position; + end; + + function Create_Query_Language_Descriptions_Iterator(World: Redland_World_Type_Without_Finalize'Class) + return Query_Language_Description_Iterator is + begin + return (World=>Get_Handle(World)); + end; + + function librdf_new_query (World: Redland_World_Handle; + Name: char_array; + URI: URI_Handle; + Query_String: char_array; + Base_URI: URI_Handle) + return Query_Handle + with Import, Convention=>C; + + function Create (World: Redland_World_Type_Without_Finalize'Class; + Name: String; + Query_String: String; + URI, Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Query_Type is + Handle: constant Query_Handle := librdf_new_query(Get_Handle(World), + To_C(Name), + Get_Handle(URI), + To_C(Query_String), + Get_Handle(Base_URI)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_query_from_query (Query: Query_Handle) return Query_Handle + with Import, Convention=>C; + +-- function Adjust_Handle (Object: Query_Type_Without_Finalize; Handle: Query_Handle) return Query_Handle is +-- begin +-- return librdf_new_query_from_query(Handle); +-- end; + + function Copy (Query: Query_Type_Without_Finalize'Class) return Query_Type is + begin + return From_Non_Null_Handle(librdf_new_query_from_query(Get_Handle(Query))); + end; + + procedure librdf_free_query (Query: Query_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Query_Type_Without_Finalize; Handle: Query_Handle) is + begin + librdf_free_query(Handle); + end; + +-- function librdf_query_execute (Query: Query_Handle; Model: Model_Handle) return Query_Results_Handle +-- with Import, Convention=>C; +-- +-- function Execute (Query: Query_Type_Without_Finalize; +-- Model: Model_Type_Without_Finalize'Class) +-- return Query_Results_Type is +-- Handle: constant Query_Results_Handle := librdf_query_execute(Get_Handle(Query), Get_Handle(Model)); +-- begin +-- return From_Non_Null_Handle(Handle); +-- end; + +end RDF.Redland.Query; diff --git a/ada/src/rdf-redland-query.ads b/ada/src/rdf-redland-query.ads new file mode 100644 index 000000000..0493dc01e --- /dev/null +++ b/ada/src/rdf-redland-query.ads @@ -0,0 +1,77 @@ +with Ada.Iterator_Interfaces; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.Syntaxes; use RDF.Raptor.Syntaxes; +with RDF.Redland.World; use RDF.Redland.World; +with RDF.Redland.URI; use RDF.Redland.URI; + +package RDF.Redland.Query is + + package Query_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + type Query_Type_Without_Finalize is new RDF.Redland.Query.Query_Handled_Record.Base_Object with null record; + + subtype Query_Handle is Query_Handled_Record.Access_Type; + + overriding procedure Finalize_Handle (Object: Query_Type_Without_Finalize; Handle: Query_Handle); + +-- overriding function Adjust_Handle (Object: Query_Type_Without_Finalize; Handle: Query_Handle) return Query_Handle; + + function Get_Query_Language_Description (World: Redland_World_Type_Without_Finalize'Class; + Counter: Natural) + return Raptor_Syntax_Description_Type; + + type Query_Language_Description_Cursor is private; + + function Get_Position (Cursor: Query_Language_Description_Cursor) return Natural; + + function Get_Description (Cursor: Query_Language_Description_Cursor) return Raptor_Syntax_Description_Type; + + function Has_Element (Position: Query_Language_Description_Cursor) return Boolean; + + package Query_Language_Description_Iterators is new Ada.Iterator_Interfaces(Query_Language_Description_Cursor, Has_Element); + + type Query_Language_Description_Iterator is new Query_Language_Description_Iterators.Forward_Iterator with private; + + overriding function First (Object: Query_Language_Description_Iterator) return Query_Language_Description_Cursor; + overriding function Next (Object: Query_Language_Description_Iterator; Position: Query_Language_Description_Cursor) + return Query_Language_Description_Cursor; + + function Create_Query_Language_Descriptions_Iterator (World: Redland_World_Type_Without_Finalize'Class) + return Query_Language_Description_Iterator; + + -- TODO: How to do this without a circular dependency? +-- not overriding function Execute (Query: Query_Type_Without_Finalize; +-- Model: Model_Type_Without_Finalize'Class) +-- return Query_Results_Type; + + package Handlers is new Query_Handled_Record.Common_Handlers(Query_Type_Without_Finalize); + + type Query_Type is new Handlers.Base_With_Finalization with null record; + + type Query_Type_User is new Handlers.User_Type with null record; + + -- Order of arguments not the same as in C + not overriding + function Create (World: Redland_World_Type_Without_Finalize'Class; + Name: String; + Query_String: String; + URI, Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Query_Type; + + -- It seems that this is buggy (see count_test2.adb) + not overriding function Copy (Query: Query_Type_Without_Finalize'Class) return Query_Type; + +private + + type Query_Language_Description_Cursor is + record + World: Redland_World_Handle; + Position: Natural; + end record; + + type Query_Language_Description_Iterator is new Query_Language_Description_Iterators.Forward_Iterator with + record + World: Redland_World_Handle; + end record; + +end RDF.Redland.Query; diff --git a/ada/src/rdf-redland-query_results.adb b/ada/src/rdf-redland-query_results.adb new file mode 100644 index 000000000..f8ec12435 --- /dev/null +++ b/ada/src/rdf-redland-query_results.adb @@ -0,0 +1,285 @@ +with Ada.Containers; +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; +with RDF.Auxiliary.C_Pointers; use RDF.Auxiliary.C_Pointers; +with RDF.Redland.Memory; + +package body RDF.Redland.Query_Results is + + function librdf_query_results_as_stream (Results: Query_Results_Handle) return Stream_Handle + with Import, Convention=>C; + + function As_Stream (Results: Query_Results_Type_Without_Finalize) return Stream_Type is + begin + return From_Non_Null_Handle(librdf_query_results_as_stream(Get_Handle(Results))); + end; + + function librdf_query_results_get_count (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Get_Current_Count (Results: Query_Results_Type_Without_Finalize) return Natural is + begin + return Natural(librdf_query_results_get_count(Get_Handle(Results))); + end; + + function librdf_query_results_next (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + procedure Next (Results: Query_Results_Type_Without_Finalize'Class) is + begin + if librdf_query_results_next(Get_Handle(Results)) /= 0 then + -- Check is done by Finished procedure, not here + null; -- raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_query_results_finished (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Finished (Results: Query_Results_Type_Without_Finalize) return Boolean is + (librdf_query_results_finished(Get_Handle(Results)) /= 0); + + function librdf_query_results_get_bindings_count (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Get_Bindings_Count (Results: Bindings_Query_Results_Type_Without_Finalize'Class) + return Natural is + Result: constant int := librdf_query_results_get_bindings_count(Get_Handle(Results)); + begin + if Result < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Natural(Result); + end; + + type chars_ptr_ptr is access chars_ptr with Convention=>C; + type chars_ptr_ptr_ptr is access all chars_ptr_ptr with Convention=>C; + type Node_Handle_ptr is access all Node_Handle with Convention=>C; + + function librdf_query_results_get_bindings (Results: Query_Results_Handle; + Names: chars_ptr_ptr_ptr; + Values: Node_Handle_ptr) + return int + with Import, Convention=>C; + + function Get_Binding_Names (Results: Bindings_Query_Results_Type_Without_Finalize'Class) + return String_List_Type is + Count: constant Natural := Get_Bindings_Count(Results); + type chars_ptr_ptr_array is array(1..Count) of aliased chars_ptr_ptr; + Names: aliased chars_ptr_ptr_array; + Code: constant int := + librdf_query_results_get_bindings(Get_Handle(Results), Names(1)'Unchecked_Access, null); + begin + if Code /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Result: String_List_Type do + Reserve_Capacity(Result, Ada.Containers.Count_Type(Count)); + for Name of Names loop + Append(Result, Value(Name.all)); + end loop; + end return; + end; + + function Get_Binding_Values (Results: Bindings_Query_Results_Type_Without_Finalize'Class) + return Node_List_Type is + Count: constant Natural := Get_Bindings_Count(Results); + type Node_Handle_array is array(1..Count) of aliased Node_Handle; + Values: aliased Node_Handle_array; + Code: constant int := + librdf_query_results_get_bindings(Get_Handle(Results), null, Values(1)'Unchecked_Access); + begin + if Code /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Result: Node_List_Type do + Reserve_Capacity(Result, Ada.Containers.Count_Type(Count)); + for Value of Values loop + Append(Result, From_Non_Null_Handle(Value)); + end loop; + end return; + end; + + function librdf_query_results_get_binding_value (Results: Query_Results_Handle; Index: int) + return Node_Handle + with Import, Convention=>C; + + function Get_Binding_Value (Results: Bindings_Query_Results_Type_Without_Finalize'Class; Index: Natural) + return Node_Type is + begin + return From_Non_Null_Handle(librdf_query_results_get_binding_value(Get_Handle(Results), int(Index))); + end; + + function librdf_query_results_get_binding_name (Results: Query_Results_Handle; Index: int) + return chars_ptr + with Import, Convention=>C; + + function Get_Binding_Name (Results: Bindings_Query_Results_Type_Without_Finalize'Class; Index: Natural) + return String is + Ptr: constant chars_ptr := librdf_query_results_get_binding_name(Get_Handle(Results), int(Index)); + begin + if Ptr = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Value(Ptr); + end; + + function librdf_query_results_get_binding_value_by_name (Results: Query_Results_Handle; + Name: char_array) + return Node_Handle + with Import, Convention=>C; + + function Get_Binding_Value_By_Name (Results: Bindings_Query_Results_Type_Without_Finalize'Class; Name: String) + return Node_Type is + Handle: constant Node_Handle := + librdf_query_results_get_binding_value_by_name(Get_Handle(Results), To_C(Name)); + begin + return From_Non_Null_Handle(Handle); + end; + + type Size_T_P is access all size_t; + + function librdf_query_results_to_counted_string2(Results: Query_Results_Handle; + Name, Mime_Type: chars_ptr; + Format_URI, Base_URI: URI_Handle; + Length: Size_T_P) + return RDF.Auxiliary.C_Pointers.Pointer + with Import, Convention=>C; + + function To_String (Results: Query_Results_Type_Without_Finalize; + Name: String := ""; + Mime_Type: String := ""; + Format_URI, Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return String is + Name2: aliased char_array := To_C(Name); + Mime_Type2: aliased char_array := To_C(Mime_Type); + Length: aliased size_t; + Ptr: constant RDF.Auxiliary.C_Pointers.Pointer := + librdf_query_results_to_counted_string2(Get_Handle(Results), + (if Name = "" then Null_Ptr else To_Chars_Ptr(Name2'Unchecked_Access)), + (if Mime_Type = "" then Null_Ptr else To_Chars_Ptr(Mime_Type2'Unchecked_Access)), + Get_Handle(Format_URI), + Get_Handle(Base_URI), + Length'Unchecked_Access); + begin + if Ptr = null then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Str: constant String := Value_With_Possible_NULs(Ptr, Length); + begin + RDF.Redland.Memory.librdf_free_memory(Convert(Ptr)); + return Str; + end; + end; + + function librdf_query_results_to_file_handle2 (Results: Query_Results_Handle; + File: RDF.Auxiliary.C_File_Access; + Name, Mime_Type: chars_ptr; + Format_URI, Base_URI: URI_Handle) + return int + with Import, Convention=>C; + + procedure To_File_Handle (Results: Query_Results_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access; + Name: String := ""; + Mime_Type: String := ""; + Format_URI, Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + Name2: aliased char_array := To_C(Name); + Mime_Type2: aliased char_array := To_C(Mime_Type); + Result: constant int := + librdf_query_results_to_file_handle2(Get_Handle(Results), + File, + (if Name = "" then Null_Ptr else To_Chars_Ptr(Name2'Unchecked_Access)), + (if Mime_Type = "" then Null_Ptr else To_Chars_Ptr(Mime_Type2'Unchecked_Access)), + Get_Handle(Format_URI), + Get_Handle(Base_URI)); + begin + if Result /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + procedure librdf_free_query_results (Results: Query_Results_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Query_Results_Type_Without_Finalize; + Handle: Query_Results_Handle) is + begin + librdf_free_query_results(Handle); + end; + + function librdf_query_results_is_bindings (Results: Query_Results_Handle) return int + with Import, Convention=>C; + function librdf_query_results_is_boolean (Results: Query_Results_Handle) return int + with Import, Convention=>C; + function librdf_query_results_is_graph (Results: Query_Results_Handle) return int + with Import, Convention=>C; + function librdf_query_results_is_syntax (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Is_Bindings (Results: Query_Results_Type_Without_Finalize) return Boolean is + (librdf_query_results_is_bindings(Get_Handle(Results)) /= 0); + function Is_Boolean (Results: Query_Results_Type_Without_Finalize) return Boolean is + (librdf_query_results_is_boolean(Get_Handle(Results)) /= 0); + function Is_Graph (Results: Query_Results_Type_Without_Finalize) return Boolean is + (librdf_query_results_is_graph(Get_Handle(Results)) /= 0); + function Is_Syntax (Results: Query_Results_Type_Without_Finalize) return Boolean is + (librdf_query_results_is_syntax(Get_Handle(Results)) /= 0); + + function librdf_query_results_get_boolean (Results: Query_Results_Handle) return int + with Import, Convention=>C; + + function Get_Boolean (Results: Boolean_Query_Results_Type_Without_Finalize'Class) return Boolean is + Result: constant int := librdf_query_results_get_boolean(Get_Handle(Results)); + begin + if Result < 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + return Result /= 0; + end; + + function Has_Element (Position: Cursor) return Boolean is + (Not_Finished(Position.all)); + + function Create_Bindings_Iterator (Results: in out Bindings_Query_Results_Type_Without_Finalize'Class) + return Bindings_Iterator is + (Ref=>Results'Unchecked_Access); + + function First (Object: Bindings_Iterator) return Cursor is + (Object.Ref); + + function Next (Object: Bindings_Iterator; Position: Cursor) return Cursor is + begin + Next(Position.all); + return Position; + end; + + function Get_Binding_Value (Position: Cursor; + Offset: Natural) + return Node_Type is + (Get_Binding_Value(Position.all, Offset)); + + function Get_Binding_Value_By_Name (Position: Cursor; + Name: String) + return Node_Type is + (Get_Binding_Value_By_Name(Position.all, Name)); + + function Has_Element (Position: Variables_Cursor) return Boolean is + (Position.Count < Get_Bindings_Count(Position.Ref.all)); + + function Create_Variables_Iterator (Results: Bindings_Query_Results_Type_Without_Finalize'Class) + return Variables_Iterator is + (Ref=>Results'Unchecked_Access); + + function First (Object: Variables_Iterator) return Variables_Cursor is + (Ref=>Object.Ref, Count=>0); + + function Next (Object: Variables_Iterator; Position: Variables_Cursor) return Variables_Cursor is + (Position with delta Count=>Position.Count); + + function Get_Name (Position: Variables_Cursor) return String is + (Get_Binding_Name(Position.Ref.all, Position.Count)); + +end RDF.Redland.Query_Results; diff --git a/ada/src/rdf-redland-query_results.ads b/ada/src/rdf-redland-query_results.ads new file mode 100644 index 000000000..337cb9669 --- /dev/null +++ b/ada/src/rdf-redland-query_results.ads @@ -0,0 +1,169 @@ +with Ada.Iterator_Interfaces; +with Ada.Containers.Indefinite_Vectors; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Redland.URI; use RDF.Redland.URI; +with RDF.Redland.Node; use RDF.Redland.Node; +with RDF.Redland.Stream; use RDF.Redland.Stream; + +package RDF.Redland.Query_Results is + + package Query_Results_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + type Query_Results_Type_Without_Finalize is new RDF.Redland.Query_Results.Query_Results_Handled_Record.Base_Object with null record; + + subtype Query_Results_Handle is Query_Results_Handled_Record.Access_Type; + + subtype Bindings_Query_Results_Type_Without_Finalize is Query_Results_Type_Without_Finalize + with Dynamic_Predicate => Is_Bindings(Bindings_Query_Results_Type_Without_Finalize); + subtype Boolean_Query_Results_Type_Without_Finalize is Query_Results_Type_Without_Finalize + with Dynamic_Predicate => Is_Boolean(Boolean_Query_Results_Type_Without_Finalize); + subtype Graph_Query_Results_Type_Without_Finalize is Query_Results_Type_Without_Finalize + with Dynamic_Predicate => Is_Graph(Graph_Query_Results_Type_Without_Finalize); + subtype Syntax_Query_Results_Type_Without_Finalize is Query_Results_Type_Without_Finalize + with Dynamic_Predicate => Is_Syntax(Syntax_Query_Results_Type_Without_Finalize); + + overriding procedure Finalize_Handle (Object: Query_Results_Type_Without_Finalize; + Handle: Query_Results_Handle); + + not overriding function As_Stream (Results: Query_Results_Type_Without_Finalize) return Stream_Type; + + not overriding function Get_Current_Count (Results: Query_Results_Type_Without_Finalize) return Natural; + + procedure Next (Results: Query_Results_Type_Without_Finalize'Class) + with Pre => Is_Bindings(Results) or Is_Graph(Results); + + not overriding function Finished (Results: Query_Results_Type_Without_Finalize) return Boolean + with Pre'Class => Is_Bindings(Results) or Is_Graph(Results); + + not overriding function Not_Finished (Results: Query_Results_Type_Without_Finalize) return Boolean is + (not Finished(Results)); + + function Get_Bindings_Count (Results: Bindings_Query_Results_Type_Without_Finalize'Class) + return Natural; -- or shall we use Positive? + + package String_Lists is new Ada.Containers.Indefinite_Vectors(Natural, String); + type String_List_Type is new String_Lists.Vector with null record; + + function Get_Binding_Names (Results: Bindings_Query_Results_Type_Without_Finalize'Class) + return String_List_Type; + + package Node_Lists is new Ada.Containers.Indefinite_Vectors(Natural, Node_Type); + type Node_List_Type is new Node_Lists.Vector with null record; + + function Get_Binding_Values (Results: Bindings_Query_Results_Type_Without_Finalize'Class) + return Node_List_Type; + + function Get_Binding_Value (Results: Bindings_Query_Results_Type_Without_Finalize'Class; Index: Natural) + return Node_Type; + + function Get_Binding_Name (Results: Bindings_Query_Results_Type_Without_Finalize'Class; Index: Natural) + return String; + + function Get_Binding_Value_By_Name (Results: Bindings_Query_Results_Type_Without_Finalize'Class; Name: String) + return Node_Type; + + not overriding + function To_String (Results: Query_Results_Type_Without_Finalize; + Name: String := ""; + Mime_Type: String := ""; + Format_URI, Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return String; + + not overriding + procedure To_File_Handle (Results: Query_Results_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access; + Name: String := ""; + Mime_Type: String := ""; + Format_URI, Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + -- librdf_query_results_to_file2() is wrong: http://bugs.librdf.org/mantis/view.php?id=639 + + not overriding function Is_Bindings (Results: Query_Results_Type_Without_Finalize) return Boolean; + not overriding function Is_Boolean (Results: Query_Results_Type_Without_Finalize) return Boolean; + not overriding function Is_Graph (Results: Query_Results_Type_Without_Finalize) return Boolean; + not overriding function Is_Syntax (Results: Query_Results_Type_Without_Finalize) return Boolean; + + function Get_Boolean (Results: Boolean_Query_Results_Type_Without_Finalize'Class) return Boolean; + + -- I was lazy to implement query_results_formatter and related functions + + package Handlers is new Query_Results_Handled_Record.Common_Handlers(Query_Results_Type_Without_Finalize); + + -- The same cursor is used for bindings iterator and for Graph iterator. + -- However, don't rely on using the same type. + -- Do not create more than one cursor for the same query results object. + type Cursor is private; + + not overriding function Has_Element (Position: Cursor) return Boolean; + + package Base_Iterators is new Ada.Iterator_Interfaces(Cursor, Has_Element); + + type Bindings_Iterator is new Base_Iterators.Forward_Iterator with private; + + not overriding function Create_Bindings_Iterator (Results: in out Bindings_Query_Results_Type_Without_Finalize'Class) + return Bindings_Iterator; + + overriding function First (Object: Bindings_Iterator) return Cursor; + + overriding function Next (Object: Bindings_Iterator; Position: Cursor) return Cursor; + + not overriding function Get_Binding_Value (Position: Cursor; + Offset: Natural) + return Node_Type; + + not overriding function Get_Binding_Value_By_Name (Position: Cursor; + Name: String) + return Node_Type; + + type Query_Results_Type is new Handlers.Base_With_Finalization with null record; + + type Query_Results_Type_User is new Handlers.User_Type with null record; + + subtype Bindings_Query_Results_Type is Query_Results_Type + with Dynamic_Predicate => Is_Bindings(Bindings_Query_Results_Type); + subtype Boolean_Query_Results_Type is Query_Results_Type + with Dynamic_Predicate => Is_Boolean(Boolean_Query_Results_Type); + subtype Graph_Query_Results_Type is Query_Results_Type + with Dynamic_Predicate => Is_Graph(Graph_Query_Results_Type); + subtype Syntax_Query_Results_Type is Query_Results_Type + with Dynamic_Predicate => Is_Syntax(Syntax_Query_Results_Type); + + type Variables_Cursor is private; + + not overriding function Has_Element (Position: Variables_Cursor) return Boolean; + + package Variables_Iterators is new Ada.Iterator_Interfaces(Variables_Cursor, Has_Element); + + -- We can also make backward iterator, but I see no use cases for this + type Variables_Iterator is new Variables_Iterators.Forward_Iterator with private; + + not overriding function Create_Variables_Iterator (Results: Bindings_Query_Results_Type_Without_Finalize'Class) + return Variables_Iterator; + + overriding function First (Object: Variables_Iterator) return Variables_Cursor; + + overriding function Next (Object: Variables_Iterator; Position: Variables_Cursor) return Variables_Cursor; + + not overriding function Get_Name (Position: Variables_Cursor) return String; + +private + + type Cursor is access constant Query_Results_Type_Without_Finalize'Class; + + type Bindings_Iterator is new Base_Iterators.Forward_Iterator with + record + Ref: Cursor; + end record; + + type Variables_Cursor is + record + Ref: Cursor; -- hack + Count: Natural; + end record; + + type Variables_Iterator is new Variables_Iterators.Forward_Iterator with + record + Ref: Cursor; + end record; + +end RDF.Redland.Query_Results; diff --git a/ada/src/rdf-redland-serializer.adb b/ada/src/rdf-redland-serializer.adb new file mode 100644 index 000000000..3de9b7e2c --- /dev/null +++ b/ada/src/rdf-redland-serializer.adb @@ -0,0 +1,278 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; +with RDF.Redland.Memory; + +package body RDF.Redland.Serializer is + + function librdf_serializer_get_description (Serializer: Serializer_Handle; Index: unsigned) + return Raptor_Syntax_Description_Type + with Import, Convention=>C; + + function Get_Description (Serializer: Serializer_Type_Without_Finalize; Index: Natural) + return Raptor_Syntax_Description_Type is + begin + return librdf_serializer_get_description(Get_Handle(Serializer), unsigned(Index)); + end; + + function librdf_new_serializer (World: Redland_World_Handle; + Name, Mime_Type: chars_ptr; + Type_URI: URI_Handle) + return Serializer_Handle + with Import, Convention=>C; + + function Create (World: Redland_World_Type_Without_Finalize'Class; + Name, Mime_Type: String := ""; + Type_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Serializer_Type is + Name2: aliased char_array := To_C(Name); + Mime_Type2: aliased char_array := To_C(Mime_Type); + Handle: constant Serializer_Handle := + librdf_new_serializer(Get_Handle(World), + (if Name = "" then Null_Ptr else To_Chars_Ptr(Name2'Unchecked_Access)), + (if Mime_Type = "" then Null_Ptr else To_Chars_Ptr(Mime_Type2'Unchecked_Access)), + Get_Handle(Type_URI)); + begin + return From_Non_Null_Handle(Handle); + end; + + procedure librdf_free_serializer (Serializer: Serializer_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Serializer_Type_Without_Finalize; Handle: Serializer_Handle) is + begin + librdf_free_serializer(Handle); + end; + + function librdf_serializer_check_name (World: Redland_World_Handle; Name: char_array) + return int + with Import, Convention=>C; + + function Serializer_Check_Name (World: Redland_World_Type_Without_Finalize'Class; + Name: String) + return Boolean is + begin + return librdf_serializer_check_name(Get_Handle(World), To_C(Name)) /= 0; + end; + + function librdf_serializer_serialize_model_to_file_handle (Serializer: Serializer_Handle; + File: RDF.Auxiliary.C_File_Access; + Base_URI: URI_Handle; + Model: Model_Handle) + return int + with Import, Convention=>C; + + procedure Serialize_To_File_Handle (Serializer: Serializer_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access; + Model: Model_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_serializer_serialize_model_to_file_handle(Get_Handle(Serializer), + File, + Get_Handle(Base_URI), + Get_Handle(Model)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_serializer_serialize_model_to_file (Serializer: Serializer_Handle; + File_Name: char_array; + Base_URI: URI_Handle; + Model: Model_Handle) + return int + with Import, Convention=>C; + + procedure Serialize_To_File (Serializer: Serializer_Type_Without_Finalize; + File_Name: String; + Model: Model_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_serializer_serialize_model_to_file(Get_Handle(Serializer), + To_C(File_Name), + Get_Handle(Base_URI), + Get_Handle(Model)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + type Size_T_P is access all size_t with Convention=>C; + + function librdf_serializer_serialize_model_to_counted_string (Serialize: Serializer_Handle; + Base_URI: URI_Handle; + Model: Model_Handle; + Length: Size_T_P) + return chars_ptr + with Import, Convention=>C; + + function Serialize_To_String (Serializer: Serializer_Type_Without_Finalize; + Model: Model_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return String is + Length: aliased size_t; + Ptr: constant chars_ptr := + librdf_serializer_serialize_model_to_counted_string(Get_Handle(Serializer), + Get_Handle(Base_URI), + Get_Handle(Model), + Length'Unchecked_Access); + begin + if Ptr = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Str: constant String := Value_With_Possible_NULs(Convert(Ptr), Length); + begin + RDF.Redland.Memory.librdf_free_memory(Ptr); + return Str; + end; + end; + + function librdf_serializer_serialize_model_to_iostream (Serializer: Serializer_Handle; + Base_URI: URI_Handle; + Model: Model_Handle; + IOStream: IOStream_Handle) + return int + with Import, Convention=>C; + + procedure Serialize_Model_To_IOStream + (Serializer: Serializer_Type_Without_Finalize; + Model: Model_Type_Without_Finalize'Class; + IOStream: IOStream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_serializer_serialize_model_to_iostream(Get_Handle(Serializer), + Get_Handle(Base_URI), + Get_Handle(Model), + Get_Handle(IOStream)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_serializer_serialize_stream_to_counted_string (Serializer: Serializer_Handle; + Base_URI: URI_Handle; + Stream: IOStream_Handle; + Length: Size_T_P) + return chars_ptr + with Import, Convention=>C; + + function Serialize_To_String (Serializer: Serializer_Type_Without_Finalize; + Stream: Stream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return String is + Length: aliased size_t; + Ptr: constant chars_ptr := + librdf_serializer_serialize_stream_to_counted_string(Get_Handle(Serializer), + Get_Handle(Base_URI), + Get_Handle(Stream), + Length'Unchecked_Access); + begin + if Ptr = Null_Ptr then + raise RDF.Auxiliary.RDF_Exception; + end if; + declare + Str: constant String := Value_With_Possible_NULs(Convert(Ptr), Length); + begin + RDF.Redland.Memory.librdf_free_memory(Ptr); + return Str; + end; + end; + + function librdf_serializer_serialize_stream_to_file (Serializer: Serializer_Handle; + File_Name: char_array; + Base_URI: URI_Handle; + Stream: Stream_Handle) + return int + with Import, Convention=>C; + + procedure Serialize_To_File (Serializer: Serializer_Type_Without_Finalize; + File_Name: String; + Stream: Stream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_serializer_serialize_stream_to_file(Get_Handle(Serializer), + To_C(File_Name), + Get_Handle(Base_URI), + Get_Handle(Stream)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_serializer_serialize_stream_to_file_handle (Serializer: Serializer_Handle; + File: RDF.Auxiliary.C_File_Access; + Base_URI: URI_Handle; + Stream: Stream_Handle) + return int + with Import, Convention=>C; + + procedure Serialize_To_File_Handle (Serializer: Serializer_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access; + Stream: Stream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_serializer_serialize_stream_to_file_handle(Get_Handle(Serializer), + File, + Get_Handle(Base_URI), + Get_Handle(Stream)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_serializer_serialize_stream_to_iostream (Serializer: Serializer_Handle; + Base_URI: URI_Handle; + Stream: Stream_Handle; + File: IOStream_Handle) + return int + with Import, Convention=>C; + + procedure Serialize_To_IOStream (Serializer: Serializer_Type_Without_Finalize; + File: IOStream_Type_Without_Finalize'Class; + Stream: Stream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) is + begin + if librdf_serializer_serialize_stream_to_iostream(Get_Handle(Serializer), + Get_Handle(File), + Get_Handle(Base_URI), + Get_Handle(Stream)) /= 0 + then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function Has_Element (Position: Serializer_Description_Cursor) return Boolean is + begin + return librdf_serializer_get_description(Position.World, unsigned(Position.Position)) /= null; + end; + + function First (Object: Serializer_Description_Iterator) return Serializer_Description_Cursor is + begin + return (Position=>0, World=>Object.World); + end; + + function Next (Object: Serializer_Description_Iterator; Position: Serializer_Description_Cursor) + return Serializer_Description_Cursor is + begin + return (Position=>Position.Position+1, World=>Position.World); + end; + + function Get_Description (Cursor: Serializer_Description_Cursor) + return Raptor_Syntax_Description_Type is + begin + return librdf_serializer_get_description(Cursor.World, unsigned(Cursor.Position)); + end; + + function Get_Position (Cursor: Serializer_Description_Cursor) return Natural is + begin + return Cursor.Position; + end; + + function Create_Serializer_Descriptions_Iterator(World: Redland_World_Type_Without_Finalize'Class) + return Serializer_Description_Iterator is + begin + return (World=>Get_Handle(World)); + end; + +end RDF.Redland.Serializer; diff --git a/ada/src/rdf-redland-serializer.ads b/ada/src/rdf-redland-serializer.ads new file mode 100644 index 000000000..37f25aad6 --- /dev/null +++ b/ada/src/rdf-redland-serializer.ads @@ -0,0 +1,136 @@ +with Ada.Iterator_Interfaces; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; +with RDF.Raptor.Syntaxes; use RDF.Raptor.Syntaxes; +with RDF.Redland.World; use RDF.Redland.World; +with RDF.Redland.URI; use RDF.Redland.URI; +with RDF.Redland.Stream; use RDF.Redland.Stream; +with RDF.Redland.Model; use RDF.Redland.Model; + +package RDF.Redland.Serializer is + + package Serializer_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + type Serializer_Type_Without_Finalize is new RDF.Redland.Serializer.Serializer_Handled_Record.Base_Object with null record; + + subtype Serializer_Handle is Serializer_Handled_Record.Access_Type; + + overriding procedure Finalize_Handle (Object: Serializer_Type_Without_Finalize; + Handle: Serializer_Handle); + + -- FIXME: 1. rename to Get_Serializer_Description; 2. use World not Serializer + not overriding + function Get_Description (Serializer: Serializer_Type_Without_Finalize; Index: Natural) + return Raptor_Syntax_Description_Type; + + function Serializer_Check_Name (World: Redland_World_Type_Without_Finalize'Class; + Name: String) + return Boolean; + + -- Order of arguments not the same as in C + not overriding + procedure Serialize_To_File_Handle (Serializer: Serializer_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access; + Model: Model_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + -- Order of arguments not the same as in C + not overriding + procedure Serialize_To_File (Serializer: Serializer_Type_Without_Finalize; + File_Name: String; + Model: Model_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + -- Order of arguments not the same as in C + not overriding function Serialize_To_String (Serializer: Serializer_Type_Without_Finalize; + Model: Model_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return String; + + -- FIXME: Serialize_Model_To_IOStream -> Serialize_To_IOStream + -- Order of arguments not the same as in C + not overriding procedure Serialize_Model_To_IOStream + (Serializer: Serializer_Type_Without_Finalize; + Model: Model_Type_Without_Finalize'Class; + IOStream: IOStream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + -- Order of arguments not the same as in C + not overriding function Serialize_To_String (Serializer: Serializer_Type_Without_Finalize; + Stream: Stream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return String; + + -- Order of arguments not the same as in C + not overriding + procedure Serialize_To_File (Serializer: Serializer_Type_Without_Finalize; + File_Name: String; + Stream: Stream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + -- Order of arguments not the same as in C + not overriding + procedure Serialize_To_File_Handle (Serializer: Serializer_Type_Without_Finalize; + File: RDF.Auxiliary.C_File_Access; + Stream: Stream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + -- Order of arguments not the same as in C + not overriding + procedure Serialize_To_IOStream (Serializer: Serializer_Type_Without_Finalize; + File: IOStream_Type_Without_Finalize'Class; + Stream: Stream_Type_Without_Finalize'Class; + Base_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))); + + -- http://bugs.librdf.org/mantis/view.php?id=641 +-- not overriding function Get_Feature (Serializer: Serializer_Type_Without_Finalize; +-- Feature: URI_Type_Without_Finalize'Class); +-- return Node_Type; +-- not overriding function Set_Feature (Serializer: Serializer_Type_Without_Finalize; +-- Feature: URI_Type_Without_Finalize'Class; +-- Value: Node_Iterator_Type_Without_Finalize'Class); + + type Serializer_Description_Cursor is private; + + function Get_Position (Cursor: Serializer_Description_Cursor) return Natural; + + function Get_Description (Cursor: Serializer_Description_Cursor) return Raptor_Syntax_Description_Type; + + function Has_Element (Position: Serializer_Description_Cursor) return Boolean; + + package Serializer_Description_Iterators is new Ada.Iterator_Interfaces(Serializer_Description_Cursor, Has_Element); + + type Serializer_Description_Iterator is new Serializer_Description_Iterators.Forward_Iterator with private; + + overriding function First (Object: Serializer_Description_Iterator) return Serializer_Description_Cursor; + overriding function Next (Object: Serializer_Description_Iterator; Position: Serializer_Description_Cursor) + return Serializer_Description_Cursor; + + function Create_Serializer_Descriptions_Iterator (World: Redland_World_Type_Without_Finalize'Class) + return Serializer_Description_Iterator; + + package Handlers is new Serializer_Handled_Record.Common_Handlers(Serializer_Type_Without_Finalize); + + type Serializer_Type is new Handlers.Base_With_Finalization with null record; + + type Serializer_Type_User is new Handlers.User_Type with null record; + + not overriding function Create (World: Redland_World_Type_Without_Finalize'Class; + Name, Mime_Type: String := ""; + Type_URI: URI_Type_Without_Finalize'Class := URI_Type_Without_Finalize'(From_Handle(null))) + return Serializer_Type; + +private + + type Serializer_Description_Cursor is + record + World: Redland_World_Handle; + Position: Natural; + end record; + + type Serializer_Description_Iterator is new Serializer_Description_Iterators.Forward_Iterator with + record + World: Redland_World_Handle; + end record; + +end RDF.Redland.Serializer; diff --git a/ada/src/rdf-redland-statement.adb b/ada/src/rdf-redland-statement.adb new file mode 100644 index 000000000..7e9974992 --- /dev/null +++ b/ada/src/rdf-redland-statement.adb @@ -0,0 +1,204 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; + +package body RDF.Redland.Statement is + + function To_Raptor (Statement: Statement_Type_Without_Finalize'Class) + return RDF.Raptor.Statement.Statement_Type_Without_Finalize is + use RDF.Raptor.Statement; + begin + return From_Handle(Get_Handle(Statement)); + end; + + function From_Raptor (Statement: RDF.Raptor.Statement.Statement_Type_Without_Finalize'Class) + return Statement_Type_Without_Finalize is + use RDF.Raptor.Statement; + begin + return From_Handle(Get_Handle(Statement)); + end; + + function librdf_new_statement (World: Redland_World_Handle) return Statement_Handle + with Import, Convention=>C; + + function Create (World: Redland_World_Type_Without_Finalize'Class) return Statement_Type is + begin + return From_Non_Null_Handle(librdf_new_statement(Get_Handle(World))); + end; + + function librdf_new_statement_from_statement (Statement: Statement_Handle) return Statement_Handle + with Import, Convention=>C; + + function Adjust_Handle (Object: Statement_Type_Without_Finalize; Handle: Statement_Handle) + return Statement_Handle is + begin + return librdf_new_statement_from_statement(Handle); + end; + + function librdf_new_statement_from_nodes (World: Redland_World_Handle; + Subject, Predicate, Object: Node_Handle) + return Statement_Handle + with Import, Convention=>C; + + function From_Nodes (World: Redland_World_Type_Without_Finalize'Class; + Subject, Predicate, Object: Node_Type_Without_Finalize'Class) + return Statement_Type is + Handle: constant Statement_Handle := librdf_new_statement_from_nodes(Get_Handle(World), + Get_Handle(Subject), + Get_Handle(Predicate), + Get_Handle(Object)); + begin + return From_Non_Null_Handle(Handle); + end; + + procedure librdf_statement_clear (Statement: Statement_Handle) + with Import, Convention=>C; + + procedure Clear (Statement: in out Statement_Type_Without_Finalize) is + begin + librdf_statement_clear(Get_Handle(Statement)); + end; + + procedure librdf_free_statement (Statement: Statement_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Statement_Type_Without_Finalize; Handle: Statement_Handle) is + begin + librdf_free_statement(Handle); + end; + + function librdf_statement_get_subject (Statement: Statement_Handle) return Node_Handle + with Import, Convention=>C; + function librdf_statement_get_predicate (Statement: Statement_Handle) return Node_Handle + with Import, Convention=>C; + function librdf_statement_get_object (Statement: Statement_Handle) return Node_Handle + with Import, Convention=>C; + + function Get_Subject (Statement: Statement_Type_Without_Finalize) return Node_Type_Without_Finalize is + (From_Handle(librdf_statement_get_subject(Get_Handle(Statement)))); + function Get_Predicate (Statement: Statement_Type_Without_Finalize) return Node_Type_Without_Finalize is + (From_Handle(librdf_statement_get_predicate(Get_Handle(Statement)))); + function Get_Object (Statement: Statement_Type_Without_Finalize) return Node_Type_Without_Finalize is + (From_Handle(librdf_statement_get_object(Get_Handle(Statement)))); + + function librdf_new_node_from_node (Node: Node_Handle) return Node_Handle + with Import, Convention=>C; + + procedure librdf_statement_set_subject (Statement: Statement_Handle; Node: Node_Handle) + with Import, Convention=>C; + procedure librdf_statement_set_predicate (Statement: Statement_Handle; Node: Node_Handle) + with Import, Convention=>C; + procedure librdf_statement_set_object (Statement: Statement_Handle; Node: Node_Handle) + with Import, Convention=>C; + + procedure Set_Subject (Statement: Statement_Type_Without_Finalize; + Node: Node_Type_Without_Finalize'Class) is + begin + librdf_statement_set_subject(Get_Handle(Statement), + librdf_new_node_from_node(Get_Handle(Node))); + end; + + procedure Set_Predicate (Statement: Statement_Type_Without_Finalize; + Node: Node_Type_Without_Finalize'Class) is + begin + librdf_statement_set_predicate(Get_Handle(Statement), + librdf_new_node_from_node(Get_Handle(Node))); + end; + + procedure Set_Object (Statement: Statement_Type_Without_Finalize; + Node: Node_Type_Without_Finalize'Class) is + begin + librdf_statement_set_object(Get_Handle(Statement), + librdf_new_node_from_node(Get_Handle(Node))); + end; + + function librdf_statement_is_complete (Statement: Statement_Handle) return int + with Import, Convention=>C; + + function Is_Complete (Statement: Statement_Type_Without_Finalize) return Boolean is + (librdf_statement_is_complete(Get_Handle(Statement)) /= 0); + + procedure librdf_statement_print (Statement: Statement_Handle; File: C_File_Access) + with Import, Convention=>C; + + procedure Print (Statement: Statement_Type_Without_Finalize; File: C_File_Access) is + begin + librdf_statement_print(Get_Handle(Statement), File); + end; + + function librdf_statement_equals (Left, Right: Statement_Handle) return int + with Import, Convention=>C; + + function Equals (Left, Right: Statement_Type_Without_Finalize) return Boolean is + (librdf_statement_equals(Get_Handle(Left), Get_Handle(Right)) /= 0); + + function librdf_statement_match (Statement, Partial: Statement_Handle) return int + with Import, Convention=>C; + + function Match (Statement, Partial: Statement_Type_Without_Finalize) return Boolean is + (librdf_statement_match(Get_Handle(Statement), Get_Handle(Partial)) /= 0); + + function librdf_statement_encode2 (World: Redland_World_Handle; + Statement: Statement_Handle; + Buffer: chars_ptr; + Length: size_t) + return size_t + with Import, Convention=>C; + + function Encode (World: Redland_World_Type_Without_Finalize'Class; + Statement: Statement_Type_Without_Finalize) + return String is + Length: size_t := + librdf_statement_encode2(Get_Handle(World), Get_Handle(Statement), Null_Ptr, 0); +-- Buffer: aliased char_array(1..Length); -- GCC 7.2.0 warning + Buffer: aliased char_array := (1..Length => nul); + begin + Length := librdf_statement_encode2(Get_Handle(World), + Get_Handle(Statement), + To_Chars_Ptr(Buffer'Unchecked_Access), + Length); + return To_Ada(Buffer, Trim_Nul=>False); + end; + + function librdf_statement_encode_parts2 (World: Redland_World_Handle; + Statement: Statement_Handle; + Context_Node: Node_Handle; + Buffer: chars_ptr; + Length: size_t; + Fields: Statement_Part_Flags) + return size_t + with Import, Convention=>C; + + function Encode_Parts (World: Redland_World_Type_Without_Finalize'Class; + Statement: Statement_Type_Without_Finalize; + Context_Node: Node_Type_Without_Finalize'Class; + Fields: Statement_Part_Flags) + return String is + Length: size_t := librdf_statement_encode_parts2(Get_Handle(World), + Get_Handle(Statement), + Get_Handle(Context_Node), + Null_Ptr, + 0, + Fields); +-- Buffer: aliased char_array(1..Length); -- GCC 7.2.0 warning + Buffer: aliased char_array := (1..Length => nul); + begin + Length := librdf_statement_encode_parts2(Get_Handle(World), + Get_Handle(Statement), + Get_Handle(Context_Node), + To_Chars_Ptr(Buffer'Unchecked_Access), + Length, + Fields); + return To_Ada(Buffer, Trim_Nul=>False); + end; + + function librdf_statement_write (Statement: Statement_Handle; Stream: IOStream_Handle) return int + with Import, Convention=>C; + + procedure Write (Statement: Statement_Type_Without_Finalize; Stream: IOStream_Type_Without_Finalize'Class) is + begin + if librdf_statement_write(Get_Handle(Statement), Get_Handle(Stream)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + +end RDF.Redland.Statement; diff --git a/ada/src/rdf-redland-statement.ads b/ada/src/rdf-redland-statement.ads new file mode 100644 index 000000000..3436776f2 --- /dev/null +++ b/ada/src/rdf-redland-statement.ads @@ -0,0 +1,86 @@ +with RDF.Auxiliary; use RDF.Auxiliary; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; +with RDF.Raptor.Statement; +with RDF.Redland.World; use RDF.Redland.World; +with RDF.Redland.Node; use RDF.Redland.Node; + +package RDF.Redland.Statement is + + subtype Statement_Handle is RDF.Raptor.Statement.Statement_Handle; + + type Statement_Type_Without_Finalize is new RDF.Raptor.Statement.Statement_Handled_Record.Base_Object with null record; + + function To_Raptor (Statement: Statement_Type_Without_Finalize'Class) return RDF.Raptor.Statement.Statement_Type_Without_Finalize; + + overriding function Adjust_Handle (Object: Statement_Type_Without_Finalize; Handle: Statement_Handle) return Statement_Handle; + + overriding procedure Finalize_Handle (Object: Statement_Type_Without_Finalize; Handle: Statement_Handle); + + not overriding function From_Raptor (Statement: RDF.Raptor.Statement.Statement_Type_Without_Finalize'Class) return Statement_Type_Without_Finalize; + + type Statement_Part_Flags is mod 256; -- the number may change in a future version + + Subject_Part : Statement_Part_Flags := 1; + Predicate_Part: Statement_Part_Flags := 2; + Object_Part : Statement_Part_Flags := 4; + All_Parts : Statement_Part_Flags := Subject_Part or Predicate_Part or Object_Part; + + not overriding procedure Clear (Statement: in out Statement_Type_Without_Finalize); + + not overriding function Get_Subject (Statement: Statement_Type_Without_Finalize) + return Node_Type_Without_Finalize; + not overriding function Get_Predicate (Statement: Statement_Type_Without_Finalize) + return Node_Type_Without_Finalize; + not overriding function Get_Object (Statement: Statement_Type_Without_Finalize) + return Node_Type_Without_Finalize; + + not overriding procedure Set_Subject (Statement: Statement_Type_Without_Finalize; + Node: Node_Type_Without_Finalize'Class); + not overriding procedure Set_Predicate (Statement: Statement_Type_Without_Finalize; + Node: Node_Type_Without_Finalize'Class); + not overriding procedure Set_Object (Statement: Statement_Type_Without_Finalize; + Node: Node_Type_Without_Finalize'Class); + + not overriding function Is_Complete (Statement: Statement_Type_Without_Finalize) return Boolean; + + not overriding procedure Print (Statement: Statement_Type_Without_Finalize; File: C_File_Access); + + not overriding function Equals (Left, Right: Statement_Type_Without_Finalize) return Boolean; + + overriding function "=" (Left, Right: Statement_Type_Without_Finalize) return Boolean + renames Equals; + + not overriding function Match (Statement, Partial: Statement_Type_Without_Finalize) return Boolean; + + not overriding function Encode (World: Redland_World_Type_Without_Finalize'Class; + Statement: Statement_Type_Without_Finalize) + return String; + + not overriding function Encode_Parts (World: Redland_World_Type_Without_Finalize'Class; + Statement: Statement_Type_Without_Finalize; + Context_Node: Node_Type_Without_Finalize'Class; + Fields: Statement_Part_Flags) + return String; + + -- librdf_statement_decode2() not implemented (not so important and somehow hard to do) + + not overriding procedure Write (Statement: Statement_Type_Without_Finalize; Stream: IOStream_Type_Without_Finalize'Class); + + package Handlers is new RDF.Raptor.Statement.Statement_Handled_Record.Common_Handlers(Statement_Type_Without_Finalize); + + type Statement_Type is new Handlers.Base_With_Finalization with null record; + + type Statement_Type_User is new Handlers.User_Type with null record; + + -- librdf_new_statement_from_statement2() not bound. + -- (It is unclear how this would interact with Ada copying.) + + not overriding function Create (World: Redland_World_Type_Without_Finalize'Class) return Statement_Type; + + not overriding function From_Nodes (World: Redland_World_Type_Without_Finalize'Class; + Subject, Predicate, Object: Node_Type_Without_Finalize'Class) + return Statement_Type; + + -- librdf_statement_init() not bound because we don't support statistially declared objects. + +end RDF.Redland.Statement; diff --git a/ada/src/rdf-redland-storage.adb b/ada/src/rdf-redland-storage.adb new file mode 100644 index 000000000..c095bfbb5 --- /dev/null +++ b/ada/src/rdf-redland-storage.adb @@ -0,0 +1,101 @@ +with Interfaces.C.Strings; use Interfaces.C.Strings; + +package body RDF.Redland.Storage is + + type String_P_Type is access all chars_ptr with Convention=>C; + + function librdf_storage_enumerate (World: Redland_World_Handle; + Counter: unsigned; + Name, Label: String_P_Type) + return int + with Import, Convention=>C; + + function Enumerate_Storages (World: Redland_World_Type_Without_Finalize'Class; + Counter: unsigned) + return Storage_Info_Holders.Holder is + Name, Label: aliased chars_ptr; + Result: constant int := + librdf_storage_enumerate(Get_Handle(World), Counter, Name'Unchecked_Access, Label'Unchecked_Access); + use Storage_Info_Holders; + begin + if Result /= 0 then + return Empty_Holder; + end if; + declare + Name2 : constant String := Value(Name ); + Label2: constant String := Value(Label); + begin + return To_Holder((Name_Length => Name2 'Length, + Label_Length => Label2'Length, + Name => Name2, Label => Label2)); + end; + end; + + function Has_Element (Position: Enumerate_Storages_Cursor) return Boolean is + begin + return librdf_storage_enumerate(Position.World, Position.Counter, null, null) = 0; + end; + + function First (Object: Enumerate_Storages_Iterator) return Enumerate_Storages_Cursor is + begin + return (World => Object.World, Counter => 0); + end; + + function Next (Object: Enumerate_Storages_Iterator; Position: Enumerate_Storages_Cursor) + return Enumerate_Storages_Cursor is + begin + return (World => Position.World, Counter => Position.Counter + 1); + end; + + function librdf_new_storage (World: Redland_World_Handle; Factory_Name, Name, Options: char_array) + return Storage_Handle + with Import, Convention=>C; + + function Create (World: Redland_World_Type_Without_Finalize'Class; + Factory_Name: String; + Name: String; + Options: String := "") + return Storage_Type is + Handle: constant Storage_Handle := + librdf_new_storage(Get_Handle(World), To_C(Factory_Name), To_C(Name), To_C(Options)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_storage_from_storage (Storage: Storage_Handle) return Storage_Handle + with Import, Convention=>C; + + function Copy (Storage: Storage_Type_Without_Finalize'Class) return Storage_Type is + begin + return From_Non_Null_Handle(librdf_new_storage_from_storage(Get_Handle(Storage))); + end; + + procedure librdf_free_storage (Handle: Storage_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Storage_Type_Without_Finalize; Handle: Storage_Handle) is + begin + librdf_free_storage(Handle); + end; + + function librdf_storage_sync (Storage: Storage_Handle) return int + with Import, Convention=>C; + + procedure Sync (Storage: Storage_Type_Without_Finalize) is + begin + if librdf_storage_sync(Get_Handle(Storage)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + + function librdf_storage_get_world (Storage: Storage_Handle) return Redland_World_Handle + with Import, Convention=>C; + + function Get_World (Storage: Storage_Type_Without_Finalize) + return Redland_World_Type_Without_Finalize is + begin + -- Or just From_Handle? + return From_Non_Null_Handle(librdf_storage_get_world(Get_Handle(Storage))); + end; + +end RDF.Redland.Storage; diff --git a/ada/src/rdf-redland-storage.ads b/ada/src/rdf-redland-storage.ads new file mode 100644 index 000000000..518fefa29 --- /dev/null +++ b/ada/src/rdf-redland-storage.ads @@ -0,0 +1,87 @@ +with Ada.Containers.Indefinite_Holders; +with Interfaces.C; use Interfaces.C; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Redland.World; use RDF.Redland.World; +with Ada.Iterator_Interfaces; +with RDF.Auxiliary; + +package RDF.Redland.Storage is + + -- Use Limited_Handled_Record because despite a storage can be copied, + -- copying may be a very expensive operation. Use Copy function instead. + -- See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62042 + package Storage_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + type Storage_Type_Without_Finalize is new Storage_Handled_Record.Base_Object with null record; + + subtype Storage_Handle is Storage_Handled_Record.Access_Type; + + overriding procedure Finalize_Handle (Object: Storage_Type_Without_Finalize; Handle: Storage_Handle); + + type Storage_Info (Name_Length, Label_Length: Natural) is + record + Name : String(1..Name_Length ); + Label: String(1..Label_Length); + end record; + + package Storage_Info_Holders is new Ada.Containers.Indefinite_Holders(Storage_Info); + + function Enumerate_Storages (World: Redland_World_Type_Without_Finalize'Class; + Counter: unsigned) + return Storage_Info_Holders.Holder; + + type Enumerate_Storages_Cursor is private; + + function Has_Element (Position: Enumerate_Storages_Cursor) return Boolean; + + package Enumerate_Storages_Interfaces is + new Ada.Iterator_Interfaces(Enumerate_Storages_Cursor, Has_Element); + + type Enumerate_Storages_Iterator is new Enumerate_Storages_Interfaces.Forward_Iterator with private; + + overriding function First (Object: Enumerate_Storages_Iterator) return Enumerate_Storages_Cursor; + + overriding function Next (Object: Enumerate_Storages_Iterator; Position: Enumerate_Storages_Cursor) + return Enumerate_Storages_Cursor; + + not overriding procedure Sync (Storage: Storage_Type_Without_Finalize); + + -- Will implement after http://bugs.librdf.org/mantis/view.php?id=636 bug fix +-- not overriding function Get_Feature (Storage: Storage_Type_Without_Finalize; +-- Feature: URI_Type_Without_Finalize'Class) +-- return Node_Type_Without_Finalize; +-- not overriding procedure Set_Feature (Storage: Storage_Type_Without_Finalize; +-- Feature: URI_Type_Without_Finalize'Class; +-- Value: Node_Type_Without_Finalize'Class); + + not overriding function Get_World (Storage: Storage_Type_Without_Finalize) + return Redland_World_Type_Without_Finalize; + + package Handlers is new Storage_Handled_Record.Common_Handlers(Storage_Type_Without_Finalize); + + type Storage_Type is new Handlers.Base_With_Finalization with null record; + + type Storage_Type_User is new Handlers.User_Type with null record; + + not overriding function Create (World: Redland_World_Type_Without_Finalize'Class; + Factory_Name: String; + Name: String; + Options: String := "") + return Storage_Type; + + not overriding function Copy (Storage: Storage_Type_Without_Finalize'Class) return Storage_Type; + +private + + type Enumerate_Storages_Cursor is + record + World: Redland_World_Handle; + Counter: unsigned; + end record; + + type Enumerate_Storages_Iterator is new Enumerate_Storages_Interfaces.Forward_Iterator with + record + World: Redland_World_Handle; + end record; + +end RDF.Redland.Storage; diff --git a/ada/src/rdf-redland-stream.adb b/ada/src/rdf-redland-stream.adb new file mode 100644 index 000000000..5aaaa0217 --- /dev/null +++ b/ada/src/rdf-redland-stream.adb @@ -0,0 +1,117 @@ +with Ada.Containers.Vectors; +with Interfaces.C; use Interfaces.C; +with RDF.Redland.Iterator; use RDF.Redland.Iterator; + +package body RDF.Redland.Stream is + + function librdf_new_stream_from_node_iterator (Iterator: Iterator_Handle; + Statement: Statement_Handle; + Field: Statement_Part_Flags) + return Stream_Handle + with Import, Convention=>C; + + function From_Node_Iterator (Iterator: Node_Iterator_Type_Without_Finalize'Class; + Statement: Statement_Type_Without_Finalize'Class; + Field: Statement_Part_Flags) + return Stream_Type is + Handle: constant Stream_Handle := + librdf_new_stream_from_node_iterator(Get_Handle(Iterator), Get_Handle(Statement), Field); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_empty_stream (World: Redland_World_Handle) return Stream_Handle + with Import, Convention=>C; + + function Empty_Stream (World: Redland_World_Type_Without_Finalize'Class) return Stream_Type is + begin + return From_Non_Null_Handle(librdf_new_empty_stream(Get_Handle(World))); + end; + + procedure librdf_free_stream (Stream: Stream_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Stream_Type_Without_Finalize; Handle: Stream_Handle) is + begin + librdf_free_stream(Handle); + end; + + function librdf_stream_end (Stream: Stream_Handle) return int + with Import, Convention=>C; + + function Is_End (Stream: Stream_Type_Without_Finalize) return Boolean is + begin + return librdf_stream_end(Get_Handle(Stream)) /= 0; + end; + + function librdf_stream_next (Stream: Stream_Handle) return int + with Import, Convention=>C; + + procedure Next(Stream: Stream_Type_Without_Finalize) is + Result: constant int := librdf_stream_next(Get_Handle(Stream)); + pragma Unreferenced(Result); + begin + null; + end; + + function librdf_stream_get_object (Stream: Stream_Handle) return Statement_Handle + with Import, Convention=>C; + + function Get_Object (Stream: Stream_Type_Without_Finalize) return Statement_Type_Without_Finalize is + begin + return From_Handle(librdf_stream_get_object(Get_Handle(Stream))); + end; + + function librdf_stream_get_context2 (Stream: Stream_Handle) return Node_Handle + with Import, Convention=>C; + + function Get_Context (Stream: Stream_Type_Without_Finalize) return Node_Type_Without_Finalize is + begin + return From_Handle(librdf_stream_get_context2(Get_Handle(Stream))); + end; + + function librdf_stream_write (Stream: Stream_Handle; Raptor_Stream: IOStream_Handle) return int + with Import, Convention=>C; + + procedure Write (Stream: Stream_Type_Without_Finalize; Raptor_Stream: IOStream_Type_Without_Finalize'Class) is + begin + if librdf_stream_write(Get_Handle(Stream), Get_Handle(Raptor_Stream)) /= 0 then + raise RDF.Raptor.IOStream.IOStream_Exception; + end if; + end; + + function Has_Element (Position: Cursor) return Boolean is + (not Is_End(Position.all)); + + function Create_Stream_Iterator (Stream: in out Stream_Type_Without_Finalize'Class) + return Stream_Iterator is + (Ref=>Stream'Unchecked_Access); + + function First (Object: Stream_Iterator) return Cursor is + (Object.Ref); + + function Next (Object: Stream_Iterator; Position: Cursor) return Cursor is + begin + Next(Position.all); + return Position; + end; + + function To_Array (Stream: in out Stream_Type_Without_Finalize) return Statement_Array is + package V is new Ada.Containers.Vectors(Ada.Containers.Count_Type, Statement_Type); + Result: V.Vector; + begin + while not Is_End(Stream) loop + V.Append(Result, Copy(Get_Object(Stream))); + Next(Stream); + end loop; + declare + Result2: Statement_Array(1..V.Length(Result)); + begin + for I in Result2'Range loop + Result2(I) := Result.Element(I); + end loop; + return Result2; + end; + end; + +end RDF.Redland.Stream; diff --git a/ada/src/rdf-redland-stream.ads b/ada/src/rdf-redland-stream.ads new file mode 100644 index 000000000..20b5d23f3 --- /dev/null +++ b/ada/src/rdf-redland-stream.ads @@ -0,0 +1,79 @@ +with Ada.Containers; +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.IOStream; use RDF.Raptor.IOStream; +with RDF.Redland.World; use RDF.Redland.World; +with RDF.Redland.Node; use RDF.Redland.Node; +with RDF.Redland.Statement; use RDF.Redland.Statement; +with RDF.Redland.Node_Iterator; use RDF.Redland.Node_Iterator; +with Ada.Iterator_Interfaces; + +package RDF.Redland.Stream is + + package Stream_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + type Stream_Type_Without_Finalize is new Stream_Handled_Record.Base_Object with null record; + + subtype Stream_Handle is Stream_Handled_Record.Access_Type; + + overriding procedure Finalize_Handle (Object: Stream_Type_Without_Finalize; Handle: Stream_Handle); + + not overriding function Is_End (Stream: Stream_Type_Without_Finalize) return Boolean; + + not overriding procedure Next(Stream: Stream_Type_Without_Finalize); + + -- Should we instead return a copy of the statement? + not overriding function Get_Object (Stream: Stream_Type_Without_Finalize) + return Statement_Type_Without_Finalize; + + -- Should we instead return a copy of the node? + not overriding function Get_Context (Stream: Stream_Type_Without_Finalize) + return Node_Type_Without_Finalize; + + -- librdf_stream_add_map() not implemented + + not overriding procedure Write (Stream: Stream_Type_Without_Finalize; Raptor_Stream: IOStream_Type_Without_Finalize'Class); + + type Statement_Array is array (Ada.Containers.Count_Type range <>) of Statement_Type; + + -- Note that after this operation Stream is not usable + not overriding function To_Array (Stream: in out Stream_Type_Without_Finalize) + return Statement_Array; + + package Handlers is new Stream_Handled_Record.Common_Handlers(Stream_Type_Without_Finalize); + + type Stream_Type is new Handlers.Base_With_Finalization with null record; + + type Stream_Type_User is new Handlers.User_Type with null record; + + function Empty_Stream (World: Redland_World_Type_Without_Finalize'Class) return Stream_Type; + + not overriding function From_Node_Iterator (Iterator: Node_Iterator_Type_Without_Finalize'Class; + Statement: Statement_Type_Without_Finalize'Class; + Field: Statement_Part_Flags) + return Stream_Type; + + type Cursor is private; + + not overriding function Has_Element (Position: Cursor) return Boolean; + + package Base_Iterators is new Ada.Iterator_Interfaces(Cursor, Has_Element); + + type Stream_Iterator is new Base_Iterators.Forward_Iterator with private; + + not overriding function Create_Stream_Iterator (Stream: in out Stream_Type_Without_Finalize'Class) + return Stream_Iterator; + + overriding function First (Object: Stream_Iterator) return Cursor; + + overriding function Next (Object: Stream_Iterator; Position: Cursor) return Cursor; + +private + + type Cursor is access constant Stream_Type_Without_Finalize'Class; + + type Stream_Iterator is new Base_Iterators.Forward_Iterator with + record + Ref: Cursor; + end record; + +end RDF.Redland.Stream; diff --git a/ada/src/rdf-redland-uri.adb b/ada/src/rdf-redland-uri.adb new file mode 100644 index 000000000..630911aff --- /dev/null +++ b/ada/src/rdf-redland-uri.adb @@ -0,0 +1,185 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with RDF.Auxiliary; +with RDF.Auxiliary.C_Pointers; +with RDF.Auxiliary.Convert; use RDF.Auxiliary.Convert; +with RDF.Redland.Memory; + +package body RDF.Redland.URI is + + function To_Raptor (URI: URI_Type_Without_Finalize'Class) return RDF.Raptor.URI.URI_Type_Without_Finalize is + use RDF.Raptor.URI; + begin + return From_Handle(Get_Handle(URI)); + end; + + function From_Raptor (URI: RDF.Raptor.URI.URI_Type_Without_Finalize'Class) return URI_Type_Without_Finalize is + use RDF.Raptor.URI; + begin + return From_Handle(Get_Handle(URI)); + end; + + function librdf_new_uri2 (World: Redland_World_Handle; URI: char_array; Length: size_t) + return URI_Handle + with Import, Convention=>C; + + function From_String (World: Redland_World_Type_Without_Finalize'Class; URI: URI_String) + return URI_Type is + Handle: constant URI_Handle := + librdf_new_uri2(Get_Handle(World), To_C(String(URI), Append_Nul=>False), URI'Length); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_uri_from_uri (Old_URI: URI_Handle) return URI_Handle + with Import, Convention=>C; + + function Adjust_Handle (Object: URI_Type_Without_Finalize; Handle: URI_Handle) return URI_Handle is + begin + return librdf_new_uri_from_uri(Handle); + end; + + function librdf_new_uri_from_uri_local_name (Old_URI: URI_Handle; Local_Name: char_array) + return URI_Handle + with Import, Convention=>C; + + function From_URI_Local_Name (Old_URI: URI_Type_Without_Finalize'Class; + Local_Name: String) + return URI_Type is + Handle: constant URI_Handle := + librdf_new_uri_from_uri_local_name(Get_Handle(Old_URI), To_C(Local_Name)); + begin + return From_Non_Null_Handle(Handle); + end; + + procedure librdf_free_uri (Handle: URI_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: URI_Type_Without_Finalize; Handle: URI_Handle) is + begin + librdf_free_uri (Handle); + end; + + type Size_T_P is access all size_t with Convention=>C; + + function librdf_uri_as_counted_string(URI: URI_Handle; Length: Size_T_P) + return RDF.Auxiliary.C_Pointers.Pointer + with Import, Convention=>C; + + function As_String (URI: URI_Type_Without_Finalize) return String is + Length: aliased size_t; + Str: constant RDF.Auxiliary.C_Pointers.Pointer := + librdf_uri_as_counted_string(Get_Handle(URI), Length'Unchecked_Access); + begin + return Value_With_Possible_NULs(Str, Length); + end; + + procedure librdf_uri_print (URI: URI_Handle; File: RDF.Auxiliary.C_File_Access) + with Import, Convention=>C; + + procedure Print (URI: URI_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access) is + begin + librdf_uri_print(Get_Handle(URI), File); + end; + + function librdf_uri_equals (Left, Right: URI_Handle) return int + with Import, Convention=>C; + + function Equals (Left, Right: URI_Type_Without_Finalize) return Boolean is + begin + return librdf_uri_equals(Get_Handle(Left), Get_Handle(Right)) /= 0; + end; + + function librdf_uri_is_file_uri (URI: URI_Handle) return int + with Import, Convention=>C; + + function Is_File_URI (URI: URI_Type_Without_Finalize) return Boolean is + begin + return librdf_uri_is_file_uri(Get_Handle(URI)) /= 0; + end; + + function librdf_uri_to_filename (URI: URI_Handle) return chars_ptr + with Import, Convention=>C; + + function To_Filename (URI: URI_Type_Without_Finalize) return String is + Pointer: constant chars_ptr := librdf_uri_to_filename(Get_Handle(URI)); + Result: constant String := Value(Pointer); + begin + RDF.Redland.Memory.librdf_free_memory(Pointer); + return Result; + end; + + function librdf_new_uri_normalised_to_base (URI_Str: char_array; Source_URI, Base_URI: URI_Handle) + return URI_Handle + with Import, Convention=>C; + + function Normalised_To_Base (URI_Str: URI_String; + Source_URI, Base_URI: URI_Type_Without_Finalize'Class) + return URI_Type is + Handle: constant URI_Handle := + librdf_new_uri_normalised_to_base(To_C(String(URI_Str)), Get_Handle(Source_URI), Get_Handle(Base_URI)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_uri_relative_to_base (Base_URI: URI_Handle; Str: char_array) return URI_Handle + with Import, Convention=>C; + + function Relative_To_Base (Base_URI: URI_Type_Without_Finalize'Class; + Str: URI_String) + return URI_Type is + Handle: constant URI_Handle := + librdf_new_uri_relative_to_base(Get_Handle(Base_URI), To_C(String(Str))); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_new_uri_from_filename (World: Redland_World_Handle; Filename: char_array) return URI_Handle + with Import, Convention=>C; + + function From_Filename (World: Redland_World_Type_Without_Finalize'Class; + Filename: String) + return URI_Type is + Handle: constant URI_Handle := + librdf_new_uri_from_filename(Get_Handle(World), To_C(Filename)); + begin + return From_Non_Null_Handle(Handle); + end; + + function librdf_uri_compare (URI1, URI2: URI_Handle) return int + with Import, Convention=>C; + + function Compare(URI1, URI2: URI_Type_Without_Finalize) return RDF.Auxiliary.Comparison_Result is + begin + return RDF.Auxiliary.Comparison_Result (librdf_uri_compare (Get_Handle(URI1), Get_Handle(URI2))); + end; + + function librdf_get_concept_ms_namespace (World: Redland_World_Handle) return URI_Handle + with Import, Convention=>C; + + function Concept_Ms_Namespace (World: Redland_World_Type_Without_Finalize'Class) + return URI_Type_Without_Finalize is + begin + return From_Non_Null_Handle(librdf_get_concept_ms_namespace(Get_Handle(World))); + end; + + function librdf_get_concept_schema_namespace (World: Redland_World_Handle) return URI_Handle + with Import, Convention=>C; + + function Concept_Schema_Namespace (World: Redland_World_Type_Without_Finalize'Class) + return URI_Type_Without_Finalize is + begin + return From_Non_Null_Handle(librdf_get_concept_schema_namespace(Get_Handle(World))); + end; + + use type RDF.Auxiliary.Comparison_Result; + + function "<"(URI1, URI2: URI_Type_Without_Finalize) return Boolean is (Compare(URI1, URI2) < 0); + + function ">"(URI1, URI2: URI_Type_Without_Finalize) return Boolean is (Compare(URI1, URI2) > 0); + + function "<="(URI1, URI2: URI_Type_Without_Finalize) return Boolean is (Compare(URI1, URI2) <= 0); + + function ">="(URI1, URI2: URI_Type_Without_Finalize) return Boolean is (Compare(URI1, URI2) >= 0); + +end RDF.Redland.URI; diff --git a/ada/src/rdf-redland-uri.ads b/ada/src/rdf-redland-uri.ads new file mode 100644 index 000000000..d9a946c56 --- /dev/null +++ b/ada/src/rdf-redland-uri.ads @@ -0,0 +1,76 @@ +with RDF.Auxiliary; +with RDF.Raptor.URI; +with RDF.Redland.World; use RDF.Redland.World; + +package RDF.Redland.URI is + + subtype URI_String is RDF.Raptor.URI.URI_String; + + subtype URI_Handle is RDF.Raptor.URI.URI_Handle; + + type URI_Type_Without_Finalize is new RDF.Raptor.URI.URI_Handled_Record.Base_Object with null record; + + overriding function Adjust_Handle (Object: URI_Type_Without_Finalize; Handle: URI_Handle) return URI_Handle; + + overriding procedure Finalize_Handle (Object: URI_Type_Without_Finalize; Handle: URI_Handle); + + -- FIXME: URI_Type_Without_Finalize -> URI_Type? (also in D) + function To_Raptor (URI: URI_Type_Without_Finalize'Class) return RDF.Raptor.URI.URI_Type_Without_Finalize; + + -- FIXME: URI_Type_Without_Finalize -> URI_Type? (also in D) + not overriding function From_Raptor (URI: RDF.Raptor.URI.URI_Type_Without_Finalize'Class) return URI_Type_Without_Finalize; + + not overriding function As_String (URI: URI_Type_Without_Finalize) return String; + + not overriding procedure Print (URI: URI_Type_Without_Finalize; File: RDF.Auxiliary.C_File_Access); + + not overriding function Equals (Left, Right: URI_Type_Without_Finalize) return Boolean; + + overriding function "=" (Left, Right: URI_Type_Without_Finalize) return Boolean + renames Equals; + + not overriding function "<"(URI1, URI2: URI_Type_Without_Finalize) return Boolean; + + not overriding function ">"(URI1, URI2: URI_Type_Without_Finalize) return Boolean; + + not overriding function "<="(URI1, URI2: URI_Type_Without_Finalize) return Boolean; + + not overriding function ">="(URI1, URI2: URI_Type_Without_Finalize) return Boolean; + + not overriding function Compare(URI1, URI2: URI_Type_Without_Finalize) return RDF.Auxiliary.Comparison_Result; + + not overriding function Is_File_URI (URI: URI_Type_Without_Finalize) return Boolean; + + not overriding function To_Filename (URI: URI_Type_Without_Finalize) return String; + + -- From http://librdf.org/docs/api/redland-concepts.html: + not overriding function Concept_Ms_Namespace (World: Redland_World_Type_Without_Finalize'Class) + return URI_Type_Without_Finalize; + not overriding function Concept_Schema_Namespace (World: Redland_World_Type_Without_Finalize'Class) + return URI_Type_Without_Finalize; + + package Handlers is new RDF.Raptor.URI.URI_Handled_Record.Common_Handlers(URI_Type_Without_Finalize); + + type URI_Type is new Handlers.Base_With_Finalization with null record; + + type URI_Type_User is new Handlers.User_Type with null record; + + not overriding function From_String (World: Redland_World_Type_Without_Finalize'Class; URI: URI_String) + return URI_Type; + + not overriding function From_URI_Local_Name (Old_URI: URI_Type_Without_Finalize'Class; + Local_Name: String) + return URI_Type; + + not overriding function Normalised_To_Base (URI_Str: URI_String; + Source_URI, Base_URI: URI_Type_Without_Finalize'Class) + return URI_Type; + + not overriding function Relative_To_Base (Base_URI: URI_Type_Without_Finalize'Class; Str: URI_String) + return URI_Type; + + not overriding function From_Filename (World: Redland_World_Type_Without_Finalize'Class; + Filename: String) + return URI_Type; + +end RDF.Redland.URI; diff --git a/ada/src/rdf-redland-world.adb b/ada/src/rdf-redland-world.adb new file mode 100644 index 000000000..0746d7561 --- /dev/null +++ b/ada/src/rdf-redland-world.adb @@ -0,0 +1,106 @@ +with Interfaces.C; use Interfaces.C; +with RDF.Redland.Node; use RDF.Redland.Node; +with RDF.Redland.URI; use RDF.Redland.URI; + +package body RDF.Redland.World is + + function librdf_new_world return Redland_World_Handle + with Import, Convention=>C; + + function Default_Handle (Object: Redland_World_Type_Without_Finalize) + return Redland_World_Handle is + begin + return librdf_new_world; + end; + + procedure librdf_free_world (Handle: Redland_World_Handle) + with Import, Convention=>C; + + procedure Finalize_Handle (Object: Redland_World_Type_Without_Finalize; Handle: Redland_World_Handle) is + begin + librdf_free_world(Handle); + end; + + procedure librdf_world_open (Handle: Redland_World_Handle) + with Import, Convention=>C; + + procedure Open (Object: in out Redland_World_Type_Without_Finalize) is + begin + librdf_world_open(Get_Handle(Object)); + end; + + function Open return Redland_World_Type is + begin + return Object: Redland_World_Type do + Open(Object); + end return; + end; + + procedure librdf_world_set_rasqal (World: Redland_World_Handle; Rasqal_World: Rasqal_World_Handle) + with Import, Convention=>C; + + procedure Set_Rasqal (World: Redland_World_Type_Without_Finalize; + Rasqal_World: Rasqal_World_Type_Without_Finalize'Class) is + begin + librdf_world_set_rasqal(Get_Handle(World), Get_Handle(Rasqal_World)); + end; + + function librdf_world_get_rasqal (World: Redland_World_Handle) return Rasqal_World_Handle + with Import, Convention=>C; + + function Get_Rasqal (World: Redland_World_Type_Without_Finalize) + return Rasqal_World_Type_Without_Finalize is + begin + return From_Non_Null_Handle(librdf_world_get_rasqal(Get_Handle(World))); + end; + + procedure librdf_world_set_raptor (World: Redland_World_Handle; Raptor_World: Raptor_World_Handle) + with Import, Convention=>C; + + procedure Set_Raptor (World: Redland_World_Type_Without_Finalize; + Raptor_World: Raptor_World_Type_Without_Finalize'Class) is + begin + librdf_world_set_raptor(Get_Handle(World), Get_Handle(Raptor_World)); + end; + + function librdf_world_get_raptor (World: Redland_World_Handle) return Raptor_World_Handle + with Import, Convention=>C; + + function Get_Raptor (World: Redland_World_Type_Without_Finalize) + return Raptor_World_Type_Without_Finalize is + begin + return From_Non_Null_Handle(librdf_world_get_raptor(Get_Handle(World))); + end; + + procedure librdf_world_set_digest (World: Redland_World_Handle; Name: char_array) + with Import, Convention=>C; + + procedure Set_Digest (World: Redland_World_Type_Without_Finalize; Name: String) is + begin + librdf_world_set_digest(Get_Handle(World), To_C(Name)); + end; + + function librdf_world_get_feature (World: Redland_World_Handle; Feature: URI_Handle) return Node_Handle + with Import, Convention=>C; + + function Get_Feature (World: Redland_World_Type_Without_Finalize; + Feature: RDF.Redland.URI.URI_Type_Without_Finalize'Class) + return RDF.Redland.Node.Node_Type is + begin + return From_Handle(librdf_world_get_feature(Get_Handle(World), Get_Handle(Feature))); + end; + + function librdf_world_set_feature (World: Redland_World_Handle; Feature: URI_Handle; Value: Node_Handle) + return int + with Import, Convention=>C; + + procedure Set_Feature (World: Redland_World_Type_Without_Finalize; + Feature: RDF.Redland.URI.URI_Type_Without_Finalize'Class; + Value: RDF.Redland.Node.Node_Type_Without_Finalize'Class) is + begin + if librdf_world_set_feature(Get_Handle(World), Get_Handle(Feature), Get_Handle(Value)) /= 0 then + raise RDF.Auxiliary.RDF_Exception; + end if; + end; + +end RDF.Redland.World; diff --git a/ada/src/rdf-redland-world.ads b/ada/src/rdf-redland-world.ads new file mode 100644 index 000000000..7ca95ce03 --- /dev/null +++ b/ada/src/rdf-redland-world.ads @@ -0,0 +1,61 @@ +with RDF.Auxiliary.Limited_Handled_Record; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Rasqal.World; use RDF.Rasqal.World; +limited with RDF.Redland.Node; +limited with RDF.Redland.URI; + +package RDF.Redland.World is + + Feature_Genid_Base: constant String := "http://feature.librdf.org/genid-base"; + Feature_Genid_Counter: constant String := "http://feature.librdf.org/genid-counter"; + + package Redland_World_Handled_Record is new RDF.Auxiliary.Limited_Handled_Record(RDF.Auxiliary.Dummy_Record, RDF.Auxiliary.Dummy_Record_Access); + + type Redland_World_Type_Without_Finalize is new Redland_World_Handled_Record.Base_Object with null record; + + subtype Redland_World_Handle is Redland_World_Handled_Record.Access_Type; + + overriding procedure Finalize_Handle (Object: Redland_World_Type_Without_Finalize; Handle: Redland_World_Handle); + + overriding function Default_Handle(Object: Redland_World_Type_Without_Finalize) + return Redland_World_Handle; + + not overriding procedure Open (Object: in out Redland_World_Type_Without_Finalize); + + not overriding procedure Set_Rasqal (World: Redland_World_Type_Without_Finalize; + Rasqal_World: Rasqal_World_Type_Without_Finalize'Class); + + not overriding function Get_Rasqal (World: Redland_World_Type_Without_Finalize) + return Rasqal_World_Type_Without_Finalize; + + not overriding procedure Set_Raptor (World: Redland_World_Type_Without_Finalize; + Raptor_World: Raptor_World_Type_Without_Finalize'Class); + + not overriding function Get_Raptor (World: Redland_World_Type_Without_Finalize) + return Raptor_World_Type_Without_Finalize; + + not overriding procedure Set_Digest (World: Redland_World_Type_Without_Finalize; Name: String); + + not overriding function Get_Feature (World: Redland_World_Type_Without_Finalize; + Feature: RDF.Redland.URI.URI_Type_Without_Finalize'Class) + return RDF.Redland.Node.Node_Type; + + not overriding procedure Set_Feature (World: Redland_World_Type_Without_Finalize; + Feature: RDF.Redland.URI.URI_Type_Without_Finalize'Class; + Value: RDF.Redland.Node.Node_Type_Without_Finalize'Class); + + package Handlers is new Redland_World_Handled_Record.Common_Handlers(Redland_World_Type_Without_Finalize); + + type Redland_World_Type is new Handlers.Base_With_Finalization with null record; + + type Redland_World_Type_User is new Handlers.User_Type with null record; + + not overriding function Open return Redland_World_Type; + + -- librdf_world_set_error() and librdf_world_set_warning() deliberately not implemented. + + -- I deliberately not implement librdf_world_set_raptor_init_handler() and + -- librdf_world_set_rasqal_init_handler(). + -- I recommend to use Set_Raptor and Set_Rasqal instead. + +end RDF.Redland.World; diff --git a/ada/src/rdf-redland.ads b/ada/src/rdf-redland.ads new file mode 100644 index 000000000..22b471c01 --- /dev/null +++ b/ada/src/rdf-redland.ads @@ -0,0 +1,3 @@ +package RDF.Redland is + pragma Pure; +end RDF.Redland; diff --git a/ada/src/rdf.ads b/ada/src/rdf.ads new file mode 100644 index 000000000..c99a7efb6 --- /dev/null +++ b/ada/src/rdf.ads @@ -0,0 +1,3 @@ +package RDF is + pragma Pure; +end RDF; diff --git a/ada/src/test/basic_test.adb b/ada/src/test/basic_test.adb new file mode 100644 index 000000000..35b9821a3 --- /dev/null +++ b/ada/src/test/basic_test.adb @@ -0,0 +1,30 @@ +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Rasqal.World; use RDF.Rasqal.World; +-- use all type Raptor_Flag_Type; + +package body Basic_Test is + + -- This just creates and assigns some variables (and ignores their values) + procedure Test_Open(T : in out Test_Cases.Test_Case'Class) is + Default_World: Raptor_World_Type := Open with Unreferenced; + World_With_Some_Flags: Raptor_World_Type := Open((1=>(Flag=>URI_Interning, Value=>False))) with Unreferenced; + + World2: Rasqal_World_Type := Open; + World: Raptor_World_Type_Without_Finalize := Get_Raptor(World2) with Unreferenced; + begin + null; + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("Constructors of worlds"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_Open'Access, "Testing the constructors and function Open"); + end Register_Tests; + +end Basic_Test; diff --git a/ada/src/test/basic_test.ads b/ada/src/test/basic_test.ads new file mode 100644 index 000000000..3e683d34a --- /dev/null +++ b/ada/src/test/basic_test.ads @@ -0,0 +1,14 @@ +with AUnit, AUnit.Test_Cases; use AUnit, AUnit.Test_Cases; + +package Basic_Test is + + type Test_Case is new AUnit.Test_Cases.Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end Basic_Test; diff --git a/ada/src/test/constants_test.adb b/ada/src/test/constants_test.adb new file mode 100644 index 000000000..b6f55adf8 --- /dev/null +++ b/ada/src/test/constants_test.adb @@ -0,0 +1,54 @@ +with AUnit.Assertions; +with Ada.Strings.Fixed; +with Interfaces.C; +with RDF.Raptor.Constants; +with RDF.Rasqal.Constants; + +package body Constants_Test is + + subtype unsigned is Interfaces.C.unsigned; + use type unsigned; + + function My_Image (I : Unsigned) return String is + begin + return Ada.Strings.Fixed.Trim (Unsigned'Image (I), Ada.Strings.Left); + end My_Image; + + -- This just creates and assigns some variables (and ignores their values) + + procedure Test_Raptor(T : in out Test_Cases.Test_Case'Class) is + use RDF.Raptor.Constants; + Combined_String: constant String := + My_Image(version_major) & '.' & My_Image(version_minor) & '.' & My_Image(version_release); + Combined_Decimal: constant unsigned := + version_major * 10000 + version_minor * 100 + version_release; + begin + AUnit.Assertions.Assert (Combined_String = version_string, "Combined version string"); + AUnit.Assertions.Assert (Combined_Decimal = version_decimal, "Combined decimal version"); + end; + + procedure Test_Rasqal(T : in out Test_Cases.Test_Case'Class) is + use RDF.Rasqal.Constants; + Combined_String: constant String := + My_Image(version_major) & '.' & My_Image(version_minor) & '.' & My_Image(version_release); + Combined_Decimal: constant unsigned := + version_major * 10000 + version_minor * 100 + version_release; + begin + AUnit.Assertions.Assert (Combined_String = version_string, "Combined version string"); + AUnit.Assertions.Assert (Combined_Decimal = version_decimal, "Combined decimal version"); + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("Some constants"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_Raptor'Access, "Testing version of Raptor"); + Register_Routine (T, Test_Rasqal'Access, "Testing version of Rasqal"); + end Register_Tests; + +end Constants_Test; diff --git a/ada/src/test/constants_test.ads b/ada/src/test/constants_test.ads new file mode 100644 index 000000000..ddedb04df --- /dev/null +++ b/ada/src/test/constants_test.ads @@ -0,0 +1,14 @@ +with AUnit, AUnit.Test_Cases; use AUnit, AUnit.Test_Cases; + +package Constants_Test is + + type Test_Case is new AUnit.Test_Cases.Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end Constants_Test; diff --git a/ada/src/test/count_test.adb b/ada/src/test/count_test.adb new file mode 100644 index 000000000..28f1cb5df --- /dev/null +++ b/ada/src/test/count_test.adb @@ -0,0 +1,74 @@ +with Ada.Strings.Unbounded; +with Ada.Containers.Indefinite_Vectors; +with AUnit.Assertions; use AUnit.Assertions; +with RDF.Auxiliary; +with RDF.Raptor.IOStream; +with RDF.Raptor.URI; +with RDF.Rasqal.World; +with RDF.Rasqal.Literal; +with RDF.Rasqal.Data_Graph; use RDF.Rasqal.Data_Graph; +with RDF.Rasqal.Query; use RDF.Rasqal.Query; +with RDF.Rasqal.Query_Results; use RDF.Rasqal.Query_Results; +with AUnit.Test_Cases; use AUnit.Test_Cases; + +package body Count_Test is + + procedure Test_Count (T : in out Test_Cases.Test_Case'Class) is + use Ada.Strings.Unbounded; + use RDF.Auxiliary.String_Holders; + use RDF.Raptor.URI; + use RDF.Raptor.IOStream; + use RDF.Rasqal.World; + T2: Test_Case renames Test_Case(T); + Directory: constant String := To_String(Get_Environment(T2).Directory); + RDF_File: constant String := Directory & "/../data/dc.nt"; + SPARQL: constant String := "SELECT (count(*) as ?count) WHERE { ?s ?p ?o . }"; + + World: Rasqal_World_Type := Open; + Graph_Stream: RDF.Raptor.IOStream.IOStream_Type := From_Filename(Get_Raptor(World), RDF_File); + Graph: Data_Graph_Type := From_IOStream(World, + Graph_Stream, + Base_URI => From_String(Get_Raptor(World), "http://example.org") + -- Name_URI => URI_Type'(From_Handle(null)), + -- Flags => Background, + -- Format_Type => Empty_Holder, + -- Format_Name => Empty_Holder, + -- Format_URI => URI_Type'(From_Handle(null)) + ); + Query: RDF.Rasqal.Query.Query_Type := Create(World, Empty_Holder, Empty_Holder); + begin + Prepare(Query, SPARQL); + Add_Data_Graph(Query, Graph); + declare + Results: Bindings_Query_Results_Type := Execute(Query); + package Rows_Holder is new Ada.Containers.Indefinite_Vectors(Positive, String); + use Ada.Containers, Rows_Holder; + Rows: Vector; + begin + Assert(Is_Bindings(Results), "Result is bindings"); + for I in Create_Bindings_Iterator(Results) loop + declare + use RDF.Rasqal.Literal; + L: Literal_Type_Without_Finalize := Get_Binding_Value_By_Name(I, "count"); + begin + Append(Rows, As_String(L)); + end; + end loop; + Assert(Length(Rows) = Count_Type(1), "count() returns one row"); + Assert(Element(Rows, 1) = "3", "count() = 3"); + end; + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("Test SPARQL count()"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_Count'Access, "count() = 3"); + end Register_Tests; + +end Count_Test; diff --git a/ada/src/test/count_test.ads b/ada/src/test/count_test.ads new file mode 100644 index 000000000..a978734bc --- /dev/null +++ b/ada/src/test/count_test.ads @@ -0,0 +1,15 @@ +with AUnit; use AUnit; +with Our_Test; + +package Count_Test is + + type Test_Case is new Our_Test.Our_Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end Count_Test; diff --git a/ada/src/test/count_test2.adb b/ada/src/test/count_test2.adb new file mode 100644 index 000000000..ec4df6645 --- /dev/null +++ b/ada/src/test/count_test2.adb @@ -0,0 +1,55 @@ +with Ada.Containers.Indefinite_Vectors; +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with AUnit.Assertions; use AUnit.Assertions; +with RDF.Redland.World; use RDF.Redland.World; +with RDF.Redland.URI; use RDF.Redland.URI; +with RDF.Redland.Node; use RDF.Redland.Node; +with RDF.Redland.Storage; use RDF.Redland.Storage; +with RDF.Redland.Model; use RDF.Redland.Model; +with RDF.Redland.Query; use RDF.Redland.Query; +with RDF.Redland.Query_Results; use RDF.Redland.Query_Results; +with AUnit.Test_Cases; +with Our_Test; use Our_Test; + +package body Count_Test2 is + + procedure Test_Empty(T : in out Test_Cases.Test_Case'Class) is + World: Redland_World_Type; + Storage: Storage_Type := Create(World, "memory", "test"); + Model: Model_Type := Create(World, Storage); + T2: Our_Test_Case renames Our_Test_Case(T); + Directory: constant String := To_String(Get_Environment(T2).Directory); + RDF_File: constant String := Directory & "/../data/dc.nt"; + SPARQL: constant String := "SELECT (count(*) as ?count) WHERE { ?s ?p ?o . }"; +-- Query: Query_Type := Copy(Create(World, "sparql", SPARQL)); -- FIXME: Copy causes an unhandled signal + Query: Query_Type := Create(World, "sparql", SPARQL); + Results: Bindings_Query_Results_Type := Query_Execute(Model, Query); + package Rows_Holder is new Ada.Containers.Indefinite_Vectors(Positive, String); + use Ada.Containers, Rows_Holder; + Rows: Vector; + begin + Load(Model, From_Filename(World, RDF_File)); + for I in Create_Bindings_Iterator(Results) loop + declare + L: Literal_Node_Type := Get_Binding_Value_By_Name(I, "count"); + begin + Append(Rows, As_String(L)); + end; + end loop; + Assert(Length(Rows) = Count_Type(1), "count() returns one row"); + Assert(Element(Rows, 1) = "3", "count() = 3"); + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("Redland query"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_Empty'Access, "count() = 3"); + end Register_Tests; + +end Count_Test2; diff --git a/ada/src/test/count_test2.ads b/ada/src/test/count_test2.ads new file mode 100644 index 000000000..12876ec69 --- /dev/null +++ b/ada/src/test/count_test2.ads @@ -0,0 +1,15 @@ +with AUnit; use AUnit; +with Our_Test; + +package Count_Test2 is + + type Test_Case is new Our_Test.Our_Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end Count_Test2; diff --git a/ada/src/test/empty_stream_test.adb b/ada/src/test/empty_stream_test.adb new file mode 100644 index 000000000..d593d6eab --- /dev/null +++ b/ada/src/test/empty_stream_test.adb @@ -0,0 +1,30 @@ +with AUnit.Assertions; use AUnit.Assertions; +with RDF.Redland.World; use RDF.Redland.World; +with RDF.Redland.Stream; use RDF.Redland.Stream; + +package body Empty_Stream_Test is + + procedure Test_Empty(T : in out Test_Cases.Test_Case'Class) is + World: Redland_World_Type; + Stream: Stream_Type := Empty_Stream(World); + Counter: Natural := 0; + begin + for X in Create_Stream_Iterator(Stream) loop + Counter := Counter + 1; + end loop; + Assert(Counter = 0, "Zero counter"); + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("Empty Redland stream"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_Empty'Access, "Testing empty streams"); + end Register_Tests; + +end Empty_Stream_Test; diff --git a/ada/src/test/empty_stream_test.ads b/ada/src/test/empty_stream_test.ads new file mode 100644 index 000000000..3cd6f3712 --- /dev/null +++ b/ada/src/test/empty_stream_test.ads @@ -0,0 +1,14 @@ +with AUnit, AUnit.Test_Cases; use AUnit, AUnit.Test_Cases; + +package Empty_Stream_Test is + + type Test_Case is new AUnit.Test_Cases.Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end Empty_Stream_Test; diff --git a/ada/src/test/iostreams_test.adb b/ada/src/test/iostreams_test.adb new file mode 100644 index 000000000..8978b96bb --- /dev/null +++ b/ada/src/test/iostreams_test.adb @@ -0,0 +1,52 @@ +with Interfaces.C; use Interfaces.C; +with Interfaces.C.Strings; use Interfaces.C.Strings; +with AUnit.Assertions; use AUnit.Assertions; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Raptor.Iostream; use RDF.Raptor.Iostream; + +package body Iostreams_Test is + + procedure Test_Sinks(T : in out Test_Cases.Test_Case'Class) is + World: Raptor_World_Type; + Str: aliased char_array := "qqq"; + In_Sink: IOStream_Type := From_Sink(World); + Out_Sink: IOStream_Type := To_Sink (World); + begin + Assert (Read_Bytes (To_Chars_Ptr (Str'Unchecked_Access), 10, 10, In_Sink) = 0, "Read zero bytes from a sink"); + Write ("XYZ", Out_Sink); -- does nothing + end; + + procedure Test_Strings(T : in out Test_Cases.Test_Case'Class) is + World: Raptor_World_Type; + Str : String := "xqqq"; + Buf: aliased char_array := (1..99=>'w', 100=>NUL); + In_String: Stream_From_String := Open_From_String (World, Str); + Out_String: Stream_To_String := Open (World); + Out_String2: Stream_To_String := Open (World); + Bytes_Read: size_t; + begin + Bytes_Read := Read_Bytes (To_Chars_Ptr (Buf'Unchecked_Access), 1, 100, In_String); + Assert (Bytes_Read = 4, "Read 4 bytes from string"); + Assert (To_Ada (Buf(1..4), Trim_Nul=>False) = Str, "Compare read string"); + Write(Str, Out_String); + Write("QQ", Out_String); + Assert (Value (Out_String) = Str & "QQ", "Compare written string"); + Assert (Tell (Out_String) = 4+2, "'Tell' position"); + Decimal_Write (1234, Out_String2); + Assert (Value (Out_String2) = "1234", "Decimal write"); + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("Streams"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_Sinks'Access, "Testing sinks"); + Register_Routine (T, Test_Strings'Access, "Testing string streams"); + end Register_Tests; + +end Iostreams_Test; diff --git a/ada/src/test/iostreams_test.ads b/ada/src/test/iostreams_test.ads new file mode 100644 index 000000000..5669aa7af --- /dev/null +++ b/ada/src/test/iostreams_test.ads @@ -0,0 +1,15 @@ +with AUnit, AUnit.Test_Cases; use AUnit, AUnit.Test_Cases; +-- with RDF.Raptor.World; + +package Iostreams_Test is + + type Test_Case is new AUnit.Test_Cases.Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end Iostreams_Test; diff --git a/ada/src/test/namespaces_test.adb b/ada/src/test/namespaces_test.adb new file mode 100644 index 000000000..8010ef4b4 --- /dev/null +++ b/ada/src/test/namespaces_test.adb @@ -0,0 +1,37 @@ +with AUnit.Assertions; use AUnit.Assertions; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.Namespace; use RDF.Raptor.Namespace; +with RDF.Raptor.Namespace_Stack; use RDF.Raptor.Namespace_Stack; +with RDF.Raptor.World; use RDF.Raptor.World; + +package body Namespaces_Test is + + procedure Test_Stacks(T : in out Test_Cases.Test_Case'Class) is + World: Raptor_World_Type; + + Stack: Namespace_Stack_Type := Create_Stack (World, XML_Type); + + URI_1_Obj: constant URI_Type := From_String(World, "http://www.w3.org/1999/xhtml/"); + + NS1: Namespace_Type := Create (Stack, "xhtml", "http://www.w3.org/1999/xhtml/", 1); + NS2: Namespace_Type := From_URI (Stack, "xhtml", URI_1_Obj, 1); + begin + Assert (To_String(Get_URI(NS1)) = "http://www.w3.org/1999/xhtml/", "Check namespace URI"); + Assert (To_String(Get_URI(NS2)) = "http://www.w3.org/1999/xhtml/", "Check namespace URI"); + Assert (Get_Prefix(NS1) = "xhtml", "Check namespace prefix"); + Assert (Get_Prefix(NS2) = "xhtml", "Check namespace prefix"); + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("Namespaces"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_Stacks'Access, "Testing namespace stacks"); + end Register_Tests; + +end Namespaces_Test; diff --git a/ada/src/test/namespaces_test.ads b/ada/src/test/namespaces_test.ads new file mode 100644 index 000000000..7abeaa354 --- /dev/null +++ b/ada/src/test/namespaces_test.ads @@ -0,0 +1,15 @@ +with AUnit, AUnit.Test_Cases; use AUnit, AUnit.Test_Cases; +-- with RDF.Raptor.World; + +package Namespaces_Test is + + type Test_Case is new AUnit.Test_Cases.Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end Namespaces_Test; diff --git a/ada/src/test/our_test.adb b/ada/src/test/our_test.adb new file mode 100644 index 000000000..414654920 --- /dev/null +++ b/ada/src/test/our_test.adb @@ -0,0 +1,11 @@ +package body Our_Test is + + function Get_Environment (C: Our_Test_Case) + return Raptor_Environments.Raptor_Environment_Access + is + use AUnit.Test_Cases; + begin + return Raptor_Environments.Raptor_Environment_Access(AUnit.Test_Cases.Get_Environment(Test_Case(C))); + end Get_Environment; + +end Our_Test; diff --git a/ada/src/test/our_test.ads b/ada/src/test/our_test.ads new file mode 100644 index 000000000..ffb8c8786 --- /dev/null +++ b/ada/src/test/our_test.ads @@ -0,0 +1,11 @@ +with AUnit.Test_Cases; +with Raptor_Environments; + +package Our_Test is + + type Our_Test_Case is abstract new AUnit.Test_Cases.Test_Case with null record; + + function Get_Environment (C: Our_Test_Case) + return Raptor_Environments.Raptor_Environment_Access; + +end Our_Test; diff --git a/ada/src/test/raptor_environments.ads b/ada/src/test/raptor_environments.ads new file mode 100644 index 000000000..51479c6c3 --- /dev/null +++ b/ada/src/test/raptor_environments.ads @@ -0,0 +1,13 @@ +with Ada.Strings.Unbounded; +with AUnit.Environments; + +package Raptor_Environments is + + type Raptor_Environment is new AUnit.Environments.Environment with + record + Directory: Ada.Strings.Unbounded.Unbounded_String; + end record; + + type Raptor_Environment_Access is access all Raptor_Environment; + +end Raptor_Environments; diff --git a/ada/src/test/raptor_test_suite.adb b/ada/src/test/raptor_test_suite.adb new file mode 100644 index 000000000..e2c727039 --- /dev/null +++ b/ada/src/test/raptor_test_suite.adb @@ -0,0 +1,60 @@ +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with Ada.Command_Line; +with AUnit.Environments; +with Raptor_Environments; +with Basic_Test; +with Constants_Test; +with Iostreams_Test; +with URI_Test; +with Namespaces_Test; +with Term_Test; +with Statement_Test; +with Syntaxes_Test; +with Count_Test; +with Empty_Stream_Test; +with Stream_Test; +with Count_Test2; + +package body Raptor_Test_Suite is + + use AUnit.Test_Suites; + + Env: aliased Raptor_Environments.Raptor_Environment := + (AUnit.Environments.Environment with Directory => To_Unbounded_String(Ada.Command_Line.Argument(1))); + + -- Statically allocate test suite: + Result : aliased Test_Suite; + + -- Statically allocate test cases: + Test_Case_1 : aliased Basic_Test.Test_Case; + Test_Case_2 : aliased Constants_Test.Test_Case; + Test_Case_3 : aliased Iostreams_Test.Test_Case; + Test_Case_4 : aliased URI_Test.Test_Case; + Test_Case_5 : aliased Namespaces_Test.Test_Case; + Test_Case_6 : aliased Term_Test.Test_Case; + Test_Case_7 : aliased Statement_Test.Test_Case; + Test_Case_8 : aliased Syntaxes_Test.Test_Case; + Test_Case_9 : aliased Count_Test.Test_Case; + Test_Case_10 : aliased Empty_Stream_Test.Test_Case; + Test_Case_11 : aliased Stream_Test.Test_Case; + Test_Case_12 : aliased Count_Test2.Test_Case; + + function Suite return Access_Test_Suite is + begin + Set_Environment (Result, Env'Access); + Add_Test (Result'Access, Test_Case_1'Access); + Add_Test (Result'Access, Test_Case_2'Access); + Add_Test (Result'Access, Test_Case_3'Access); + Add_Test (Result'Access, Test_Case_4'Access); + Add_Test (Result'Access, Test_Case_5'Access); + Add_Test (Result'Access, Test_Case_6'Access); + Add_Test (Result'Access, Test_Case_7'Access); + Add_Test (Result'Access, Test_Case_8'Access); + Add_Test (Result'Access, Test_Case_9'Access); + Add_Test (Result'Access, Test_Case_10'Access); + Add_Test (Result'Access, Test_Case_11'Access); + Add_Test (Result'Access, Test_Case_12'Access); + return Result'Access; + end Suite; + +end Raptor_Test_Suite; diff --git a/ada/src/test/raptor_test_suite.ads b/ada/src/test/raptor_test_suite.ads new file mode 100644 index 000000000..f8237145d --- /dev/null +++ b/ada/src/test/raptor_test_suite.ads @@ -0,0 +1,7 @@ +with AUnit.Test_Suites; + +package Raptor_Test_Suite is + + function Suite return AUnit.Test_Suites.Access_Test_Suite; + +end Raptor_Test_Suite; diff --git a/ada/src/test/run_all_tests.adb b/ada/src/test/run_all_tests.adb new file mode 100644 index 000000000..45d677201 --- /dev/null +++ b/ada/src/test/run_all_tests.adb @@ -0,0 +1,10 @@ +with Raptor_Test_Suite; +with AUnit.Run; +with AUnit.Reporter.Text; + +procedure Run_All_Tests is + procedure Run is new AUnit.Run.Test_Runner (Raptor_Test_Suite.Suite); + Reporter : AUnit.Reporter.Text.Text_Reporter; +begin + Run (Reporter); +end Run_All_Tests; diff --git a/ada/src/test/special_test.adb b/ada/src/test/special_test.adb new file mode 100644 index 000000000..77efc6e21 --- /dev/null +++ b/ada/src/test/special_test.adb @@ -0,0 +1,23 @@ +-- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62236 (FIXED) +with Ada.Iterator_Interfaces; + +procedure Special_Test is + + type My_Description_Cursor is null record; + + function Has_Element (Position: My_Description_Cursor) return Boolean is (False); + + package My_Description_Iterators is new Ada.Iterator_Interfaces(My_Description_Cursor, Has_Element); + + type My_Description_Iterator is new My_Description_Iterators.Forward_Iterator with null record; + + overriding function First (Object: My_Description_Iterator) return My_Description_Cursor is (null record); + overriding function Next (Object: My_Description_Iterator; Position: My_Description_Cursor) return My_Description_Cursor is (null record); + + My_Iterator: My_Description_Iterator; + +begin + for C in My_Iterator loop + null; + end loop; +end; diff --git a/ada/src/test/statement_test.adb b/ada/src/test/statement_test.adb new file mode 100644 index 000000000..c9f0d31ef --- /dev/null +++ b/ada/src/test/statement_test.adb @@ -0,0 +1,39 @@ +with AUnit.Assertions; use AUnit.Assertions; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.Term; use RDF.Raptor.Term; +with RDF.Raptor.Statement; use RDF.Raptor.Statement; +with RDF.Raptor.World; use RDF.Raptor.World; + +package body Statement_Test is + + procedure Test_Statements(T : in out Test_Cases.Test_Case'Class) is + World: Raptor_World_Type; + + URI_1: constant URI_String := "http://example.org/xyz"; + URI_2: constant URI_String := "http://example.org/qqq"; + URI_3: constant URI_String := "http://example.org/123"; + + Term_1: Term_Type := From_URI_String(World, URI_1); + Term_2: Term_Type := From_URI_String(World, URI_2); + Term_3: Term_Type := From_URI_String(World, URI_3); + + St: Statement_Type := Create(World, Term_1, Term_2, Term_3); + begin + Assert(To_String(Get_Subject (St)) = String("<" & URI_1 & ">"), "Subject matches"); + Assert(To_String(Get_Predicate(St)) = String("<" & URI_2 & ">"), "Predicate matches"); + Assert(To_String(Get_Object (St)) = String("<" & URI_3 & ">"), "Object matches"); + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("RDF statements"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_Statements'Access, "Testing statements"); + end Register_Tests; + +end Statement_Test; diff --git a/ada/src/test/statement_test.ads b/ada/src/test/statement_test.ads new file mode 100644 index 000000000..b078e99f4 --- /dev/null +++ b/ada/src/test/statement_test.ads @@ -0,0 +1,15 @@ +with AUnit, AUnit.Test_Cases; use AUnit, AUnit.Test_Cases; +-- with RDF.Raptor.World; + +package Statement_Test is + + type Test_Case is new AUnit.Test_Cases.Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end Statement_Test; diff --git a/ada/src/test/stream_test.adb b/ada/src/test/stream_test.adb new file mode 100644 index 000000000..980a37252 --- /dev/null +++ b/ada/src/test/stream_test.adb @@ -0,0 +1,45 @@ +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with AUnit.Assertions; use AUnit.Assertions; +with RDF.Redland.World; use RDF.Redland.World; +with RDF.Redland.URI; use RDF.Redland.URI; +with RDF.Redland.Stream; use RDF.Redland.Stream; +with RDF.Redland.Storage; use RDF.Redland.Storage; +with RDF.Redland.Model; use RDF.Redland.Model; +with AUnit.Test_Cases; +with Our_Test; use Our_Test; + +package body Stream_Test is + + procedure Test_Empty(T : in out Test_Cases.Test_Case'Class) is + World: Redland_World_Type; + Storage: Storage_Type := Create(World, "memory", "test"); + Model: Model_Type := Create(World, Storage); + T2: Our_Test_Case renames Our_Test_Case(T); + Directory: constant String := To_String(Get_Environment(T2).Directory); + RDF_File: constant String := Directory & "/../data/dc.nt"; + begin + Load(Model, From_Filename(World, RDF_File)); + declare + Stream: Stream_Type := As_Stream(Model); + Counter: Natural := 0; + begin + for X in Create_Stream_Iterator(Stream) loop + Counter := Counter + 1; + end loop; + Assert(Counter = 3, "Counter = 3"); + end; + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("Redland stream"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_Empty'Access, "Testing stream elements count"); + end Register_Tests; + +end Stream_Test; diff --git a/ada/src/test/stream_test.ads b/ada/src/test/stream_test.ads new file mode 100644 index 000000000..e890709bb --- /dev/null +++ b/ada/src/test/stream_test.ads @@ -0,0 +1,15 @@ +with AUnit; use AUnit; +with Our_Test; + +package Stream_Test is + + type Test_Case is new Our_Test.Our_Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end Stream_Test; diff --git a/ada/src/test/syntaxes_test.adb b/ada/src/test/syntaxes_test.adb new file mode 100644 index 000000000..2ec817457 --- /dev/null +++ b/ada/src/test/syntaxes_test.adb @@ -0,0 +1,48 @@ +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Rasqal.World; use RDF.Rasqal.World; +with RDF.Raptor.Syntaxes; use RDF.Raptor.Syntaxes; +with RDF.Rasqal.Syntaxes; use RDF.Rasqal.Syntaxes; + +package body Syntaxes_Test is + + procedure Test_Enum_Syntaxes (T : in out Test_Cases.Test_Case'Class) is + World2: Rasqal_World_Type := Open; + World: Raptor_World_Type_Without_Finalize := Get_Raptor(World2); + + Iterator: Parser_Description_Iterator := Create_Parser_Descriptions_Iterator(World); + Cursor: Parser_Description_Cursor := First(Iterator); + Iterator2: Serializer_Description_Iterator := Create_Serializer_Descriptions_Iterator(World); + Cursor2: Serializer_Description_Cursor := First(Iterator2); + Iterator3: Query_Language_Description_Iterator := Create_Query_Language_Descriptions_Iterator(World2); + Cursor3: Query_Language_Description_Cursor := First(Iterator3); + Iterator4: Query_Results_Format_Description_Iterator := Create_Query_Results_Format_Descriptions_Iterator(World2); + Cursor4: Query_Results_Format_Description_Cursor := First(Iterator4); + begin + -- Does not compile with GCC 4.9.1 + while Has_Element(Cursor) loop + Cursor := Next(Iterator, Cursor); + end loop; + while Has_Element(Cursor2) loop + Cursor2 := Next(Iterator2, Cursor2); + end loop; + while Has_Element(Cursor3) loop + Cursor3 := Next(Iterator3, Cursor3); + end loop; + while Has_Element(Cursor4) loop + Cursor4 := Next(Iterator4, Cursor4); + end loop; + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("Enumerating syntaxes"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_Enum_Syntaxes'Access, "Enumerating syntaxes is finite"); + end Register_Tests; + +end Syntaxes_Test; diff --git a/ada/src/test/syntaxes_test.ads b/ada/src/test/syntaxes_test.ads new file mode 100644 index 000000000..35857aa5b --- /dev/null +++ b/ada/src/test/syntaxes_test.ads @@ -0,0 +1,14 @@ +with AUnit, AUnit.Test_Cases; use AUnit, AUnit.Test_Cases; + +package Syntaxes_Test is + + type Test_Case is new AUnit.Test_Cases.Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end Syntaxes_Test; diff --git a/ada/src/test/term_test.adb b/ada/src/test/term_test.adb new file mode 100644 index 000000000..f05c3ec65 --- /dev/null +++ b/ada/src/test/term_test.adb @@ -0,0 +1,45 @@ +with AUnit.Assertions; use AUnit.Assertions; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.Term; use RDF.Raptor.Term; +with RDF.Raptor.World; use RDF.Raptor.World; +with RDF.Auxiliary; + +package body Term_Test is + + procedure Test_Terms(T : in out Test_Cases.Test_Case'Class) is + World: Raptor_World_Type; + + Term_1: Term_Type := From_Literal (World, + RDF.Auxiliary.String_Holders.To_Holder("QWE"), + From_String(World, "http://example.org"), -- datatype + RDF.Auxiliary.String_Holders.Empty_Holder -- language + ); + Term_2: Term_Type := From_URI_String(World, "http://example.org/abc"); + Term_3: Term_Type := From_URI(World, From_String(World, "http://example.org/cvb")); + Term_4: Term_Type := From_String(World, """ZZZ"""); -- Turtle string + begin + Assert(Value(Get_Literal(Term_1)) = "QWE", "Term_1 value"); + Assert(To_String(Get_URI(Term_2)) = "http://example.org/abc", "Term_2 URI"); + Assert(To_String(Get_URI(Term_3)) = "http://example.org/cvb", "Term_3 URI"); + Assert(Value(Get_Literal(Term_4)) = "ZZZ", "Term_4 value"); + Assert(To_String(Datatype(Get_Literal(Term_1))) = "http://example.org", "Term_1 datatype"); -- infinite loop! why? + Assert(Term_1 /= Term_2, "Non-equal terms"); + Assert(Get_Kind(Term_1) = Literal, "Term_1 is literal"); + Assert(Get_Kind(Term_2) = URI, "Term_2 is URI"); + Assert(Get_Kind(Term_3) = URI, "Term_3 is URI"); + Assert(Get_Kind(Term_4) = Literal, "Term_4 is literal"); + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("RDF terms"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_Terms'Access, "Testing terms"); + end Register_Tests; + +end Term_Test; diff --git a/ada/src/test/term_test.ads b/ada/src/test/term_test.ads new file mode 100644 index 000000000..dd673ad0f --- /dev/null +++ b/ada/src/test/term_test.ads @@ -0,0 +1,15 @@ +with AUnit, AUnit.Test_Cases; use AUnit, AUnit.Test_Cases; +-- with RDF.Raptor.World; + +package Term_Test is + + type Test_Case is new AUnit.Test_Cases.Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end Term_Test; diff --git a/ada/src/test/uri_test.adb b/ada/src/test/uri_test.adb new file mode 100644 index 000000000..4515382ab --- /dev/null +++ b/ada/src/test/uri_test.adb @@ -0,0 +1,35 @@ +with AUnit.Assertions; use AUnit.Assertions; +with RDF.Raptor.URI; use RDF.Raptor.URI; +with RDF.Raptor.World; use RDF.Raptor.World; + +package body URI_Test is + + procedure Test_URIs(T : in out Test_Cases.Test_Case'Class) is + World: Raptor_World_Type; + URI_1: constant URI_String := "http://example.org/xyz"; + URI_3: constant URI_String := "http://example.org/123"; + URI_1_Obj: constant URI_Type := From_String(World, URI_1); + URI_2_Obj: constant URI_Type := From_String(World, URI_1); + URI_3_Obj: constant URI_Type := From_String(World, URI_3); + URI_4_Obj: constant URI_Type := From_String(World, "http://example.org"); + begin + Assert (To_String(URI_1_Obj) = URI_1, "Converting URI to string"); + Assert (URI_1_Obj = URI_2_Obj, "Comparing identical URIs"); + Assert (URI_1_Obj /= URI_3_Obj, "Comparing different URIs"); + Assert (To_String(From_URI_Relative_To_Base(World, URI_1_Obj, "zxc")) = "http://example.org/zxc", "Relative URI to base"); + Assert (To_String(For_Retrieval(URI_4_Obj)) = "http://example.org/", "URI for retrieval"); + end; + + function Name (T : Test_Case) + return Test_String is + begin + return Format ("URIs"); + end Name; + + procedure Register_Tests (T : in out Test_Case) is + use AUnit.Test_Cases.Registration; + begin + Register_Routine (T, Test_URIs'Access, "Testing URIs"); + end Register_Tests; + +end URI_Test; diff --git a/ada/src/test/uri_test.ads b/ada/src/test/uri_test.ads new file mode 100644 index 000000000..b0210c85d --- /dev/null +++ b/ada/src/test/uri_test.ads @@ -0,0 +1,15 @@ +with AUnit, AUnit.Test_Cases; use AUnit, AUnit.Test_Cases; +-- with RDF.Raptor.World; + +package URI_Test is + + type Test_Case is new AUnit.Test_Cases.Test_Case with null record; + + procedure Register_Tests (T : in out Test_Case); + -- Register routines to be run + + function Name (T : Test_Case) + return Test_String; + -- Returns name identifying the test case + +end URI_Test; diff --git a/ada/test.gpr b/ada/test.gpr new file mode 100644 index 000000000..f92e1a447 --- /dev/null +++ b/ada/test.gpr @@ -0,0 +1,49 @@ +with "librdf.gpr"; +with "libaunit-3.7.2/lib/gnat/aunit.gpr"; + +project Test is + + for Object_Dir use "obj-static/test"; + type Runtime_Type is + ("cert", "default", "full", "hi", "kernel", "kernel-sjlj", "kernel-smp", "pthread", "sjlj", "ravenscar", "ravenscar-apex", "ravenscar-full", "ravenscar-cert", "ravenscar-cert-rci", "ravenscar-cert-rtp", "ravenscar-sfp", "rtp", "rtp-smp", + "soft-float", "xenomai", "zcx", "zfp", "minimal"); + Runtime : Runtime_Type := external ("RUNTIME", "default"); + type Compilation_Mode_Type is + ("Devel", "Install"); + Mode : Compilation_Mode_Type := external ("MODE", "default"); + + type Debug_Mode_Type is ("debug", "release", "check"); + Debug_Mode : Debug_Mode_Type := external ("DEBUG_MODE", "debug"); + + for Main use ("run_all_tests.adb"); + for Source_Dirs use ("src/test"); + + package Compiler is + Common_Ada_Flags := ("-gnat2012", + "-gnaty3", "-gnatya", "-gnatyA", "-gnatyb", "-gnatyd", "-gnatyf", "-gnatyh", "-gnatyi", "-gnatyl", "-gnatyp", "-gnatyx", + "-gnatwe", "-gnatwa", "-gnatwF", + "-gnatwK"); + + Debug_Flags := (); + case Debug_Mode is + when "debug" => + Debug_Flags := ("-g", "-gnata"); + when "release" => + Debug_Flags := ("-O2"); + when "check" => + Debug_Flags := ("-gnatc"); + end case; + + for Default_Switches ("Ada") use Common_Ada_Flags & Debug_Flags; + end Compiler; + + package Linker is + for Linker_Options use (); + end Linker; + + package Ide is + for Vcs_Kind use "Git"; + end Ide; + +end Test; + diff --git a/autogen.sh b/autogen.sh index dddc15f84..d8f2aa526 100755 --- a/autogen.sh +++ b/autogen.sh @@ -129,7 +129,7 @@ for my \$varg (qw(--version -version)) { while() { chomp; next if @vnums; # drain pipe if we got a vnums - next unless /^\$mname/i; + next unless /\$name.*\d+\.\d+.*/i; my(\$v)=/(\S+)\$/i; \$v =~ s/-.*\$//; @vnums=grep { defined \$_ && !/^\s*\$/} map { s/\D//g; \$_; } split(/\./, \$v); } diff --git a/configure.ac b/configure.ac index 8b0991487..d671dba26 100644 --- a/configure.ac +++ b/configure.ac @@ -5,25 +5,25 @@ dnl (Process this file with autoconf to produce a configure script.) dnl dnl Copyright (C) 2000-2011, David Beckett http://www.dajobe.org/ dnl Copyright (C) 2000-2005 Copyright (C) 2000-2005, University of Bristol, UK http://www.bristol.ac.uk/ -dnl +dnl dnl This package is Free Software and part of Redland http://librdf.org/ -dnl +dnl dnl It is licensed under the following three licenses as alternatives: dnl 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version dnl 2. GNU General Public License (GPL) V2 or any newer version dnl 3. Apache License, V2.0 or any newer version -dnl +dnl dnl You may not use this file except in compliance with at least one of dnl the above three licenses. -dnl +dnl dnl See LICENSE.html or LICENSE.txt at the top of this package for the dnl complete terms and further detail along with the license texts for dnl the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively. -dnl -dnl +dnl +dnl -AC_INIT([Redland librdf Language bindings],[1.0.17.2],[http://bugs.librdf.org/],[redland-bindings]) +AC_INIT([Redland librdf Language bindings],[1.0.14],[http://bugs.librdf.org/],[redland-bindings]) AC_PREREQ([2.62]) AC_CONFIG_SRCDIR(perl/example.pl) AC_REVISION($Revision$)dnl @@ -34,7 +34,7 @@ AM_INIT_AUTOMAKE([1.11 check-news std-options -Wobsolete -Wportability -Wsyntax AM_MAINTAINER_MODE dnl 1.0.14 probably also works (Raptor and Rasqal dependencies the same) -MIN_REDLAND_VERSION=1.0.15 +MIN_REDLAND_VERSION=1.0.14 AC_CANONICAL_HOST @@ -46,6 +46,15 @@ AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET +AC_ARG_ENABLE([debug], +[ --enable-debug Turn on debugging], +[case "${enableval}" in + yes) debug=true ;; + no) debug=false ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;; +esac],[debug=false]) +AM_CONDITIONAL([DEBUG], [test x$debug = xtrue]) + m4_undefine([AC_PROG_CXX]) m4_defun([AC_PROG_CXX],[]) m4_undefine([AC_PROG_F77]) @@ -60,10 +69,14 @@ AC_CHECK_PROGS(PYTHON, python) AC_CHECK_PROGS(PERL, perl) AC_CHECK_PROGS(PHP, php) AC_CHECK_PROGS(RUBY, ruby) +AC_CHECK_PROGS(R, R) AC_CHECK_PROGS(SWIG, swig) # Gnome AC_CHECK_PROGS(PKG_CONFIG, pkg-config) +AC_SUBST(prefix) +AC_SUBST(includedir) + if test "X$PERL" != "X"; then PERLINSTALLSITEARCH=`$PERL -MConfig -e 'print $Config{installsitearch};'` PERLMAN3DIR=`$PERL -MConfig -e 'print $Config{man3dir};'` @@ -168,7 +181,7 @@ if test "X$PHP_CONFIG" != X ; then fi # Configure these if PHP_SO_SUFFIX is missing - if test "X$PHP_SO_SUFFIX" = "X"; then + if test "X$PHP_SO_SUFFIX" = "X"; then # OSX/Darwin default is bundle if test `uname` = Darwin; then # FIXME - how to decide between bundle and dylib? @@ -336,6 +349,39 @@ else fi +AC_ARG_WITH(R, [ --with-R(=R) Enable the R interface], with_R="$withval", with_R="no") +AC_MSG_CHECKING(Enable R API) +if test "X$with_R" != Xno ; then + if test "X$with_R" != Xyes; then + R=$with_R + fi + with_R=yes +fi +AC_MSG_RESULT($with_R) + +R_VERSION= +R_CFLAGS= +R_LDFLAGS= +if test "X$with_R" = Xyes -a -n "$PKG_CONFIG"; then + AC_MSG_CHECKING(R Version) + R_PKGCONFIG=lib$R + R_VERSION=`$PKG_CONFIG $R_PKGCONFIG --modversion` + R_CFLAGS=`$PKG_CONFIG $R_PKGCONFIG --cflags` + R_LDFLAGS=`$PKG_CONFIG $R_PKGCONFIG --libs` + AC_MSG_RESULT($R_VERSION) +fi +AC_SUBST(R_CFLAGS) +AC_SUBST(R_LDFLAGS) + +if test "X$R_VERSION" != X; then + languages_available="$languages_available R($R_VERSION)" + if test $with_R = yes; then + languages="$languages R" + fi +fi + + + AC_ARG_WITH(ruby-arch-install-dir-variable, [ --with-ruby-arch-install-dir-variable=NAME Set Ruby arch install directory config variable (default 'archdir')], ruby_arch_install_dir_variable="$withval", ruby_arch_install_dir_variable="archdir") dnl Setting this overrides ruby-arch-install-dir-variable above @@ -482,6 +528,45 @@ AC_MSG_RESULT($with_ruby) AC_SUBST(RUBY_VERSION) +AC_ARG_WITH(ada, [ --with-ada Enable the Ada interface], with_ada="$withval", with_ada="no") +AC_MSG_CHECKING(Enable Ada API) + +if test "X$with_ada" != Xno; then + languages="$languages ada" +fi +AC_MSG_RESULT($with_ada) + +if test "X$with_ada" != Xno; then + AC_ARG_WITH(gprbuild, [ --with-gprbuild(=gprbuild) Ada builder], GPRBUILD="$withval") + AC_ARG_WITH(gprclean, [ --with-gprclean(=gprclean) Ada cleaner], GPRCLEAN="$withval") + AC_ARG_WITH(gprinstall, [ --with-gprbuild(=gprinstall) Ada installer], GPRINSTALL="$withval") + + AC_CHECK_PROGS(GPRBUILD, gprbuild) + AC_CHECK_PROGS(GPRCLEAN, gprclean) + AC_CHECK_PROGS(GPRINSTALL, gprinstall) +fi + +AC_SUBST(GPRBUILD) +AC_SUBST(GPRCLEAN) +AC_SUBST(GPRINSTALL) + +AC_ARG_WITH(dlang, [ --with-dlang Enable the D interface], with_dlang="$withval", with_dlang="no") +AC_MSG_CHECKING(Enable D API) + +if test "X$with_dlang" != Xno; then + languages="$languages dlang" + AC_ARG_VAR(DUB, [D DUB package manager]) + AC_CHECK_PROGS(DUB, dub, [no-dub]) + if test "X$DUB" = "Xno-dub"; then + AC_MSG_ERROR([DUB package manager for D not found]) + fi + AC_ARG_VAR(DC, [D compiler]) + AC_CHECK_PROGS(DC, ldc2 ldc gdc dmd) + AC_ARG_VAR(DFLAGS, [D flags]) + AC_ARG_VAR(D_LDFLAGS, [Linker flags for D]) +fi +AC_MSG_RESULT($with_dlang) + AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir) AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) @@ -493,9 +578,9 @@ release_version=no AC_ARG_ENABLE(release, [ --enable-release Turn on optimizations (for maintainer). ], \ if test "$enableval" = "yes"; then \ release_version=yes -fi;) +fi;) -if test "$USE_MAINTAINER_MODE" = yes -a $release_version = no; then +if test "$USE_MAINTAINER_MODE" = yes -a $release_version = no; then CFLAGS=`echo $CFLAGS | sed s/-O2//` CXXFLAGS=`echo $CXXFLAGS | sed s/-O2//` CPPFLAGS=`echo $CPPFLAGS | sed s/-O2//` @@ -568,7 +653,7 @@ dnl needed for some bindings such as python to link raptor locator functions RAPTOR_LDFLAGS=`$PKG_CONFIG raptor2 --libs` RASQAL_LDFLAGS=`$PKG_CONFIG rasqal --libs` - +RASQAL_VERSION=`$PKG_CONFIG rasqal --modversion` dnl Checks for building sub-packages in sub directories SD="$languages" @@ -589,6 +674,8 @@ LIBS= CPPFLAGS= LDFLAGS= +AC_SUBST(RASQAL_VERSION) + AC_SUBST(LIBRDF_CPPFLAGS) AC_SUBST(LIBRDF_LDFLAGS) @@ -619,13 +706,18 @@ lua/Makefile php/Makefile python/Makefile python/test/Makefile +R/Makefile ruby/Makefile ruby/test/Makefile ruby/lib/Makefile ruby/lib/rdf/Makefile ruby/lib/rdf/redland/Makefile ruby/lib/rdf/redland/schemas/Makefile +ada/Makefile +dlang/Makefile +dlang/source/rdf/config.d data/Makefile +docs/ada/Makefile ]) AC_CONFIG_FILES([redland-bindings.spec]) AC_CONFIG_FILES([perl/lib/RDF/Redland.pm]) @@ -636,4 +728,4 @@ AC_MSG_RESULT([ Redland build summary: Redland: $REDLAND_VERSION Language APIs built: $languages -]) +]) \ No newline at end of file diff --git a/dlang/Makefile.am b/dlang/Makefile.am new file mode 100644 index 000000000..b187cf6e4 --- /dev/null +++ b/dlang/Makefile.am @@ -0,0 +1,41 @@ +# TODO: Take --enable-shared --enable-static into account +all-local: librdf_dlang.a librdf_dlang.so + +my-check: rdf_dlang + ./rdf_dlang $(srcdir) + +check: my-check + +clean-local: + $(DUB) clean + rm -f librdf_dlang.a librdf_dlang.so rdf_dlang + +lib_LIB = librdf_dlang.a librdf_dlang.so + +if DEBUG +buildflags = --build=debug +else +buildflags = --build=release +endif + +.PHONY: librdf_dlang.a librdf_dlang.so rdf_dlang + +librdf_dlang.a: + $(DUB) build --compiler=$(DC) --config=static-library $(buildflags) + +librdf_dlang.so: + $(DUB) build --compiler=$(DC) --config=shared-library $(buildflags) + +rdf_dlang: + $(DUB) build --compiler=$(DC) --config=application --build=unittest + +dist-hook: + cp -a source $(distdir)/ + find $(distdir)/source \! -name "*.d" \! -type d | xargs rm -f + +install-data-local: + mkdir -p $(libdir) + install librdf_dlang.a librdf_dlang.so $(libdir) + mkdir -p $(includedir)/d/librdf + cd $(srcdir)/source && cp --parents `find -name "*.d" \! -name main.d` $(includedir)/d/librdf/ + cat dub-install.json | sed 's%INLCUDEDIR%$(includedir)%g; s|$${prefix}|@prefix@|g' > $(includedir)/d/librdf/dub.json diff --git a/dlang/TODO.txt b/dlang/TODO.txt new file mode 100644 index 000000000..9919ed69c --- /dev/null +++ b/dlang/TODO.txt @@ -0,0 +1,9 @@ +WARNING: The API is not yet stable. + +const qualifier of function arguments where appropriate. +Also scope? + +More unittests (especially for streams and iterators) and code review. + +Review usage of const and cast(Dummy*) in redland/constants.d. + diff --git a/dlang/dub-install.json.in b/dlang/dub-install.json.in new file mode 100644 index 000000000..80efcdcc5 --- /dev/null +++ b/dlang/dub-install.json.in @@ -0,0 +1,29 @@ +{ + "name": "rdf_dlang", + "authors": [ + "Victor Porton" + ], + "description": "D bindings for librdf", + "copyright": "Copyright © 2018, Victor Porton", + "license": "see parent directory", + "libs": ["rasqal", "rdf"], + "configurations": [ + { + "name": "application", + "targetType": "executable", + "sourcePaths": ["INLCUDEDIR/d/librdf"] + }, + { + "name": "shared-library", + "targetType": "dynamicLibrary", + "excludedSourceFiles": ["sources/main.d"], + "sourcePaths": ["INLCUDEDIR/d/librdf"] + }, + { + "name": "static-library", + "targetType": "staticLibrary", + "excludedSourceFiles": ["sources/main.d"], + "sourcePaths": ["INLCUDEDIR/d/librdf"] + } + ] +} diff --git a/dlang/dub.json b/dlang/dub.json new file mode 100644 index 000000000..a5ca04acd --- /dev/null +++ b/dlang/dub.json @@ -0,0 +1,26 @@ +{ + "name": "rdf_dlang", + "authors": [ + "Victor Porton" + ], + "description": "D bindings for librdf", + "copyright": "Copyright © 2018, Victor Porton", + "license": "see parent directory", + "libs": ["rasqal", "rdf"], + "configurations": [ + { + "name": "application", + "targetType": "executable" + }, + { + "name": "shared-library", + "targetType": "dynamicLibrary", + "excludedSourceFiles": ["sources/main.d"] + }, + { + "name": "static-library", + "targetType": "staticLibrary", + "excludedSourceFiles": ["sources/main.d"] + } + ] +} diff --git a/dlang/source/main.d b/dlang/source/main.d new file mode 100644 index 000000000..e80242382 --- /dev/null +++ b/dlang/source/main.d @@ -0,0 +1,118 @@ +import std.typecons; +import std.stdio; +import rdf.raptor.iostream; + +void streamTest(string dir) { + import std.range.primitives : walkLength; + import rdf.redland.world; + import rdf.redland.uri; + import rdf.redland.stream; + import rdf.redland.model; + import rdf.redland.storage; + + RedlandWorld world = RedlandWorld.createAndOpen(); + Storage storage = Storage.create(world, "memory", "test"); + Model model = Model.create(world, storage); + string rdfFile = dir ~ "../data/dc.nt"; + model.load(URI.fromFilename(world, rdfFile)); + Stream stream = model.asStream; +// auto counter = stream.walkLength; // https://issues.dlang.org/show_bug.cgi?id=19596 + size_t counter = 0; + foreach(i; stream) { + ++counter; + } + assert(counter == 3, "counter == 3"); +} + +void countTest(string dir) { + static import rdf.raptor.uri; + import rdf.rasqal.data_graph; + import rdf.rasqal.world; + import rdf.rasqal.query; + import rdf.rasqal.query_results; + import rdf.rasqal.literal; + + string rdfFile = dir ~ "../data/dc.nt"; + string sparql = "SELECT (count(*) as ?count) WHERE { ?s ?p ?o . }"; + RasqalWorld world = RasqalWorld.createAndOpen(); + IOStream graphStream = IOStream.fromFilename(world.raptor, rdfFile); + DataGraph graph = DataGraph.fromIOStream(world, + graphStream, + rdf.raptor.uri.URI.fromString(world.raptor, "http://example.org") + // Name_URI => URI_Type'(From_Handle(null)), + // Flags => Background, + // Format_Type => Empty_Holder, + // Format_Name => Empty_Holder, + // Format_URI => URI_Type'(From_Handle(null)) + ); + Query query = Query.create(world, Nullable!string(), Nullable!string()); + query.prepare(sparql); + query.addDataGraph(graph); + QueryResults results = query.execute(); + string[] rows; + assert(results.isBindings, "Result is bindings"); + foreach(i; QueryResultsRange(results)) { + LiteralWithoutFinalize L = i.getBindingValueByName("count"); + rows ~= L.toString; + } + assert(rows.length == 1, "count() returns one row"); + assert(rows[0] == "3", "count() == 3"); +} + +void countTest2(string dir) { + import rdf.redland.world; + import rdf.redland.uri; + import rdf.redland.node; + import rdf.redland.model; + import rdf.redland.storage; + import rdf.redland.query; + import rdf.redland.query_results; + + RedlandWorld world = RedlandWorld.createAndOpen(); + Storage storage = Storage.create(world, "memory", "test"); + Model model = Model.create(world, storage); + string rdfFile = dir ~ "../data/dc.nt"; + string sparql = "SELECT (count(*) as ?count) WHERE { ?s ?p ?o . }"; +// Query: Query_Type := Copy(Create(World, "sparql", SPARQL)); // Copy causes an unhandled signal? + Query query = Query.create(world, "sparql", sparql); + QueryResults results = model.queryExecute(query); + model.load(URI.fromFilename(world, rdfFile)); + string[] rows; + foreach(i; QueryResultsRange(results)) { + Node L = i.getBindingValueByName("count"); + rows ~= L.toString; + } + assert(rows.length == 1, "count() returns one row"); + assert(rows[0] == "3", "count() == 3"); +} + +void listTest(string dir) { + import rdf.redland.world; + import rdf.redland.uri; + import rdf.redland.node; + import rdf.redland.model; + import rdf.redland.storage; + import rdf.redland.containers; + + RedlandWorld world = RedlandWorld.createAndOpen(); + Storage storage = Storage.create(world, "memory", "test"); + Model model = Model.create(world, storage); + string rdfFile = dir ~ "../data/list.ttl"; + model.load(URI.fromFilename(world, rdfFile)); + + auto start = model.getTarget(Node.fromURI(world, URI.fromString(world, "http://example.com")), + Node.fromURI(world, URI.fromString(world, "http://example.com"))); + auto list = rdfList(world, model, start); + assert(list == [Node.fromLiteral(world, "a", null), + Node.fromLiteral(world, "b", null), + Node.fromLiteral(world, "c", null)]); +} + +void main(string[] args) { + string dir = args.length > 1 ? args[1] ~ '/' : ""; + streamTest(dir); + countTest(dir); + countTest2(dir); + listTest(dir); + writeln("Tests passed."); +} diff --git a/dlang/source/rdf/auxiliary/handled_record.d b/dlang/source/rdf/auxiliary/handled_record.d new file mode 100644 index 000000000..a5833b86d --- /dev/null +++ b/dlang/source/rdf/auxiliary/handled_record.d @@ -0,0 +1,140 @@ +module rdf.auxiliary.handled_record; + +class RDFException: Exception { + this(string msg, string file = __FILE__, size_t line = __LINE__) { + super(msg, file, line); + } + this(string file = __FILE__, size_t line = __LINE__) { + this("RDF error", file, line); + } +} + +class NullRDFException: RDFException { + this(string msg, string file = __FILE__, size_t line = __LINE__) { + super(msg, file, line); + } + this(string file = __FILE__, size_t line = __LINE__) { + this("librdf null pointer exception", file, line); + } +} + +// struct Dummy; + +mixin template WithoutFinalize(alias Dummy, + alias _WithoutFinalize, + alias _WithFinalize, + alias copier = null) +{ + import std.traits; + + private Dummy* ptr; + // Use fromHandle() instead + private this(Dummy* ptr) nothrow @safe { + this.ptr = ptr; + } + private this(const(Dummy*) ptr) const nothrow @safe { + this.ptr = ptr; + } + @property Dummy* handle() const nothrow @trusted { + return cast(Dummy*)ptr; + } + static _WithoutFinalize fromHandle(const Dummy* ptr) { + return _WithoutFinalize(cast(Dummy*)ptr); + } + static _WithoutFinalize fromNonnullHandle(const Dummy* ptr) { + if(!ptr) throw new NullRDFException(); + return _WithoutFinalize(cast(Dummy*)ptr); + } + @property bool isNull() { + return ptr == null; + } + static if(isCallable!copier) { + _WithFinalize dup() { + return _WithFinalize(copier(ptr)); + } + } + size_t toHash() const nothrow @safe { + return cast(size_t) handle; + } +} + +mixin template WithFinalize(alias Dummy, + alias _WithoutFinalize, + alias _WithFinalize, + alias destructor, + alias constructor = null) +{ + import std.traits; + + private Dummy* ptr; + @disable this(); + static if (isCallable!constructor) { + static _WithFinalize create() { + return _WithFinalize(constructor()); + } + } + @disable this(this); + // Use fromHandle() instead + private this(Dummy* ptr) nothrow @safe { + this.ptr = ptr; + } + private this(const Dummy* ptr) const nothrow @safe { + this.ptr = ptr; + } + ~this() { + destructor(ptr); + } + /*private*/ @property _WithoutFinalize base() nothrow @trusted { // private does not work in v2.081.2 + return _WithoutFinalize(ptr); + } + /*private*/ @property const(_WithoutFinalize) base() const nothrow @trusted { // private does not work in v2.081.2 + return const _WithoutFinalize(ptr); + } + alias base this; + @property Dummy* handle() const { + return cast(Dummy*)ptr; + } + static _WithFinalize fromHandle(const Dummy* ptr) { + return _WithFinalize(cast(Dummy*)ptr); + } + static _WithFinalize fromNonnullHandle(const Dummy* ptr) { + if(!ptr) throw new NullRDFException(); + return _WithFinalize(cast(Dummy*)ptr); + } + static if (__traits(compiles, _WithoutFinalize.opEquals)) { + bool opEquals(const ref _WithFinalize s) const { + return this.base.opEquals(s.base); + } + bool opEquals(const _WithoutFinalize s) const { + return this.base.opEquals(s); + } + } + static if (__traits(compiles, _WithoutFinalize.opCmp)) { + int opCmp(const ref _WithFinalize s) const { + return this.base.opEquals( s.base); + } + int opCmp(const _WithoutFinalize s) const { + return this.base.opEquals( s); + } + } + size_t toHash() const nothrow @safe { + return base.toHash; + } +} + +mixin template CompareHandles(alias equal, alias compare) { + import std.traits; + + bool opEquals(const typeof(this) s) const { + static if(isCallable!equal) { + return equal(handle, s.handle) != 0; + } else { + return compare(handle, s.handle) == 0; + } + } + static if(isCallable!compare) { + int opCmp(const typeof(this) s) const { + return compare( handle, s.handle); + } + } +} diff --git a/dlang/source/rdf/auxiliary/nullable_string.d b/dlang/source/rdf/auxiliary/nullable_string.d new file mode 100644 index 000000000..69a96b26a --- /dev/null +++ b/dlang/source/rdf/auxiliary/nullable_string.d @@ -0,0 +1,22 @@ +module rdf.auxiliary.nullable_string; + +import std.typecons; +import std.string; + +immutable(char)* myToStringz(Nullable!string s) { + return s.isNull ? null : s.get.toStringz; +} + +// Can't use fromStringz and length because of automatic type conversion to string + +Nullable!string myFromStringz(const char* s) { + return s ? Nullable!string(s.fromStringz.idup) : Nullable!string(); +} + +size_t myLength(Nullable!string s) { + return s.isNull ? 0 : s.get.length; +} + +// const(char*) idup(Nullable!string s) { +// return s ? s.get.idup : null; +// } diff --git a/dlang/source/rdf/auxiliary/user.d b/dlang/source/rdf/auxiliary/user.d new file mode 100644 index 000000000..e63259608 --- /dev/null +++ b/dlang/source/rdf/auxiliary/user.d @@ -0,0 +1,19 @@ +module rdf.auxiliary.user; + +import core.memory : GC; + +class UnmovableObject { + this() { + GC.setAttr(cast(void*)this, GC.BlkAttr.NO_MOVE); + } + // Called AFTER object finalization: +// ~this() { +// GC.clrAttr(cast(void*)this, GC.BlkAttr.NO_MOVE); +// } +} + +/// Integration of callbacks with OOP +abstract class UserObject : UnmovableObject { + //alias record this; // prevents compilation as of v2.083.1 + final @property void* context() const { return cast(void*)this; } +} diff --git a/dlang/source/rdf/auxiliary/versions.d b/dlang/source/rdf/auxiliary/versions.d new file mode 100644 index 000000000..d241a2c2e --- /dev/null +++ b/dlang/source/rdf/auxiliary/versions.d @@ -0,0 +1,19 @@ +module rdf.auxiliary.versions; + +import std.conv : to; +import std.algorithm : map; +import std.algorithm.comparison : cmp; +import std.algorithm.iteration : splitter; + +struct Version { + private string str; + this(string str) { + this.str = str; + } + int opCmp(Version other) const { + auto i = str.splitter(".").map!(x => to!int(x)); + auto j = other.str.splitter(".").map!(x => to!int(x)); + return cmp(i, j); + } +} + diff --git a/dlang/source/rdf/config.d.in b/dlang/source/rdf/config.d.in new file mode 100644 index 000000000..eb1445578 --- /dev/null +++ b/dlang/source/rdf/config.d.in @@ -0,0 +1,4 @@ +module rdf.config; + +enum rasqalVersionFeatures = "@RASQAL_VERSION@"; + diff --git a/dlang/source/rdf/raptor/bnode.d b/dlang/source/rdf/raptor/bnode.d new file mode 100644 index 000000000..22f8ef69a --- /dev/null +++ b/dlang/source/rdf/raptor/bnode.d @@ -0,0 +1,48 @@ +module rdf.raptor.bnode; + +import std.string; +import std.typecons; +import rdf.auxiliary.nullable_string; +import rdf.auxiliary.handled_record; +import rdf.auxiliary.user; +import rdf.raptor.memory; +import rdf.raptor.world; + +private extern extern(C) { + char* raptor_world_generate_bnodeid(RaptorWorldHandle* world); + alias raptor_generate_bnodeid_handler = const(char)* function(char* data, char* userID); + void raptor_world_set_generate_bnodeid_handler(RaptorWorldHandle* world, + void* user_data, + raptor_generate_bnodeid_handler handler); + void raptor_world_set_generate_bnodeid_parameters(RaptorWorldHandle* world, const char *prefix, int base); +} + +struct BNode { + static string generateId(RaptorWorldWithoutFinalize world) { + char* str = raptor_world_generate_bnodeid(world.handle); + if(!str) throw new NullRDFException(); + scope(exit) raptor_free_memory(str); + return str.fromStringz.idup; + } + static void setGenerateBnodeidParameters(RaptorWorldWithoutFinalize world, + Nullable!string prefix, + int base = 1) + { + raptor_world_set_generate_bnodeid_parameters(world.handle, prefix.myToStringz, base); + } +} + +class BNodeIDHandler : UnmovableObject { + abstract string doHandle(Nullable!string userID) const; + private static extern(C) const(char)* handleImpl(char* data, char* userID) { + scope(exit) { + if(userID) raptor_free_memory(userID); + } + Nullable!string userID2; + if(userID) userID2 = cast(string)fromStringz(userID); + return (cast(BNodeIDHandler)data).doHandle(userID2).toStringz; + } + final void set(RaptorWorldWithoutFinalize world) const { + raptor_world_set_generate_bnodeid_handler(world.handle, cast(void*)this, &handleImpl); + } +} diff --git a/dlang/source/rdf/raptor/constants.d b/dlang/source/rdf/raptor/constants.d new file mode 100644 index 000000000..2dd395eca --- /dev/null +++ b/dlang/source/rdf/raptor/constants.d @@ -0,0 +1,67 @@ +module rdf.raptor.constants; + +import std.string; + +private extern extern(C) immutable __gshared uint raptor_version_major; +private extern extern(C) immutable __gshared uint raptor_version_minor; +private extern extern(C) immutable __gshared uint raptor_version_release; +private extern extern(C) immutable __gshared uint raptor_version_decimal; + +alias versionMajor = raptor_version_major; +alias versionMinor = raptor_version_minor; +alias versionRelease = raptor_version_release; +alias versionDecimal = raptor_version_decimal; + +private extern extern(C) { + immutable char* raptor_copyright_string; + immutable char* raptor_home_url_string; + immutable char* raptor_license_string; + immutable char* raptor_short_copyright_string; + immutable char* raptor_version_string; + immutable char* raptor_owl_namespace_uri; + immutable char* raptor_rdf_namespace_uri; + immutable char* raptor_rdf_schema_namespace_uri; + immutable char* raptor_xml_literal_datatype_uri_string; + immutable char* raptor_xml_namespace_uri; + immutable char* raptor_xmlschema_datatypes_namespace_uri; +} + +string copyrightString() { return raptor_copyright_string.fromStringz; } +string homeURLString() { return raptor_home_url_string.fromStringz; } +string licenseString() { return raptor_license_string.fromStringz; } +string shortCopyrightString() { return raptor_short_copyright_string.fromStringz; } +string versionString() { return raptor_version_string.fromStringz; } +string owlNamespaceURI() { return raptor_owl_namespace_uri.fromStringz; } +string rdfNamespaceURI() { return raptor_rdf_namespace_uri[0..43]; } +string rdfSchemaNamespaceURI() { return raptor_rdf_schema_namespace_uri.fromStringz; } +string xmlLiteralDatatypeURIString() { + return raptor_xml_literal_datatype_uri_string[0..53]; +} +string xmlNamespaceURI() { return raptor_xml_namespace_uri.fromStringz; } +string xmlschemaDatatypesNamespaceURI() { return raptor_xmlschema_datatypes_namespace_uri.fromStringz; } + +enum DomainType : ubyte { none = 0, + ioStream = 1, + namespace = 2, + parser = 3, + Qname = 4, + sax2 = 5, + serializer = 6, + term = 7, + turtle_Writer = 8, + uri = 9, + world = 10, + www = 11, + xmlWriter = 12 } + +unittest { + import std.conv; + + string combinedString = + to!string(versionMajor) ~ '.' ~ to!string(versionMinor) ~ '.' ~ to!string(versionRelease); + uint combinedDecimal = + versionMajor * 10000 + versionMinor * 100 + versionRelease; + assert(combinedString == versionString, "Combined version string"); + assert(combinedDecimal == versionDecimal, "Combined decimal version"); +} + diff --git a/dlang/source/rdf/raptor/iostream.d b/dlang/source/rdf/raptor/iostream.d new file mode 100644 index 000000000..b8b7e0cb0 --- /dev/null +++ b/dlang/source/rdf/raptor/iostream.d @@ -0,0 +1,338 @@ +module rdf.raptor.iostream; + +import std.string; +import std.stdio; +import rdf.auxiliary.handled_record; +import rdf.auxiliary.user; +import rdf.raptor.world; +import rdf.raptor.uri; +import rdf.raptor.term; + +struct IOStreamHandle; + +private extern extern(C) { + void raptor_free_iostream(IOStreamHandle* iostr); + int raptor_iostream_hexadecimal_write(uint integer, int width, IOStreamHandle* iostr); + int raptor_iostream_read_bytes(void *ptr, size_t size, size_t nmemb, IOStreamHandle* iostr); + int raptor_iostream_read_eof(IOStreamHandle* iostr); + ulong raptor_iostream_tell(IOStreamHandle* iostr); + int raptor_iostream_counted_string_write(const void* string, size_t len, IOStreamHandle* iostr); + int raptor_iostream_decimal_write(int integer, IOStreamHandle* iostr); + int raptor_iostream_write_byte(const int byte_, IOStreamHandle* iostr); + int raptor_iostream_write_bytes(const void *ptr, size_t size, size_t nmemb, IOStreamHandle* iostr); + int raptor_iostream_write_end(IOStreamHandle* iostr); + int raptor_bnodeid_ntriples_write(const char *bnodeid, size_t len, IOStreamHandle* iostr); + int raptor_string_escaped_write(const char *string, + size_t len, const char delim, + uint flags, + IOStreamHandle* iostr); + int raptor_uri_escaped_write(URIHandle* uri, + URIHandle* base_uri, + uint flags, + IOStreamHandle* iostr); + int raptor_term_escaped_write(const TermHandle* term, uint flags, IOStreamHandle* iostr); + int raptor_string_ntriples_write(const char *string, + size_t len, + char delim, + IOStreamHandle* iostr); + IOStreamHandle* raptor_new_iostream_from_sink(RaptorWorldHandle* world); + IOStreamHandle* raptor_new_iostream_from_filename(RaptorWorldHandle* world, const char *filename); + IOStreamHandle* raptor_new_iostream_from_file_handle(RaptorWorldHandle* world, FILE *handle); + IOStreamHandle* raptor_new_iostream_to_sink(RaptorWorldHandle* world); + IOStreamHandle* raptor_new_iostream_to_filename(RaptorWorldHandle* world, const char *filename); + IOStreamHandle* raptor_new_iostream_to_file_handle(RaptorWorldHandle* world, FILE *handle); + IOStreamHandle* raptor_new_iostream_from_handler(RaptorWorldHandle* world, + void *user_data, + const DispatcherType* handler); + IOStreamHandle* raptor_new_iostream_from_string(RaptorWorldHandle* world, void *string, size_t length); +} + +class IOStreamException: RDFException { + this(string msg, string file = __FILE__, size_t line = __LINE__) { + super(msg, file, line); + } + this(string file = __FILE__, size_t line = __LINE__) { + this("IOStream error", file, line); + } +} + +enum EscapedWriteBitflags { + bitflagBSEscapesBF = 1, + bitflagBSEscapesTNRU = 2, + bitflagUTF8 = 4, + bitflagSparqlURIEscapes = 8, + + // N-Triples - favour writing \u, \U over UTF8 + nTriplesLiteral = bitflagBSEscapesTNRU | bitflagBSEscapesBF, + nTriplesURI = bitflagSparqlURIEscapes, + + // Sparql literal allows raw UTF8 for printable literals + sparqlLiteral = bitflagUTF8, + + // Sparql long literal no BS-escapes allowe + sparqlLongLiteral = bitflagUTF8, + + // Sparql uri have to escape certain characters + sparqlURI = bitflagUTF8 | bitflagSparqlURIEscapes, + + // Turtle (2013) escapes are like Sparql + TurtleURI = sparqlURI, + TurtleLiteral = sparqlLiteral, + TurtleLongLiteral = sparqlLongLiteral, + + //- JSON literals \b \f \t \r \n and \u \U + jsonLiteral = bitflagBSEscapesTNRU | bitflagBSEscapesBF, +} + +struct IOStreamWithoutFinalize { + mixin WithoutFinalize!(IOStreamHandle, + IOStreamWithoutFinalize, + IOStream); + void hexadecimalWrite(uint value, uint width) { + if(raptor_iostream_hexadecimal_write(value, width, handle) < 0) + throw new IOStreamException(); + } + size_t readBytes(char *ptr, size_t size, size_t nmemb) { + immutable int result = raptor_iostream_read_bytes(ptr, size, nmemb, handle); + if(result < 0) throw new IOStreamException(); + return result; + } + @property bool eof() const { + return raptor_iostream_read_eof(handle) != 0; + } + ulong tell() const { + return raptor_iostream_tell(handle); + } + void write(string value) { + if(raptor_iostream_counted_string_write(value.ptr, value.length, handle) != 0) + throw new IOStreamException(); + } + void write(char c) { + if(raptor_iostream_write_byte(c, handle) != 0) + throw new IOStreamException(); + } + void decimalWrite(int value) { + if(raptor_iostream_decimal_write(value, handle) < 0) + throw new IOStreamException(); + } + int writeBytes(char *ptr, size_t size, size_t nmemb) { + immutable int result = raptor_iostream_write_bytes (ptr, size, nmemb, handle); + if(result < 0) throw new IOStreamException(); + return result; + } + void writeEnd() { + if(raptor_iostream_write_end(handle) != 0) + throw new IOStreamException(); + } + void bnodeidNtriplesWrite(string bnode) { + if(raptor_bnodeid_ntriples_write(bnode.ptr, bnode.length, handle) != 0) + throw new IOStreamException(); + } + void escapedWrite(string value, char delim, EscapedWriteBitflags flags) { + if(raptor_string_escaped_write(value.ptr, value.length, delim, flags, handle) != 0) + throw new IOStreamException(); + } + void uriEscapedWrite(URIWithoutFinalize uri, + URIWithoutFinalize baseURI, + EscapedWriteBitflags flags) + { + if(raptor_uri_escaped_write(uri.handle, baseURI.handle, flags, handle) != 0) + throw new IOStreamException(); + } + void termEscapedWrite(TermWithoutFinalize term, EscapedWriteBitflags flags) { + if(raptor_term_escaped_write(term.handle, flags, handle) != 0) + throw new IOStreamException(); + } + void ntriplesWrite(string value, char delim) { + if(raptor_string_ntriples_write(value.ptr, value.length, delim, handle) != 0) + throw new IOStreamException(); + } +} + +/// It would be nice to make this a wrapper over D streams. +/// But D streams are not yet settled: https://stackoverflow.com/a/54029257/856090 +struct IOStream { + mixin WithFinalize!(IOStreamHandle, + IOStreamWithoutFinalize, + IOStream, + raptor_free_iostream); + static IOStream fromSink(RaptorWorldWithoutFinalize world) { + return fromNonnullHandle(raptor_new_iostream_from_sink(world.handle)); + } + static IOStream fromFilename(RaptorWorldWithoutFinalize world, string filename) { + return fromNonnullHandle(raptor_new_iostream_from_filename(world.handle, filename.toStringz)); + } + static IOStream fromFileHandle(RaptorWorldWithoutFinalize world, File file) { + return fromNonnullHandle(raptor_new_iostream_from_file_handle(world.handle, file.getFP)); + } + static IOStream toSink(RaptorWorldWithoutFinalize world) { + return fromNonnullHandle(raptor_new_iostream_to_sink(world.handle)); + } + static IOStream toFilename(RaptorWorldWithoutFinalize world, string filename) { + return fromNonnullHandle(raptor_new_iostream_to_filename(world.handle, filename.toStringz)); + } + static IOStream toFileHandle(RaptorWorldWithoutFinalize world, File file) { + return fromNonnullHandle(raptor_new_iostream_to_file_handle(world.handle, file.getFP)); + } +} + +private extern(C) { + alias raptor_iostream_init_func = int function(void *context); + alias raptor_iostream_finish_func = void function(void *context); + alias raptor_iostream_write_byte_func = int function(void *context, int byte_); + alias raptor_iostream_write_bytes_func = int function(void *context, + const void *ptr, + size_t size, + size_t nmemb); + alias raptor_iostream_write_end_func = int function(void *context); + alias raptor_iostream_read_bytes_func = int function(void *context, + void *ptr, + size_t size, + size_t nmemb); + alias raptor_iostream_read_eof_func = int function(void *context); + + int raptor_iostream_write_byte_impl(void* context, int byte_) { + try { + (cast(UserIOStream)context).doWriteByte(cast(char)byte_); + return 0; + } + catch(Exception) { + return 1; + } + } + + int raptor_iostream_write_bytes_impl(void* context, const void* ptr, size_t size, size_t nmemb) { + try { + return (cast(UserIOStream)context).doWriteBytes(cast(char*)ptr, size, nmemb); + } + catch(Exception) { + return -1; + } + } + + int raptor_iostream_write_end_impl(void* context) { + try { + (cast(UserIOStream)context).doWriteEnd(); + return 0; + } + catch(Exception) { + return 1; + } + } + + int raptor_iostream_read_bytes_impl(void* context, void* ptr, size_t size, size_t nmemb) { + try { + return cast(int)(cast(UserIOStream)context).doReadBytes(cast(char*)ptr, size, nmemb); + } + catch(Exception) { + return -1; + } + } + + int raptor_iostream_read_eof_impl(void* context) { + return (cast(UserIOStream)context).doReadEof; + } +} + +struct DispatcherType { + int version_ = 2; + // V1 functions + raptor_iostream_init_func init = null; + raptor_iostream_finish_func finish = null; + raptor_iostream_write_byte_func write_byte; + raptor_iostream_write_bytes_func write_bytes; + raptor_iostream_write_end_func write_end; + // V2 functions + raptor_iostream_read_bytes_func read_bytes; + raptor_iostream_read_eof_func read_eof; +} + +private immutable DispatcherType Dispatch = + { version_: 2, + init: null, + finish: null, + write_byte : &raptor_iostream_write_byte_impl, + write_bytes: &raptor_iostream_write_bytes_impl, + write_end : &raptor_iostream_write_end_impl, + read_bytes : &raptor_iostream_read_bytes_impl, + read_eof : &raptor_iostream_read_eof_impl }; + +class UserIOStream : UserObject { + IOStream record; + this(RaptorWorldWithoutFinalize world) { + IOStreamHandle* handle = raptor_new_iostream_from_handler(world.handle, + context, + &Dispatch); + record = IOStream.fromNonnullHandle(handle); + } + void doWriteByte(char byte_) { + if(doWriteBytes(&byte_, 1, 1) != 1) + throw new IOStreamException(); + } + abstract int doWriteBytes(char* data, size_t size, size_t count); + abstract void doWriteEnd(); + abstract size_t doReadBytes(char* data, size_t size, size_t count); + abstract bool doReadEof(); +} + +class StreamFromString : UserObject { + private string _str; + IOStream record; + this(RaptorWorldWithoutFinalize world, string str) { + _str = str; + IOStreamHandle* handle = raptor_new_iostream_from_string(world.handle, cast(void*)str.ptr, str.length); + record = IOStream.fromNonnullHandle(handle); + } + final string value() const { return _str; } + alias value this; +} + +// I decided to implement it in D instead of using corresponding C functions +class StreamToString : UserIOStream { + private string _str; + this(RaptorWorldWithoutFinalize world) { + super(world); + } + final string value() const { return _str; } + alias value this; + override int doWriteBytes(char* data, size_t size, size_t count) { + _str ~= data[0..size*count]; + return cast(int)(size*count); + } + override void doWriteEnd() { } + override size_t doReadBytes(char* data, size_t size, size_t count) { assert(0); } + override bool doReadEof() { assert(0); } +} + +unittest { + import std.array; + import std.range; + + RaptorWorld world = RaptorWorld.createAndOpen(); + + { // Sinks + char[] str = "qqq".dup; + auto inSink = IOStream.fromSink(world); + auto outSink = IOStream.toSink(world); + assert(inSink.readBytes(str.ptr, 10, 10) == 0, "Read zero bytes from a sink"); + outSink.write("XYZ"); // does nothing + } + { // String streams + string str = "xqqq"; + char[] buf = 'w'.repeat(99).array ~ '\0'; + StreamFromString inString = new StreamFromString(world, str); + StreamToString outString = new StreamToString(world); + StreamToString outString2 = new StreamToString(world); + size_t bytesRead = inString.record.readBytes(buf.ptr, 1, 100); + assert(bytesRead == 4, "Read 4 bytes from string"); + assert(buf[0..4] == str, "Compare read string"); + outString.record.write(str); + outString.record.write("QQ"); + assert (outString.value == str ~ "QQ", "Compare written string"); + assert (outString.record.tell == 4+2, "'Tell' position"); + outString2.record.decimalWrite(1234); + assert(outString2.value == "1234", "Decimal write"); + } + + // See also main.d +} diff --git a/dlang/source/rdf/raptor/log.d b/dlang/source/rdf/raptor/log.d new file mode 100644 index 000000000..9b9c9b000 --- /dev/null +++ b/dlang/source/rdf/raptor/log.d @@ -0,0 +1,190 @@ +module rdf.raptor.log; + +import std.string; +import std.stdio : FILE, File; +import rdf.auxiliary.handled_record; +import rdf.auxiliary.user; +import rdf.raptor.constants; +import rdf.raptor.world; +import rdf.raptor.memory; +import rdf.raptor.uri; +import rdf.rasqal.world; // this dependency should probably be eliminated + +enum LogLevel { none = 0, + trace = 1, + debug_ = 2, + info = 3, + warn = 4, + error = 5, + fatal = 6 } + +string getLabel(LogLevel level) { + return raptor_log_level_get_label(level).fromStringz.idup; +} + +string getLabel(DomainType level) { + return raptor_domain_get_label(level).fromStringz.idup; +} + +struct LocatorHandle { +private: + URIHandle* _uri; + char* _file; + int _line, _column, _byte; +} + +struct LogMessageHandle { +private: + int _code; + DomainType _domain; + LogLevel _logLevel; + LocatorHandle* _locator; + char* _text; +} + +private void free_locator(LocatorHandle* handle) { + raptor_free_uri(handle._uri); + raptor_free_memory(handle._file); + raptor_free_memory(cast(char*)handle); +} + +private LocatorHandle* locator_copy(LocatorHandle* handle) { + LocatorHandle* result = cast(LocatorHandle*)raptor_alloc_memory(LocatorHandle.sizeof); + if(!result) return null; + *result = *handle; + result._uri = raptor_uri_copy(handle._uri); + if(!result._uri) { + raptor_free_memory(cast(char*)result); + return null; + } + result._file = raptor_copy_c_string(handle._file); + if(!result._file) { + raptor_free_memory(cast(char*)result._uri); + raptor_free_memory(cast(char*)result); + return null; + } + return result; +} + +private void free_log_message(LogMessageHandle* handle) { + raptor_free_memory(handle._text); + free_locator(handle._locator); + raptor_free_memory(cast(char*)handle); +} + +private LogMessageHandle* log_message_copy(LogMessageHandle* handle) { + LogMessageHandle* result = cast(LogMessageHandle*)raptor_alloc_memory(LogMessageHandle.sizeof); + if(!result) return null; + *result = *handle; + result._text = raptor_copy_c_string(handle._text); + if(!result._text) { + raptor_free_memory(cast(char*)result); + } + result._locator = locator_copy(handle._locator); + if(!result._locator) { + raptor_free_memory(cast(char*)result._text); + raptor_free_memory(cast(char*)result); + return null; + } + return result; +} + +private extern extern(C) { + void raptor_free_uri(URIHandle* uri); + URIHandle* raptor_uri_copy(URIHandle* uri); + int raptor_locator_print(LocatorHandle* locator, FILE *stream); + int raptor_locator_format(char *buffer, size_t length, LocatorHandle* locator); + alias raptor_log_handler = void function(void *user_data, LogMessageHandle* message); + int raptor_world_set_log_handler(RaptorWorldHandle* world, void *user_data, raptor_log_handler handler); + const(char*) raptor_log_level_get_label(LogLevel level); + const(char*) raptor_domain_get_label(DomainType domain); + // Experimental code: + void rasqal_world_set_log_handler(RasqalWorldHandle* world, + void *user_data, + raptor_log_handler handler); +} + +struct LocatorWithoutFinalize { + mixin WithoutFinalize!(LocatorHandle, + LocatorWithoutFinalize, + Locator, + locator_copy); + @property URIWithoutFinalize uri() const { + return URIWithoutFinalize.fromHandle(handle._uri); + } + @property string file() const { + return handle._file.fromStringz.idup; + } + @property uint line() const { + return handle._line; + } + @property uint column() const { + return handle._column; + } + @property uint byte_() const { + return handle._byte; + } + void print(File file) const { + if(raptor_locator_print(handle, file.getFP) != 0) + throw new RDFException(); + } + string format() const { + immutable int res = raptor_locator_format(null, 0, handle); + if(res < 0) throw new RDFException(); + char[] buffer = new char[res]; + if(raptor_locator_format(buffer.ptr, 0, handle) < 0) throw new RDFException(); + return buffer.idup; + } +} + +struct Locator { + mixin WithFinalize!(LocatorHandle, + LocatorWithoutFinalize, + Locator, + free_locator); +} + +struct LogMessageWithoutFinalize { + mixin WithoutFinalize!(LogMessageHandle, + LogMessageWithoutFinalize, + LogMessage, + log_message_copy); + @property int errorCode() const { + return handle._code; + } + @property DomainType domain() const { + return handle._domain; + } + @property LogLevel logLevel() const { + return handle._logLevel; + } + @property string text() const { + return handle._text.fromStringz.idup; + } + @property LocatorWithoutFinalize locator() const { + return LocatorWithoutFinalize.fromNonnullHandle(handle._locator); + } +} + +struct LogMessage { + mixin WithFinalize!(LogMessageHandle, + LogMessageWithoutFinalize, + LogMessage, + free_log_message); +} + +class LogHandler : UnmovableObject { + abstract void logMessage(LogMessageWithoutFinalize info); + private static extern(C) void handleImpl(void* data, LogMessageHandle* msg) { + return (cast(LogHandler)data).logMessage(LogMessageWithoutFinalize.fromHandle(msg)); + } + final void set(RaptorWorldWithoutFinalize world) { + if(raptor_world_set_log_handler(world.handle, cast(void*)this, &handleImpl) != 0) + throw new RDFException(); + } + /// Experimental API + final void set(RasqalWorldWithoutFinalize world) { + rasqal_world_set_log_handler(world.handle, cast(void*)this, &handleImpl); + } +} + diff --git a/dlang/source/rdf/raptor/memory.d b/dlang/source/rdf/raptor/memory.d new file mode 100644 index 000000000..b264396d1 --- /dev/null +++ b/dlang/source/rdf/raptor/memory.d @@ -0,0 +1,29 @@ +module rdf.raptor.memory; + +import std.typecons; + +extern extern(C) { + void raptor_free_memory (char* ptr); + char* raptor_alloc_memory(size_t size); + char* raptor_calloc_memory (size_t nmemb, size_t size); +} + +// Missing in C code, so I implement it in D +char *raptor_copy_c_string(char* str) { + import core.stdc.string; + immutable size_t len = strlen(str) + 1; + char* newStr = raptor_alloc_memory(len); + return strncpy(newStr, str, len); +} + +// Missing in C code, so I implement it in D +char* raptor_new_string(string str) { + import core.stdc.string; + char* newStr = raptor_alloc_memory(str.length+1); + newStr[str.length] = '\0'; + return strncpy(newStr, str.ptr, str.length); +} + +char* raptor_new_string(Nullable!string str) { + return str.isNull ? null : raptor_new_string(str.get); +} diff --git a/dlang/source/rdf/raptor/namespace.d b/dlang/source/rdf/raptor/namespace.d new file mode 100644 index 000000000..87f0be036 --- /dev/null +++ b/dlang/source/rdf/raptor/namespace.d @@ -0,0 +1,114 @@ +module rdf.raptor.namespace; + +import std.string; +import rdf.auxiliary.handled_record; +import rdf.raptor.memory; +import rdf.raptor.world; +import rdf.raptor.uri; +import rdf.raptor.iostream; +import rdf.raptor.namespace_stack; + +struct NamespaceHandle; + +private extern extern(C) { + void raptor_free_namespace(NamespaceHandle* ns); + URIHandle* raptor_namespace_get_uri(const NamespaceHandle* ns); + const(char*) raptor_namespace_get_prefix(const NamespaceHandle* ns); + int raptor_namespace_write(NamespaceHandle* ns, IOStreamHandle* iostr); + char* raptor_namespace_format_as_xml(const NamespaceHandle* ns, size_t* length_p); + int raptor_xml_namespace_string_parse(const char *string, char **prefix, char **uri_string); + + NamespaceHandle* raptor_new_namespace(NamespaceStackHandle* nstack, + const char* prefix, + const char* ns_uri_string, + int depth); + NamespaceHandle* raptor_new_namespace_from_uri(NamespaceStackHandle* nstack, + const char* prefix, + URIHandle* ns_uri, + int depth); +} + +struct PrefixAndURI { + string prefix; + string uri; +} + +struct NamespaceWithoutFinalize { + mixin WithoutFinalize!(NamespaceHandle, + NamespaceWithoutFinalize, + Namespace); + @property URIWithoutFinalize uri() const { + // raptor_namespace_get_uri() may return NULL (for xmlns="") + return URIWithoutFinalize.fromHandle(raptor_namespace_get_uri(handle)); + } + @property string prefix() const { + return raptor_namespace_get_prefix(handle).fromStringz.idup; + } + void write(IOStreamWithoutFinalize stream) const { + if(raptor_namespace_write(handle, stream.handle) != 0) + throw new IOStreamException(); + } + string formatAsXML() const { + char* str = raptor_namespace_format_as_xml(handle, null); + if(!str) throw new RDFException(); + scope(exit) raptor_free_memory(str); + return str.fromStringz.idup; + } +} + +struct Namespace { + mixin WithFinalize!(NamespaceHandle, + NamespaceWithoutFinalize, + Namespace, + raptor_free_namespace); + static Namespace create(NamespaceStackWithoutFinalize stack, string prefix, string ns, uint depth) { + NamespaceHandle* h = + raptor_new_namespace(stack.handle, prefix.toStringz, ns.toStringz, depth); + return fromNonnullHandle(h); + } + static Namespace fromURI(NamespaceStackWithoutFinalize stack, + string prefix, + URIWithoutFinalize uri, + int depth) + { + NamespaceHandle* h = + raptor_new_namespace_from_uri(stack.handle, prefix.toStringz, uri.handle, depth); + return fromNonnullHandle(h); + } +} + +// See also extractPrefix and extractURI +PrefixAndURI stringParse(string ns) { + char* prefix, uri; + if(raptor_xml_namespace_string_parse(ns.toStringz, &prefix, &uri) != 0) + throw new RDFException(); + scope(exit) { + raptor_free_memory(prefix); + raptor_free_memory(uri); + } + string prefix2 = prefix.fromStringz.idup; + string uri2 = uri.fromStringz.idup; + return PrefixAndURI(prefix2, uri2); +} + +string extractPrefix(string ns) { + char* prefix; + if(raptor_xml_namespace_string_parse(ns.toStringz, &prefix, null) != 0) + throw new RDFException(); + scope(exit) raptor_free_memory(prefix); + string result = prefix.fromStringz.idup; + return result; +} + +string extractURI(string ns) { + char* uri; + if(raptor_xml_namespace_string_parse(ns.toStringz, null, &uri) != 0) + throw new RDFException(); + scope(exit) raptor_free_memory(uri); + return uri.fromStringz.idup; +} + +unittest { + // see namespace_stack.d +} + diff --git a/dlang/source/rdf/raptor/namespace_stack.d b/dlang/source/rdf/raptor/namespace_stack.d new file mode 100644 index 000000000..852a74c43 --- /dev/null +++ b/dlang/source/rdf/raptor/namespace_stack.d @@ -0,0 +1,110 @@ +module rdf.raptor.namespace_stack; + +import std.string; +import std.typecons; +import rdf.auxiliary.handled_record; +import rdf.raptor.memory; +import rdf.raptor.world; +import rdf.raptor.uri; +import rdf.raptor.namespace; + +struct NamespaceStackHandle; + +private extern extern(C) { + void raptor_free_namespaces(NamespaceStackHandle* nstack); + void raptor_namespaces_clear(NamespaceStackHandle* nstack); + void raptor_namespaces_start_namespace(NamespaceStackHandle* nstack, NamespaceHandle* nspace); + int raptor_namespace_stack_start_namespace(NamespaceStackHandle* nstack, + NamespaceHandle* ns, + int new_depth); + int raptor_namespaces_start_namespace_full(NamespaceStackHandle* nstack, + const char *prefix, + const char *ns_uri_string, + int depth); + void raptor_namespaces_end_for_depth(NamespaceStackHandle* nstack, int depth); + NamespaceHandle* raptor_namespaces_get_default_namespace(NamespaceStackHandle* nstack); + NamespaceHandle* raptor_namespaces_find_namespace(NamespaceStackHandle* nstack, + const char *prefix, + int prefix_length); + NamespaceHandle* raptor_namespaces_find_namespace_by_uri(NamespaceStackHandle* nstack, + URIHandle* ns_uri); + int raptor_namespaces_namespace_in_scope(NamespaceStackHandle* nstack, + const NamespaceHandle* nspace); + NamespaceStackHandle* raptor_new_namespaces(RaptorWorldHandle *world, int defaults); +} + +enum NamespaceOptions { noneType = 0, xmlType = 1, rdfType = 2, undefinedType = 3 } + +struct NamespaceStackWithoutFinalize { + mixin WithoutFinalize!(NamespaceStackHandle, + NamespaceStackWithoutFinalize, + NamespaceStack); + void clear() { + raptor_namespaces_clear(handle); + } + void startNamespace(NamespaceWithoutFinalize ns) { + raptor_namespaces_start_namespace(handle, ns.handle); + } + void startNamespace(NamespaceWithoutFinalize ns, uint newDepth) { + if(raptor_namespace_stack_start_namespace(handle, ns.handle, newDepth) != 0) + throw new RDFException(); + } + void startNamespace(NamespaceWithoutFinalize ns, + Nullable!string prefix, + Nullable!string nsURI, + uint newDepth) + { + immutable int res = raptor_namespaces_start_namespace_full(handle, + prefix.get.toStringz, + nsURI.get.toStringz, + newDepth); + if(res != 0) + throw new RDFException(); + } + void endForDepth(uint depth) { + raptor_namespaces_end_for_depth(handle, depth); + } + @property NamespaceWithoutFinalize defaultNamespace() { + return NamespaceWithoutFinalize.fromNonnullHandle(raptor_namespaces_get_default_namespace(handle)); + } + NamespaceWithoutFinalize findNamespace(string prefix) const { + NamespaceHandle* handle = + raptor_namespaces_find_namespace(handle, prefix.ptr, cast(int)prefix.length); + return NamespaceWithoutFinalize.fromNonnullHandle(handle); + } + NamespaceWithoutFinalize findDefaultNamespace(string prefix) const { + return NamespaceWithoutFinalize.fromNonnullHandle(raptor_namespaces_find_namespace(handle, null, 0)); + } + NamespaceWithoutFinalize findNamespaceByURI(URIWithoutFinalize uri) const { + NamespaceHandle* res = raptor_namespaces_find_namespace_by_uri(handle, uri.handle); + return NamespaceWithoutFinalize.fromNonnullHandle(res) ; + } + bool inScope(NamespaceWithoutFinalize ns) const { + return raptor_namespaces_namespace_in_scope(handle, ns.handle) != 0; + } +} + +struct NamespaceStack { + mixin WithFinalize!(NamespaceStackHandle, + NamespaceStackWithoutFinalize, + NamespaceStack, + raptor_free_namespaces); + static NamespaceStack createStack(RaptorWorldWithoutFinalize world, NamespaceOptions defaults) { + return fromNonnullHandle(raptor_new_namespaces(world.handle, defaults) ); + } +} + +// raptor_namespaces_init() not bound (it seems that function is internal for Raptor implementation). + +unittest { + RaptorWorld world = RaptorWorld.createAndOpen(); + NamespaceStack stack = NamespaceStack.createStack(world, NamespaceOptions.xmlType); + URI uri1obj = URI.fromString(world, "http://www.w3.org/1999/xhtml/"); + Namespace ns1 = Namespace.create(stack, "xhtml", "http://www.w3.org/1999/xhtml/", 1); + Namespace ns2 = Namespace.fromURI(stack, "xhtml", uri1obj, 1); + assert(ns1.uri.toString == "http://www.w3.org/1999/xhtml/", "Check namespace URI"); + assert(ns2.uri.toString == "http://www.w3.org/1999/xhtml/", "Check namespace URI"); + assert(ns1.prefix == "xhtml", "Check namespace prefix"); + assert(ns2.prefix == "xhtml", "Check namespace prefix"); +} + diff --git a/dlang/source/rdf/raptor/options.d b/dlang/source/rdf/raptor/options.d new file mode 100644 index 000000000..25a18e56f --- /dev/null +++ b/dlang/source/rdf/raptor/options.d @@ -0,0 +1,131 @@ +module rdf.raptor.options; + +import std.string; +import rdf.auxiliary.handled_record; +import rdf.raptor.world; +import rdf.raptor.uri; + +enum RaptorOption : short { + scanning = 0, + allowNonNSAttributes = 1, + allowOtherParsetypes = 2, + allowBagid = 3, + allowRDFTypeRDFList = 4, + normalizeLanguage = 5, + nonNFCFatal = 6, + warnOtherParsetypes = 7, + checkRDFId = 8, + relativeUris = 9, + writerAutoIndent = 10, + writerAutoEmpty = 11, + writerIndentWidth = 12, + writerXMLVersion = 13, + writerXMLDeclaration = 14, + noNet = 15, + resourceBorder = 16, + literalBorder = 17, + bnodeBorder = 18, + resourceFill = 19, + literalFill = 20, + bnodeFill = 21, + htmlTagSoup = 22, + microformats = 23, + htmlLink = 24, + wwwTimeout = 25, + writeBaseURI = 26, + wwwHTTPCacheControl = 27, + wwwHTTPUserAgent = 28, + jsonCallback = 29, + jsonExtraData = 30, + rssTriples = 31, + atomEntryURI = 32, + prefixElements = 33, + strict = 34, + wwwCertFilename = 35, + wwwCertType = 36, + wwwCertPassphrase = 37, + noFile = 38, + wwwSSLVerifyPeer = 39, + wwwSSLVerifyHost = 40, + loadExternalEntities = 41, +} + +enum ValueType { bool_, int_, string_, uri_ } + +enum Domain { + none, + ioStream, + namespace, + parser, + qname, + sax2, + serializer, + term, + turtleWriter, + uri, + world, + www, + xmlWriter, +} + +struct OptionDescriptionHandle { +private: + Domain _domain; + RaptorOption _option; + ValueType _valueType; + char* _name; + size_t _len; + char* _label; + URIHandle* _uri; +} + +private extern extern(C) { + uint raptor_option_get_count(); + const(char*) raptor_option_get_value_type_label(ValueType type); + void raptor_free_option_description(OptionDescriptionHandle* option_description); + OptionDescriptionHandle* raptor_world_get_option_description(RaptorWorldHandle* world, + Domain domain, + RaptorOption option); + RaptorOption raptor_world_get_option_from_uri(RaptorWorldHandle* world, URIHandle* uri); +} + +struct OptionDescriptionWithoutFinalize { + mixin WithoutFinalize!(OptionDescriptionHandle, + OptionDescriptionWithoutFinalize, + OptionDescription); + @property Domain domain() const { return handle._domain; } + @property RaptorOption option() const { return handle._option; } + @property ValueType option() const { return handle._valueType; } + @property string name() const { return handle._name[0..handle._len].idup; } + @property string label() const { return handle._label.fromStringz.idup; } + @property URIWithoutFinalize uri() const { return URIWithoutFinalize.fromHandle(handle._uri); } +} + +struct OptionDescription { + mixin WithFinalize!(OptionDescriptionHandle, + OptionDescriptionWithoutFinalize, + OptionDescription, + raptor_free_option_description); +} + +ushort optionsCount() { + return cast(ushort)raptor_option_get_count(); +} + +string valueTypeLabel(ValueType type) { + const char* ptr = raptor_option_get_value_type_label(type); + if(!ptr) throw new RDFException(); + return ptr.fromStringz.idup; +} + +OptionDescription getOptionDescription(RaptorWorldWithoutFinalize world, + Domain domain, + RaptorOption option) +{ + return OptionDescription.fromNonnullHandle( + raptor_world_get_option_description(world.handle, domain, option)); +} + +RaptorOption optionFromURI (RaptorWorldWithoutFinalize world, URIWithoutFinalize uri) { + return raptor_world_get_option_from_uri(world.handle, uri.handle); +} diff --git a/dlang/source/rdf/raptor/parser.d b/dlang/source/rdf/raptor/parser.d new file mode 100644 index 000000000..3d0331801 --- /dev/null +++ b/dlang/source/rdf/raptor/parser.d @@ -0,0 +1,245 @@ +module rdf.raptor.parser; + +import std.string; +import std.typecons; +import std.stdio : FILE, File; +import rdf.auxiliary.handled_record; +import rdf.auxiliary.nullable_string; +import rdf.auxiliary.user; +import rdf.raptor.memory; +import rdf.raptor.world; +import rdf.raptor.uri; +import rdf.raptor.statement; +import rdf.raptor.namespace; +import rdf.raptor.log; +import rdf.raptor.iostream; +import rdf.raptor.syntax; +import rdf.raptor.options; + +struct ParserHandle; + +private extern extern(C) { + ParserHandle* raptor_new_parser(RaptorWorldHandle* world, const char *name); + ParserHandle* raptor_new_parser_for_content(RaptorWorldHandle* world, + URIHandle* uri, + const char *mime_type, + const char *buffer, + size_t len, + const char *identifier); + void raptor_free_parser(ParserHandle* parser); + alias raptor_graph_mark_handler = void function(void* user_data, + URIHandle* graph, + int flags); + alias raptor_namespace_handler = void function(void* user_data, NamespaceHandle* nspace); + alias raptor_statement_handler = void function(void* user_data, StatementHandle *statement); + alias raptor_uri_filter_func = int function(void* user_data, URIHandle* uri); + void raptor_parser_set_statement_handler(ParserHandle* parser, + void* user_data, + raptor_statement_handler handler); + void raptor_parser_set_graph_mark_handler(ParserHandle* parser, + void* user_data, + raptor_graph_mark_handler handler); + void raptor_parser_set_namespace_handler(ParserHandle* parser, + void* user_data, + raptor_namespace_handler handler); + void raptor_parser_set_uri_filter(ParserHandle* parser, + raptor_uri_filter_func filter, + void* user_data); + LocatorHandle* raptor_parser_get_locator(ParserHandle* rdf_parser); + void raptor_parser_parse_abort(ParserHandle* rdf_parser); + int raptor_parser_parse_chunk(ParserHandle* rdf_parser, + const char *buffer, + size_t len, + int is_end); + int raptor_parser_parse_file(ParserHandle* rdf_parser, URIHandle* uri, URIHandle* base_uri); + int raptor_parser_parse_file_stream(ParserHandle* rdf_parser, + FILE *stream, + const char *filename, + URIHandle* base_uri); + int raptor_parser_parse_iostream(ParserHandle* rdf_parser, + IOStreamHandle* iostr, + URIHandle* base_uri); + int raptor_parser_parse_start(ParserHandle* rdf_parser, URIHandle* uri); + int raptor_parser_parse_uri(ParserHandle* rdf_parser, URIHandle* uri, URIHandle* base_uri); + int raptor_parser_parse_uri_with_connection(ParserHandle* rdf_parser, + URIHandle* uri, + URIHandle* base_uri, + void *connection); + URIHandle* raptor_parser_get_graph(ParserHandle* rdf_parser); + const(SyntaxDescription*) raptor_parser_get_description(ParserHandle* rdf_parser); + const(char*) raptor_parser_get_name(ParserHandle* rdf_parser); + int raptor_parser_set_option(ParserHandle* parser, + RaptorOption option, + const char *string, int integer); + int raptor_parser_get_option(ParserHandle* parser, + RaptorOption option, + char **string_p, + int *integer_p); + const(char*) raptor_parser_get_accept_header(ParserHandle* parser); + RaptorWorldHandle* raptor_parser_get_world(ParserHandle* parser); +} + +enum GraphMarkFlags { graphMarkStart = 1, graphMarkDeclared = 2 } + +struct ParserWithoutFinalize { + mixin WithoutFinalize!(ParserHandle, + ParserWithoutFinalize, + Parser); + @property LocatorWithoutFinalize locator() const { + return LocatorWithoutFinalize.fromHandle(raptor_parser_get_locator(handle)); + } + void parseAbort() { + raptor_parser_parse_abort(handle); + } + void parseChunk(string buffer, bool isEnd) { + if(raptor_parser_parse_chunk(handle, buffer.ptr, buffer.length, isEnd) != 0) + throw new RDFException(); + } + void parseFile(URIWithoutFinalize uri, URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) { + if(raptor_parser_parse_file(handle, uri.handle, baseURI.handle) != 0) + throw new RDFException(); + } + void parseStdin(URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) { + parseFile(URIWithoutFinalize.fromHandle(null), baseURI); + } + void parseFileStream(File stream, string filename, URIWithoutFinalize baseURI) { + immutable int res = raptor_parser_parse_file_stream(handle, + stream.getFP, + filename.toStringz, + baseURI.handle); + if(res != 0) throw new RDFException(); + } + void parseIOStream(IOStreamWithoutFinalize stream, URIWithoutFinalize baseURI) { + if(raptor_parser_parse_iostream(handle, stream.handle, baseURI.handle) != 0) + throw new RDFException(); + } + void parseStart(URIWithoutFinalize uri) { + if(raptor_parser_parse_start(handle, uri.handle) != 0) + throw new RDFException(); + } + void parseURI(URIWithoutFinalize uri, URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) { + if(raptor_parser_parse_uri(handle, uri.handle, baseURI.handle) != 0) + throw new RDFException(); + } + void parseURI(URIWithoutFinalize uri, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null), + void* connection = null) + { + if(raptor_parser_parse_uri_with_connection(handle, uri.handle, baseURI.handle, connection) != 0) + throw new RDFException(); + } + @property URI graph() const { + return URI.fromHandle(raptor_parser_get_graph(handle)); + } + @property ref const(SyntaxDescription) description() const { + return *raptor_parser_get_description(handle); + } + @property string name() const { + return raptor_parser_get_name(handle).fromStringz.idup; + } + void setOption(RaptorOption option, string value) { + if(raptor_parser_set_option(handle, option, value.toStringz, 0) != 0) + throw new RDFException(); + } + void setOption(RaptorOption option, int value) { + if(raptor_parser_set_option(handle, option, null, value) != 0) + throw new RDFException(); + } + uint getNumericOption(RaptorOption option) const { + int V; + if(raptor_parser_get_option(handle, option, null, &V) < 0) + throw new RDFException(); + return V; + } + string getStringOption(RaptorOption option) const { + char* V; + if(raptor_parser_get_option(handle, option, &V, null) < 0) + throw new RDFException(); + return V.fromStringz.idup; // do NOT free V + } + @property string acceptHeader() const { + char* V = cast(char*)raptor_parser_get_accept_header(handle); + if(!V) throw new RDFException(); + scope(exit) raptor_free_memory(V); + return V.fromStringz.idup; + } + @property RaptorWorldWithoutFinalize world() const { + return RaptorWorldWithoutFinalize.fromHandle(raptor_parser_get_world(handle)); + } +} + +struct Parser { + mixin WithFinalize!(ParserHandle, + ParserWithoutFinalize, + Parser, + raptor_free_parser); + static Parser create(RaptorWorldWithoutFinalize world, string name) { + return Parser.fromNonnullHandle(raptor_new_parser(world.handle, name.toStringz)); + } + static Parser createFromContent(RaptorWorldWithoutFinalize world, + URIWithoutFinalize uri, + Nullable!string mimeType, + Nullable!string buffer, + Nullable!string identifier) + { + return Parser.fromNonnullHandle(raptor_new_parser_for_content(world.handle, + uri.handle, + mimeType.myToStringz, + buffer.myToStringz, + buffer.myLength, + identifier.myToStringz)); + } +} + +class UserParser : UserObject { + Parser record; + this(RaptorWorldWithoutFinalize world, string name) { + record = Parser.create(world, name); + } + final void initializeAllCallbacks() { + initializeGraphMarkHandler(); + initializeStatementHandler(); + initializeNamespaceHandler(); + initializeURIFilter(); + } + final void initializeGraphMarkHandler() { + raptor_parser_set_graph_mark_handler(record.handle, + context, + &raptor_graph_mark_handler_impl); + } + final void initializeStatementHandler() { + raptor_parser_set_statement_handler(record.handle, + context, + &raptor_statement_handler_impl); + } + final void initializeNamespaceHandler() { + raptor_parser_set_namespace_handler(record.handle, + context, + &raptor_namespace_handler_impl); + } + final void initializeURIFilter() { + raptor_parser_set_uri_filter(record.handle, &raptor_uri_filter_impl, context); + } + + void statementHandler(StatementWithoutFinalize statement) { } + void graphMarkHandler(URIWithoutFinalize uri, GraphMarkFlags flags) { } + void namespaceHandler(NamespaceWithoutFinalize namespace) { } + bool uriFilter(URIWithoutFinalize uri) const { + return true; + } + private static extern(C) { + void raptor_statement_handler_impl(void* data, StatementHandle* statement) { + (cast(UserParser)data).statementHandler(StatementWithoutFinalize.fromNonnullHandle(statement)); + } + void raptor_graph_mark_handler_impl(void* data, URIHandle* uri, int Flags) { + (cast(UserParser)data).graphMarkHandler(URIWithoutFinalize.fromNonnullHandle(uri), cast(GraphMarkFlags)Flags); + } + void raptor_namespace_handler_impl(void* data, NamespaceHandle* NS) { + (cast(UserParser)data).namespaceHandler(NamespaceWithoutFinalize.fromNonnullHandle(NS)); + } + int raptor_uri_filter_impl(void* data, URIHandle* uri) { + return (cast(UserParser)data).uriFilter(URIWithoutFinalize.fromNonnullHandle(uri)); + } + } +} + diff --git a/dlang/source/rdf/raptor/serializer.d b/dlang/source/rdf/raptor/serializer.d new file mode 100644 index 000000000..9153c350e --- /dev/null +++ b/dlang/source/rdf/raptor/serializer.d @@ -0,0 +1,144 @@ +module rdf.raptor.serializer; + +import std.string; +import std.stdio : FILE, File; +import rdf.auxiliary.handled_record; +import rdf.raptor.world; +import rdf.raptor.uri; +import rdf.raptor.statement; +import rdf.raptor.namespace; +import rdf.raptor.iostream; +import rdf.raptor.syntax; +import rdf.raptor.log; +import rdf.raptor.options; + +struct SerializerHandle; + +private extern extern(C) { + void raptor_free_serializer(SerializerHandle* rdf_serializer); + int raptor_serializer_start_to_iostream(SerializerHandle* rdf_serializer, + URIHandle* uri, + IOStreamHandle* iostream); + int raptor_serializer_start_to_filename(SerializerHandle* rdf_serializer, + const char *filename); + int raptor_serializer_start_to_file_handle(SerializerHandle* rdf_serializer, + URIHandle* uri, + FILE *fh); + int raptor_serializer_set_namespace(SerializerHandle* rdf_serializer, + URIHandle* uri, + const char *prefix); + int raptor_serializer_set_namespace_from_namespace(SerializerHandle* rdf_serializer, + NamespaceHandle* nspace); + int raptor_serializer_serialize_statement(SerializerHandle* rdf_serializer, + StatementHandle* statement); + int raptor_serializer_serialize_end(SerializerHandle* rdf_serializer); + int raptor_serializer_flush(SerializerHandle* rdf_serializer); + const(SyntaxDescription*) raptor_serializer_get_description(SerializerHandle* rdf_serializer); + IOStreamHandle* raptor_serializer_get_iostream(SerializerHandle* serializer); + LocatorHandle* raptor_serializer_get_locator(SerializerHandle* serializer); + int raptor_serializer_set_option(SerializerHandle* serializer, + RaptorOption option, + const char *string, + int integer); + int raptor_serializer_get_option(SerializerHandle* serializer, + RaptorOption option, + char **string_p, + int *integer_p); + RaptorWorldHandle* raptor_serializer_get_world(SerializerHandle* serializer); + SerializerHandle* raptor_new_serializer(RaptorWorldHandle* world, const char *name); +} + +struct SerializerWithoutFinalize { + mixin WithoutFinalize!(SerializerHandle, + SerializerWithoutFinalize, + Serializer); + // WARNING: Other order of arguments than in C + void startToIOStream(IOStreamWithoutFinalize stream, + URIWithoutFinalize uri = URIWithoutFinalize.fromHandle(null)) + { + if(raptor_serializer_start_to_iostream(handle, uri.handle, stream.handle) != 0) + throw new RDFException(); + } + void startToFilename(string filename) { + if(raptor_serializer_start_to_filename(handle, filename.toStringz) != 0) + throw new RDFException(); + } + // raptor_serializer_start_to_string() is deliberately not used. + // Use StreamToString instead. + void startToFilehandle(URIWithoutFinalize uri, File file) { + if(raptor_serializer_start_to_file_handle(handle, uri.handle, file.getFP) != 0) + throw new RDFException(); + } + // WARNING: Other order of arguments than in C + void setNamespace(string prefix, + URIWithoutFinalize uri = URIWithoutFinalize.fromHandle(null)) + { + if(raptor_serializer_set_namespace(handle, uri.handle, prefix.toStringz) != 0) + throw new RDFException(); + } + void setNamespaceWithoutPrefix(URIWithoutFinalize uri = URIWithoutFinalize.fromHandle(null)) { + if(raptor_serializer_set_namespace(handle, uri.handle, null) != 0) + throw new RDFException(); + } + void setNamespace(NamespaceWithoutFinalize namespace) { + if(raptor_serializer_set_namespace_from_namespace(handle, namespace.handle) != 0) + throw new RDFException(); + } + void serializeStatement(StatementWithoutFinalize statement) { + if(raptor_serializer_serialize_statement(handle, statement.handle) != 0) + throw new RDFException(); + } + void serializeEnd() { + if(raptor_serializer_serialize_end(handle) != 0) + throw new RDFException(); + } + void serializeFlush() { + if(raptor_serializer_flush(handle) != 0) + throw new RDFException(); + } + @property ref const(SyntaxDescription) description() const { + return *raptor_serializer_get_description(handle); + } + @property IOStreamWithoutFinalize iostream() const { + return IOStreamWithoutFinalize.fromHandle(raptor_serializer_get_iostream(handle)); + } + @property LocatorWithoutFinalize locator() const { + return LocatorWithoutFinalize.fromHandle(raptor_serializer_get_locator(handle)); + } + void setOption(RaptorOption option, string value) { + if(raptor_serializer_set_option(handle, option, value.toStringz, 0) != 0) + throw new RDFException(); + } + void setOption(RaptorOption option, int value) { + if(raptor_serializer_set_option(handle, option, null, value) != 0) + throw new RDFException(); + } + uint getNumericOption(RaptorOption option) const { + int V; + if(raptor_serializer_get_option(handle, option, null, &V) < 0) + throw new RDFException(); + return V; + } + string getStringOption(RaptorOption option) const { + char *V; + if(raptor_serializer_get_option(handle, option, &V, null) < 0) + throw new RDFException(); + return V.fromStringz.idup; // do NOT free V + } + @property RaptorWorldWithoutFinalize world() const { + return RaptorWorldWithoutFinalize.fromHandle(raptor_serializer_get_world(handle)); + } +} + +struct Serializer { + mixin WithFinalize!(SerializerHandle, + SerializerWithoutFinalize, + Serializer, + raptor_free_serializer); + static Serializer create(RaptorWorldWithoutFinalize world) { + return Serializer.fromNonnullHandle(raptor_new_serializer(world.handle, null)); + } + static Serializer create(RaptorWorldWithoutFinalize world, string syntaxName) { + return Serializer.fromNonnullHandle(raptor_new_serializer(world.handle, syntaxName.toStringz)); + } +} diff --git a/dlang/source/rdf/raptor/statement.d b/dlang/source/rdf/raptor/statement.d new file mode 100644 index 000000000..478994aae --- /dev/null +++ b/dlang/source/rdf/raptor/statement.d @@ -0,0 +1,106 @@ +module rdf.raptor.statement; + +import std.string; +import std.stdio; +import rdf.auxiliary.handled_record; +import rdf.raptor.memory; +import rdf.raptor.world; +import rdf.raptor.term; +import rdf.raptor.iostream; + +struct StatementHandle { +private: + RaptorWorldHandle* _world; + int _usage; + TermHandle* _subject, _predicate, _object, _graph; +} + +private extern extern(C) { + StatementHandle* raptor_statement_copy(StatementHandle* statement); + void raptor_free_statement(StatementHandle* statement); + int raptor_statement_equals(const StatementHandle* s1, const StatementHandle* s2); + int raptor_statement_compare(const StatementHandle* s1, const StatementHandle* s2); + int raptor_statement_print(const StatementHandle* statement, FILE *stream); + int raptor_statement_print_as_ntriples(const StatementHandle* statement, FILE *stream); + int raptor_statement_ntriples_write(const StatementHandle* statement, + IOStreamHandle *iostr, + int write_graph_term); + StatementHandle* raptor_new_statement(RaptorWorldHandle *world); + StatementHandle* raptor_new_statement_from_nodes(RaptorWorldHandle* world, + TermHandle* subject, + TermHandle* predicate, + TermHandle* object, + TermHandle* graph); + TermHandle* raptor_term_copy(TermHandle* term); +} + +struct StatementWithoutFinalize { + mixin WithoutFinalize!(StatementHandle, + StatementWithoutFinalize, + Statement, + raptor_statement_copy); + mixin CompareHandles!(raptor_statement_equals, raptor_statement_compare); + @property RaptorWorldWithoutFinalize world() const { + return RaptorWorldWithoutFinalize.fromNonnullHandle(handle._world); + } + @property TermWithoutFinalize subject() const { return TermWithoutFinalize.fromHandle(handle._subject); } + @property TermWithoutFinalize predicate() const { return TermWithoutFinalize.fromHandle(handle._predicate); } + @property TermWithoutFinalize object() const { return TermWithoutFinalize.fromHandle(handle._object); } + @property TermWithoutFinalize graph() const { return TermWithoutFinalize.fromHandle(handle._graph); } + void print(File file) const { + if(raptor_statement_print(handle, file.getFP)) + throw new IOStreamException(); + } + void printAsNtriples(File file) const { + if(raptor_statement_print_as_ntriples(handle, file.getFP)) + throw new IOStreamException(); + } + // raptor_statement_init(), raptor_statement_clear() are not boound, because they are probably internal + void ntriplesWrite(IOStreamWithoutFinalize stream, bool writeGraphTerm) const { + if(raptor_statement_ntriples_write(handle, stream.handle, writeGraphTerm)) + throw new IOStreamException(); + } +} + +struct Statement { + mixin WithFinalize!(StatementHandle, + StatementWithoutFinalize, + Statement, + raptor_free_statement); + static Statement create(RaptorWorldWithoutFinalize world) { + return Statement.fromNonnullHandle(raptor_new_statement(world.handle)); + } + /// Makes copies of the terms (unlike the C library) + static Statement create(RaptorWorldWithoutFinalize world, + TermWithoutFinalize subject, + TermWithoutFinalize predicate, + TermWithoutFinalize object, + TermWithoutFinalize graph = TermWithoutFinalize.fromHandle(null)) + { + StatementHandle* handle = + raptor_new_statement_from_nodes(world.handle, + raptor_term_copy(subject.handle), + raptor_term_copy(predicate.handle), + raptor_term_copy(object.handle), + raptor_term_copy(graph.handle)); + return Statement.fromNonnullHandle(handle); + } +} + +unittest { + RaptorWorld world = RaptorWorld.createAndOpen(); + + string uri1 = "http://example.org/xyz"; + string uri2 = "http://example.org/qqq"; + string uri3 = "http://example.org/123"; + + Term term1 = Term.fromURIString(world, uri1); + Term term2 = Term.fromURIString(world, uri2); + Term term3 = Term.fromURIString(world, uri3); + + Statement st = Statement.create(world, term1, term2, term3); + assert(st.subject.toString == '<' ~ uri1 ~ '>', "Subject matches"); + assert(st.predicate.toString == '<' ~ uri2 ~ '>', "Predicate matches"); + assert(st.object.toString == '<' ~ uri3 ~ '>', "Object matches"); +} + diff --git a/dlang/source/rdf/raptor/syntax.d b/dlang/source/rdf/raptor/syntax.d new file mode 100644 index 000000000..4e4da6d55 --- /dev/null +++ b/dlang/source/rdf/raptor/syntax.d @@ -0,0 +1,142 @@ +module rdf.raptor.syntax; + +import std.string; +import rdf.raptor.world; +import rdf.raptor.uri; + +enum SyntaxBitflags { needBaseURI = 1 } + +private extern extern(C) { + const(SyntaxDescription)* raptor_world_get_parser_description(RaptorWorldHandle* world, + uint counter); + const(SyntaxDescription)* raptor_world_get_serializer_description(RaptorWorldHandle* world, + uint counter); + int raptor_world_get_parsers_count(RaptorWorldHandle* world); + int raptor_world_get_serializers_count(RaptorWorldHandle* world); + int raptor_world_is_parser_name(RaptorWorldHandle* world, const char *name); + int raptor_world_is_serializer_name(RaptorWorldHandle* world, const char *name); + immutable(char*) raptor_world_guess_parser_name(RaptorWorldHandle* world, + URIHandle* uri, + const char *mime_type, + const char *buffer, + size_t len, + const char *identifier); +} + +struct MimeTypeQ { +private: + char* _mimeType; + size_t _mimeTypeLen; + char _Q; +public: + @property string mimeType() const { return _mimeType[0.._mimeTypeLen].idup; } + @property byte Q() const { return _Q; } +} + +struct SyntaxDescription { +private: + char** _names; + uint _namesCount; + char* _label; + MimeTypeQ* _mimeTypes; + uint _mimeTypesCount; + char** uriStrings; + uint uriStringsCount; + SyntaxBitflags _flags; +public: + @disable this(this); + string name(uint index) const + in(index < namesCount) + { + return _names[index].fromStringz.idup; + } + @property uint namesCount() const { return _namesCount; } + @property string label() const { return _label.fromStringz.idup; } + ref const(MimeTypeQ) mimeTypeInfo(uint index) const + in(index < _mimeTypesCount) + { + return _mimeTypes[index]; + } + @property uint mimeTypesCount() const { return _mimeTypesCount; } + string uri(uint index) const + in(index < uriStringsCount) + { + return uriStrings[index].fromStringz.idup; + } + @property uint urisCount() const { return uriStringsCount; } + @property SyntaxBitflags flags() const { return _flags; } +} + +struct ParserDescriptionIterator { +private: + RaptorWorldWithoutFinalize _world; + uint _pos = 0; +public: + this(RaptorWorldWithoutFinalize world) { + this._world = world; + } + @property uint position() const { return _pos; } + @property ref const(SyntaxDescription) front() const { + return *raptor_world_get_parser_description(_world.handle, _pos); + } + @property bool empty() const { + return !raptor_world_get_parser_description(_world.handle, _pos); + } + void popFront() + in(!empty) + do { + ++_pos; + } +} + +struct SerializerDescriptionIterator { +private: + RaptorWorldWithoutFinalize _world; + uint _pos = 0; +public: + this(RaptorWorldWithoutFinalize world) { + this._world = world; + } + @property uint position() const { return _pos; } + @property ref const(SyntaxDescription) front() const { + return *raptor_world_get_serializer_description(_world.handle, _pos); + } + @property bool empty() const { + return !raptor_world_get_serializer_description(_world.handle, _pos); + } + void popFront() + in(!empty) + do { + ++_pos; + } +} + +bool isParserName(RaptorWorldWithoutFinalize world, string name) { + return raptor_world_is_parser_name(world.handle, name.toStringz) != 0; +} + +bool isSerializerName(RaptorWorldWithoutFinalize world, string name) { + return raptor_world_is_serializer_name(world.handle, name.toStringz) != 0; +} + +string guessParserName(RaptorWorldWithoutFinalize world, + URIWithoutFinalize uri, + string mimeType, + string buffer, + string identifier) +{ + immutable char* str = raptor_world_guess_parser_name(world.handle, + uri.handle, + mimeType.toStringz, + buffer.ptr, + buffer.length, + identifier.toStringz); + // I don't use .idup because it is valid as long as the world exists + return str.fromStringz; +} + +unittest { + RaptorWorld world = RaptorWorld.createAndOpen(); + for(auto i = ParserDescriptionIterator(world); !i.empty; i.popFront()) { } + for(auto i = SerializerDescriptionIterator(world); !i.empty; i.popFront()) { } +} diff --git a/dlang/source/rdf/raptor/term.d b/dlang/source/rdf/raptor/term.d new file mode 100644 index 000000000..743c60cf1 --- /dev/null +++ b/dlang/source/rdf/raptor/term.d @@ -0,0 +1,206 @@ +module rdf.raptor.term; + +import std.string; +import std.typecons; +import rdf.auxiliary.handled_record; +import rdf.auxiliary.nullable_string; +import rdf.raptor.memory; +import rdf.raptor.world; +import rdf.raptor.uri; +import rdf.raptor.namespace_stack; +import rdf.raptor.iostream; + +private extern extern(C) { + void raptor_free_term(TermHandle* term); + TermHandle* raptor_term_copy(TermHandle* term); + int raptor_term_compare(const TermHandle* t1, const TermHandle* t2); + int raptor_term_equals(const TermHandle* t1, const TermHandle* t2); + char* raptor_term_to_string(TermHandle *term); + TermHandle* raptor_new_term_from_counted_blank(RaptorWorldHandle *world, + const char *blank, + size_t length); + TermHandle* raptor_new_term_from_counted_literal(RaptorWorldHandle* world, + const char *literal, + size_t literal_len, + URIHandle* datatype, + const char *language, + char language_len); + TermHandle* raptor_new_term_from_counted_uri_string(RaptorWorldHandle* world, + const char *uri_string, + size_t length); + TermHandle* raptor_new_term_from_uri(RaptorWorldHandle* world, URIHandle* uri); + TermHandle* raptor_new_term_from_counted_string(RaptorWorldHandle* world, + const char *string, + size_t length); + char* raptor_term_to_turtle_string(TermHandle *term, + NamespaceStackHandle* nstack, + URIHandle* base_uri); + int raptor_term_turtle_write(IOStreamHandle *iostr, + TermHandle *term, + NamespaceStackHandle* nstack, + URIHandle* base_uri); +} + +enum TermKind { unknown = 0, + uri = 1, + literal = 2, + // unused type 3 + blank = 4 } + +struct TermLiteralValue { +private: + char* _str; + uint _len; + URIHandle* _datatype; + char* _language; + uint _languageLen; +public: + @property string value() const { + return _str[0.._len].idup; // with idup it is more reliable + } + @property URIWithoutFinalize datatype() const { + return URIWithoutFinalize.fromHandle(_datatype); + } + /// Return the language tag or empty string if there are none + @property string language() const { + return _language ? _language[0.._languageLen].idup : ""; + } +} + +struct TermBlankValue { +private: + char* str; + uint len; +public: + @property string value() const { + return str[0..len].idup; + } +} + +union TermValue { +private: + URIHandle* uri; + TermLiteralValue literal; + TermBlankValue blank; +} + +struct TermHandle { +private: + RaptorWorldHandle* world; + int usage; // intentionally not accessible from our D bindings + TermKind kind; + TermValue value; +} + +struct TermWithoutFinalize { + mixin WithoutFinalize!(TermHandle, + TermWithoutFinalize, + Term, + raptor_term_copy); + mixin CompareHandles!(raptor_term_equals, raptor_term_compare); + @property RaptorWorldWithoutFinalize world() const { + return RaptorWorldWithoutFinalize.fromHandle(handle.world); + } + @property kind() const { return handle.kind; } + @property bool isURI() const { return kind == TermKind.uri; } + @property bool isLiteral() const { return kind == TermKind.literal; } + @property bool isBlank() const { return kind == TermKind.blank; } + @property URIWithoutFinalize uri() const { + return URIWithoutFinalize.fromHandle(handle.value.uri); + } + @property ref const(TermLiteralValue) literal() const { + return handle.value.literal; + } + @property ref const(TermBlankValue) blank() const { + return handle.value.blank; + } + string toString() const { + char* str = raptor_term_to_string(handle); + if(!str) throw new RDFException(); + scope(exit) raptor_free_memory(str); + return str.fromStringz.idup; + } + string toTurtleString(NamespaceStackWithoutFinalize stack, URIWithoutFinalize baseURI) const { + char* str = raptor_term_to_turtle_string(handle, stack.handle, baseURI.handle); + // Better use raptor_term_to_turtle_counted_string() instead (here and in Ada) + if(!str) throw new RDFException(); + scope(exit) raptor_free_memory(str); + return str.fromStringz.idup; + } + void turtleWrite(IOStreamWithoutFinalize stream, + NamespaceStackWithoutFinalize stack, + URIWithoutFinalize baseURI) + { + if(raptor_term_turtle_write(stream.handle, handle, stack.handle,baseURI.handle) != 0) + throw new RDFException(); + } +} + +struct Term { + mixin WithFinalize!(TermHandle, + TermWithoutFinalize, + Term, + raptor_free_term); + static Term fromBlank(RaptorWorldWithoutFinalize world) { + return Term.fromNonnullHandle(raptor_new_term_from_counted_blank(world.handle, null, 0)); + } + static Term fromBlank(RaptorWorldWithoutFinalize world, string id) { + const char* str = id.toStringz; + TermHandle* handle = raptor_new_term_from_counted_blank(world.handle, str, id.length); + return fromNonnullHandle(handle); + } + static Term fromBlank(RaptorWorldWithoutFinalize world, Nullable!string id) { + const char* str = id.myToStringz; + return fromNonnullHandle(raptor_new_term_from_counted_blank(world.handle, str, str ? id.get.length : 0)); + } + static Term fromLiteral(RaptorWorldWithoutFinalize world, + Nullable!string literal, + URIWithoutFinalize datatype, + Nullable!string language) + { + TermHandle* handle = + raptor_new_term_from_counted_literal(world.handle, + literal.myToStringz, + literal.myLength, + datatype.handle, + language.myToStringz, + cast(char)language.myLength); + return fromNonnullHandle(handle); + } + static Term fromURIString(RaptorWorldWithoutFinalize world, string uri) { + TermHandle* handle = + raptor_new_term_from_counted_uri_string(world.handle, uri.ptr, uri.length); + return fromNonnullHandle(handle); + } + static Term fromURI(RaptorWorldWithoutFinalize world, URIWithoutFinalize uri) { + return fromNonnullHandle(raptor_new_term_from_uri(world.handle, uri.handle)); + } + static Term fromString(RaptorWorldWithoutFinalize world, string uriString) { + return fromNonnullHandle(raptor_new_term_from_counted_string(world.handle, uriString.ptr, uriString.length)); + } +} + +unittest { + RaptorWorld world = RaptorWorld.createAndOpen(); + Term term1 = Term.fromLiteral(world, + Nullable!string("QWE"), + URI.fromString(world, "http://example.org"), // datatype + Nullable!string()); // langage + Term term2 = Term.fromURIString(world, "http://example.org/abc"); + Term term3 = Term.fromURI(world, URI.fromString(world, "http://example.org/cvb")); + // .dup below is necessary due to http://bugs.librdf.org/mantis/view.php?id=648 + Term term4 = Term.fromString(world, "\"ZZZ\"".dup); // Turtle string + assert(term1.literal.value == "QWE", "term1 value"); + assert(term2.uri.toString == "http://example.org/abc", "term2 URI"); + assert(term3.uri.toString == "http://example.org/cvb", "term3 URI"); + assert(term4.literal.value == "ZZZ", "term4 value"); + assert(term1.literal.datatype.toString == "http://example.org", "term1 datatype"); // infinite loop! why? + assert(term1 != term2, "Non-equal terms"); + with(TermKind) { + assert(term1.kind == literal, "term1 is literal"); + assert(term2.kind == uri, "term2 is URI"); + assert(term3.kind == uri, "term3 is URI"); + assert(term4.kind == literal, "term4 is literal"); + } +} + diff --git a/dlang/source/rdf/raptor/uri.d b/dlang/source/rdf/raptor/uri.d new file mode 100644 index 000000000..596d921f6 --- /dev/null +++ b/dlang/source/rdf/raptor/uri.d @@ -0,0 +1,249 @@ +module rdf.raptor.uri; + +import std.string; +import std.stdio : FILE, File; +import rdf.auxiliary.handled_record; +import rdf.raptor.memory; +import rdf.raptor.world; +import rdf.raptor.iostream; +import rdf.raptor.namespace_stack; + +struct URIHandle; + +private extern extern(C) { + void raptor_free_uri(URIHandle* uri); + URIHandle* raptor_uri_copy(URIHandle* uri); + int raptor_uri_compare(URIHandle* uri1, URIHandle* uri2); + int raptor_uri_equals(URIHandle* uri1, URIHandle* uri2); + char* raptor_uri_as_string(URIHandle* uri); + char* raptor_uri_to_relative_uri_string(URIHandle* base_uri, URIHandle* reference_uri); + size_t raptor_uri_resolve_uri_reference(const char *base_uri, + const char *reference_uri, + char *buffer, + size_t length); + char* raptor_uri_counted_filename_to_uri_string(const char *filename, size_t filename_len); + int raptor_uri_uri_string_is_absolute(const char *uri_string); + int raptor_uri_uri_string_is_file_uri(const char *uri_string); + char* raptor_uri_uri_string_to_filename(const char *uri_string); + char* raptor_uri_uri_string_to_filename_fragment(const char *uri_string, char **fragment_p); + int raptor_uri_print(const URIHandle* uri, FILE* stream); + RaptorWorldHandle* raptor_uri_get_world(URIHandle* uri); + int raptor_uri_write(URIHandle* uri, IOStreamHandle* iostr); + int raptor_uri_file_exists(URIHandle* uri); + int raptor_uri_filename_exists(const char *path); + URIHandle* raptor_new_uri_from_counted_string(RaptorWorldHandle* world, const char *uriString, size_t length); + URIHandle* raptor_new_uri_from_uri_local_name(RaptorWorldHandle* world, URIHandle* uri, const char *local_name); + URIHandle* raptor_new_uri_from_uri_or_file_string(RaptorWorldHandle* world, URIHandle* base_uri, const char *uri_or_file_string); + URIHandle* raptor_new_uri_relative_to_base_counted(RaptorWorldHandle* world, + URIHandle* base_uri, + const char *uri_string, + size_t uri_len); + URIHandle* raptor_new_uri_from_id(RaptorWorldHandle* world, URIHandle* base_uri, const char *id); + URIHandle* raptor_new_uri_for_rdf_concept(RaptorWorldHandle* world, const char *name); + URIHandle* raptor_new_uri_for_xmlbase(URIHandle* old_uri); + URIHandle* raptor_new_uri_for_retrieval(URIHandle* old_uri); + char* raptor_uri_to_turtle_string(RaptorWorldHandle* world, + URIHandle* uri, + NamespaceStackHandle* nstack, + URIHandle* base_uri); + int raptor_uri_turtle_write(RaptorWorldHandle* world, + IOStreamHandle* iostr, + URIHandle* uri, + NamespaceStackHandle* nstack, + URIHandle* base_uri); +} + +/// Only absolute URIs! +struct URIWithoutFinalize { + mixin WithoutFinalize!(URIHandle, + URIWithoutFinalize, + URI, + raptor_uri_copy); + mixin CompareHandles!(raptor_uri_equals, raptor_uri_compare); + string toString() const { + return raptor_uri_as_string(handle).fromStringz.idup; + } + alias toString this; + /// Not supposed to be used, but included for completeness + void print(File file) const { + if(raptor_uri_print(handle, file.getFP) != 0) + throw new IOStreamException(); + } + @property RaptorWorldWithoutFinalize world() const { + return RaptorWorldWithoutFinalize.fromHandle(raptor_uri_get_world(handle)); + } + void write(IOStreamWithoutFinalize stream) const { + if(raptor_uri_write(handle, stream.handle) != 0) + throw new IOStreamException(); + } + bool uriFileExists() const { + immutable int result = raptor_uri_file_exists(handle); + if(result < 0) throw new RDFException(); + return result != 0; + } + string toTurtleString(RaptorWorldWithoutFinalize world, + NamespaceStackWithoutFinalize stack, + URIWithoutFinalize baseURI) const + { + // Better use raptor_uri_to_turtle_counted_string() instead (here and in Ada) + char* str = raptor_uri_to_turtle_string(world.handle, handle, stack.handle, baseURI.handle); + if(!str) throw new RDFException(); + scope(exit) raptor_free_memory(str); + return str.fromStringz.idup; + } + void turtleWrite(RaptorWorldWithoutFinalize world, + IOStreamWithoutFinalize stream, + NamespaceStackWithoutFinalize stack, + URIWithoutFinalize baseURI) const + { + int res = raptor_uri_turtle_write(world.handle, + stream.handle, + handle, + stack.handle, + baseURI.handle); + if(res != 0) throw new RDFException(); + } +} + +struct URI { + mixin WithFinalize!(URIHandle, + URIWithoutFinalize, + URI, + raptor_free_uri); + static URI fromString(RaptorWorldWithoutFinalize world, string uriString) { + URIHandle* handle = + raptor_new_uri_from_counted_string(world.handle, uriString.ptr, uriString.length); + return fromNonnullHandle(handle); + } + this(URIHandle* ptr) { + this.ptr = ptr; + } + this(RaptorWorldWithoutFinalize world, string s) { + ptr = raptor_new_uri_from_counted_string(world.handle, s.ptr, s.length); + if(!ptr) throw new NullRDFException(); + } + static URI fromURIWithLocalName(RaptorWorldWithoutFinalize world, + URIWithoutFinalize uri, + string localName) + { + URIHandle* handle = + raptor_new_uri_from_uri_local_name(world.handle, uri.handle, localName.toStringz); + return fromNonnullHandle(handle); + } + static URI fromURIOrFileString(RaptorWorldWithoutFinalize world, + URIWithoutFinalize baseURI, + string uriOrFile) + { + URIHandle* handle = + raptor_new_uri_from_uri_or_file_string(world.handle, baseURI.handle, uriOrFile.toStringz); + return fromNonnullHandle(handle); + } + static URI fromURIRelativeToBase(RaptorWorldWithoutFinalize world, + URIWithoutFinalize baseURI, + string uri) + { + URIHandle* handle = + raptor_new_uri_relative_to_base_counted(world.handle, baseURI.handle, uri.ptr, uri.length); + return fromNonnullHandle(handle); + } + static URI fromID(RaptorWorldWithoutFinalize world, URIWithoutFinalize baseURI, string id) { + URIHandle* handle = + raptor_new_uri_from_id(world.handle, baseURI.handle, id.toStringz); + return fromNonnullHandle(handle); + } + static URI fromRDFConcept(RaptorWorldWithoutFinalize world, string name) { + return fromNonnullHandle(raptor_new_uri_for_rdf_concept(world.handle, name.toStringz)); + } + static URI fromXMLBase(URIWithoutFinalize oldURI) { + return fromNonnullHandle(raptor_new_uri_for_xmlbase(oldURI.handle)); + } + static URI forRetrieval(URIWithoutFinalize oldURI) { + return fromNonnullHandle(raptor_new_uri_for_retrieval(oldURI.handle)); + } +} + +string toRelativeURIString(URIWithoutFinalize baseURI, URIWithoutFinalize referenceURI) { + char* str = raptor_uri_to_relative_uri_string(baseURI.handle, referenceURI.handle); + if(!str) throw new NullRDFException(); + scope(exit) raptor_free_memory(str); + return str.fromStringz.idup; +} + +string resolveURIReference(string baseURI, string referenceURI) { + immutable size_t bufferLength = baseURI.length + referenceURI.length + 1; + char[] buffer = new char[bufferLength]; + immutable res = raptor_uri_resolve_uri_reference(baseURI.toStringz, + referenceURI.toStringz, + buffer.ptr, + bufferLength); + if(!res) throw new RDFException(); + buffer.length = bufferLength; + return cast(string)buffer; +} + +string filenameToURIString(string filename) { + char* result1 = raptor_uri_counted_filename_to_uri_string(filename.ptr, filename.length); + if(!result1) throw new RDFException(); + scope(exit) raptor_free_memory(result1); + return result1.fromStringz.idup; +} + +bool uriStringIsAbsolute(string uriString) { + immutable int res = raptor_uri_uri_string_is_absolute(uriString.toStringz); + if(res < 0) throw new RDFException(); + return res > 0; +} + +bool uriStringIsFileURI(string uriString) { + return raptor_uri_uri_string_is_file_uri(uriString.toStringz) != 0; +} + +string uriStringToFilename(string uriString) { + char* result = raptor_uri_uri_string_to_filename(uriString.toStringz); + if(!result) throw new RDFException(); + scope(exit) raptor_free_memory(result); + return result.fromStringz.idup; +} + +struct FilenameAndFragment { + string filename, fragment; +} + +FilenameAndFragment uriStringToFilenameAndFragment(string uriString) { + char* fragment; + char* filename = + raptor_uri_uri_string_to_filename_fragment(uriString.toStringz, &fragment); + if(!filename) throw new RDFException(); + scope(exit) { + raptor_free_memory(filename); + if(fragment) raptor_free_memory (fragment); + } + return FilenameAndFragment(filename.fromStringz.idup, fragment.fromStringz.idup); +} + +bool filenameExists(string filename) { + immutable int result = raptor_uri_filename_exists(filename.toStringz); + if(result < 0) throw new RDFException(); + return result != 0; +} + +unittest { + RaptorWorld world = RaptorWorld.createAndOpen(); + + // Conversions to/from string + URI u = URI(world, "http://example.com"); + assert(u.toString == "http://example.com"); + // assert(u == "http://example.com"); does not work with DMD v2.080.1 + + string URI_1 = "http://example.org/xyz"; + string URI_3 = "http://example.org/123"; + URI URI_1_Obj = URI.fromString(world, URI_1); + URI URI_2_Obj = URI.fromString(world, URI_1); + URI URI_3_Obj = URI.fromString(world, URI_3); + URI URI_4_Obj = URI.fromString(world, "http://example.org"); + assert(URI_1_Obj.toString == URI_1, "Converting URI to string"); + assert(URI_1_Obj == URI_2_Obj, "Comparing identical URIs"); + assert(URI_1_Obj != URI_3_Obj, "Comparing different URIs"); + assert(URI.fromURIRelativeToBase(world, URI_1_Obj, "zxc").toString == "http://example.org/zxc", "Relative URI to base"); + assert(URI.forRetrieval(URI_4_Obj).toString == "http://example.org/", "URI for retrieval"); +} diff --git a/dlang/source/rdf/raptor/world.d b/dlang/source/rdf/raptor/world.d new file mode 100644 index 000000000..a0f2c30a2 --- /dev/null +++ b/dlang/source/rdf/raptor/world.d @@ -0,0 +1,73 @@ +module rdf.raptor.world; + +import rdf.auxiliary.handled_record; + +struct RaptorWorldHandle; + +enum RaptorFlagType : char { libxmlErrorSave = 1, + libxmlStructuredErrorSave = 2, + uriInterning = 3, + wwwSkipInitFinish = 4 } + +struct FlagAndValue { + RaptorFlagType flag; + bool value; +} + +private extern extern(C) { + RaptorWorldHandle* raptor_new_world_internal(uint _version); + void raptor_free_world(RaptorWorldHandle* world); + void raptor_world_open(RaptorWorldHandle* world); + int raptor_world_set_flag(RaptorWorldHandle* raptor_world, int flag, int value); +} + +private RaptorWorldHandle* raptor_new_world() { + import rdf.raptor.constants : versionDecimal; + return raptor_new_world_internal(versionDecimal); +} + +struct RaptorWorldWithoutFinalize { + mixin WithoutFinalize!(RaptorWorldHandle, + RaptorWorldWithoutFinalize, + RaptorWorld); + void open() { + raptor_world_open(handle); + } + void open(FlagAndValue[] flags) { + setFlags(flags); + open(); + } + void setFlag(RaptorFlagType flag, bool value) { + raptor_world_set_flag(handle, flag, value ? 1 : 0); + } + void setFlags(FlagAndValue[] flags) { + foreach(f; flags) + setFlag(f.flag, f.value); + } +} + +struct RaptorWorld { + mixin WithFinalize!(RaptorWorldHandle, + RaptorWorldWithoutFinalize, + RaptorWorld, + raptor_free_world, + raptor_new_world); + static RaptorWorld createAndOpen() { + RaptorWorld world = create(); + world.open(); + return world; + } + static RaptorWorld createAndOpen(FlagAndValue[] flags) { + RaptorWorld world = create(); + world.open(flags); + return world; + } +} + +// Not implemented: set_libxslt_security_preferences() + +unittest { + RaptorWorld defaultWorld = RaptorWorld.createAndOpen(); + RaptorWorld worldWithSomeFlags = + RaptorWorld.createAndOpen([FlagAndValue(RaptorFlagType.uriInterning, false)]); +} diff --git a/dlang/source/rdf/raptor/www.d b/dlang/source/rdf/raptor/www.d new file mode 100644 index 000000000..f3cf4510d --- /dev/null +++ b/dlang/source/rdf/raptor/www.d @@ -0,0 +1,205 @@ +module rdf.raptor.www; + +import std.string; +import rdf.auxiliary.handled_record; +import rdf.auxiliary.user; +import rdf.raptor.memory; +import rdf.raptor.world; +import rdf.raptor.uri; + +private extern extern(C) { + void raptor_free_www(WWWHandle* www); + alias raptor_www_write_bytes_handler = void function(WWWHandle* www, + void* userdata, + const void* ptr, + size_t size, + size_t nmemb); + alias raptor_www_content_type_handler = void function(WWWHandle* www, + void* userdata, + const char *content_type); + alias raptor_uri_filter_func = int function(void *userData, URIHandle* uri); + alias raptor_www_final_uri_handler = void function(WWWHandle* www, + void* userdata, + URIHandle* final_uri); + void raptor_www_set_write_bytes_handler(WWWHandle *www, + raptor_www_write_bytes_handler handler, + void *userData); + void raptor_www_set_content_type_handler(WWWHandle *www, + raptor_www_content_type_handler handler, + void *userData); + void raptor_www_set_uri_filter(WWWHandle *www, raptor_uri_filter_func filter, void *userData); + void raptor_www_set_final_uri_handler(WWWHandle *www, + raptor_www_final_uri_handler handler, + void *userData); + // raptor_www_set_user_agent() & raptor_www_set_proxy() & raptor_www_set_http_accept() + // don't return an error on out-of-memory: http://bugs.librdf.org/mantis/view.php?id=649 + void raptor_www_set_user_agent(WWWHandle *www, const char *user_agent); + void raptor_www_set_proxy(WWWHandle *www, const char *proxy); + void raptor_www_set_http_accept(WWWHandle *www, const char *value); + int raptor_www_set_http_cache_control(WWWHandle *www, const char *cache_control); + void raptor_www_set_connection_timeout(WWWHandle *www, int timeout); + URIHandle* raptor_www_get_final_uri(WWWHandle* www); + int raptor_www_fetch(WWWHandle* www, URIHandle* uri); + alias raptor_data_malloc_handler = void* function(size_t size); + int raptor_www_fetch_to_string(WWWHandle* www, + URIHandle* uri, + void **string_p, + size_t *length_p, + raptor_data_malloc_handler malloc_handler); + void* raptor_www_get_connection(WWWHandle* www); + int raptor_www_set_ssl_cert_options(WWWHandle* www, + const char *cert_filename, + const char *cert_type, + const char *cert_passphrase); + int raptor_www_set_ssl_verify_options(WWWHandle* www, int verify_peer, int verify_host); + void raptor_www_abort(WWWHandle* www, const char *reason); + WWWHandle* raptor_new_www(RaptorWorldHandle* world); + WWWHandle* raptor_new_www_with_connection(RaptorWorldHandle* world, void *connection); +} + +struct WWWHandle; + +private immutable(char*) emptyToNull(string s) { + if(s == "") return null; + return s.toStringz; +} + +struct WWWWithoutFinalize { + mixin WithoutFinalize!(WWWHandle, + WWWWithoutFinalize, + WWW); + /// Empty string means no User-Agent header (I make the behavior the same as --user-agent="" in Wget. + void setUserAgent(string userAgent) { + raptor_www_set_user_agent(handle, userAgent.emptyToNull); + } + void setProxy(string userAgent) { + raptor_www_set_proxy(handle, userAgent.toStringz); + } + void setHTTPAccept(string value) { + raptor_www_set_http_accept(handle, value.emptyToNull); + } + void setCacheControl(string value) { + if(raptor_www_set_http_cache_control(handle, value.toStringz)) + throw new RDFException(); + } + /// Remove Cache-Control: header altogether + void unsetCacheControl() { + if(raptor_www_set_http_cache_control(handle, null)) + throw new RDFException(); + } + void setConnectionTimeout(uint seconds) { + raptor_www_set_connection_timeout(handle, seconds); + } + URI getFinalURI() { + // may return object with NULL handle + return URI.fromHandle(raptor_www_get_final_uri(handle)); + } + void fetch(URIWithoutFinalize uri) { + if(raptor_www_fetch(handle, uri.handle) != 0) + throw new RDFException(); + } + string fetchToString(URIWithoutFinalize uri) { + char* str; + size_t len; + if(raptor_www_fetch_to_string(handle, uri.handle, cast(void**)&str, &len, null) != 0) + throw new RDFException(); + scope(exit) raptor_free_memory(str); + return str[0..len].idup; + } + @property void* connection() const { + return raptor_www_get_connection(handle); + } + void setSSLCertOptions(string certFilename, string certType, string certPassphrase) { + immutable int res = raptor_www_set_ssl_cert_options(handle, + certFilename.toStringz, + certType.toStringz, + certPassphrase.toStringz); + if(res != 0) throw new RDFException(); + } + void setSSLVerifyOptions(bool verifyPeer, bool verifyHost) { + if(raptor_www_set_ssl_verify_options(handle, verifyPeer ? 1 : 0, verifyHost ? 1 : 0) != 0) + throw new RDFException(); + } + void abortOperation(string reason) { + raptor_www_abort(handle, reason.toStringz); + } +} + +struct WWW { + mixin WithFinalize!(WWWHandle, + WWWWithoutFinalize, + WWW, + raptor_free_www); + static WWW create(RaptorWorldWithoutFinalize world) { + return fromNonnullHandle(raptor_new_www(world.handle)); + } + static WWW create(RaptorWorldWithoutFinalize world, void* connection) { + return fromNonnullHandle(raptor_new_www_with_connection(world.handle, connection)); + } +} + +class UserWWW : UserObject { + WWW record; + this(RaptorWorldWithoutFinalize world) { + record = WWW.create(world); + } + this(RaptorWorldWithoutFinalize world, void* connection) { + record = WWW.create(world, connection); + } + final void initializeAllCallbacks() { + initializeWriteBytesHandler(); + initializeContentTypeHandler(); + initializeURIFilter(); + initializeFinalURIHandler(); + } + final void initializeWriteBytesHandler() { + raptor_www_set_write_bytes_handler(record.handle, + &writeBytesHandlerImpl, + context); + + } + final void initializeContentTypeHandler() { + raptor_www_set_content_type_handler(record.handle, + &contentTypeHandlerImpl, + context); + } + final void initializeURIFilter() { + raptor_www_set_uri_filter(record.handle, &uriFilterImpl, context); + } + final void initializeFinalURIHandler() { + raptor_www_set_final_uri_handler(record.handle, &finalURIHandlerImpl, context); + } + + void writeBytesHandler(string value) { } + void contentTypeHandler(string contentType) { } + void finalURIHandler(URIWithoutFinalize URI) { } + + /// Return False to disallow loading an URI + bool uriFilter(URIWithoutFinalize URI) { + return true; + } + + private static extern(C) { + void writeBytesHandlerImpl(WWWHandle *www, + void* userData, + const void* ptr, + size_t Size, + size_t Nmemb) + { + (cast(UserWWW)userData).writeBytesHandler(// fromHandle(www)), // ignored + (cast(immutable char*)ptr)[0..Size*Nmemb]); + } + void contentTypeHandlerImpl(WWWHandle *www, void* userData, const char* contentType) { + (cast(UserWWW)userData).contentTypeHandler(// fromHandle(www)), // ignored + (cast(immutable char*)contentType).fromStringz); + } + int uriFilterImpl(void* userData, URIHandle* URI) { + return !(cast(UserWWW)userData).uriFilter(URIWithoutFinalize.fromNonnullHandle(URI)); + } + void finalURIHandlerImpl(WWWHandle *www, void* userData, URIHandle* URI) { + (cast(UserWWW)userData).finalURIHandler(// fromHandle(www)), // ignored + URIWithoutFinalize.fromNonnullHandle(URI)); + } + } +} + diff --git a/dlang/source/rdf/rasqal/bnode.d b/dlang/source/rdf/rasqal/bnode.d new file mode 100644 index 000000000..bd4433a9a --- /dev/null +++ b/dlang/source/rdf/rasqal/bnode.d @@ -0,0 +1,45 @@ +module rdf.rasqal.bnode; + +import std.typecons; +import std.string; +import rdf.auxiliary.handled_record; +import rdf.auxiliary.nullable_string; +import rdf.auxiliary.user; +import rdf.rasqal.memory; +import rdf.rasqal.world; + +private extern extern(C) { + alias rasqal_generate_bnodeid_handler = const(char*) function(RasqalWorldHandle* world, + void *user_data, + char *user_bnodeid); + int rasqal_world_set_generate_bnodeid_handler(RasqalWorldHandle* world, + void *user_data, + rasqal_generate_bnodeid_handler handler); + int rasqal_world_set_default_generate_bnodeid_parameters(RasqalWorldHandle* world, + const char *prefix, + int base); +} + +class BNodeIDHandler : UnmovableObject { + this(RasqalWorldWithoutFinalize world) { + rasqal_world_set_generate_bnodeid_handler(world.handle, cast(void*)this, &bnodeIDHandleImpl); + } + abstract string doHandle(RasqalWorldWithoutFinalize world, Nullable!string userID) const; + static extern(C) const(char*) + bnodeIDHandleImpl(RasqalWorldHandle* world, void* data, char* userID) { + scope(exit) rasqal_free_memory(userID); + return (cast(BNodeIDHandler)data).doHandle( + RasqalWorldWithoutFinalize.fromNonnullHandle(world), + userID.myFromStringz).toStringz; + } +} + +void setDefaultGenerateBnodeidParameters(RasqalWorldWithoutFinalize world, + Nullable!string prefix, + int base) +{ + immutable int result = + rasqal_world_set_default_generate_bnodeid_parameters(world.handle, prefix.myToStringz, base); + if(result != 0) + throw new RDFException(); +} diff --git a/dlang/source/rdf/rasqal/constants.d b/dlang/source/rdf/rasqal/constants.d new file mode 100644 index 000000000..9196e57cd --- /dev/null +++ b/dlang/source/rdf/rasqal/constants.d @@ -0,0 +1,52 @@ +module rdf.rasqal.constants; + +import std.string; + +private extern extern(C) immutable __gshared uint rasqal_version_major; +private extern extern(C) immutable __gshared uint rasqal_version_minor; +private extern extern(C) immutable __gshared uint rasqal_version_release; +private extern extern(C) immutable __gshared uint rasqal_version_decimal; + +alias versionMajor = rasqal_version_major; +alias versionMinor = rasqal_version_minor; +alias versionRelease = rasqal_version_release; +alias versionDecimal = rasqal_version_decimal; + +private extern extern(C) { + immutable char* rasqal_copyright_string; + immutable char* rasqal_home_url_string; + immutable char* rasqal_license_string; + immutable char* rasqal_short_copyright_string; + immutable char* rasqal_version_string; +} + +string copyrightString() { + return rasqal_copyright_string.fromStringz; +} + +string homeURLString() { + return rasqal_home_url_string.fromStringz; +} + +string licenseString() { + return rasqal_license_string.fromStringz; +} + +string shortCopyrightString() { + return rasqal_short_copyright_string.fromStringz; +} + +string versionString() { + return rasqal_version_string.fromStringz; +} + +unittest { + import std.conv; + + string combinedString = + to!string(versionMajor) ~ '.' ~ to!string(versionMinor) ~ '.' ~ to!string(versionRelease); + uint combinedDecimal = + versionMajor * 10000 + versionMinor * 100 + versionRelease; + assert(combinedString == versionString, "Combined version string"); + assert(combinedDecimal == versionDecimal, "Combined decimal version"); +} diff --git a/dlang/source/rdf/rasqal/data_graph.d b/dlang/source/rdf/rasqal/data_graph.d new file mode 100644 index 000000000..12d3424ea --- /dev/null +++ b/dlang/source/rdf/rasqal/data_graph.d @@ -0,0 +1,134 @@ +module rdf.rasqal.data_graph; + +import std.typecons; +import std.string; +import std.stdio : File, FILE; +import rdf.auxiliary.handled_record; +import rdf.auxiliary.nullable_string; +import rdf.raptor.uri; +import rdf.raptor.iostream; +import rdf.rasqal.world; + +enum DataGraphFlags { none, // unused + named, + background } + +struct DataGraphHandle { +private: + RasqalWorldHandle* _world; + URIHandle* _uri, _nameURI; + uint _flags; + char* _formatType, _formatName; + URIHandle* _formatURI; + IOStreamHandle* _ioStr; + URIHandle* _baseURI; + int _usage; +} + +private extern extern(C) { + void rasqal_free_data_graph(DataGraphHandle* dg); + DataGraphHandle* rasqal_new_data_graph_from_data_graph(DataGraphHandle* dg); + int rasqal_data_graph_print(DataGraphHandle* dg, FILE *fh); + DataGraphHandle* rasqal_new_data_graph_from_iostream(RasqalWorldHandle* world, + IOStreamHandle* iostr, + URIHandle* base_uri, + URIHandle* name_uri, + uint flags, + const char *formatType, + const char *formatName, + URIHandle* formatURI); + DataGraphHandle* rasqal_new_data_graph_from_uri(RasqalWorldHandle* world, + URIHandle* uri, + URIHandle* name_uri, + uint flags, + const char *formatType, + const char *formatName, + URIHandle* formatURI); +} + +struct DataGraphWithoutFinalize { + mixin WithoutFinalize!(DataGraphHandle, + DataGraphWithoutFinalize, + DataGraph, + rasqal_new_data_graph_from_data_graph); + @property RasqalWorldWithoutFinalize world() const { + return RasqalWorldWithoutFinalize.fromHandle(handle._world); + } + @property URIWithoutFinalize uri() const { + return URIWithoutFinalize.fromHandle(handle._uri); + } + @property URIWithoutFinalize nameURI() const { + return URIWithoutFinalize.fromHandle(handle._nameURI); + } + @property DataGraphFlags flags() const { + return cast(DataGraphFlags)handle._flags; + } + @property string formatType() const { + return handle._formatType.fromStringz.idup; + } + @property string formatName() const { + return handle._formatName.fromStringz.idup; + } + @property URIWithoutFinalize formatURI() const { + return URIWithoutFinalize.fromHandle(handle._formatURI); + } + @property IOStreamWithoutFinalize iostream() { + return IOStreamWithoutFinalize.fromHandle(handle._ioStr); + } + @property URIWithoutFinalize baseURI() const { + return URIWithoutFinalize.fromHandle(handle._baseURI); + } + @property uint usageCount() const { + return handle._usage; + } + void print(File file) const { + if(rasqal_data_graph_print(handle, file.getFP) != 0) + throw new RDFException(); + } +} + +struct DataGraph { + mixin WithFinalize!(DataGraphHandle, + DataGraphWithoutFinalize, + DataGraph, + rasqal_free_data_graph); + static DataGraph fromIOStream(RasqalWorldWithoutFinalize world, + IOStreamWithoutFinalize iostream, + URIWithoutFinalize baseURI, + URIWithoutFinalize nameURI = URIWithoutFinalize.fromHandle(null), + DataGraphFlags flags = DataGraphFlags.background, + Nullable!string formatType = Nullable!string(), + Nullable!string formatName = Nullable!string(), + URIWithoutFinalize formatURI = URIWithoutFinalize.fromHandle(null)) + { + DataGraphHandle* handle = + rasqal_new_data_graph_from_iostream(world.handle, + iostream.handle, + baseURI.handle, + nameURI.handle, + flags, + formatType.myToStringz, + formatName.myToStringz, + formatURI.handle); + return DataGraph.fromHandle(handle); + } + static DataGraph fromURI(RasqalWorldWithoutFinalize world, + URIWithoutFinalize uri, + URIWithoutFinalize nameURI, + DataGraphFlags flags, + Nullable!string formatType, + Nullable!string formatName, + URIWithoutFinalize formatURI) + { + DataGraphHandle* handle = + rasqal_new_data_graph_from_uri(world.handle, + uri.handle, + nameURI.handle, + flags, + formatType.myToStringz, + formatName.myToStringz, + formatURI.handle); + return DataGraph.fromHandle(handle); + } +} + diff --git a/dlang/source/rdf/rasqal/features.d b/dlang/source/rdf/rasqal/features.d new file mode 100644 index 000000000..03599a042 --- /dev/null +++ b/dlang/source/rdf/rasqal/features.d @@ -0,0 +1,80 @@ +module rdf.rasqal.features; + +import std.string; +import rdf.auxiliary.handled_record; +import rdf.raptor.uri; +import rdf.rasqal.world; + +enum FeatureType { unknown = -1, noNet = 0, randSeed = 1 } + +enum FeatureValueType { other = -1, integerType = 0, stringType = 1 } + +private extern extern(C) { + FeatureType rasqal_feature_from_uri(RasqalWorldHandle* world, URIHandle* uri); + int rasqal_feature_value_type(const FeatureType feature); + int rasqal_features_enumerate(RasqalWorldHandle* world, + const FeatureType feature, + const char**name, + URIHandle** uri, + const char** label); + uint rasqal_get_feature_count(); +} + +FeatureType featureFromURI(RasqalWorldWithoutFinalize world, URIWithoutFinalize uri) { + return rasqal_feature_from_uri(world.handle, uri.handle); +} + +FeatureValueType getType(FeatureType feature) { + return cast(FeatureValueType)rasqal_feature_value_type(feature); +} + +/// In a future version the field may be made readonly +struct FeatureDescription { + string name, label; + URI uri; // with finalize +} + +class RDFUnknownFeature: RDFException { + this(string msg, string file = __FILE__, size_t line = __LINE__) { + super(msg, file, line); + } + this(string file = __FILE__, size_t line = __LINE__) { + this("IOStream error", file, line); + } +} + + +// For API simplicity, I don't support the C library feature to retrieve only a part of the data. +const(FeatureDescription) getFeatureDescription(const RasqalWorldWithoutFinalize world, FeatureType feature) { + char* name, label; + URIHandle* uri; + int res = rasqal_features_enumerate(world.handle, feature, &name, &uri, &label); + if(res > 0) throw new RDFUnknownFeature(); + if(res != 0) throw new RDFException(); + return FeatureDescription(name.fromStringz.idup, label.fromStringz.idup, URI.fromNonnullHandle(uri)); +} + +uint getFeatureCount() { + return rasqal_get_feature_count(); +} + +struct FeatureIterator { +private: + RasqalWorldWithoutFinalize _world; + uint _num = 0; +public: + this(RasqalWorldWithoutFinalize world) { + _world = world; + } + bool empty() const { + return _num == getFeatureCount(); + } + const(FeatureDescription) front() const { + return getFeatureDescription(_world, cast(FeatureType)_num); + } + void popFront() { + ++_num; + } + @property size_t position() const { return _num; } +} + diff --git a/dlang/source/rdf/rasqal/literal.d b/dlang/source/rdf/rasqal/literal.d new file mode 100644 index 000000000..aa06b3fc2 --- /dev/null +++ b/dlang/source/rdf/rasqal/literal.d @@ -0,0 +1,237 @@ +module rdf.rasqal.literal; + +import std.typecons; +import std.string; +import std.stdio : File, FILE; +import rdf.config; +import rdf.auxiliary.versions; +import rdf.auxiliary.handled_record; +import rdf.raptor.uri; +import rdf.rasqal.memory; +import rdf.rasqal.world; + +struct LiteralHandle; + +enum LiteralType { unknown, // internal + blank, + uri, + string_, + xsd_string, + boolean, + integer, + float_, + double_, + decimal, + datetime, + udt, + pattern, + qname, + variable, + date } + +enum CompareFlags { none = 0, + nocase = 1, + xQuery = 2, + rdf = 4, + uri = 8, + sameterm = 16 } + +private extern extern(C) { + void rasqal_free_literal(LiteralHandle* l); + int rasqal_literal_same_term(LiteralHandle* l1, LiteralHandle* l2); + const(char*) rasqal_literal_as_counted_string(LiteralHandle* l, + size_t *len_p, + int flags, + int *error_p); + int rasqal_literal_compare(LiteralHandle* l1, LiteralHandle* l2, int flags, int *error_p); + URIHandle* rasqal_literal_datatype(LiteralHandle* l); + LiteralType rasqal_literal_get_rdf_term_type(LiteralHandle* l); + int rasqal_literal_is_rdf_literal(LiteralHandle* l); + int rasqal_literal_print(LiteralHandle* l, FILE *fh); + void rasqal_literal_print_type(LiteralHandle* l, FILE *fh); + const(char*) rasqal_literal_type_label(LiteralType type); + LiteralHandle* rasqal_new_typed_literal(RasqalWorldHandle* world, + LiteralType type, + const char *string); + LiteralHandle* rasqal_new_boolean_literal(RasqalWorldHandle* world, int value); + LiteralHandle* rasqal_new_decimal_literal(RasqalWorldHandle* world, const char *string); + LiteralHandle* rasqal_new_double_literal(RasqalWorldHandle* world, double d); + LiteralHandle* rasqal_new_float_literal(RasqalWorldHandle* world, float f); + LiteralHandle* rasqal_new_floating_literal(RasqalWorldHandle* world, + LiteralType type, + double d); + LiteralHandle* rasqal_new_numeric_literal_from_long(RasqalWorldHandle* world, + LiteralType type, + long value); + LiteralHandle* rasqal_new_simple_literal(RasqalWorldHandle* world, + LiteralType type, + const char *string_); + LiteralHandle* rasqal_new_string_literal(RasqalWorldHandle* world, + const char* string_, + const char* language, + URIHandle* datatype, + const char* datatype_qname); + LiteralHandle* rasqal_new_uri_literal(RasqalWorldHandle* world, URIHandle* uri); + LiteralHandle* rasqal_literal_value(LiteralHandle* l); + LiteralHandle* rasqal_literal_as_node(LiteralHandle* l); +} + +struct LiteralWithoutFinalize { + mixin WithoutFinalize!(LiteralHandle, + LiteralWithoutFinalize, + Literal); + bool opEquals(const LiteralWithoutFinalize other) const { + return rasqal_literal_same_term(handle, other.handle) != 0; + } + string toString(CompareFlags flags = CompareFlags.none) const { + int error = 0; + size_t length; + const char* item = rasqal_literal_as_counted_string(handle, + &length, + cast(int)flags, + &error); + if(error != 0) throw new RDFException(); + return item[0..length].idup; + } + int compare(LiteralWithoutFinalize other, CompareFlags flags) const { + int error = 0; + return rasqal_literal_compare(handle, other.handle, int(flags), &error); + } + @property URIWithoutFinalize datatype() const { + return URIWithoutFinalize.fromHandle(rasqal_literal_datatype(handle)); + } + @property LiteralType rdfTermType() const { + return rasqal_literal_get_rdf_term_type(handle); + } + static if(Version(rasqalVersionFeatures) >= Version("0.9.33")) { + private extern extern(C) LiteralType rasqal_literal_get_type(LiteralHandle* l); + private extern extern(C) char* rasqal_literal_get_language(LiteralHandle* l); + @property Nullable!string language() const { + rasqal_literal_get_language(handle).myFromStringz; + } + @property literalType type() const { + return rasqal_literal_get_type(handle); + } + } + bool isRDFLiteral() const { + return rasqal_literal_is_rdf_literal(handle) != 0; + } + void print(File file) const { + if(rasqal_literal_print(handle, file.getFP) != 0) + throw new RDFException(); + } + void printType(File file) const { + rasqal_literal_print_type(handle, file.getFP); + } + Literal value() const { + return Literal.fromHandle(rasqal_literal_value(handle)); + } + Literal asNode() const { + return Literal.fromHandle(rasqal_literal_as_node(handle)); + } +} + +struct Literal { + mixin WithFinalize!(LiteralHandle, + LiteralWithoutFinalize, + Literal, + rasqal_free_literal); + bool opEquals(const LiteralWithoutFinalize other) const { + return rasqal_literal_same_term(handle, other.handle) != 0; + } + static Literal newTypedLiteral(RasqalWorldWithoutFinalize world, + LiteralType typeOfLiteral, + string value) + { + LiteralHandle* handle = + rasqal_new_typed_literal(world.handle, typeOfLiteral, value.toStringz); + return fromNonnullHandle(handle); + } + static Literal fromBoolean(RasqalWorldWithoutFinalize world, bool value) { + LiteralHandle* handle = + rasqal_new_boolean_literal(world.handle, cast(int)value); + return fromNonnullHandle(handle); + } + // Not implemented + // Literal fromDatetime(RasqalWorldWithoutFinalize world, XSD_Datetime value) + static Literal fromDecimal(RasqalWorldWithoutFinalize world, string value) { + LiteralHandle* handle = + rasqal_new_decimal_literal(world.handle, value.toStringz); + return fromNonnullHandle(handle); + } + // Not implemented + // Literal fromDecimal(RasqalWorldWithoutFinalize world, XSD_Decimal value) { + static Literal fromDouble(RasqalWorldWithoutFinalize world, double value) { + return fromNonnullHandle(rasqal_new_double_literal(world.handle, value)); + } + static Literal fromFloat(RasqalWorldWithoutFinalize world, float value) { + return fromNonnullHandle(rasqal_new_float_literal(world.handle, value)); + } + static Literal fromFloating(RasqalWorldWithoutFinalize world, LiteralType type, double value) + in(type == LiteralType.float_ || type == LiteralType.double_) + { + return fromNonnullHandle(rasqal_new_floating_literal(world.handle, type, value)); + } + /// Deliberately accept only long integers, don't implement "int value". + static Literal fromInteger(RasqalWorldWithoutFinalize world, long value) { + LiteralHandle* handle = + rasqal_new_numeric_literal_from_long(world.handle, LiteralType.integer, value); + return fromNonnullHandle(handle); + } + static Literal newSimpleLiteral(RasqalWorldWithoutFinalize world, + LiteralType type, + string value) + in(type == LiteralType.blank || type == LiteralType.qname) + { + char* value2 = rasqal_new_string(value); // freed by rasqal_new_simple_literal() + return fromNonnullHandle(rasqal_new_simple_literal(world.handle, type, value2)); + } + static Literal newStringLiteral(RasqalWorldWithoutFinalize world, + string value, + Nullable!string language, + URIWithoutFinalize datatype) + { + return Literal.fromNonnullHandle( + rasqal_new_string_literal(world.handle, + rasqal_new_string(value), + rasqal_new_string(language), + datatype.handle, + null)); + } + + static Literal newStringLiteral(RasqalWorldWithoutFinalize world, + string value, + Nullable!string language, + string Datatype_Qname) + { + return Literal.fromNonnullHandle( + rasqal_new_string_literal(world.handle, + rasqal_new_string(value), + rasqal_new_string(language), + null, + rasqal_new_string(Datatype_Qname))); + } + + static Literal newStringLiteral(RasqalWorldWithoutFinalize world, + string value, + Nullable!string language = Nullable!string()) + { + return Literal.fromNonnullHandle( + rasqal_new_string_literal(world.handle, + rasqal_new_string(value), + rasqal_new_string(language), + null, + null)); + } + static Literal fromString(RasqalWorldWithoutFinalize world, string value) { + return newStringLiteral(world, value); + } + static Literal fromURI(RasqalWorldWithoutFinalize world, URIWithoutFinalize value) { + return Literal.fromNonnullHandle(rasqal_new_uri_literal(world.handle, value.handle)); + } +} + +string typeLabel(LiteralType kind) { + return rasqal_literal_type_label(kind).fromStringz.idup; +} + diff --git a/dlang/source/rdf/rasqal/memory.d b/dlang/source/rdf/rasqal/memory.d new file mode 100644 index 000000000..132df760b --- /dev/null +++ b/dlang/source/rdf/rasqal/memory.d @@ -0,0 +1,30 @@ +module rdf.rasqal.memory; + +import std.typecons; + +extern extern(C) { + void rasqal_free_memory (char* ptr); + char* rasqal_alloc_memory(size_t size); + char* rasqal_calloc_memory (size_t nmemb, size_t size); +} + +// Missing in C code, so I implement it in D +char *rasqal_copy_c_string(const char* str) { + import core.stdc.string; + immutable size_t len = strlen(str) + 1; + char* newStr = rasqal_alloc_memory(len); + return strncpy(newStr, str, len); +} + +// Missing in C code, so I implement it in D +char* rasqal_new_string(string str) { + import core.stdc.string; + char* newStr = rasqal_alloc_memory(str.length+1); + newStr[str.length] = '\0'; + return strncpy(newStr, str.ptr, str.length); +} + +char* rasqal_new_string(Nullable!string str) { + return str.isNull ? null : rasqal_new_string(str.get); +} + diff --git a/dlang/source/rdf/rasqal/query.d b/dlang/source/rdf/rasqal/query.d new file mode 100644 index 000000000..2352d6ecb --- /dev/null +++ b/dlang/source/rdf/rasqal/query.d @@ -0,0 +1,146 @@ +module rdf.rasqal.query; + +import std.typecons; +import std.string; +import rdf.auxiliary.handled_record; +import rdf.auxiliary.nullable_string; +import rdf.raptor.uri; +import rdf.raptor.iostream; +import rdf.rasqal.memory; +import rdf.rasqal.world; +import rdf.rasqal.features; +import rdf.rasqal.data_graph; +import rdf.rasqal.query_results; + +// This API is partial, as I consider many C functions as internals. + +struct QueryHandle; + +private extern extern(C) { + DataGraphHandle* rasqal_new_data_graph_from_data_graph(DataGraphHandle* dg); + + void rasqal_free_query(QueryHandle* query); + int rasqal_query_add_data_graph(QueryHandle* query, DataGraphHandle* data_graph); + QueryResultsHandle* rasqal_query_execute(QueryHandle* query); + int rasqal_query_prepare(QueryHandle* query, const char *query_string, URIHandle* base_uri); + int rasqal_query_set_store_results(QueryHandle* query, int store_results); + void rasqal_query_set_wildcard(QueryHandle* query, int wildcard); + int rasqal_query_write(IOStreamHandle* iostr, + QueryHandle* query, + URIHandle* format_uri, + URIHandle* base_uri); + int rasqal_query_iostream_write_escaped_counted_string(QueryHandle* query, + IOStreamHandle* iostr, + const char *string, + size_t len); + char* rasqal_query_escape_counted_string(QueryHandle* query, + const char *string, + size_t len, + size_t *output_len_p); + int rasqal_query_set_feature(QueryHandle* query, FeatureType feature, int value); + int rasqal_query_set_feature_string(QueryHandle* query, FeatureType feature, const char *value); + int rasqal_query_get_feature(QueryHandle* query, FeatureType feature); + const(char*) rasqal_query_get_feature_string(QueryHandle* query, FeatureType feature); + QueryResultsType rasqal_query_get_result_type(QueryHandle* query); + QueryHandle* rasqal_new_query(RasqalWorldHandle* world, const char *name, const char *uri); +} + +struct QueryWithoutFinalize { + mixin WithoutFinalize!(QueryHandle, + QueryWithoutFinalize, + Query); + void addDataGraph(DataGraphWithoutFinalize graph) { + int res = rasqal_query_add_data_graph(handle, + rasqal_new_data_graph_from_data_graph(graph.handle)); + if(res != 0) throw new RDFException(); + } + // TODO: +// void addDataGraphDetach(DataGraphWithoutFinalize graph) { +// addDataGraph(detach(Graph)); +// } + void addDataGraphs(DataGraphWithoutFinalize[] graphs) { + foreach(dg; graphs) addDataGraph(dg); + } + // TODO: +// void addDataGraphsDetach(DataGraphWithoutFinalize[] graphs) { +// foreach(dg; graphs) addDataGraphDetach(dg); +// } + QueryResults execute() { + return QueryResults.fromNonnullHandle(rasqal_query_execute(handle)); + } + void prepare(string queryString, URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) { + if(rasqal_query_prepare(handle, queryString.toStringz, baseURI.handle) != 0) + throw new RDFException(); + } + void setStoreResults(bool store) { + if(rasqal_query_set_store_results(handle, store) != 0) + throw new RDFException(); + } + void setWilcard(bool wilcard) { + rasqal_query_set_store_results(handle, wilcard); + } + void writeQuery(IOStreamWithoutFinalize stream, + URIWithoutFinalize formatURI, + URIWithoutFinalize baseURI) const + { + if(rasqal_query_write(stream.handle, handle, formatURI.handle, baseURI.handle) != 0) + throw new RDFException(); + } + // Is it really useful? Maybe remove from public API? + void writeEscapedString(IOStreamWithoutFinalize stream, string str) const { + int res = rasqal_query_iostream_write_escaped_counted_string(handle, + stream.handle, + str.ptr, + str.length); + if(res != 0) throw new RDFException(); + } + string escapeString(string str) const { + size_t outLen; + char* result = rasqal_query_escape_counted_string(handle, str.ptr, str.length, &outLen); + if(!result) throw new RDFException(); + scope(exit) rasqal_free_memory(result); + return result[0..outLen].idup; + } + void setFeature(FeatureType feature, uint value) { + if(rasqal_query_set_feature(handle, feature, value) != 0) + throw new RDFException(); + } + void setFeature(FeatureType feature, string value) { + if(rasqal_query_set_feature_string(handle, feature, value.toStringz) != 0) + throw new RDFException(); + } + uint getFeatureInt(FeatureType feature) const { + int result = rasqal_query_get_feature(handle, feature); + if(result < 0) throw new RDFException(); + return result; + } + string getFeatureString(FeatureType feature) const { + const char* result = rasqal_query_get_feature_string(handle, feature); + if(!result) throw new RDFException(); + scope(exit) rasqal_free_memory(cast(char*)result); + return result.fromStringz.idup; + } + QueryResultsType getResultType() const { + QueryResultsType result = rasqal_query_get_result_type(handle); + if(result == QueryResultsType.unknown) throw new RDFException(); + return result; + } + // Deliberately not implemented + // function getUpdateOperation + // function getUpdateOperationsSequence +} + +struct Query { + mixin WithFinalize!(QueryHandle, + QueryWithoutFinalize, + Query, + rasqal_free_query); + static Query create(RasqalWorldWithoutFinalize world, Nullable!string name, Nullable!string uri) { + return fromNonnullHandle(rasqal_new_query(world.handle, name.myToStringz, uri.myToStringz)); + } +} + +unittest { + // see main.d instead +} + diff --git a/dlang/source/rdf/rasqal/query_results.d b/dlang/source/rdf/rasqal/query_results.d new file mode 100644 index 000000000..299f71e3a --- /dev/null +++ b/dlang/source/rdf/rasqal/query_results.d @@ -0,0 +1,272 @@ +module rdf.rasqal.query_results; + +import std.string; +import rdf.config; +import rdf.auxiliary.versions; +import rdf.auxiliary.handled_record; +import rdf.raptor.uri; +import rdf.raptor.statement; +import rdf.raptor.iostream; +import rdf.rasqal.world; +import rdf.rasqal.literal; +import rdf.rasqal.query; + +struct QueryResultsHandle; + +private struct MyDummy; + +enum QueryResultsType { bindings, + boolean, + graph, + syntax, + unknown } + +private extern extern(C) { + void rasqal_free_query_results(QueryResultsHandle* query_results); + QueryResultsType rasqal_query_results_get_type(QueryResultsHandle* query_results); + int rasqal_query_results_is_bindings(QueryResultsHandle* query_results); + int rasqal_query_results_is_boolean(QueryResultsHandle* query_results); + int rasqal_query_results_is_graph(QueryResultsHandle* query_results); + int rasqal_query_results_is_syntax(QueryResultsHandle* query_results); + int rasqal_query_results_finished(QueryResultsHandle* query_results); + const(char*) rasqal_query_results_get_binding_name(QueryResultsHandle* query_results, + int offset); + LiteralHandle* rasqal_query_results_get_binding_value(QueryResultsHandle* query_results, + int offset); + LiteralHandle* rasqal_query_results_get_binding_value_by_name(QueryResultsHandle* query_results, + const char *name); + int rasqal_query_results_get_bindings_count(QueryResultsHandle* query_results); + int rasqal_query_results_get_boolean(QueryResultsHandle* query_results); + int rasqal_query_results_get_count(QueryResultsHandle* query_results); + StatementHandle* rasqal_query_results_get_triple(QueryResultsHandle* query_results); + int rasqal_query_results_next(QueryResultsHandle* query_results); + int rasqal_query_results_next_triple(QueryResultsHandle* query_results); + int rasqal_query_results_read(IOStreamHandle* iostr, + QueryResultsHandle* results, + const char *name, + const char *mime_type, + URIHandle* format_uri, + URIHandle* base_uri); + int rasqal_query_results_write(IOStreamHandle* iostr, + QueryResultsHandle* results, + const char *name, + const char *mime_type, + URIHandle* format_uri, + URIHandle* base_uri); + const(char*) rasqal_query_results_type_label(QueryResultsType type); + int rasqal_query_results_rewind(QueryResultsHandle* results); + QueryResultsHandle* rasqal_new_query_results(RasqalWorldHandle* world, + QueryHandle* query, + QueryResultsType type, + MyDummy* vars_table); +// QueryResultsHandle* rasqal_new_query_results2(RasqalWorldHandle* world, +// QueryHandle* query, +// QueryResultsType type); + QueryHandle* rasqal_query_results_get_query(QueryResultsHandle* query_results); +} + +struct QueryResultsWithoutFinalize { + mixin WithoutFinalize!(QueryResultsHandle, + QueryResultsWithoutFinalize, + QueryResults); + @property QueryResultsType type() const { + return rasqal_query_results_get_type(handle); + } + @property bool isBindings() const { + return rasqal_query_results_is_bindings(handle) != 0; + } + @property bool isBoolean() const { + return rasqal_query_results_is_boolean(handle) != 0; + } + @property bool isGraph() const { + return rasqal_query_results_is_graph(handle) != 0; + } + @property bool isSyntax() const { + return rasqal_query_results_is_syntax(handle) != 0; + } + // function addRow is deliberately not implemented + bool finished() const + in(isBindings() || isGraph()) + { + return rasqal_query_results_finished(handle) != 0; + } + string getBindingName(uint offset) const + in(isBindings) + { + const char* ptr = rasqal_query_results_get_binding_name(handle, int(offset)); + if(!ptr) throw new RDFException(); + return ptr.fromStringz.idup; + } + LiteralWithoutFinalize getBindingValue(uint offset) const + in(isBindings) + { + return LiteralWithoutFinalize.fromNonnullHandle( + rasqal_query_results_get_binding_value(handle, int(offset))); + } + LiteralWithoutFinalize getBindingValueByName(string name) const + in(isBindings) + { + return LiteralWithoutFinalize.fromNonnullHandle( + rasqal_query_results_get_binding_value_by_name(handle, name.toStringz)); + } + // rasqal_query_results_get_bindings() deliberately not implemented. + // Use iterators instead. + @property uint bindingsCount() const + in(isBindings) + { + int count = rasqal_query_results_get_bindings_count(handle); + if(count < 0) throw new RDFException(); + return count; + } + @property bool boolean() const + in(isBoolean) + { + int value = rasqal_query_results_get_boolean(handle); + if(value < 0) throw new RDFException(); + return value != 0; + } + @property uint currentCount() const { + int value = rasqal_query_results_get_count(handle); + if(value < 0) throw new RDFException(); + return value; + } + @property QueryWithoutFinalize query() const { + return QueryWithoutFinalize.fromNonnullHandle(rasqal_query_results_get_query(handle)); + } + @property StatementWithoutFinalize triple() const + in(isGraph) + { + return StatementWithoutFinalize.fromNonnullHandle(rasqal_query_results_get_triple(handle)); + } + // Deliberately not implemented: + // getRowByOffset(uint offset) + void next() { + int res = rasqal_query_results_next(handle); + //if(res != 0) throw new RDFException(); // Check is done by Finished procedure, not here + } + void nextTriple() { + int res = rasqal_query_results_next_triple(handle); + //if(res != 0) throw new RDFException(); // Check is done by Finished procedure, not here + } + void read(IOStreamWithoutFinalize stream, + string formatName, + string mimeType, + URIWithoutFinalize formatURI, + URIWithoutFinalize baseURI) + { + int res = rasqal_query_results_read(stream.handle, + handle, + formatName == "" ? null : formatName.toStringz, + mimeType == "" ? null : mimeType.toStringz, + formatURI.handle, + baseURI.handle); + if(res != 0) throw new RDFException(); + } + void write(IOStreamWithoutFinalize stream, + string formatName, + string mimeType, + URIWithoutFinalize formatURI, + URIWithoutFinalize baseURI) const + { + int res = rasqal_query_results_write(stream.handle, + handle, + formatName == "" ? null : formatName.toStringz, + mimeType == "" ? null : mimeType.toStringz, + formatURI.handle, + baseURI.handle); + if(res != 0) throw new RDFException(); + } + void rewind() { + if(rasqal_query_results_rewind(handle) != 0) + throw new RDFException(); + } +} + +struct QueryResults { + mixin WithFinalize!(QueryResultsHandle, + QueryResultsWithoutFinalize, + QueryResults, + rasqal_free_query_results); + static QueryResults create(RasqalWorldWithoutFinalize world, + QueryWithoutFinalize query, + QueryResultsType type) + { + return fromNonnullHandle(rasqal_new_query_results(world.handle, query.handle, type, null)); + } + static if(Version(rasqalVersionFeatures) >= Version("0.9.33")) { + private extern extern(C) + QueryResultsHandle* rasqal_new_query_results_from_string(RasqalWorldHandle* world, + QueryResultsType type, + URIHandle* base_uri, + const char* string, + size_t string_len); + static create(RasqalWorldWithoutFinalize world, + QueryResultsType type, + URITypeWithoutFinalize baseURI, + string value) + { + return QueryResults.fromNonnullHandle( + rasqal_new_query_results_from_string(world.handle, + type, + baseURI.handle, + value.ptr, value.length)); + } + } +} + +string typeLabel(QueryResultsType type) { + const char* ptr = rasqal_query_results_type_label(type); + if(!ptr) throw new RDFException(); + return ptr.fromStringz.idup; +} + +struct QueryResultsRange { +private: + QueryResultsWithoutFinalize obj; +public: + this(QueryResultsWithoutFinalize obj) { + this.obj = obj; + } + @property bool empty() const { return obj.finished(); } + @property const(QueryResultsRange) front() const { return this; } // return itself + void popFront() { obj.next(); } + string getBindingName(uint offset) const { + return obj.getBindingName(offset); + } + LiteralWithoutFinalize getBindingValue(uint offset) const { + return obj.getBindingValue(offset); + } + LiteralWithoutFinalize getBindingValueByName(string name) const { + return obj.getBindingValueByName(name); + } + void rewind() { obj.rewind(); } +} + +struct QueryResultsTriplesRange { +private: + QueryResultsWithoutFinalize obj; +public: + this(QueryResultsWithoutFinalize obj) { + this.obj = obj; + } + @property bool empty() const { return obj.finished(); } + @property StatementWithoutFinalize front() const { return triple(); } + void popFront() { obj.nextTriple(); } + StatementWithoutFinalize triple() const { return obj.triple(); } + void rewind() { obj.rewind(); } +} + +struct VariablesRange { +private: + QueryResultsWithoutFinalize obj; + uint count = 0; +public: + this(QueryResultsWithoutFinalize obj) { + this.obj = obj; + } + @property bool empty() const { return count == obj.bindingsCount; } + @property string front() const { return name; } + void popFront() { ++count; } + @property string name() const { return obj.getBindingName(count); } +} + diff --git a/dlang/source/rdf/rasqal/syntax.d b/dlang/source/rdf/rasqal/syntax.d new file mode 100644 index 000000000..9a56518f6 --- /dev/null +++ b/dlang/source/rdf/rasqal/syntax.d @@ -0,0 +1,76 @@ +module rdf.rasqal.syntax; + +import std.string; +import rdf.rasqal.world; +import rdf.raptor.syntax; + +private extern extern(C) { + const(SyntaxDescription*) rasqal_world_get_query_language_description( + RasqalWorldHandle* world, + uint counter); + const(SyntaxDescription*) rasqal_world_get_query_results_format_description( + RasqalWorldHandle* world, + uint counter); + int rasqal_language_name_check(RasqalWorldHandle* world, const char *name); +} + +const(SyntaxDescription*) getQueryLanguageDescription(const RasqalWorldWithoutFinalize world, + uint counter) +{ + return rasqal_world_get_query_language_description(world.handle, counter); +} + +const(SyntaxDescription*) getQueryResultsFormatDescription(const RasqalWorldWithoutFinalize world, + uint counter) +{ + return rasqal_world_get_query_results_format_description(world.handle, counter); +} + +struct QueryLanguageIterator { +private: + RasqalWorldWithoutFinalize _world; + uint _counter = 0; +public: + this(RasqalWorldWithoutFinalize world) { + _world = world; + } + bool empty() const { + return !getQueryLanguageDescription(_world, _counter); + } + ref const(SyntaxDescription) front() const { + return *getQueryLanguageDescription(_world, _counter); + } + void popFront() { + ++_counter; + } +} + +struct QueryResultsFormatIterator { +private: + RasqalWorldWithoutFinalize _world; + uint _counter = 0; +public: + this(RasqalWorldWithoutFinalize world) { + _world = world; + } + bool empty() const { + return !getQueryResultsFormatDescription(_world, _counter); + } + ref const(SyntaxDescription) front() const { + return *getQueryResultsFormatDescription(_world, _counter); + } + void popFront() { + ++_counter; + } +} + +bool languageNameCheck(RasqalWorldWithoutFinalize world, string name) { + return rasqal_language_name_check(world.handle, name.toStringz) != 0; +} + +unittest { + RasqalWorld world = RasqalWorld.createAndOpen(); + for(auto i = QueryLanguageIterator(world); !i.empty; i.popFront()) { } + for(auto i = QueryResultsFormatIterator(world); !i.empty; i.popFront()) { } +} + diff --git a/dlang/source/rdf/rasqal/world.d b/dlang/source/rdf/rasqal/world.d new file mode 100644 index 000000000..b70d68175 --- /dev/null +++ b/dlang/source/rdf/rasqal/world.d @@ -0,0 +1,74 @@ +module rdf.rasqal.world; + +import std.typecons; +import rdf.auxiliary.handled_record; +import rdf.auxiliary.nullable_string; +import rdf.raptor.world; +import rdf.raptor.uri; + +struct RasqalWorldHandle; + +private extern extern(C) { + RasqalWorldHandle* rasqal_new_world(); + void rasqal_free_world(RasqalWorldHandle* world); + int rasqal_world_open(RasqalWorldHandle* world); + RaptorWorldHandle* rasqal_world_get_raptor(RasqalWorldHandle* world); + void rasqal_world_set_raptor(RasqalWorldHandle* world, RaptorWorldHandle* raptor_world); + int rasqal_world_set_warning_level(RasqalWorldHandle* world, uint warning_level); + const(char*) rasqal_world_guess_query_results_format_name(RasqalWorldHandle* world, + URIHandle* uri, + const char *mime_type, + const char *buffer, + size_t len, + const char *identifier); +} + +struct RasqalWorldWithoutFinalize { + mixin WithoutFinalize!(RasqalWorldHandle, + RasqalWorldWithoutFinalize, + RasqalWorld); + void open() { + rasqal_world_open(handle); + } + @property RaptorWorldWithoutFinalize raptor() const { + return RaptorWorldWithoutFinalize.fromNonnullHandle(rasqal_world_get_raptor(this.handle)); + } + @property void raptor(RaptorWorldWithoutFinalize world) { + rasqal_world_set_raptor(handle, world.handle); + } + @property void warningLevel(uint level) { + if(rasqal_world_set_warning_level(handle, level) != 0) + throw new RDFException(); + } + Nullable!string guessQueryResultsFormatName(URIWithoutFinalize uri, + Nullable!string mimeType, + Nullable!string buffer, + Nullable!string identifier) const + { + const char* result = rasqal_world_guess_query_results_format_name(handle, + uri.handle, + mimeType.myToStringz, + buffer.myToStringz, + buffer.myLength, + identifier.myToStringz); + return result.myFromStringz; + } +} + +struct RasqalWorld { + mixin WithFinalize!(RasqalWorldHandle, + RasqalWorldWithoutFinalize, + RasqalWorld, + rasqal_free_world, + rasqal_new_world); + static RasqalWorld createAndOpen() { + RasqalWorld world = create(); + world.open(); + return world; + } +} + +unittest { + RasqalWorld world2 = RasqalWorld.createAndOpen(); + RaptorWorldWithoutFinalize world = world2.raptor; +} diff --git a/dlang/source/rdf/redland/constants.d b/dlang/source/rdf/redland/constants.d new file mode 100644 index 000000000..c9f273416 --- /dev/null +++ b/dlang/source/rdf/redland/constants.d @@ -0,0 +1,52 @@ +module rdf.librdf.constants; + +import std.string; + +private extern extern(C) immutable __gshared uint librdf_version_major; +private extern extern(C) immutable __gshared uint librdf_version_minor; +private extern extern(C) immutable __gshared uint librdf_version_release; +private extern extern(C) immutable __gshared uint librdf_version_decimal; + +alias versionMajor = librdf_version_major; +alias versionMinor = librdf_version_minor; +alias versionRelease = librdf_version_release; +alias versionDecimal = librdf_version_decimal; + +private extern extern(C) { + immutable char* librdf_copyright_string; + immutable char* librdf_home_url_string; + immutable char* librdf_license_string; + immutable char* librdf_short_copyright_string; + immutable char* librdf_version_string; +} + +string copyrightString() { + return librdf_copyright_string.fromStringz; +} + +string homeURLString() { + return librdf_home_url_string.fromStringz; +} + +string licenseString() { + return librdf_license_string.fromStringz; +} + +string shortCopyrightString() { + return librdf_short_copyright_string.fromStringz; +} + +string versionString() { + return librdf_version_string.fromStringz; +} + +unittest { + import std.conv; + + string combinedString = + to!string(versionMajor) ~ '.' ~ to!string(versionMinor) ~ '.' ~ to!string(versionRelease); + uint combinedDecimal = + versionMajor * 10000 + versionMinor * 100 + versionRelease; + assert(combinedString == versionString, "Combined version string"); + assert(combinedDecimal == versionDecimal, "Combined decimal version"); +} diff --git a/dlang/source/rdf/redland/containers.d b/dlang/source/rdf/redland/containers.d new file mode 100644 index 000000000..4b3a588a3 --- /dev/null +++ b/dlang/source/rdf/redland/containers.d @@ -0,0 +1,38 @@ +module rdf.redland.containers; + +import rdf.auxiliary.handled_record; +import rdf.redland.world; +import rdf.redland.model; +import rdf.redland.node; +import rdf.redland.uri; + +class WrongListFormat: RDFException { + this(string msg, string file = __FILE__, size_t line = __LINE__) { + super(msg, file, line); + } + this(string file = __FILE__, size_t line = __LINE__) { + this("Wrong RDF list", file, line); + } +} + +NodeWithoutFinalize[] rdfList(RedlandWorldWithoutFinalize world, ModelWithoutFinalize model, NodeWithoutFinalize start) { + NodeWithoutFinalize[] result; + // Ugly and not very efficient code. + auto firstURI = Node.fromURI(world, URI.fromString(world, "http://www.w3.org/1999/02/22-rdf-syntax-ns#first")); + auto nilURI = Node.fromURI(world, URI.fromString(world, "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil")); + auto nextURI = Node.fromURI(world, URI.fromString(world, "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest")); + while (start != nilURI) { + import std.array; + auto first = model.getTargets(start, firstURI).array; + if(first.length != 1) throw new WrongListFormat(); + result ~= first; + auto next = model.getTargets(start, nextURI).array; + if(next.length != 1) throw new WrongListFormat(); + start = next.front; + } + return result; +} + +unittest { + // see main.d instead +} \ No newline at end of file diff --git a/dlang/source/rdf/redland/iterator.d b/dlang/source/rdf/redland/iterator.d new file mode 100644 index 000000000..5312710fb --- /dev/null +++ b/dlang/source/rdf/redland/iterator.d @@ -0,0 +1,56 @@ +module rdf.redland.iterator; + +import rdf.auxiliary.handled_record; +import rdf.redland.world; + +// Usually you should use Base_With_Finalization types, such as defined in RDF.Redland.Iterator_Iterator + +struct IteratorHandle; + +private extern extern(C) { + void librdf_free_iterator(IteratorHandle* iterator); + int librdf_iterator_end(IteratorHandle* iterator); + int librdf_iterator_next(IteratorHandle* iterator); + void* librdf_iterator_get_object(IteratorHandle* iterator); + void* librdf_iterator_get_context(IteratorHandle* iterator); + void* librdf_iterator_get_key(IteratorHandle* iterator); + void* librdf_iterator_get_value(IteratorHandle* iterator); + IteratorHandle* librdf_new_empty_iterator(RedlandWorldHandle* world); +} + +struct IteratorWithoutFinalize { + mixin WithoutFinalize!(IteratorHandle, + IteratorWithoutFinalize, + Iterator); + @property bool empty() const { + return librdf_iterator_end(handle) != 0; + } + @property const(IteratorWithoutFinalize) front() const { return this; } + void popFront() { + cast(void)librdf_iterator_next(handle); + } + @property void* _object() const { + return librdf_iterator_get_object(handle); + } + @property void* _context() const { + return librdf_iterator_get_context(handle); + } + @property void* _key() const { + return librdf_iterator_get_key(handle); + } + @property void* _value() const { + return librdf_iterator_get_value(handle); + } + // librdf_iterator_add_map() not implemented +} + +struct Iterator { + mixin WithFinalize!(IteratorHandle, + IteratorWithoutFinalize, + Iterator, + librdf_free_iterator); + static Iterator emptyIterator(RedlandWorldWithoutFinalize world) { + return Iterator.fromNonnullHandle(librdf_new_empty_iterator(world.handle)); + } +} + diff --git a/dlang/source/rdf/redland/log.d b/dlang/source/rdf/redland/log.d new file mode 100644 index 000000000..88c02afb4 --- /dev/null +++ b/dlang/source/rdf/redland/log.d @@ -0,0 +1,76 @@ +module rdf.redland.log; + +import std.string; +import rdf.auxiliary.user; +import rdf.raptor.log; +import rdf.redland.world; + +struct LogMessageHandle; + +enum loglevel { none = 0, + debug_ = 1, + info = 2, + warn = 3, + error = 4, + fatal = 5 } + +enum LogFacility { none, + concepts, + digest, + files, + hash, + init, + iterator, + list, + model, + node, + parser, + query, + serializer, + statement, + storage, + stream, + uri, + utf8, + memory, + raptor } + +private extern extern(C) { + int librdf_log_message_code(const LogMessageHandle* message); + LogLevel librdf_log_message_level(const LogMessageHandle* message); + LogFacility librdf_log_message_facility(const LogMessageHandle* message); + const(char*) librdf_log_message_message(const LogMessageHandle* message); + LocatorHandle* librdf_log_message_locator(const LogMessageHandle* message); + alias librdf_log_func = int function(void *user_data, LogMessageHandle* message); + + void librdf_world_set_logger(RedlandWorldHandle* world, + void *user_data, + librdf_log_func log_handler); +} + +struct LogMessage { +private: + LogMessageHandle* handle; +public: + @property int code() const { return librdf_log_message_code(handle); } + @property int level() const { return librdf_log_message_level(handle); } + @property LogFacility facility() const { return librdf_log_message_facility(handle); } + @property string message() const { + return librdf_log_message_message(handle).fromStringz.idup; + } + @property Locator locator() const { + return Locator.fromHandle(librdf_log_message_locator(handle)); + } +} + +class LogHandler : UnmovableObject { + this(RedlandWorldWithoutFinalize world) { + librdf_world_set_logger(world.handle, cast(void*)this, &ourHandler); + } + abstract void handle(LogMessage message); + private static extern(C) int ourHandler(void *user_data, LogMessageHandle* message) { + (cast(LogHandler)user_data).handle(LogMessage(message)); + return 1; + } +} + diff --git a/dlang/source/rdf/redland/memory.d b/dlang/source/rdf/redland/memory.d new file mode 100644 index 000000000..b6f629119 --- /dev/null +++ b/dlang/source/rdf/redland/memory.d @@ -0,0 +1,30 @@ +module rdf.redland.memory; + +import std.typecons; + +extern extern(C) { + void librdf_free_memory (char* ptr); + char* librdf_alloc_memory(size_t size); + char* librdf_calloc_memory (size_t nmemb, size_t size); +} + +// Missing in C code, so I implement it in D +char *librdf_copy_c_string(char* str) { + import core.stdc.string; + immutable size_t len = strlen(str) + 1; + char* newStr = librdf_alloc_memory(len); + return strncpy(newStr, str, len); +} + +// Missing in C code, so I implement it in D +char* librdf_new_string(string str) { + import core.stdc.string; + char* newStr = librdf_alloc_memory(str.length+1); + newStr[str.length] = '\0'; + return strncpy(newStr, str.ptr, str.length); +} + +char* librdf_new_string(Nullable!string str) { + return str.isNull ? null : librdf_new_string(str.get); +} + diff --git a/dlang/source/rdf/redland/model.d b/dlang/source/rdf/redland/model.d new file mode 100644 index 000000000..fda5f90b5 --- /dev/null +++ b/dlang/source/rdf/redland/model.d @@ -0,0 +1,360 @@ +module rdf.redland.model; + +import std.typecons; +import std.string; +import rdf.auxiliary.handled_record; +import rdf.raptor.iostream; +import rdf.redland.world; +import rdf.redland.uri; +import rdf.redland.node; +import rdf.redland.statement; +import rdf.redland.node_iterator; +import rdf.redland.stream; +import rdf.redland.query; +import rdf.redland.query_results; +import rdf.redland.model; +import rdf.redland.storage; + +struct ModelHandle; + +private extern extern(C) { + void librdf_free_model(ModelHandle* model); + int librdf_model_enumerate(RedlandWorldHandle* world, + const int counter, + const char **name, + const char **label); + int librdf_model_size(ModelHandle* model); + int librdf_model_add(ModelHandle* model, + NodeHandle* subject, + NodeHandle* predicate, + NodeHandle* object); + int librdf_model_add_statement(ModelHandle* model, StatementHandle* statement); + int librdf_model_add_statements(ModelHandle* model, StreamHandle* statement_stream); + int librdf_model_context_add_statement(ModelHandle* model, + NodeHandle* context, + StatementHandle* statement); + int librdf_model_context_add_statements(ModelHandle* model, + NodeHandle* context, + StreamHandle* stream); + int librdf_model_remove_statement(ModelHandle* model, StatementHandle* statement); + int librdf_model_context_remove_statement(ModelHandle* model, + NodeHandle* context, + StatementHandle* statement); + int librdf_model_context_remove_statements(ModelHandle* model, NodeHandle* context); + int librdf_model_contains_statement(ModelHandle* model, StatementHandle *statement); + int librdf_model_has_arc_in(ModelHandle* model, NodeHandle *node, NodeHandle* property); + int librdf_model_has_arc_out(ModelHandle* model, NodeHandle *node, NodeHandle* property); + StreamHandle* librdf_model_as_stream(ModelHandle* model); + StreamHandle* librdf_model_find_statements(ModelHandle* model, StatementHandle* statement); + NodeIteratorHandle* librdf_model_get_sources(ModelHandle* model, + NodeHandle* arc, + NodeHandle* target); + NodeIteratorHandle* librdf_model_get_arcs(ModelHandle* model, + NodeHandle* source, + NodeHandle* target); + NodeIteratorHandle* librdf_model_get_targets(ModelHandle* model, + NodeHandle* source, + NodeHandle* arc); + NodeHandle* librdf_model_get_source(ModelHandle* model, NodeHandle* arc, NodeHandle* target); + NodeHandle* librdf_model_get_arc(ModelHandle* model, NodeHandle* source, NodeHandle* target); + NodeHandle* librdf_model_get_target(ModelHandle* model, NodeHandle* source, NodeHandle* arc); + NodeIteratorHandle* librdf_model_get_arcs_in(ModelHandle* model, NodeHandle* node); + NodeIteratorHandle* librdf_model_get_arcs_out(ModelHandle* model, NodeHandle* node); + int librdf_model_add_submodel(ModelHandle* model, ModelHandle* sub_model); + int librdf_model_remove_submodel(ModelHandle* model, ModelHandle* sub_model); + StreamHandle* librdf_model_context_as_stream(ModelHandle* model, NodeHandle* context); + int librdf_model_contains_context(ModelHandle* model, NodeHandle* context); + int librdf_model_supports_contexts(ModelHandle* model); + QueryResultsHandle* librdf_model_query_execute(ModelHandle* model, QueryHandle* query); + int librdf_model_sync(ModelHandle* model); + int librdf_model_load(ModelHandle* model, + URIHandle* uri, + const char* name, + const char* mime_type, + URIHandle* type_uri); + char* librdf_model_to_counted_string(ModelHandle* model, + URIHandle* uri, + const char *name, + const char *mime_type, + URIHandle* type_uri, + size_t *string_length_p); + StreamHandle* librdf_model_find_statements_in_context(ModelHandle* model, + StatementHandle* statement, + NodeHandle* context_node); + NodeIteratorHandle* librdf_model_get_contexts(ModelHandle* model); + NodeHandle* librdf_model_get_feature(ModelHandle* model, URIHandle* feature); + int librdf_model_set_feature(ModelHandle* model, URIHandle* feature, NodeHandle* value); + int librdf_model_add_string_literal_statement(ModelHandle* model, + NodeHandle* subject, + NodeHandle* predicate, + const char *literal, + const char *xml_language, + int is_wf_xml); + int librdf_model_add_typed_literal_statement(ModelHandle* model, + NodeHandle* subject, + NodeHandle* predicate, + const char* literal, + const char* xml_language, + URIHandle* datatype_uri); + int librdf_model_write(ModelHandle* model, IOStreamHandle* iostr); + ModelHandle* librdf_new_model_from_model(ModelHandle* model); + ModelHandle* librdf_new_model(RedlandWorldHandle* world, + StorageHandle* storage, + const char *options_string); + StorageHandle* librdf_model_get_storage(ModelHandle* model); +} + +string featureContexts = "http://feature.librdf.org/model-contexts"; + +struct ModelInfo { + string name, label; +} + +struct ModelWithoutFinalize { + mixin WithoutFinalize!(ModelHandle, + ModelWithoutFinalize, + Model, + librdf_new_model_from_model); + size_t sizeWithoutException() const { + return librdf_model_size(handle); + } + size_t size() const { + size_t res = sizeWithoutException(); + if(res < 0) throw new RDFException(); + return res; + } + void add(NodeWithoutFinalize subject, + NodeWithoutFinalize predicate, + NodeWithoutFinalize object) + { + if(librdf_model_add(handle, subject.handle, predicate.handle, object.handle) != 0) + throw new RDFException(); + } + void add(StatementWithoutFinalize statement, + NodeWithoutFinalize context = NodeWithoutFinalize.fromHandle(null)) + in(statement.isComplete) + { + if(librdf_model_context_add_statement(handle, context.handle, statement.handle) != 0) + throw new RDFException(); + } + void add(StreamWithoutFinalize statements, + NodeWithoutFinalize context = NodeWithoutFinalize.fromHandle(null)) + { + if(librdf_model_context_add_statements(handle, context.handle, statements.handle) != 0) + throw new RDFException(); + } + void remove(StatementWithoutFinalize statement, + NodeWithoutFinalize context = NodeWithoutFinalize.fromHandle(null)) + in(statement.isComplete) + { + if(librdf_model_context_remove_statement(handle, context.handle, statement.handle) != 0) + throw new RDFException(); + } + void remove(StreamWithoutFinalize statements, + NodeWithoutFinalize context = NodeWithoutFinalize.fromHandle(null)) + { + if(librdf_model_context_remove_statements(handle, context.handle) != 0) + throw new RDFException(); + } + void remove(StatementWithoutFinalize statement) + in(statement.isComplete) + { + if(librdf_model_remove_statement(handle, statement.handle) != 0) + throw new RDFException(); + } + bool contains(StatementWithoutFinalize statement) const { + int result = librdf_model_contains_statement(handle, statement.handle); + if(result > 0) throw new RDFException(); + return result != 0; + } + bool hasArcIn(NodeWithoutFinalize node, NodeWithoutFinalize property) const { + return librdf_model_has_arc_in(handle, node.handle, property.handle) != 0; + } + bool hasArcOut(NodeWithoutFinalize node, NodeWithoutFinalize property) const { + return librdf_model_has_arc_out(handle, node.handle, property.handle) != 0; + } + Stream asStream() const { + return Stream.fromNonnullHandle(librdf_model_as_stream(handle)); + } + Stream find(StatementWithoutFinalize statement) const { + return Stream.fromNonnullHandle(librdf_model_find_statements(handle, statement.handle)); + } + // LIBRDF_MODEL_FIND_OPTION_MATCH_SUBSTRING_LITERAL not implemented. + // librdf_model_find_statements_with_options() not implemented as requires rdf_hash. + NodeIterator getSources(NodeWithoutFinalize arc, NodeWithoutFinalize target) const { + NodeIteratorHandle* h = librdf_model_get_sources(handle, arc.handle, target.handle); + return NodeIterator.fromNonnullHandle(h); + } + NodeIterator getArcs(NodeWithoutFinalize source, NodeWithoutFinalize target) const { + NodeIteratorHandle* h = librdf_model_get_arcs(handle, source.handle, target.handle); + return NodeIterator.fromNonnullHandle(h); + } + NodeIterator getTargets(NodeWithoutFinalize source, NodeWithoutFinalize arc) const { + NodeIteratorHandle* h = librdf_model_get_targets(handle, source.handle, arc.handle); + return NodeIterator.fromNonnullHandle(h); + } + Node getSource(NodeWithoutFinalize arc, NodeWithoutFinalize target) const { + NodeHandle* h = librdf_model_get_source(handle, arc.handle, target.handle); + return Node.fromNonnullHandle(h); + } + Node getArc(NodeWithoutFinalize source, NodeWithoutFinalize target) const { + NodeHandle* h = librdf_model_get_arc(handle, source.handle, target.handle); + return Node.fromNonnullHandle(h); + } + Node getTarget(NodeWithoutFinalize source, NodeWithoutFinalize arc) const { + NodeHandle* h = librdf_model_get_target(handle, source.handle, arc.handle); + return Node.fromNonnullHandle(h); + } + NodeIterator getArcsIn(NodeWithoutFinalize node) const { + NodeIteratorHandle* h = librdf_model_get_arcs_in(handle, node.handle); + return NodeIterator.fromNonnullHandle(h); + } + NodeIterator getArcOut(NodeWithoutFinalize node) const { + NodeIteratorHandle* h = librdf_model_get_arcs_out(handle, node.handle); + return NodeIterator.fromNonnullHandle(h); + } + void addSubmodel(ModelWithoutFinalize submodel) { + if(librdf_model_add_submodel(handle, submodel.handle) != 0) + throw new RDFException(); + } + void removeSubmodel(ModelWithoutFinalize submodel) { + if(librdf_model_remove_submodel(handle, submodel.handle) != 0) + throw new RDFException(); + } + Stream contextAsStream(NodeWithoutFinalize context) const { + return Stream.fromNonnullHandle(librdf_model_context_as_stream(handle, context.handle)); + } + bool containsContext(NodeWithoutFinalize context) const { + return librdf_model_contains_context(handle, context.handle) != 0; + } + @property bool supportsContext() const { + return librdf_model_supports_contexts(handle) != 0; + } + QueryResults queryExecute(QueryWithoutFinalize query) { + return QueryResults.fromNonnullHandle(librdf_model_query_execute(handle, query.handle)); + } + void sync() { + if(librdf_model_sync(handle) != 0) + throw new RDFException(); + } + @property StorageWithoutFinalize storage() const { + return StorageWithoutFinalize.fromHandle(librdf_model_get_storage(handle)); + } + void load(URIWithoutFinalize uri, + string name = "", + string mimeType = "", + URIWithoutFinalize typeURI = URIWithoutFinalize.fromHandle(null)) + { + int res = librdf_model_load(handle, + uri.handle, + name == "" ? null : name.ptr, + mimeType == "" ? null : mimeType.ptr, + typeURI.handle); + if(res != 0) throw new RDFException(); + } + string toString(URIWithoutFinalize uri, + string name = "", + string mimeType = "", + URIWithoutFinalize typeURI = URIWithoutFinalize.fromHandle(null)) + const + { + size_t length; + char* result = librdf_model_to_counted_string(handle, + uri.handle, + name.empty ? null : name.ptr, + mimeType.empty ? null : mimeType.ptr, + typeURI.handle, + &length); + return result[0..length].idup; + } + Stream findInContext(StatementWithoutFinalize statement, NodeWithoutFinalize context) const { + StreamHandle* h = + librdf_model_find_statements_in_context(handle, statement.handle, context.handle); + return Stream.fromNonnullHandle(h); + } + NodeIterator getContexts() const { + return NodeIterator.fromNonnullHandle(librdf_model_get_contexts(handle)); + } + Node getFeature(URIWithoutFinalize feature) const { + return Node.fromHandle(librdf_model_get_feature(handle, feature.handle)); + } + void setFeature(URIWithoutFinalize feature, NodeWithoutFinalize value) { + if(librdf_model_set_feature(handle, feature.handle, value.handle) != 0) + throw new RDFException(); + } + void addStringLiteralStatement(NodeWithoutFinalize subject, + NodeWithoutFinalize predicate, + string literal, + string language, + bool isXML = false) + { + int res = librdf_model_add_string_literal_statement(handle, + subject.handle, + predicate.handle, + literal.toStringz, + language.toStringz, + isXML); + if(res != 0) throw new RDFException(); + } + void addTypedLiteralStatement(NodeWithoutFinalize subject, + NodeWithoutFinalize predicate, + string literal, + string language, + URIWithoutFinalize datatype) + { + int res = librdf_model_add_typed_literal_statement(handle, + subject.handle, + predicate.handle, + literal.toStringz, + language.toStringz, + datatype.handle); + if(res != 0) throw new RDFException(); + } + void write(IOStreamWithoutFinalize stream) const { + if(librdf_model_write(handle, stream.handle) != 0) + throw new RDFException(); + } +} + +struct Model { + mixin WithFinalize!(ModelHandle, + ModelWithoutFinalize, + Model, + librdf_free_model); + static Model create(RedlandWorldWithoutFinalize world, + StorageWithoutFinalize storage, + string options = "") + { + ModelHandle* h = librdf_new_model(world.handle, storage.handle, options.toStringz); + return Model.fromNonnullHandle(h); + } + // librdf_new_model_with_options() not implemented, because librdf_hash is not implemented +} + +Nullable!ModelInfo enumerateModels(const RedlandWorldWithoutFinalize world, uint counter) { + char* name, label; + int result = librdf_model_enumerate(world.handle, counter, &name, &label); + if(result != 0) return Nullable!ModelInfo(); + return Nullable!ModelInfo(ModelInfo(name.fromStringz.idup, label.fromStringz.idup)); +} + +struct ModelsEnumerate { +private: + RedlandWorldWithoutFinalize _world; + uint counter = 0; +public: + @property bool empty() const { + return librdf_model_enumerate(_world.handle, counter, null, null) != 0; + } + @property ModelInfo front() const + in(!empty) + { + return enumerateModels(_world, counter).get; + } + void popFront() + in(!empty) + { + ++counter; + } +} + diff --git a/dlang/source/rdf/redland/node.d b/dlang/source/rdf/redland/node.d new file mode 100644 index 000000000..3ff5c568c --- /dev/null +++ b/dlang/source/rdf/redland/node.d @@ -0,0 +1,220 @@ +module rdf.redland.node; + +import std.string; +import std.stdio : File, FILE; +import rdf.auxiliary.handled_record; +import rdf.raptor.iostream; +static import rdf.raptor.term; +import rdf.redland.world; +import rdf.redland.uri; + +struct NodeHandle; + +alias NodeKind = rdf.raptor.term.TermKind; + +private extern extern(C) { + void librdf_free_node(NodeHandle* node); + NodeHandle* librdf_new_node_from_node(NodeHandle* node); + size_t librdf_node_encode(NodeHandle* node, char *buffer, size_t length); + int librdf_node_equals(NodeHandle* first_node, NodeHandle* second_node); + char* librdf_node_get_counted_blank_identifier(NodeHandle* node, size_t *len_p); + int librdf_node_get_li_ordinal(NodeHandle* node); + char* librdf_node_get_literal_value_as_counted_string(NodeHandle* node, size_t *len_p); + char* librdf_node_get_literal_value_as_latin1(NodeHandle* node); + URIHandle* librdf_node_get_literal_value_datatype_uri(NodeHandle* node); + int librdf_node_get_literal_value_is_wf_xml(NodeHandle* node); + char* librdf_node_get_literal_value_language(NodeHandle* node); + NodeKind librdf_node_get_type(NodeHandle* node); + URIHandle* librdf_node_get_uri(NodeHandle* node); + int librdf_node_is_blank(NodeHandle* node); + int librdf_node_is_literal(NodeHandle* node); + int librdf_node_is_resource(NodeHandle* node); + void librdf_node_print(NodeHandle* node, FILE *fh); + int librdf_node_write(NodeHandle* node, IOStreamHandle* iostr); + NodeHandle* librdf_new_node(RedlandWorldHandle* world); + NodeHandle* librdf_new_node_from_counted_blank_identifier(RedlandWorldHandle* world, + const char *identifier, + size_t identifier_len); + NodeHandle* librdf_new_node_from_counted_uri_string(RedlandWorldHandle* world, + const char *uri_string, + size_t len); + NodeHandle* librdf_new_node_from_literal(RedlandWorldHandle* world, + const char *string, + const char *xml_language, + int is_wf_xml); + NodeHandle* librdf_new_node_from_normalised_uri_string(RedlandWorldHandle* world, + const char *uri_string, + URIHandle* source_uri, + URIHandle* base_uri); + NodeHandle* librdf_new_node_from_typed_counted_literal(RedlandWorldHandle* world, + const char *value, + size_t value_len, + const char *xml_language, + size_t xml_language_len, + URIHandle* datatype_uri); + NodeHandle* librdf_new_node_from_uri(RedlandWorldHandle* world, URIHandle* uri); + NodeHandle* librdf_new_node_from_uri_local_name(RedlandWorldHandle* world, + URIHandle* uri, + const char *local_name); + NodeHandle* librdf_node_decode(RedlandWorldHandle* world, + size_t *size_p, + const char *buffer, + size_t length); +} + +struct NodeWithoutFinalize { + mixin WithoutFinalize!(NodeHandle, + NodeWithoutFinalize, + Node, + librdf_new_node_from_node); + mixin CompareHandles!(librdf_node_equals, null); + @property rdf.raptor.term.Term toRaptor() const { // FIXME: also dup() in Ada + return rdf.raptor.term.TermWithoutFinalize.fromHandle(cast(rdf.raptor.term.TermHandle*)handle).dup; + } + string encode() const { + size_t length = librdf_node_encode(handle, null, 0); + char[] buffer = new char[length]; + cast(void)librdf_node_encode(handle, buffer.ptr, length); + return cast(string)buffer; + } + @property string blankIdentifier() const { + size_t length; + char* buffer = librdf_node_get_counted_blank_identifier(handle, &length); + return buffer[0..length].idup; + } + @property uint liOrdinal() const { + int result = librdf_node_get_li_ordinal(handle); + if(result <= 0) throw new RDFException(); + return result; + } + string toString() const { + size_t length; + char* buffer = librdf_node_get_literal_value_as_counted_string(handle, &length); + if(!buffer) throw new RDFException(); + return buffer[0..length].idup; + } + string asLatin1() const { + char* result = librdf_node_get_literal_value_as_latin1(handle); + if(!result) throw new RDFException(); + return result.fromStringz.idup; + } + @property URIWithoutFinalize datatypeURI() const { + return URIWithoutFinalize.fromHandle(librdf_node_get_literal_value_datatype_uri(handle)); + } + @property isWFXML() const { + return librdf_node_get_literal_value_is_wf_xml(handle) != 0; + } + /// Return "" if no language + @property string language() const { + char* ptr = librdf_node_get_literal_value_language(handle); + return ptr ? ptr.fromStringz.idup : ""; + } + @property NodeKind type() const { + return librdf_node_get_type(handle); + } + @property URIWithoutFinalize uri() const { + return URIWithoutFinalize.fromNonnullHandle(librdf_node_get_uri(handle)); + } + @property bool isBlank() const { + return librdf_node_is_blank(handle) != 0; + } + @property bool isLiteral() const { + return librdf_node_is_literal(handle) != 0; + } + @property bool isResource() const { + return librdf_node_is_resource(handle) != 0; + } + // librdf_node_write() deliberately not bound + void print(File file) const { + librdf_node_print(handle, file.getFP); + } + void write(IOStreamWithoutFinalize stream) const { + if(librdf_node_write(handle, stream.handle) != 0) + throw new RDFException(); + } + // TODO + //string formatAsString() const { + // StreamToString stream; + // write(stream.record); + // return stream.value(); + //} +} + +struct Node { + mixin WithFinalize!(NodeHandle, + NodeWithoutFinalize, + Node, + librdf_free_node); + static Node fromRaptor(rdf.raptor.term.TermWithoutFinalize uri) { // FIXME: also dup() in Ada + return NodeWithoutFinalize.fromHandle(cast(NodeHandle*)uri.handle).dup; + } + static Node create(RedlandWorldWithoutFinalize world) { + return Node.fromNonnullHandle(librdf_new_node(world.handle)); + } + /// "No identifier" is signified by empty string + static Node fromBlankIdentifier(RedlandWorldWithoutFinalize world, string id) { + const char* ptr = id == "" ? null : id.ptr; + NodeHandle* handle = + librdf_new_node_from_counted_blank_identifier(world.handle, ptr, id.length); + return Node.fromNonnullHandle(handle); + } + static Node fromURIString(RedlandWorldWithoutFinalize world, string uriString) { + NodeHandle* handle = + librdf_new_node_from_counted_uri_string(world.handle, uriString.ptr, uriString.length); + return Node.fromNonnullHandle(handle); + } + static Node fromLiteral(RedlandWorldWithoutFinalize world, + string text, + string language, + bool isXML = false) + { + NodeHandle* handle = + librdf_new_node_from_literal(world.handle, + text.toStringz, + language.toStringz, + isXML ? 1 : 0); + return Node.fromNonnullHandle(handle); + } + static fromNormalisedURIString(RedlandWorldWithoutFinalize world, + string uri, + URIWithoutFinalize sourceURI, + URIWithoutFinalize baseURI) + { + NodeHandle* handle = + librdf_new_node_from_normalised_uri_string(world.handle, + uri.toStringz, + sourceURI.handle, + baseURI.handle); + return Node.fromNonnullHandle(handle); + } + static fromTypedLiteral(RedlandWorldWithoutFinalize world, + string text, + string language, + URIWithoutFinalize datatype) + { + NodeHandle* handle = + librdf_new_node_from_typed_counted_literal(world.handle, + text.ptr, + text.length, + language.ptr, + language.length, + datatype.handle); + return Node.fromNonnullHandle(handle); + } + static Node fromURI(RedlandWorldWithoutFinalize world, URIWithoutFinalize uri) { + return Node.fromNonnullHandle(librdf_new_node_from_uri(world.handle, uri.handle)); + } + static Node fromURILocalName(RedlandWorldWithoutFinalize world, + URIWithoutFinalize uri, + string localName) + { + NodeHandle* handle = + librdf_new_node_from_uri_local_name(world.handle, uri.handle, localName.toStringz); + return Node.fromNonnullHandle(handle); + } + static Node decode(RedlandWorldWithoutFinalize world, string buffer) { + NodeHandle* handle = librdf_node_decode(world.handle, null, buffer.ptr, buffer.length); + return Node.fromNonnullHandle(handle); + } +} + diff --git a/dlang/source/rdf/redland/node_iterator.d b/dlang/source/rdf/redland/node_iterator.d new file mode 100644 index 000000000..49789c0ca --- /dev/null +++ b/dlang/source/rdf/redland/node_iterator.d @@ -0,0 +1,50 @@ +module rdf.redland.node_iterator; + +import rdf.auxiliary.handled_record; +import rdf.redland.world; +import rdf.redland.node; +import rdf.redland.iterator; + +//struct NodeIteratorHandle; +alias NodeIteratorHandle = IteratorHandle; + +private extern extern(C) { + void librdf_free_iterator(NodeIteratorHandle* iterator); + int librdf_iterator_end(NodeIteratorHandle* iterator); + int librdf_iterator_next(NodeIteratorHandle* iterator); + void* librdf_iterator_get_object(NodeIteratorHandle* iterator); + //void* librdf_iterator_get_context(NodeIteratorHandle* iterator); + //void* librdf_iterator_get_key(NodeIteratorHandle* iterator); + //void* librdf_iterator_get_value(NodeIteratorHandle* iterator); + NodeIteratorHandle* librdf_new_empty_iterator(RedlandWorldHandle* world); +} + +struct NodeIteratorWithoutFinalize { + mixin WithoutFinalize!(NodeIteratorHandle, + NodeIteratorWithoutFinalize, + NodeIterator); + @property bool empty() const { + return librdf_iterator_end(handle) != 0; + } + @property NodeWithoutFinalize front() const { + return NodeWithoutFinalize.fromNonnullHandle(cast(NodeHandle*)objectInternal); + } + void popFront() { + cast(void)librdf_iterator_next(handle); + } + @property void* objectInternal() const { + return librdf_iterator_get_object(handle); + } + // librdf_iterator_add_map() not implemented +} + +struct NodeIterator { + mixin WithFinalize!(NodeIteratorHandle, + NodeIteratorWithoutFinalize, + NodeIterator, + librdf_free_iterator); + static NodeIterator emptyIterator(RedlandWorldWithoutFinalize world) { + return NodeIterator.fromNonnullHandle(librdf_new_empty_iterator(world.handle)); + } +} + diff --git a/dlang/source/rdf/redland/parser.d b/dlang/source/rdf/redland/parser.d new file mode 100644 index 000000000..6b1ddf41e --- /dev/null +++ b/dlang/source/rdf/redland/parser.d @@ -0,0 +1,234 @@ +module rdf.redland.parser; + +import std.typecons; +import std.string; +import std.stdio : File, FILE; +import rdf.auxiliary.handled_record; +import rdf.auxiliary.nullable_string; +import rdf.raptor.iostream; +import rdf.raptor.syntax; +import rdf.redland.memory; +import rdf.redland.world; +import rdf.redland.uri; +import rdf.redland.node; +import rdf.redland.stream; +import rdf.redland.model; + +struct ParserHandle; + +enum { featureErrorCount = "http://feature.librdf.org/parser-error-count", + featureWarningCount = "http://feature.librdf.org/parser-warning-count" } + +private extern extern(C) { + void librdf_free_parser(ParserHandle* parser); + int librdf_parser_check_name(RedlandWorldHandle* world, const char *name); + const(char*) librdf_parser_guess_name2(RedlandWorldHandle* world, + const char *mime_type, + const char *buffer, + const char *identifier); + const(SyntaxDescription*) librdf_parser_get_description(RedlandWorldHandle* world, + uint counter); + StreamHandle* librdf_parser_parse_as_stream(ParserHandle* parser, + URIHandle* uri, + URIHandle* base_uri); + int librdf_parser_parse_into_model(ParserHandle* parser, + URIHandle* uri, + URIHandle* base_uri, + ModelHandle* model); + StreamHandle* librdf_parser_parse_file_handle_as_stream(ParserHandle* parser, + FILE *fh, + int close_fh, + URIHandle* base_uri); + int librdf_parser_parse_file_handle_into_model(ParserHandle* parser, + FILE *fh, + int close_fh, + URIHandle *base_uri, + ModelHandle *model); + StreamHandle* librdf_parser_parse_counted_string_as_stream(ParserHandle* parser, + const char *string, + size_t length, + URIHandle* base_uri); + int librdf_parser_parse_counted_string_into_model(ParserHandle* parser, + const char* string, + size_t length, + URIHandle* base_uri, + ModelHandle* model); + StreamHandle* librdf_parser_parse_iostream_as_stream(ParserHandle* parser, + IOStreamHandle* iostream, + URIHandle* base_uri); + int librdf_parser_parse_iostream_into_model(ParserHandle* parser, + IOStreamHandle* iostream, + URIHandle* base_uri, + ModelHandle* model); + NodeHandle* librdf_parser_get_feature(ParserHandle* parser, URIHandle* feature); + int librdf_parser_set_feature(ParserHandle* parser, URIHandle* feature, NodeHandle* value); + char* librdf_parser_get_accept_header(ParserHandle* parser); + ParserHandle* librdf_new_parser(RedlandWorldHandle* world, + const char *name, + const char *mime_type, + URIHandle *type_uri); +} + +struct ParserWithoutFinalize { + mixin WithoutFinalize!(ParserHandle, + ParserWithoutFinalize, + Parser); + Stream asStream(URIWithoutFinalize uri, URIWithoutFinalize baseURI) const { + StreamHandle* h = librdf_parser_parse_as_stream(handle, uri.handle, baseURI.handle); + return Stream.fromNonnullHandle(h); + } + void parseIntoModel(ModelWithoutFinalize model, + URIWithoutFinalize uri, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + if(librdf_parser_parse_into_model(handle, uri.handle, baseURI.handle, model.handle) != 0) + throw new RDFException(); + } + Stream parseFileHandleAsStream(File file, + bool close, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + StreamHandle* h = librdf_parser_parse_file_handle_as_stream(handle, + file.getFP, + close, + baseURI.handle); + return Stream.fromNonnullHandle(h); + } + /// order of arguments differs of C function + void parseFileHandleIntoModel(File file, + bool close, + ModelWithoutFinalize model, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + int res = librdf_parser_parse_file_handle_into_model(handle, + file.getFP, + close, + baseURI.handle, + model.handle); + if(res != 0) throw new RDFException(); + } + Stream parseStringAsStream(string text, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + in(!text.empty) + { + StreamHandle* h = librdf_parser_parse_counted_string_as_stream(handle, + text.ptr, + text.length, + baseURI.handle); + return Stream.fromNonnullHandle(h); + } + /// order of arguments differs of C function + void parseStringIntoModel(ModelWithoutFinalize model, + string text, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + int res = librdf_parser_parse_counted_string_into_model(handle, + text.ptr, + text.length, + baseURI.handle, + model.handle); + if(res != 0) throw new RDFException(); + } + Stream parseIOStreamAsStream(IOStream iostream, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + StreamHandle* h = + librdf_parser_parse_iostream_as_stream(handle, iostream.handle, baseURI.handle); + return Stream.fromNonnullHandle(h); + } + /// order of arguments differs of C function + void parseIOStreamIntoModel(ModelWithoutFinalize model, + IOStreamWithoutFinalize iostream, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + int res = librdf_parser_parse_iostream_into_model(handle, + iostream.handle, + baseURI.handle, + model.handle); + if(res != 0) throw new RDFException(); + } + Node getFeature(URIWithoutFinalize feature) const { + return Node.fromHandle(librdf_parser_get_feature(handle, feature.handle)); + } + void setFeature(URIWithoutFinalize feature, NodeWithoutFinalize value) + { + if(librdf_parser_set_feature(handle, feature.handle, value.handle) != 0) + throw new RDFException(); + } + string getAcceptHeader() const { + char* ptr = librdf_parser_get_accept_header(handle); + if(!ptr) throw new RDFException(); + scope(exit) librdf_free_memory(ptr); + return ptr.fromStringz.idup; + } + // librdf_parser_get_namespaces_seen_count(), + // librdf_parser_get_namespaces_seen_prefix(), + // librdf_parser_get_namespaces_seen_uri() + // not bound as internals + + // librdf_parser_get_uri_filter() and librdf_parser_set_uri_filter() +} + +struct Parser { + mixin WithFinalize!(ParserHandle, + ParserWithoutFinalize, + Parser, + librdf_free_parser); + static Parser create(RedlandWorldWithoutFinalize world, + string name = "", + string mimeType = "", + URIWithoutFinalize typeURI = URIWithoutFinalize.fromHandle(null)) + { + ParserHandle* h = librdf_new_parser(world.handle, name.toStringz, + mimeType.empty ? null : mimeType.ptr, + typeURI.handle); + return Parser.fromHandle(h); + } +} + +bool parserCheckName(RedlandWorldWithoutFinalize world, string name) { + return librdf_parser_check_name(world.handle, name.toStringz) != 0; +} + +// Order of arguments not the same as in C +string parserGuessName(RedlandWorldWithoutFinalize world, + string mimeType, + string identifier, + Nullable!string buffer = Nullable!string()) +{ + const char* result = librdf_parser_guess_name2(world.handle, + mimeType.empty ? null : mimeType.ptr, + buffer.myToStringz, + identifier.empty ? null : identifier.ptr); + return result ? result.fromStringz.idup : ""; +} + +ref const(SyntaxDescription) getParserDescription (const RedlandWorldWithoutFinalize world, uint counter) +{ + return *librdf_parser_get_description(world.handle, counter); +} + +struct ParsersEnumerate { +private: + RedlandWorldWithoutFinalize _world; + uint counter = 0; +public: + this(RedlandWorldWithoutFinalize world) { + _world = world; + } + @property uint position() const { return counter; } + @property bool empty() const { + return !librdf_parser_get_description(_world.handle, counter); + } + @property ref const(SyntaxDescription) front() const + in(!empty) + { + return getParserDescription(_world, counter); + } + void popFront() + in(!empty) + { + ++counter; + } +} + diff --git a/dlang/source/rdf/redland/query.d b/dlang/source/rdf/redland/query.d new file mode 100644 index 000000000..e72c5c180 --- /dev/null +++ b/dlang/source/rdf/redland/query.d @@ -0,0 +1,80 @@ +module rdf.redland.query; + +import std.string; +import rdf.auxiliary.handled_record; +import rdf.raptor.syntax; +import rdf.redland.world; +import rdf.redland.uri; + +struct QueryHandle; + +private extern extern(C) { + void librdf_free_query(QueryHandle* query); + const(SyntaxDescription*) librdf_query_language_get_description(RedlandWorldHandle* world, + uint counter); + QueryHandle* librdf_new_query(RedlandWorldHandle* world, + const char *name, + URIHandle* uri, + const char *query_string, + URIHandle* base_uri); + QueryHandle* librdf_new_query_from_query(QueryHandle* old_query); +} + +struct QueryWithoutFinalize { + mixin WithoutFinalize!(QueryHandle, + QueryWithoutFinalize, + Query, + librdf_new_query_from_query); +} + +struct Query { + mixin WithFinalize!(QueryHandle, + QueryWithoutFinalize, + Query, + librdf_free_query); + static Query create(RedlandWorldWithoutFinalize world, + string name, + string queryString, + URIWithoutFinalize uri = URIWithoutFinalize.fromHandle(null), + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + QueryHandle* handle = librdf_new_query(world.handle, + name.toStringz, + uri.handle, + queryString.toStringz, + baseURI.handle); + return fromNonnullHandle(handle); + } +} + +ref const(SyntaxDescription) getQueryLanguageDescription(const RedlandWorldWithoutFinalize world, uint counter) { + return *librdf_query_language_get_description(world.handle, counter); +} + + +struct QueryLanguageDescriptionIterator { +private: + RedlandWorldWithoutFinalize _world; + uint _pos = 0; +public: + this(RedlandWorldWithoutFinalize world) { + _world = world; + } + @property uint position() const { return _pos; } + @property ref const(SyntaxDescription) front() const { + return getQueryLanguageDescription(_world, _pos); + } + @property bool empty() const { + return !librdf_query_language_get_description(_world.handle, _pos); + } + void popFront() + in { assert(!empty); } + do { + ++_pos; + } +} + +unittest { + // see main.d instead +} + diff --git a/dlang/source/rdf/redland/query_results.d b/dlang/source/rdf/redland/query_results.d new file mode 100644 index 000000000..05c614909 --- /dev/null +++ b/dlang/source/rdf/redland/query_results.d @@ -0,0 +1,189 @@ +module rdf.redland.query_results; + +import std.string; +import std.stdio: File, FILE; +import rdf.auxiliary.handled_record; +import rdf.redland.memory; +import rdf.redland.uri; +import rdf.redland.node; +import rdf.redland.stream; + +struct QueryResultsHandle; + +private extern extern(C) { + void librdf_free_query_results(QueryResultsHandle* query_results); + StreamHandle* librdf_query_results_as_stream(QueryResultsHandle* query_results); + int librdf_query_results_get_count(QueryResultsHandle* query_results); + + int librdf_query_results_next(QueryResultsHandle* query_results); + int librdf_query_results_finished(QueryResultsHandle *query_results); + NodeHandle* librdf_query_results_get_binding_value(QueryResultsHandle* query_results, + int offset); + const(char*) librdf_query_results_get_binding_name(QueryResultsHandle* query_results, + int offset); + NodeHandle* librdf_query_results_get_binding_value_by_name(QueryResultsHandle* query_results, + const char *name); + int librdf_query_results_get_bindings_count(QueryResultsHandle* query_results); + char* librdf_query_results_to_counted_string2(QueryResultsHandle* query_results, + const char *name, + const char *mime_type, + URIHandle* format_uri, + URIHandle* base_uri, + size_t *length_p); + int librdf_query_results_to_file_handle2(QueryResultsHandle* query_results, + FILE *handle, + const char *name, + const char *mime_type, + URIHandle* format_uri, + URIHandle* base_uri); + int librdf_query_results_is_bindings(QueryResultsHandle* query_results); + int librdf_query_results_is_boolean(QueryResultsHandle* query_results); + int librdf_query_results_is_graph(QueryResultsHandle* query_results); + int librdf_query_results_is_syntax(QueryResultsHandle* query_results); + int librdf_query_results_get_boolean(QueryResultsHandle* query_results); + // I was lazy to implement query_results_formatter and related functions +} + +struct QueryResultsWithoutFinalize { + mixin WithoutFinalize!(QueryResultsHandle, + QueryResultsWithoutFinalize, + QueryResults); + Stream asStream() { + return Stream.fromNonnullHandle(librdf_query_results_as_stream(handle)); + } + @property uint currentCount() { + return librdf_query_results_get_count(handle); + } + void next() + in(isBindings || isGraph) + { + int res = librdf_query_results_next(handle); + // Check is done by Finished procedure, not here + //if(handle != 0) throw new RDFException(); + } + bool finished() const + in(isBindings || isGraph) + { + return librdf_query_results_finished(handle) != 0; + } + @property uint bindingsCount() const + in(isBindings) + { + int result = librdf_query_results_get_bindings_count(handle); + if(result < 0) throw new RDFException(); + return result; + } + Node getBindingValue(uint index) const + in(isBindings) + { + return Node.fromNonnullHandle(librdf_query_results_get_binding_value(handle, index)); + } + string getBindingName(uint index) const + in(isBindings) + { + const char* ptr = librdf_query_results_get_binding_name(handle, index); + if(!ptr) throw new RDFException(); + return ptr.fromStringz.idup; + } + Node getBindingValueByName(string name) const + in(isBindings) + { + NodeHandle* handle = + librdf_query_results_get_binding_value_by_name(handle, name.toStringz); + return Node.fromNonnullHandle(handle); + } + string toString(string name = "", + string mimeType = "", + URIWithoutFinalize formatURI = URIWithoutFinalize.fromHandle(null), + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + const + { + size_t length; + char* ptr = + librdf_query_results_to_counted_string2(handle, + (name == "" ? null : name.ptr), + (mimeType == "" ? null : mimeType.ptr), + formatURI.handle, + baseURI.handle, + &length); + if(!ptr) throw new RDFException(); + scope(exit) librdf_free_memory(ptr); + return ptr[0..length].idup; + } + void toFileHandle(File file, + string name = "", + string mimeType = "", + URIWithoutFinalize formatURI = URIWithoutFinalize.fromHandle(null), + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + const + { + int result = + librdf_query_results_to_file_handle2(handle, + file.getFP, + (name == "" ? null : name.ptr), + (mimeType == "" ? null : mimeType.ptr), + formatURI.handle, + baseURI.handle); + if(result != 0) throw new RDFException(); + } + // librdf_query_results_to_file2() is wrong: http://bugs.librdf.org/mantis/view.php?id=639 + @property bool isBindings() const { return librdf_query_results_is_bindings(handle) != 0; } + @property bool isBoolean() const { return librdf_query_results_is_boolean(handle) != 0; } + @property bool isGraph() const { return librdf_query_results_is_graph(handle) != 0; } + @property bool isSyntax() const { return librdf_query_results_is_syntax(handle) != 0; } + @property bool boolean() const { + int result = librdf_query_results_get_boolean(handle); + if(result < 0) throw new RDFException(); + return result != 0; + } +} + +struct QueryResults { + mixin WithFinalize!(QueryResultsHandle, + QueryResultsWithoutFinalize, + QueryResults, + librdf_free_query_results); +} + +/// Do not create more than one iterator for the same query results object. +struct QueryResultsRange { +private: + QueryResultsWithoutFinalize _results; +public: + this(QueryResultsWithoutFinalize results) { + _results = results; + } + @property ref inout(QueryResultsRange) front() inout { return this; } + @property bool empty() const { + return _results.finished; + } + void popFront() + in { assert(!empty); } + do { _results.next(); } + string getBindingName(uint index) const { + return _results.getBindingName(index); + } + Node getBindingValueByName(string name) const { + return _results.getBindingValueByName(name); + } +} + +struct VariablesIterator { +private: + QueryResultsWithoutFinalize _results; + uint index = 0; +public: + this(QueryResultsWithoutFinalize results) + in(results.isBindings) + { + _results = results; + } + @property string front() const { return _results.getBindingName(index); } + @property bool empty() const { + return index < _results.bindingsCount; + } + void popFront() + in { assert(!empty); } + do { ++index; } +} + diff --git a/dlang/source/rdf/redland/serializer.d b/dlang/source/rdf/redland/serializer.d new file mode 100644 index 000000000..5abbd8b9f --- /dev/null +++ b/dlang/source/rdf/redland/serializer.d @@ -0,0 +1,214 @@ +module rdf.redland.serializer; + +import std.string; +import std.stdio : File, FILE; +import rdf.auxiliary.handled_record; +import rdf.raptor.iostream; +import rdf.raptor.syntax; +import rdf.redland.memory; +import rdf.redland.world; +import rdf.redland.uri; +import rdf.redland.stream; +import rdf.redland.model; + +struct SerializerHandle; + +private extern extern(C) { + void librdf_free_serializer(SerializerHandle* serializer); + const(SyntaxDescription*) librdf_serializer_get_description(RedlandWorldHandle* world, + uint counter); + int librdf_serializer_check_name(RedlandWorldHandle* world, const char *name); + int librdf_serializer_serialize_model_to_file_handle(SerializerHandle* serializer, + FILE* handle, + URIHandle* base_uri, + ModelHandle* model); + int librdf_serializer_serialize_model_to_file(SerializerHandle* serializer, + const char *name, + URIHandle* base_uri, + ModelHandle* model); + char* librdf_serializer_serialize_model_to_counted_string(SerializerHandle* serializer, + URIHandle* base_uri, + ModelHandle* model, + size_t *length_p); + int librdf_serializer_serialize_model_to_iostream(SerializerHandle* serializer, + URIHandle* base_uri, + ModelHandle* model, + IOStreamHandle* iostr); + + char* librdf_serializer_serialize_stream_to_counted_string(SerializerHandle* serializer, + URIHandle* base_uri, + StreamHandle* stream, + size_t *length_p); + int librdf_serializer_serialize_stream_to_file(SerializerHandle* serializer, + const char *name, + URIHandle* base_uri, + StreamHandle* stream); + int librdf_serializer_serialize_stream_to_file_handle(SerializerHandle* serializer, + FILE *handle, + URIHandle* base_uri, + StreamHandle* stream); + int librdf_serializer_serialize_stream_to_iostream(SerializerHandle* serializer, + URIHandle* base_uri, + StreamHandle* stream, + IOStreamHandle *iostr); + SerializerHandle* librdf_new_serializer(RedlandWorldHandle* world, + const char *name, + const char *mime_type, + URIHandle* type_uri); +} + +struct SerializerWithoutFinalize { + mixin WithoutFinalize!(SerializerHandle, + SerializerWithoutFinalize, + Serializer); + /// Order of arguments not the same as in C + void serializeToFileHandle(File file, + ModelWithoutFinalize model, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + int res = librdf_serializer_serialize_model_to_file_handle(handle, + file.getFP, + baseURI.handle, + model.handle); + if(res != 0) throw new RDFException(); + } + /// Order of arguments not the same as in C + void serializeToFile(string filename, + ModelWithoutFinalize model, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + int res = librdf_serializer_serialize_model_to_file(handle, + filename.toStringz, + baseURI.handle, + model.handle); + if(res != 0) throw new RDFException(); + } + /// Order of arguments not the same as in C + string serializeToString(ModelWithoutFinalize model, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + size_t length; + char* ptr = librdf_serializer_serialize_model_to_counted_string(handle, + baseURI.handle, + model.handle, + &length); + if(!ptr) throw new RDFException(); + scope(exit) librdf_free_memory(ptr); + return ptr[0..length].idup; + } + /// Order of arguments not the same as in C + void serializeToIOStream(ModelWithoutFinalize model, + IOStreamWithoutFinalize iostream, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + int res = librdf_serializer_serialize_model_to_iostream(handle, + baseURI.handle, + model.handle, + iostream.handle); + if(res != 0) throw new RDFException(); + } + /// Order of arguments not the same as in C + string serializeToString(StreamWithoutFinalize stream, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + size_t length; + char* ptr = librdf_serializer_serialize_stream_to_counted_string(handle, + baseURI.handle, + stream.handle, + &length); + if(!ptr) throw new RDFException(); + scope(exit) librdf_free_memory(ptr); + return ptr[0..length].idup; + } + /// Order of arguments not the same as in C + void serializeToFile(string filename, + StreamWithoutFinalize stream, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + int res = librdf_serializer_serialize_stream_to_file(handle, + filename.toStringz, + baseURI.handle, + stream.handle); + if(res != 0) throw new RDFException(); + } + void serializeToFileHandle(File file, + StreamWithoutFinalize stream, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + int res = librdf_serializer_serialize_stream_to_file_handle(handle, + file.getFP, + baseURI.handle, + stream.handle); + if(res != 0) throw new RDFException(); + } + void serializeToIOStream(IOStreamWithoutFinalize file, + StreamWithoutFinalize stream, + URIWithoutFinalize baseURI = URIWithoutFinalize.fromHandle(null)) + { + int res = librdf_serializer_serialize_stream_to_iostream(handle, + baseURI.handle, + stream.handle, + file.handle); + if(res != 0) throw new RDFException(); + } + // http://bugs.librdf.org/mantis/view.php?id=641 +// not overriding function Get_Feature (Serializer: Serializer_Type_Without_Finalize; +// Feature: URI_Type_Without_Finalize'Class); +// return Node_Type; +// not overriding function Set_Feature (Serializer: Serializer_Type_Without_Finalize; +// Feature: URI_Type_Without_Finalize'Class; +// Value: Node_Iterator_Type_Without_Finalize'Class); +} + +struct Serializer { + mixin WithFinalize!(SerializerHandle, + SerializerWithoutFinalize, + Serializer, + librdf_free_serializer); + static Serializer create(RedlandWorldWithoutFinalize world, + string name = "", + string mimeType = "", + URIWithoutFinalize typeURI = URIWithoutFinalize.fromHandle(null)) + { + SerializerHandle* h = librdf_new_serializer(world.handle, + name.empty ? null : name.ptr, + mimeType.empty ? null : mimeType.ptr, + typeURI.handle); + return Serializer.fromNonnullHandle(h); + } +} + +ref const(SyntaxDescription) getSerializerDescription(const RedlandWorldWithoutFinalize world, + uint index) +{ + return *librdf_serializer_get_description(world.handle, index); +} + +bool serializerCheckName(RedlandWorldWithoutFinalize world, string name) { + return librdf_serializer_check_name(world.handle, name.toStringz) != 0; +} + +struct SerializersEnumerate { +private: + RedlandWorldWithoutFinalize _world; + uint counter = 0; +public: + this(RedlandWorldWithoutFinalize world) { + _world = world; + } + @property uint position() const { return counter; } + @property bool empty() const { + return !librdf_serializer_get_description(_world.handle, counter); + } + @property ref const(SyntaxDescription) front() const + in(!empty) + { + return getSerializerDescription(_world, counter); + } + void popFront() + in(!empty) + { + ++counter; + } +} + diff --git a/dlang/source/rdf/redland/statement.d b/dlang/source/rdf/redland/statement.d new file mode 100644 index 000000000..0f535d3eb --- /dev/null +++ b/dlang/source/rdf/redland/statement.d @@ -0,0 +1,155 @@ +module rdf.redland.statement; + +import std.stdio : File, FILE; +import rdf.auxiliary.handled_record; +static import rdf.raptor.statement; +import rdf.raptor.iostream; +import rdf.redland.world; +import rdf.redland.node; + +struct StatementHandle; + +enum StatementPartFlags { + subjectPart = 1, + predicatePart = 2, + objectPart = 4, + allParts = subjectPart | predicatePart | objectPart } + +private extern extern(C) { + void librdf_free_statement(StatementHandle* statement); + StatementHandle* librdf_new_statement_from_statement(StatementHandle* statement); + void librdf_statement_clear(StatementHandle* statement); + NodeHandle* librdf_statement_get_subject(StatementHandle* statement); + void librdf_statement_set_subject(StatementHandle* statement, NodeHandle* node); + NodeHandle* librdf_statement_get_predicate(StatementHandle* statement); + void librdf_statement_set_predicate(StatementHandle* statement, NodeHandle* node); + NodeHandle* librdf_statement_get_object(StatementHandle* statement); + void librdf_statement_set_object(StatementHandle* statement, NodeHandle* node); + NodeHandle* librdf_new_node_from_node(NodeHandle* node); + int librdf_statement_is_complete(StatementHandle* statement); + void librdf_statement_print(StatementHandle* statement, FILE *fh); + int librdf_statement_equals(StatementHandle* statement1, StatementHandle* statement2); + int librdf_statement_match(StatementHandle* statement, StatementHandle* partial_statement); + size_t librdf_statement_encode2(RedlandWorldHandle* world, + StatementHandle* statement, + char *buffer, + size_t length); + size_t librdf_statement_encode_parts2(RedlandWorldHandle* world, + StatementHandle* statement, + NodeHandle* context_node, + char *buffer, + size_t length, + StatementPartFlags fields); + int librdf_statement_write(StatementHandle* statement, IOStreamHandle* iostr); + StatementHandle* librdf_new_statement(RedlandWorldHandle* world); + StatementHandle* librdf_new_statement_from_nodes(RedlandWorldHandle* world, + NodeHandle* subject, + NodeHandle* predicate, + NodeHandle* object); +} + +struct StatementWithoutFinalize { + mixin WithoutFinalize!(StatementHandle, + StatementWithoutFinalize, + Statement, + librdf_new_statement_from_statement); + mixin CompareHandles!(librdf_statement_equals, null); + @property rdf.raptor.statement.Statement toRaptor() const { // FIXME: also dup() in Ada + return rdf.raptor.statement.StatementWithoutFinalize.fromHandle( + cast(rdf.raptor.statement.StatementHandle*)handle).dup; + } + void clear() { + librdf_statement_clear(handle); + } + @property NodeWithoutFinalize subject() const { + return NodeWithoutFinalize.fromHandle(librdf_statement_get_subject(handle)); + } + @property NodeWithoutFinalize predicate() const { + return NodeWithoutFinalize.fromHandle(librdf_statement_get_predicate(handle)); + } + @property NodeWithoutFinalize object() const { + return NodeWithoutFinalize.fromHandle(librdf_statement_get_object(handle)); + } + @property void subject(NodeWithoutFinalize node) { + librdf_statement_set_subject(handle, librdf_new_node_from_node(node.handle)); + } + @property void predicate(NodeWithoutFinalize node) { + librdf_statement_set_predicate(handle, librdf_new_node_from_node(node.handle)); + } + @property void object(NodeWithoutFinalize node) { + librdf_statement_set_object(handle, librdf_new_node_from_node(node.handle)); + } + @property bool isComplete() const { + return librdf_statement_is_complete(handle) != 0; + } + void print(File file) const { + librdf_statement_print(handle, file.getFP); + } + bool matchedBy(const StatementWithoutFinalize partial) const { + return librdf_statement_match(handle, partial.handle) != 0; + } + bool matches(const StatementWithoutFinalize full) const { + return full.matchedBy(this); + } + string encode(RedlandWorldWithoutFinalize world) const { + size_t length = librdf_statement_encode2(world.handle, handle, null, 0); + char[] buffer = new char[length]; + cast(void)librdf_statement_encode2(world.handle, handle, buffer.ptr, length); + return cast(string)buffer; + } + string encodeParts(RedlandWorldWithoutFinalize world, + StatementWithoutFinalize statement, + NodeWithoutFinalize contextNode, + StatementPartFlags fields) + const + { + size_t length = librdf_statement_encode_parts2(world.handle, + handle, + contextNode.handle, + null, + 0, + fields); + char[] buffer = new char[length]; + cast(void)librdf_statement_encode_parts2(world.handle, + handle, + contextNode.handle, + buffer.ptr, + length, + fields); + return cast(string)buffer; + } + // librdf_statement_decode2() not implemented (not so important and somehow hard to do) + void write(IOStreamWithoutFinalize stream) const { + if(librdf_statement_write(handle, stream.handle) != 0) + throw new RDFException(); + } + // librdf_new_statement_from_statement2() not bound. + // (It is unclear how this would interact with D copying.) +} + +struct Statement { + mixin WithFinalize!(StatementHandle, + StatementWithoutFinalize, + Statement, + librdf_free_statement); + static Statement fromRaptor(rdf.raptor.statement.StatementWithoutFinalize uri) { // FIXME: also dup() in Ada + return StatementWithoutFinalize.fromHandle(cast(StatementHandle*)uri.handle).dup; + } + static Statement create(RedlandWorldWithoutFinalize world) { + return fromNonnullHandle(librdf_new_statement(world.handle)); + } + static Statement fromNodes(RedlandWorldWithoutFinalize world, + NodeWithoutFinalize subject, + NodeWithoutFinalize predicate, + NodeWithoutFinalize object) + { + StatementHandle* handle = + librdf_new_statement_from_nodes(world.handle, + subject.handle, + predicate.handle, + object.handle); + return fromNonnullHandle(handle); + } + // librdf_statement_init() not bound because we don't support statistially declared objects. // TODO: Check +} + diff --git a/dlang/source/rdf/redland/storage.d b/dlang/source/rdf/redland/storage.d new file mode 100644 index 000000000..47d2f76ed --- /dev/null +++ b/dlang/source/rdf/redland/storage.d @@ -0,0 +1,98 @@ +module rdf.redland.storage; + +import std.typecons; +import std.string; +import rdf.auxiliary.handled_record; +import rdf.redland.world; + +struct StorageHandle; + +private extern extern(C) { + void librdf_free_storage(StorageHandle* storage); + StorageHandle* librdf_new_storage_from_storage(StorageHandle* old_storage); + int librdf_storage_enumerate(RedlandWorldHandle* world, + const int counter, + const char **name, + const char **label); + int librdf_storage_sync(StorageHandle* storage); + RedlandWorldHandle* librdf_storage_get_world(StorageHandle* storage); + StorageHandle* librdf_new_storage(RedlandWorldHandle* world, + const char *storage_name, + const char *name, + const char *options_string); +} + +struct StorageInfo { + string name, label; +} + +struct StorageWithoutFinalize { + mixin WithoutFinalize!(StorageHandle, + StorageWithoutFinalize, + Storage, + librdf_new_storage_from_storage); + void sync() { + if(librdf_storage_sync(handle) != 0) + throw new RDFException(); + } + // Will implement after http://bugs.librdf.org/mantis/view.php?id=636 bug fix +// not overriding function Get_Feature (Storage: Storage_Type_Without_Finalize; +// Feature: URI_Type_Without_Finalize'Class) +// return Node_Type_Without_Finalize; +// not overriding procedure Set_Feature (Storage: Storage_Type_Without_Finalize; +// Feature: URI_Type_Without_Finalize'Class; +// Value: Node_Type_Without_Finalize'Class); + @property RedlandWorldWithoutFinalize world() const { + // Or just fromHandle? + return RedlandWorldWithoutFinalize.fromNonnullHandle(librdf_storage_get_world(handle)); + } +} + +struct Storage { + mixin WithFinalize!(StorageHandle, + StorageWithoutFinalize, + Storage, + librdf_free_storage); + static Storage create(RedlandWorldWithoutFinalize world, + string factoryName, + string name, + string options = "") + { + StorageHandle* h = librdf_new_storage(world.handle, + factoryName.toStringz, + name.toStringz, + options.toStringz); + return Storage.fromNonnullHandle(h); + } +} + +Nullable!StorageInfo enumerateStorages(const RedlandWorldWithoutFinalize world, uint counter) { + char* name, label; + int result = librdf_storage_enumerate(world.handle, counter, &name, &label); + if(result != 0) return Nullable!StorageInfo(); + return Nullable!StorageInfo(StorageInfo(name.fromStringz.idup, label.fromStringz.idup)); +} + +struct StoragesEnumerate { +private: + RedlandWorldWithoutFinalize _world; + uint counter = 0; +public: + this(RedlandWorldWithoutFinalize world) { + _world = world; + } + @property bool empty() const { + return librdf_storage_enumerate(_world.handle, counter, null, null) != 0; + } + @property StorageInfo front() const + in(!empty) + { + return enumerateStorages(_world, counter).get; + } + void popFront() + in(!empty) + { + ++counter; + } +} + diff --git a/dlang/source/rdf/redland/stream.d b/dlang/source/rdf/redland/stream.d new file mode 100644 index 000000000..c382c6349 --- /dev/null +++ b/dlang/source/rdf/redland/stream.d @@ -0,0 +1,75 @@ +module rdf.redland.stream; + +import rdf.auxiliary.handled_record; +import rdf.raptor.iostream; +import rdf.redland.world; +import rdf.redland.node; +import rdf.redland.statement; +import rdf.redland.node_iterator; + +// Necessarily test that it works as expected + +struct StreamHandle; + +private extern extern(C) { + void librdf_free_stream(StreamHandle* stream); + int librdf_stream_end(StreamHandle* stream); + int librdf_stream_next(StreamHandle* stream); + StatementHandle* librdf_stream_get_object(StreamHandle* stream); + NodeHandle* librdf_stream_get_context2(StreamHandle* stream); + int librdf_stream_write(StreamHandle* stream, IOStreamHandle* iostr); + StreamHandle* librdf_new_empty_stream(RedlandWorldHandle* world); + StreamHandle* librdf_new_stream_from_node_iterator(NodeIteratorHandle* iterator, + StatementHandle *statement, + StatementPartFlags field); +} + +struct StreamWithoutFinalize { + mixin WithoutFinalize!(StreamHandle, + StreamWithoutFinalize, + Stream); + @property bool empty() const { + return librdf_stream_end(handle) != 0; + } + @property inout(StreamWithoutFinalize) front() inout { return this; } + void popFront() { + cast(void)librdf_stream_next(handle); + } + @property StatementWithoutFinalize object() const { + return StatementWithoutFinalize.fromHandle(librdf_stream_get_object(handle)); + } + @property NodeWithoutFinalize context() const { + return NodeWithoutFinalize.fromHandle(librdf_stream_get_context2(handle)); + } + // librdf_stream_add_map() not implemented + void write(IOStreamWithoutFinalize raptorStream) { + if(librdf_stream_write(handle, raptorStream.handle) != 0) + throw new RDFException(); + } +} + +struct Stream { + mixin WithFinalize!(StreamHandle, + StreamWithoutFinalize, + Stream, + librdf_free_stream); + static Stream emptyStream(RedlandWorldWithoutFinalize world) { + return fromNonnullHandle(librdf_new_empty_stream(world.handle)); + } + static Stream fromNodeIterator(NodeIterator iterator, + StatementWithoutFinalize statement, + StatementPartFlags field) + { + StreamHandle* handle = + librdf_new_stream_from_node_iterator(iterator.handle, statement.handle, field); + return fromNonnullHandle(handle); + } +} + +unittest { + RedlandWorld world = RedlandWorld.createAndOpen(); + import std.range.primitives; + auto s = Stream.emptyStream(world); + assert(s.empty); +} + diff --git a/dlang/source/rdf/redland/uri.d b/dlang/source/rdf/redland/uri.d new file mode 100644 index 000000000..04eb463ea --- /dev/null +++ b/dlang/source/rdf/redland/uri.d @@ -0,0 +1,98 @@ +module rdf.redland.uri; + +import std.string; +import std.stdio : File, FILE; +import rdf.auxiliary.handled_record; +static import rdf.raptor.uri; +import rdf.redland.memory; +import rdf.redland.world; + +struct URIHandle; + +private extern extern(C) { + void librdf_free_uri(URIHandle* uri); + URIHandle* librdf_new_uri_from_uri(URIHandle* old_uri); + char* librdf_uri_as_counted_string(URIHandle* uri, size_t *len_p); + void librdf_uri_print(URIHandle* uri, FILE *fh); + int librdf_uri_equals(URIHandle* first_uri, URIHandle* second_uri); + int librdf_uri_compare(URIHandle* first_uri, URIHandle* second_uri); + int librdf_uri_is_file_uri(URIHandle* uri); + const(char*) librdf_uri_to_filename(URIHandle* uri); + URIHandle* librdf_get_concept_ms_namespace (RedlandWorldHandle* world); + URIHandle* librdf_get_concept_schema_namespace (RedlandWorldHandle* world); + URIHandle* librdf_new_uri2(RedlandWorldHandle* world, const char *uri_string, size_t length); + URIHandle* librdf_new_uri_from_uri_local_name(URIHandle* old_uri, const char *local_name); + URIHandle* librdf_new_uri_normalised_to_base(const char *uri_string, + URIHandle* source_uri, + URIHandle* base_uri); + URIHandle* librdf_new_uri_relative_to_base(URIHandle* base_uri, const char *uri_string); + URIHandle* librdf_new_uri_from_filename(RedlandWorldHandle* world, const char *filename); +} + +struct URIWithoutFinalize { + mixin WithoutFinalize!(URIHandle, + URIWithoutFinalize, + URI, + librdf_new_uri_from_uri); + mixin CompareHandles!(librdf_uri_equals, librdf_uri_compare); + @property rdf.raptor.uri.URI toRaptor() const { // FIXME: also dup() in Ada + return rdf.raptor.uri.URIWithoutFinalize.fromHandle(cast(rdf.raptor.uri.URIHandle*)handle).dup; + } + string toString() const { + size_t length; + char* str = librdf_uri_as_counted_string(handle, &length); + return str[0..length].idup; + } + void print(File file) const { + librdf_uri_print(handle, file.getFP); + } + bool isFileURI() const { + return librdf_uri_is_file_uri(handle) != 0; + } + string toFilename() const { + const char* ptr = librdf_uri_to_filename(handle); + scope(exit) librdf_free_memory(cast(char*)ptr); + return ptr.fromStringz.idup; + } +} + +struct URI { + mixin WithFinalize!(URIHandle, + URIWithoutFinalize, + URI, + librdf_free_uri); + static URI fromRaptor(rdf.raptor.uri.URIWithoutFinalize uri) { // FIXME: also dup() in Ada + return URIWithoutFinalize.fromHandle(cast(URIHandle*)uri.handle).dup; + } + static URI fromString(RedlandWorldWithoutFinalize world, string uri) { + return fromNonnullHandle(librdf_new_uri2(world.handle, uri.ptr, uri.length)); + } + static URI fromURILocalName(URIWithoutFinalize oldURI, string localName) { + return fromNonnullHandle( + librdf_new_uri_from_uri_local_name(oldURI.handle, localName.toStringz)); + } + static URI normalisedToBase(string uriStr, + URIWithoutFinalize sourceURI, + URIWithoutFinalize baseURI) + { + return fromNonnullHandle( + librdf_new_uri_normalised_to_base(uriStr.toStringz, sourceURI.handle, baseURI.handle)); + } + static URI relativeToBase(URIWithoutFinalize baseURI, string uri) { + return fromNonnullHandle( + librdf_new_uri_relative_to_base(baseURI.handle, uri.toStringz)); + } + static URI fromFilename (RedlandWorldWithoutFinalize world, string filename) { + return fromNonnullHandle(librdf_new_uri_from_filename(world.handle, filename.toStringz)); + } +} + +// From http://librdf.org/docs/api/redland-concepts.html: +URIWithoutFinalize conceptMsNamespace(RedlandWorldWithoutFinalize world) { + return URIWithoutFinalize.fromNonnullHandle(librdf_get_concept_ms_namespace(world.handle)); +} + +URIWithoutFinalize conceptSchemaNamespace(RedlandWorldWithoutFinalize world) { + return URIWithoutFinalize.fromNonnullHandle(librdf_get_concept_schema_namespace(world.handle)); +} + diff --git a/dlang/source/rdf/redland/world.d b/dlang/source/rdf/redland/world.d new file mode 100644 index 000000000..6bb9f6a3b --- /dev/null +++ b/dlang/source/rdf/redland/world.d @@ -0,0 +1,78 @@ +module rdf.redland.world; + +import std.string; +import rdf.auxiliary.handled_record; +import rdf.raptor.world; +import rdf.rasqal.world; +import rdf.redland.uri; +import rdf.redland.node; + +struct RedlandWorldHandle; + +private extern extern(C) { + void librdf_free_world(RedlandWorldHandle* world); + RedlandWorldHandle* librdf_new_world(); + void librdf_world_open(RedlandWorldHandle* world); + RaptorWorldHandle* librdf_world_get_raptor(RedlandWorldHandle* world); + RasqalWorldHandle* librdf_world_get_rasqal(RedlandWorldHandle* world); + void librdf_world_set_raptor(RedlandWorldHandle* world, RaptorWorldHandle* raptor_world_ptr); + void librdf_world_set_rasqal(RedlandWorldHandle* world, RasqalWorldHandle* rasqal_world_ptr); + void librdf_world_set_digest(RedlandWorldHandle* world, const char *name); + NodeHandle* librdf_world_get_feature(RedlandWorldHandle* world, URIHandle* feature); + int librdf_world_set_feature(RedlandWorldHandle* world, URIHandle* feature, NodeHandle* value); +} + +enum { + featureGenidBase = "http://feature.librdf.org/genid-base", + featureGenidCounter = "http://feature.librdf.org/genid-counter", +} + +struct RedlandWorldWithoutFinalize { + mixin WithoutFinalize!(RedlandWorldHandle, + RedlandWorldWithoutFinalize, + RedlandWorld); + void open() { + librdf_world_open(handle); + } + @property void rasqal(RasqalWorldWithoutFinalize rasqalWorld) { + librdf_world_set_rasqal(handle, rasqalWorld.handle); + } + @property RasqalWorldWithoutFinalize rasqal() const { + return RasqalWorldWithoutFinalize.fromNonnullHandle(librdf_world_get_rasqal(handle)); + } + @property void raptor(RaptorWorldWithoutFinalize raptorWorld) { + librdf_world_set_raptor(handle, raptorWorld.handle); + } + @property RaptorWorldWithoutFinalize raptor() const { + return RaptorWorldWithoutFinalize.fromNonnullHandle(librdf_world_get_raptor(handle)); + } + @property void digest(string name) const { + librdf_world_set_digest(handle, name.toStringz); + } + @property Node feature(URIWithoutFinalize feature) const { + return Node.fromHandle(librdf_world_get_feature(handle, feature.handle)); + } + @property void feature(URIWithoutFinalize feature, NodeWithoutFinalize value) { + if(librdf_world_set_feature(handle, feature.handle, value.handle) != 0) + throw new RDFException(); + } + // librdf_world_set_error() and librdf_world_set_warning() deliberately not implemented. + + // I deliberately not implement librdf_world_set_raptor_init_handler() and + // librdf_world_set_rasqal_init_handler(). + // I recommend to use properties `raptor` and `rasqal` instead. +} + +struct RedlandWorld { + mixin WithFinalize!(RedlandWorldHandle, + RedlandWorldWithoutFinalize, + RedlandWorld, + librdf_free_world, + librdf_new_world); + static RedlandWorld createAndOpen() { + RedlandWorld world = create(); + world.open(); + return world; + } +} + diff --git a/docs/Makefile.am b/docs/Makefile.am index f4d61b46b..beb44e383 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -21,6 +21,8 @@ # # +SUBDIRS=ada + EXTRA_DIST=\ README.html README \ perl.html python.html ruby.html php.html \ diff --git a/docs/README.html b/docs/README.html index edd7a4853..0d643e208 100644 --- a/docs/README.html +++ b/docs/README.html @@ -18,6 +18,7 @@

Redland RDF Application Framework Bindings - Documentation

  • Redland Perl interface
  • Redland PHP interface
  • Redland Python interface
  • +
  • Redland R package
  • Redland Ruby interface
  • Redland storage implementations overview
  • diff --git a/docs/ada/Makefile.am b/docs/ada/Makefile.am new file mode 100644 index 000000000..b7eb5c375 --- /dev/null +++ b/docs/ada/Makefile.am @@ -0,0 +1,9 @@ +EXTRA_DIST = ada-bindings.odt ada-bindings.html ada-bindings.pdf + +ada-bindings.html: ada-bindings.odt + libreoffice --headless --convert-to "html:XHTML Writer File:UTF8" $< + +ada-bindings.pdf: ada-bindings.odt + libreoffice --headless --convert-to pdf $< + +all-local: ada-bindings.html ada-bindings.pdf diff --git a/docs/ada/ada-bindings.html b/docs/ada/ada-bindings.html new file mode 100644 index 000000000..d55d8410b --- /dev/null +++ b/docs/ada/ada-bindings.html @@ -0,0 +1,104 @@ + +Writing Ada Bindings for a C Library

    Writing Ada Bindings for a C Library

    Victor Porton

    Shay Agnon 32-29, Ashkelon, Israel; email: porton@narod.ru

     

    1. 1.Abstract 

    I share my experience of writing thick (object oriented) Ada binding of a C library. This article provides some Ada tips and tricks (especially for Ada bindings writers).

    Keywords: Ada bindings, thick bindings, C.

    1. 2.Introduction 

    We have a C library, written in object oriented style (C structure pointers serve as objects, and C functions taking such structure pointers serve as methods). However there is no inheritance in that C library (to make things easier for us).

    The particular library is Redland RDF Libraries, a set of libraries which parses RDF files or other RDF resources and manages them, allows to do RDF queries, etc. Don't worry if you don't know what RDF is, it is not really relevant for this article. See more info about this C library in [4] and [1] and on RDF itself in [3].

    I write thick Ada bindings for this library. “Thick” means that the API which I create is a full fledged Ada interface. For example, it uses Ada controlled tagged types to represent objects. (It also uses derived types and some other Ada features which are not available in C.)

    By Ada here I will mean Ada2012, the latest currently available Ada standard.

    This is a work in progress. Please write your comments. Don’t forget to notify me through porton@narod.ru (as I am not subscribed to this journal).

    The source code of my library is available at https://github.com/vporton/redland-bindings (currently only in ada2012 branch).

    Note that the main purpose I created Ada bindings for Redland is to use them in this project:
    https://en.wikiversity.org/wiki/Automatic_transformation_of_XML_namespaces

    1. 3.Little things 

    One thing I learned during this project, is that Ada types should have different names, they shouldn’t have the same name even if they are in different packages. This both allows to shorten the code with use directives and to increase reliability of not passing a wrong type if a use directive is indeed used.

    Initially I tried to use GCC with -fdump-ada-spec flag to autogenerate Ada specs from C headers. But shortly I realized that it will work better if I write Convention=>C subprograms manually (mainly because I sometimes want char_array and sometimes chars_ptr for a char* argument of a C function).

    1. 4.Packages structure 

    I put all my API into package hierarchy RDF.*.

    The package RDF itself is empty:

    package RDF is

       pragma Pure(RDF);
    end
    RDF;

    I also have RDF.Auxiliary package and its subpackages for “auxiliary” things (things used by or with my bindings, but not being bindings for a particular C library function).

    I will discuss some particular RDF.Auxiliary.* packages below.

    1. 5.My tagged types 

    As I've said above, C objects are pointers to structures. All C pointers to structures have the same format and alignment [2]. This allows to represent any pointers to C structures as pointers to Dummy_Record as defined in RDF.Auxiliary package:

    type Dummy_Record is null record
     with Convention=>C;

    A new Ada type (call it T_Without_Finalize for the below explained reasons) corresponding to a dynamically allocated C record is created by instantiating generic packages RDF.Auxiliary.Handled_Record or RDF.Auxiliary.Limited_Handled_Record with a Convention=>C record type (can be Dummy_Record if record layout is considered internal by the C library documentation) and a Convention=>C access to this record and deriving our type from the tagged type Base_Object in the instantiated package.

    Representing C structure pointers as tagged types is not memory efficient, but here we trade efficiency for programming ease.

    It would be compelling to make Limited_Handled_Record a descendant type of  Handled_Record, but it is impossible in Ada because Ada.Finalization.Limited_Controlled is not a descendant of Ada.Finalization.Controlled (as it probably should be). As such I wrote two similar packages RDF.Auxiliary.Limited_Handled_Record and RDF.Auxiliary.Handled_Record which duplicate mainly the same code. This is not perfect, but neither it is very bad, as the quantity of the code of these two packages (including their bodies) is not great.

    1. 6.About finalization and related stuff 

    The main challenge writing object oriented bindings for a C library is finalization.

    In the C library in consideration (as well as in many other C libraries) every object is represented as a pointer to a dynamically allocated C structure.

    The corresponding Ada object can be a (tagged) record holding the pointer (aka handle).

    Ada object representing C objects should be descendants of Ada.Finalization.Limited_Controlled or Ada.Finalization.Controlled to be properly finalized when appropriate.

    But oftentimes a C function returns so called “shared handle” that is a pointer to a C struct which we should not free because it is a part of a greater C object and shall be freed (by the C library) only when that greater C object goes away.

    As such I first define a tagged type T_Without_Finalize type. For this type I define such procedures as Do_Finalize and Do_Adjust which do what Finalize and Adjust should do but leave Finalize and Adjust empty, so that a shared handle is neither finalized nor copied.

    I define type T with Finalize and Adjust as a derived type. T could be defined as ancestor of both T_Without_Finalize and a type which defines Finalize and Adjust. But as Ada misses inheritance from multiple tagged types, I do it with generics instead (below is a partial listing):

    generic

      type Base is new Base_Object with private;

    package Common_Handlers is

      type User_Type is new Base with null record;

      overriding procedure Finalize(Object: in out User_Type)

                                    renames Do_Finalize;

      overriding procedure Adjust(Object: in out User_Type)

                                  renames Do_Adjust;

      type Base_With_Finalization is new User_Type

        with null record;

    end;

    The Base generic parameter is intended to be that T_Without_Finalize type.

    You see that Do_Finalize and Do_Adjust become actual handlers of finalization and adjustment.

    Note that I recommend to override the subprograms Finalize_Handle and Adjust_Handle (see the source) rather than Do_Finalize and Do_Adjust themselves.

    Note that values of  T_Without_Finalize type may become invalid (containing dangling access values). There seems that there is no easy enough way to deal with this problem (because of the way the C library works). Just be careful when using this library not to use objects which are already destroyed.

    1. 7.User defined types 

    Next thing to note that I first define User_Type. This type is intended to serve among other as a base for user-defined types which may contain not only the C handle but also other fields. The type Base_With_Finalization on the other hand is meant not to be a base for types with additional fields but contain only the handle (and null record extensions).

    The reason why I make distinction between User_Type and Base_With_Finalization is the following:

    We define some functions like

    function From_Filename

      (World: Raptor_World_Type_Without_Finalize'Class;

       Filename: String)

        return IOStream_Type;

    IOStream_Type is derived from Base_With_Finalization not from User_Type directly. If we derived our User_Type from IOStream_Type then non-null record extensions would cause (by Ada rules) the necessity to redefine From_Filename function also for the derived type what is a nonsense.

    We actually use User_Type (in the private part of a package) like this (for an I/O stream reading from a string):

    type Stream_From_String(Length: size_t) is

      new IOStream_Type_User with

      record

        Str: char_array(1..Length);

      end record;

    1. 8.Controlling vs class-wide arguments 

    Controlling and class-wide arguments differ mainly in their relationship with inheritance. But as there is no inheritance in the C library which we bind, we have certain freedom to choose either.

    One disadvantage of class-wide types is that such things as that is makes necessary Get_Handle(null) to be type-qualified and thus the subprogram specifications longer.

    One advantage of class-wide types is that I can use (as in query_results.ads) ST‘Class where ST is a subtype with a predicate to restrict to a subtypes matching a predicate.

    Example:
    subtype URI_Term_Type_Without_Finalize is

      Term_Type_Without_Finalize

       with Dynamic_Predicate =>

          Is_URI(URI_Term_Type_Without_Finalize);

    It is possible that in a future version of the library I will consistently replace controlling arguments with class-wide arguments. This would make it more symmetric, as all tagged arguments would be class-wide and none special controlling one.

    1. 9.Dealing with callbacks 

    To deal with C callbacks (particularly accepting a void* argument for additional data) in object oriented way, we need a way to convert between C void pointers and accesses to Ada tagged (even class-wide) objects. (We pass Ada tagged objects as C “user data” pointers.)

    When we create a callback we need to pass an Ada object as a C pointer and a Convention=>C subprogram defined by us as the callback. The callback receives the pointer previously passed by us and in the callback code we should (if we want to stay object oriented) convert this pointer into an Ada object access.

    What we need is some bijective (“back and forth”) mapping between Ada access values and C pointers.

    At first I was tempted to use Ada.Unchecked_Conversion. But (despite GNAT 7.2.0 gives no warning on this) it is not in any way guaranteed to work, because the format of Ada access type and of C pointer are not necessarily the same.

    Now I do conversion this way:

    I convert chars_ptr to a Convention=>C access to char then this to System.Address using System.Address_To_Access_Conversions and then (also by Address_To_Access_Conversions) address to the required access to a class-wide type.

    The backward conversion is analogous.

    The above should work if we understand the words “back and forth” RM13.7.2(5/2) “The To_Pointer and To_Address subprograms convert back and forth between values of types Object_Pointer and Address.” as that the conversion must be bijective. (I filed a clarification request about meaning of the words “back and forth” to Ada standardization committee.)

    All this is implemented in RDF.Auxiliary.Convert_Void of my library, but in my opinion this package should be added to Ada standard packages.

    How to do this in practice? The best way to explain is an example (for a user-defined I/O Stream which calls our function Do_Write_Bytes when “write” message is sent to it):

    package My_Conv is

      new RDF.Auxiliary.Convert_Void

        (Handled_IOStream_Type_User'Class);

    function raptor_iostream_write_bytes_impl

      (context: chars_ptr; ptr: chars_ptr; size, nmemb: size_t)

       return int

      with Convention=>C;
    function raptor_iostream_write_bytes_impl

      (context: chars_ptr; ptr: chars_ptr; size, nmemb: size_t)

       return int is

    begin

      declare

          Result: constant int := Do_Write_Bytes (My_Conv.To_Access (context).all, ptr, size, nmemb);

      begin

          return Result;

      end;

    exception

      when others =>

          return -1;

    end;

    1. 10.Storage pools for memory allocation 

    I tried to define storage pools for C allocation/deallocation functions such as raptor_alloc_memory() and raptor_free_memory(), but it appeared to be impossible by the following reason:

    System.Storage_Pools receives Alignment argument which is an integer multiple of the alignment of the allocated type. This alignment may be greater than the alignment raptor_alloc_memory() warrants (Dummy_Record’Alignment) and so lead to undefined behavior.

    I have sent a proposal to the standardization committee to make the programmer able to restrict the maximum alignment.

    Because using allocators appeared to be impossible, I did it instead this way (for Locator_Handle which is a pointer to Locator_Type record):

    package Locator_Conv is

      new RDF.Auxiliary.Convert_Void(Locator_Type_Record);

     

    function Copy_Locator (Handle: Locator_Handle)

      return Locator_Handle

    is

      Size: constant size_t := size_t((Locator_Type'Max_Size_In_Storage_Elements * Storage_Unit + (char'Size-1)) / char'Size);

      Result2: constant chars_ptr :=

        RDF.Raptor.Memory.raptor_alloc_memory(Size);

      Result: constant Locator_Handle :=

        Locator_Handle(Locator_Conv.To_Access(Result2));

    begin

      Result.all := Handle.all;

      Result.URI := raptor_uri_copy(Handle.URI);

      Result.File := RDF.Raptor.Memory.Copy_C_String(Handle.File);

      return Result;

    end;

    Note that (Locator_Type'Max_Size_In_Storage_Elements * Storage_Unit + (char'Size-1)) / char'Size is the ceiling of floating point division of  Locator_Type'Max_Size_In_Storage_Elements * Storage_Unit by char'Size (but without using floating point). Using ceiling warrants that the allocated space is at least as big as required space.

    Here I allocate with  raptor_alloc_memory() function the amount of memory which is max size needed (apparently not to overwrite nearby memory) for a record pointed by Locator_Type (ARM specifies this max size only for memory returned by an allocator, but I am pretty sure that in any reasonable implementation of Ada the same amount of memory will work well if it is allocated by raptor_alloc_memory() function instead and the nearby memory thus won’t be overwritten).

    1. 11.More little things 

    Ada standard misses a function converting a C string (with possible NULs) described by a chars_ptr and and its length in characters into an Ada String.

    I define function Value_With_Possible_NULs which does this in terms of Interfaces.C.Pointers. Note that the pointer defined in suitably instantiated Interfaces.C.Pointers is correctly converted from/to chars_ptr with Ada.Unchecked_Conversion.

    The Ada standard To_C with Trim_Nul=>False is broken: RM B.3(51) “If Append_Nul is False and Item'Length is 0, then To_C propagates Constraint_Error.” Said in another way the Standard means: “This does not work with empty strings.” So I wrote a wrapper My_To_C_Without_Nul around it.

    I would write a lot more advice how to write Ada bindings for a C library, but you can just follow my source, which can serve as an example.

    I “encode” values of C strings (which can be NULL) as an Ada indefinite holder holding a String. If the string is NULL, the holder is empty. However often it is enough to transform an empty Ada string into NULL C string (this can work only if we don’t differentiate between empty and null strings).

    1. 12.References 
    1. [1]Bootstrapping RDF applications with Redland. David Beckett, https://www.dajobe.org/papers/xtech2005/  

    2. [2]ISO/IEC 9899:2011 section 6.2.5 paragraph 28. 

    3. [3]Resource Description Framework (RDF). RDF Working Group, https://www.w3.org/RDF/ 

    4. [4]The Design and Implementation of the Redland RDF Application Framework. David Beckett, 2001, http://www10.org/cdrom/papers/490/ 

    \ No newline at end of file diff --git a/docs/ada/ada-bindings.odt b/docs/ada/ada-bindings.odt new file mode 100644 index 000000000..1e451e80c Binary files /dev/null and b/docs/ada/ada-bindings.odt differ diff --git a/docs/ada/ada-bindings.pdf b/docs/ada/ada-bindings.pdf new file mode 100644 index 000000000..8c3e51fc4 Binary files /dev/null and b/docs/ada/ada-bindings.pdf differ diff --git a/docs/r.html b/docs/r.html new file mode 100644 index 000000000..994a59629 --- /dev/null +++ b/docs/r.html @@ -0,0 +1,81 @@ + + + + + Redland RDF Application Framework - R Interface + + + +

    Redland RDF Application Framework - R Interface

    + +

    Building the Redland R interface

    + +

    This is built if --with-R is given to the configure +line. The standard 'make' at the top level will build it. Building +the R package is generally not needed for a standard R install because +the redland R package ships with the SWIG-generated bindings and code +already built. So, most users can install the redland package +in R without running the SWIG build. See the README.md in the R/redland directory +for instructions on installing the package into R.

    + +

    The python interface for Redland is mature and requires R 3.1.1 or later. +It has been most intensively tested on R 3.2.0.

    + + +

    Testing the Redland R interface

    + +

    If you did the install described in the redland/README.md, run the R testing +code with:

    +
    +  R --no-save -e 'library(testthat); library(redland); test_package("redland")'
    +
    + +

    and the result should be something like:

    +
    +> test_package("redland")
    +librdf free memory tests :
    +Model tests : ................
    +Node tests : ................
    +Parser tests : ..................
    +Query tests : ....................
    +librdf base API tests : ...............................
    +Serializer tests : .......................
    +Statement tests : ..........................
    +Storage tests : .....
    +World tests : ...
    +
    +Keep up the good work.
    +>
    +
    + +

    Using the Redland R API

    + +

    Read the R documentation using '?redland' within the R environment +for full details of the classes and methods provided along with +examples of use. In addition, the 'redland_overview' vignette in R provides +a simple overview of usage and can be accessed with +vignette("redland_overview", package="redland").

    + +

    The R API maps the underlying librdf functions to a set of S4 classes in R +that represent the main concepts in librdf:

    + + + + + + + + + + + + + +
    ConceptRedland C typeredland R classPurpose
    Resource / Literal librdf_node redland::Node RDF Model & Syntax nodes
    Statement / Triple librdf_statement redland::Statement RDF Model & Syntax arcs (statements, triples) [isa Resource]
    Model librdf_model redland::Model Set of Statements usually held in one Storage.
    Node librdf_node redland::Node The subject, predicate or object of a Statement
    Storage librdf_storage redland::Storage Storage for Models either persistant or in-memory.
    Parser librdf_parser redland::Parser Syntaxes parsers delivering Stream of Statements or writing to a Model
    Query librdf_query redland::Query Querying of an Model delivering a QueryResults
    QueryResults librdf_query_results redland::QueryResults Results of applying an Query to a Model giving either variable bindings with Node values or Stream of Statements
    Serializer librdf_serializer redland::Serializer Serializes a Model into a syntax such as RDF/XML
    World librdf_world redland::World RDF wrapper class handling Redland startup/shutdown
    + +
    + +

    Copyright (C) 2015 Regents of the University of California

    + + + diff --git a/php/Makefile.am b/php/Makefile.am index cdc73c977..f192b6fde 100644 --- a/php/Makefile.am +++ b/php/Makefile.am @@ -4,17 +4,17 @@ # # Copyright (C) 2002-2012 David Beckett - http://www.dajobe.org/ # Copyright (C) 2002-2005 University of Bristol - http://www.bristol.ac.uk/ -# +# # This package is Free Software and part of Redland http://librdf.org/ -# +# # It is licensed under the following three licenses as alternatives: # 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version # 2. GNU General Public License (GPL) V2 or any newer version # 3. Apache License, V2.0 or any newer version -# +# # You may not use this file except in compliance with at least one of # the above three licenses. -# +# # See LICENSE.html or LICENSE.txt at the top of this package for the # full license terms. # @@ -56,7 +56,7 @@ RUN=@REDLAND_RUN@ SWIG_OPTS=-I$(srcdir) -DREDLAND_POST_I -DREDLAND_INIT_I -DREDLAND_DECL_I -DREDLAND_TYPEMAP_I $(PHP_PACKAGE)_wrap.c: @REDLAND_SWIG@ redland-decl.i redland-init.i redland-post.i redland-typemap.i - swig -v $(PHP_SWIG) $(SWIG_OPTS) -noproxy -module $(PHP_PACKAGE) -o $@ @REDLAND_SWIG@ + swig -v $(PHP_SWIG) $(SWIG_OPTS) -php -noproxy -module $(PHP_PACKAGE) -o $@ @REDLAND_SWIG@ rm -f $(PHP_PACKAGE).php # -UHAVE_CONFIG_H to stop PHP trying to include config.h which