2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
gbx_variant.h
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
(c) 2000-2009 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-08-17 12:41:51 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2007-12-30 17:41:49 +01:00
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __VARIANT_H
|
|
|
|
#define __VARIANT_H
|
|
|
|
|
2009-11-28 02:22:00 +01:00
|
|
|
#include "gbx_type.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gbx_string.h"
|
|
|
|
#include "gbx_object.h"
|
|
|
|
|
|
|
|
typedef
|
2009-11-28 02:22:00 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
TYPE type;
|
2009-12-24 03:02:05 +01:00
|
|
|
union {
|
|
|
|
char _boolean;
|
|
|
|
unsigned char _byte;
|
|
|
|
short _short;
|
|
|
|
int _integer;
|
|
|
|
int64_t _long;
|
|
|
|
float _single;
|
|
|
|
double _float;
|
|
|
|
GB_DATE_VALUE _date;
|
2009-11-28 02:22:00 +01:00
|
|
|
char *_string;
|
|
|
|
void *_object;
|
2010-05-19 14:43:57 +02:00
|
|
|
void *_pointer;
|
2009-11-28 02:22:00 +01:00
|
|
|
int64_t data;
|
2009-12-24 03:02:05 +01:00
|
|
|
}
|
2009-11-28 02:22:00 +01:00
|
|
|
value;
|
|
|
|
}
|
2009-12-24 03:02:05 +01:00
|
|
|
PACKED
|
2007-12-30 17:41:49 +01:00
|
|
|
VARIANT;
|
|
|
|
|
2009-11-28 02:22:00 +01:00
|
|
|
#define VARIANT_copy_value(_dst, _src) (_dst)->value.data = (_src)->value.data
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static INLINE void VARIANT_undo(VALUE *val)
|
|
|
|
{
|
|
|
|
if (val->type == T_VARIANT)
|
|
|
|
VALUE_conv(val, val->_variant.vtype);
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE void VARIANT_free(VARIANT *var)
|
|
|
|
{
|
|
|
|
if (var->type == T_STRING)
|
|
|
|
{
|
2009-11-28 02:22:00 +01:00
|
|
|
STRING_unref(&var->value._string);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
else if (TYPE_is_object(var->type))
|
|
|
|
{
|
2009-11-28 02:22:00 +01:00
|
|
|
OBJECT_UNREF(var->value._object, "VARIANT_free");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE void VARIANT_keep(VARIANT *var)
|
|
|
|
{
|
|
|
|
if (var->type == T_STRING)
|
|
|
|
{
|
2009-11-28 02:22:00 +01:00
|
|
|
STRING_ref(var->value._string);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
else if (TYPE_is_object(var->type))
|
|
|
|
{
|
2009-11-28 02:22:00 +01:00
|
|
|
OBJECT_REF(var->value._object, "VARIANT_keep");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-28 02:22:00 +01:00
|
|
|
static INLINE boolean VARIANT_is_null(VARIANT *var)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
if (var->type == T_NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
2009-11-28 02:22:00 +01:00
|
|
|
if (var->type == T_STRING && !var->value._string)
|
2007-12-30 17:41:49 +01:00
|
|
|
return TRUE;
|
|
|
|
|
2009-11-28 02:22:00 +01:00
|
|
|
if (TYPE_is_object(var->type) && !var->value._object)
|
2007-12-30 17:41:49 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE void VARIANT_clear(VARIANT *var)
|
|
|
|
{
|
|
|
|
VARIANT_free(var);
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
var->type = 0;
|
2009-11-28 02:22:00 +01:00
|
|
|
var->value.data = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2009-11-28 02:22:00 +01:00
|
|
|
|