[Gambas-devel] What's in GB_BASE or Is it save to copy it for another object?

Benoît Minisini gambas at ...1...
Sun Aug 11 02:34:50 CEST 2013


Le 11/08/2013 02:21, Tobias Boege a écrit :
> Hi Benoit,
>
> I'm currently implementing an AVL tree class (named AvlTree) in gb.data and
> for my plans I need to give it a Current property which is an AvlTree
> itself, which is given in theory but I fear that it's not that easy in
> Gambas:
>
> ---
> typedef struct {
> 	NODE *left, *right;	/* Children or NULL */
> 	GB_STRING key;		/* The key string */
> 	GB_VARIANT_VALUE value;	/* Payload */
> } NODE;
>
> typedef struct {
> 	GB_BASE ob;
> 	NODE *root, *current;
> } CAVLTREE;
>
> GB_DESC CAvlTree[] = {
> 	GB_DECLARE("AvlTree", sizeof(CAVLTREE)),
> 	...
>
> 	GB_PROPERTY_READ("Current", "AvlTree", AvlTree_Current),
>
> 	...
> 	GB_END_DECLARE
> };
> ---
>
> To implement AvlTree_Current I imagine something as simple as:
>
> ---
> BEGIN_PROPERTY(AvlTree_Current)
>
> 	CAVLTREE *subtree;
>
> 	GB.Alloc(&subtree, sizeof(*subtree));
> 	memcpy(subtree, _object, sizeof(*subtree));
> 	subtree->root = subtree->current;
> 	GB.Ref(_object);
> 	GB.ReturnObject(subtree);
>
> END_PROPERTY
> ---
>

Simple: you *must* create a new Gambas object with the GB.New() API.

-- 
Benoît Minisini




More information about the Devel mailing list