277 lines
5.1 KiB
C
277 lines
5.1 KiB
C
#include <fx/bool.h>
|
|
#include <fx/double.h>
|
|
#include <fx/int.h>
|
|
#include <fx/string.h>
|
|
#include <fx/uint.h>
|
|
#include <fx/value.h>
|
|
|
|
void fx_value_init(fx_value *v, fx_type type)
|
|
{
|
|
}
|
|
|
|
void fx_value_init_primitive(fx_value *v, fx_value_type type)
|
|
{
|
|
}
|
|
|
|
void fx_value_copy(fx_value *dst, fx_value *src)
|
|
{
|
|
memcpy(dst, src, sizeof *dst);
|
|
|
|
if (dst->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
fx_object_ref(dst->v_object);
|
|
}
|
|
}
|
|
|
|
void fx_value_copy_array(fx_value *dst, fx_value *src, size_t count)
|
|
{
|
|
for (size_t i = 0; i < count; i++) {
|
|
fx_value_copy(dst + i, src + i);
|
|
}
|
|
}
|
|
|
|
void fx_value_unset(fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
fx_object_unref(v->v_object);
|
|
}
|
|
|
|
memset(v, 0x0, sizeof *v);
|
|
}
|
|
|
|
void fx_value_unset_array(fx_value *v, size_t count)
|
|
{
|
|
for (size_t i = 0; i < count; i++) {
|
|
fx_value_unset(v + i);
|
|
}
|
|
}
|
|
|
|
void fx_value_set_bool(fx_value *v, bool b)
|
|
{
|
|
}
|
|
|
|
void fx_value_set_int(fx_value *v, intptr_t i)
|
|
{
|
|
}
|
|
|
|
void fx_value_set_uint(fx_value *v, uintptr_t u)
|
|
{
|
|
}
|
|
|
|
void fx_value_set_double(fx_value *v, double d)
|
|
{
|
|
}
|
|
|
|
void fx_value_set_static_cstr(fx_value *v, const char *cstr)
|
|
{
|
|
}
|
|
|
|
void fx_value_set_pointer(fx_value *v, void *p)
|
|
{
|
|
}
|
|
|
|
void fx_value_set_object(fx_value *v, fx_object *obj)
|
|
{
|
|
}
|
|
|
|
bool fx_value_is_bool(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_BOOL) {
|
|
return true;
|
|
}
|
|
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
if (fx_type_id_compare(v->v_type.t_object, FX_TYPE_BOOL)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool fx_value_is_int(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_INT) {
|
|
return true;
|
|
}
|
|
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
if (fx_type_id_compare(v->v_type.t_object, FX_TYPE_INT)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool fx_value_is_uint(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_UINT) {
|
|
return true;
|
|
}
|
|
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
if (fx_type_id_compare(v->v_type.t_object, FX_TYPE_UINT)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool fx_value_is_double(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_DOUBLE) {
|
|
return true;
|
|
}
|
|
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
if (fx_type_id_compare(v->v_type.t_object, FX_TYPE_DOUBLE)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool fx_value_is_string(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_CSTR) {
|
|
return true;
|
|
}
|
|
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
if (fx_type_id_compare(v->v_type.t_object, FX_TYPE_STRING)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool fx_value_is_pointer(const fx_value *v)
|
|
{
|
|
return (v->v_type.t_primitive == FX_VALUE_TYPE_POINTER);
|
|
}
|
|
|
|
bool fx_value_is_object(const fx_value *v, fx_type type)
|
|
{
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
if (fx_type_id_compare(v->v_type.t_object, type)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool fx_value_get_bool(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_BOOL) {
|
|
return v->v_bool;
|
|
}
|
|
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
if (fx_type_id_compare(v->v_type.t_object, FX_TYPE_BOOL)) {
|
|
return fx_bool_get_value(v->v_object);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
intptr_t fx_value_get_int(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_INT) {
|
|
return v->v_int;
|
|
}
|
|
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
if (fx_type_id_compare(v->v_type.t_object, FX_TYPE_INT)) {
|
|
return fx_int_get_value(v->v_object);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
uintptr_t fx_value_get_uint(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_UINT) {
|
|
return v->v_uint;
|
|
}
|
|
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
if (fx_type_id_compare(v->v_type.t_object, FX_TYPE_UINT)) {
|
|
return fx_uint_get_value(v->v_object);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
double fx_value_get_double(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_DOUBLE) {
|
|
return v->v_uint;
|
|
}
|
|
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
if (fx_type_id_compare(v->v_type.t_object, FX_TYPE_DOUBLE)) {
|
|
return fx_double_get_value(v->v_object);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
const char *fx_value_get_cstr(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_CSTR) {
|
|
return v->v_cstr;
|
|
}
|
|
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
if (fx_type_id_compare(v->v_type.t_object, FX_TYPE_STRING)) {
|
|
return fx_string_get_cstr(v->v_object);
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void *fx_value_get_pointer(fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_POINTER) {
|
|
return v->v_pointer;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
const void *fx_value_get_pointer_c(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive == FX_VALUE_TYPE_POINTER) {
|
|
return v->v_pointer;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
fx_object *fx_value_get_object(fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
return v->v_object;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
const fx_object *fx_value_get_object_c(const fx_value *v)
|
|
{
|
|
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
|
return v->v_object;
|
|
}
|
|
|
|
return NULL;
|
|
}
|