Skip to content

Commit

Permalink
Merge pull request #1654 from mapnik/no-bind
Browse files Browse the repository at this point in the history
Remove bind option for datasources closes #962, reverts #622, refs #1655 and #1656
  • Loading branch information
Dane Springmeyer committed Dec 17, 2012
2 parents cba1ec5 + 43244ef commit 83215ba
Show file tree
Hide file tree
Showing 37 changed files with 380 additions and 722 deletions.
12 changes: 1 addition & 11 deletions bindings/python/mapnik_datasource.cpp
Expand Up @@ -50,24 +50,15 @@ namespace
using namespace boost::python;
boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
{
bool bind=true;
mapnik::parameters params;
boost::python::list keys=d.keys();
for (int i=0; i<len(keys); ++i)
{
std::string key = extract<std::string>(keys[i]);
object obj = d[key];

if (key == "bind")
{
bind = extract<bool>(obj)();
continue;
}

extract<std::string> ex0(obj);
extract<int> ex1(obj);
extract<double> ex2(obj);

if (ex0.check())
{
params[key] = ex0();
Expand All @@ -82,7 +73,7 @@ boost::shared_ptr<mapnik::datasource> 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<mapnik::datasource> const& ds)
Expand Down Expand Up @@ -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))
Expand Down
10 changes: 1 addition & 9 deletions bindings/python/mapnik_datasource_cache.cpp
Expand Up @@ -31,20 +31,12 @@ using namespace boost::python;

boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
{
bool bind=true;
mapnik::parameters params;
boost::python::list keys=d.keys();
for (int i=0; i<len(keys); ++i)
{
std::string key = extract<std::string>(keys[i]);
object obj = d[key];

if (key == "bind")
{
bind = extract<bool>(obj)();
continue;
}

extract<std::string> ex0(obj);
extract<int> ex1(obj);
extract<double> ex2(obj);
Expand All @@ -63,7 +55,7 @@ boost::shared_ptr<mapnik::datasource> 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)
Expand Down
22 changes: 6 additions & 16 deletions include/mapnik/datasource.hpp
Expand Up @@ -86,10 +86,7 @@ class MAPNIK_DECL datasource : private mapnik::noncopyable
};

datasource (parameters const& params)
: params_(params),
is_bound_(false)
{
}
: params__(params) {}

