diff --git a/bindings/python/mapnik_datasource.cpp b/bindings/python/mapnik_datasource.cpp index 445c1b11f..651f030eb 100644 --- a/bindings/python/mapnik_datasource.cpp +++ b/bindings/python/mapnik_datasource.cpp @@ -50,24 +50,15 @@ namespace using namespace boost::python; boost::shared_ptr create_datasource(const dict& d) { - bool bind=true; mapnik::parameters params; boost::python::list keys=d.keys(); for (int i=0; i(keys[i]); object obj = d[key]; - - if (key == "bind") - { - bind = extract(obj)(); - continue; - } - extract ex0(obj); extract ex1(obj); extract ex2(obj); - if (ex0.check()) { params[key] = ex0(); @@ -82,7 +73,7 @@ boost::shared_ptr create_datasource(const dict& d) } } - return mapnik::datasource_cache::instance().create(params, bind); + return mapnik::datasource_cache::instance().create(params); } boost::python::dict describe(boost::shared_ptr const& ds) @@ -170,7 +161,6 @@ void export_datasource() .def("describe",&describe) .def("envelope",&datasource::envelope) .def("features",&datasource::features) - .def("bind",&datasource::bind) .def("fields",&fields) .def("field_types",&field_types) .def("features_at_point",&datasource::features_at_point, (arg("coord"),arg("tolerance")=0)) diff --git a/bindings/python/mapnik_datasource_cache.cpp b/bindings/python/mapnik_datasource_cache.cpp index db30d72c2..ad9c6c376 100644 --- a/bindings/python/mapnik_datasource_cache.cpp +++ b/bindings/python/mapnik_datasource_cache.cpp @@ -31,20 +31,12 @@ using namespace boost::python; boost::shared_ptr create_datasource(const dict& d) { - bool bind=true; mapnik::parameters params; boost::python::list keys=d.keys(); for (int i=0; i(keys[i]); object obj = d[key]; - - if (key == "bind") - { - bind = extract(obj)(); - continue; - } - extract ex0(obj); extract ex1(obj); extract ex2(obj); @@ -63,7 +55,7 @@ boost::shared_ptr create_datasource(const dict& d) } } - return mapnik::datasource_cache::instance().create(params, bind); + return mapnik::datasource_cache::instance().create(params); } void register_datasources(std::string const& path) diff --git a/include/mapnik/datasource.hpp b/include/mapnik/datasource.hpp index 014cc99e6..2693b0a2c 100644 --- a/include/mapnik/datasource.hpp +++ b/include/mapnik/datasource.hpp @@ -86,10 +86,7 @@ public: }; datasource (parameters const& params) - : params_(params), - is_bound_(false) - { - } + : params__(params) {} /*! * @brief Get the configuration parameters of the data source. @@ -100,7 +97,7 @@ public: */ parameters const& params() const { - return params_; + return params__; } /*! @@ -108,12 +105,6 @@ public: * @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(query const& q) const = 0; virtual featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const = 0; virtual box2d envelope() const = 0; @@ -121,12 +112,11 @@ public: virtual layer_descriptor get_descriptor() const = 0; virtual ~datasource() {} protected: - parameters params_; - mutable bool is_bound_; + parameters params__; }; typedef const char * datasource_name(); -typedef datasource* create_ds(parameters const& params, bool bind); +typedef datasource* create_ds(parameters const& params); typedef void destroy_ds(datasource *ds); class datasource_deleter @@ -145,9 +135,9 @@ typedef boost::shared_ptr datasource_ptr; { \ return classname::name(); \ } \ - extern "C" MAPNIK_EXP datasource* create(parameters const& params, 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 51cdfd415..ee8e3ad6d 100644 --- a/include/mapnik/datasource_cache.hpp +++ b/include/mapnik/datasource_cache.hpp @@ -48,7 +48,7 @@ public: std::string plugin_directories(); void register_datasources(std::string const& path); bool register_datasource(std::string const& path); - boost::shared_ptr create(parameters const& params, bool bind=true); + boost::shared_ptr create(parameters const& params); private: datasource_cache(); ~datasource_cache(); diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index 042c19448..4ce9b3f23 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -56,23 +56,23 @@ using namespace boost::spirit; DATASOURCE_PLUGIN(csv_datasource) -csv_datasource::csv_datasource(parameters const& params, bool bind) +csv_datasource::csv_datasource(parameters const& params) : datasource(params), - desc_(*params_.get("type"), *params_.get("encoding", "utf-8")), + desc_(*params.get("type"), *params.get("encoding", "utf-8")), extent_(), filename_(), inline_string_(), file_length_(0), - row_limit_(*params_.get("row_limit", 0)), + row_limit_(*params.get("row_limit", 0)), features_(), - escape_(*params_.get("escape", "")), - separator_(*params_.get("separator", "")), - quote_(*params_.get("quote", "")), + escape_(*params.get("escape", "")), + separator_(*params.get("separator", "")), + quote_(*params.get("quote", "")), headers_(), - manual_headers_(mapnik::util::trim_copy(*params_.get("headers", ""))), - strict_(*params_.get("strict", false)), - quiet_(*params_.get("quiet", false)), - filesize_max_(*params_.get("filesize_max", 20.0)), // MB + manual_headers_(mapnik::util::trim_copy(*params.get("headers", ""))), + strict_(*params.get("strict", false)), + quiet_(*params.get("quiet", false)), + filesize_max_(*params.get("filesize_max", 20.0)), // MB ctx_(boost::make_shared()) { /* TODO: @@ -97,36 +97,22 @@ csv_datasource::csv_datasource(parameters const& params, bool bind) http://boost-spirit.com/home/articles/qi-example/tracking-the-input-position-while-parsing/ */ - boost::optional inline_string = params_.get("inline"); + boost::optional inline_string = params.get("inline"); if (inline_string) { inline_string_ = *inline_string; } else { - boost::optional file = params_.get("file"); + boost::optional file = params.get("file"); if (!file) throw mapnik::datasource_exception("CSV Plugin: missing parameter"); - boost::optional base = params_.get("base"); + boost::optional base = params.get("base"); if (base) filename_ = *base + "/" + *file; else filename_ = *file; } - - if (bind) - { - this->bind(); - } -} - - -csv_datasource::~csv_datasource() { } - -void csv_datasource::bind() const -{ - if (is_bound_) return; - if (!inline_string_.empty()) { std::istringstream in(inline_string_); @@ -140,9 +126,11 @@ void csv_datasource::bind() const parse_csv(in,escape_, separator_, quote_); in.close(); } - is_bound_ = true; } + +csv_datasource::~csv_datasource() { } + template void csv_datasource::parse_csv(T & stream, std::string const& escape, @@ -890,14 +878,11 @@ datasource::datasource_t csv_datasource::type() const mapnik::box2d csv_datasource::envelope() const { - if (!is_bound_) bind(); - return extent_; } boost::optional csv_datasource::get_geometry_type() const { - if (! is_bound_) bind(); boost::optional result; int multi_type = 0; unsigned num_features = features_.size(); @@ -920,15 +905,11 @@ boost::optional csv_datasource::get_geometry_typ mapnik::layer_descriptor csv_datasource::get_descriptor() const { - if (!is_bound_) bind(); - return desc_; } mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const { - if (!is_bound_) bind(); - const std::set& attribute_names = q.property_names(); std::set::const_iterator pos = attribute_names.begin(); while (pos != attribute_names.end()) @@ -958,7 +939,5 @@ mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const mapnik::featureset_ptr csv_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const { - if (!is_bound_) bind(); - throw mapnik::datasource_exception("CSV Plugin: features_at_point is not supported yet"); } diff --git a/plugins/input/csv/csv_datasource.hpp b/plugins/input/csv/csv_datasource.hpp index 991a005a1..fb8b21666 100644 --- a/plugins/input/csv/csv_datasource.hpp +++ b/plugins/input/csv/csv_datasource.hpp @@ -42,7 +42,7 @@ class csv_datasource : public mapnik::datasource { public: - csv_datasource(mapnik::parameters const& params, bool bind=true); + csv_datasource(mapnik::parameters const& params); virtual ~csv_datasource (); mapnik::datasource::datasource_t type() const; static const char * name(); @@ -51,7 +51,6 @@ public: mapnik::box2d envelope() const; boost::optional get_geometry_type() const; mapnik::layer_descriptor get_descriptor() const; - void bind() const; template void parse_csv(T & stream, diff --git a/plugins/input/gdal/gdal_datasource.cpp b/plugins/input/gdal/gdal_datasource.cpp index 3a7ea2122..69d49a229 100644 --- a/plugins/input/gdal/gdal_datasource.cpp +++ b/plugins/input/gdal/gdal_datasource.cpp @@ -73,20 +73,24 @@ inline GDALDataset* gdal_datasource::open_dataset() const } -gdal_datasource::gdal_datasource(parameters const& params, bool bind) +gdal_datasource::gdal_datasource(parameters const& params) : datasource(params), desc_(*params.get("type"), "utf-8"), - filter_factor_(*params_.get("filter_factor", 0.0)), - nodata_value_(params_.get("nodata")) + filter_factor_(*params.get("filter_factor", 0.0)), + nodata_value_(params.get("nodata")) { MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Initializing..."; +#ifdef MAPNIK_STATS + mapnik::progress_timer __stats__(std::clog, "gdal_datasource::init"); +#endif + GDALAllRegister(); boost::optional file = params.get("file"); if (! file) throw datasource_exception("missing parameter"); - boost::optional base = params_.get("base"); + boost::optional base = params.get("base"); if (base) { dataset_name_ = *base + "/" + *file; @@ -96,22 +100,8 @@ gdal_datasource::gdal_datasource(parameters const& params, bool bind) dataset_name_ = *file; } - if (bind) - { - this->bind(); - } -} - -void gdal_datasource::bind() const -{ - if (is_bound_) return; - -#ifdef MAPNIK_STATS - mapnik::progress_timer __stats__(std::clog, "gdal_datasource::bind"); -#endif - - shared_dataset_ = *params_.get("shared", false); - band_ = *params_.get("band", -1); + shared_dataset_ = *params.get("shared", false); + band_ = *params.get("band", -1); GDALDataset *dataset = open_dataset(); @@ -121,7 +111,7 @@ void gdal_datasource::bind() const double tr[6]; bool bbox_override = false; - boost::optional bbox_s = params_.get("extent"); + boost::optional bbox_s = params.get("extent"); if (bbox_s) { MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: BBox Parameter=" << *bbox_s; @@ -188,7 +178,6 @@ void gdal_datasource::bind() const MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Raster Size=" << width_ << "," << height_; MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Raster Extent=" << extent_; - is_bound_ = true; } gdal_datasource::~gdal_datasource() @@ -207,8 +196,6 @@ const char * gdal_datasource::name() box2d gdal_datasource::envelope() const { - if (! is_bound_) bind(); - return extent_; } @@ -224,8 +211,6 @@ layer_descriptor gdal_datasource::get_descriptor() const featureset_ptr gdal_datasource::features(query const& q) const { - if (! is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "gdal_datasource::features"); #endif @@ -248,8 +233,6 @@ featureset_ptr gdal_datasource::features(query const& q) const featureset_ptr gdal_datasource::features_at_point(coord2d const& pt, double tol) const { - if (! is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "gdal_datasource::features_at_point"); #endif diff --git a/plugins/input/gdal/gdal_datasource.hpp b/plugins/input/gdal/gdal_datasource.hpp index 1152c5849..2032f0194 100644 --- a/plugins/input/gdal/gdal_datasource.hpp +++ b/plugins/input/gdal/gdal_datasource.hpp @@ -45,7 +45,7 @@ class gdal_datasource : public mapnik::datasource { public: - gdal_datasource(mapnik::parameters const& params, bool bind = true); + gdal_datasource(mapnik::parameters const& params); virtual ~gdal_datasource(); mapnik::datasource::datasource_t type() const; static const char * name(); @@ -54,7 +54,6 @@ public: mapnik::box2d envelope() const; boost::optional get_geometry_type() const; mapnik::layer_descriptor get_descriptor() const; - void bind() const; private: GDALDataset* open_dataset() const; mutable mapnik::box2d extent_; diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index 60f63b0b7..ea60b69d0 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -49,24 +49,6 @@ using mapnik::parameters; DATASOURCE_PLUGIN(geojson_datasource) -geojson_datasource::geojson_datasource(parameters const& params, bool bind) -: datasource(params), - type_(datasource::Vector), - desc_(*params_.get("type"), - *params_.get("encoding","utf-8")), - file_(*params_.get("file","")), - extent_(), - tr_(new mapnik::transcoder(*params_.get("encoding","utf-8"))), - features_(), - tree_(16,1) -{ - if (file_.empty()) throw mapnik::datasource_exception("GeoJSON Plugin: missing parameter"); - if (bind) - { - this->bind(); - } -} - struct attr_value_converter : public boost::static_visitor { mapnik::eAttributeType operator() (int /*val*/) const @@ -105,9 +87,18 @@ struct attr_value_converter : public boost::static_visitor("type"), + *params.get("encoding","utf-8")), + file_(*params.get("file","")), + extent_(), + tr_(new mapnik::transcoder(*params.get("encoding","utf-8"))), + features_(), + tree_(16,1) { - if (is_bound_) return; + if (file_.empty()) throw mapnik::datasource_exception("GeoJSON Plugin: missing parameter"); typedef std::istreambuf_iterator base_iterator_type; @@ -149,7 +140,6 @@ void geojson_datasource::bind() const } tree_.insert(box_type(point_type(box.minx(),box.miny()),point_type(box.maxx(),box.maxy())), count++); } - is_bound_ = true; } geojson_datasource::~geojson_datasource() { } @@ -188,21 +178,16 @@ mapnik::datasource::datasource_t geojson_datasource::type() const mapnik::box2d geojson_datasource::envelope() const { - if (!is_bound_) bind(); return extent_; } mapnik::layer_descriptor geojson_datasource::get_descriptor() const { - if (!is_bound_) bind(); - return desc_; } mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) const { - if (!is_bound_) bind(); - // if the query box intersects our world extent then query for features mapnik::box2d const& b = q.get_bbox(); if (extent_.intersects(b)) @@ -218,7 +203,6 @@ mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) cons // FIXME mapnik::featureset_ptr geojson_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const { - if (!is_bound_) bind(); throw mapnik::datasource_exception("GeoJSON Plugin: features_at_point is not supported yet"); return mapnik::featureset_ptr(); } diff --git a/plugins/input/geojson/geojson_datasource.hpp b/plugins/input/geojson/geojson_datasource.hpp index e3d0e491c..41537868d 100644 --- a/plugins/input/geojson/geojson_datasource.hpp +++ b/plugins/input/geojson/geojson_datasource.hpp @@ -55,7 +55,7 @@ public: typedef boost::geometry::index::rtree spatial_index_type; // constructor - geojson_datasource(mapnik::parameters const& params, bool bind=true); + geojson_datasource(mapnik::parameters const& params); virtual ~geojson_datasource (); mapnik::datasource::datasource_t type() const; static const char * name(); @@ -64,7 +64,6 @@ public: mapnik::box2d envelope() const; mapnik::layer_descriptor get_descriptor() const; boost::optional get_geometry_type() const; - void bind() const; private: mapnik::datasource::datasource_t type_; mutable std::map statistics_; diff --git a/plugins/input/geos/geos_datasource.cpp b/plugins/input/geos/geos_datasource.cpp index 9e24bf968..9e44d7e7d 100644 --- a/plugins/input/geos/geos_datasource.cpp +++ b/plugins/input/geos/geos_datasource.cpp @@ -85,7 +85,7 @@ void geos_error(const char* format, ...) } -geos_datasource::geos_datasource(parameters const& params, bool bind) +geos_datasource::geos_datasource(parameters const& params) : datasource(params), extent_(), extent_initialized_(false), @@ -99,42 +99,22 @@ geos_datasource::geos_datasource(parameters const& params, bool bind) if (! geometry) throw datasource_exception("missing parameter"); geometry_string_ = *geometry; - boost::optional ext = params_.get("extent"); + boost::optional ext = params.get("extent"); if (ext) extent_initialized_ = extent_.from_string(*ext); - boost::optional id = params_.get("gid"); + boost::optional id = params.get("gid"); if (id) geometry_id_ = *id; - boost::optional gdata = params_.get("field_data"); + boost::optional gdata = params.get("field_data"); if (gdata) geometry_data_ = *gdata; - boost::optional gdata_name = params_.get("field_name"); + boost::optional gdata_name = params.get("field_name"); if (gdata_name) geometry_data_name_ = *gdata_name; desc_.add_descriptor(attribute_descriptor(geometry_data_name_, mapnik::String)); - if (bind) - { - this->bind(); - } -} - -geos_datasource::~geos_datasource() -{ - if (is_bound_) - { - geometry_.set_feature(0); - - finishGEOS(); - } -} - -void geos_datasource::bind() const -{ - if (is_bound_) return; - #ifdef MAPNIK_STATS - mapnik::progress_timer __stats__(std::clog, "geos_datasource::bind"); + mapnik::progress_timer __stats__(std::clog, "geos_datasource::init"); #endif // open geos driver @@ -151,7 +131,7 @@ void geos_datasource::bind() const if (! extent_initialized_) { #ifdef MAPNIK_STATS - mapnik::progress_timer __stats2__(std::clog, "geos_datasource::bind(initialize_extent)"); + mapnik::progress_timer __stats2__(std::clog, "geos_datasource::init(initialize_extent)"); #endif MAPNIK_LOG_DEBUG(geos) << "geos_datasource: Initializing extent from geometry"; @@ -222,9 +202,18 @@ void geos_datasource::bind() const throw datasource_exception("GEOS Plugin: cannot determine extent for geometry"); } - is_bound_ = true; } +geos_datasource::~geos_datasource() +{ + { + geometry_.set_feature(0); + + finishGEOS(); + } +} + + const char * geos_datasource::name() { return "geos"; @@ -237,14 +226,11 @@ mapnik::datasource::datasource_t geos_datasource::type() const box2d geos_datasource::envelope() const { - if (! is_bound_) bind(); - return extent_; } boost::optional geos_datasource::get_geometry_type() const { - if (! is_bound_) bind(); boost::optional result; #ifdef MAPNIK_STATS @@ -280,15 +266,11 @@ boost::optional geos_datasource::get_geometry_ty layer_descriptor geos_datasource::get_descriptor() const { - if (! is_bound_) bind(); - return desc_; } featureset_ptr geos_datasource::features(query const& q) const { - if (! is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "geos_datasource::features"); #endif @@ -316,8 +298,6 @@ featureset_ptr geos_datasource::features(query const& q) const featureset_ptr geos_datasource::features_at_point(coord2d const& pt, double tol) const { - if (! is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "geos_datasource::features_at_point"); #endif diff --git a/plugins/input/geos/geos_datasource.hpp b/plugins/input/geos/geos_datasource.hpp index 463ed497f..35bb813ec 100644 --- a/plugins/input/geos/geos_datasource.hpp +++ b/plugins/input/geos/geos_datasource.hpp @@ -45,7 +45,7 @@ class geos_datasource : public mapnik::datasource { public: - geos_datasource(mapnik::parameters const& params, bool bind = true); + geos_datasource(mapnik::parameters const& params); virtual ~geos_datasource (); mapnik::datasource::datasource_t type() const; static const char * name(); @@ -54,17 +54,17 @@ public: mapnik::box2d envelope() const; boost::optional get_geometry_type() const; mapnik::layer_descriptor get_descriptor() const; - void bind() const; private: - mutable mapnik::box2d extent_; - mutable bool extent_initialized_; + void init(mapnik::parameters const& params); + mapnik::box2d extent_; + bool extent_initialized_; mapnik::datasource::datasource_t type_; - mutable mapnik::layer_descriptor desc_; + mapnik::layer_descriptor desc_; mutable geos_feature_ptr geometry_; - mutable std::string geometry_data_; - mutable std::string geometry_data_name_; - mutable int geometry_id_; + std::string geometry_data_; + std::string geometry_data_name_; + int geometry_id_; std::string geometry_string_; }; diff --git a/plugins/input/kismet/kismet_datasource.cpp b/plugins/input/kismet/kismet_datasource.cpp index cfd149ed7..209bd9a20 100644 --- a/plugins/input/kismet/kismet_datasource.cpp +++ b/plugins/input/kismet/kismet_datasource.cpp @@ -67,7 +67,7 @@ boost::mutex knd_list_mutex; std::list knd_list; const unsigned int queue_size = 20; -kismet_datasource::kismet_datasource(parameters const& params, bool bind) +kismet_datasource::kismet_datasource(parameters const& params) : datasource(params), extent_(), extent_initialized_(false), @@ -75,7 +75,7 @@ kismet_datasource::kismet_datasource(parameters const& params, bool bind) srs_("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"), desc_(*params.get("type"), *params.get("encoding","utf-8")) { - boost::optional host = params_.get("host"); + boost::optional host = params.get("host"); if (host) { host_ = *host; @@ -85,37 +85,25 @@ kismet_datasource::kismet_datasource(parameters const& params, bool bind) throw datasource_exception("Kismet Plugin: missing parameter"); } - boost::optional port = params_.get("port", 2501); + boost::optional port = params.get("port", 2501); if (port) { port_ = *port; } - boost::optional srs = params_.get("srs"); + boost::optional srs = params.get("srs"); if (srs) { srs_ = *srs; } - boost::optional ext = params_.get("extent"); + boost::optional ext = params.get("extent"); if (ext) { extent_initialized_ = extent_.from_string(*ext); } kismet_thread.reset(new boost::thread(boost::bind(&kismet_datasource::run, this, host_, port_))); - - if (bind) - { - this->bind(); - } -} - -void kismet_datasource::bind() const -{ - if (is_bound_) return; - - is_bound_ = true; } kismet_datasource::~kismet_datasource() @@ -134,7 +122,6 @@ mapnik::datasource::datasource_t kismet_datasource::type() const box2d kismet_datasource::envelope() const { - if (! is_bound_) bind(); return extent_; } @@ -150,8 +137,6 @@ layer_descriptor kismet_datasource::get_descriptor() const featureset_ptr kismet_datasource::features(query const& q) const { - if (! is_bound_) bind(); - MAPNIK_LOG_DEBUG(kismet) << "kismet_datasource::features()"; // TODO: use box2d to filter bbox before adding to featureset_ptr @@ -168,8 +153,6 @@ featureset_ptr kismet_datasource::features(query const& q) const featureset_ptr kismet_datasource::features_at_point(coord2d const& pt, double tol) const { - if (! is_bound_) bind(); - MAPNIK_LOG_DEBUG(kismet) << "kismet_datasource::features_at_point()"; return featureset_ptr(); diff --git a/plugins/input/kismet/kismet_datasource.hpp b/plugins/input/kismet/kismet_datasource.hpp index 28d3c335b..c1d727830 100644 --- a/plugins/input/kismet/kismet_datasource.hpp +++ b/plugins/input/kismet/kismet_datasource.hpp @@ -47,7 +47,7 @@ class kismet_datasource : public mapnik::datasource { public: - kismet_datasource(mapnik::parameters const& params, bool bind = true); + kismet_datasource(mapnik::parameters const& params); virtual ~kismet_datasource (); datasource::datasource_t type() const; static const char * name(); @@ -56,7 +56,6 @@ public: mapnik::box2d envelope() const; boost::optional get_geometry_type() const; mapnik::layer_descriptor get_descriptor() const; - void bind() const; private: void run (std::string const& host, const unsigned int port); diff --git a/plugins/input/occi/occi_datasource.cpp b/plugins/input/occi/occi_datasource.cpp index 8f23675ae..93d01c725 100644 --- a/plugins/input/occi/occi_datasource.cpp +++ b/plugins/input/occi/occi_datasource.cpp @@ -68,25 +68,29 @@ const std::string occi_datasource::METADATA_TABLE = "USER_SDO_GEOM_METADATA"; DATASOURCE_PLUGIN(occi_datasource) -occi_datasource::occi_datasource(parameters const& params, bool bind) +occi_datasource::occi_datasource(parameters const& params) : datasource (params), type_(datasource::Vector), - fields_(*params_.get("fields", "*")), - geometry_field_(*params_.get("geometry_field", "")), + fields_(*params.get("fields", "*")), + geometry_field_(*params.get("geometry_field", "")), srid_initialized_(false), extent_initialized_(false), - desc_(*params_.get("type"), *params_.get("encoding", "utf-8")), - use_wkb_(*params_.get("use_wkb", false)), - row_limit_(*params_.get("row_limit", 0)), - row_prefetch_(*params_.get("row_prefetch", 100)), + desc_(*params.get("type"), *params.get("encoding", "utf-8")), + use_wkb_(*params.get("use_wkb", false)), + row_limit_(*params.get("row_limit", 0)), + row_prefetch_(*params.get("row_prefetch", 100)), pool_(0), conn_(0) { - if (! params_.get("user")) throw datasource_exception("OCCI Plugin: no specified"); - if (! params_.get("password")) throw datasource_exception("OCCI Plugin: no specified"); - if (! params_.get("host")) throw datasource_exception("OCCI Plugin: no string specified"); +#ifdef MAPNIK_STATS + mapnik::progress_timer __stats__(std::clog, "occi_datasource::init"); +#endif - boost::optional table = params_.get("table"); + if (! params.get("user")) throw datasource_exception("OCCI Plugin: no specified"); + if (! params.get("password")) throw datasource_exception("OCCI Plugin: no specified"); + if (! params.get("host")) throw datasource_exception("OCCI Plugin: no string specified"); + + boost::optional table = params.get("table"); if (! table) { throw datasource_exception("OCCI Plugin: no parameter specified"); @@ -95,57 +99,20 @@ occi_datasource::occi_datasource(parameters const& params, bool bind) { table_ = *table; } + estimate_extent_ = *params.get("estimate_extent",false); + use_spatial_index_ = *params.get("use_spatial_index",true); + use_connection_pool_ = *params.get("use_connection_pool",true); - use_spatial_index_ = *params_.get("use_spatial_index",true); - use_connection_pool_ = *params_.get("use_connection_pool",true); - - boost::optional ext = params_.get("extent"); + boost::optional ext = params.get("extent"); if (ext) extent_initialized_ = extent_.from_string(*ext); - boost::optional srid = params_.get("srid"); + boost::optional srid = params.get("srid"); if (srid) { srid_ = *srid; srid_initialized_ = true; } - if (bind) - { - this->bind(); - } -} - -occi_datasource::~occi_datasource() -{ - if (is_bound_) - { - Environment* env = occi_environment::get_environment(); - - if (use_connection_pool_) - { - if (pool_ != 0) - { - env->terminateStatelessConnectionPool(pool_, StatelessConnectionPool::SPD_FORCE); - } - } - else - { - if (conn_ != 0) - { - env->terminateConnection(conn_); - } - } - } -} - -void occi_datasource::bind() const -{ - if (is_bound_) return; - -#ifdef MAPNIK_STATS - mapnik::progress_timer __stats__(std::clog, "occi_datasource::bind"); -#endif - // connect to environment if (use_connection_pool_) { @@ -154,11 +121,11 @@ void occi_datasource::bind() const Environment* env = occi_environment::get_environment(); pool_ = env->createStatelessConnectionPool( - *params_.get("user"), - *params_.get("password"), - *params_.get("host"), - *params_.get("max_size", 5), - *params_.get("initial_size", 1), + *params.get("user"), + *params.get("password"), + *params.get("host"), + *params.get("max_size", 5), + *params.get("initial_size", 1), 1, StatelessConnectionPool::HOMOGENEOUS); } @@ -174,9 +141,9 @@ void occi_datasource::bind() const Environment* env = occi_environment::get_environment(); conn_ = env->createConnection( - *params_.get("user"), - *params_.get("password"), - *params_.get("host")); + *params.get("user"), + *params.get("password"), + *params.get("host")); } catch (SQLException& ex) { @@ -348,8 +315,28 @@ void occi_datasource::bind() const throw datasource_exception(ex.getMessage()); } } +} - is_bound_ = true; +occi_datasource::~occi_datasource() +{ + { + Environment* env = occi_environment::get_environment(); + + if (use_connection_pool_) + { + if (pool_ != 0) + { + env->terminateStatelessConnectionPool(pool_, StatelessConnectionPool::SPD_FORCE); + } + } + else + { + if (conn_ != 0) + { + env->terminateConnection(conn_); + } + } + } } const char * occi_datasource::name() @@ -365,14 +352,11 @@ mapnik::datasource::datasource_t occi_datasource::type() const box2d occi_datasource::envelope() const { if (extent_initialized_) return extent_; - if (! is_bound_) bind(); double lox = 0.0, loy = 0.0, hix = 0.0, hiy = 0.0; - boost::optional estimate_extent = - params_.get("estimate_extent",false); - if (estimate_extent && *estimate_extent) + if (estimate_extent_) { #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "occi_datasource::envelope(estimate_extent)"); @@ -487,22 +471,16 @@ box2d occi_datasource::envelope() const boost::optional occi_datasource::get_geometry_type() const { - // FIXME - //if (! is_bound_) bind(); return boost::optional(); } layer_descriptor occi_datasource::get_descriptor() const { - if (! is_bound_) bind(); - return desc_; } featureset_ptr occi_datasource::features(query const& q) const { - if (! is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "occi_datasource::features"); #endif @@ -592,8 +570,6 @@ featureset_ptr occi_datasource::features(query const& q) const featureset_ptr occi_datasource::features_at_point(coord2d const& pt, double tol) const { - if (! is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "occi_datasource::features_at_point"); #endif diff --git a/plugins/input/occi/occi_datasource.hpp b/plugins/input/occi/occi_datasource.hpp index 4d0d2ba22..76c8288f3 100644 --- a/plugins/input/occi/occi_datasource.hpp +++ b/plugins/input/occi/occi_datasource.hpp @@ -46,7 +46,7 @@ class occi_datasource : public mapnik::datasource { public: - occi_datasource(mapnik::parameters const& params, bool bind = true); + occi_datasource(mapnik::parameters const& params); virtual ~occi_datasource (); mapnik::datasource::datasource_t type() const; static const char * name(); @@ -55,7 +55,6 @@ public: mapnik::box2d envelope() const; boost::optional get_geometry_type() const; mapnik::layer_descriptor get_descriptor() const; - void bind() const; private: static const std::string METADATA_TABLE; @@ -77,6 +76,7 @@ private: mutable oracle::occi::Connection* conn_; bool use_connection_pool_; bool use_spatial_index_; + bool estimate_extent_; }; #endif // OCCI_DATASOURCE_HPP diff --git a/plugins/input/ogr/ogr_datasource.cpp b/plugins/input/ogr/ogr_datasource.cpp index 1125f9091..ca6602b6b 100644 --- a/plugins/input/ogr/ogr_datasource.cpp +++ b/plugins/input/ogr/ogr_datasource.cpp @@ -57,13 +57,32 @@ using mapnik::filter_in_box; using mapnik::filter_at_point; -ogr_datasource::ogr_datasource(parameters const& params, bool bind) +ogr_datasource::ogr_datasource(parameters const& params) : datasource(params), extent_(), type_(datasource::Vector), - desc_(*params_.get("type"), *params_.get("encoding", "utf-8")), + desc_(*params.get("type"), *params.get("encoding", "utf-8")), indexed_(false) { + init(params); +} + +ogr_datasource::~ogr_datasource() +{ + // free layer before destroying the datasource + layer_.free_layer(); + OGRDataSource::DestroyDataSource (dataset_); +} + +void ogr_datasource::init(mapnik::parameters const& params) +{ +#ifdef MAPNIK_STATS + mapnik::progress_timer __stats__(std::clog, "ogr_datasource::init"); +#endif + + // initialize ogr formats + OGRRegisterAll(); + boost::optional file = params.get("file"); boost::optional string = params.get("string"); if (! file && ! string) @@ -88,35 +107,7 @@ ogr_datasource::ogr_datasource(parameters const& params, bool bind) } } - if (bind) - { - this->bind(); - } -} - -ogr_datasource::~ogr_datasource() -{ - if (is_bound_) - { - // free layer before destroying the datasource - layer_.free_layer(); - - OGRDataSource::DestroyDataSource (dataset_); - } -} - -void ogr_datasource::bind() const -{ - if (is_bound_) return; - -#ifdef MAPNIK_STATS - mapnik::progress_timer __stats__(std::clog, "ogr_datasource::bind"); -#endif - - // initialize ogr formats - OGRRegisterAll(); - - std::string driver = *params_.get("driver",""); + std::string driver = *params.get("driver",""); if (! driver.empty()) { @@ -147,9 +138,9 @@ void ogr_datasource::bind() const } // initialize layer - boost::optional layer_by_name = params_.get("layer"); - boost::optional layer_by_index = params_.get("layer_by_index"); - boost::optional layer_by_sql = params_.get("layer_by_sql"); + boost::optional layer_by_name = params.get("layer"); + boost::optional layer_by_index = params.get("layer_by_index"); + boost::optional layer_by_sql = params.get("layer_by_sql"); int passed_parameters = 0; passed_parameters += layer_by_name ? 1 : 0; @@ -185,7 +176,7 @@ void ogr_datasource::bind() const else if (layer_by_sql) { #ifdef MAPNIK_STATS - mapnik::progress_timer __stats_sql__(std::clog, "ogr_datasource::bind(layer_by_sql)"); + mapnik::progress_timer __stats_sql__(std::clog, "ogr_datasource::init(layer_by_sql)"); #endif layer_.layer_by_sql(dataset_, *layer_by_sql); @@ -278,7 +269,7 @@ void ogr_datasource::bind() const #endif #ifdef MAPNIK_STATS - mapnik::progress_timer __stats2__(std::clog, "ogr_datasource::bind(get_column_description)"); + mapnik::progress_timer __stats2__(std::clog, "ogr_datasource::init(get_column_description)"); #endif // deal with attributes descriptions @@ -328,8 +319,6 @@ void ogr_datasource::bind() const } } } - - is_bound_ = true; } const char * ogr_datasource::name() @@ -344,7 +333,6 @@ mapnik::datasource::datasource_t ogr_datasource::type() const box2d ogr_datasource::envelope() const { - if (! is_bound_) bind(); return extent_; } @@ -432,7 +420,6 @@ boost::optional ogr_datasource::get_geometry_typ layer_descriptor ogr_datasource::get_descriptor() const { - if (! is_bound_) bind(); return desc_; } @@ -475,8 +462,6 @@ void validate_attribute_names(query const& q, std::vector featureset_ptr ogr_datasource::features(query const& q) const { - if (! is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "ogr_datasource::features"); #endif @@ -522,8 +507,6 @@ featureset_ptr ogr_datasource::features(query const& q) const featureset_ptr ogr_datasource::features_at_point(coord2d const& pt, double tol) const { - if (!is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "ogr_datasource::features_at_point"); #endif diff --git a/plugins/input/ogr/ogr_datasource.hpp b/plugins/input/ogr/ogr_datasource.hpp index 3b383f053..ebff6c548 100644 --- a/plugins/input/ogr/ogr_datasource.hpp +++ b/plugins/input/ogr/ogr_datasource.hpp @@ -47,7 +47,7 @@ class ogr_datasource : public mapnik::datasource { public: - ogr_datasource(mapnik::parameters const& params, bool bind=true); + ogr_datasource(mapnik::parameters const& params); virtual ~ogr_datasource (); mapnik::datasource::datasource_t type() const; static const char * name(); @@ -56,18 +56,18 @@ public: mapnik::box2d envelope() const; boost::optional get_geometry_type() const; mapnik::layer_descriptor get_descriptor() const; - void bind() const; - + private: - mutable mapnik::box2d extent_; + void init(mapnik::parameters const& params); + mapnik::box2d extent_; mapnik::datasource::datasource_t type_; std::string dataset_name_; - mutable std::string index_name_; - mutable OGRDataSource* dataset_; - mutable ogr_layer_ptr layer_; - mutable std::string layer_name_; - mutable mapnik::layer_descriptor desc_; - mutable bool indexed_; + std::string index_name_; + OGRDataSource* dataset_; + ogr_layer_ptr layer_; + std::string layer_name_; + mapnik::layer_descriptor desc_; + bool indexed_; }; #endif // OGR_DATASOURCE_HPP diff --git a/plugins/input/osm/osm_datasource.cpp b/plugins/input/osm/osm_datasource.cpp index b2ba7ff5b..0a18b4975 100644 --- a/plugins/input/osm/osm_datasource.cpp +++ b/plugins/input/osm/osm_datasource.cpp @@ -49,28 +49,17 @@ using mapnik::attribute_descriptor; DATASOURCE_PLUGIN(osm_datasource) -osm_datasource::osm_datasource(const parameters& params, bool bind) +osm_datasource::osm_datasource(const parameters& params) : datasource (params), extent_(), type_(datasource::Vector), - desc_(*params_.get("type"), *params_.get("encoding", "utf-8")) + desc_(*params.get("type"), *params.get("encoding", "utf-8")) { - if (bind) - { - this->bind(); - } -} - -void osm_datasource::bind() const -{ - if (is_bound_) return; - osm_data_ = NULL; - std::string osm_filename = *params_.get("file", ""); - std::string parser = *params_.get("parser", "libxml2"); - std::string url = *params_.get("url", ""); - std::string bbox = *params_.get("bbox", ""); - + std::string osm_filename = *params.get("file", ""); + std::string parser = *params.get("parser", "libxml2"); + std::string url = *params.get("url", ""); + std::string bbox = *params.get("bbox", ""); // load the data if (url != "" && bbox != "") @@ -118,7 +107,6 @@ void osm_datasource::bind() const // Get the bounds of the data and set extent_ accordingly bounds b = osm_data_->get_bounds(); extent_ = box2d(b.w, b.s, b.e, b.n); - is_bound_ = true; } osm_datasource::~osm_datasource() @@ -144,8 +132,6 @@ layer_descriptor osm_datasource::get_descriptor() const featureset_ptr osm_datasource::features(const query& q) const { - if (!is_bound_) bind(); - filter_in_box filter(q.get_bbox()); // so we need to filter osm features by bbox here... @@ -157,8 +143,6 @@ featureset_ptr osm_datasource::features(const query& q) const featureset_ptr osm_datasource::features_at_point(coord2d const& pt, double tol) const { - if (!is_bound_) bind(); - filter_at_point filter(pt); // collect all attribute names std::vector const& desc_vector = desc_.get_descriptors(); @@ -180,12 +164,10 @@ featureset_ptr osm_datasource::features_at_point(coord2d const& pt, double tol) box2d osm_datasource::envelope() const { - if (!is_bound_) bind(); return extent_; } boost::optional osm_datasource::get_geometry_type() const { - if (! is_bound_) bind(); return boost::optional(mapnik::datasource::Collection); } diff --git a/plugins/input/osm/osm_datasource.hpp b/plugins/input/osm/osm_datasource.hpp index 2ef8b5841..4b7d60fa3 100644 --- a/plugins/input/osm/osm_datasource.hpp +++ b/plugins/input/osm/osm_datasource.hpp @@ -53,7 +53,7 @@ using mapnik::box2d; class osm_datasource : public datasource { public: - osm_datasource(const parameters& params, bool bind = true); + osm_datasource(const parameters& params); virtual ~osm_datasource(); mapnik::datasource::datasource_t type() const; static const char * name(); @@ -62,7 +62,6 @@ public: box2d envelope() const; boost::optional get_geometry_type() const; layer_descriptor get_descriptor() const; - void bind() const; private: mutable box2d extent_; diff --git a/plugins/input/postgis/postgis_datasource.cpp b/plugins/input/postgis/postgis_datasource.cpp index 30719541b..2d78ea093 100644 --- a/plugins/input/postgis/postgis_datasource.cpp +++ b/plugins/input/postgis/postgis_datasource.cpp @@ -55,20 +55,20 @@ using boost::shared_ptr; using mapnik::PoolGuard; using mapnik::attribute_descriptor; -postgis_datasource::postgis_datasource(parameters const& params, bool bind) +postgis_datasource::postgis_datasource(parameters const& params) : datasource(params), - table_(*params_.get("table", "")), + table_(*params.get("table", "")), schema_(""), - geometry_table_(*params_.get("geometry_table", "")), - geometry_field_(*params_.get("geometry_field", "")), - key_field_(*params_.get("key_field", "")), - cursor_fetch_size_(*params_.get("cursor_size", 0)), - row_limit_(*params_.get("row_limit", 0)), + geometry_table_(*params.get("geometry_table", "")), + geometry_field_(*params.get("geometry_field", "")), + key_field_(*params.get("key_field", "")), + cursor_fetch_size_(*params.get("cursor_size", 0)), + row_limit_(*params.get("row_limit", 0)), type_(datasource::Vector), - srid_(*params_.get("srid", 0)), + srid_(*params.get("srid", 0)), extent_initialized_(false), simplify_geometries_(false), - desc_(*params_.get("type"), "utf-8"), + desc_(*params.get("type"), "utf-8"), creator_(params.get("host"), params.get("port"), params.get("dbname"), @@ -79,45 +79,32 @@ postgis_datasource::postgis_datasource(parameters const& params, bool bind) scale_denom_token_("!scale_denominator!"), pixel_width_token_("!pixel_width!"), pixel_height_token_("!pixel_height!"), - persist_connection_(*params_.get("persist_connection", true)), - extent_from_subquery_(*params_.get("extent_from_subquery", false)), + persist_connection_(*params.get("persist_connection", true)), + extent_from_subquery_(*params.get("extent_from_subquery", false)), // params below are for testing purposes only (will likely be removed at any time) - intersect_min_scale_(*params_.get("intersect_min_scale", 0)), - intersect_max_scale_(*params_.get("intersect_max_scale", 0)) + intersect_min_scale_(*params.get("intersect_min_scale", 0)), + intersect_max_scale_(*params.get("intersect_max_scale", 0)) { +#ifdef MAPNIK_STATS + mapnik::progress_timer __stats__(std::clog, "postgis_datasource::init"); +#endif if (table_.empty()) { throw mapnik::datasource_exception("Postgis Plugin: missing
parameter"); } - boost::optional ext = params_.get("extent"); + boost::optional ext = params.get("extent"); if (ext && !ext->empty()) { extent_initialized_ = extent_.from_string(*ext); } - if (bind) - { - this->bind(); - } -} - -void postgis_datasource::bind() const -{ - if (is_bound_) - { - return; - } - -#ifdef MAPNIK_STATS - mapnik::progress_timer __stats__(std::clog, "postgis_datasource::bind"); -#endif - - boost::optional initial_size = params_.get("initial_size", 1); - boost::optional max_size = params_.get("max_size", 10); - boost::optional autodetect_key_field = params_.get("autodetect_key_field", false); - - boost::optional simplify_opt = params_.get("simplify_geometries", false); + boost::optional initial_size = params.get("initial_size", 1); + boost::optional max_size = params.get("max_size", 10); + boost::optional autodetect_key_field = params.get("autodetect_key_field", false); + boost::optional estimate_extent = params.get("estimate_extent", false); + estimate_extent_ = estimate_extent && *estimate_extent; + boost::optional simplify_opt = params.get("simplify_geometries", false); simplify_geometries_ = simplify_opt && *simplify_opt; ConnectionManager::instance().registerPool(creator_, *initial_size, *max_size); @@ -424,14 +411,13 @@ void postgis_datasource::bind() const rs->close(); - is_bound_ = true; - } + } } } postgis_datasource::~postgis_datasource() { - if (is_bound_ && ! persist_connection_) + if (! persist_connection_) { shared_ptr< Pool > pool = ConnectionManager::instance().getPool(creator_.id()); if (pool) @@ -457,11 +443,6 @@ mapnik::datasource::datasource_t postgis_datasource::type() const layer_descriptor postgis_datasource::get_descriptor() const { - if (! is_bound_) - { - bind(); - } - return desc_; } @@ -603,11 +584,6 @@ boost::shared_ptr postgis_datasource::get_resultset(boost::shared_pt featureset_ptr postgis_datasource::features(const query& q) const { - if (! is_bound_) - { - bind(); - } - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "postgis_datasource::features"); #endif @@ -725,11 +701,6 @@ featureset_ptr postgis_datasource::features(const query& q) const featureset_ptr postgis_datasource::features_at_point(coord2d const& pt, double tol) const { - if (! is_bound_) - { - bind(); - } - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "postgis_datasource::features_at_point"); #endif @@ -817,11 +788,6 @@ box2d postgis_datasource::envelope() const return extent_; } - if (! is_bound_) - { - bind(); - } - shared_ptr< Pool > pool = ConnectionManager::instance().getPool(creator_.id()); if (pool) { @@ -832,9 +798,6 @@ box2d postgis_datasource::envelope() const std::ostringstream s; - boost::optional estimate_extent = - params_.get("estimate_extent", false); - if (geometryColumn_.empty()) { std::ostringstream s_error; @@ -852,7 +815,7 @@ box2d postgis_datasource::envelope() const throw mapnik::datasource_exception("Postgis Plugin: " + s_error.str()); } - if (estimate_extent && *estimate_extent) + if (estimate_extent_) { s << "SELECT ST_XMin(ext),ST_YMin(ext),ST_XMax(ext),ST_YMax(ext)" << " FROM (SELECT ST_Estimated_Extent('"; @@ -915,11 +878,6 @@ box2d postgis_datasource::envelope() const boost::optional postgis_datasource::get_geometry_type() const { - if (! is_bound_) - { - bind(); - } - boost::optional result; shared_ptr< Pool > pool = ConnectionManager::instance().getPool(creator_.id()); diff --git a/plugins/input/postgis/postgis_datasource.hpp b/plugins/input/postgis/postgis_datasource.hpp index 9885ca3c2..32e6069ad 100644 --- a/plugins/input/postgis/postgis_datasource.hpp +++ b/plugins/input/postgis/postgis_datasource.hpp @@ -58,7 +58,7 @@ using mapnik::coord2d; class postgis_datasource : public datasource { public: - postgis_datasource(const parameters ¶ms, bool bind=true); + postgis_datasource(const parameters ¶ms); ~postgis_datasource(); mapnik::datasource::datasource_t type() const; static const char * name(); @@ -67,7 +67,6 @@ public: mapnik::box2d envelope() const; boost::optional get_geometry_type() const; layer_descriptor get_descriptor() const; - void bind() const; private: std::string sql_bbox(box2d const& env) const; @@ -104,6 +103,7 @@ private: const std::string pixel_height_token_; bool persist_connection_; bool extent_from_subquery_; + bool estimate_extent_; // params below are for testing purposes only (will likely be removed at any time) int intersect_min_scale_; int intersect_max_scale_; diff --git a/plugins/input/postgis/postgis_featureset.cpp b/plugins/input/postgis/postgis_featureset.cpp index 25d516bc8..2da06d113 100644 --- a/plugins/input/postgis/postgis_featureset.cpp +++ b/plugins/input/postgis/postgis_featureset.cpp @@ -75,7 +75,7 @@ feature_ptr postgis_featureset::next() const char* buf = rs_->getValue(pos); std::string name = rs_->getFieldName(pos); - // validation happens of this type at bind() + // validation happens of this type at initialization int val; if (oid == 20) { diff --git a/plugins/input/python/python_datasource.cpp b/plugins/input/python/python_datasource.cpp index bceeb20bb..3c8795503 100644 --- a/plugins/input/python/python_datasource.cpp +++ b/plugins/input/python/python_datasource.cpp @@ -20,53 +20,27 @@ using mapnik::parameters; DATASOURCE_PLUGIN(python_datasource) -python_datasource::python_datasource(parameters const& params, bool bind) +python_datasource::python_datasource(parameters const& params) : datasource(params), - desc_(*params_.get("type"), *params_.get("encoding","utf-8")), - factory_(*params_.get("factory", "")) + desc_(*params.get("type"), *params.get("encoding","utf-8")), + factory_(*params.get("factory", "")) { // extract any remaining parameters as keyword args for the factory - BOOST_FOREACH(const mapnik::parameters::value_type& kv, params_) + BOOST_FOREACH(const mapnik::parameters::value_type& kv, params) { if((kv.first != "type") && (kv.first != "factory")) { - kwargs_.insert(std::make_pair(kv.first, *params_.get(kv.first))); + kwargs_.insert(std::make_pair(kv.first, *params.get(kv.first))); } } - if (bind) - { - this->bind(); - } -} - -python_datasource::~python_datasource() { } - -// This name must match the plugin filename, eg 'python.input' -const char* python_datasource::name_="python"; - -const char* python_datasource::name() -{ - return name_; -} - -mapnik::layer_descriptor python_datasource::get_descriptor() const -{ - if (!is_bound_) bind(); - - return desc_; -} - -// The following methods call into the Python interpreter and hence require, unfortunately, that the GIL be held. - -void python_datasource::bind() const -{ + // The following methods call into the Python interpreter and hence require, unfortunately, that the GIL be held. using namespace boost; - if (is_bound_) return; - - // if no factory callable is defined, bind is a nop - if (factory_.empty()) return; + if (factory_.empty()) + { + throw mapnik::datasource_exception("Python: 'factory' option must be defined"); + } try { @@ -111,16 +85,27 @@ void python_datasource::bind() const { throw mapnik::datasource_exception(extractException()); } +} - is_bound_ = true; +python_datasource::~python_datasource() { } + +// This name must match the plugin filename, eg 'python.input' +const char* python_datasource::name_="python"; + +const char* python_datasource::name() +{ + return name_; +} + +mapnik::layer_descriptor python_datasource::get_descriptor() const +{ + return desc_; } mapnik::datasource::datasource_t python_datasource::type() const { typedef boost::optional return_type; - if (!is_bound_) bind(); - try { ensure_gil lock; @@ -137,8 +122,6 @@ mapnik::datasource::datasource_t python_datasource::type() const mapnik::box2d python_datasource::envelope() const { - if (!is_bound_) bind(); - try { ensure_gil lock; @@ -154,8 +137,6 @@ boost::optional python_datasource::get_geometry_ { typedef boost::optional return_type; - if (!is_bound_) bind(); - try { ensure_gil lock; @@ -181,8 +162,6 @@ boost::optional python_datasource::get_geometry_ mapnik::featureset_ptr python_datasource::features(mapnik::query const& q) const { - if (!is_bound_) bind(); - try { // if the query box intersects our world extent then query for features @@ -209,8 +188,6 @@ mapnik::featureset_ptr python_datasource::features(mapnik::query const& q) const mapnik::featureset_ptr python_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const { - if (!is_bound_) bind(); - try { ensure_gil lock; diff --git a/plugins/input/python/python_datasource.hpp b/plugins/input/python/python_datasource.hpp index 1b9980dfe..3465a3024 100644 --- a/plugins/input/python/python_datasource.hpp +++ b/plugins/input/python/python_datasource.hpp @@ -12,7 +12,7 @@ class python_datasource : public mapnik::datasource public: // constructor // arguments must not change - python_datasource(mapnik::parameters const& params, bool bind=true); + python_datasource(mapnik::parameters const& params); // destructor virtual ~python_datasource (); @@ -41,9 +41,6 @@ public: // mandatory: return the layer descriptor mapnik::layer_descriptor get_descriptor() const; - // mandatory: will bind the datasource given params - void bind() const; - private: static const char* name_; mutable mapnik::layer_descriptor desc_; diff --git a/plugins/input/raster/raster_datasource.cpp b/plugins/input/raster/raster_datasource.cpp index d188c1de7..125c2eac1 100644 --- a/plugins/input/raster/raster_datasource.cpp +++ b/plugins/input/raster/raster_datasource.cpp @@ -45,7 +45,7 @@ using mapnik::image_reader; DATASOURCE_PLUGIN(raster_datasource) -raster_datasource::raster_datasource(parameters const& params, bool bind) +raster_datasource::raster_datasource(parameters const& params) : datasource(params), desc_(*params.get("type"), "utf-8"), extent_initialized_(false) @@ -61,18 +61,19 @@ raster_datasource::raster_datasource(parameters const& params, bool bind) else filename_ = *file; - multi_tiles_ = *params_.get("multi", false); - tile_size_ = *params_.get("tile_size", 256); - tile_stride_ = *params_.get("tile_stride", 1); + multi_tiles_ = *params.get("multi", false); + tile_size_ = *params.get("tile_size", 256); + tile_stride_ = *params.get("tile_stride", 1); - format_ = *params_.get("format","tiff"); - - boost::optional lox = params_.get("lox"); - boost::optional loy = params_.get("loy"); - boost::optional hix = params_.get("hix"); - boost::optional hiy = params_.get("hiy"); - boost::optional ext = params_.get("extent"); + format_ = *params.get("format","tiff"); + boost::optional lox = params.get("lox"); + boost::optional loy = params.get("loy"); + boost::optional hix = params.get("hix"); + boost::optional hiy = params.get("hiy"); + + boost::optional ext = params.get("extent"); + if (lox && loy && hix && hiy) { extent_.init(*lox, *loy, *hix, *hiy); @@ -87,21 +88,11 @@ raster_datasource::raster_datasource(parameters const& params, bool bind) { throw datasource_exception("Raster Plugin: valid or are required"); } - - if (bind) - { - this->bind(); - } -} - -void raster_datasource::bind() const -{ - if (is_bound_) return; - + if (multi_tiles_) { - boost::optional x_width = params_.get("x_width"); - boost::optional y_width = params_.get("y_width"); + boost::optional x_width = params.get("x_width"); + boost::optional y_width = params.get("y_width"); if (! x_width) { @@ -148,7 +139,6 @@ void raster_datasource::bind() const MAPNIK_LOG_DEBUG(raster) << "raster_datasource: Raster size=" << width_ << "," << height_; - is_bound_ = true; } raster_datasource::~raster_datasource() @@ -182,8 +172,6 @@ layer_descriptor raster_datasource::get_descriptor() const featureset_ptr raster_datasource::features(query const& q) const { - if (! is_bound_) bind(); - mapnik::CoordTransform t(width_, height_, extent_, 0, 0); mapnik::box2d intersect = extent_.intersect(q.get_bbox()); mapnik::box2d ext = t.forward(intersect); diff --git a/plugins/input/raster/raster_datasource.hpp b/plugins/input/raster/raster_datasource.hpp index 91306ca14..44fff7df1 100644 --- a/plugins/input/raster/raster_datasource.hpp +++ b/plugins/input/raster/raster_datasource.hpp @@ -44,7 +44,7 @@ class raster_datasource : public mapnik::datasource { public: - raster_datasource(const mapnik::parameters& params, bool bind=true); + raster_datasource(const mapnik::parameters& params); virtual ~raster_datasource(); datasource::datasource_t type() const; static const char * name(); @@ -54,7 +54,6 @@ public: boost::optional get_geometry_type() const; mapnik::layer_descriptor get_descriptor() const; bool log_enabled() const; - void bind() const; private: mapnik::layer_descriptor desc_; diff --git a/plugins/input/rasterlite/rasterlite_datasource.cpp b/plugins/input/rasterlite/rasterlite_datasource.cpp index 803090635..893fb7f45 100644 --- a/plugins/input/rasterlite/rasterlite_datasource.cpp +++ b/plugins/input/rasterlite/rasterlite_datasource.cpp @@ -71,7 +71,7 @@ inline void* rasterlite_datasource::open_dataset() const } -rasterlite_datasource::rasterlite_datasource(parameters const& params, bool bind) +rasterlite_datasource::rasterlite_datasource(parameters const& params) : datasource(params), desc_(*params.get("type"),"utf-8") { @@ -91,16 +91,11 @@ rasterlite_datasource::rasterlite_datasource(parameters const& params, bool bind else dataset_name_ = *file; - if (bind) - { - this->bind(); - } + this->init(params); } -void rasterlite_datasource::bind() const +void rasterlite_datasource::init(mapnik::parameters const& params) { - if (is_bound_) return; - if (!boost::filesystem::exists(dataset_name_)) throw datasource_exception(dataset_name_ + " does not exist"); void *dataset = open_dataset(); @@ -158,8 +153,6 @@ void rasterlite_datasource::bind() const #endif rasterliteClose(dataset); - - is_bound_ = true; } rasterlite_datasource::~rasterlite_datasource() @@ -178,8 +171,6 @@ mapnik::datasource::datasource_t rasterlite_datasource::type() const box2d rasterlite_datasource::envelope() const { - if (!is_bound_) bind(); - return extent_; } @@ -195,16 +186,12 @@ layer_descriptor rasterlite_datasource::get_descriptor() const featureset_ptr rasterlite_datasource::features(query const& q) const { - if (!is_bound_) bind(); - rasterlite_query gq = q; return boost::make_shared(open_dataset(), gq); } featureset_ptr rasterlite_datasource::features_at_point(coord2d const& pt, double tol) const { - if (!is_bound_) bind(); - rasterlite_query gq = pt; return boost::make_shared(open_dataset(), gq); } diff --git a/plugins/input/rasterlite/rasterlite_datasource.hpp b/plugins/input/rasterlite/rasterlite_datasource.hpp index 7c046e582..c9c41f3e7 100644 --- a/plugins/input/rasterlite/rasterlite_datasource.hpp +++ b/plugins/input/rasterlite/rasterlite_datasource.hpp @@ -45,7 +45,7 @@ class rasterlite_datasource : public mapnik::datasource { public: - rasterlite_datasource(mapnik::parameters const& params, bool bind = true); + rasterlite_datasource(mapnik::parameters const& params); virtual ~rasterlite_datasource (); mapnik::datasource::datasource_t type() const; static const char * name(); @@ -54,7 +54,6 @@ public: mapnik::box2d envelope() const; boost::optional get_geometry_type() const; mapnik::layer_descriptor get_descriptor() const; - void bind() const; private: void* open_dataset() const; diff --git a/plugins/input/shape/shape_datasource.cpp b/plugins/input/shape/shape_datasource.cpp index 3a4dff4c8..c1679a189 100644 --- a/plugins/input/shape/shape_datasource.cpp +++ b/plugins/input/shape/shape_datasource.cpp @@ -55,14 +55,17 @@ using mapnik::filter_in_box; using mapnik::filter_at_point; using mapnik::attribute_descriptor; -shape_datasource::shape_datasource(const parameters ¶ms, bool bind) +shape_datasource::shape_datasource(const parameters ¶ms) : datasource (params), type_(datasource::Vector), file_length_(0), indexed_(false), - row_limit_(*params_.get("row_limit",0)), + row_limit_(*params.get("row_limit",0)), desc_(*params.get("type"), *params.get("encoding","utf-8")) { +#ifdef MAPNIK_STATS + mapnik::progress_timer __stats__(std::clog, "shape_datasource::init"); +#endif boost::optional file = params.get("file"); if (!file) throw datasource_exception("Shape Plugin: missing parameter"); @@ -74,20 +77,6 @@ shape_datasource::shape_datasource(const parameters ¶ms, bool bind) boost::algorithm::ireplace_last(shape_name_,".shp",""); - if (bind) - { - this->bind(); - } -} - -void shape_datasource::bind() const -{ - if (is_bound_) return; - -#ifdef MAPNIK_STATS - mapnik::progress_timer __stats__(std::clog, "shape_datasource::bind"); -#endif - if (!boost::filesystem::exists(shape_name_ + ".shp")) { throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".shp' does not exist"); @@ -107,7 +96,7 @@ void shape_datasource::bind() const try { #ifdef MAPNIK_STATS - mapnik::progress_timer __stats2__(std::clog, "shape_datasource::bind(get_column_description)"); + mapnik::progress_timer __stats2__(std::clog, "shape_datasource::init(get_column_description)"); #endif boost::shared_ptr shape_ref = boost::make_shared(shape_name_); @@ -171,7 +160,6 @@ void shape_datasource::bind() const throw; } - is_bound_ = true; } shape_datasource::~shape_datasource() {} @@ -252,14 +240,11 @@ datasource::datasource_t shape_datasource::type() const layer_descriptor shape_datasource::get_descriptor() const { - if (!is_bound_) bind(); return desc_; } featureset_ptr shape_datasource::features(const query& q) const { - if (!is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "shape_datasource::features"); #endif @@ -290,8 +275,6 @@ featureset_ptr shape_datasource::features(const query& q) const featureset_ptr shape_datasource::features_at_point(coord2d const& pt, double tol) const { - if (!is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "shape_datasource::features_at_point"); #endif @@ -334,8 +317,6 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt, double tol box2d shape_datasource::envelope() const { - if (!is_bound_) bind(); - return extent_; } diff --git a/plugins/input/shape/shape_datasource.hpp b/plugins/input/shape/shape_datasource.hpp index ea3e10587..6e10b9608 100644 --- a/plugins/input/shape/shape_datasource.hpp +++ b/plugins/input/shape/shape_datasource.hpp @@ -52,7 +52,7 @@ using mapnik::coord2d; class shape_datasource : public datasource { public: - shape_datasource(const parameters ¶ms, bool bind=true); + shape_datasource(const parameters ¶ms); virtual ~shape_datasource(); datasource::datasource_t type() const; static const char * name(); @@ -61,7 +61,6 @@ public: box2d envelope() const; boost::optional get_geometry_type() const; layer_descriptor get_descriptor() const; - void bind() const; private: void init(shape_io& shape) const; diff --git a/plugins/input/sqlite/sqlite_datasource.cpp b/plugins/input/sqlite/sqlite_datasource.cpp index 10a2f8b9d..4c3c2e816 100644 --- a/plugins/input/sqlite/sqlite_datasource.cpp +++ b/plugins/input/sqlite/sqlite_datasource.cpp @@ -52,22 +52,22 @@ using mapnik::parameters; DATASOURCE_PLUGIN(sqlite_datasource) -sqlite_datasource::sqlite_datasource(parameters const& params, bool bind) +sqlite_datasource::sqlite_datasource(parameters const& params) : datasource(params), extent_(), extent_initialized_(false), type_(datasource::Vector), - table_(*params_.get("table", "")), - fields_(*params_.get("fields", "*")), - metadata_(*params_.get("metadata", "")), - geometry_table_(*params_.get("geometry_table", "")), - geometry_field_(*params_.get("geometry_field", "")), - index_table_(*params_.get("index_table", "")), - key_field_(*params_.get("key_field", "")), - row_offset_(*params_.get("row_offset", 0)), - row_limit_(*params_.get("row_limit", 0)), + table_(*params.get("table", "")), + fields_(*params.get("fields", "*")), + metadata_(*params.get("metadata", "")), + geometry_table_(*params.get("geometry_table", "")), + geometry_field_(*params.get("geometry_field", "")), + index_table_(*params.get("index_table", "")), + key_field_(*params.get("key_field", "")), + row_offset_(*params.get("row_offset", 0)), + row_limit_(*params.get("row_limit", 0)), intersects_token_("!intersects!"), - desc_(*params_.get("type"), *params_.get("encoding", "utf-8")), + desc_(*params.get("type"), *params.get("encoding", "utf-8")), format_(mapnik::wkbAuto) { /* TODO @@ -76,27 +76,14 @@ sqlite_datasource::sqlite_datasource(parameters const& params, bool bind) - if spatialite - leverage more of the metadata for geometry type detection */ - boost::optional file = params_.get("file"); - if (! file) throw datasource_exception("Sqlite Plugin: missing parameter"); - - if (bind) - { - this->bind(); - } -} - -void sqlite_datasource::bind() const -{ - if (is_bound_) return; - #ifdef MAPNIK_STATS - mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::bind"); + mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::init"); #endif - boost::optional file = params_.get("file"); + boost::optional file = params.get("file"); if (! file) throw datasource_exception("Sqlite Plugin: missing parameter"); - boost::optional base = params_.get("base"); + boost::optional base = params.get("base"); if (base) dataset_name_ = *base + "/" + *file; else @@ -107,15 +94,15 @@ void sqlite_datasource::bind() const throw datasource_exception("Sqlite Plugin: " + dataset_name_ + " does not exist"); } - use_spatial_index_ = *params_.get("use_spatial_index", true); + use_spatial_index_ = *params.get("use_spatial_index", true); // TODO - remove this option once all datasources have an indexing api - bool auto_index = *params_.get("auto_index", true); + bool auto_index = *params.get("auto_index", true); - boost::optional ext = params_.get("extent"); + boost::optional ext = params.get("extent"); if (ext) extent_initialized_ = extent_.from_string(*ext); - boost::optional wkb = params_.get("wkb_format"); + boost::optional wkb = params.get("wkb_format"); if (wkb) { if (*wkb == "spatialite") @@ -139,13 +126,13 @@ void sqlite_datasource::bind() const // databases are relative to directory containing dataset_name_. Sqlite // will default to attaching from cwd. Typicaly usage means that the // map loader will produce full paths here. - boost::optional attachdb = params_.get("attachdb"); + boost::optional attachdb = params.get("attachdb"); if (attachdb) { parse_attachdb(*attachdb); } - boost::optional initdb = params_.get("initdb"); + boost::optional initdb = params.get("initdb"); if (initdb) { init_statements_.push_back(*initdb); @@ -154,10 +141,10 @@ void sqlite_datasource::bind() const // now actually create the connection and start executing setup sql dataset_ = boost::make_shared(dataset_name_); - boost::optional table_by_index = params_.get("table_by_index"); + boost::optional table_by_index = params.get("table_by_index"); int passed_parameters = 0; - passed_parameters += params_.get("table") ? 1 : 0; + passed_parameters += params.get("table") ? 1 : 0; passed_parameters += table_by_index ? 1 : 0; if (passed_parameters > 1) @@ -289,7 +276,7 @@ void sqlite_datasource::bind() const if (use_spatial_index_) { #ifdef MAPNIK_STATS - mapnik::progress_timer __stats2__(std::clog, "sqlite_datasource::bind(use_spatial_index)"); + mapnik::progress_timer __stats2__(std::clog, "sqlite_datasource::init(use_spatial_index)"); #endif if (boost::filesystem::exists(index_db)) @@ -374,7 +361,6 @@ void sqlite_datasource::bind() const } } - is_bound_ = true; } std::string sqlite_datasource::populate_tokens(std::string const& sql) const @@ -487,15 +473,11 @@ mapnik::datasource::datasource_t sqlite_datasource::type() const box2d sqlite_datasource::envelope() const { - if (! is_bound_) bind(); - return extent_; } boost::optional sqlite_datasource::get_geometry_type() const { - if (! is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::get_geometry_type"); #endif @@ -547,15 +529,11 @@ boost::optional sqlite_datasource::get_geometry_ layer_descriptor sqlite_datasource::get_descriptor() const { - if (! is_bound_) bind(); - return desc_; } featureset_ptr sqlite_datasource::features(query const& q) const { - if (! is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::features"); #endif @@ -634,8 +612,6 @@ featureset_ptr sqlite_datasource::features(query const& q) const featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt, double tol) const { - if (! is_bound_) bind(); - #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::features_at_point"); #endif diff --git a/plugins/input/sqlite/sqlite_datasource.hpp b/plugins/input/sqlite/sqlite_datasource.hpp index c87d94d04..11ef7196b 100644 --- a/plugins/input/sqlite/sqlite_datasource.hpp +++ b/plugins/input/sqlite/sqlite_datasource.hpp @@ -48,7 +48,7 @@ class sqlite_datasource : public mapnik::datasource { public: - sqlite_datasource(mapnik::parameters const& params, bool bind = true); + sqlite_datasource(mapnik::parameters const& params); virtual ~sqlite_datasource (); datasource::datasource_t type() const; static const char * name(); @@ -57,7 +57,6 @@ public: mapnik::box2d envelope() const; boost::optional get_geometry_type() const; mapnik::layer_descriptor get_descriptor() const; - void bind() const; private: // Fill init_statements with any statements @@ -65,9 +64,6 @@ private: void parse_attachdb(std::string const& attachdb) const; std::string populate_tokens(std::string const& sql) const; - // FIXME: remove mutable qualifier from data members - // by factoring out bind() logic out from - // datasource impl !!! mutable mapnik::box2d extent_; mutable bool extent_initialized_; mapnik::datasource::datasource_t type_; diff --git a/plugins/input/templates/helloworld/hello_datasource.cpp b/plugins/input/templates/helloworld/hello_datasource.cpp index 9b9b4437a..38b1d0e10 100644 --- a/plugins/input/templates/helloworld/hello_datasource.cpp +++ b/plugins/input/templates/helloworld/hello_datasource.cpp @@ -11,29 +11,22 @@ using mapnik::parameters; DATASOURCE_PLUGIN(hello_datasource) -hello_datasource::hello_datasource(parameters const& params, bool bind) +hello_datasource::hello_datasource(parameters const& params) : datasource(params), - desc_(*params_.get("type"), *params_.get("encoding","utf-8")), + desc_(*params.get("type"), *params.get("encoding","utf-8")), extent_() { - if (bind) - { - this->bind(); - } + this->init(params); } -void hello_datasource::bind() const +void hello_datasource::init(mapnik::parameters const& params) { - if (is_bound_) return; - // every datasource must have some way of reporting its extent // in this case we are not actually reading from any data so for fun // let's just create a world extent in Mapnik's default srs: // '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' (equivalent to +init=epsg:4326) // see http://spatialreference.org/ref/epsg/4326/ for more details extent_.init(-180,-90,180,90); - - is_bound_ = true; } hello_datasource::~hello_datasource() { } @@ -51,8 +44,6 @@ mapnik::datasource::datasource_t hello_datasource::type() const mapnik::box2d hello_datasource::envelope() const { - if (!is_bound_) bind(); - return extent_; } @@ -63,15 +54,11 @@ boost::optional hello_datasource::get_geometry_t mapnik::layer_descriptor hello_datasource::get_descriptor() const { - if (!is_bound_) bind(); - return desc_; } mapnik::featureset_ptr hello_datasource::features(mapnik::query const& q) const { - if (!is_bound_) bind(); - // if the query box intersects our world extent then query for features if (extent_.intersects(q.get_bbox())) { @@ -84,8 +71,6 @@ mapnik::featureset_ptr hello_datasource::features(mapnik::query const& q) const mapnik::featureset_ptr hello_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const { - if (!is_bound_) bind(); - // features_at_point is rarely used - only by custom applications, // so for this sample plugin let's do nothing... return mapnik::featureset_ptr(); diff --git a/plugins/input/templates/helloworld/hello_datasource.hpp b/plugins/input/templates/helloworld/hello_datasource.hpp index 969c07332..b1d8f2b32 100644 --- a/plugins/input/templates/helloworld/hello_datasource.hpp +++ b/plugins/input/templates/helloworld/hello_datasource.hpp @@ -22,7 +22,7 @@ class hello_datasource : public mapnik::datasource public: // constructor // arguments must not change - hello_datasource(mapnik::parameters const& params, bool bind=true); + hello_datasource(mapnik::parameters const& params); // destructor virtual ~hello_datasource (); @@ -51,10 +51,10 @@ public: // mandatory: return the layer descriptor mapnik::layer_descriptor get_descriptor() const; - // mandatory: will bind the datasource given params - void bind() const; - private: + // recommended - do intialization in a so-named init function + // to reduce code in constructor + void init(mapnik::parameters const& params); // recommended naming convention of datasource members: // name_, type_, extent_, and desc_ static const std::string name_; diff --git a/src/datasource_cache.cpp b/src/datasource_cache.cpp index 5d5d63616..1b68b22a7 100644 --- a/src/datasource_cache.cpp +++ b/src/datasource_cache.cpp @@ -55,7 +55,7 @@ datasource_cache::~datasource_cache() lt_dlexit(); } -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) @@ -114,7 +114,7 @@ datasource_ptr datasource_cache::create(const parameters& params, bool bind) } #endif - ds = datasource_ptr(create_datasource(params, bind), datasource_deleter()); + ds = datasource_ptr(create_datasource(params), datasource_deleter()); MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Datasource=" << ds << " type=" << type; diff --git a/src/deepcopy.cpp b/src/deepcopy.cpp index 3613b90e3..22356c966 100644 --- a/src/deepcopy.cpp +++ b/src/deepcopy.cpp @@ -119,7 +119,6 @@ namespace mapnik { namespace util { feature_type_style style_out(style_in,true); // deep copy map_out.insert_style(kv.first, style_out); } - } - }} +}}