2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2012-02-12 22:37:46 +01:00
|
|
|
gbx_exec_enum.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2022-09-12 15:13:13 +02:00
|
|
|
(c) 2000-2017 Benoît Minisini <benoit.minisini@gambas-basic.org>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-12 22:37:46 +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
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-12 22:37:46 +01:00
|
|
|
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.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-12 22:37:46 +01:00
|
|
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_limit.h"
|
|
|
|
#include "gbx_c_enum.h"
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* EXEC_object() ne doit pas faire d'auto-create, car sinon
|
2012-02-12 22:37:46 +01:00
|
|
|
il renvoie un objet référencé */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2018-06-05 11:43:39 +02:00
|
|
|
void EXEC_enum_first(PCODE code, VALUE *local, VALUE *penum)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-12 22:37:46 +01:00
|
|
|
OBJECT *object;
|
|
|
|
CLASS *class;
|
|
|
|
CENUM *old = EXEC_enum;
|
|
|
|
CENUM *cenum;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-12 22:37:46 +01:00
|
|
|
EXEC_object(local, &class, &object);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (!object && class->auto_create && !class->enum_static)
|
|
|
|
object = EXEC_auto_create(class, FALSE);
|
|
|
|
|
2012-02-12 22:37:46 +01:00
|
|
|
cenum = CENUM_create(object ? (void *)object : (void *)class);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2018-06-05 11:43:39 +02:00
|
|
|
RELEASE(penum);
|
|
|
|
penum->_object.class = OBJECT_class(cenum);
|
|
|
|
penum->_object.object = cenum;
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_REF(cenum);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-12 22:37:46 +01:00
|
|
|
EXEC_enum = cenum;
|
|
|
|
EXEC_special(SPEC_FIRST, class, object, 0, TRUE);
|
2008-11-08 18:45:13 +01:00
|
|
|
EXEC_enum = old;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-05 11:43:39 +02:00
|
|
|
bool EXEC_enum_next(PCODE code, VALUE *local, VALUE *penum)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-12 22:37:46 +01:00
|
|
|
OBJECT *object;
|
|
|
|
CLASS *class;
|
|
|
|
bool defined;
|
|
|
|
bool drop = (code & 1);
|
|
|
|
bool err;
|
|
|
|
CENUM *old = EXEC_enum;
|
|
|
|
CENUM *cenum;
|
|
|
|
|
|
|
|
defined = EXEC_object(local, &class, &object);
|
2018-06-05 11:43:39 +02:00
|
|
|
cenum = (CENUM *)penum->_object.object;
|
2013-07-21 01:57:44 +02:00
|
|
|
if (!cenum)
|
|
|
|
return TRUE;
|
2012-02-12 22:37:46 +01:00
|
|
|
|
2013-07-21 01:56:55 +02:00
|
|
|
if (cenum->stop)
|
|
|
|
goto __STOP;
|
|
|
|
|
|
|
|
EXEC_enum = cenum;
|
|
|
|
err = EXEC_special(SPEC_NEXT, class, object, 0, FALSE);
|
|
|
|
EXEC_enum = old;
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
THROW(E_ENUM);
|
2012-02-12 22:37:46 +01:00
|
|
|
|
2013-07-21 01:56:55 +02:00
|
|
|
if (!defined && !drop && !cenum->stop)
|
|
|
|
VALUE_conv_variant(&SP[-1]);
|
2012-02-12 22:37:46 +01:00
|
|
|
|
2013-07-21 01:56:55 +02:00
|
|
|
if (drop || cenum->stop)
|
|
|
|
POP();
|
|
|
|
|
|
|
|
if (!cenum->stop)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
__STOP:
|
2012-02-12 22:37:46 +01:00
|
|
|
|
2013-07-21 01:57:44 +02:00
|
|
|
OBJECT_UNREF(cenum);
|
2018-06-05 11:43:39 +02:00
|
|
|
penum->_object.object = NULL;
|
2013-07-21 01:56:55 +02:00
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|