123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #ifndef _LSUP_TERM_H
- #define _LSUP_TERM_H
- #include <assert.h>
- #include <regex.h>
- #include "buffer.h"
- #include "namespace.h"
- #define LANG_SIZE 8
- #define NULL_TRP {NULL_KEY, NULL_KEY, NULL_KEY}
- #define UUID4_URN_SIZE UUIDSTR_SIZE + 10
- typedef XXH64_hash_t LSUP_TermHash64;
- typedef char langtag[LANG_SIZE];
- typedef char LSUP_term_type;
- #define LSUP_TERM_UNDEFINED 0
- #define LSUP_TERM_URI 1
- #define LSUP_TERM_BNODE 2
- #define LSUP_TERM_LITERAL 3
- #define DEFAULT_DTYPE "http://www.w3.org/2001/XMLSchema#string"
- typedef struct term_t {
- char * data;
- char * datatype;
-
- union {
- langtag lang;
-
-
-
-
- uint64_t bnode_id;
- };
- LSUP_term_type type;
- } LSUP_Term;
- LSUP_Term *
- LSUP_term_new(
- LSUP_term_type type, const char *data, char *datatype, char *lang);
- #define TERM_DUMMY LSUP_term_new (LSUP_TERM_UNDEFINED, NULL, NULL, NULL)
- inline LSUP_Term *
- LSUP_uri_new (const char *data)
- {
- if (!data) {
- uuid_t uuid;
- uuid_generate_random (uuid);
- uuid_str_t uuid_str;
- uuid_unparse_lower (uuid, uuid_str);
- char uri[UUID4_URN_SIZE];
- snprintf (uri, UUID4_URN_SIZE, "urn:uuid4:%s", uuid_str);
- data = uri;
- }
- return LSUP_term_new (LSUP_TERM_URI, data, NULL, NULL);
- }
- LSUP_rc
- LSUP_term_init(
- LSUP_Term *term, LSUP_term_type type,
- const char *data, char *datatype, char *lang);
- LSUP_Term *
- LSUP_term_new_from_buffer (const LSUP_Buffer *sterm);
- LSUP_Buffer *
- LSUP_buffer_new_from_term (const LSUP_Term *term);
- inline LSUP_rc
- LSUP_uri_init (LSUP_Term *term, const char *data)
- {
- if (!data) {
- uuid_t uuid;
- uuid_generate_random (uuid);
- uuid_str_t uuid_str;
- uuid_unparse_lower (uuid, uuid_str);
- char uri[UUIDSTR_SIZE + 10];
- sprintf (uri, "urn:uuid4:%s", uuid_str);
- data = uri;
- }
- return LSUP_term_init (term, LSUP_TERM_URI, data, NULL, NULL);
- }
- LSUP_rc
- LSUP_term_serialize (const LSUP_Term *term, LSUP_Buffer *sterm);
- LSUP_rc
- LSUP_term_deserialize (const LSUP_Buffer *sterm, LSUP_Term *term);
- inline LSUP_Key
- LSUP_term_hash (const LSUP_Term *term)
- {
- LSUP_Buffer *buf;
- if (UNLIKELY (!term)) buf = BUF_DUMMY;
- else buf = LSUP_buffer_new_from_term (term);
- LSUP_Key key = LSUP_buffer_hash (buf);
- LSUP_buffer_free (buf);
- return key;
- }
- bool LSUP_term_equals (const LSUP_Term *term1, const LSUP_Term *term2);
- void
- LSUP_term_done (LSUP_Term *term);
- void
- LSUP_term_free (LSUP_Term *term);
- #endif
|