[Glib] - Can't store two values in a same GNode



Hi, I'm new in this list, so I don't know if it's the correct one.
Here is my problem:

I want to store more than a value in a GNode node, and so, for doing that I use a struct.
I can store the values, but when I try to find them again using g_node_find_child, It doesn't work.

######### Here's the code: #########

#include <glib.h>
#include <stdio.h>
#include <string.h>

int main()
{
    // Types declaration
    typedef struct _struct
    {
        int min;
        int max;
    } struct_type;
    typedef int int_type;

    // Variables declaration
    GNode *Root,
 *Child;
    int_type var_int1, var_int2;
    struct_type var_struct1, var_struct2;

    // Variables inizialization
    var_int1 = 5;
    var_struct1.min = 1;
    var_struct1.max = 9;

    // Root and child nodes creation, with its respective values
    // The root node has one int
    Root = g_node_new((gpointer) var_int1);     
    // The child node has two int inside a struct
    Child = g_node_append_data(Root, &var_struct1); 

    // Getting the values stored in the nodes
    var_int2 = (int) Root->data;
    memcpy(&var_struct2, Child->data, sizeof(struct_type));

    // Visualization of the values
    printf("'var_int1'
 data: %d\n", var_int1);
    printf("'var_struct1' data: %d, %d\n", var_struct1.min, var_struct1.max);
    printf("'var_int2' data: %d\n", var_int2);
    printf("'var_struct2' data: %d, %d\n", var_struct2.min, var_struct2.max);

    // Make some searchs and see the results
    if (g_node_find(Root, G_LEVEL_ORDER, G_TRAVERSE_ALL, (gpointer) var_int1) == NULL)
        printf("Data 'var_int1' not found\n");
    else
        printf("Data 'var_int1' found\n");

    if (g_node_find(Root, G_LEVEL_ORDER, G_TRAVERSE_ALL, (gpointer) var_int2) == NULL)
        printf("Data 'var_int2' not found\n");
    else
        printf("Data 'var_int2' found\n");

    if
 (g_node_find_child(Root, G_TRAVERSE_ALL, &var_struct1) == NULL)
        printf("Data 'var_struct1' not found\n");
    else
        printf("Data 'var_struct1' found\n");

    if (g_node_find_child(Root, G_TRAVERSE_ALL, &var_struct2) == NULL)
        printf("Data 'var_struct2' not found\n");
    else
        printf("Data 'var_struct2' found\n");

    // Destruction of the tree (root and child)
    g_node_destroy(Root);

    return 0;
}

######### And this is the output: #########

root charles-laptop:/home/charles/workspace/Glib_test_05# ./Glib_test_05 
'var_int1' data: 5
'var_struct1' data: 1, 9
'var_int2' data: 5
'var_struct2' data: 1, 9
Data 'var_int1' found
Data
 'var_int2' found
Data 'var_struct1' found
Data 'var_struct2' not found


Any ideas?
Thanks in advance.-





      ____________________________________________________________________________________
¡Obtén la mejor experiencia en la web!
Descarga gratis el nuevo Internet Explorer 8. 
http://downloads.yahoo.com/ieak8/?l=e1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]