summaryrefslogtreecommitdiffstats
path: root/src/value.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-04-28 21:56:29 +0000
committerDavid Robillard <d@drobilla.net>2011-04-28 21:56:29 +0000
commit809f5ae5999901be62f9d0cc1eb8a2d0f4806780 (patch)
tree4a2c1a7b344ec0f0a75d6a64ed1177a61822af89 /src/value.c
parent372ad8bcac948087bbc261933e38868f533c6708 (diff)
downloadlilv-809f5ae5999901be62f9d0cc1eb8a2d0f4806780.tar.gz
lilv-809f5ae5999901be62f9d0cc1eb8a2d0f4806780.tar.bz2
lilv-809f5ae5999901be62f9d0cc1eb8a2d0f4806780.zip
Rename slv2 to lilv.
API breakage was proving too much of a hassle, and would be even further of a mess after release and packaging. Best to make a clean break now, and fix installation to support parallel installs and prevent this kind of problem in the future. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3217 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/value.c')
-rw-r--r--src/value.c280
1 files changed, 140 insertions, 140 deletions
diff --git a/src/value.c b/src/value.c
index 486182e..991f681 100644
--- a/src/value.c
+++ b/src/value.c
@@ -23,116 +23,116 @@
#include <glib.h>
-#include "slv2_internal.h"
+#include "lilv_internal.h"
static void
-slv2_value_set_numerics_from_string(SLV2Value val)
+lilv_value_set_numerics_from_string(LilvValue val)
{
char* locale;
char* endptr;
switch (val->type) {
- case SLV2_VALUE_URI:
- case SLV2_VALUE_BLANK:
- case SLV2_VALUE_QNAME_UNUSED:
- case SLV2_VALUE_STRING:
+ case LILV_VALUE_URI:
+ case LILV_VALUE_BLANK:
+ case LILV_VALUE_QNAME_UNUSED:
+ case LILV_VALUE_STRING:
break;
- case SLV2_VALUE_INT:
+ case LILV_VALUE_INT:
// FIXME: locale kludge, need a locale independent strtol
- locale = slv2_strdup(setlocale(LC_NUMERIC, NULL));
+ locale = lilv_strdup(setlocale(LC_NUMERIC, NULL));
setlocale(LC_NUMERIC, "POSIX");
val->val.int_val = strtol(val->str_val, &endptr, 10);
setlocale(LC_NUMERIC, locale);
free(locale);
break;
- case SLV2_VALUE_FLOAT:
+ case LILV_VALUE_FLOAT:
// FIXME: locale kludge, need a locale independent strtod
- locale = slv2_strdup(setlocale(LC_NUMERIC, NULL));
+ locale = lilv_strdup(setlocale(LC_NUMERIC, NULL));
setlocale(LC_NUMERIC, "POSIX");
val->val.float_val = strtod(val->str_val, &endptr);
setlocale(LC_NUMERIC, locale);
free(locale);
break;
- case SLV2_VALUE_BOOL:
+ case LILV_VALUE_BOOL:
val->val.bool_val = (!strcmp(val->str_val, "true"));
break;
}
}
/** Note that if @a type is numeric or boolean, the returned value is corrupt
- * until slv2_value_set_numerics_from_string is called. It is not
+ * until lilv_value_set_numerics_from_string is called. It is not
* automatically called from here to avoid overhead and imprecision when the
* exact string value is known.
*/
-SLV2Value
-slv2_value_new(SLV2World world, SLV2ValueType type, const char* str)
+LilvValue
+lilv_value_new(LilvWorld world, LilvValueType type, const char* str)
{
- SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value));
+ LilvValue val = (LilvValue)malloc(sizeof(struct _LilvValue));
val->world = world;
val->type = type;
switch (type) {
- case SLV2_VALUE_URI:
+ case LILV_VALUE_URI:
val->val.uri_val = sord_new_uri(world->world, (const uint8_t*)str);
assert(val->val.uri_val);
val->str_val = (char*)sord_node_get_string(val->val.uri_val);
break;
- case SLV2_VALUE_QNAME_UNUSED:
- case SLV2_VALUE_BLANK:
- case SLV2_VALUE_STRING:
- case SLV2_VALUE_INT:
- case SLV2_VALUE_FLOAT:
- case SLV2_VALUE_BOOL:
- val->str_val = slv2_strdup(str);
+ case LILV_VALUE_QNAME_UNUSED:
+ case LILV_VALUE_BLANK:
+ case LILV_VALUE_STRING:
+ case LILV_VALUE_INT:
+ case LILV_VALUE_FLOAT:
+ case LILV_VALUE_BOOL:
+ val->str_val = lilv_strdup(str);
break;
}
return val;
}
-/** Create a new SLV2Value from @a node, or return NULL if impossible */
-SLV2Value
-slv2_value_new_from_node(SLV2World world, const SordNode* node)
+/** Create a new LilvValue from @a node, or return NULL if impossible */
+LilvValue
+lilv_value_new_from_node(LilvWorld world, const SordNode* node)
{
- SLV2Value result = NULL;
+ LilvValue result = NULL;
SordNode* datatype_uri = NULL;
- SLV2ValueType type = SLV2_VALUE_STRING;
+ LilvValueType type = LILV_VALUE_STRING;
switch (sord_node_get_type(node)) {
case SORD_URI:
- type = SLV2_VALUE_URI;
- result = (SLV2Value)malloc(sizeof(struct _SLV2Value));
+ type = LILV_VALUE_URI;
+ result = (LilvValue)malloc(sizeof(struct _LilvValue));
result->world = world;
- result->type = SLV2_VALUE_URI;
- result->val.uri_val = slv2_node_copy(node);
+ result->type = LILV_VALUE_URI;
+ result->val.uri_val = lilv_node_copy(node);
result->str_val = (char*)sord_node_get_string(result->val.uri_val);
break;
case SORD_LITERAL:
datatype_uri = sord_node_get_datatype(node);
if (datatype_uri) {
if (sord_node_equals(datatype_uri, world->xsd_boolean_node))
- type = SLV2_VALUE_BOOL;
+ type = LILV_VALUE_BOOL;
else if (sord_node_equals(datatype_uri, world->xsd_decimal_node)
|| sord_node_equals(datatype_uri, world->xsd_double_node))
- type = SLV2_VALUE_FLOAT;
+ type = LILV_VALUE_FLOAT;
else if (sord_node_equals(datatype_uri, world->xsd_integer_node))
- type = SLV2_VALUE_INT;
+ type = LILV_VALUE_INT;
else
- SLV2_ERRORF("Unknown datatype %s\n", sord_node_get_string(datatype_uri));
+ LILV_ERRORF("Unknown datatype %s\n", sord_node_get_string(datatype_uri));
}
- result = slv2_value_new(world, type, (const char*)sord_node_get_string(node));
+ result = lilv_value_new(world, type, (const char*)sord_node_get_string(node));
switch (result->type) {
- case SLV2_VALUE_INT:
- case SLV2_VALUE_FLOAT:
- case SLV2_VALUE_BOOL:
- slv2_value_set_numerics_from_string(result);
+ case LILV_VALUE_INT:
+ case LILV_VALUE_FLOAT:
+ case LILV_VALUE_BOOL:
+ lilv_value_set_numerics_from_string(result);
default:
break;
}
break;
case SORD_BLANK:
- type = SLV2_VALUE_BLANK;
- result = slv2_value_new(world, type, (const char*)sord_node_get_string(node));
+ type = LILV_VALUE_BLANK;
+ result = lilv_value_new(world, type, (const char*)sord_node_get_string(node));
break;
default:
assert(false);
@@ -141,80 +141,80 @@ slv2_value_new_from_node(SLV2World world, const SordNode* node)
return result;
}
-SLV2_API
-SLV2Value
-slv2_value_new_uri(SLV2World world, const char* uri)
+LILV_API
+LilvValue
+lilv_value_new_uri(LilvWorld world, const char* uri)
{
- return slv2_value_new(world, SLV2_VALUE_URI, uri);
+ return lilv_value_new(world, LILV_VALUE_URI, uri);
}
-SLV2_API
-SLV2Value
-slv2_value_new_string(SLV2World world, const char* str)
+LILV_API
+LilvValue
+lilv_value_new_string(LilvWorld world, const char* str)
{
- return slv2_value_new(world, SLV2_VALUE_STRING, str);
+ return lilv_value_new(world, LILV_VALUE_STRING, str);
}
-SLV2_API
-SLV2Value
-slv2_value_new_int(SLV2World world, int val)
+LILV_API
+LilvValue
+lilv_value_new_int(LilvWorld world, int val)
{
char str[32];
snprintf(str, sizeof(str), "%d", val);
- SLV2Value ret = slv2_value_new(world, SLV2_VALUE_INT, str);
+ LilvValue ret = lilv_value_new(world, LILV_VALUE_INT, str);
ret->val.int_val = val;
return ret;
}
-SLV2_API
-SLV2Value
-slv2_value_new_float(SLV2World world, float val)
+LILV_API
+LilvValue
+lilv_value_new_float(LilvWorld world, float val)
{
char str[32];
snprintf(str, sizeof(str), "%f", val);
- SLV2Value ret = slv2_value_new(world, SLV2_VALUE_FLOAT, str);
+ LilvValue ret = lilv_value_new(world, LILV_VALUE_FLOAT, str);
ret->val.float_val = val;
return ret;
}
-SLV2_API
-SLV2Value
-slv2_value_new_bool(SLV2World world, bool val)
+LILV_API
+LilvValue
+lilv_value_new_bool(LilvWorld world, bool val)
{
- SLV2Value ret = slv2_value_new(world, SLV2_VALUE_BOOL, val ? "true" : "false");
+ LilvValue ret = lilv_value_new(world, LILV_VALUE_BOOL, val ? "true" : "false");
ret->val.bool_val = val;
return ret;
}
-SLV2_API
-SLV2Value
-slv2_value_duplicate(SLV2Value val)
+LILV_API
+LilvValue
+lilv_value_duplicate(LilvValue val)
{
if (val == NULL)
return val;
- SLV2Value result = (SLV2Value)malloc(sizeof(struct _SLV2Value));
+ LilvValue result = (LilvValue)malloc(sizeof(struct _LilvValue));
result->world = val->world;
result->type = val->type;
- if (val->type == SLV2_VALUE_URI) {
- result->val.uri_val = slv2_node_copy(val->val.uri_val);
+ if (val->type == LILV_VALUE_URI) {
+ result->val.uri_val = lilv_node_copy(val->val.uri_val);
result->str_val = (char*)sord_node_get_string(result->val.uri_val);
} else {
- result->str_val = slv2_strdup(val->str_val);
+ result->str_val = lilv_strdup(val->str_val);
result->val = val->val;
}
return result;
}
-SLV2_API
+LILV_API
void
-slv2_value_free(SLV2Value val)
+lilv_value_free(LilvValue val)
{
if (val) {
- if (val->type == SLV2_VALUE_URI) {
- slv2_node_free(val->world, val->val.uri_val);
+ if (val->type == LILV_VALUE_URI) {
+ lilv_node_free(val->world, val->val.uri_val);
} else {
free(val->str_val);
}
@@ -222,9 +222,9 @@ slv2_value_free(SLV2Value val)
}
}
-SLV2_API
+LILV_API
bool
-slv2_value_equals(SLV2Value value, SLV2Value other)
+lilv_value_equals(LilvValue value, LilvValue other)
{
if (value == NULL && other == NULL)
return true;
@@ -234,60 +234,60 @@ slv2_value_equals(SLV2Value value, SLV2Value other)
return false;
switch (value->type) {
- case SLV2_VALUE_URI:
+ case LILV_VALUE_URI:
return sord_node_equals(value->val.uri_val, other->val.uri_val);
- case SLV2_VALUE_BLANK:
- case SLV2_VALUE_STRING:
- case SLV2_VALUE_QNAME_UNUSED:
+ case LILV_VALUE_BLANK:
+ case LILV_VALUE_STRING:
+ case LILV_VALUE_QNAME_UNUSED:
return !strcmp(value->str_val, other->str_val);
- case SLV2_VALUE_INT:
+ case LILV_VALUE_INT:
return (value->val.int_val == other->val.int_val);
- case SLV2_VALUE_FLOAT:
+ case LILV_VALUE_FLOAT:
return (value->val.float_val == other->val.float_val);
- case SLV2_VALUE_BOOL:
+ case LILV_VALUE_BOOL:
return (value->val.bool_val == other->val.bool_val);
}
return false; /* shouldn't get here */
}
-SLV2_API
+LILV_API
char*
-slv2_value_get_turtle_token(SLV2Value value)
+lilv_value_get_turtle_token(LilvValue value)
{
size_t len = 0;
char* result = NULL;
char* locale = NULL;
switch (value->type) {
- case SLV2_VALUE_URI:
+ case LILV_VALUE_URI:
len = strlen(value->str_val) + 3;
result = calloc(len, 1);
snprintf(result, len, "<%s>", value->str_val);
break;
- case SLV2_VALUE_BLANK:
+ case LILV_VALUE_BLANK:
len = strlen(value->str_val) + 3;
result = calloc(len, 1);
snprintf(result, len, "_:%s", value->str_val);
break;
- case SLV2_VALUE_STRING:
- case SLV2_VALUE_QNAME_UNUSED:
- case SLV2_VALUE_BOOL:
- result = slv2_strdup(value->str_val);
+ case LILV_VALUE_STRING:
+ case LILV_VALUE_QNAME_UNUSED:
+ case LILV_VALUE_BOOL:
+ result = lilv_strdup(value->str_val);
break;
- case SLV2_VALUE_INT:
+ case LILV_VALUE_INT:
// INT64_MAX is 9223372036854775807 (19 digits) + 1 for sign
// FIXME: locale kludge, need a locale independent snprintf
- locale = slv2_strdup(setlocale(LC_NUMERIC, NULL));
+ locale = lilv_strdup(setlocale(LC_NUMERIC, NULL));
len = 20;
result = calloc(len, 1);
setlocale(LC_NUMERIC, "POSIX");
snprintf(result, len, "%d", value->val.int_val);
setlocale(LC_NUMERIC, locale);
break;
- case SLV2_VALUE_FLOAT:
+ case LILV_VALUE_FLOAT:
// FIXME: locale kludge, need a locale independent snprintf
- locale = slv2_strdup(setlocale(LC_NUMERIC, NULL));
+ locale = lilv_strdup(setlocale(LC_NUMERIC, NULL));
len = 20; // FIXME: proper maximum value?
result = calloc(len, 1);
setlocale(LC_NUMERIC, "POSIX");
@@ -301,120 +301,120 @@ slv2_value_get_turtle_token(SLV2Value value)
return result;
}
-SLV2_API
+LILV_API
bool
-slv2_value_is_uri(SLV2Value value)
+lilv_value_is_uri(LilvValue value)
{
- return (value && value->type == SLV2_VALUE_URI);
+ return (value && value->type == LILV_VALUE_URI);
}
-SLV2_API
+LILV_API
const char*
-slv2_value_as_uri(SLV2Value value)
+lilv_value_as_uri(LilvValue value)
{
- assert(slv2_value_is_uri(value));
+ assert(lilv_value_is_uri(value));
return value->str_val;
}
-SLV2Node
-slv2_value_as_node(SLV2Value value)
+LilvNode
+lilv_value_as_node(LilvValue value)
{
- assert(slv2_value_is_uri(value));
+ assert(lilv_value_is_uri(value));
return value->val.uri_val;
}
-SLV2_API
+LILV_API
bool
-slv2_value_is_blank(SLV2Value value)
+lilv_value_is_blank(LilvValue value)
{
- return (value && value->type == SLV2_VALUE_BLANK);
+ return (value && value->type == LILV_VALUE_BLANK);
}
-SLV2_API
+LILV_API
const char*
-slv2_value_as_blank(SLV2Value value)
+lilv_value_as_blank(LilvValue value)
{
- assert(slv2_value_is_blank(value));
+ assert(lilv_value_is_blank(value));
return value->str_val;
}
-SLV2_API
+LILV_API
bool
-slv2_value_is_literal(SLV2Value value)
+lilv_value_is_literal(LilvValue value)
{
if (!value)
return false;
switch (value->type) {
- case SLV2_VALUE_STRING:
- case SLV2_VALUE_INT:
- case SLV2_VALUE_FLOAT:
+ case LILV_VALUE_STRING:
+ case LILV_VALUE_INT:
+ case LILV_VALUE_FLOAT:
return true;
default:
return false;
}
}
-SLV2_API
+LILV_API
bool
-slv2_value_is_string(SLV2Value value)
+lilv_value_is_string(LilvValue value)
{
- return (value && value->type == SLV2_VALUE_STRING);
+ return (value && value->type == LILV_VALUE_STRING);
}
-SLV2_API
+LILV_API
const char*
-slv2_value_as_string(SLV2Value value)
+lilv_value_as_string(LilvValue value)
{
return value->str_val;
}
-SLV2_API
+LILV_API
bool
-slv2_value_is_int(SLV2Value value)
+lilv_value_is_int(LilvValue value)
{
- return (value && value->type == SLV2_VALUE_INT);
+ return (value && value->type == LILV_VALUE_INT);
}
-SLV2_API
+LILV_API
int
-slv2_value_as_int(SLV2Value value)
+lilv_value_as_int(LilvValue value)
{
assert(value);
- assert(slv2_value_is_int(value));
+ assert(lilv_value_is_int(value));
return value->val.int_val;
}
-SLV2_API
+LILV_API
bool
-slv2_value_is_float(SLV2Value value)
+lilv_value_is_float(LilvValue value)
{
- return (value && value->type == SLV2_VALUE_FLOAT);
+ return (value && value->type == LILV_VALUE_FLOAT);
}
-SLV2_API
+LILV_API
float
-slv2_value_as_float(SLV2Value value)
+lilv_value_as_float(LilvValue value)
{
- assert(slv2_value_is_float(value) || slv2_value_is_int(value));
- if (slv2_value_is_float(value))
+ assert(lilv_value_is_float(value) || lilv_value_is_int(value));
+ if (lilv_value_is_float(value))
return value->val.float_val;
- else // slv2_value_is_int(value)
+ else // lilv_value_is_int(value)
return (float)value->val.int_val;
}
-SLV2_API
+LILV_API
bool
-slv2_value_is_bool(SLV2Value value)
+lilv_value_is_bool(LilvValue value)
{
- return (value && value->type == SLV2_VALUE_BOOL);
+ return (value && value->type == LILV_VALUE_BOOL);
}
-SLV2_API
+LILV_API
bool
-slv2_value_as_bool(SLV2Value value)
+lilv_value_as_bool(LilvValue value)
{
assert(value);
- assert(slv2_value_is_bool(value));
+ assert(lilv_value_is_bool(value));
return value->val.bool_val;
}