annotate win32-mingw/include/sord/sord.h @ 163:5cc1366da2e9

Apply patch from Tim Bunnell on PortAudio mailing list (2016-12-28, Mac 10.11 deprecation warning)
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 30 Oct 2019 11:28:45 +0000
parents e8430c78066a
children
rev   line source
chris@100 1 /*
chris@100 2 Copyright 2011-2013 David Robillard <http://drobilla.net>
chris@100 3
chris@100 4 Permission to use, copy, modify, and/or distribute this software for any
chris@100 5 purpose with or without fee is hereby granted, provided that the above
chris@100 6 copyright notice and this permission notice appear in all copies.
chris@100 7
chris@100 8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
chris@100 9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
chris@100 10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
chris@100 11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
chris@100 12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
chris@100 13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
chris@100 14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
chris@100 15 */
chris@100 16
chris@100 17 /**
chris@100 18 @file sord.h API for Sord, a lightweight RDF model library.
chris@100 19 */
chris@100 20
chris@100 21 #ifndef SORD_SORD_H
chris@100 22 #define SORD_SORD_H
chris@100 23
chris@100 24 #include <stddef.h>
chris@100 25 #include <stdint.h>
chris@100 26 #include <stdio.h>
chris@100 27
chris@100 28 #include "serd/serd.h"
chris@100 29
chris@100 30 #ifdef SORD_SHARED
chris@100 31 # ifdef _WIN32
chris@100 32 # define SORD_LIB_IMPORT __declspec(dllimport)
chris@100 33 # define SORD_LIB_EXPORT __declspec(dllexport)
chris@100 34 # else
chris@100 35 # define SORD_LIB_IMPORT __attribute__((visibility("default")))
chris@100 36 # define SORD_LIB_EXPORT __attribute__((visibility("default")))
chris@100 37 # endif
chris@100 38 # ifdef SORD_INTERNAL
chris@100 39 # define SORD_API SORD_LIB_EXPORT
chris@100 40 # else
chris@100 41 # define SORD_API SORD_LIB_IMPORT
chris@100 42 # endif
chris@100 43 #else
chris@100 44 # define SORD_API
chris@100 45 #endif
chris@100 46
chris@100 47 #ifdef __cplusplus
chris@100 48 extern "C" {
chris@100 49 #else
chris@100 50 # include <stdbool.h>
chris@100 51 #endif
chris@100 52
chris@100 53 /**
chris@100 54 @defgroup sord Sord
chris@100 55 A lightweight RDF model library.
chris@100 56
chris@100 57 Sord stores RDF (subject object predicate context) quads, where the context
chris@100 58 may be omitted (to represent triples in the default graph).
chris@100 59 @{
chris@100 60 */
chris@100 61
chris@100 62 /**
chris@100 63 Sord World.
chris@100 64 The World represents all library state, including interned strings.
chris@100 65 */
chris@100 66 typedef struct SordWorldImpl SordWorld;
chris@100 67
chris@100 68 /**
chris@100 69 Sord Model.
chris@100 70
chris@100 71 A model is an indexed set of Quads (i.e. it can contain several RDF
chris@100 72 graphs). It may be searched using various patterns depending on which
chris@100 73 indices are enabled.
chris@100 74 */
chris@100 75 typedef struct SordModelImpl SordModel;
chris@100 76
chris@100 77 /**
chris@100 78 Model Inserter.
chris@100 79
chris@100 80 An inserter is used for writing statements to a model using the Serd sink
chris@100 81 interface. This makes it simple to write to a model directly using a
chris@100 82 SerdReader, or any other code that writes statements to a SerdStatementSink.
chris@100 83 */
chris@100 84 typedef struct SordInserterImpl SordInserter;
chris@100 85
chris@100 86 /**
chris@100 87 Model Iterator.
chris@100 88 */
chris@100 89 typedef struct SordIterImpl SordIter;
chris@100 90
chris@100 91 /**
chris@100 92 RDF Node.
chris@100 93 A Node is a component of a Quad. Nodes may be URIs, blank nodes, or
chris@100 94 (in the case of quad objects only) string literals. Literal nodes may
chris@100 95 have an associate language or datatype (but not both).
chris@100 96 */
chris@100 97 typedef struct SordNodeImpl SordNode;
chris@100 98
chris@100 99 /**
chris@100 100 Quad of nodes (a statement), or a quad pattern.
chris@100 101
chris@100 102 Nodes are ordered (S P O G). The ID of the default graph is 0.
chris@100 103 */
chris@100 104 typedef const SordNode* SordQuad[4];
chris@100 105
chris@100 106 /**
chris@100 107 Index into a SordQuad.
chris@100 108 */
chris@100 109 typedef enum {
chris@100 110 SORD_SUBJECT = 0, /**< Subject */
chris@100 111 SORD_PREDICATE = 1, /**< Predicate (a.k.a. "key") */
chris@100 112 SORD_OBJECT = 2, /**< Object (a.k.a. "value") */
chris@100 113 SORD_GRAPH = 3 /**< Graph (a.k.a. "context") */
chris@100 114 } SordQuadIndex;
chris@100 115
chris@100 116 /**
chris@100 117 Type of a node.
chris@100 118 */
chris@100 119 typedef enum {
chris@100 120 SORD_URI = 1, /**< URI */
chris@100 121 SORD_BLANK = 2, /**< Blank node identifier */
chris@100 122 SORD_LITERAL = 3 /**< Literal (string with optional lang or datatype) */
chris@100 123 } SordNodeType;
chris@100 124
chris@100 125 /**
chris@100 126 Indexing option.
chris@100 127 */
chris@100 128 typedef enum {
chris@100 129 SORD_SPO = 1, /**< Subject, Predicate, Object */
chris@100 130 SORD_SOP = 1 << 1, /**< Subject, Object, Predicate */
chris@100 131 SORD_OPS = 1 << 2, /**< Object, Predicate, Subject */
chris@100 132 SORD_OSP = 1 << 3, /**< Object, Subject, Predicate */
chris@100 133 SORD_PSO = 1 << 4, /**< Predicate, Subject, Object */
chris@100 134 SORD_POS = 1 << 5 /**< Predicate, Object, Subject */
chris@100 135 } SordIndexOption;
chris@100 136
chris@100 137 /**
chris@100 138 @name World
chris@100 139 @{
chris@100 140 */
chris@100 141
chris@100 142 /**
chris@100 143 Create a new Sord World.
chris@100 144 It is safe to use multiple worlds in one process, though no data
chris@100 145 (e.g. nodes) can be shared between worlds, and this should be avoided if
chris@100 146 possible for performance reasons.
chris@100 147 */
chris@100 148 SORD_API
chris@100 149 SordWorld*
chris@100 150 sord_world_new(void);
chris@100 151
chris@100 152 /**
chris@100 153 Free @c world.
chris@100 154 */
chris@100 155 SORD_API
chris@100 156 void
chris@100 157 sord_world_free(SordWorld* world);
chris@100 158
chris@100 159 /**
chris@100 160 Set a function to be called when errors occur.
chris@100 161
chris@100 162 The @p error_sink will be called with @p handle as its first argument. If
chris@100 163 no error function is set, errors are printed to stderr.
chris@100 164 */
chris@100 165 SORD_API
chris@100 166 void
chris@100 167 sord_world_set_error_sink(SordWorld* world,
chris@100 168 SerdErrorSink error_sink,
chris@100 169 void* handle);
chris@100 170
chris@100 171 /**
chris@100 172 @}
chris@100 173 @name Node
chris@100 174 @{
chris@100 175 */
chris@100 176
chris@100 177 /**
chris@100 178 Get a URI node from a string.
chris@100 179
chris@100 180 Note this function measures @c str, which is a common bottleneck.
chris@100 181 Use sord_node_from_serd_node instead if @c str is already measured.
chris@100 182 */
chris@100 183 SORD_API
chris@100 184 SordNode*
chris@100 185 sord_new_uri(SordWorld* world, const uint8_t* uri);
chris@100 186
chris@100 187 /**
chris@100 188 Get a URI node from a relative URI string.
chris@100 189 */
chris@100 190 SORD_API
chris@100 191 SordNode*
chris@100 192 sord_new_relative_uri(SordWorld* world,
chris@100 193 const uint8_t* str,
chris@100 194 const uint8_t* base_uri);
chris@100 195
chris@100 196 /**
chris@100 197 Get a blank node from a string.
chris@100 198
chris@100 199 Note this function measures @c str, which is a common bottleneck.
chris@100 200 Use sord_node_from_serd_node instead if @c str is already measured.
chris@100 201 */
chris@100 202 SORD_API
chris@100 203 SordNode*
chris@100 204 sord_new_blank(SordWorld* world, const uint8_t* str);
chris@100 205
chris@100 206 /**
chris@100 207 Get a literal node from a string.
chris@100 208
chris@100 209 Note this function measures @c str, which is a common bottleneck.
chris@100 210 Use sord_node_from_serd_node instead if @c str is already measured.
chris@100 211 */
chris@100 212 SORD_API
chris@100 213 SordNode*
chris@100 214 sord_new_literal(SordWorld* world,
chris@100 215 SordNode* datatype,
chris@100 216 const uint8_t* str,
chris@100 217 const char* lang);
chris@100 218
chris@100 219 /**
chris@100 220 Copy a node (obtain a reference).
chris@100 221
chris@100 222 Node that since nodes are interned and reference counted, this does not
chris@100 223 actually create a deep copy of @c node.
chris@100 224 */
chris@100 225 SORD_API
chris@100 226 SordNode*
chris@100 227 sord_node_copy(const SordNode* node);
chris@100 228
chris@100 229 /**
chris@100 230 Free a node (drop a reference).
chris@100 231 */
chris@100 232 SORD_API
chris@100 233 void
chris@100 234 sord_node_free(SordWorld* world, SordNode* node);
chris@100 235
chris@100 236 /**
chris@100 237 Return the type of a node (SORD_URI, SORD_BLANK, or SORD_LITERAL).
chris@100 238 */
chris@100 239 SORD_API
chris@100 240 SordNodeType
chris@100 241 sord_node_get_type(const SordNode* node);
chris@100 242
chris@100 243 /**
chris@100 244 Return the string value of a node.
chris@100 245 */
chris@100 246 SORD_API
chris@100 247 const uint8_t*
chris@100 248 sord_node_get_string(const SordNode* node);
chris@100 249
chris@100 250 /**
chris@100 251 Return the string value of a node, and set @c len to its length.
chris@100 252 */
chris@100 253 SORD_API
chris@100 254 const uint8_t*
chris@100 255 sord_node_get_string_counted(const SordNode* node, size_t* len);
chris@100 256
chris@100 257 /**
chris@100 258 Return the language of a literal node (or NULL).
chris@100 259 */
chris@100 260 SORD_API
chris@100 261 const char*
chris@100 262 sord_node_get_language(const SordNode* node);
chris@100 263
chris@100 264 /**
chris@100 265 Return the datatype URI of a literal node (or NULL).
chris@100 266 */
chris@100 267 SORD_API
chris@100 268 SordNode*
chris@100 269 sord_node_get_datatype(const SordNode* node);
chris@100 270
chris@100 271 /**
chris@100 272 Return the flags (string attributes) of a node.
chris@100 273 */
chris@100 274 SORD_API
chris@100 275 SerdNodeFlags
chris@100 276 sord_node_get_flags(const SordNode* node);
chris@100 277
chris@100 278 /**
chris@100 279 Return true iff node can be serialised as an inline object.
chris@100 280
chris@100 281 More specifically, this returns true iff the node is the object field
chris@100 282 of exactly one statement, and therefore can be inlined since it needn't
chris@100 283 be referred to by name.
chris@100 284 */
chris@100 285 SORD_API
chris@100 286 bool
chris@100 287 sord_node_is_inline_object(const SordNode* node);
chris@100 288
chris@100 289 /**
chris@100 290 Return true iff @c a is equal to @c b.
chris@100 291
chris@100 292 Note this is much faster than comparing the node's strings.
chris@100 293 */
chris@100 294 SORD_API
chris@100 295 bool
chris@100 296 sord_node_equals(const SordNode* a,
chris@100 297 const SordNode* b);
chris@100 298
chris@100 299 /**
chris@100 300 Return a SordNode as a SerdNode.
chris@100 301
chris@100 302 The returned node is shared and must not be freed or modified.
chris@100 303 */
chris@100 304 SORD_API
chris@100 305 const SerdNode*
chris@100 306 sord_node_to_serd_node(const SordNode* node);
chris@100 307
chris@100 308 /**
chris@100 309 Create a new SordNode from a SerdNode.
chris@100 310
chris@100 311 The returned node must be freed using sord_node_free.
chris@100 312 */
chris@100 313 SORD_API
chris@100 314 SordNode*
chris@100 315 sord_node_from_serd_node(SordWorld* world,
chris@100 316 SerdEnv* env,
chris@100 317 const SerdNode* node,
chris@100 318 const SerdNode* datatype,
chris@100 319 const SerdNode* lang);
chris@100 320
chris@100 321 /**
chris@100 322 @}
chris@100 323 @name Model
chris@100 324 @{
chris@100 325 */
chris@100 326
chris@100 327 /**
chris@100 328 Create a new model.
chris@100 329
chris@100 330 @param world The world in which to make this model.
chris@100 331
chris@100 332 @param indices SordIndexOption flags (e.g. SORD_SPO|SORD_OPS). Be sure to
chris@100 333 enable an index where the most significant node(s) are not variables in your
chris@100 334 queries (e.g. to make (? P O) queries, enable either SORD_OPS or SORD_POS).
chris@100 335
chris@100 336 @param graphs If true, store (and index) graph contexts.
chris@100 337 */
chris@100 338 SORD_API
chris@100 339 SordModel*
chris@100 340 sord_new(SordWorld* world,
chris@100 341 unsigned indices,
chris@100 342 bool graphs);
chris@100 343
chris@100 344 /**
chris@100 345 Close and free @c model.
chris@100 346 */
chris@100 347 SORD_API
chris@100 348 void
chris@100 349 sord_free(SordModel* model);
chris@100 350
chris@100 351 /**
chris@100 352 Get the world associated with @c model.
chris@100 353 */
chris@100 354 SORD_API
chris@100 355 SordWorld*
chris@100 356 sord_get_world(SordModel* model);
chris@100 357
chris@100 358 /**
chris@100 359 Return the number of nodes stored in @c world.
chris@100 360
chris@100 361 Nodes are included in this count iff they are a part of a quad in @c world.
chris@100 362 */
chris@100 363 SORD_API
chris@100 364 size_t
chris@100 365 sord_num_nodes(const SordWorld* world);
chris@100 366
chris@100 367 /**
chris@100 368 Return the number of quads stored in @c model.
chris@100 369 */
chris@100 370 SORD_API
chris@100 371 size_t
chris@100 372 sord_num_quads(const SordModel* model);
chris@100 373
chris@100 374 /**
chris@100 375 Return an iterator to the start of @c model.
chris@100 376 */
chris@100 377 SORD_API
chris@100 378 SordIter*
chris@100 379 sord_begin(const SordModel* model);
chris@100 380
chris@100 381 /**
chris@100 382 Search for statements by a quad pattern.
chris@100 383 @return an iterator to the first match, or NULL if no matches found.
chris@100 384 */
chris@100 385 SORD_API
chris@100 386 SordIter*
chris@100 387 sord_find(SordModel* model, const SordQuad pat);
chris@100 388
chris@100 389 /**
chris@100 390 Search for statements by nodes.
chris@100 391 @return an iterator to the first match, or NULL if no matches found.
chris@100 392 */
chris@100 393 SORD_API
chris@100 394 SordIter*
chris@100 395 sord_search(SordModel* model,
chris@100 396 const SordNode* s,
chris@100 397 const SordNode* p,
chris@100 398 const SordNode* o,
chris@100 399 const SordNode* g);
chris@100 400 /**
chris@100 401 Search for a single node that matches a pattern.
chris@100 402 Exactly one of @p s, @p p, @p o must be NULL.
chris@100 403 This function is mainly useful for predicates that only have one value.
chris@100 404 The returned node must be freed using sord_node_free.
chris@100 405 @return the first matching node, or NULL if no matches are found.
chris@100 406 */
chris@100 407 SORD_API
chris@100 408 SordNode*
chris@100 409 sord_get(SordModel* model,
chris@100 410 const SordNode* s,
chris@100 411 const SordNode* p,
chris@100 412 const SordNode* o,
chris@100 413 const SordNode* g);
chris@100 414
chris@100 415 /**
chris@100 416 Return true iff a statement exists.
chris@100 417 */
chris@100 418 SORD_API
chris@100 419 bool
chris@100 420 sord_ask(SordModel* model,
chris@100 421 const SordNode* s,
chris@100 422 const SordNode* p,
chris@100 423 const SordNode* o,
chris@100 424 const SordNode* g);
chris@100 425
chris@100 426 /**
chris@100 427 Return the number of matching statements.
chris@100 428 */
chris@100 429 SORD_API
chris@100 430 uint64_t
chris@100 431 sord_count(SordModel* model,
chris@100 432 const SordNode* s,
chris@100 433 const SordNode* p,
chris@100 434 const SordNode* o,
chris@100 435 const SordNode* g);
chris@100 436
chris@100 437 /**
chris@100 438 Check if @a model contains a triple pattern.
chris@100 439 */
chris@100 440 SORD_API
chris@100 441 bool
chris@100 442 sord_contains(SordModel* model, const SordQuad pat);
chris@100 443
chris@100 444 /**
chris@100 445 Add a quad to a model.
chris@100 446 */
chris@100 447 SORD_API
chris@100 448 bool
chris@100 449 sord_add(SordModel* model, const SordQuad quad);
chris@100 450
chris@100 451 /**
chris@100 452 Remove a quad from a model.
chris@100 453
chris@100 454 Note that is it illegal to remove while iterating over @c model.
chris@100 455 */
chris@100 456 SORD_API
chris@100 457 void
chris@100 458 sord_remove(SordModel* model, const SordQuad quad);
chris@100 459
chris@100 460 /**
chris@100 461 @}
chris@100 462 @name Inserter
chris@100 463 @{
chris@100 464 */
chris@100 465
chris@100 466 /**
chris@100 467 Create an inserter for writing statements to a model.
chris@100 468 */
chris@100 469 SORD_API
chris@100 470 SordInserter*
chris@100 471 sord_inserter_new(SordModel* model,
chris@100 472 SerdEnv* env);
chris@100 473
chris@100 474 /**
chris@100 475 Free an inserter.
chris@100 476 */
chris@100 477 SORD_API
chris@100 478 void
chris@100 479 sord_inserter_free(SordInserter* inserter);
chris@100 480
chris@100 481 /**
chris@100 482 Set the current base URI for writing to the model.
chris@100 483
chris@100 484 Note this function can be safely casted to SerdBaseSink.
chris@100 485 */
chris@100 486 SORD_API
chris@100 487 SerdStatus
chris@100 488 sord_inserter_set_base_uri(SordInserter* inserter,
chris@100 489 const SerdNode* uri);
chris@100 490
chris@100 491 /**
chris@100 492 Set a namespace prefix for writing to the model.
chris@100 493
chris@100 494 Note this function can be safely casted to SerdPrefixSink.
chris@100 495 */
chris@100 496 SORD_API
chris@100 497 SerdStatus
chris@100 498 sord_inserter_set_prefix(SordInserter* inserter,
chris@100 499 const SerdNode* name,
chris@100 500 const SerdNode* uri);
chris@100 501
chris@100 502 /**
chris@100 503 Write a statement to the model.
chris@100 504
chris@100 505 Note this function can be safely casted to SerdStatementSink.
chris@100 506 */
chris@100 507 SORD_API
chris@100 508 SerdStatus
chris@100 509 sord_inserter_write_statement(SordInserter* inserter,
chris@100 510 SerdStatementFlags flags,
chris@100 511 const SerdNode* graph,
chris@100 512 const SerdNode* subject,
chris@100 513 const SerdNode* predicate,
chris@100 514 const SerdNode* object,
chris@100 515 const SerdNode* object_datatype,
chris@100 516 const SerdNode* object_lang);
chris@100 517
chris@100 518 /**
chris@100 519 @}
chris@100 520 @name Iteration
chris@100 521 @{
chris@100 522 */
chris@100 523
chris@100 524 /**
chris@100 525 Set @c quad to the quad pointed to by @c iter.
chris@100 526 */
chris@100 527 SORD_API
chris@100 528 void
chris@100 529 sord_iter_get(const SordIter* iter, SordQuad quad);
chris@100 530
chris@100 531 /**
chris@100 532 Return a field of the quad pointed to by @c iter.
chris@100 533 */
chris@100 534 SORD_API
chris@100 535 const SordNode*
chris@100 536 sord_iter_get_node(const SordIter* iter, SordQuadIndex index);
chris@100 537
chris@100 538 /**
chris@100 539 Return the store pointed to by @c iter.
chris@100 540 */
chris@100 541 SORD_API
chris@100 542 const SordModel*
chris@100 543 sord_iter_get_model(SordIter* iter);
chris@100 544
chris@100 545 /**
chris@100 546 Increment @c iter to point to the next statement.
chris@100 547 */
chris@100 548 SORD_API
chris@100 549 bool
chris@100 550 sord_iter_next(SordIter* iter);
chris@100 551
chris@100 552 /**
chris@100 553 Return true iff @c iter is at the end of its range.
chris@100 554 */
chris@100 555 SORD_API
chris@100 556 bool
chris@100 557 sord_iter_end(const SordIter* iter);
chris@100 558
chris@100 559 /**
chris@100 560 Free @c iter.
chris@100 561 */
chris@100 562 SORD_API
chris@100 563 void
chris@100 564 sord_iter_free(SordIter* iter);
chris@100 565
chris@100 566 /**
chris@100 567 @}
chris@100 568 @name Utilities
chris@100 569 @{
chris@100 570 */
chris@100 571
chris@100 572 /**
chris@100 573 Match two quads (using ID comparison only).
chris@100 574
chris@100 575 This function is a straightforward and fast equivalence match with wildcard
chris@100 576 support (ID 0 is a wildcard). It does not actually read node data.
chris@100 577 @return true iff @c x and @c y match.
chris@100 578 */
chris@100 579 SORD_API
chris@100 580 bool
chris@100 581 sord_quad_match(const SordQuad x, const SordQuad y);
chris@100 582
chris@100 583 /**
chris@100 584 @}
chris@100 585 @name Serialisation
chris@100 586 @{
chris@100 587 */
chris@100 588
chris@100 589 /**
chris@100 590 Return a reader that will read into @c model.
chris@100 591 */
chris@100 592 SORD_API
chris@100 593 SerdReader*
chris@100 594 sord_new_reader(SordModel* model,
chris@100 595 SerdEnv* env,
chris@100 596 SerdSyntax syntax,
chris@100 597 SordNode* graph);
chris@100 598
chris@100 599 /**
chris@100 600 Write a model to a writer.
chris@100 601 */
chris@100 602 SORD_API
chris@100 603 bool
chris@100 604 sord_write(SordModel* model,
chris@100 605 SerdWriter* writer,
chris@100 606 SordNode* graph);
chris@100 607
chris@100 608 /**
chris@100 609 Write a range to a writer.
chris@100 610
chris@100 611 This increments @c iter to its end, then frees it.
chris@100 612 */
chris@100 613 SORD_API
chris@100 614 bool
chris@100 615 sord_write_iter(SordIter* iter,
chris@100 616 SerdWriter* writer);
chris@100 617
chris@100 618 /**
chris@100 619 @}
chris@100 620 @}
chris@100 621 */
chris@100 622
chris@100 623 #ifdef __cplusplus
chris@100 624 } /* extern "C" */
chris@100 625 #endif
chris@100 626
chris@100 627 #endif /* SORD_SORD_H */