2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
gbx_c_array.c
|
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
(c) 2000-2012 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,
|
2011-12-31 03:39:20 +01:00
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __GBX_C_ARRAY_C
|
|
|
|
|
|
|
|
#include "gbx_info.h"
|
|
|
|
|
|
|
|
#ifndef GBX_INFO
|
|
|
|
|
2009-07-21 15:14:01 +02:00
|
|
|
#include <limits.h>
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_error.h"
|
|
|
|
#include "gb_array.h"
|
|
|
|
#include "gb_limit.h"
|
|
|
|
#include "gbx_class.h"
|
|
|
|
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
#include "gbx_date.h"
|
|
|
|
#include "gbx_variant.h"
|
|
|
|
#include "gbx_compare.h"
|
|
|
|
#include "gbx_class.h"
|
|
|
|
#include "gbx_object.h"
|
|
|
|
#include "gbx_api.h"
|
|
|
|
#include "gbx_c_file.h"
|
2010-07-08 00:06:05 +02:00
|
|
|
#include "gbx_struct.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gbx_c_array.h"
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
static bool _create_static_array;
|
|
|
|
|
|
|
|
|
|
|
|
static void THROW_static_array()
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_SARRAY);
|
|
|
|
return;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
static bool check_not_multi(CARRAY *_object)
|
|
|
|
{
|
2010-05-19 22:18:23 +02:00
|
|
|
if (UNLIKELY(THIS->ref != NULL))
|
2010-05-19 14:43:57 +02:00
|
|
|
{
|
|
|
|
THROW_static_array();
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-05-19 22:18:23 +02:00
|
|
|
else if (UNLIKELY(THIS->dim != NULL))
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
|
|
|
GB_Error("Array is multi-dimensional");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-08-14 22:51:42 +02:00
|
|
|
static bool check_start_length(int count, int *start, int *length)
|
|
|
|
{
|
|
|
|
if (*start < 0)
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_BOUND);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*start >= count)
|
|
|
|
*length = 0;
|
|
|
|
|
|
|
|
if (*length == -1)
|
|
|
|
*length = count - *start;
|
|
|
|
|
|
|
|
if (*length < 0 || (*start + *length) > count)
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_BOUND);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-19 14:43:57 +02:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static int get_dim(CARRAY *_object)
|
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
int d;
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
if (LIKELY(THIS->dim == NULL))
|
2009-03-02 12:36:42 +01:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(d = 0;; d++)
|
|
|
|
{
|
|
|
|
if (THIS->dim[d] < 0)
|
|
|
|
return (d + 1);
|
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static int get_bound(CARRAY *_object, int d)
|
|
|
|
{
|
2010-05-19 22:18:23 +02:00
|
|
|
if (LIKELY(THIS->dim == NULL))
|
2010-05-19 14:43:57 +02:00
|
|
|
return THIS->count;
|
2009-03-02 12:36:42 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
d = THIS->dim[d];
|
|
|
|
if (d < 0)
|
|
|
|
d = (-d);
|
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
CLASS *CARRAY_get_array_class(CLASS *class, CTYPE ctype)
|
2010-05-19 14:43:57 +02:00
|
|
|
{
|
2010-07-08 00:06:05 +02:00
|
|
|
if (ctype.id == T_NULL)
|
2010-05-19 14:43:57 +02:00
|
|
|
{
|
2010-07-08 00:06:05 +02:00
|
|
|
if (TYPE_is_pure_object((TYPE)class))
|
|
|
|
return CLASS_get_array_class(class);
|
|
|
|
|
|
|
|
ctype.id = (unsigned char)(TYPE)class;
|
|
|
|
ctype.value = -1;
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
switch (ctype.id)
|
|
|
|
{
|
|
|
|
case T_BOOLEAN: class = CLASS_BooleanArray; break;
|
|
|
|
case T_BYTE: class = CLASS_ByteArray; break;
|
|
|
|
case T_SHORT: class = CLASS_ShortArray; break;
|
|
|
|
case T_INTEGER: class = CLASS_IntegerArray; break;
|
|
|
|
case T_LONG: class = CLASS_LongArray; break;
|
|
|
|
case T_SINGLE: class = CLASS_SingleArray; break;
|
|
|
|
case T_FLOAT: class = CLASS_FloatArray; break;
|
|
|
|
case T_STRING: class = CLASS_StringArray; break;
|
|
|
|
case T_DATE: class = CLASS_DateArray; break;
|
|
|
|
case T_POINTER: class = CLASS_PointerArray; break;
|
|
|
|
|
|
|
|
case T_OBJECT:
|
|
|
|
if (ctype.value >= 0)
|
|
|
|
class = CLASS_get_array_class(class->load->class_ref[ctype.value]);
|
|
|
|
else
|
|
|
|
class = CLASS_ObjectArray;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TC_STRUCT:
|
|
|
|
class = CLASS_get_array_of_struct_class(class->load->class_ref[ctype.value]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
class = CLASS_VariantArray;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
return class;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
void *CARRAY_out_of_bound()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-03-19 15:32:30 +01:00
|
|
|
GB_Error((char *)E_BOUND);
|
|
|
|
return NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
|
2008-01-24 11:42:42 +01:00
|
|
|
#define get_data_multi CARRAY_get_data_multi
|
2008-03-19 15:32:30 +01:00
|
|
|
#define get_data CARRAY_get_data
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-24 11:42:42 +01:00
|
|
|
void *CARRAY_get_data_multi(CARRAY *_object, GB_INTEGER *arg, int nparam)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
int index;
|
|
|
|
|
|
|
|
//fprintf(stderr, "get_data_multi: nparam = %d\n", nparam);
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
if (UNLIKELY(THIS->dim != NULL))
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
|
|
|
int max;
|
|
|
|
int i;
|
|
|
|
int d;
|
|
|
|
bool stop = FALSE;
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
nparam--;
|
|
|
|
|
|
|
|
for (i = 0;; i++)
|
|
|
|
{
|
|
|
|
if (i > nparam)
|
|
|
|
break;
|
|
|
|
|
|
|
|
max = THIS->dim[i];
|
|
|
|
if (max < 0)
|
|
|
|
{
|
|
|
|
max = (-max);
|
|
|
|
stop = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-03 01:23:50 +02:00
|
|
|
VALUE_conv_integer((VALUE *)&arg[i]);
|
2009-03-02 12:36:42 +01:00
|
|
|
d = arg[i].value;
|
|
|
|
|
|
|
|
if (d < 0 || d >= max)
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_BOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
index *= max;
|
|
|
|
index += d;
|
|
|
|
|
|
|
|
if (stop)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != nparam)
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_NDIM);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nparam != 1)
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_NDIM);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = arg->value;
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if ((index < 0) || (index >= THIS->count))
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
|
|
|
GB_Error((char *)E_BOUND);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
return (void *)((char *)(THIS->data) + index * THIS->size);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
static int get_count(int *dim)
|
|
|
|
{
|
|
|
|
int i, size;
|
|
|
|
|
|
|
|
size = 1;
|
|
|
|
|
|
|
|
for (i = 0;; i++)
|
|
|
|
{
|
|
|
|
size *= dim[i];
|
|
|
|
if (size < 0)
|
|
|
|
{
|
|
|
|
size = (-size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static void release_one(CARRAY *_object, int i)
|
|
|
|
{
|
2008-09-22 01:22:07 +02:00
|
|
|
if (THIS->type == T_STRING)
|
|
|
|
STRING_unref(&(((char **)(THIS->data))[i]));
|
|
|
|
else if (THIS->type == T_VARIANT)
|
|
|
|
VARIANT_free(&(((VARIANT *)(THIS->data))[i]));
|
|
|
|
else if (TYPE_is_object(THIS->type))
|
|
|
|
OBJECT_UNREF(((void **)(THIS->data))[i], "release_one");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
static void release_static(TYPE type, void *data, int start, int end)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
int i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
if (type == T_STRING)
|
2008-09-22 01:22:07 +02:00
|
|
|
{
|
|
|
|
for (i = start; i < end; i++)
|
2010-05-27 00:01:28 +02:00
|
|
|
STRING_unref(&((char **)data)[i]);
|
2008-09-22 01:22:07 +02:00
|
|
|
}
|
2010-05-27 00:01:28 +02:00
|
|
|
else if (type == T_VARIANT)
|
2008-09-22 01:22:07 +02:00
|
|
|
{
|
|
|
|
for (i = start; i < end; i++)
|
2010-05-27 00:01:28 +02:00
|
|
|
VARIANT_free(&((VARIANT *)data)[i]);
|
2008-09-22 01:22:07 +02:00
|
|
|
}
|
2010-05-27 00:01:28 +02:00
|
|
|
else if (TYPE_is_object(type))
|
2008-09-22 01:22:07 +02:00
|
|
|
{
|
|
|
|
for (i = start; i < end; i++)
|
2010-05-27 00:01:28 +02:00
|
|
|
OBJECT_UNREF(((void **)data)[i], "release");
|
2008-09-22 01:22:07 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
static void release(CARRAY *_object, int start, int end)
|
|
|
|
{
|
|
|
|
if (end < 0)
|
|
|
|
end = THIS->count;
|
|
|
|
|
|
|
|
release_static(THIS->type, THIS->data, start, end);
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static void borrow(CARRAY *_object, int start, int end)
|
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
int i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (end < 0)
|
2010-05-19 14:43:57 +02:00
|
|
|
end = THIS->count;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
if (THIS->type == T_STRING)
|
|
|
|
{
|
|
|
|
for (i = start; i < end; i++)
|
|
|
|
STRING_ref(((char **)(THIS->data))[i]);
|
|
|
|
}
|
|
|
|
else if (THIS->type == T_VARIANT)
|
|
|
|
{
|
|
|
|
for (i = start; i < end; i++)
|
|
|
|
VARIANT_keep(&((VARIANT *)(THIS->data))[i]);
|
|
|
|
}
|
|
|
|
else if (TYPE_is_object(THIS->type))
|
|
|
|
{
|
|
|
|
for (i = start; i < end; i++)
|
|
|
|
OBJECT_ref(((void **)(THIS->data))[i]);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void clear(CARRAY *_object)
|
|
|
|
{
|
2010-05-19 22:18:23 +02:00
|
|
|
if (UNLIKELY(THIS->ref != NULL))
|
2010-05-19 14:43:57 +02:00
|
|
|
{
|
|
|
|
THROW_static_array();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
release(THIS, 0, -1);
|
2010-05-19 22:18:23 +02:00
|
|
|
if (UNLIKELY(THIS->dim != NULL))
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
2010-07-08 00:06:05 +02:00
|
|
|
memset(THIS->data, 0, THIS->size * THIS->count);
|
2009-03-02 12:36:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ARRAY_delete(&THIS->data);
|
2010-07-08 00:06:05 +02:00
|
|
|
ARRAY_create_with_size(&THIS->data, THIS->size, 8);
|
2010-05-19 14:43:57 +02:00
|
|
|
THIS->count = 0;
|
2009-03-02 12:36:42 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *insert(CARRAY *_object, int index)
|
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
THIS->count++;
|
2009-03-02 12:36:42 +01:00
|
|
|
return ARRAY_insert(&THIS->data, index);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
size_t CARRAY_get_static_size(CLASS *class, CLASS_ARRAY *desc)
|
2010-05-27 00:01:28 +02:00
|
|
|
{
|
2010-07-08 00:06:05 +02:00
|
|
|
return (size_t)get_count(desc->dim) * CLASS_sizeof_ctype(class, desc->ctype);
|
2010-05-27 00:01:28 +02:00
|
|
|
}
|
|
|
|
|
2010-11-26 21:30:58 +01:00
|
|
|
int CARRAY_get_static_count(CLASS_ARRAY *desc)
|
|
|
|
{
|
|
|
|
return get_count(desc->dim);
|
|
|
|
}
|
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
CARRAY *CARRAY_create_static(CLASS *class, void *ref, CLASS_ARRAY *desc, void *data)
|
2010-05-27 00:01:28 +02:00
|
|
|
{
|
|
|
|
CARRAY *array;
|
2010-07-08 00:06:05 +02:00
|
|
|
TYPE type;
|
|
|
|
CLASS *aclass;
|
2010-05-27 00:01:28 +02:00
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
type = CLASS_ctype_to_type(class, desc->ctype);
|
2010-05-27 00:01:28 +02:00
|
|
|
_create_static_array = TRUE;
|
2010-07-08 00:06:05 +02:00
|
|
|
aclass = CARRAY_get_array_class(class, desc->ctype);
|
|
|
|
array = OBJECT_create_native(aclass, NULL);
|
2010-05-27 00:01:28 +02:00
|
|
|
_create_static_array = FALSE;
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
array->type = type;
|
2010-05-27 00:01:28 +02:00
|
|
|
array->data = data;
|
|
|
|
array->ref = ref;
|
|
|
|
array->count = get_count(desc->dim);
|
|
|
|
OBJECT_REF(ref, "CARRAY_create_static");
|
|
|
|
array->dim = desc->dim;
|
2010-07-08 00:06:05 +02:00
|
|
|
array->size = CLASS_sizeof_ctype(class, desc->ctype);
|
2010-05-27 00:01:28 +02:00
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
void CARRAY_release_static(CLASS *class, CLASS_ARRAY *desc, void *data)
|
2010-05-27 00:01:28 +02:00
|
|
|
{
|
2010-07-08 00:06:05 +02:00
|
|
|
int count = get_count(desc->dim);
|
|
|
|
|
|
|
|
if (desc->ctype.id == TC_STRUCT)
|
|
|
|
{
|
|
|
|
CLASS *sclass = class->load->class_ref[desc->ctype.value];
|
|
|
|
int i;
|
|
|
|
int size = CLASS_sizeof_ctype(class, desc->ctype);
|
|
|
|
char *p = (char *)data;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
OBJECT_release_static(sclass, sclass->load->dyn, sclass->load->n_dyn, p);
|
|
|
|
p += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
release_static(CLASS_ctype_to_type(class, desc->ctype), data, 0, count);
|
2010-05-27 00:01:28 +02:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void CARRAY_get_value(CARRAY *_object, int index, VALUE *value)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
VALUE_read(value, get_data(THIS, index), THIS->type);
|
|
|
|
}
|
|
|
|
|
2011-03-16 23:16:19 +01:00
|
|
|
int *CARRAY_get_array_bounds(CARRAY *_object)
|
|
|
|
{
|
|
|
|
return THIS->dim;
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_new, GB_INTEGER size)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
TYPE type;
|
|
|
|
CLASS *klass;
|
2009-07-21 15:14:01 +02:00
|
|
|
uint64_t size;
|
|
|
|
int max_size;
|
2009-03-02 12:36:42 +01:00
|
|
|
int inc;
|
|
|
|
GB_INTEGER *sizes = ARG(size);
|
|
|
|
int nsize = GB_NParam() + 1;
|
|
|
|
int i;
|
2010-05-19 14:43:57 +02:00
|
|
|
|
|
|
|
if (_create_static_array)
|
|
|
|
return;
|
2009-03-02 12:36:42 +01:00
|
|
|
|
|
|
|
klass = OBJECT_class(THIS);
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
type = (TYPE)klass->array_type;
|
|
|
|
if (!type)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
GB_Error("Bad array type");
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
/*if (TYPE_is_object(type))
|
2010-05-30 21:37:40 +02:00
|
|
|
THIS->mode = T_OBJECT;
|
|
|
|
else
|
2010-07-08 00:06:05 +02:00
|
|
|
THIS->mode = (int)type;*/
|
2010-05-30 21:37:40 +02:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
//printf("Array_new: type = %d nsize = %d\n", type, nsize);
|
2009-03-02 12:36:42 +01:00
|
|
|
|
|
|
|
THIS->type = type;
|
2010-07-08 00:06:05 +02:00
|
|
|
THIS->size = TYPE_sizeof_memory(type);
|
|
|
|
max_size = INT_MAX / THIS->size;
|
2009-03-02 12:36:42 +01:00
|
|
|
|
|
|
|
if (nsize <= 1)
|
|
|
|
{
|
|
|
|
size = VARGOPT(size, 0);
|
2009-07-21 15:14:01 +02:00
|
|
|
if (size > max_size)
|
|
|
|
THROW(E_MEMORY);
|
2009-03-02 12:36:42 +01:00
|
|
|
if (size < 0)
|
|
|
|
size = 0;
|
|
|
|
|
|
|
|
inc = (size / 8) & ~7;
|
|
|
|
if (inc < 8)
|
|
|
|
inc = 8;
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
ARRAY_create_with_size(&THIS->data, THIS->size, inc);
|
2009-03-02 12:36:42 +01:00
|
|
|
if (size > 0)
|
|
|
|
ARRAY_add_many_void(&THIS->data, size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nsize > MAX_ARRAY_DIM)
|
|
|
|
{
|
|
|
|
GB_Error("Too many dimensions");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = 1;
|
|
|
|
for (i = 0; i < nsize; i++)
|
|
|
|
{
|
2010-06-03 01:23:50 +02:00
|
|
|
VALUE_conv_integer((VALUE *)&sizes[i]);
|
2009-03-02 12:36:42 +01:00
|
|
|
if (sizes[i].value < 1)
|
|
|
|
{
|
|
|
|
GB_Error("Bad dimension");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
size *= sizes[i].value;
|
2009-07-21 15:14:01 +02:00
|
|
|
if (size > max_size)
|
|
|
|
THROW(E_MEMORY);
|
2009-03-02 12:36:42 +01:00
|
|
|
}
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
ALLOC_ZERO(&THIS->dim, nsize * sizeof(int), "Array_new");
|
2009-03-02 12:36:42 +01:00
|
|
|
|
|
|
|
for (i = 0; i < nsize; i++)
|
|
|
|
THIS->dim[i] = sizes[i].value;
|
|
|
|
THIS->dim[nsize - 1] = (-THIS->dim[nsize - 1]);
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
ARRAY_create_with_size(&THIS->data, THIS->size, 8);
|
2009-07-21 15:14:01 +02:00
|
|
|
ARRAY_add_many_void(&THIS->data, (int)size);
|
2009-03-02 12:36:42 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
THIS->count = size;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_PROPERTY(Array_Type)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
GB_ReturnInteger(THIS->type);
|
|
|
|
|
2010-07-16 16:15:11 +02:00
|
|
|
END_PROPERTY
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD_VOID(Array_free)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
if (UNLIKELY(THIS->ref != NULL))
|
2010-05-19 14:43:57 +02:00
|
|
|
{
|
|
|
|
GB_Unref(&THIS->ref);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
release(THIS, 0, -1);
|
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
ARRAY_delete(&THIS->data);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
FREE(&THIS->dim, "CARRAY_free");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD_VOID(Array_Clear)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
clear(THIS);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_PROPERTY(Array_Data)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_ReturnPointer(THIS->data);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_PROPERTY(Array_Count)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
GB_ReturnInt(THIS->count);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_PROPERTY(Array_Max)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
GB_ReturnInt(THIS->count - 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
|
|
|
static bool copy_remove(CARRAY *_object, int start, int length, bool copy, bool remove)
|
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
CARRAY *array;
|
2010-05-19 14:43:57 +02:00
|
|
|
int count = THIS->count;
|
2009-03-02 12:36:42 +01:00
|
|
|
void *data;
|
|
|
|
int i, nsize;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (check_not_multi(THIS) && (start != 0 || length != -1))
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-14 22:51:42 +02:00
|
|
|
if (check_start_length(count, &start, &length))
|
2009-03-02 12:36:42 +01:00
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (copy)
|
|
|
|
{
|
|
|
|
GB_ArrayNew((GB_ARRAY *)POINTER(&array), THIS->type, 0);
|
|
|
|
|
|
|
|
if (length > 0)
|
|
|
|
{
|
|
|
|
data = ARRAY_insert_many(&array->data, 0, length);
|
2010-05-19 14:43:57 +02:00
|
|
|
array->count += length;
|
2010-07-08 00:06:05 +02:00
|
|
|
memmove(data, get_data(THIS, start), length * THIS->size);
|
2007-12-30 17:41:49 +01:00
|
|
|
borrow(array, 0, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (THIS->dim)
|
|
|
|
{
|
|
|
|
nsize = get_dim(THIS);
|
2009-03-02 12:36:42 +01:00
|
|
|
ALLOC_ZERO(&array->dim, nsize * sizeof(int), "copy_remove");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
for (i = 0; i < nsize; i++)
|
|
|
|
array->dim[i] = THIS->dim[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remove)
|
|
|
|
{
|
|
|
|
release(THIS, start, start + length);
|
|
|
|
ARRAY_remove_many(&THIS->data, start, length);
|
2010-05-19 14:43:57 +02:00
|
|
|
THIS->count -= length;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (copy)
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_ReturnObject(array);
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Remove, GB_INTEGER index; GB_INTEGER length)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
copy_remove(THIS, VARG(index), VARGOPT(length, 1), FALSE, TRUE);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Copy, GB_INTEGER start; GB_INTEGER length)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
int start, length;
|
|
|
|
|
|
|
|
if (MISSING(start) && MISSING(length))
|
|
|
|
{
|
|
|
|
start = 0;
|
|
|
|
length = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start = VARGOPT(start, 0);
|
|
|
|
length = VARGOPT(length, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_remove(THIS, start, length, TRUE, FALSE);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Extract, GB_INTEGER start; GB_INTEGER length)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
copy_remove(THIS, VARG(start), VARGOPT(length, 1), TRUE, TRUE);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Resize, GB_INTEGER size)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
int size = VARG(size);
|
2010-05-19 14:43:57 +02:00
|
|
|
int count = THIS->count;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (check_not_multi(THIS))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (size > count)
|
|
|
|
{
|
|
|
|
ARRAY_add_many_void(&THIS->data, size - count);
|
|
|
|
}
|
|
|
|
else if ((size < count) && (size >= 0))
|
|
|
|
{
|
|
|
|
release(THIS, size, -1);
|
|
|
|
ARRAY_remove_many(&THIS->data, size, count - size);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
THIS->count = size;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
static void add(CARRAY *_object, GB_VALUE *value, int index)
|
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
void *data;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (check_not_multi(THIS))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
data = insert(THIS, index);
|
|
|
|
/*GB_Conv(value, THIS->type);*/
|
|
|
|
GB_Store(THIS->type, value, data);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define IMPLEMENT_add(_type, _gtype) \
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_##_type##_Add, GB_##_gtype value; GB_INTEGER index) \
|
2007-12-30 17:41:49 +01:00
|
|
|
\
|
2009-03-02 12:36:42 +01:00
|
|
|
add(THIS, (GB_VALUE *)(void *)ARG(value), VARGOPT(index, -1)); \
|
|
|
|
\
|
2007-12-30 17:41:49 +01:00
|
|
|
END_METHOD \
|
|
|
|
\
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_##_type##_Push, GB_##_gtype value) \
|
2007-12-30 17:41:49 +01:00
|
|
|
\
|
2009-03-02 12:36:42 +01:00
|
|
|
add(THIS, (GB_VALUE *)(void *)ARG(value), -1); \
|
|
|
|
\
|
2007-12-30 17:41:49 +01:00
|
|
|
END_METHOD
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
IMPLEMENT_add(Integer, INTEGER)
|
|
|
|
IMPLEMENT_add(Long, LONG)
|
|
|
|
IMPLEMENT_add(Float, FLOAT)
|
|
|
|
IMPLEMENT_add(Single, SINGLE)
|
|
|
|
IMPLEMENT_add(Date, DATE)
|
|
|
|
IMPLEMENT_add(String, STRING)
|
|
|
|
IMPLEMENT_add(Object, OBJECT)
|
|
|
|
IMPLEMENT_add(Variant, VARIANT)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Add, GB_VARIANT value; GB_INTEGER index)
|
2009-04-08 12:11:16 +02:00
|
|
|
|
|
|
|
GB_VALUE *value = (GB_VALUE *)(void *)ARG(value);
|
|
|
|
GB_Conv(value, THIS->type);
|
|
|
|
add(THIS, value, VARGOPT(index, -1));
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Push, GB_VARIANT value)
|
2009-04-08 12:11:16 +02:00
|
|
|
|
|
|
|
GB_VALUE *value = (GB_VALUE *)(void *)ARG(value);
|
|
|
|
GB_Conv(value, THIS->type);
|
|
|
|
add(THIS, value, -1);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#define IMPLEMENT_put(_type, _gtype) \
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_##_type##_put, GB_##_gtype value; GB_INTEGER index) \
|
2009-03-02 12:36:42 +01:00
|
|
|
\
|
|
|
|
void *data = get_data_multi(THIS, ARG(index), GB_NParam() + 1); \
|
|
|
|
if (!data) return; \
|
|
|
|
GB_Store(GB_T_##_gtype, (GB_VALUE *)(void *)ARG(value), data); \
|
|
|
|
\
|
2007-12-30 17:41:49 +01:00
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
#define IMPLEMENT_put2(_type, _gtype, _gstore) \
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_##_type##_put, GB_##_gtype value; GB_INTEGER index) \
|
2007-12-30 17:41:49 +01:00
|
|
|
\
|
2009-03-02 12:36:42 +01:00
|
|
|
void *data = get_data_multi(THIS, ARG(index), GB_NParam() + 1); \
|
|
|
|
if (!data) return; \
|
|
|
|
GB_Store(GB_T_##_gstore, (GB_VALUE *)(void *)ARG(value), data); \
|
|
|
|
\
|
2007-12-30 17:41:49 +01:00
|
|
|
END_METHOD
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_put, GB_VARIANT value; GB_INTEGER index)
|
2009-04-08 12:11:16 +02:00
|
|
|
|
|
|
|
GB_VALUE *value;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
value = (GB_VALUE *)(void *)ARG(value);
|
|
|
|
GB_Conv(value, THIS->type);
|
|
|
|
|
|
|
|
data = get_data_multi(THIS, ARG(index), GB_NParam() + 1);
|
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
GB_Store(THIS->type, value, data);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
IMPLEMENT_put(Integer, INTEGER)
|
|
|
|
IMPLEMENT_put2(Short, INTEGER, SHORT)
|
|
|
|
IMPLEMENT_put2(Byte, INTEGER, BYTE)
|
|
|
|
IMPLEMENT_put2(Boolean, INTEGER, BOOLEAN)
|
|
|
|
IMPLEMENT_put(Long, LONG)
|
|
|
|
IMPLEMENT_put(Float, FLOAT)
|
|
|
|
IMPLEMENT_put(Single, SINGLE)
|
|
|
|
IMPLEMENT_put(Date, DATE)
|
|
|
|
IMPLEMENT_put(String, STRING)
|
|
|
|
IMPLEMENT_put(Object, OBJECT)
|
|
|
|
IMPLEMENT_put(Variant, VARIANT)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Fill, GB_VALUE value; GB_INTEGER start; GB_INTEGER length)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
int count = THIS->count;
|
2009-03-02 12:36:42 +01:00
|
|
|
int start = VARGOPT(start, 0);
|
|
|
|
int length = VARGOPT(length, count);
|
|
|
|
int i;
|
|
|
|
void *data;
|
|
|
|
int size;
|
2010-08-14 22:51:42 +02:00
|
|
|
|
|
|
|
if (check_start_length(count, &start, &length))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
VALUE_conv((VALUE *)ARG(value), THIS->type);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
data = get_data(THIS, start);
|
2010-07-08 00:06:05 +02:00
|
|
|
size = THIS->size;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
GB_Store(THIS->type, (GB_VALUE *)ARG(value), data);
|
|
|
|
data += size;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Insert, GB_OBJECT array; GB_INTEGER pos)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
int pos = VARGOPT(pos, -1);
|
|
|
|
CARRAY *array = (CARRAY *)VARG(array);
|
|
|
|
void *data;
|
|
|
|
int count;
|
2008-05-11 20:07:16 +02:00
|
|
|
|
|
|
|
if (GB_CheckObject(array))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (check_not_multi(THIS))
|
|
|
|
{
|
|
|
|
GB_ReturnNull();
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
count = array->count;
|
2009-03-02 12:36:42 +01:00
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
if (pos < 0)
|
2010-05-19 14:43:57 +02:00
|
|
|
pos = THIS->count;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
data = ARRAY_insert_many(&THIS->data, pos, count);
|
2010-05-19 14:43:57 +02:00
|
|
|
THIS->count += count;
|
2007-12-30 17:41:49 +01:00
|
|
|
borrow(array, 0, -1);
|
2010-07-08 00:06:05 +02:00
|
|
|
memmove(data, array->data, count * THIS->size);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2009-03-02 12:36:42 +01:00
|
|
|
|
|
|
|
GB_ReturnObject(THIS);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD_VOID(Array_Pop)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
int index = THIS->count - 1;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (check_not_multi(THIS))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (index < 0)
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_ARG);
|
|
|
|
return;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_ReturnPtr(THIS->type, get_data(THIS, index));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
BORROW(&TEMP);
|
|
|
|
release_one(THIS, index);
|
|
|
|
ARRAY_remove(&THIS->data, index);
|
2010-05-19 14:43:57 +02:00
|
|
|
THIS->count--;
|
2009-03-02 12:36:42 +01:00
|
|
|
UNBORROW(&TEMP);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_get, GB_INTEGER index)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
void *data = get_data_multi(THIS, ARG(index), GB_NParam() + 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (data)
|
|
|
|
GB_ReturnPtr(THIS->type, data);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2011-06-25 00:33:26 +02:00
|
|
|
#if 0
|
|
|
|
BEGIN_PROPERTY(Array_Last)
|
|
|
|
|
|
|
|
void *data;
|
|
|
|
int index = THIS->count - 1;
|
|
|
|
|
|
|
|
if (check_not_multi(THIS))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_ARG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = get_data(THIS, index);
|
|
|
|
|
|
|
|
if (READ_PROPERTY)
|
|
|
|
{
|
|
|
|
GB_ReturnPtr(THIS->type, data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GB_VALUE *value;
|
|
|
|
|
|
|
|
value = (GB_VALUE *)(void *)ARG(value);
|
|
|
|
GB_Conv(value, THIS->type);
|
|
|
|
|
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
GB_Store(THIS->type, value, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
#endif
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD_VOID(Array_next)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
int *index = (int *)GB_GetEnum();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (*index >= THIS->count)
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_StopEnum();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GB_ReturnPtr(THIS->type, get_data(THIS, *index));
|
|
|
|
(*index)++;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Sort, GB_INTEGER mode)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
COMPARE_FUNC compare;
|
|
|
|
int mode = VARGOPT(mode, 0);
|
|
|
|
void *data = THIS->data;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (THIS->count > 1)
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
|
|
|
compare = COMPARE_get(THIS->type, mode);
|
2010-07-08 00:06:05 +02:00
|
|
|
qsort(data, THIS->count, THIS->size, compare);
|
2009-03-02 12:36:42 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_ReturnObject(THIS);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2009-08-22 14:17:31 +02:00
|
|
|
static int find(CARRAY *_object, int mode, void *value, int start)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
COMPARE_FUNC compare = COMPARE_get(THIS->type, mode);
|
|
|
|
int i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-08-22 14:17:31 +02:00
|
|
|
if (start < 0)
|
|
|
|
start = 0;
|
2010-05-19 14:43:57 +02:00
|
|
|
else if (start >= THIS->count)
|
2009-08-22 14:17:31 +02:00
|
|
|
return (-1);
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
for (i = start; i < THIS->count; i++)
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
2009-08-22 14:17:31 +02:00
|
|
|
if ((*compare)(get_data(THIS, i), value) == 0)
|
2009-03-02 12:36:42 +01:00
|
|
|
return i;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2011-09-26 03:46:48 +02:00
|
|
|
static int find_string(CARRAY *_object, int mode, const char *value, int len_value, int start)
|
|
|
|
{
|
|
|
|
char **data;
|
|
|
|
char *str;
|
|
|
|
int i;
|
|
|
|
int len;
|
|
|
|
|
2011-09-26 05:00:00 +02:00
|
|
|
//fprintf(stderr, "find_string: %p %d: %.*s | %s\n", THIS, THIS->count, len_value, value, DEBUG_get_current_position());
|
|
|
|
|
2011-09-26 03:46:48 +02:00
|
|
|
if (start < 0)
|
|
|
|
start = 0;
|
|
|
|
else if (start >= THIS->count)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
data = ((char **)THIS->data);
|
|
|
|
|
|
|
|
if (mode == GB_COMP_BINARY)
|
|
|
|
{
|
|
|
|
for (i = start; i < THIS->count; i++)
|
|
|
|
{
|
|
|
|
str = data[i];
|
|
|
|
len = STRING_length(str);
|
|
|
|
if (STRING_equal(str, len, value, len_value))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == GB_COMP_NOCASE)
|
|
|
|
{
|
|
|
|
for (i = start; i < THIS->count; i++)
|
|
|
|
{
|
|
|
|
str = data[i];
|
|
|
|
len = STRING_length(str);
|
|
|
|
if (STRING_equal_ignore_case(str, len, value, len_value))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
COMPARE_FUNC compare = COMPARE_get(THIS->type, mode);
|
|
|
|
|
|
|
|
for (i = start; i < THIS->count; i++)
|
|
|
|
{
|
|
|
|
if ((*compare)(&data[i], &value) == 0)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#define IMPLEMENT_find(_type, _gtype) \
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_##_type##_Find, _gtype value; GB_INTEGER start) \
|
2007-12-30 17:41:49 +01:00
|
|
|
\
|
2009-08-22 14:17:31 +02:00
|
|
|
GB_ReturnInt(find(THIS, 0, &VARG(value), VARGOPT(start, 0))); \
|
2007-12-30 17:41:49 +01:00
|
|
|
\
|
|
|
|
END_METHOD \
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_##_type##_Exist, _gtype value) \
|
2007-12-30 17:41:49 +01:00
|
|
|
\
|
2009-08-22 14:17:31 +02:00
|
|
|
GB_ReturnBoolean(find(THIS, 0, &VARG(value), 0) >= 0); \
|
2007-12-30 17:41:49 +01:00
|
|
|
\
|
|
|
|
END_METHOD
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
IMPLEMENT_find(Integer, GB_INTEGER)
|
2007-12-30 17:41:49 +01:00
|
|
|
/*IMPLEMENT_find(short, GB_INTEGER)
|
|
|
|
IMPLEMENT_find(byte, GB_INTEGER)*/
|
2011-12-28 04:04:46 +01:00
|
|
|
IMPLEMENT_find(Long, GB_LONG)
|
|
|
|
IMPLEMENT_find(Float, GB_FLOAT)
|
|
|
|
IMPLEMENT_find(Single, GB_SINGLE)
|
|
|
|
IMPLEMENT_find(Date, GB_DATE)
|
2009-02-16 22:39:07 +01:00
|
|
|
|
2011-12-27 14:39:23 +01:00
|
|
|
static int find_object(CARRAY *_object, void *value, int start, bool byref)
|
2009-02-16 22:39:07 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
int i;
|
2011-12-27 14:39:23 +01:00
|
|
|
void **data;
|
2009-02-16 22:39:07 +01:00
|
|
|
|
2009-08-22 14:17:31 +02:00
|
|
|
if (start < 0)
|
|
|
|
start = 0;
|
2010-05-19 14:43:57 +02:00
|
|
|
else if (start >= THIS->count)
|
2009-08-22 14:17:31 +02:00
|
|
|
return (-1);
|
|
|
|
|
2011-12-27 14:39:23 +01:00
|
|
|
data = get_data(THIS, 0);
|
|
|
|
|
|
|
|
if (byref)
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
2011-12-27 14:39:23 +01:00
|
|
|
for (i = 0; i < THIS->count; i++)
|
|
|
|
{
|
|
|
|
if (data[i] == value)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < THIS->count; i++)
|
|
|
|
{
|
|
|
|
//if (*((void **)get_data(THIS, i)) == value)
|
|
|
|
if (!COMPARE_object(&data[i], &value))
|
|
|
|
return i;
|
|
|
|
}
|
2009-03-02 12:36:42 +01:00
|
|
|
}
|
2009-02-16 22:39:07 +01:00
|
|
|
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Object_Find, GB_OBJECT value; GB_INTEGER start)
|
2009-02-16 22:39:07 +01:00
|
|
|
|
2011-12-27 14:39:23 +01:00
|
|
|
GB_ReturnInt(find_object(THIS, VARG(value), VARGOPT(start, 0), FALSE));
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
BEGIN_METHOD(Array_Object_FindByRef, GB_OBJECT value; GB_INTEGER start)
|
|
|
|
|
|
|
|
GB_ReturnInt(find_object(THIS, VARG(value), VARGOPT(start, 0), TRUE));
|
2009-02-16 22:39:07 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Object_Exist, GB_OBJECT value)
|
2009-02-16 22:39:07 +01:00
|
|
|
|
2011-12-27 14:39:23 +01:00
|
|
|
GB_ReturnBoolean(find_object(THIS, VARG(value), 0, FALSE) >= 0);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
BEGIN_METHOD(Array_Object_ExistByRef, GB_OBJECT value)
|
|
|
|
|
|
|
|
GB_ReturnBoolean(find_object(THIS, VARG(value), 0, TRUE) >= 0);
|
2009-02-16 22:39:07 +01:00
|
|
|
|
|
|
|
END_METHOD
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_String_Find, GB_STRING value; GB_INTEGER mode; GB_INTEGER start)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-09-26 03:46:48 +02:00
|
|
|
GB_ReturnInteger(find_string(THIS, VARGOPT(mode, GB_COMP_BINARY), STRING(value), LENGTH(value), VARGOPT(start, 0)));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_String_Exist, GB_STRING value; GB_INTEGER mode)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-11 20:14:04 +01:00
|
|
|
//fprintf(stderr, "%s\n", DEBUG_get_current_position());
|
2011-09-26 03:46:48 +02:00
|
|
|
GB_ReturnBoolean(find_string(THIS, VARGOPT(mode, GB_COMP_BINARY), STRING(value), LENGTH(value), 0) >= 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_String_join, GB_STRING sep; GB_STRING esc)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
char *sep = ",";
|
|
|
|
int lsep = 1;
|
|
|
|
char *esc = "";
|
|
|
|
int lesc = 0;
|
|
|
|
char escl, NO_WARNING(escr);
|
|
|
|
int i;
|
|
|
|
char **data = (char **)THIS->data;
|
2007-12-30 17:41:49 +01:00
|
|
|
char *p, *p2;
|
2008-11-08 15:55:03 +01:00
|
|
|
int l, max;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (!MISSING(sep))
|
|
|
|
{
|
|
|
|
sep = STRING(sep);
|
|
|
|
lsep = LENGTH(sep);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!MISSING(esc))
|
|
|
|
{
|
|
|
|
esc = STRING(esc);
|
|
|
|
lesc = LENGTH(esc);
|
|
|
|
|
|
|
|
if (lesc == 1)
|
|
|
|
escl = escr = esc[0];
|
|
|
|
else if (lesc >= 2)
|
|
|
|
{
|
|
|
|
escl = esc[0];
|
|
|
|
escr = esc[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-08 15:55:03 +01:00
|
|
|
if (!lesc)
|
|
|
|
{
|
|
|
|
max = 0;
|
2010-05-19 14:43:57 +02:00
|
|
|
for (i = 0; i < THIS->count; i++)
|
2008-11-08 15:55:03 +01:00
|
|
|
max += STRING_length(data[i]) + lsep;
|
2010-05-19 14:43:57 +02:00
|
|
|
if (THIS->count)
|
2008-11-08 15:55:03 +01:00
|
|
|
max -= lsep;
|
|
|
|
|
2008-11-10 01:18:00 +01:00
|
|
|
STRING_start_len(max);
|
2008-11-08 15:55:03 +01:00
|
|
|
}
|
|
|
|
else
|
2008-11-10 01:18:00 +01:00
|
|
|
STRING_start();
|
2009-03-02 12:36:42 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
for (i = 0; i < THIS->count; i++)
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
2007-12-30 17:41:49 +01:00
|
|
|
p = data[i];
|
|
|
|
l = STRING_length(data[i]);
|
2009-03-02 12:36:42 +01:00
|
|
|
|
|
|
|
if (i)
|
|
|
|
STRING_make(sep, lsep);
|
2007-12-30 17:41:49 +01:00
|
|
|
if (lesc)
|
|
|
|
{
|
2008-11-10 01:18:00 +01:00
|
|
|
STRING_make(&escl, 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
if (l)
|
|
|
|
{
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
p2 = index(p, escr);
|
|
|
|
if (p2)
|
|
|
|
{
|
2008-11-10 01:18:00 +01:00
|
|
|
STRING_make(p, p2 - p + 1);
|
|
|
|
STRING_make_char(escr);
|
2007-12-30 17:41:49 +01:00
|
|
|
p = p2 + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-10 01:18:00 +01:00
|
|
|
STRING_make(p, l + data[i] - p);
|
2007-12-30 17:41:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-10 01:18:00 +01:00
|
|
|
STRING_make_char(escr);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
else if (l)
|
2009-03-02 12:36:42 +01:00
|
|
|
STRING_make(p, l);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-11-10 01:18:00 +01:00
|
|
|
GB_ReturnString(STRING_end_temp());
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CARRAY_reverse)
|
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
size_t size;
|
|
|
|
int count;
|
|
|
|
char *buffer[16];
|
|
|
|
char *pi, *pj;
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
count = THIS->count;
|
2011-11-24 22:45:21 +01:00
|
|
|
if (count > 1)
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
2011-11-24 22:45:21 +01:00
|
|
|
size = THIS->size;
|
|
|
|
pi = get_data(THIS, 0);
|
|
|
|
pj = get_data(THIS, count - 1);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
memcpy(buffer, pi, size);
|
|
|
|
memcpy(pi, pj, size);
|
|
|
|
memcpy(pj, buffer, size);
|
|
|
|
pi += size;
|
|
|
|
pj -= size;
|
|
|
|
}
|
|
|
|
while (pi < pj);
|
2009-03-02 12:36:42 +01:00
|
|
|
}
|
2011-11-24 22:45:21 +01:00
|
|
|
|
|
|
|
GB_ReturnObject(THIS);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Read, GB_OBJECT file; GB_INTEGER start; GB_INTEGER length)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
int count = THIS->count;
|
2009-03-02 12:36:42 +01:00
|
|
|
int start = VARGOPT(start, 0);
|
|
|
|
int length = VARGOPT(length, count);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-14 22:51:42 +02:00
|
|
|
if (check_start_length(count, &start, &length))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
STREAM_read(CSTREAM_stream(VARG(file)), get_data(THIS, start), length * THIS->size);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Write, GB_OBJECT file; GB_INTEGER start; GB_INTEGER length)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
int count = THIS->count;
|
2009-03-02 12:36:42 +01:00
|
|
|
int start = VARGOPT(start, 0);
|
|
|
|
int length = VARGOPT(length, count);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-14 22:51:42 +02:00
|
|
|
if (check_start_length(count, &start, &length))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
STREAM_write(CSTREAM_stream(VARG(file)), get_data(THIS, start), length * THIS->size);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_PROPERTY(Array_Dim)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_ReturnInteger(get_dim(THIS));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Bounds_get, GB_INTEGER index)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
int dim = get_dim(THIS);
|
|
|
|
int index = VARG(index);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (index < 0 || index >= dim)
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_BOUND);
|
|
|
|
return;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_ReturnInteger(get_bound(THIS, index));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Byte_ToString, GB_INTEGER start; GB_INTEGER length)
|
2010-07-08 00:06:05 +02:00
|
|
|
|
|
|
|
int start, length;
|
|
|
|
int count = THIS->count;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
start = VARGOPT(start, 0);
|
|
|
|
|
|
|
|
if (start < 0)
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_BOUND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start >= count)
|
|
|
|
{
|
2011-10-24 21:33:41 +02:00
|
|
|
GB_ReturnVoidString();
|
2010-07-08 00:06:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = VARGOPT(length, -1);
|
|
|
|
if (length < 0)
|
|
|
|
{
|
|
|
|
p = memchr((char *)THIS->data + start, 0, count - start);
|
|
|
|
if (!p)
|
|
|
|
length = count - start;
|
|
|
|
else
|
|
|
|
length = p - ((char *)THIS->data + start);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((start + length) > count)
|
|
|
|
length = count - start;
|
|
|
|
}
|
|
|
|
|
|
|
|
GB_ReturnNewString((char *)THIS->data + start, length);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
BEGIN_METHOD(Array_Byte_FromString, GB_STRING string)
|
2010-07-08 00:06:05 +02:00
|
|
|
|
2011-07-03 22:46:03 +02:00
|
|
|
CARRAY *array;
|
2010-07-08 00:06:05 +02:00
|
|
|
char *string = STRING(string);
|
|
|
|
int length = LENGTH(string);
|
|
|
|
|
2011-07-03 22:46:03 +02:00
|
|
|
GB_ArrayNew((GB_ARRAY *)POINTER(&array), T_BYTE, length);
|
2011-09-11 18:31:51 +02:00
|
|
|
memcpy(array->data, string, length);
|
2011-07-03 22:46:03 +02:00
|
|
|
GB_ReturnObject(array);
|
2010-07-08 00:06:05 +02:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD(ArrayOfStruct_get, GB_INTEGER index)
|
|
|
|
|
|
|
|
void *data = get_data_multi(THIS, ARG(index), GB_NParam() + 1);
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
GB_ReturnObject(CSTRUCT_create_static(THIS, (CLASS *)THIS->type, data));
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2011-06-25 00:33:26 +02:00
|
|
|
|
2011-01-13 19:56:52 +01:00
|
|
|
BEGIN_METHOD(ArrayOfStruct_put, GB_OBJECT value; GB_INTEGER index)
|
|
|
|
|
|
|
|
int i;
|
|
|
|
CLASS *class = (CLASS *)THIS->type;
|
|
|
|
char *addr;
|
|
|
|
void *object = VARG(value);
|
|
|
|
void *data;
|
|
|
|
VALUE temp;
|
|
|
|
CLASS_DESC *desc;
|
|
|
|
|
|
|
|
if (GB_CheckObject(object))
|
|
|
|
return;
|
|
|
|
|
|
|
|
data = get_data_multi(THIS, ARG(index), GB_NParam() + 1);
|
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < class->n_desc; i++)
|
|
|
|
{
|
|
|
|
desc = class->table[i].desc;
|
|
|
|
|
|
|
|
if (((CSTRUCT *)object)->ref)
|
|
|
|
addr = (char *)((CSTATICSTRUCT *)object)->addr + desc->variable.offset;
|
|
|
|
else
|
|
|
|
addr = (char *)object + sizeof(CSTRUCT) + desc->variable.offset;
|
|
|
|
|
|
|
|
VALUE_class_read(desc->variable.class, &temp, (void *)addr, desc->variable.ctype, object);
|
|
|
|
|
|
|
|
addr = (char *)data + desc->variable.offset;
|
|
|
|
VALUE_write(&temp, (void *)addr, desc->variable.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
|
2011-06-25 00:33:26 +02:00
|
|
|
#if 0
|
|
|
|
BEGIN_PROPERTY(ArrayOfStruct_Last)
|
|
|
|
|
|
|
|
int index = THIS->count - 1;
|
|
|
|
|
|
|
|
if (check_not_multi(THIS))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_ARG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *data = get_data(THIS, index);
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
GB_ReturnObject(CSTRUCT_create_static(THIS, (CLASS *)THIS->type, data));
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
BEGIN_METHOD_VOID(ArrayOfStruct_next)
|
|
|
|
|
|
|
|
int *index = (int *)GB_GetEnum();
|
|
|
|
|
|
|
|
if (*index >= THIS->count)
|
|
|
|
GB_StopEnum();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GB_ReturnObject(CSTRUCT_create_static(THIS, (CLASS *)THIS->type, get_data(THIS, *index)));
|
|
|
|
(*index)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2010-11-27 02:27:23 +01:00
|
|
|
static CARRAY *_converted_array;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-27 02:27:23 +01:00
|
|
|
static void error_array_convert()
|
|
|
|
{
|
|
|
|
OBJECT_UNREF(_converted_array, "error_array_convert");
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-27 02:27:23 +01:00
|
|
|
static void *array_convert(CARRAY *src, CLASS *class)
|
|
|
|
{
|
|
|
|
CARRAY *array;
|
|
|
|
int i;
|
|
|
|
void *data;
|
|
|
|
VALUE temp;
|
|
|
|
|
|
|
|
if (!CLASS_inherits(class, CLASS_Array))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
_converted_array = array = OBJECT_create(class, NULL, NULL, 0);
|
|
|
|
|
|
|
|
ARRAY_add_many_void(&array->data, src->count);
|
|
|
|
array->count = src->count;
|
|
|
|
|
|
|
|
ON_ERROR(error_array_convert)
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
2010-11-27 02:27:23 +01:00
|
|
|
for (i = 0; i < src->count; i++)
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
2010-11-27 02:27:23 +01:00
|
|
|
data = CARRAY_get_data(src, i);
|
|
|
|
VALUE_read(&temp, data, src->type);
|
2010-11-27 02:40:19 +01:00
|
|
|
BORROW(&temp);
|
2010-11-27 02:27:23 +01:00
|
|
|
data = CARRAY_get_data(array, i);
|
|
|
|
VALUE_write(&temp, data, array->type);
|
2010-11-27 02:40:19 +01:00
|
|
|
RELEASE(&temp);
|
2009-03-02 12:36:42 +01:00
|
|
|
}
|
|
|
|
}
|
2010-11-27 02:27:23 +01:00
|
|
|
END_ERROR
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
#include "gbx_c_array.h"
|
|
|
|
|
2010-11-27 02:27:23 +01:00
|
|
|
#define array_convert NULL
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif /* #ifndef GBX_INFO */
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_ArrayBounds[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE(".Array.Bounds", sizeof(CARRAY)), GB_NOT_CREATABLE(),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_get", "i", Array_Bounds_get, "(Dimension)i"),
|
[DEVELOPMENT ENVIRONMENT]
* NEW: The debug window has a button to switch between "normal view" and
"symbol view". In "normal view", array and collection contents are
displayed. If the object is not an array or a collection, then all
non-hidden symbols are displayed. In "symbol view", all objects symbols
are displayed, whatever the object type is.
[INTERPRETER]
* NEW: The debugger now can display collection-like objects. An object can
be displayed like a collection if it has a Count property, is enumerable,
has a _get special method taking a string, and has a Key property that
returns the key of the last enumerated element.
[GB.DEBUG]
* NEW: The debugger now can display collection-like objects. An object can
be displayed like a collection if it has a Count property, is enumerable,
has a _get special method taking a string, and has a Key property that
returns the key of the last enumerated element.
[GB.FORM]
* BUG: GridView.Clear resets the height of all rows to the default value.
git-svn-id: svn://localhost/gambas/trunk@4558 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-03-17 03:05:31 +01:00
|
|
|
GB_PROPERTY_READ("Count", "i", Array_Dim),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_Array[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("Array", sizeof(CARRAY)), GB_NOT_CREATABLE(),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_free", NULL, Array_free, NULL),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_PROPERTY_READ("Type", "i", Array_Type),
|
|
|
|
GB_PROPERTY_READ("Count", "i", Array_Count),
|
|
|
|
GB_PROPERTY_READ("Max", "i", Array_Max),
|
|
|
|
GB_PROPERTY_READ("Length", "i", Array_Count),
|
|
|
|
GB_PROPERTY_READ("Dim", "i", Array_Dim),
|
|
|
|
GB_PROPERTY_READ("Data", "p", Array_Data),
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_PROPERTY_SELF("Bounds", ".Array.Bounds"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Remove", NULL, Array_Remove, "(Index)i[(Length)i]"),
|
|
|
|
GB_METHOD("Clear", NULL, Array_Clear, NULL),
|
|
|
|
GB_METHOD("Resize", NULL, Array_Resize, "(Size)i"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-29 22:47:41 +01:00
|
|
|
//GB_METHOD("Add", NULL, Array_Add, "(Value)v[(Index)i]"),
|
|
|
|
//GB_METHOD("Push", NULL, Array_Push, "(Value)v"),
|
|
|
|
//GB_METHOD("_put", NULL, Array_put, "(Value)v(Index)i."),
|
2009-04-08 12:11:16 +02:00
|
|
|
|
2011-12-29 22:47:41 +01:00
|
|
|
//GB_METHOD("Pop", "v", Array_Pop_variant, NULL), // Does not work
|
|
|
|
//GB_METHOD("_get", "v", Array_get_variant, "(Index)i."),
|
|
|
|
//GB_METHOD("_next", "v", Array_next_variant, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "v", Array_Last),
|
2009-04-08 12:11:16 +02:00
|
|
|
|
2011-12-29 22:47:41 +01:00
|
|
|
/*GB_METHOD("Copy", "Array", Array_Copy, "[(Start)i(Length)i]"),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Extract", "Array", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Array", Array_Extract, "(Start)i[(Length)i]"),
|
2011-12-29 22:47:41 +01:00
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)v[(Start)i(Length)i]"),*/
|
2010-11-27 02:27:23 +01:00
|
|
|
|
|
|
|
GB_INTERFACE("_convert", array_convert),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_BooleanArray[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("Boolean[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Integer_Add, "(Value)b[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Integer_Push, "(Value)b"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Boolean_put, "(Value)b(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_Integer_Find, "(Value)b[(Start)i]"),
|
|
|
|
GB_METHOD("Exist", "b", Array_Integer_Exist, "(Value)b"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "b", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "b", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "b", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "b", Array_Last),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Read", NULL, Array_Read, "(Stream)Stream;[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Write", NULL, Array_Write, "(Stream)Stream;[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "Boolean[]", Array_Insert, "(Array)Boolean[];[(Pos)i]"),
|
|
|
|
GB_METHOD("Copy", "Boolean[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "Boolean[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Boolean[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Sort", "Boolean[]", Array_Sort, "[(Mode)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "Boolean[]", CARRAY_reverse, NULL),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)b[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_ByteArray[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("Byte[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Integer_Add, "(Value)c[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Integer_Push, "(Value)c"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Byte_put, "(Value)c(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_Integer_Find, "(Value)c[(Start)i]"),
|
|
|
|
GB_METHOD("Exist", "b", Array_Integer_Exist, "(Value)c"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "c", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "c", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "c", Array_next, NULL),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Read", NULL, Array_Read, "(Stream)Stream;[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Write", NULL, Array_Write, "(Stream)Stream;[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "Byte[]", Array_Insert, "(Array)Byte[];[(Pos)i]"),
|
|
|
|
GB_METHOD("Copy", "Byte[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "Byte[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Byte[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Sort", "Byte[]", Array_Sort, "[(Mode)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "Byte[]", CARRAY_reverse, NULL),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)c[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("ToString", "s", Array_Byte_ToString, "[(Start)i(Length)i]"),
|
|
|
|
GB_STATIC_METHOD("FromString", "Byte[]", Array_Byte_FromString, "(String)s"),
|
2010-07-08 00:06:05 +02:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_ShortArray[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("Short[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Integer_Add, "(Value)h[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Integer_Push, "(Value)h"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Short_put, "(Value)h(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_Integer_Find, "(Value)h[(Start)i]"),
|
|
|
|
GB_METHOD("Exist", "b", Array_Integer_Exist, "(Value)h"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "h", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "h", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "h", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "h", Array_Last),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Read", NULL, Array_Read, "(Stream)Stream;[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Write", NULL, Array_Write, "(Stream)Stream;[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "Short[]", Array_Insert, "(Array)Short[];[(Pos)i]"),
|
|
|
|
GB_METHOD("Copy", "Short[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "Short[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Short[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Sort", "Short[]", Array_Sort, "[(Mode)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "Short[]", CARRAY_reverse, NULL),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)h[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_IntegerArray[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("Integer[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Integer_Add, "(Value)i[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Integer_Push, "(Value)i"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Integer_put, "(Value)i(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_Integer_Find, "(Value)i[(Start)i]"),
|
|
|
|
GB_METHOD("Exist", "b", Array_Integer_Exist, "(Value)i"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "i", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "i", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "i", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "i", Array_Last),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Read", NULL, Array_Read, "(Stream)Stream;[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Write", NULL, Array_Write, "(Stream)Stream;[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "Integer[]", Array_Insert, "(Array)Integer[];[(Pos)i]"),
|
|
|
|
GB_METHOD("Copy", "Integer[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "Integer[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Integer[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Sort", "Integer[]", Array_Sort, "[(Mode)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "Integer[]", CARRAY_reverse, NULL),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)i[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_LongArray[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("Long[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Long_Add, "(Value)l[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Long_Push, "(Value)l"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Long_put, "(Value)l(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_Long_Find, "(Value)l[(Start)i]"),
|
|
|
|
GB_METHOD("Exist", "b", Array_Long_Exist, "(Value)l"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "l", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "l", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "l", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "l", Array_Last),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Read", NULL, Array_Read, "(Stream)Stream;[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Write", NULL, Array_Write, "(Stream)Stream;[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "Long[]", Array_Insert, "(Array)Long[];[(Pos)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Copy", "Long[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "Long[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Long[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Sort", "Long[]", Array_Sort, "[(Mode)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "Long[]", CARRAY_reverse, NULL),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)l[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
2008-01-23 20:56:18 +01:00
|
|
|
#ifdef OS_64BITS
|
2011-12-28 04:04:46 +01:00
|
|
|
#define Array_Pointer_Add Array_Long_Add
|
|
|
|
#define Array_Pointer_Push Array_Long_Push
|
|
|
|
#define Array_Pointer_put Array_Long_put
|
|
|
|
#define Array_Pointer_Find Array_Long_Find
|
|
|
|
#define Array_Pointer_Exist Array_Long_Exist
|
2008-01-23 20:56:18 +01:00
|
|
|
#else
|
2011-12-28 04:04:46 +01:00
|
|
|
#define Array_Pointer_Add Array_Integer_Add
|
|
|
|
#define Array_Pointer_Push Array_Integer_Push
|
|
|
|
#define Array_Pointer_put Array_Integer_put
|
|
|
|
#define Array_Pointer_Find Array_Integer_Find
|
|
|
|
#define Array_Pointer_Exist Array_Integer_Exist
|
2008-01-23 20:56:18 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
GB_DESC NATIVE_PointerArray[] =
|
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("Pointer[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2008-01-23 20:56:18 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2008-01-23 20:56:18 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Pointer_Add, "(Value)p[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Pointer_Push, "(Value)p"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Pointer_put, "(Value)p(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_Pointer_Find, "(Value)p[(Start)i]"),
|
|
|
|
GB_METHOD("Exist", "b", Array_Pointer_Exist, "(Value)p"),
|
2008-01-23 20:56:18 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "p", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "p", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "p", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "p", Array_Last),
|
2008-01-23 20:56:18 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Read", NULL, Array_Read, "(Stream)Stream;[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Write", NULL, Array_Write, "(Stream)Stream;[(Start)i(Length)i]"),
|
2008-01-23 20:56:18 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "Pointer[]", Array_Insert, "(Array)Pointer[];[(Pos)i]"),
|
2008-01-23 20:56:18 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Copy", "Pointer[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "Pointer[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Pointer[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Sort", "Pointer[]", Array_Sort, "[(Mode)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "Pointer[]", CARRAY_reverse, NULL),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)p[(Start)i(Length)i]"),
|
2008-01-23 20:56:18 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2008-01-23 20:56:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_StringArray[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("String[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_String_Add, "(Value)s[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_String_Push, "(Value)s"),
|
|
|
|
GB_METHOD("_put", NULL, Array_String_put, "(Value)s(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_String_Find, "(Value)s[(Mode)i(Start)i]"),
|
|
|
|
GB_METHOD("Exist", "b", Array_String_Exist, "(Value)s[(Mode)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "s", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "s", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "s", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "s", Array_Last),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "String[]", Array_Insert, "(Array)String[];[(Pos)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Join", "s", Array_String_join, "[(Separator)s(Escape)s]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Copy", "String[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "String[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "String[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Sort", "String[]", Array_Sort, "[(Mode)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "String[]", CARRAY_reverse, NULL),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)s[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_FloatArray[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("Float[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Float_Add, "(Value)f[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Float_Push, "(Value)f"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Float_put, "(Value)f(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_Float_Find, "(Value)f[(Start)i]"),
|
|
|
|
GB_METHOD("Exist", "b", Array_Float_Exist, "(Value)f"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "f", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "f", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "f", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "f", Array_Last),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Read", NULL, Array_Read, "(Stream)Stream;[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Write", NULL, Array_Write, "(Stream)Stream;[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "Float[]", Array_Insert, "(Array)Float[];[(Pos)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Copy", "Float[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "Float[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Float[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Sort", "Float[]", Array_Sort, "[(Mode)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "Float[]", CARRAY_reverse, NULL),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)f[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_SingleArray[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("Single[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Single_Add, "(Value)g[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Single_Push, "(Value)g"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Single_put, "(Value)g(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_Single_Find, "(Value)g[(Start)i]"),
|
|
|
|
GB_METHOD("Exist", "b", Array_Single_Exist, "(Value)g"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "g", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "g", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "g", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "g", Array_Last),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Read", NULL, Array_Read, "(Stream)Stream;[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Write", NULL, Array_Write, "(Stream)Stream;[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "Single[]", Array_Insert, "(Array)Single[];[(Pos)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Copy", "Single[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "Single[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Single[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Sort", "Single[]", Array_Sort, "[(Mode)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "Single[]", CARRAY_reverse, NULL),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)g[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_DateArray[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("Date[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Date_Add, "(Value)d[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Date_Push, "(Value)d"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Date_put, "(Value)d(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_Date_Find, "(Value)d[(Start)i]"),
|
|
|
|
GB_METHOD("Exist", "b", Array_Date_Exist, "(Value)d"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "d", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "d", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "d", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "d", Array_Last),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Read", NULL, Array_Read, "(Stream)Stream;[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Write", NULL, Array_Write, "(Stream)Stream;[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "Date[]", Array_Insert, "(Array)Date[];[(Pos)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Copy", "Date[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "Date[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Date[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Sort", "Date[]", Array_Sort, "[(Mode)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "Date[]", CARRAY_reverse, NULL),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)d[(Start)i(Length)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_ObjectArray[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("Object[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Object_Add, "(Value)o[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Object_Push, "(Value)o"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Object_put, "(Value)o(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_Object_Find, "(Value)o[(Start)i]"),
|
2011-12-27 14:39:23 +01:00
|
|
|
GB_METHOD("FindByRef", "i", Array_Object_FindByRef, "(Value)o[(Start)i]"),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Exist", "b", Array_Object_Exist, "(Value)o"),
|
2011-12-27 14:39:23 +01:00
|
|
|
GB_METHOD("ExistByRef", "b", Array_Object_ExistByRef, "(Value)o"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "o", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "o", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "o", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "o", Array_Last),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "Object[]", Array_Insert, "(Array)Object[];[(Pos)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Copy", "Object[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "Object[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Object[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)o[(Start)i(Length)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "Object[]", CARRAY_reverse, NULL),
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Sort", "Object[]", Array_Sort, "[(Mode)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
GB_DESC NATIVE_VariantArray[] =
|
|
|
|
{
|
|
|
|
GB_DECLARE("Variant[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2010-07-08 00:06:05 +02:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Variant_Add, "(Value)v[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Variant_Push, "(Value)v"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Variant_put, "(Value)v(Index)i."),
|
2010-07-08 00:06:05 +02:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "v", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "v", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "v", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "v", Array_Last),
|
2010-07-08 00:06:05 +02:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "Variant[]", Array_Insert, "(Array)Variant[];[(Pos)i]"),
|
2010-07-08 00:06:05 +02:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Copy", "Variant[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "Variant[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "Variant[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)v[(Start)i(Length)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "Variant[]", CARRAY_reverse, NULL),
|
2010-07-08 00:06:05 +02:00
|
|
|
|
|
|
|
GB_END_DECLARE
|
|
|
|
};
|
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
// Beware: if this declaration is modified, the ARRAY_TEMPLATE_NDESC constant must be modified accordingly.
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_DESC NATIVE_TemplateArray[ARRAY_TEMPLATE_NDESC] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_DECLARE("*[]", sizeof(CARRAY)), GB_INHERITS("Array"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Add", NULL, Array_Object_Add, "(Value)*;[(Index)i]"),
|
|
|
|
GB_METHOD("Push", NULL, Array_Object_Push, "(Value)*;"),
|
|
|
|
GB_METHOD("_put", NULL, Array_Object_put, "(Value)*;(Index)i."),
|
|
|
|
GB_METHOD("Find", "i", Array_Object_Find, "(Value)*;[(Start)i]"),
|
2011-12-27 14:39:23 +01:00
|
|
|
GB_METHOD("FindByRef", "i", Array_Object_FindByRef, "(Value)*;[(Start)i]"),
|
2012-01-13 09:04:11 +01:00
|
|
|
GB_METHOD("Exist", "b", Array_Object_Exist, "(Value)*;"),
|
2011-12-27 14:39:23 +01:00
|
|
|
GB_METHOD("ExistByRef", "b", Array_Object_ExistByRef, "(Value)*;"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Pop", "*", Array_Pop, NULL),
|
|
|
|
GB_METHOD("_get", "*", Array_get, "(Index)i."),
|
|
|
|
GB_METHOD("_next", "*", Array_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "*", Array_Last),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Insert", "*", Array_Insert, "(Array)*[];[(Pos)i]"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_METHOD("Copy", "*[]", Array_Copy, "[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Extract", "*[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Delete", "*[]", Array_Extract, "(Start)i[(Length)i]"),
|
|
|
|
GB_METHOD("Fill", NULL, Array_Fill, "(Value)*;[(Start)i(Length)i]"),
|
|
|
|
GB_METHOD("Sort", "*[]", Array_Sort, "[(Mode)i]"),
|
2011-11-24 22:45:21 +01:00
|
|
|
GB_METHOD("Reverse", "*[]", CARRAY_reverse, NULL),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
// Beware: if this declaration is modified, the ARRAY_OF_STRUCT_TEMPLATE_NDESC constant must be modified accordingly.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
GB_DESC NATIVE_TemplateArrayOfStruct[ARRAY_OF_STRUCT_TEMPLATE_NDESC] =
|
|
|
|
{
|
|
|
|
GB_DECLARE("$*[]", sizeof(CARRAY)), GB_NOT_CREATABLE(),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
//GB_METHOD("_new", NULL, Array_new, "[(Size)i.]"),
|
|
|
|
GB_METHOD("_free", NULL, Array_free, NULL),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-28 04:04:46 +01:00
|
|
|
GB_PROPERTY_READ("Count", "i", Array_Count),
|
|
|
|
GB_PROPERTY_READ("Max", "i", Array_Max),
|
|
|
|
GB_PROPERTY_READ("Length", "i", Array_Count),
|
|
|
|
GB_PROPERTY_READ("Dim", "i", Array_Dim),
|
|
|
|
GB_PROPERTY_READ("Data", "p", Array_Data),
|
2010-07-08 00:06:05 +02:00
|
|
|
GB_PROPERTY_SELF("Bounds", ".Array.Bounds"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
GB_METHOD("_get", "*", ArrayOfStruct_get, "(Index)i."),
|
2011-01-13 19:56:52 +01:00
|
|
|
GB_METHOD("_put", NULL, ArrayOfStruct_put, "(Value)*;(Index)i."),
|
2010-07-08 00:06:05 +02:00
|
|
|
GB_METHOD("_next", "*", ArrayOfStruct_next, NULL),
|
2011-06-25 00:33:26 +02:00
|
|
|
//GB_PROPERTY_READ("Last", "b", ArrayOfStruct_Last),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GBX_INFO
|
|
|
|
|
|
|
|
|
|
|
|
static CARRAY *_array;
|
|
|
|
static bool _novoid;
|
|
|
|
static char *_entry;
|
|
|
|
static const char *_ptr;
|
|
|
|
static int _lptr;
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
static void add_char_real(const char *p)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
//fprintf(stderr, "add_char: %p %c\n", p, p ? *p : 0);
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
/*if (p && p == (_ptr + _lptr))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
_lptr++;
|
|
|
|
return;
|
2010-06-05 01:48:53 +02:00
|
|
|
}*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (_lptr)
|
|
|
|
{
|
|
|
|
//fprintf(stderr, "STRING_add: '%.*s'\n", _lptr, _ptr);
|
2011-09-07 14:38:29 +02:00
|
|
|
_entry = STRING_add(_entry, _ptr, _lptr);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_ptr = p;
|
|
|
|
_lptr = p ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
#define add_char(_p) \
|
|
|
|
({ \
|
|
|
|
if ((_p) && (_p) == (_ptr + _lptr)) \
|
|
|
|
_lptr++; \
|
|
|
|
else \
|
|
|
|
add_char_real(_p); \
|
|
|
|
})
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static void add_entry()
|
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
add_char_real(NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (!_entry)
|
|
|
|
{
|
|
|
|
if (!_novoid)
|
2010-05-29 23:10:36 +02:00
|
|
|
ARRAY_add_void_size(&_array->data);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-29 23:10:36 +02:00
|
|
|
*((char **)ARRAY_add_size(&_array->data)) = _entry;
|
2007-12-30 17:41:49 +01:00
|
|
|
_entry = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//fprintf(stderr, "** add_entry\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-10 21:30:41 +02:00
|
|
|
void CARRAY_split(CARRAY *_object, const char *str, int lstr, const char *sep, const char *esc, bool no_void, bool keep_esc)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char c;
|
|
|
|
bool escape;
|
2009-03-02 12:36:42 +01:00
|
|
|
char escl, escr;
|
|
|
|
bool lsep;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
if (sep == NULL || *sep == 0)
|
|
|
|
sep = ",";
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-20 00:50:34 +01:00
|
|
|
lsep = sep[1];
|
|
|
|
|
2009-03-02 12:36:42 +01:00
|
|
|
clear(THIS);
|
|
|
|
|
|
|
|
_array = _object;
|
|
|
|
_entry = NULL;
|
|
|
|
_novoid = no_void;
|
|
|
|
_ptr = NULL;
|
|
|
|
_lptr = 0;
|
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
if (esc == NULL || *esc == 0)
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
i = lstr;
|
2010-06-16 12:25:21 +02:00
|
|
|
|
|
|
|
if (!lsep)
|
2010-06-09 01:08:04 +02:00
|
|
|
{
|
2010-06-16 12:25:21 +02:00
|
|
|
char csep = sep[0];
|
2010-06-09 01:08:04 +02:00
|
|
|
|
2010-06-16 12:25:21 +02:00
|
|
|
while (i--)
|
|
|
|
{
|
|
|
|
if (*str == csep)
|
|
|
|
add_entry();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//add_char(str);
|
|
|
|
if (!_lptr) _ptr = str;
|
|
|
|
_lptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (i--)
|
2010-06-09 01:08:04 +02:00
|
|
|
{
|
2010-06-16 12:25:21 +02:00
|
|
|
if (index(sep, *str))
|
|
|
|
add_entry();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//add_char(str);
|
|
|
|
if (!_lptr) _ptr = str;
|
|
|
|
_lptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
str++;
|
2010-06-09 01:08:04 +02:00
|
|
|
}
|
|
|
|
}
|
2009-03-02 12:36:42 +01:00
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
add_entry();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
escl = *esc++;
|
|
|
|
if (*esc)
|
|
|
|
escr = *esc;
|
|
|
|
else
|
|
|
|
escr = escl;
|
|
|
|
|
|
|
|
escape = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < lstr; i++)
|
2009-03-02 12:36:42 +01:00
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
c = *str;
|
|
|
|
|
|
|
|
if (escape)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
if (c != escr)
|
|
|
|
add_char(str);
|
|
|
|
else if ((i < (lstr - 1)) && str[1] == escr)
|
|
|
|
{
|
|
|
|
add_char(str);
|
|
|
|
str++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
escape = FALSE;
|
|
|
|
if (keep_esc)
|
|
|
|
add_char(str);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2010-06-09 01:08:04 +02:00
|
|
|
else if (c == escl)
|
2009-09-10 21:30:41 +02:00
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
escape = TRUE;
|
2009-09-10 21:30:41 +02:00
|
|
|
if (keep_esc)
|
|
|
|
add_char(str);
|
|
|
|
}
|
2010-06-09 01:08:04 +02:00
|
|
|
else if (c == *sep || (lsep && index(&sep[1], c)))
|
|
|
|
{
|
|
|
|
add_entry();
|
|
|
|
}
|
|
|
|
else
|
2009-09-10 21:30:41 +02:00
|
|
|
add_char(str);
|
2010-06-09 01:08:04 +02:00
|
|
|
|
|
|
|
str++;
|
2009-03-02 12:36:42 +01:00
|
|
|
}
|
2010-06-09 01:08:04 +02:00
|
|
|
|
|
|
|
add_entry();
|
2009-03-02 12:36:42 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
_object->count = ARRAY_count(_object->data);
|
2007-12-30 17:41:49 +01:00
|
|
|
_array = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Gambas API */
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
void GB_ArrayNew(GB_ARRAY *array, TYPE type, int size)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
int np;
|
2010-07-08 00:06:05 +02:00
|
|
|
CTYPE ctype;
|
2009-03-02 12:36:42 +01:00
|
|
|
|
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
GB_Push(1, GB_T_INTEGER, size);
|
|
|
|
np = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
np = 0;
|
|
|
|
}
|
2010-05-19 14:43:57 +02:00
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
ctype.id = T_NULL;
|
|
|
|
*array = OBJECT_create(CARRAY_get_array_class((CLASS *)type, ctype), NULL, NULL, np);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
int GB_ArrayCount(GB_ARRAY array)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
return ((CARRAY *)array)->count;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void *GB_ArrayAdd(GB_ARRAY array)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
return insert((CARRAY *)array, -1);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void *GB_ArrayGet(GB_ARRAY array, int index)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-03-02 12:36:42 +01:00
|
|
|
return get_data((CARRAY *)array, index);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-03-31 21:04:28 +02:00
|
|
|
TYPE GB_ArrayType(GB_ARRAY array)
|
|
|
|
{
|
|
|
|
return ((CARRAY *)array)->type;
|
|
|
|
}
|
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
void GB_ArrayRemove(GB_ARRAY array, int index)
|
|
|
|
{
|
|
|
|
copy_remove((CARRAY *)array, index, 1, FALSE, TRUE);
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|