2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
gbx_c_enum.c
|
|
|
|
|
2011-03-21 01:04:10 +01:00
|
|
|
(c) 2000-2011 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
|
2011-06-03 02:51:09 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
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"
|
|
|
|
|
|
|
|
//#define DEBUG_ME
|
|
|
|
|
|
|
|
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);
|
2008-08-14 21:42:27 +02:00
|
|
|
OBJECT_UNREF_KEEP(_object, "CENUM_create");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
THIS->enum_object = enum_object;
|
2010-05-27 00:01:28 +02:00
|
|
|
OBJECT_REF(enum_object, "CENUM_create");
|
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);
|
2010-05-27 00:01:28 +02:00
|
|
|
OBJECT_UNREF(THIS->enum_object, "CENUM_free");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (THIS->variant)
|
|
|
|
GB_StoreVariant(NULL, THIS->data);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CENUM_stop)
|
|
|
|
|
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "CENUM_stop: %p <%p>\n", EXEC_enum, EXEC_enum->enum_object);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EXEC_enum->stop = TRUE;
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CENUM_index)
|
|
|
|
|
|
|
|
_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
|
|
|
|
GB_ReturnNull();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "CENUM_index: %p <%p>: -> value (%d)\n", THIS, THIS->enum_object, ((VARIANT *)THIS->data)->type);
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
|
|
#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),
|
|
|
|
GB_STATIC_METHOD("Stop", NULL, CENUM_stop, NULL),
|
|
|
|
|
|
|
|
GB_STATIC_METHOD("_next", NULL, CENUM_next, NULL),
|
|
|
|
|
|
|
|
GB_END_DECLARE
|
|
|
|
};
|
|
|
|
|
|
|
|
|