2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
gbx_c_enum.c
|
|
|
|
|
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
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __GBX_C_ENUM_C
|
|
|
|
|
|
|
|
#include "gbx_info.h"
|
|
|
|
|
|
|
|
#ifndef GBX_INFO
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gbx_class.h"
|
|
|
|
|
|
|
|
#include "gambas.h"
|
|
|
|
#include "gbx_api.h"
|
|
|
|
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
#include "gbx_object.h"
|
|
|
|
#include "gbx_c_enum.h"
|
|
|
|
|
2013-07-21 02:57:48 +02:00
|
|
|
//#define DEBUG_ME
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static CENUM *_enum_list = NULL;
|
|
|
|
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
CENUM *CENUM_create(void *enum_object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
CENUM *_object;
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
_object = OBJECT_new(CLASS_Enum, NULL, NULL);
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_UNREF_KEEP(_object);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
THIS->enum_object = enum_object;
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_REF(enum_object);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
LIST_insert(&_enum_list, THIS, &THIS->list);
|
|
|
|
|
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "CENUM_create: %p <%p>\n", THIS, enum_object);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return THIS;
|
|
|
|
}
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
CENUM *CENUM_get_next(CENUM *cenum)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
if (!cenum)
|
|
|
|
return _enum_list;
|
|
|
|
else
|
|
|
|
return cenum->list.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CENUM_free)
|
|
|
|
|
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "CENUM_free: %p <%p>\n", THIS, THIS->enum_object);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LIST_remove(&_enum_list, THIS, &THIS->list);
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_UNREF(THIS->enum_object);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (THIS->variant)
|
|
|
|
GB_StoreVariant(NULL, THIS->data);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2013-11-03 14:30:02 +01:00
|
|
|
static bool check_enum()
|
|
|
|
{
|
|
|
|
if (!EXEC_enum)
|
|
|
|
{
|
|
|
|
GB_Error("No current enumeration");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CENUM_stop)
|
|
|
|
|
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "CENUM_stop: %p <%p>\n", EXEC_enum, EXEC_enum->enum_object);
|
|
|
|
#endif
|
|
|
|
|
2013-11-03 14:30:02 +01:00
|
|
|
if (check_enum())
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
EXEC_enum->stop = TRUE;
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CENUM_index)
|
|
|
|
|
2013-11-03 14:30:02 +01:00
|
|
|
if (check_enum())
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
_object = EXEC_enum;
|
|
|
|
|
|
|
|
if (READ_PROPERTY)
|
|
|
|
{
|
|
|
|
if (!THIS->variant)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "CENUM_index: %p <%p>: -> NULL\n", THIS, THIS->enum_object);
|
|
|
|
#endif
|
2011-11-14 02:06:51 +01:00
|
|
|
GB_ReturnVariant(NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ME
|
2013-07-21 01:56:55 +02:00
|
|
|
fprintf(stderr, "CENUM_index: %p <%p>: -> value (%ld)\n", THIS, THIS->enum_object, ((VARIANT *)THIS->data)->type);
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|
2010-05-22 20:02:34 +02:00
|
|
|
GB_ReturnVariant((GB_VARIANT_VALUE *)THIS->data);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "CENUM_index: %p <%p>: set: variant = %d\n", THIS, THIS->enum_object, THIS->variant);
|
|
|
|
#endif
|
|
|
|
if (!THIS->variant)
|
|
|
|
((VARIANT *)THIS->data)->type = T_NULL;
|
|
|
|
|
|
|
|
GB_StoreVariant(PROP(GB_VARIANT), THIS->data);
|
|
|
|
THIS->variant = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CENUM_next)
|
|
|
|
|
|
|
|
void *enum_object = OP ? (void *)OP : (void *)CP;
|
|
|
|
CENUM **pcenum = (CENUM **)GB_GetEnum();
|
|
|
|
CENUM *cenum;
|
|
|
|
|
|
|
|
if (*pcenum == NULL)
|
|
|
|
cenum = _enum_list;
|
|
|
|
else
|
|
|
|
cenum = *pcenum;
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (!cenum)
|
|
|
|
{
|
|
|
|
GB_StopEnum();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cenum->enum_object == enum_object)
|
|
|
|
break;
|
|
|
|
|
|
|
|
cenum = cenum->list.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcenum = cenum->list.next;
|
|
|
|
EXEC_enum = cenum;
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2013-11-03 14:30:02 +01:00
|
|
|
BEGIN_PROPERTY(Enum_Stopped)
|
|
|
|
|
|
|
|
if (check_enum())
|
|
|
|
return;
|
|
|
|
|
|
|
|
GB_ReturnBoolean(EXEC_enum->stop);
|
|
|
|
|
|
|
|
END_PROPERTY
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
GB_DESC NATIVE_Enum[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
GB_DECLARE("Enum", sizeof(CENUM)), GB_NOT_CREATABLE(),
|
|
|
|
|
|
|
|
GB_METHOD("_free", NULL, CENUM_free, NULL),
|
|
|
|
|
|
|
|
GB_STATIC_PROPERTY("Index", "v", CENUM_index),
|
2013-11-03 14:30:02 +01:00
|
|
|
GB_STATIC_PROPERTY_READ("Stopped", "b", Enum_Stopped),
|
2007-12-30 17:41:49 +01:00
|
|
|
GB_STATIC_METHOD("Stop", NULL, CENUM_stop, NULL),
|
|
|
|
|
|
|
|
GB_STATIC_METHOD("_next", NULL, CENUM_next, NULL),
|
|
|
|
|
|
|
|
GB_END_DECLARE
|
|
|
|
};
|
|
|
|
|
|
|
|
|