2013-05-16 21:03:30 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2021-01-05 15:39:07 +01:00
|
|
|
* Copyright (C) 2021 Artem Pavlenko
|
2013-05-16 21:03:30 +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,
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
// mapnik
|
|
|
|
#include <mapnik/datasource_cache.hpp>
|
2014-07-23 23:02:36 +02:00
|
|
|
#include <mapnik/datasource.hpp>
|
2013-05-16 21:03:30 +02:00
|
|
|
|
|
|
|
#ifdef MAPNIK_STATIC_PLUGINS
|
|
|
|
#include <mapnik/params.hpp>
|
2022-01-29 12:52:23 +01:00
|
|
|
#include <mapnik/datasource_plugin.hpp>
|
2013-05-16 21:03:30 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// stl
|
|
|
|
#include <stdexcept>
|
2015-06-18 11:08:35 +02:00
|
|
|
#include <unordered_map>
|
2013-05-16 21:03:30 +02:00
|
|
|
|
|
|
|
// static plugin linkage
|
|
|
|
#ifdef MAPNIK_STATIC_PLUGINS
|
2022-01-26 10:43:31 +01:00
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_CSV)
|
|
|
|
#include "input/csv/csv_datasource.hpp"
|
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_GDAL)
|
|
|
|
#include "input/gdal/gdal_datasource.hpp"
|
|
|
|
#endif
|
2022-02-02 17:15:55 +01:00
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_GEOBUF)
|
|
|
|
#include "input/geobuf/geobuf_datasource.hpp"
|
|
|
|
#endif
|
2022-01-26 10:43:31 +01:00
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_GEOJSON)
|
|
|
|
#include "input/geojson/geojson_datasource.hpp"
|
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_GEOS)
|
|
|
|
#include "input/geos/geos_datasource.hpp"
|
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_KISMET)
|
|
|
|
#include "input/kismet/kismet_datasource.hpp"
|
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_OCCI)
|
|
|
|
#include "input/occi/occi_datasource.hpp"
|
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_OGR)
|
|
|
|
#include "input/ogr/ogr_datasource.hpp"
|
|
|
|
#endif
|
2022-02-02 17:15:55 +01:00
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_PGRASTER)
|
|
|
|
#include "input/pgraster/pgraster_datasource.hpp"
|
|
|
|
#endif
|
2022-01-26 10:43:31 +01:00
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_OSM)
|
|
|
|
#include "input/osm/osm_datasource.hpp"
|
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_POSTGIS)
|
|
|
|
#include "input/postgis/postgis_datasource.hpp"
|
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_RASTER)
|
|
|
|
#include "input/raster/raster_datasource.hpp"
|
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_RASTERLITE)
|
|
|
|
#include "input/rasterlite/rasterlite_datasource.hpp"
|
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_SHAPE)
|
|
|
|
#include "input/shape/shape_datasource.hpp"
|
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_SQLITE)
|
|
|
|
#include "input/sqlite/sqlite_datasource.hpp"
|
|
|
|
#endif
|
2022-02-02 17:15:55 +01:00
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_TOPOJSON)
|
|
|
|
#include "input/topojson/topojson_datasource.hpp"
|
|
|
|
#endif
|
2013-05-16 21:03:30 +02:00
|
|
|
#endif
|
|
|
|
|
2022-02-02 17:20:29 +01:00
|
|
|
#define REGISTER_STATIC_DATASOURCE_PLUGIN(classname) \
|
2022-02-14 17:34:20 +01:00
|
|
|
{ \
|
|
|
|
auto plugin = std::make_shared<classname>(); \
|
|
|
|
plugin->after_load(); \
|
|
|
|
ds_map.emplace(std::string{classname::kName}, std::move(plugin)); \
|
|
|
|
}
|
2013-05-16 21:03:30 +02:00
|
|
|
namespace mapnik {
|
|
|
|
|
|
|
|
#ifdef MAPNIK_STATIC_PLUGINS
|
2022-02-02 17:20:29 +01:00
|
|
|
|
2013-05-16 21:03:30 +02:00
|
|
|
template<typename T>
|
|
|
|
datasource_ptr ds_generator(parameters const& params)
|
|
|
|
{
|
2013-09-20 15:00:11 +02:00
|
|
|
return std::make_shared<T>(params);
|
2013-05-16 21:03:30 +02:00
|
|
|
}
|
|
|
|
|
2014-11-11 23:42:53 +01:00
|
|
|
typedef datasource_ptr (*ds_generator_ptr)(parameters const& params);
|
2022-01-29 12:52:23 +01:00
|
|
|
using datasource_map = std::unordered_map<std::string, std::shared_ptr<datasource_plugin>>;
|
2013-05-16 21:03:30 +02:00
|
|
|
|
2022-02-02 17:20:29 +01:00
|
|
|
static datasource_map ds_map{};
|
|
|
|
|
|
|
|
void init_datasource_cache_static()
|
2022-02-02 17:15:55 +01:00
|
|
|
{
|
2022-01-26 10:43:31 +01:00
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_CSV)
|
2022-02-02 17:20:29 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(csv_datasource_plugin);
|
2022-01-26 10:43:31 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_GDAL)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(gdal_datasource_plugin);
|
2022-02-02 17:15:55 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_GEOBUF)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(geobuf_datasource_plugin);
|
2022-01-26 10:43:31 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_GEOJSON)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(geojson_datasource_plugin);
|
2022-01-26 10:43:31 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_OCCI)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(occi_datasource_plugin);
|
2022-01-26 10:43:31 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_OGR)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(ogr_datasource_plugin);
|
2022-02-02 17:15:55 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_PGRASTER)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(pgraster_datasource_plugin);
|
2022-01-26 10:43:31 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_OSM)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(osm_datasource_plugin);
|
2022-01-26 10:43:31 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_POSTGIS)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(postgis_datasource_plugin);
|
2022-01-26 10:43:31 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_RASTER)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(raster_datasource_plugin);
|
2022-01-26 10:43:31 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_RASTERLITE)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(rasterlite_datasource_plugin);
|
2022-01-26 10:43:31 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_SHAPE)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(shape_datasource_plugin);
|
2022-01-26 10:43:31 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_SQLITE)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(sqlite_datasource_plugin);
|
2022-02-02 17:15:55 +01:00
|
|
|
#endif
|
|
|
|
#if defined(MAPNIK_STATIC_PLUGIN_TOPOJSON)
|
2022-02-14 17:34:20 +01:00
|
|
|
REGISTER_STATIC_DATASOURCE_PLUGIN(topojson_datasource_plugin);
|
2022-01-26 10:43:31 +01:00
|
|
|
#endif
|
2022-01-29 12:52:23 +01:00
|
|
|
};
|
2013-05-16 21:03:30 +02:00
|
|
|
|
|
|
|
datasource_ptr create_static_datasource(parameters const& params)
|
|
|
|
{
|
2024-04-19 20:45:24 +02:00
|
|
|
const auto type = params.get<std::string>("type");
|
2013-05-16 21:03:30 +02:00
|
|
|
datasource_map::iterator it = ds_map.find(*type);
|
|
|
|
if (it != ds_map.end())
|
|
|
|
{
|
2022-02-14 17:34:20 +01:00
|
|
|
return it->second->create(params);
|
2013-05-16 21:03:30 +02:00
|
|
|
}
|
2022-02-14 17:34:20 +01:00
|
|
|
return datasource_ptr{};
|
2013-05-16 21:03:30 +02:00
|
|
|
}
|
2013-07-23 21:51:22 +02:00
|
|
|
#else
|
|
|
|
datasource_ptr create_static_datasource(parameters const& /*params*/)
|
|
|
|
{
|
|
|
|
return datasource_ptr();
|
|
|
|
}
|
|
|
|
#endif
|
2013-05-16 21:03:30 +02:00
|
|
|
|
|
|
|
std::vector<std::string> get_static_datasource_names()
|
|
|
|
{
|
|
|
|
std::vector<std::string> names;
|
|
|
|
|
|
|
|
#ifdef MAPNIK_STATIC_PLUGINS
|
|
|
|
datasource_map::iterator it = ds_map.begin();
|
|
|
|
while (it != ds_map.end())
|
|
|
|
{
|
|
|
|
names.push_back(it->first);
|
|
|
|
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2022-01-26 10:43:31 +01:00
|
|
|
} // namespace mapnik
|