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 37 extern "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 */ 65 typedef 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. */ 80 REDLAND_API 81 librdf_node* librdf_new_node(librdf_world* world); 82 83 /* Create a new resource Node from URI string. */ 84 REDLAND_API 85 librdf_node* librdf_new_node_from_uri_string(librdf_world* world, const unsigned char *uri_string); 86 REDLAND_API 87 librdf_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. */ 90 REDLAND_API 91 librdf_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 */ 94 REDLAND_API 95 librdf_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 */ 98 REDLAND_API 99 librdf_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. */ 102 REDLAND_API 103 librdf_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. */ 106 REDLAND_API 107 librdf_node* librdf_new_node_from_typed_literal(librdf_world *world, const unsigned char *value, const char *xml_language, librdf_uri* datatype_uri); 108 109 REDLAND_API 110 librdf_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. */ 113 REDLAND_API 114 librdf_node* librdf_new_node_from_blank_identifier(librdf_world* world, const unsigned char *identifier); 115 REDLAND_API 116 librdf_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 */ 119 REDLAND_API 120 librdf_node* librdf_new_node_from_node(librdf_node *node); 121 122 /* destructor */ 123 REDLAND_API 124 void librdf_free_node(librdf_node* node); 125 126 127 128 /* functions / methods */ 129 130 REDLAND_API 131 librdf_uri* librdf_node_get_uri(librdf_node* node); 132 133 REDLAND_API 134 librdf_node_type librdf_node_get_type(librdf_node* node); 135 136 REDLAND_API 137 unsigned char* librdf_node_get_literal_value(librdf_node* node); 138 REDLAND_API 139 unsigned char* librdf_node_get_literal_value_as_counted_string(librdf_node* node, size_t* len_p); 140 REDLAND_API 141 char* librdf_node_get_literal_value_as_latin1(librdf_node* node); 142 REDLAND_API 143 char* librdf_node_get_literal_value_language(librdf_node* node); 144 REDLAND_API 145 int librdf_node_get_literal_value_is_wf_xml(librdf_node* node); 146 REDLAND_API 147 librdf_uri* librdf_node_get_literal_value_datatype_uri(librdf_node* node); 148 149 REDLAND_API 150 int librdf_node_get_li_ordinal(librdf_node* node); 151 152 REDLAND_API 153 unsigned char *librdf_node_get_blank_identifier(librdf_node* node); 154 REDLAND_API 155 unsigned char *librdf_node_get_counted_blank_identifier(librdf_node* node, size_t* len_p); 156 REDLAND_API 157 int librdf_node_is_resource(librdf_node* node); 158 REDLAND_API 159 int librdf_node_is_literal(librdf_node* node); 160 REDLAND_API 161 int librdf_node_is_blank(librdf_node* node); 162 163 /* serialise / deserialise */ 164 REDLAND_API 165 size_t librdf_node_encode(librdf_node* node, unsigned char *buffer, size_t length); 166 REDLAND_API 167 librdf_node* librdf_node_decode(librdf_world *world, size_t* size_p, unsigned char *buffer, size_t length); 168 169 /* convert to a string */ 170 REDLAND_API REDLAND_DEPRECATED 171 unsigned char *librdf_node_to_string(librdf_node* node); 172 REDLAND_API REDLAND_DEPRECATED 173 unsigned char* librdf_node_to_counted_string(librdf_node* node, size_t* len_p); 174 175 /* pretty print it */ 176 REDLAND_API 177 int librdf_node_write(librdf_node* node, raptor_iostream *iostr); 178 REDLAND_API 179 void librdf_node_print(librdf_node* node, FILE *fh); 180 181 182 /* utility functions */ 183 REDLAND_API 184 int librdf_node_equals(librdf_node* first_node, librdf_node* second_node); 185 186 187 /* create an iterator for a static array of nodes */ 188 REDLAND_API REDLAND_DEPRECATED 189 librdf_iterator* librdf_node_static_iterator_create(librdf_node** nodes, int size); 190 REDLAND_API 191 librdf_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