mapnik/include/mapnik/datasource.hpp

139 lines
4.5 KiB
C++
Raw Normal View History

2006-03-31 12:32:02 +02:00
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
2005-06-14 17:06:59 +02:00
*
2006-03-31 12:32:02 +02:00
* Copyright (C) 2006 Artem Pavlenko
2005-06-14 17:06:59 +02:00
*
2006-03-31 12:32:02 +02:00
* 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,
2005-06-14 17:06:59 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2006-03-31 12:32:02 +02:00
* 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
2005-06-14 17:06:59 +02:00
*
2006-03-31 12:32:02 +02:00
*****************************************************************************/
2005-06-14 17:06:59 +02:00
//$Id: datasource.hpp 43 2005-04-22 18:52:47Z pavlenko $
#ifndef DATASOURCE_HPP
#define DATASOURCE_HPP
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/ctrans.hpp>
#include <mapnik/params.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/query.hpp>
#include <mapnik/feature_layer_desc.hpp>
2007-10-08 20:10:31 +02:00
// boost
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
// stl
#include <map>
#include <string>
namespace mapnik {
typedef MAPNIK_DECL boost::shared_ptr<Feature> feature_ptr;
2006-03-22 16:52:29 +01:00
struct MAPNIK_DECL Featureset
2005-06-14 17:06:59 +02:00
{
virtual feature_ptr next()=0;
2005-06-14 17:06:59 +02:00
virtual ~Featureset() {};
};
typedef MAPNIK_DECL boost::shared_ptr<Featureset> featureset_ptr;
2005-06-14 17:06:59 +02:00
2006-03-22 16:52:29 +01:00
class MAPNIK_DECL datasource_exception : public std::exception
2005-06-14 17:06:59 +02:00
{
private:
std::string message_;
2005-06-14 17:06:59 +02:00
public:
datasource_exception(const std::string& message=std::string("no reason"))
:message_(message) {}
2005-06-14 17:06:59 +02:00
~datasource_exception() throw() {}
virtual const char* what() const throw()
{
return message_.c_str();
}
2005-06-14 17:06:59 +02:00
};
class MAPNIK_DECL datasource : private boost::noncopyable
2005-06-14 17:06:59 +02:00
{
public:
enum datasource_t {
Vector,
Raster
};
datasource (parameters const& params)
: params_(params) {}
/*!
* @brief Get the configuration parameters of the data source.
*
* These vary depending on the type of data source.
*
* @return The configuration parameters of the data source.
*/
parameters const& params() const
{
return params_;
}
/*!
* @brief Get the type of the datasource
* @return The type of the datasource (Vector or Raster)
*/
virtual int type() const=0;
virtual featureset_ptr features(const query& q) const=0;
virtual featureset_ptr features_at_point(coord2d const& pt) const=0;
virtual Envelope<double> envelope() const=0;
virtual layer_descriptor get_descriptor() const=0;
virtual ~datasource() {};
protected:
parameters params_;
2005-06-14 17:06:59 +02:00
};
typedef std::string datasource_name();
typedef datasource* create_ds(const parameters& params);
2005-06-14 17:06:59 +02:00
typedef void destroy_ds(datasource *ds);
class datasource_deleter
2005-06-14 17:06:59 +02:00
{
public:
void operator() (datasource* ds)
{
delete ds;
}
2005-06-14 17:06:59 +02:00
};
typedef boost::shared_ptr<datasource> datasource_ptr;
#define DATASOURCE_PLUGIN(classname) \
extern "C" MAPNIK_EXP std::string datasource_name() \
{ \
return classname::name(); \
} \
extern "C" MAPNIK_EXP datasource* create(const parameters &params) \
{ \
return new classname(params); \
} \
extern "C" MAPNIK_EXP void destroy(datasource *ds) \
{ \
delete ds; \
} \
//
2005-06-14 17:06:59 +02:00
}
#endif //DATASOURCE_HPP