From ec0436fcd91d2798ac81c5b187e6b7a8606d3734 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Tue, 10 May 2011 14:22:47 +0000 Subject: [PATCH] + consistent [h,c]pp files naming --- plugins/input/postgis/SConscript | 4 +- plugins/input/postgis/connection.hpp | 1 - .../{postgis.cpp => postgis_datasource.cpp} | 3 +- .../{postgis.hpp => postgis_datasource.hpp} | 34 +---- .../{postgisfs.cpp => postgis_featureset.cpp} | 142 +++++++++--------- plugins/input/postgis/postgis_featureset.hpp | 64 ++++++++ plugins/input/postgis/resultset.hpp | 5 +- 7 files changed, 152 insertions(+), 101 deletions(-) rename plugins/input/postgis/{postgis.cpp => postgis_datasource.cpp} (99%) rename plugins/input/postgis/{postgis.hpp => postgis_datasource.hpp} (80%) rename plugins/input/postgis/{postgisfs.cpp => postgis_featureset.cpp} (50%) create mode 100644 plugins/input/postgis/postgis_featureset.hpp diff --git a/plugins/input/postgis/SConscript b/plugins/input/postgis/SConscript index 03b3c1290..efc73ec58 100644 --- a/plugins/input/postgis/SConscript +++ b/plugins/input/postgis/SConscript @@ -28,8 +28,8 @@ plugin_env = env.Clone() postgis_src = Split( """ - postgis.cpp - postgisfs.cpp + postgis_datasource.cpp + postgis_featureset.cpp """ ) diff --git a/plugins/input/postgis/connection.hpp b/plugins/input/postgis/connection.hpp index b92edd71a..9a8da17ce 100644 --- a/plugins/input/postgis/connection.hpp +++ b/plugins/input/postgis/connection.hpp @@ -34,7 +34,6 @@ extern "C" #include "resultset.hpp" -class ResultSet; class Connection { private: diff --git a/plugins/input/postgis/postgis.cpp b/plugins/input/postgis/postgis_datasource.cpp similarity index 99% rename from plugins/input/postgis/postgis.cpp rename to plugins/input/postgis/postgis_datasource.cpp index f229f5525..d8bd7577e 100644 --- a/plugins/input/postgis/postgis.cpp +++ b/plugins/input/postgis/postgis_datasource.cpp @@ -32,7 +32,8 @@ #endif #include "connection_manager.hpp" -#include "postgis.hpp" +#include "postgis_datasource.hpp" +#include "postgis_featureset.hpp" // boost #include diff --git a/plugins/input/postgis/postgis.hpp b/plugins/input/postgis/postgis_datasource.hpp similarity index 80% rename from plugins/input/postgis/postgis.hpp rename to plugins/input/postgis/postgis_datasource.hpp index 758b5ef20..e7b290112 100644 --- a/plugins/input/postgis/postgis.hpp +++ b/plugins/input/postgis/postgis_datasource.hpp @@ -22,17 +22,17 @@ //$Id: postgis.hpp 44 2005-04-22 18:53:54Z pavlenko $ -#ifndef POSTGIS_HPP -#define POSTGIS_HPP - +#ifndef POSTGIS_DATASOURCE_HPP +#define POSTGIS_DATASOURCE_HPP +// mapnik #include #include -#include #include + +// boost #include #include -#include #include "connection_manager.hpp" #include "resultset.hpp" @@ -48,7 +48,6 @@ using mapnik::query; using mapnik::parameters; using mapnik::coord2d; -//class transcoder; class postgis_datasource : public datasource { static const std::string GEOMETRY_COLUMNS; @@ -98,25 +97,4 @@ class postgis_datasource : public datasource postgis_datasource& operator=(const postgis_datasource&); }; -class postgis_featureset : public mapnik::Featureset -{ - private: - boost::shared_ptr rs_; - bool multiple_geometries_; - unsigned num_attrs_; - boost::scoped_ptr tr_; - mutable int totalGeomSize_; - mutable int feature_id_; - public: - postgis_featureset(boost::shared_ptr const& rs, - std::string const& encoding, - bool multiple_geometries, - unsigned num_attrs); - feature_ptr next(); - ~postgis_featureset(); - private: - postgis_featureset(const postgis_featureset&); - const postgis_featureset& operator=(const postgis_featureset&); -}; - -#endif //POSTGIS_HPP +#endif //POSTGIS_DATASOURCE_HPP diff --git a/plugins/input/postgis/postgisfs.cpp b/plugins/input/postgis/postgis_featureset.cpp similarity index 50% rename from plugins/input/postgis/postgisfs.cpp rename to plugins/input/postgis/postgis_featureset.cpp index e6da85e63..f96214ffd 100644 --- a/plugins/input/postgis/postgisfs.cpp +++ b/plugins/input/postgis/postgis_featureset.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * Copyright (C) 2011 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,18 +20,24 @@ * *****************************************************************************/ -//$Id: postgisfs.cc 34 2005-04-04 13:27:23Z pavlenko $ +//$Id$ -#include -#include +// mapnik #include #include #include #include #include +#include "postgis_featureset.hpp" +#include "resultset.hpp" +#include "cursorresultset.hpp" -#include "postgis.hpp" +// boost +#include +#include +// stl #include +#include using boost::lexical_cast; using boost::bad_lexical_cast; @@ -66,74 +72,74 @@ feature_ptr postgis_featureset::next() for (unsigned pos=1;posgetFieldName(pos); + std::string name = rs_->getFieldName(pos); - if (!rs_->isNull(pos)) - { - const char* buf=rs_->getValue(pos); - int oid = rs_->getTypeOID(pos); + if (!rs_->isNull(pos)) + { + const char* buf=rs_->getValue(pos); + int oid = rs_->getTypeOID(pos); - if (oid==16) //bool - { - boost::put(*feature,name,buf[0] != 0); - } - else if (oid==23) //int4 - { - int val = int4net(buf); - boost::put(*feature,name,val); - } - else if (oid==21) //int2 - { - int val = int2net(buf); - boost::put(*feature,name,val); - } - else if (oid==20) //int8/BigInt - { - int val = int8net(buf); - boost::put(*feature,name,val); - } - else if (oid == 700) // float4 - { - float val; - float4net(val,buf); - boost::put(*feature,name,val); - } - else if (oid == 701) // float8 - { - double val; - float8net(val,buf); - boost::put(*feature,name,val); - } - else if (oid==25 || oid==1043) // text or varchar - { - UnicodeString ustr = tr_->transcode(buf); - boost::put(*feature,name,ustr); - } - else if (oid==1042) - { - UnicodeString ustr = tr_->transcode(trim_copy(string(buf)).c_str()); // bpchar - boost::put(*feature,name,ustr); - } - else if (oid == 1700) // numeric - { - std::string str = mapnik::numeric2string(buf); - try - { - double val = boost::lexical_cast(str); + if (oid==16) //bool + { + boost::put(*feature,name,buf[0] != 0); + } + else if (oid==23) //int4 + { + int val = int4net(buf); boost::put(*feature,name,val); - } - catch (boost::bad_lexical_cast & ex) - { - std::clog << ex.what() << "\n"; - } - } - else - { + } + else if (oid==21) //int2 + { + int val = int2net(buf); + boost::put(*feature,name,val); + } + else if (oid==20) //int8/BigInt + { + int val = int8net(buf); + boost::put(*feature,name,val); + } + else if (oid == 700) // float4 + { + float val; + float4net(val,buf); + boost::put(*feature,name,val); + } + else if (oid == 701) // float8 + { + double val; + float8net(val,buf); + boost::put(*feature,name,val); + } + else if (oid==25 || oid==1043) // text or varchar + { + UnicodeString ustr = tr_->transcode(buf); + boost::put(*feature,name,ustr); + } + else if (oid==1042) + { + UnicodeString ustr = tr_->transcode(trim_copy(std::string(buf)).c_str()); // bpchar + boost::put(*feature,name,ustr); + } + else if (oid == 1700) // numeric + { + std::string str = mapnik::numeric2string(buf); + try + { + double val = boost::lexical_cast(str); + boost::put(*feature,name,val); + } + catch (boost::bad_lexical_cast & ex) + { + std::clog << ex.what() << "\n"; + } + } + else + { #ifdef MAPNIK_DEBUG - std::clog << "Postgis Plugin: uknown OID = " << oid << " FIXME " << std::endl; + std::clog << "Postgis Plugin: uknown OID = " << oid << " FIXME " << std::endl; #endif - } - } + } + } } return feature; } diff --git a/plugins/input/postgis/postgis_featureset.hpp b/plugins/input/postgis/postgis_featureset.hpp new file mode 100644 index 000000000..f436dcc56 --- /dev/null +++ b/plugins/input/postgis/postgis_featureset.hpp @@ -0,0 +1,64 @@ + +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2011 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#ifndef POSTGIS_FEATURESET_HPP +#define POSTGIS_FEATURESET_HPP + +// mapnik +#include +#include +#include + +// boost + +#include + +using mapnik::Featureset; +using mapnik::box2d; +using mapnik::feature_ptr; +using mapnik::transcoder; + +class IResultSet; + +class postgis_featureset : public mapnik::Featureset +{ +private: + boost::shared_ptr rs_; + bool multiple_geometries_; + unsigned num_attrs_; + boost::scoped_ptr tr_; + int totalGeomSize_; + int feature_id_; +public: + postgis_featureset(boost::shared_ptr const& rs, + std::string const& encoding, + bool multiple_geometries, + unsigned num_attrs); + mapnik::feature_ptr next(); + ~postgis_featureset(); +private: + postgis_featureset(const postgis_featureset&); + const postgis_featureset& operator=(const postgis_featureset&); +}; + +#endif // POSTGIS_FEATURESET_HPP diff --git a/plugins/input/postgis/resultset.hpp b/plugins/input/postgis/resultset.hpp index ec0f7daee..25cc20148 100644 --- a/plugins/input/postgis/resultset.hpp +++ b/plugins/input/postgis/resultset.hpp @@ -26,7 +26,10 @@ #ifndef RESULTSET_HPP #define RESULTSET_HPP -#include "connection.hpp" +extern "C" +{ +#include "libpq-fe.h" +} class IResultSet {