#include "conv_functions.h" void build_MDB_val_from_node_info( MDB_val* mdb_value, double & lon, double & lat, elevation_value & elevation, std::list & neighbors ) { // Return a pointer (don't forget to free it with free()) to a // build_node_info with allocation of the two internal structure in the same // allocation. Design to be used to build a MDB_val char* pc; node_info_t ni; size_t len; len = sizeof(node_info_fixed_t) +neighbors.size()*sizeof(neightbor_t); pc = (char*)malloc(len); if(!pc) { fprintf(stderr,"Memory allocation failed\n"); abort(); } ni.fixed = (node_info_fixed_t*)pc; if(neighbors.size()>0) ni.neighbors = (neighbor_t*)(pc+sizeof(node_info_fixed_t)); else ni.neighbors = (neighbor_t*)NULL; ni.fixed->lon = lon; ni.fixed->lat = lat; ni.fixed->elevation = elevation; ni.fixed->neighbors_number = neighbors.size(); unsigned int i=0; for( std::list::iterator neighbors_it = neighbors.begin(); neighbors_it != neighbors.end(); neighbors_it++ ) { ni.neighbors[i].from = (*neighbors_it).from; ni.neighbors[i].to = (*neighbors_it).to; ni.neighbors[i].way_kind = (*neighbors_it).way_kind; i++; } mdb_value->mv_size = len; mdb_value->mv_data = (void*)pc; } void free_MDB_val_from_node_info( MDB_val* mdb_value ) { free(mdb_value->mv_data); mdb_value->mv_data = (void*)NULL; mdb_value->mv_size = 0; } void build_node_info_from_MDB_val( node_info_t* pni, MDB_val* mdb_value ) { if(mdb_value->mv_sizefixed = (node_info_fixed_t*)(mdb_value->mv_data); if(mdb_value->mv_size!=sizeof(node_info_fixed_t)+(pni->fixed->neighbors_number)*sizeof(neighbor_t)) { fprintf(stderr,"Error, database node info size mismatch\n"); abort(); } if(pni->fixed->neighbors_number>0) pni->neighbors = (neighbor_t*)(((char*)mdb_value->mv_data)+sizeof(node_info_fixed_t)); else pni->neighbors = (neighbor_t*)NULL; }