meta: rename to fx
This commit is contained in:
114
ds/uuid.c
114
ds/uuid.c
@@ -1,6 +1,6 @@
|
||||
#include <blue/core/stringstream.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <blue/ds/uuid.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/ds/uuid.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -8,17 +8,17 @@
|
||||
|
||||
/*** PRIVATE DATA *************************************************************/
|
||||
|
||||
struct b_uuid_p {
|
||||
union b_uuid_bytes uuid_bytes;
|
||||
struct fx_uuid_p {
|
||||
union fx_uuid_bytes uuid_bytes;
|
||||
};
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
static b_status uuid_to_cstr(
|
||||
const struct b_uuid_p *uuid, char out[B_UUID_STRING_MAX])
|
||||
static fx_status uuid_to_cstr(
|
||||
const struct fx_uuid_p *uuid, char out[FX_UUID_STRING_MAX])
|
||||
{
|
||||
snprintf(
|
||||
out, B_UUID_STRING_MAX,
|
||||
out, FX_UUID_STRING_MAX,
|
||||
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%"
|
||||
"02x%02x",
|
||||
uuid->uuid_bytes.uuid_bytes[0], uuid->uuid_bytes.uuid_bytes[1],
|
||||
@@ -29,41 +29,41 @@ static b_status uuid_to_cstr(
|
||||
uuid->uuid_bytes.uuid_bytes[10], uuid->uuid_bytes.uuid_bytes[11],
|
||||
uuid->uuid_bytes.uuid_bytes[12], uuid->uuid_bytes.uuid_bytes[13],
|
||||
uuid->uuid_bytes.uuid_bytes[14], uuid->uuid_bytes.uuid_bytes[15]);
|
||||
return B_SUCCESS;
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static void uuid_get_bytes(
|
||||
const struct b_uuid_p *uuid, unsigned char bytes[B_UUID_NBYTES])
|
||||
const struct fx_uuid_p *uuid, unsigned char bytes[FX_UUID_NBYTES])
|
||||
{
|
||||
memcpy(bytes, uuid->uuid_bytes.uuid_bytes, B_UUID_NBYTES);
|
||||
memcpy(bytes, uuid->uuid_bytes.uuid_bytes, FX_UUID_NBYTES);
|
||||
}
|
||||
|
||||
static void uuid_get_uuid_bytes(
|
||||
const struct b_uuid_p *uuid, union b_uuid_bytes *bytes)
|
||||
const struct fx_uuid_p *uuid, union fx_uuid_bytes *bytes)
|
||||
{
|
||||
memcpy(bytes, &uuid->uuid_bytes, sizeof *bytes);
|
||||
}
|
||||
|
||||
static union b_uuid_bytes *uuid_ptr(struct b_uuid_p *uuid)
|
||||
static union fx_uuid_bytes *uuid_ptr(struct fx_uuid_p *uuid)
|
||||
{
|
||||
return &uuid->uuid_bytes;
|
||||
}
|
||||
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
b_uuid *b_uuid_create_from_bytes(
|
||||
fx_uuid *fx_uuid_create_from_bytes(
|
||||
unsigned char u00, unsigned char u01, unsigned char u02,
|
||||
unsigned char u03, unsigned char u04, unsigned char u05,
|
||||
unsigned char u06, unsigned char u07, unsigned char u08,
|
||||
unsigned char u09, unsigned char u10, unsigned char u11,
|
||||
unsigned char u12, unsigned char u13, unsigned char u14, unsigned char u15)
|
||||
{
|
||||
b_uuid *uuid = b_uuid_create();
|
||||
fx_uuid *uuid = fx_uuid_create();
|
||||
if (!uuid) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct b_uuid_p *p = b_object_get_private(uuid, B_TYPE_UUID);
|
||||
struct fx_uuid_p *p = fx_object_get_private(uuid, FX_TYPE_UUID);
|
||||
|
||||
p->uuid_bytes.uuid_bytes[0] = u00;
|
||||
p->uuid_bytes.uuid_bytes[1] = u01;
|
||||
@@ -85,23 +85,23 @@ b_uuid *b_uuid_create_from_bytes(
|
||||
return uuid;
|
||||
}
|
||||
|
||||
b_uuid *b_uuid_create_from_bytev(const unsigned char bytes[B_UUID_NBYTES])
|
||||
fx_uuid *fx_uuid_create_from_bytev(const unsigned char bytes[FX_UUID_NBYTES])
|
||||
{
|
||||
b_uuid *uuid = b_uuid_create();
|
||||
fx_uuid *uuid = fx_uuid_create();
|
||||
if (!uuid) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct b_uuid_p *p = b_object_get_private(uuid, B_TYPE_UUID);
|
||||
struct fx_uuid_p *p = fx_object_get_private(uuid, FX_TYPE_UUID);
|
||||
|
||||
memcpy(p->uuid_bytes.uuid_bytes, bytes, B_UUID_NBYTES);
|
||||
memcpy(p->uuid_bytes.uuid_bytes, bytes, FX_UUID_NBYTES);
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
b_uuid *b_uuid_create_from_cstr(const char *str)
|
||||
fx_uuid *fx_uuid_create_from_cstr(const char *str)
|
||||
{
|
||||
union b_uuid_bytes bytes;
|
||||
union fx_uuid_bytes bytes;
|
||||
|
||||
bool valid = true;
|
||||
bool is_guid = false;
|
||||
@@ -111,7 +111,7 @@ b_uuid *b_uuid_create_from_cstr(const char *str)
|
||||
}
|
||||
|
||||
size_t i, byte = 0;
|
||||
for (i = 0; str[i] && byte < B_UUID_NBYTES;) {
|
||||
for (i = 0; str[i] && byte < FX_UUID_NBYTES;) {
|
||||
if (i == 8 || i == 13 || i == 18 || i == 23) {
|
||||
if (str[i] != '-') {
|
||||
valid = false;
|
||||
@@ -148,7 +148,7 @@ b_uuid *b_uuid_create_from_cstr(const char *str)
|
||||
}
|
||||
}
|
||||
|
||||
if (str[i] != '\0' || byte != B_UUID_NBYTES) {
|
||||
if (str[i] != '\0' || byte != FX_UUID_NBYTES) {
|
||||
valid = false;
|
||||
}
|
||||
|
||||
@@ -156,72 +156,72 @@ b_uuid *b_uuid_create_from_cstr(const char *str)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_uuid_create_from_uuid_bytes(&bytes);
|
||||
return fx_uuid_create_from_uuid_bytes(&bytes);
|
||||
}
|
||||
|
||||
b_status b_uuid_to_cstr(const b_uuid *uuid, char out[B_UUID_STRING_MAX])
|
||||
fx_status fx_uuid_to_cstr(const fx_uuid *uuid, char out[FX_UUID_STRING_MAX])
|
||||
{
|
||||
B_CLASS_DISPATCH_STATIC(B_TYPE_UUID, uuid_to_cstr, uuid, out);
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_UUID, uuid_to_cstr, uuid, out);
|
||||
}
|
||||
|
||||
void b_uuid_get_bytes(const b_uuid *uuid, unsigned char bytes[B_UUID_NBYTES])
|
||||
void fx_uuid_get_bytes(const fx_uuid *uuid, unsigned char bytes[FX_UUID_NBYTES])
|
||||
{
|
||||
B_CLASS_DISPATCH_STATIC(B_TYPE_UUID, uuid_get_bytes, uuid, bytes);
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_UUID, uuid_get_bytes, uuid, bytes);
|
||||
}
|
||||
|
||||
void b_uuid_get_uuid_bytes(const b_uuid *uuid, union b_uuid_bytes *bytes)
|
||||
void fx_uuid_get_uuid_bytes(const fx_uuid *uuid, union fx_uuid_bytes *bytes)
|
||||
{
|
||||
B_CLASS_DISPATCH_STATIC(B_TYPE_UUID, uuid_get_uuid_bytes, uuid, bytes);
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_UUID, uuid_get_uuid_bytes, uuid, bytes);
|
||||
}
|
||||
|
||||
union b_uuid_bytes *b_uuid_ptr(b_uuid *uuid)
|
||||
union fx_uuid_bytes *fx_uuid_ptr(fx_uuid *uuid)
|
||||
{
|
||||
B_CLASS_DISPATCH_STATIC_0(B_TYPE_UUID, uuid_ptr, uuid);
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_UUID, uuid_ptr, uuid);
|
||||
}
|
||||
|
||||
/*** PUBLIC ALIAS FUNCTIONS ***************************************************/
|
||||
|
||||
b_uuid *b_uuid_create_from_uuid_bytes(const union b_uuid_bytes *bytes)
|
||||
fx_uuid *fx_uuid_create_from_uuid_bytes(const union fx_uuid_bytes *bytes)
|
||||
{
|
||||
return b_uuid_create_from_bytev(bytes->uuid_bytes);
|
||||
return fx_uuid_create_from_bytev(bytes->uuid_bytes);
|
||||
}
|
||||
|
||||
b_uuid *b_uuid_create_from_string(const b_string *string)
|
||||
fx_uuid *fx_uuid_create_from_string(const fx_string *string)
|
||||
{
|
||||
return b_uuid_create_from_cstr(b_string_ptr(string));
|
||||
return fx_uuid_create_from_cstr(fx_string_ptr(string));
|
||||
}
|
||||
|
||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||
|
||||
static void uuid_init(b_object *obj, void *priv)
|
||||
static void uuid_init(fx_object *obj, void *priv)
|
||||
{
|
||||
struct b_uuid_p *uuid = priv;
|
||||
struct fx_uuid_p *uuid = priv;
|
||||
}
|
||||
|
||||
static void uuid_fini(b_object *obj, void *priv)
|
||||
static void uuid_fini(fx_object *obj, void *priv)
|
||||
{
|
||||
struct b_uuid_p *uuid = priv;
|
||||
struct fx_uuid_p *uuid = priv;
|
||||
}
|
||||
|
||||
static void uuid_to_string(const b_object *uuid, b_stream *out)
|
||||
static void uuid_to_string(const fx_object *uuid, fx_stream *out)
|
||||
{
|
||||
char str[B_UUID_STRING_MAX];
|
||||
b_uuid_to_cstr(uuid, str);
|
||||
b_stream_write_string(out, str, NULL);
|
||||
char str[FX_UUID_STRING_MAX];
|
||||
fx_uuid_to_cstr(uuid, str);
|
||||
fx_stream_write_string(out, str, NULL);
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
B_TYPE_CLASS_DEFINITION_BEGIN(b_uuid)
|
||||
B_TYPE_CLASS_INTERFACE_BEGIN(b_object, B_TYPE_OBJECT)
|
||||
B_INTERFACE_ENTRY(to_string) = uuid_to_string;
|
||||
B_TYPE_CLASS_INTERFACE_END(b_object, B_TYPE_OBJECT)
|
||||
B_TYPE_CLASS_DEFINITION_END(b_uuid)
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_uuid)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = uuid_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_uuid)
|
||||
|
||||
B_TYPE_DEFINITION_BEGIN(b_uuid)
|
||||
B_TYPE_ID(0x17037068, 0x92f7, 0x4582, 0xad1f, 0x0dea43b628de);
|
||||
B_TYPE_CLASS(b_uuid_class);
|
||||
B_TYPE_INSTANCE_PRIVATE(struct b_uuid_p);
|
||||
B_TYPE_INSTANCE_INIT(uuid_init);
|
||||
B_TYPE_INSTANCE_FINI(uuid_fini);
|
||||
B_TYPE_DEFINITION_END(b_uuid)
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_uuid)
|
||||
FX_TYPE_ID(0x17037068, 0x92f7, 0x4582, 0xad1f, 0x0dea43b628de);
|
||||
FX_TYPE_CLASS(fx_uuid_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_uuid_p);
|
||||
FX_TYPE_INSTANCE_INIT(uuid_init);
|
||||
FX_TYPE_INSTANCE_FINI(uuid_fini);
|
||||
FX_TYPE_DEFINITION_END(fx_uuid)
|
||||
|
||||
Reference in New Issue
Block a user