/*!
* @brief Get the configuration parameters of the data source.
Expand All @@ -100,33 +97,26 @@ class MAPNIK_DECL datasource : private mapnik::noncopyable
*/
parameters const& params() const
{
return params_;
return 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(query const& q) const = 0;
virtual featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const = 0;
virtual box2d<double> envelope() const = 0;
virtual boost::optional<geometry_t> get_geometry_type() const = 0;
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
Expand All @@ -145,9 +135,9 @@ typedef boost::shared_ptr<datasource> 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) \
{ \
Expand Down
2 changes: 1 addition & 1 deletion include/mapnik/datasource_cache.hpp
Expand Up @@ -48,7 +48,7 @@ class MAPNIK_DECL datasource_cache
std::string plugin_directories();
void register_datasources(std::string const& path);
bool register_datasource(std::string const& path);
boost::shared_ptr<datasource> create(parameters const& params, bool bind=true);
boost::shared_ptr<datasource> create(parameters const& params);
private:
datasource_cache();
~datasource_cache();
Expand Down
55 changes: 17 additions & 38 deletions plugins/input/csv/csv_datasource.cpp
Expand Up @@ -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<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding", "utf-8")),
extent_(),
filename_(),
inline_string_(),
file_length_(0),
row_limit_(*params_.get<int>("row_limit", 0)),
row_limit_(*params.get<int>("row_limit", 0)),
features_(),
escape_(*params_.get<std::string>("escape", "")),
separator_(*params_.get<std::string>("separator", "")),
quote_(*params_.get<std::string>("quote", "")),
escape_(*params.get<std::string>("escape", "")),
separator_(*params.get<std::string>("separator", "")),
quote_(*params.get<std::string>("quote", "")),
headers_(),
manual_headers_(mapnik::util::trim_copy(*params_.get<std::string>("headers", ""))),
strict_(*params_.get<mapnik::boolean>("strict", false)),
quiet_(*params_.get<mapnik::boolean>("quiet", false)),
filesize_max_(*params_.get<float>("filesize_max", 20.0)), // MB
manual_headers_(mapnik::util::trim_copy(*params.get<std::string>("headers", ""))),
strict_(*params.get<mapnik::boolean>("strict", false)),
quiet_(*params.get<mapnik::boolean>("quiet", false)),
filesize_max_(*params.get<float>("filesize_max", 20.0)), // MB
ctx_(boost::make_shared<mapnik::context_type>())
{
/* TODO:
Expand All @@ -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<std::string> inline_string = params_.get<std::string>("inline");
boost::optional<std::string> inline_string = params.get<std::string>("inline");
if (inline_string)
{
inline_string_ = *inline_string;
}
else
{
boost::optional<std::string> file = params_.get<std::string>("file");
boost::optional<std::string> file = params.get<std::string>("file");
if (!file) throw mapnik::datasource_exception("CSV Plugin: missing <file> parameter");

boost::optional<std::string> base = params_.get<std::string>("base");
boost::optional<std::string> base = params.get<std::string>("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_);
Expand All @@ -140,14 +126,16 @@ void csv_datasource::bind() const
parse_csv(in,escape_, separator_, quote_);
in.close();
}
is_bound_ = true;
}


csv_datasource::~csv_datasource() { }

template <typename T>
void csv_datasource::parse_csv(T & stream,
std::string const& escape,
std::string const& separator,
std::string const& quote) const
std::string const& quote)
{
stream.seekg(0, std::ios::end);
file_length_ = stream.tellg();
Expand Down Expand Up @@ -890,14 +878,11 @@ datasource::datasource_t csv_datasource::type() const

mapnik::box2d<double> csv_datasource::envelope() const
{
if (!is_bound_) bind();

return extent_;
}

boost::optional<mapnik::datasource::geometry_t> csv_datasource::get_geometry_type() const
{
if (! is_bound_) bind();
boost::optional<mapnik::datasource::geometry_t> result;
int multi_type = 0;
unsigned num_features = features_.size();
Expand All @@ -920,15 +905,11 @@ boost::optional<mapnik::datasource::geometry_t> 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<std::string>& attribute_names = q.property_names();
std::set<std::string>::const_iterator pos = attribute_names.begin();
while (pos != attribute_names.end())
Expand Down Expand Up @@ -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");
}
37 changes: 18 additions & 19 deletions plugins/input/csv/csv_datasource.hpp
Expand Up @@ -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();
Expand All @@ -51,31 +51,30 @@ class csv_datasource : public mapnik::datasource
mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const;
void bind() const;

template <typename T>
void parse_csv(T & stream,
std::string const& escape,
std::string const& separator,
std::string const& quote) const;
std::string const& quote);

private:
mutable mapnik::layer_descriptor desc_;
mutable mapnik::box2d<double> extent_;
mutable std::string filename_;
mutable std::string inline_string_;
mutable unsigned file_length_;
mutable int row_limit_;
mutable std::vector<mapnik::feature_ptr> features_;
mutable std::string escape_;
mutable std::string separator_;
mutable std::string quote_;
mutable std::vector<std::string> headers_;
mutable std::string manual_headers_;
mutable bool strict_;
mutable bool quiet_;
mutable double filesize_max_;
mutable mapnik::context_ptr ctx_;
mapnik::layer_descriptor desc_;
mapnik::box2d<double> extent_;
std::string filename_;
std::string inline_string_;
unsigned file_length_;
int row_limit_;
std::vector<mapnik::feature_ptr> features_;
std::string escape_;
std::string separator_;
std::string quote_;
std::vector<std::string> headers_;
std::string manual_headers_;
bool strict_;
bool quiet_;
double filesize_max_;
mapnik::context_ptr ctx_;
};

#endif // MAPNIK_CSV_DATASOURCE_HPP

0 comments on commit 83215ba

Please sign in to comment.