From 4c4bfc8fc5000a9b6ff58c02f321355be061dc7c Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 21 Feb 2012 11:03:33 -0800 Subject: [PATCH] remove all usage of lexical_cast in postgis plugin - refs #1055 --- plugins/input/postgis/postgis_datasource.cpp | 66 ++++++++++---------- plugins/input/postgis/postgis_datasource.hpp | 1 - plugins/input/postgis/postgis_featureset.cpp | 15 ++--- 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/plugins/input/postgis/postgis_datasource.cpp b/plugins/input/postgis/postgis_datasource.cpp index 679a21861..732fbf647 100644 --- a/plugins/input/postgis/postgis_datasource.cpp +++ b/plugins/input/postgis/postgis_datasource.cpp @@ -28,10 +28,10 @@ #include #include #include +#include // boost #include -#include #include #include #include @@ -50,10 +50,7 @@ DATASOURCE_PLUGIN(postgis_datasource) const std::string postgis_datasource::GEOMETRY_COLUMNS="geometry_columns"; const std::string postgis_datasource::SPATIAL_REF_SYS="spatial_ref_system"; -using boost::lexical_cast; -using boost::bad_lexical_cast; using boost::shared_ptr; - using mapnik::PoolGuard; using mapnik::attribute_descriptor; @@ -174,13 +171,12 @@ void postgis_datasource::bind() const if (srid_ == 0) { - try + const char * srid_c = rs->getValue("srid"); + if (srid_c != NULL) { - srid_ = lexical_cast(rs->getValue("srid")); - } - catch (bad_lexical_cast &ex) - { - std::clog << "Postgis Plugin: SRID=" << rs->getValue("srid") << " " << ex.what() << std::endl; + int result; + if (mapnik::conversions::string2int(srid_c,&result)) + srid_ = result; } } } @@ -205,13 +201,12 @@ void postgis_datasource::bind() const shared_ptr rs = conn->executeQuery(s.str()); if (rs->next()) { - try + const char * srid_c = rs->getValue("srid"); + if (srid_c != NULL) { - srid_ = lexical_cast(rs->getValue("srid")); - } - catch (bad_lexical_cast &ex) - { - std::clog << "Postgis Plugin: SRID=" << rs->getValue("srid") << " " << ex.what() << std::endl; + int result; + if (mapnik::conversions::string2int(srid_c,&result)) + srid_ = result; } } rs->close(); @@ -384,8 +379,9 @@ std::string postgis_datasource::populate_tokens(const std::string& sql) const } if ( boost::algorithm::icontains(sql,scale_denom_token_) ) { - std::string max_denom = lexical_cast(FMAX); - boost::algorithm::replace_all(populated_sql,scale_denom_token_,max_denom); + std::ostringstream ss; + ss << FMAX; + boost::algorithm::replace_all(populated_sql,scale_denom_token_,ss.str()); } return populated_sql; } @@ -397,8 +393,9 @@ std::string postgis_datasource::populate_tokens(const std::string& sql, double s if ( boost::algorithm::icontains(populated_sql,scale_denom_token_) ) { - std::string max_denom = lexical_cast(scale_denom); - boost::algorithm::replace_all(populated_sql,scale_denom_token_,max_denom); + std::ostringstream ss; + ss << scale_denom; + boost::algorithm::replace_all(populated_sql,scale_denom_token_,ss.str()); } if ( boost::algorithm::icontains(populated_sql,bbox_token_) ) @@ -684,19 +681,22 @@ box2d postgis_datasource::envelope() const shared_ptr rs = conn->executeQuery(s.str()); if (rs->next() && !rs->isNull(0)) { - try - { - double lox = lexical_cast(rs->getValue(0)); - double loy = lexical_cast(rs->getValue(1)); - double hix = lexical_cast(rs->getValue(2)); - double hiy = lexical_cast(rs->getValue(3)); - extent_.init(lox,loy,hix,hiy); - extent_initialized_ = true; - } - catch (bad_lexical_cast &ex) - { - std::clog << boost::format("Postgis Plugin: warning: could not determine extent from query: %s\nError was: '%s'\n") % s.str() % ex.what() << std::endl; - } + double lox; + double loy; + double hix; + double hiy; + if (mapnik::conversions::string2double(rs->getValue(0),&lox) && + mapnik::conversions::string2double(rs->getValue(1),&loy) && + mapnik::conversions::string2double(rs->getValue(2),&hix) && + mapnik::conversions::string2double(rs->getValue(3),&hiy)) + { + extent_.init(lox,loy,hix,hiy); + extent_initialized_ = true; + } + else + { + std::clog << boost::format("Postgis Plugin: warning: could not determine extent from query: %s\n") % s.str() << std::endl; + } } rs->close(); } diff --git a/plugins/input/postgis/postgis_datasource.hpp b/plugins/input/postgis/postgis_datasource.hpp index e7f997ed7..846664de1 100644 --- a/plugins/input/postgis/postgis_datasource.hpp +++ b/plugins/input/postgis/postgis_datasource.hpp @@ -31,7 +31,6 @@ #include // boost -#include #include #include "connection_manager.hpp" diff --git a/plugins/input/postgis/postgis_featureset.cpp b/plugins/input/postgis/postgis_featureset.cpp index b90ef4df1..052782f85 100644 --- a/plugins/input/postgis/postgis_featureset.cpp +++ b/plugins/input/postgis/postgis_featureset.cpp @@ -30,17 +30,16 @@ #include #include #include +#include // boost -#include #include +#include // stl #include #include -using boost::lexical_cast; -using boost::bad_lexical_cast; using boost::trim_copy; using mapnik::geometry_type; using mapnik::byte; @@ -162,15 +161,9 @@ feature_ptr postgis_featureset::next() else if (oid == 1700) // numeric { std::string str = mapnik::sql_utils::numeric2string(buf); - try - { - double val = boost::lexical_cast(str); + double val; + if (mapnik::conversions::string2double(str,&val)) feature->put(name,val); - } - catch (boost::bad_lexical_cast & ex) - { - std::clog << ex.what() << "\n"; - } } else {