mapnik/include/mapnik/datasource.hpp

159 lines
4.7 KiB
C++
Raw Normal View History

2006-03-31 10:32:02 +00:00
/*****************************************************************************
2012-02-02 01:53:35 +00:00
*
2006-03-31 10:32:02 +00:00
* This file is part of Mapnik (c++ mapping toolkit)
2005-06-14 15:06:59 +00:00
*
2014-11-20 14:25:50 +00:00
* Copyright (C) 2014 Artem Pavlenko
2005-06-14 15:06:59 +00:00
*
2006-03-31 10:32:02 +00: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 15:06:59 +00:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2006-03-31 10:32:02 +00: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 15:06:59 +00:00
*
2006-03-31 10:32:02 +00:00
*****************************************************************************/
2005-06-14 15:06:59 +00:00
#ifndef MAPNIK_DATASOURCE_HPP
#define MAPNIK_DATASOURCE_HPP
2005-06-14 15:06:59 +00:00
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/params.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/query.hpp>
2014-07-23 06:57:06 +00:00
#include <mapnik/featureset.hpp>
#include <mapnik/feature_layer_desc.hpp>
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/feature_style_processor_context.hpp>
#include <mapnik/datasource_geometry_type.hpp>
2007-10-08 18:10:31 +00:00
// stl
#include <map>
#include <string>
#include <memory>
namespace mapnik {
2012-01-15 06:35:40 +00:00
2010-06-02 11:03:30 +00:00
class MAPNIK_DECL datasource_exception : public std::exception
{
public:
datasource_exception(std::string const& message)
2012-03-28 19:59:40 +00:00
: message_(message)
{
}
~datasource_exception() throw()
{
}
2005-06-14 15:06:59 +00:00
2010-06-02 11:03:30 +00:00
virtual const char* what() const throw()
2005-06-14 15:06:59 +00:00
{
2010-06-02 11:03:30 +00:00
return message_.c_str();
}
2012-03-28 19:59:40 +00:00
private:
std::string message_;
2010-06-02 11:03:30 +00:00
};
2012-02-02 01:53:35 +00:00
class MAPNIK_DECL datasource : private util::noncopyable
2010-06-02 11:03:30 +00:00
{
2012-01-15 06:35:40 +00:00
public:
2014-12-02 06:20:18 +00:00
enum datasource_t : std::uint8_t {
2010-06-02 11:03:30 +00:00
Vector,
Raster
};
datasource (parameters const& params)
2012-12-17 21:12:31 +00:00
: params_(params) {}
2012-02-02 01:53:35 +00:00
2010-06-02 11:03:30 +00:00
/*!
* @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
{
2012-12-17 21:12:31 +00:00
return params_;
2010-06-02 11:03:30 +00:00
}
2012-02-02 01:53:35 +00:00
parameters & params()
{
return params_;
}
bool operator==(datasource const& rhs) const
{
return params_ == rhs.params();
}
bool operator!=(datasource const& rhs) const
{
return !(*this == rhs);
}
2010-06-02 11:03:30 +00:00
/*!
* @brief Get the type of the datasource
* @return The type of the datasource (Vector or Raster)
*/
2012-03-28 19:59:40 +00:00
virtual datasource_t type() const = 0;
virtual processor_context_ptr get_context(feature_style_context_map&) const { return processor_context_ptr(); }
virtual featureset_ptr features_with_context(query const& q, processor_context_ptr /*ctx*/) const
{
// default implementation without context use features method
return features(q);
}
virtual boost::optional<datasource_geometry_t> get_geometry_type() const = 0;
2012-09-03 17:02:39 +00:00
virtual featureset_ptr features(query const& q) const = 0;
virtual featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const = 0;
2012-03-28 19:59:40 +00:00
virtual box2d<double> envelope() const = 0;
virtual layer_descriptor get_descriptor() const = 0;
virtual ~datasource() {}
2010-06-02 11:03:30 +00:00
protected:
2012-12-17 21:12:31 +00:00
parameters params_;
2010-06-02 11:03:30 +00:00
};
2012-02-02 01:53:35 +00:00
using datasource_name = const char* (*)();
using create_ds = datasource* (*) (parameters const&);
using destroy_ds = void (*) (datasource *);
2005-06-14 15:06:59 +00:00
2010-06-02 11:03:30 +00:00
class datasource_deleter
{
public:
void operator() (datasource* ds)
2005-06-14 15:06:59 +00:00
{
2010-06-02 11:03:30 +00:00
delete ds;
}
};
2005-06-14 15:06:59 +00:00
using datasource_ptr = std::shared_ptr<datasource>;
2012-02-02 01:53:35 +00:00
#ifdef MAPNIK_STATIC_PLUGINS
#define DATASOURCE_PLUGIN(classname)
#else
#define DATASOURCE_PLUGIN(classname) \
extern "C" MAPNIK_EXP const char * datasource_name() \
{ \
return classname::name(); \
} \
extern "C" MAPNIK_EXP datasource* create(parameters const& params) \
{ \
return new classname(params); \
} \
extern "C" MAPNIK_EXP void destroy(datasource *ds) \
{ \
delete ds; \
}
#endif
2005-06-14 15:06:59 +00:00
}
#endif // MAPNIK_DATASOURCE_HPP