code cleanup / c++11 usage in plugins

This commit is contained in:
Dane Springmeyer 2015-10-09 16:07:19 -07:00
parent 34a744f7db
commit 324f70652b
5 changed files with 43 additions and 49 deletions

View file

@ -492,12 +492,9 @@ void validate_attribute_names(query const& q, std::vector<attribute_descriptor>
{
bool found_name = false;
std::vector<attribute_descriptor>::const_iterator itr = names.begin();
std::vector<attribute_descriptor>::const_iterator end = names.end();
for (; itr!=end; ++itr)
for (auto const& attr_info : names)
{
if (itr->get_name() == *pos)
if (attr_info.get_name() == *pos)
{
found_name = true;
break;
@ -508,11 +505,9 @@ void validate_attribute_names(query const& q, std::vector<attribute_descriptor>
{
std::ostringstream s;
s << "OGR Plugin: no attribute named '" << *pos << "'. Valid attributes are: ";
std::vector<attribute_descriptor>::const_iterator e_itr = names.begin();
std::vector<attribute_descriptor>::const_iterator e_end = names.end();
for ( ;e_itr!=e_end;++e_itr)
for (auto const& attr_info2 : names)
{
s << e_itr->get_name() << std::endl;
s << attr_info2.get_name() << std::endl;
}
throw mapnik::datasource_exception(s.str());
}
@ -533,10 +528,10 @@ featureset_ptr ogr_datasource::features(query const& q) const
// feature context (schema)
mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
std::vector<attribute_descriptor>::const_iterator itr = desc_ar.begin();
std::vector<attribute_descriptor>::const_iterator end = desc_ar.end();
for (; itr!=end; ++itr) ctx->push(itr->get_name()); // TODO only push query attributes
for (auto const& attr_info : desc_ar)
{
ctx->push(attr_info.get_name()); // TODO only push query attributes
}
validate_attribute_names(q, desc_ar);
@ -576,9 +571,10 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt, double tol)
// feature context (schema)
mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
std::vector<attribute_descriptor>::const_iterator itr = desc_ar.begin();
std::vector<attribute_descriptor>::const_iterator end = desc_ar.end();
for (; itr!=end; ++itr) ctx->push(itr->get_name());
for (auto const& attr_info : desc_ar)
{
ctx->push(attr_info.get_name()); // TODO only push query attributes
}
OGRLayer* layer = layer_.layer();

View file

@ -1042,28 +1042,29 @@ featureset_ptr pgraster_datasource::features_at_point(coord2d const& pt, double
s << "SELECT ST_AsBinary(\"" << geometryColumn_ << "\") AS geom";
mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin();
std::vector<attribute_descriptor>::const_iterator end = desc_.get_descriptors().end();
auto const& desc = desc_.get_descriptors();
if (! key_field_.empty())
if (!key_field_.empty())
{
mapnik::sql_utils::quote_attr(s, key_field_);
ctx->push(key_field_);
for (; itr != end; ++itr)
for (auto const& attr_info : desc)
{
if (itr->get_name() != key_field_)
std::string const& name = attr_info.get_name();
if (name != key_field_)
{
mapnik::sql_utils::quote_attr(s, itr->get_name());
ctx->push(itr->get_name());
mapnik::sql_utils::quote_attr(s, name);
ctx->push(name);
}
}
}
else
{
for (; itr != end; ++itr)
for (auto const& attr_info : desc)
{
mapnik::sql_utils::quote_attr(s, itr->get_name());
ctx->push(itr->get_name());
std::string const& name = attr_info.get_name();
mapnik::sql_utils::quote_attr(s, name);
ctx->push(name);
}
}

View file

@ -903,31 +903,32 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt, double t
s << "SELECT ST_AsBinary(\"" << geometryColumn_ << "\") AS geom";
mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin();
std::vector<attribute_descriptor>::const_iterator end = desc_.get_descriptors().end();
auto const& desc = desc_.get_descriptors();
if (! key_field_.empty())
if (!key_field_.empty())
{
mapnik::sql_utils::quote_attr(s, key_field_);
if (key_field_as_attribute_)
{
ctx->push(key_field_);
}
for (; itr != end; ++itr)
for (auto const& attr_info : desc)
{
if (itr->get_name() != key_field_)
std::string const& name = attr_info.get_name();
if (name != key_field_)
{
mapnik::sql_utils::quote_attr(s, itr->get_name());
ctx->push(itr->get_name());
mapnik::sql_utils::quote_attr(s, name);
ctx->push(name);
}
}
}
else
{
for (; itr != end; ++itr)
for (auto const& attr_info : desc)
{
mapnik::sql_utils::quote_attr(s, itr->get_name());
ctx->push(itr->get_name());
std::string const& name = attr_info.get_name();
mapnik::sql_utils::quote_attr(s, name);
ctx->push(name);
}
}

View file

@ -263,15 +263,12 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt, double tol
filter_at_point filter(pt,tol);
// collect all attribute names
std::vector<attribute_descriptor> const& desc_vector = desc_.get_descriptors();
std::vector<attribute_descriptor>::const_iterator itr = desc_vector.begin();
std::vector<attribute_descriptor>::const_iterator end = desc_vector.end();
auto const& desc = desc_.get_descriptors();
std::set<std::string> names;
while (itr != end)
for (auto const& attr_info : desc)
{
names.insert(itr->get_name());
++itr;
names.insert(attr_info.get_name());
}
if (indexed_)

View file

@ -574,16 +574,15 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt, double to
ctx->push(key_field_);
}
std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin();
std::vector<attribute_descriptor>::const_iterator end = desc_.get_descriptors().end();
auto const& desc = desc_.get_descriptors();
for ( ; itr != end; ++itr)
for (auto const& attr_info : desc)
{
std::string fld_name = itr->get_name();
if (fld_name != key_field_)
std::string const& name = attr_info.get_name();
if (name != key_field_)
{
s << ",[" << itr->get_name() << "]";
ctx->push(itr->get_name());
s << ",[" << name << "]";
ctx->push(name);
}
}