From 4aba853d7a3ea9216d2bd985470550e370c728ce Mon Sep 17 00:00:00 2001 From: Nick Whitelegg Date: Mon, 16 Feb 2009 23:10:58 +0000 Subject: [PATCH] OSM plugin: dataset_deliverer now re-fetches data if the URL has changed --- plugins/input/osm/dataset_deliverer.cpp | 14 +++++++++++++- plugins/input/osm/dataset_deliverer.h | 17 +++++++++-------- plugins/input/osm/osm.cpp | 18 ++++++++++++++++++ plugins/input/osm/osm.h | 1 + plugins/input/osm/osm_datasource.cpp | 1 + 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/plugins/input/osm/dataset_deliverer.cpp b/plugins/input/osm/dataset_deliverer.cpp index c129b10d8..12a3ffa3c 100644 --- a/plugins/input/osm/dataset_deliverer.cpp +++ b/plugins/input/osm/dataset_deliverer.cpp @@ -3,6 +3,7 @@ #include osm_dataset * dataset_deliverer::dataset=NULL; +std::string dataset_deliverer::last_bbox = ""; osm_dataset* dataset_deliverer::load_from_file(const string& file, const string& parser) @@ -22,12 +23,23 @@ osm_dataset* dataset_deliverer::load_from_file(const string& file, osm_dataset* dataset_deliverer::load_from_url (const string& url,const string& bbox,const string& parser) { + if(dataset==NULL) { dataset = new osm_dataset; if(dataset->load_from_url(url.c_str(),bbox,parser)==false) return NULL; atexit(dataset_deliverer::release); + last_bbox = bbox; } - return dataset; + else if (bbox != last_bbox) + { + cerr<<"BBOXES ARE DIFFERENT: " << last_bbox<<","<clear(); + if(dataset->load_from_url(url.c_str(),bbox,parser)==false) + return NULL; + last_bbox = bbox; + } + return dataset; } diff --git a/plugins/input/osm/dataset_deliverer.h b/plugins/input/osm/dataset_deliverer.h index c7aba817f..afb001121 100644 --- a/plugins/input/osm/dataset_deliverer.h +++ b/plugins/input/osm/dataset_deliverer.h @@ -7,16 +7,17 @@ using namespace std; class dataset_deliverer { private: - static osm_dataset* dataset; + static osm_dataset* dataset; + static std::string last_bbox; public: - static osm_dataset *load_from_file(const string&,const string&); - static osm_dataset *load_from_url - (const string&,const string&,const string&); + static osm_dataset *load_from_file(const string&,const string&); + static osm_dataset *load_from_url + (const string&,const string&,const string&); - static void release() - { - delete dataset; - } + static void release() + { + delete dataset; + } }; diff --git a/plugins/input/osm/osm.cpp b/plugins/input/osm/osm.cpp index 6db56c54d..d65b85ae7 100644 --- a/plugins/input/osm/osm.cpp +++ b/plugins/input/osm/osm.cpp @@ -53,10 +53,28 @@ bool osm_dataset::load_from_url(const std::string& url, osm_dataset::~osm_dataset() { + clear(); +} + +void osm_dataset::clear() +{ + cerr<<"osm_dataset::clear()"<