diff --git a/include/mapnik/datasource.hpp b/include/mapnik/datasource.hpp index 5cfd1bde5..a51ab3541 100644 --- a/include/mapnik/datasource.hpp +++ b/include/mapnik/datasource.hpp @@ -81,47 +81,25 @@ public: Collection = 4 }; - datasource (parameters const& params) - : params_(params), - is_bound_(false) - {} - - /*! - * @brief Get the configuration parameters of the data source. - * - * These vary depending on the type of data source. - * - * @return The configuration parameters of the data source. - */ - parameters const& params() const - { - return params_; - } - + datasource (parameters const& params) {} + /*! * @brief Get the type of the datasource * @return The type of the datasource (Vector or Raster) */ virtual datasource_t type() const=0; - - /*! - * @brief Connect to the datasource - */ - virtual void bind() const {}; - - virtual featureset_ptr features(const query& q) const=0; + virtual featureset_ptr features(query const& q) const=0; virtual featureset_ptr features_at_point(coord2d const& pt) const=0; virtual box2d envelope() const=0; virtual boost::optional get_geometry_type() const=0; virtual layer_descriptor get_descriptor() const=0; virtual ~datasource() {}; -protected: - parameters params_; - mutable bool is_bound_; }; +typedef boost::shared_ptr datasource_ptr; + typedef std::string datasource_name(); -typedef datasource* create_ds(const parameters& params, bool bind); +typedef datasource* create_ds(parameters const& params); typedef void destroy_ds(datasource *ds); @@ -134,17 +112,14 @@ public: } }; -typedef boost::shared_ptr datasource_ptr; - - #define DATASOURCE_PLUGIN(classname) \ extern "C" MAPNIK_EXP std::string datasource_name() \ { \ return classname::name(); \ } \ - extern "C" MAPNIK_EXP datasource* create(const parameters ¶ms, bool bind) \ + extern "C" MAPNIK_EXP datasource* create(parameters const& params) \ { \ - return new classname(params, bind); \ + return new classname(params); \ } \ extern "C" MAPNIK_EXP void destroy(datasource *ds) \ { \ diff --git a/include/mapnik/datasource_cache.hpp b/include/mapnik/datasource_cache.hpp index 845abd764..1b87dca3c 100644 --- a/include/mapnik/datasource_cache.hpp +++ b/include/mapnik/datasource_cache.hpp @@ -37,6 +37,9 @@ #include namespace mapnik { + +class datasource; + class MAPNIK_DECL datasource_cache : public singleton , private boost::noncopyable @@ -55,7 +58,8 @@ public: static std::vector plugin_names(); static std::string plugin_directories(); static void register_datasources(const std::string& path); - static boost::shared_ptr create(parameters const& params, bool bind=true); + + static boost::shared_ptr create(parameters const& params); }; } diff --git a/include/mapnik/layer.hpp b/include/mapnik/layer.hpp index f9f5826e7..093666716 100644 --- a/include/mapnik/layer.hpp +++ b/include/mapnik/layer.hpp @@ -176,13 +176,15 @@ public: * * @param ds The datasource to attach. */ - void set_datasource(datasource_ptr const& ds); - + void set_datasource_parameters(parameters const& p); + + parameters const& datasource_parameters() const; + /*! * @return the datasource attached to this layer. */ datasource_ptr datasource() const; - + /*! * @return the geographic envelope/bounding box of the data in the layer. */ @@ -203,7 +205,8 @@ private: bool cache_features_; std::string group_by_; std::vector styles_; - datasource_ptr ds_; + parameters datasource_params_; + mutable datasource_ptr ds_; }; } diff --git a/src/datasource_cache.cpp b/src/datasource_cache.cpp index 72af26a7c..d5bd625e0 100644 --- a/src/datasource_cache.cpp +++ b/src/datasource_cache.cpp @@ -62,7 +62,7 @@ std::map > datasource_cache::plugins_; bool datasource_cache::registered_=false; std::vector datasource_cache::plugin_directories_; -datasource_ptr datasource_cache::create(const parameters& params, bool bind) +datasource_ptr datasource_cache::create(const parameters& params) { boost::optional type = params.get("type"); if ( ! type) @@ -106,7 +106,7 @@ datasource_ptr datasource_cache::create(const parameters& params, bool bind) std::clog << i->first << "=" << i->second << "\n"; } #endif - ds=datasource_ptr(create_datasource(params, bind), datasource_deleter()); + ds=datasource_ptr(create_datasource(params), datasource_deleter()); #ifdef MAPNIK_DEBUG std::clog<<"datasource="<create(datasource_params_); + } + catch (const std::exception & ex ) + { + throw config_error( ex.what() ); + } + + catch (...) + { + throw config_error("Unknown exception occured attempting to create datasoure for layer '" + name_ + "'"); + } + return ds_; } -void layer::set_datasource(datasource_ptr const& ds) +void layer::set_datasource_parameters(parameters const& p) { - ds_ = ds; + datasource_params_ = p; +} + +parameters const& layer::datasource_parameters() const +{ + return datasource_params_; } box2d layer::envelope() const { - if (ds_) return ds_->envelope(); + datasource_ptr ds = this->datasource(); + if (ds) return ds->envelope(); return box2d(); }