diff options
author | sleske <sleske@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2014-07-07 14:28:09 +0000 |
---|---|---|
committer | sleske <sleske@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2014-07-07 14:28:09 +0000 |
commit | bbe01c917440fcf3a7ce9c03ddddd44dc1b83f62 (patch) | |
tree | bffa46b03077fab31156e341c49580b3360c418c | |
parent | 9d5f28740478b2f21419e7d43c8b5fb696ab6439 (diff) | |
download | navit-svn-bbe01c917440fcf3a7ce9c03ddddd44dc1b83f62.tar.gz |
Refactor:maptool:Introduce struct files_relation_processing to simplify file handling during relation processing.
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@5806 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r-- | navit/maptool/maptool.c | 96 | ||||
-rw-r--r-- | navit/maptool/maptool.h | 14 | ||||
-rw-r--r-- | navit/maptool/osm.c | 61 |
3 files changed, 81 insertions, 90 deletions
diff --git a/navit/maptool/maptool.c b/navit/maptool/maptool.c index b3968b6f..a79face7 100644 --- a/navit/maptool/maptool.c +++ b/navit/maptool/maptool.c @@ -116,6 +116,37 @@ sig_alrm_end(void) #endif } +static struct files_relation_processing * +files_relation_processing_new(FILE *line2poi, char *suffix) { + struct files_relation_processing *result = g_new(struct files_relation_processing, 1); + result->ways_in=tempfile(suffix,"ways_split",0); + result->ways_out=tempfile(suffix,"ways_split_relproc_tmp",1); + result->nodes_in=tempfile(suffix,"nodes",0); + result->nodes_out=tempfile(suffix,"nodes_relproc_tmp",1); + result->nodes2_in=NULL; + result->nodes2_out=NULL; + if(line2poi) { + result->nodes2_in=tempfile(suffix,"way2poi_result",0); + result->nodes2_out=tempfile(suffix,"way2poi_result_relproc_tmp",1); + } + return result; +} + +static void +files_relation_processing_destroy(struct files_relation_processing *files_relproc, char *suffix) { + fclose(files_relproc->ways_in); + fclose(files_relproc->nodes_in); + fclose(files_relproc->ways_out); + fclose(files_relproc->nodes_out); + tempfile_rename(suffix,"ways_split_relproc_tmp","ways_split"); + tempfile_rename(suffix,"nodes_relproc_tmp","nodes"); + if(files_relproc->nodes2_in) { + fclose(files_relproc->nodes2_in); + fclose(files_relproc->nodes2_out); + tempfile_rename(suffix,"way2poi_result_relproc_tmp","way2poi_result"); + } + g_free(files_relproc); +} static struct plugins *plugins; @@ -916,74 +947,25 @@ int main(int argc, char **argv) tempfile_unlink(suffix,"ways_split_index"); } if (p.process_relations && p.process_ways && p.process_nodes && start_phase(&p,"processing associated street relations")) { - FILE *ways_in=tempfile(suffix,"ways_split",0); - FILE *ways_out=tempfile(suffix,"ways_split_as",1); - FILE *nodes_in=tempfile(suffix,"nodes",0); - FILE *nodes_out=tempfile(suffix,"nodes_as",1); - FILE *nodes2_in=NULL; - FILE *nodes2_out=NULL; - if(p.osm.line2poi) { - nodes2_in=tempfile(suffix,"way2poi_result",0); - nodes2_out=tempfile(suffix,"way2poi_result_as",1); - } + struct files_relation_processing *files_relproc = files_relation_processing_new(p.osm.line2poi, suffix); p.osm.associated_streets=tempfile(suffix,"associated_streets",0); - process_associated_streets(p.osm.associated_streets, ways_in, ways_out, nodes_in, nodes_out, nodes2_in, nodes2_out); - fclose(ways_in); - fclose(nodes_in); - fclose(ways_out); - fclose(nodes_out); + process_associated_streets(p.osm.associated_streets, files_relproc); + fclose(p.osm.associated_streets); - tempfile_rename(suffix,"ways_split","ways_split_pre_as"); - tempfile_rename(suffix,"nodes","nodes_pre_as"); - tempfile_rename(suffix,"ways_split_as","ways_split"); - tempfile_rename(suffix,"nodes_as","nodes"); - if(p.osm.line2poi) { - fclose(nodes2_in); - fclose(nodes2_out); - tempfile_rename(suffix,"way2poi_result","way2poi_result_pre_as"); - tempfile_rename(suffix,"way2poi_result_as","way2poi_result"); - } - tempfile_unlink(suffix,"ways_split_pre_as"); - tempfile_unlink(suffix,"nodes_pre_as"); - tempfile_unlink(suffix,"way2poi_result_pre_as"); + files_relation_processing_destroy(files_relproc, suffix); if(!p.keep_tmpfiles) { tempfile_unlink(suffix,"associated_streets"); } } - // FIXME: c&p if (p.process_relations && p.process_ways && p.process_nodes && start_phase(&p,"processing house number interpolations")) { - FILE *ways_in=tempfile(suffix,"ways_split",0); - FILE *ways_out=tempfile(suffix,"ways_split_hn_interpol",1); - FILE *nodes_in=tempfile(suffix,"nodes",0); - FILE *nodes_out=tempfile(suffix,"nodes_hn_interpol",1); - FILE *nodes2_in=NULL; - FILE *nodes2_out=NULL; - if(p.osm.line2poi) { - nodes2_in=tempfile(suffix,"way2poi_result",0); - nodes2_out=tempfile(suffix,"way2poi_result_hn_interpol",1); - } + struct files_relation_processing *files_relproc = files_relation_processing_new(p.osm.line2poi, suffix); p.osm.house_number_interpolations=tempfile(suffix,"house_number_interpolations",0); - process_house_number_interpolations(p.osm.house_number_interpolations, ways_in, ways_out, nodes_in, nodes_out, nodes2_in, nodes2_out); - fclose(ways_in); - fclose(nodes_in); - fclose(ways_out); - fclose(nodes_out); + process_house_number_interpolations(p.osm.house_number_interpolations, files_relproc); + fclose(p.osm.house_number_interpolations); - tempfile_rename(suffix,"ways_split","ways_split_pre_hn_interpol"); - tempfile_rename(suffix,"nodes","nodes_pre_hn_interpol"); - tempfile_rename(suffix,"ways_split_hn_interpol","ways_split"); - tempfile_rename(suffix,"nodes_hn_interpol","nodes"); - if(p.osm.line2poi) { - fclose(nodes2_in); - fclose(nodes2_out); - tempfile_rename(suffix,"way2poi_result","way2poi_result_pre_hn_interpol"); - tempfile_rename(suffix,"way2poi_result_hn_interpol","way2poi_result"); - } - tempfile_unlink(suffix,"ways_split_pre_hn_interpol"); - tempfile_unlink(suffix,"nodes_pre_hn_interpol"); - tempfile_unlink(suffix,"way2poi_result_pre_hn_interpol"); + files_relation_processing_destroy(files_relproc, suffix); if(!p.keep_tmpfiles) { tempfile_unlink(suffix,"house_number_interpolations"); } diff --git a/navit/maptool/maptool.h b/navit/maptool/maptool.h index 21efb893..9bcbe745 100644 --- a/navit/maptool/maptool.h +++ b/navit/maptool/maptool.h @@ -124,6 +124,16 @@ struct country_table; typedef unsigned long long int osmid; #define OSMID_FMT LONGLONG_FMT +/** Files needed for processing a relation. */ +struct files_relation_processing { + FILE *ways_in; + FILE *ways_out; + FILE *nodes_in; + FILE *nodes_out; + FILE *nodes2_in; + FILE *nodes2_out; +}; + /* boundaries.c */ struct boundary { @@ -280,8 +290,8 @@ void osm_add_nd(osmid ref); osmid item_bin_get_id(struct item_bin *ib); void flush_nodes(int final); void sort_countries(int keep_tmpfiles); -void process_associated_streets(FILE *in, FILE *ways_in, FILE *ways_out, FILE *nodes_in, FILE *nodes_out, FILE *nodes2_in, FILE *nodes2_out); -void process_house_number_interpolations(FILE *in, FILE *ways_in, FILE *ways_out, FILE *nodes_in, FILE *nodes_out, FILE *nodes2_in, FILE *nodes2_out); +void process_associated_streets(FILE *in, struct files_relation_processing *files_relproc); +void process_house_number_interpolations(FILE *in, struct files_relation_processing *files_relproc); void process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out); void process_turn_restrictions_old(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out); void clear_node_item_buffer(void); diff --git a/navit/maptool/osm.c b/navit/maptool/osm.c index 1a49a278..16d0d63c 100644 --- a/navit/maptool/osm.c +++ b/navit/maptool/osm.c @@ -2427,7 +2427,7 @@ process_associated_streets_setup(FILE *in, struct relations *relations, struct p } void -process_associated_streets(FILE *in, FILE *ways_in, FILE *ways_out, FILE *nodes_in, FILE *nodes_out, FILE *nodes2_in, FILE *nodes2_out) +process_associated_streets(FILE *in, struct files_relation_processing *files_relproc) { struct relations *relations=relations_new(); struct process_relation_member_func_priv fp={NULL,NULL}; @@ -2435,22 +2435,22 @@ process_associated_streets(FILE *in, FILE *ways_in, FILE *ways_out, FILE *nodes_ process_associated_streets_setup(in, relations, &fp); /* Set noname relations names from their street members */ - fseek(ways_in, 0, SEEK_SET); - relations_process(relations, NULL, ways_in); + fseek(files_relproc->ways_in, 0, SEEK_SET); + relations_process(relations, NULL, files_relproc->ways_in); /* Set street names on all members */ - fp.out=ways_out; - fseek(ways_in, 0, SEEK_SET); - relations_process(relations, NULL, ways_in); + fp.out=files_relproc->ways_out; + fseek(files_relproc->ways_in, 0, SEEK_SET); + relations_process(relations, NULL, files_relproc->ways_in); - fp.out=nodes_out; - fseek(nodes_in, 0, SEEK_SET); - relations_process(relations, NULL, nodes_in); + fp.out=files_relproc->nodes_out; + fseek(files_relproc->nodes_in, 0, SEEK_SET); + relations_process(relations, NULL, files_relproc->nodes_in); - if(nodes2_in) { - fp.out=nodes2_out; - fseek(nodes2_in, 0, SEEK_SET); - relations_process(relations, NULL, nodes2_in); + if(files_relproc->nodes2_in) { + fp.out=files_relproc->nodes2_out; + fseek(files_relproc->nodes2_in, 0, SEEK_SET); + relations_process(relations, NULL, files_relproc->nodes2_in); } relations_destroy(relations); @@ -2480,33 +2480,32 @@ process_house_number_interpolations_setup(FILE *in, struct relations *relations, } void -process_house_number_interpolations(FILE *in, FILE *ways_in, FILE *ways_out, FILE *nodes_in, FILE *nodes_out, FILE *nodes2_in, FILE *nodes2_out) -{ +process_house_number_interpolations(FILE *in, struct files_relation_processing *files_relproc) { struct relations *relations=relations_new(); struct process_relation_member_func_priv fp={NULL,NULL}; fseek(in, 0, SEEK_SET); process_house_number_interpolations_setup(in, relations, &fp); /* Copy house numbers & street names from first/last node to interpolation way. */ - fseek(ways_in, 0, SEEK_SET); - relations_process(relations, NULL, ways_in); + fseek(files_relproc->ways_in, 0, SEEK_SET); + relations_process(relations, NULL, files_relproc->ways_in); - fseek(nodes_in, 0, SEEK_SET); - relations_process(relations, NULL, nodes_in); + fseek(files_relproc->nodes_in, 0, SEEK_SET); + relations_process(relations, NULL, files_relproc->nodes_in); /* Set street names on all members */ - fp.out=ways_out; - fseek(ways_in, 0, SEEK_SET); - relations_process(relations, NULL, ways_in); - - fp.out=nodes_out; - fseek(nodes_in, 0, SEEK_SET); - relations_process(relations, NULL, nodes_in); - - if(nodes2_in) { - fp.out=nodes2_out; - fseek(nodes2_in, 0, SEEK_SET); - relations_process(relations, NULL, nodes2_in); + fp.out=files_relproc->ways_out; + fseek(files_relproc->ways_in, 0, SEEK_SET); + relations_process(relations, NULL, files_relproc->ways_in); + + fp.out=files_relproc->nodes_out; + fseek(files_relproc->nodes_in, 0, SEEK_SET); + relations_process(relations, NULL, files_relproc->nodes_in); + + if(files_relproc->nodes2_in) { + fp.out=files_relproc->nodes2_out; + fseek(files_relproc->nodes2_in, 0, SEEK_SET); + relations_process(relations, NULL, files_relproc->nodes2_in); } relations_destroy(relations); |