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
|
|
|
|
2018-02-12 02:53:46 +01:00
|
|
|
(c) 2000-2017 Benoît Minisini <g4mba5@gmail.com>
|
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
|
2011-06-03 02:51:09 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
2011-12-31 03:39:20 +01:00
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
2013-10-19 04:53:17 +02:00
|
|
|
// On ARM 32 bits, sizeof(VARIANT) = 12, so it must be packed like GB_VARIANT
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
typedef
|
2015-11-02 04:24:44 +01:00
|
|
|
struct
|
2009-11-28 02:22:00 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2013-10-19 04:53:17 +02: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
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
#define VARIANT_undo(_value) \
|
|
|
|
({ \
|
|
|
|
if ((_value)->type == T_VARIANT) \
|
|
|
|
VALUE_undo_variant(_value); \
|
|
|
|
})
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
#define VARIANT_free(_var) \
|
|
|
|
({ \
|
|
|
|
if ((_var)->type == T_STRING) \
|
|
|
|
{ \
|
|
|
|
STRING_unref(&(_var)->value._string); \
|
|
|
|
} \
|
|
|
|
else if (TYPE_is_object((_var)->type)) \
|
|
|
|
{ \
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_UNREF((_var)->value._object); \
|
2010-06-13 14:03:29 +02:00
|
|
|
} \
|
|
|
|
})
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
#define VARIANT_keep(_var) \
|
|
|
|
({ \
|
|
|
|
if ((_var)->type == T_STRING) \
|
|
|
|
{ \
|
|
|
|
STRING_ref((_var)->value._string); \
|
|
|
|
} \
|
|
|
|
else if (TYPE_is_object((_var)->type)) \
|
|
|
|
{ \
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_REF((_var)->value._object); \
|
2010-06-13 14:03:29 +02:00
|
|
|
} \
|
|
|
|
})
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
#define VARIANT_is_null(_var) \
|
|
|
|
(((_var)->type == T_NULL) || ((_var)->type == T_STRING && !(_var)->value._string) || (TYPE_is_object((_var)->type) && !(_var)->value._object))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
#define VARIANT_clear(_var) \
|
|
|
|
({ \
|
|
|
|
VARIANT_free(_var); \
|
|
|
|
(_var)->type = 0; \
|
|
|
|
(_var)->value.data = 0; \
|
|
|
|
})
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#endif
|
2009-11-28 02:22:00 +01:00
|
|
|
|