[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gambas-devel
Subject:    Re: [Gambas-devel] What's in GB_BASE or Is it save to copy it for another object?
From:       Benoît_Minisini <gambas () users ! sourceforge ! net>
Date:       2013-08-11 0:34:50
Message-ID: 5206DC2A.7090400 () users ! sourceforge ! net
[Download RAW message or body]

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

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Gambas-devel mailing list
Gambas-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic