GhtErr ght_node_free(GhtNode *node) { int i; const int deep = 1; assert(node != NULL); if ( node->attributes ) GHT_TRY(ght_attribute_free(node->attributes)); if ( node->children ) GHT_TRY(ght_nodelist_free_deep(node->children)); if ( node->hash ) GHT_TRY(ght_hash_free(node->hash)); ght_free(node); return GHT_OK; }
PCPATCH_UNCOMPRESSED * pc_patch_uncompressed_from_ght(const PCPATCH_GHT *paght) { #ifndef HAVE_LIBGHT pcerror("%s: libght support is not enabled", __func__); return NULL; #else int i, npoints; PCPATCH_UNCOMPRESSED *patch; PCPOINT point; const PCSCHEMA *schema; GhtNodeListPtr nodelist; GhtCoordinate coord; GhtNodePtr node; GhtTreePtr tree; GhtAttributePtr attr; /* Build a structured tree from the tree serialization */ if ( ! paght || ! paght->ght ) return NULL; tree = ght_tree_from_pc_patch(paght); if ( ! tree ) return NULL; /* Convert tree to nodelist */ ght_nodelist_new(paght->npoints, &nodelist); ght_tree_to_nodelist(tree, nodelist); /* Allocate uncompressed patch */ ght_nodelist_get_num_nodes(nodelist, &npoints); schema = paght->schema; patch = pcalloc(sizeof(PCPATCH_UNCOMPRESSED)); patch->type = PC_NONE; patch->readonly = PC_FALSE; patch->schema = schema; patch->npoints = npoints; patch->bounds = paght->bounds; patch->stats = pc_stats_clone(paght->stats); patch->maxpoints = npoints; patch->datasize = schema->size * npoints; patch->data = pcalloc(patch->datasize); /* Set up utility point */ point.schema = schema; point.readonly = PC_FALSE; point.data = patch->data; /* Process each point... */ for ( i = 0; i < npoints; i++ ) { double val; /* Read and set X and Y */ ght_nodelist_get_node(nodelist, i, &node); ght_node_get_coordinate(node, &coord); pc_point_set_x(&point, coord.x); pc_point_set_y(&point, coord.y); /* Read and set all the attributes */ ght_node_get_attributes(node, &attr); while ( attr ) { GhtDimensionPtr dim; const char *name; ght_attribute_get_value(attr, &val); ght_attribute_get_dimension(attr, &dim); ght_dimension_get_name(dim, &name); pc_point_set_double_by_name(&point, name, val); ght_attribute_get_next(attr, &attr); } point.data += schema->size; } /* Done w/ nodelist and tree */ ght_nodelist_free_deep(nodelist); // ght_tree_free(tree); /* Done */ return patch; #endif }