![]() |
C++ API DOCUMENTATION |
00001 /***************************************************************************** 00002 * 00003 * This file is part of Mapnik (c++ mapping toolkit) 00004 * 00005 * Copyright (C) 2006 Artem Pavlenko 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 * 00021 *****************************************************************************/ 00022 00023 //$Id: datasource.hpp 43 2005-04-22 18:52:47Z pavlenko $ 00024 00025 #ifndef DATASOURCE_HPP 00026 #define DATASOURCE_HPP 00027 // mapnik 00028 #include <mapnik/config.hpp> 00029 #include <mapnik/ctrans.hpp> 00030 #include <mapnik/params.hpp> 00031 #include <mapnik/feature.hpp> 00032 #include <mapnik/query.hpp> 00033 #include <mapnik/feature_layer_desc.hpp> 00034 // boost 00035 #include <boost/utility.hpp> 00036 #include <boost/shared_ptr.hpp> 00037 // stl 00038 #include <map> 00039 #include <string> 00040 00041 namespace mapnik { 00042 typedef MAPNIK_DECL boost::shared_ptr<Feature> feature_ptr; 00043 00044 struct MAPNIK_DECL Featureset 00045 { 00046 virtual feature_ptr next()=0; 00047 virtual ~Featureset() {}; 00048 }; 00049 00050 typedef MAPNIK_DECL boost::shared_ptr<Featureset> featureset_ptr; 00051 00052 class MAPNIK_DECL datasource_exception : public std::exception 00053 { 00054 private: 00055 std::string message_; 00056 public: 00057 datasource_exception(const std::string& message=std::string("no reason")) 00058 :message_(message) {} 00059 00060 ~datasource_exception() throw() {} 00061 virtual const char* what() const throw() 00062 { 00063 return message_.c_str(); 00064 } 00065 }; 00066 00067 class MAPNIK_DECL datasource : private boost::noncopyable 00068 { 00069 public: 00070 enum datasource_t { 00071 Vector, 00072 Raster 00073 }; 00074 00075 datasource (parameters const& params) 00076 : params_(params) {} 00077 00078 parameters const& params() const 00079 { 00080 return params_; 00081 } 00082 00083 virtual int type() const=0; 00084 virtual featureset_ptr features(const query& q) const=0; 00085 virtual featureset_ptr features_at_point(coord2d const& pt) const=0; 00086 virtual Envelope<double> envelope() const=0; 00087 virtual layer_descriptor get_descriptor() const=0; 00088 virtual ~datasource() {}; 00089 protected: 00090 parameters params_; 00091 }; 00092 00093 typedef std::string datasource_name(); 00094 typedef datasource* create_ds(const parameters& params); 00095 typedef void destroy_ds(datasource *ds); 00096 00097 00098 class datasource_deleter 00099 { 00100 public: 00101 void operator() (datasource* ds) 00102 { 00103 delete ds; 00104 } 00105 }; 00106 00107 typedef boost::shared_ptr<datasource> datasource_ptr; 00108 00109 00110 #define DATASOURCE_PLUGIN(classname) \ 00111 extern "C" MAPNIK_EXP std::string datasource_name() \ 00112 { \ 00113 return classname::name(); \ 00114 } \ 00115 extern "C" MAPNIK_EXP datasource* create(const parameters ¶ms) \ 00116 { \ 00117 return new classname(params); \ 00118 } \ 00119 extern "C" MAPNIK_EXP void destroy(datasource *ds) \ 00120 { \ 00121 delete ds; \ 00122 } \ 00123 // 00124 } 00125 00126 #endif //DATASOURCE_HPP