1/* -*- Mode: c; c-basic-offset: 2 -*-
2 *
3 * rdf_node.h - RDF Node definition
4 *
5 * Copyright (C) 2000-2008, David Beckett http://www.dajobe.org/
6 * Copyright (C) 2000-2004, University of Bristol, UK http://www.bristol.ac.uk/
7 *
8 * This package is Free Software and part of Redland http://librdf.org/
9 *
10 * It is licensed under the following three licenses as alternatives:
11 * 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
12 * 2. GNU General Public License (GPL) V2 or any newer version
13 * 3. Apache License, V2.0 or any newer version
14 *
15 * You may not use this file except in compliance with at least one of
16 * the above three licenses.
17 *
18 * See LICENSE.html or LICENSE.txt at the top of this package for the
19 * complete terms and further detail along with the license texts for
20 * the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively.
21 *
22 *
23 */
24
25
26
27#ifndef LIBRDF_NODE_H
28#define LIBRDF_NODE_H
29
30#ifndef LIBRDF_OBJC_FRAMEWORK
31#include <rdf_uri.h>
32#else
33#include <Redland/rdf_uri.h>
34#endif
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40
41/* Node types */
42
43/* DEPENDENCY: If this list is changed, the librdf_node_type_names
44 * definition in rdf_node.c must be updated to match
45 *
46 * Node type 3 is unused and should not be renumbered to keep binary
47 * ABI compatibility.
48 */
49
50/**
51 * librdf_node_type:
52 * @LIBRDF_NODE_TYPE_UNKNOWN: Internal
53 * @LIBRDF_NODE_TYPE_RESOURCE: rdf:Resource (& rdf:Property) - has a URI
54 * @LIBRDF_NODE_TYPE_LITERAL: rdf:Literal - has an XML string, language,
55 * XML space
56 * @LIBRDF_NODE_TYPE_BLANK: blank node has an identifier string.
57 * @LIBRDF_NODE_TYPE_LAST: Internal
58 *
59 * Type of a redland node.
60 *
61 * Better to check this with functions librdf_node_is_resource(),
62 * librdf_node_is_literal() or librdf_node_is_blank().
63 *
64 */
65typedef enum {
66 LIBRDF_NODE_TYPE_UNKNOWN = RAPTOR_TERM_TYPE_UNKNOWN,
67 LIBRDF_NODE_TYPE_RESOURCE = RAPTOR_TERM_TYPE_URI,
68 LIBRDF_NODE_TYPE_LITERAL = RAPTOR_TERM_TYPE_LITERAL,
69 LIBRDF_NODE_TYPE_BLANK = RAPTOR_TERM_TYPE_BLANK,
70 LIBRDF_NODE_TYPE_LAST = LIBRDF_NODE_TYPE_BLANK
71} librdf_node_type;
72
73
74#ifdef LIBRDF_INTERNAL
75#include <rdf_node_internal.h>
76#endif
77
78
79/* Create a new Node. */
80REDLAND_API
81librdf_node* librdf_new_node(librdf_world* world);
82
83/* Create a new resource Node from URI string. */
84REDLAND_API
85librdf_node* librdf_new_node_from_uri_string(librdf_world* world, const unsigned char *uri_string);
86REDLAND_API
87librdf_node* librdf_new_node_from_counted_uri_string(librdf_world* world, const unsigned char *uri_string, size_t len);
88
89/* Create a new resource Node from URI object. */
90REDLAND_API
91librdf_node* librdf_new_node_from_uri(librdf_world* world, librdf_uri *uri);
92
93/* Create a new resource Node from URI object with a local_name */
94REDLAND_API
95librdf_node* librdf_new_node_from_uri_local_name(librdf_world* world, librdf_uri *uri, const unsigned char *local_name);
96
97/* Create a new resource Node from URI string renormalised to a new base */
98REDLAND_API
99librdf_node* librdf_new_node_from_normalised_uri_string(librdf_world* world, const unsigned char *uri_string, librdf_uri *source_uri, librdf_uri *base_uri);
100
101/* Create a new Node from literal string / language. */
102REDLAND_API
103librdf_node* librdf_new_node_from_literal(librdf_world* world, const unsigned char *string, const char *xml_language, int is_wf_xml);
104
105/* Create a new Node from a typed literal string / language. */
106REDLAND_API
107librdf_node* librdf_new_node_from_typed_literal(librdf_world *world, const unsigned char *value, const char *xml_language, librdf_uri* datatype_uri);
108
109REDLAND_API
110librdf_node* librdf_new_node_from_typed_counted_literal(librdf_world *world, const unsigned char *value, size_t value_len, const char *xml_language, size_t xml_language_len, librdf_uri* datatype_uri);
111
112/* Create a new Node from blank node identifier. */
113REDLAND_API
114librdf_node* librdf_new_node_from_blank_identifier(librdf_world* world, const unsigned char *identifier);
115REDLAND_API
116librdf_node* librdf_new_node_from_counted_blank_identifier(librdf_world* world, const unsigned char *identifier, size_t identifier_len);
117
118/* Create a new Node from an existing Node - CLONE */
119REDLAND_API
120librdf_node* librdf_new_node_from_node(librdf_node *node);
121
122/* destructor */
123REDLAND_API
124void librdf_free_node(librdf_node* node);
125
126
127
128/* functions / methods */
129
130REDLAND_API
131librdf_uri* librdf_node_get_uri(librdf_node* node);
132
133REDLAND_API
134librdf_node_type librdf_node_get_type(librdf_node* node);
135
136REDLAND_API
137unsigned char* librdf_node_get_literal_value(librdf_node* node);
138REDLAND_API
139unsigned char* librdf_node_get_literal_value_as_counted_string(librdf_node* node, size_t* len_p);
140REDLAND_API
141char* librdf_node_get_literal_value_as_latin1(librdf_node* node);
142REDLAND_API
143char* librdf_node_get_literal_value_language(librdf_node* node);
144REDLAND_API
145int librdf_node_get_literal_value_is_wf_xml(librdf_node* node);
146REDLAND_API
147librdf_uri* librdf_node_get_literal_value_datatype_uri(librdf_node* node);
148
149REDLAND_API
150int librdf_node_get_li_ordinal(librdf_node* node);
151
152REDLAND_API
153unsigned char *librdf_node_get_blank_identifier(librdf_node* node);
154REDLAND_API
155unsigned char *librdf_node_get_counted_blank_identifier(librdf_node* node, size_t* len_p);
156REDLAND_API
157int librdf_node_is_resource(librdf_node* node);
158REDLAND_API
159int librdf_node_is_literal(librdf_node* node);
160REDLAND_API
161int librdf_node_is_blank(librdf_node* node);
162
163/* serialise / deserialise */
164REDLAND_API
165size_t librdf_node_encode(librdf_node* node, unsigned char *buffer, size_t length);
166REDLAND_API
167librdf_node* librdf_node_decode(librdf_world *world, size_t* size_p, unsigned char *buffer, size_t length);
168
169/* convert to a string */
170REDLAND_API REDLAND_DEPRECATED
171unsigned char *librdf_node_to_string(librdf_node* node);
172REDLAND_API REDLAND_DEPRECATED
173unsigned char* librdf_node_to_counted_string(librdf_node* node, size_t* len_p);
174
175/* pretty print it */
176REDLAND_API
177int librdf_node_write(librdf_node* node, raptor_iostream *iostr);
178REDLAND_API
179void librdf_node_print(librdf_node* node, FILE *fh);
180
181
182/* utility functions */
183REDLAND_API
184int librdf_node_equals(librdf_node* first_node, librdf_node* second_node);
185
186
187/* create an iterator for a static array of nodes */
188REDLAND_API REDLAND_DEPRECATED
189librdf_iterator* librdf_node_static_iterator_create(librdf_node** nodes, int size);
190REDLAND_API
191librdf_iterator* librdf_node_new_static_node_iterator(librdf_world* world, librdf_node** nodes, int size);
192
193
194#ifdef __cplusplus
195}
196#endif
197
198#endif
199