From 709f5d5b4b14bfbfc19480a82828f8150ccb7225 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 21 Dec 2020 14:13:20 +0100 Subject: Move header to a conventional "include" directory --- .clang-tidy | 1 - doc/reference.doxygen.in | 2 +- include/sratom/sratom.h | 231 +++++++++++++++++++++++++++++++++++++++++++++++ sratom/sratom.h | 231 ----------------------------------------------- wscript | 17 ++-- 5 files changed, 242 insertions(+), 240 deletions(-) create mode 100644 include/sratom/sratom.h delete mode 100644 sratom/sratom.h diff --git a/.clang-tidy b/.clang-tidy index 34d0485..85eb383 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -9,7 +9,6 @@ Checks: > -cert-err34-c, -clang-analyzer-unix.Malloc, -hicpp-signed-bitwise, - -llvm-header-guard, -llvmlibc-*, -misc-no-recursion, WarningsAsErrors: '*' diff --git a/doc/reference.doxygen.in b/doc/reference.doxygen.in index ab16c97..79ba064 100644 --- a/doc/reference.doxygen.in +++ b/doc/reference.doxygen.in @@ -797,7 +797,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = @SRATOM_SRCDIR@/sratom/sratom.h \ +INPUT = @SRATOM_SRCDIR@/include/sratom/sratom.h \ @SRATOM_SRCDIR@/doc/mainpage.md # This tag can be used to specify the character encoding of the source files diff --git a/include/sratom/sratom.h b/include/sratom/sratom.h new file mode 100644 index 0000000..22cf39e --- /dev/null +++ b/include/sratom/sratom.h @@ -0,0 +1,231 @@ +/* + Copyright 2012-2016 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/** + @file sratom.h API for Sratom, an LV2 Atom RDF serialisation library. +*/ + +#ifndef SRATOM_SRATOM_H +#define SRATOM_SRATOM_H + +#include "lv2/atom/atom.h" +#include "lv2/atom/forge.h" +#include "lv2/urid/urid.h" +#include "serd/serd.h" +#include "sord/sord.h" + +#include +#include + +#ifdef SRATOM_SHARED +# ifdef _WIN32 +# define SRATOM_LIB_IMPORT __declspec(dllimport) +# define SRATOM_LIB_EXPORT __declspec(dllexport) +# else +# define SRATOM_LIB_IMPORT __attribute__((visibility("default"))) +# define SRATOM_LIB_EXPORT __attribute__((visibility("default"))) +# endif +# ifdef SRATOM_INTERNAL +# define SRATOM_API SRATOM_LIB_EXPORT +# else +# define SRATOM_API SRATOM_LIB_IMPORT +# endif +#else +# define SRATOM_API +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + @defgroup sratom Sratom + + A library for serialising LV2 Atoms. + + @{ +*/ + +/** + Atom serialiser. +*/ +typedef struct SratomImpl Sratom; + +/** + Mode for reading resources to LV2 Objects. + + This affects how resources (which are either blank nodes or have URIs) are + read by sratom_read(), since they may be read as simple references (a URI or + blank node ID) or a complete description (an atom "Object"). + + Currently, blank nodes are always read as Objects, but support for reading + blank node IDs may be added in the future. +*/ +typedef enum { + /** + Read blank nodes as Objects, and named resources as URIs. + */ + SRATOM_OBJECT_MODE_BLANK, + + /** + Read blank nodes and the main subject as Objects, and any other named + resources as URIs. The "main subject" is the subject parameter passed + to sratom_read(); if this is a resource it will be read as an Object, + but all other named resources encountered will be read as URIs. + */ + SRATOM_OBJECT_MODE_BLANK_SUBJECT +} SratomObjectMode; + +/** + Create a new Atom serialiser. +*/ +SRATOM_API +Sratom* +sratom_new(LV2_URID_Map* map); + +/** + Free an Atom serialisation. +*/ +SRATOM_API +void +sratom_free(Sratom* sratom); + +/** + Set the environment for reading or writing Turtle. + + This can be used to set namespace prefixes and a base URI for + sratom_to_turtle() and sratom_from_turtle(). +*/ +SRATOM_API +void +sratom_set_env(Sratom* sratom, + SerdEnv* env); + +/** + Set the sink(s) where sratom will write its output. + + This must be called before calling sratom_write(). +*/ +SRATOM_API +void +sratom_set_sink(Sratom* sratom, + const char* base_uri, + SerdStatementSink sink, + SerdEndSink end_sink, + void* handle); + +/** + Write pretty numeric literals. + + If `pretty_numbers` is true, numbers will be written as pretty Turtle + literals, rather than string literals with precise types. The cost of this + is that the types might get fudged on a round-trip to RDF and back. +*/ +SRATOM_API +void +sratom_set_pretty_numbers(Sratom* sratom, + bool pretty_numbers); + +/** + Configure how resources will be read to form LV2 Objects. +*/ +SRATOM_API +void +sratom_set_object_mode(Sratom* sratom, + SratomObjectMode object_mode); + +/** + Write an Atom to RDF. + The serialised atom is written to the sink set by sratom_set_sink(). + @return 0 on success, or a non-zero error code otherwise. +*/ +SRATOM_API +int +sratom_write(Sratom* sratom, + LV2_URID_Unmap* unmap, + uint32_t flags, + const SerdNode* subject, + const SerdNode* predicate, + uint32_t type_urid, + uint32_t size, + const void* body); + +/** + Read an Atom from RDF. + The resulting atom will be written to `forge`. +*/ +SRATOM_API +void +sratom_read(Sratom* sratom, + LV2_Atom_Forge* forge, + SordWorld* world, + SordModel* model, + const SordNode* node); + +/** + Serialise an Atom to a Turtle string. + The returned string must be free()'d by the caller. +*/ +SRATOM_API +char* +sratom_to_turtle(Sratom* sratom, + LV2_URID_Unmap* unmap, + const char* base_uri, + const SerdNode* subject, + const SerdNode* predicate, + uint32_t type, + uint32_t size, + const void* body); + +/** + Read an Atom from a Turtle string. + The returned atom must be free()'d by the caller. +*/ +SRATOM_API +LV2_Atom* +sratom_from_turtle(Sratom* sratom, + const char* base_uri, + const SerdNode* subject, + const SerdNode* predicate, + const char* str); + +/** + A convenient resizing sink for LV2_Atom_Forge. + The handle must point to an initialized SerdChunk. +*/ +SRATOM_API +LV2_Atom_Forge_Ref +sratom_forge_sink(LV2_Atom_Forge_Sink_Handle handle, + const void* buf, + uint32_t size); + +/** + The corresponding deref function for sratom_forge_sink. +*/ +SRATOM_API +LV2_Atom* +sratom_forge_deref(LV2_Atom_Forge_Sink_Handle handle, + LV2_Atom_Forge_Ref ref); + +/** + @} +*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* SRATOM_SRATOM_H */ diff --git a/sratom/sratom.h b/sratom/sratom.h deleted file mode 100644 index 22cf39e..0000000 --- a/sratom/sratom.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - Copyright 2012-2016 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -/** - @file sratom.h API for Sratom, an LV2 Atom RDF serialisation library. -*/ - -#ifndef SRATOM_SRATOM_H -#define SRATOM_SRATOM_H - -#include "lv2/atom/atom.h" -#include "lv2/atom/forge.h" -#include "lv2/urid/urid.h" -#include "serd/serd.h" -#include "sord/sord.h" - -#include -#include - -#ifdef SRATOM_SHARED -# ifdef _WIN32 -# define SRATOM_LIB_IMPORT __declspec(dllimport) -# define SRATOM_LIB_EXPORT __declspec(dllexport) -# else -# define SRATOM_LIB_IMPORT __attribute__((visibility("default"))) -# define SRATOM_LIB_EXPORT __attribute__((visibility("default"))) -# endif -# ifdef SRATOM_INTERNAL -# define SRATOM_API SRATOM_LIB_EXPORT -# else -# define SRATOM_API SRATOM_LIB_IMPORT -# endif -#else -# define SRATOM_API -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** - @defgroup sratom Sratom - - A library for serialising LV2 Atoms. - - @{ -*/ - -/** - Atom serialiser. -*/ -typedef struct SratomImpl Sratom; - -/** - Mode for reading resources to LV2 Objects. - - This affects how resources (which are either blank nodes or have URIs) are - read by sratom_read(), since they may be read as simple references (a URI or - blank node ID) or a complete description (an atom "Object"). - - Currently, blank nodes are always read as Objects, but support for reading - blank node IDs may be added in the future. -*/ -typedef enum { - /** - Read blank nodes as Objects, and named resources as URIs. - */ - SRATOM_OBJECT_MODE_BLANK, - - /** - Read blank nodes and the main subject as Objects, and any other named - resources as URIs. The "main subject" is the subject parameter passed - to sratom_read(); if this is a resource it will be read as an Object, - but all other named resources encountered will be read as URIs. - */ - SRATOM_OBJECT_MODE_BLANK_SUBJECT -} SratomObjectMode; - -/** - Create a new Atom serialiser. -*/ -SRATOM_API -Sratom* -sratom_new(LV2_URID_Map* map); - -/** - Free an Atom serialisation. -*/ -SRATOM_API -void -sratom_free(Sratom* sratom); - -/** - Set the environment for reading or writing Turtle. - - This can be used to set namespace prefixes and a base URI for - sratom_to_turtle() and sratom_from_turtle(). -*/ -SRATOM_API -void -sratom_set_env(Sratom* sratom, - SerdEnv* env); - -/** - Set the sink(s) where sratom will write its output. - - This must be called before calling sratom_write(). -*/ -SRATOM_API -void -sratom_set_sink(Sratom* sratom, - const char* base_uri, - SerdStatementSink sink, - SerdEndSink end_sink, - void* handle); - -/** - Write pretty numeric literals. - - If `pretty_numbers` is true, numbers will be written as pretty Turtle - literals, rather than string literals with precise types. The cost of this - is that the types might get fudged on a round-trip to RDF and back. -*/ -SRATOM_API -void -sratom_set_pretty_numbers(Sratom* sratom, - bool pretty_numbers); - -/** - Configure how resources will be read to form LV2 Objects. -*/ -SRATOM_API -void -sratom_set_object_mode(Sratom* sratom, - SratomObjectMode object_mode); - -/** - Write an Atom to RDF. - The serialised atom is written to the sink set by sratom_set_sink(). - @return 0 on success, or a non-zero error code otherwise. -*/ -SRATOM_API -int -sratom_write(Sratom* sratom, - LV2_URID_Unmap* unmap, - uint32_t flags, - const SerdNode* subject, - const SerdNode* predicate, - uint32_t type_urid, - uint32_t size, - const void* body); - -/** - Read an Atom from RDF. - The resulting atom will be written to `forge`. -*/ -SRATOM_API -void -sratom_read(Sratom* sratom, - LV2_Atom_Forge* forge, - SordWorld* world, - SordModel* model, - const SordNode* node); - -/** - Serialise an Atom to a Turtle string. - The returned string must be free()'d by the caller. -*/ -SRATOM_API -char* -sratom_to_turtle(Sratom* sratom, - LV2_URID_Unmap* unmap, - const char* base_uri, - const SerdNode* subject, - const SerdNode* predicate, - uint32_t type, - uint32_t size, - const void* body); - -/** - Read an Atom from a Turtle string. - The returned atom must be free()'d by the caller. -*/ -SRATOM_API -LV2_Atom* -sratom_from_turtle(Sratom* sratom, - const char* base_uri, - const SerdNode* subject, - const SerdNode* predicate, - const char* str); - -/** - A convenient resizing sink for LV2_Atom_Forge. - The handle must point to an initialized SerdChunk. -*/ -SRATOM_API -LV2_Atom_Forge_Ref -sratom_forge_sink(LV2_Atom_Forge_Sink_Handle handle, - const void* buf, - uint32_t size); - -/** - The corresponding deref function for sratom_forge_sink. -*/ -SRATOM_API -LV2_Atom* -sratom_forge_deref(LV2_Atom_Forge_Sink_Handle handle, - LV2_Atom_Forge_Ref ref); - -/** - @} -*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* SRATOM_SRATOM_H */ diff --git a/wscript b/wscript index e876199..6de029d 100644 --- a/wscript +++ b/wscript @@ -76,7 +76,10 @@ def configure(conf): conf.check_pkg('serd-0 >= 0.30.0', uselib_store='SERD') conf.check_pkg('sord-0 >= 0.14.0', uselib_store='SORD') - autowaf.set_lib_env(conf, 'sratom', SRATOM_VERSION) + # Set up environment for building/using as a subproject + autowaf.set_lib_env(conf, 'sratom', SRATOM_VERSION, + include_path=str(conf.path.find_node('include'))) + conf.write_config_header('sratom_config.h', remove=False) autowaf.display_summary(conf, {'Unit tests': bool(conf.env.BUILD_TESTS)}) @@ -106,9 +109,9 @@ def build(bld): # Shared Library if bld.env.BUILD_SHARED: bld(features = 'c cshlib', - export_includes = ['.'], + export_includes = ['include'], source = lib_source, - includes = ['.', './src'], + includes = ['include'], lib = libs, uselib = 'SERD SORD LV2', name = 'libsratom', @@ -121,9 +124,9 @@ def build(bld): # Static library if bld.env.BUILD_STATIC: bld(features = 'c cstlib', - export_includes = ['.'], + export_includes = ['include'], source = lib_source, - includes = ['.', './src'], + includes = ['include'], lib = libs, uselib = 'SERD SORD LV2', name = 'libsratom_static', @@ -143,7 +146,7 @@ def build(bld): # Static library (for unit test code coverage) bld(features = 'c cstlib', source = lib_source, - includes = ['.', './src'], + includes = ['include'], lib = test_libs, uselib = 'SERD SORD LV2', name = 'libsratom_profiled', @@ -156,7 +159,7 @@ def build(bld): # Unit test program bld(features = 'c cprogram', source = 'tests/sratom_test.c', - includes = ['.', './src'], + includes = ['include'], use = 'libsratom_profiled', lib = test_libs, uselib = 'SERD SORD LV2', -- cgit v1.2.1