annotate win32-mingw/include/sord/sord.h @ 84:08ae793730bd

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