00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef DATASOURCE_HPP
00026 #define DATASOURCE_HPP
00027
00028 #include <map>
00029 #include <string>
00030
00031 #include <boost/utility.hpp>
00032 #include <boost/shared_ptr.hpp>
00033
00034 #include <mapnik/config.hpp>
00035 #include <mapnik/ctrans.hpp>
00036 #include <mapnik/params.hpp>
00037 #include <mapnik/feature.hpp>
00038 #include <mapnik/query.hpp>
00039 #include <mapnik/feature_layer_desc.hpp>
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 const std::string message_;
00056 public:
00057 datasource_exception(const std::string& message=std::string())
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