diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 000000000..2bdda1dd4 --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,34 @@ +# This CITATION.cff file was generated with cffinit. +# Visit https://bit.ly/cffinit to generate yours today! + +cff-version: 1.2.0 +title: mapnik +message: >- + If you use this software, please cite it using the + metadata from this file. +type: software +authors: + - given-names: Artem + family-names: Pavlenko +identifiers: + - type: url + value: 'https://github.com/mapnik/mapnik' + description: GitHub Repository + - type: swh + value: >- + swh:1:dir:3f5758e17e9d54016ca694268da68cf6856fab58 + description: Software Archive +repository-code: 'https://github.com/mapnik/mapnik' +url: 'https://mapnik.org/' +abstract: >- + Mapnik is an open source toolkit for developing + mapping applications. At the core is a C++ shared + library providing algorithms and patterns for + spatial data access and visualization. +keywords: + - mapping + - gis + - cartography + - beautiful-maps + - rendering +license: LGPL-2.1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d76303d2..a9be165f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,10 +159,12 @@ if(harfbuzz_FOUND) message(STATUS "Found harfbuzz native cmake") list(APPEND MAPNIK_OPTIONAL_LIBS harfbuzz::harfbuzz) else() - # we use our "own" FindHarfBuzz. See https://github.com/mapnik/mapnik/pull/4191#issuecomment-874728157 for more details - message(STATUS "Fallback to FindHarfBuzz") - mapnik_find_package(HarfBuzz ${HARFBUZZ_MIN_VERSION} REQUIRED COMPONENTS ICU) - list(APPEND MAPNIK_OPTIONAL_LIBS HarfBuzz::HarfBuzz HarfBuzz::ICU) + # Use pkg-config when harfbuzz is not found. + # It might be possible that in future version harfbuzz could only be found via pkg-config. + # harfbuzz related discussion: https://github.com/harfbuzz/harfbuzz/issues/2653 + message(STATUS "harfbuzz not found via cmake. Searching via pkg-config...") + pkg_check_modules(harfbuzz REQUIRED IMPORTED_TARGET harfbuzz>=${HARFBUZZ_MIN_VERSION}) + list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::harfbuzz) endif() if(USE_EXTERNAL_MAPBOX_GEOMETRY) @@ -306,7 +308,7 @@ endif() if(USE_PROJ) #https://proj.org/development/cmake.html - mapnik_find_package(PROJ ${PROJ_MIN_VERSION} QUIET) + mapnik_find_package(PROJ QUIET) # currently the cmake files are not installed, when installing proj via apt-get. So search via pkg-config if(NOT PROJ_FOUND) message(STATUS "PROJ not found via FindPROJ. Searching via pkg-config...") @@ -317,6 +319,9 @@ if(USE_PROJ) set(PROJ_VERSION_PATCH "${CMAKE_MATCH_3}") list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::PROJ) else() + if(PROJ_VERSION VERSION_LESS PROJ_MIN_VERSION) + message(FATAL_ERROR "Proj needs to be at least version ${PROJ_MIN_VERSION}") + endif() list(APPEND MAPNIK_OPTIONAL_LIBS ${PROJ_LIBRARIES}) list(APPEND MAPNIK_OPTIONAL_LIBS_INCLUDE $) endif() diff --git a/CMakePresets.json b/CMakePresets.json index dbf9dac33..cb8f774de 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -9,15 +9,15 @@ { "name": "use-ninja", "hidden": true, - "generator": "Ninja" + "generator": "Ninja", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } }, { "name": "default-build-dir", "hidden": true, - "binaryDir": "${sourceDir}/build/${presetName}", - "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" - } + "binaryDir": "${sourceDir}/build/${presetName}" }, { "name": "debug-build", @@ -29,6 +29,15 @@ "USE_LOG_SEVERITY": "0" } }, + { + "name": "release-with-debug-build", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "USE_DEBUG_OUTPUT": "OFF", + "USE_LOG": "OFF" + } + }, { "name": "release-build", "hidden": true, @@ -191,5 +200,18 @@ "name": "linux-gcc-release", "configurePreset": "linux-gcc-release" } + ], + "testPresets": [ + { + "name": "test-default", + "hidden": true, + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": false + } + } ] } diff --git a/cmake/FindHarfBuzz.cmake b/cmake/FindHarfBuzz.cmake deleted file mode 100644 index a0296f321..000000000 --- a/cmake/FindHarfBuzz.cmake +++ /dev/null @@ -1,187 +0,0 @@ -# Copyright (c) 2012, Intel Corporation -# Copyright (c) 2019 Sony Interactive Entertainment Inc. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# * Neither the name of Intel Corporation nor the names of its contributors may -# be used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -# Try to find Harfbuzz include and library directories. -# -# After successful discovery, this will set for inclusion where needed: -# HarfBuzz_INCLUDE_DIRS - containg the HarfBuzz headers -# HarfBuzz_LIBRARIES - containg the HarfBuzz library - -#[=======================================================================[.rst: -FindHarfBuzz --------------- - -Find HarfBuzz headers and libraries. - -Imported Targets -^^^^^^^^^^^^^^^^ - -``HarfBuzz::HarfBuzz`` - The HarfBuzz library, if found. - -``HarfBuzz::ICU`` - The HarfBuzz ICU library, if found. - -Result Variables -^^^^^^^^^^^^^^^^ - -This will define the following variables in your project: - -``HarfBuzz_FOUND`` - true if (the requested version of) HarfBuzz is available. -``HarfBuzz_VERSION`` - the version of HarfBuzz. -``HarfBuzz_LIBRARIES`` - the libraries to link against to use HarfBuzz. -``HarfBuzz_INCLUDE_DIRS`` - where to find the HarfBuzz headers. -``HarfBuzz_COMPILE_OPTIONS`` - this should be passed to target_compile_options(), if the - target is not used for linking - -#]=======================================================================] - -find_package(PkgConfig QUIET) -pkg_check_modules(PC_HARFBUZZ QUIET harfbuzz) -set(HarfBuzz_COMPILE_OPTIONS ${PC_HARFBUZZ_CFLAGS_OTHER}) -set(HarfBuzz_VERSION ${PC_HARFBUZZ_CFLAGS_VERSION}) - -find_path(HarfBuzz_INCLUDE_DIR - NAMES hb.h - HINTS ${PC_HARFBUZZ_INCLUDEDIR} ${PC_HARFBUZZ_INCLUDE_DIRS} - PATH_SUFFIXES harfbuzz -) - -find_library(HarfBuzz_LIBRARY - NAMES ${HarfBuzz_NAMES} harfbuzz - HINTS ${PC_HARFBUZZ_LIBDIR} ${PC_HARFBUZZ_LIBRARY_DIRS} -) - -if (HarfBuzz_INCLUDE_DIR AND NOT HarfBuzz_VERSION) - if (EXISTS "${HarfBuzz_INCLUDE_DIR}/hb-version.h") - file(READ "${HarfBuzz_INCLUDE_DIR}/hb-version.h" _harfbuzz_version_content) - - string(REGEX MATCH "#define +HB_VERSION_STRING +\"([0-9]+\.[0-9]+\.[0-9]+)\"" _dummy "${_harfbuzz_version_content}") - set(HarfBuzz_VERSION "${CMAKE_MATCH_1}") - endif () -endif () - -if ("${HarfBuzz_FIND_VERSION}" VERSION_GREATER "${HarfBuzz_VERSION}") - message(FATAL_ERROR "Required version (" ${HarfBuzz_FIND_VERSION} ") is higher than found version (" ${HarfBuzz_VERSION} ")") -endif () - -# Find components -if (HarfBuzz_INCLUDE_DIR AND HarfBuzz_LIBRARY) - set(_HarfBuzz_REQUIRED_LIBS_FOUND ON) - set(HarfBuzz_LIBS_FOUND "HarfBuzz (required): ${HarfBuzz_LIBRARY}") -else () - set(_HarfBuzz_REQUIRED_LIBS_FOUND OFF) - set(HarfBuzz_LIBS_NOT_FOUND "HarfBuzz (required)") -endif () - -if ("ICU" IN_LIST HarfBuzz_FIND_COMPONENTS) - pkg_check_modules(PC_HARFBUZZ_ICU QUIET harfbuzz-icu) - set(HarfBuzz_ICU_COMPILE_OPTIONS ${PC_HARFBUZZ_ICU_CFLAGS_OTHER}) - - find_path(HarfBuzz_ICU_INCLUDE_DIR - NAMES hb-icu.h - HINTS ${PC_HARFBUZZ_ICU_INCLUDEDIR} ${PC_HARFBUZZ_ICU_INCLUDE_DIRS} - PATH_SUFFIXES harfbuzz - ) - - find_library(HarfBuzz_ICU_LIBRARY - NAMES ${HarfBuzz_ICU_NAMES} harfbuzz-icu - HINTS ${PC_HARFBUZZ_ICU_LIBDIR} ${PC_HARFBUZZ_ICU_LIBRARY_DIRS} - ) - - if (HarfBuzz_ICU_LIBRARY) - if (HarfBuzz_FIND_REQUIRED_ICU) - list(APPEND HarfBuzz_LIBS_FOUND "ICU (required): ${HarfBuzz_ICU_LIBRARY}") - else () - list(APPEND HarfBuzz_LIBS_FOUND "ICU (optional): ${HarfBuzz_ICU_LIBRARY}") - endif () - else () - if (HarfBuzz_FIND_REQUIRED_ICU) - set(_HarfBuzz_REQUIRED_LIBS_FOUND OFF) - list(APPEND HarfBuzz_LIBS_NOT_FOUND "ICU (required)") - else () - list(APPEND HarfBuzz_LIBS_NOT_FOUND "ICU (optional)") - endif () - endif () -endif () - -if (NOT HarfBuzz_FIND_QUIETLY) - if (HarfBuzz_LIBS_FOUND) - message(STATUS "Found the following HarfBuzz libraries:") - foreach (found ${HarfBuzz_LIBS_FOUND}) - message(STATUS " ${found}") - endforeach () - endif () - if (HarfBuzz_LIBS_NOT_FOUND) - message(STATUS "The following HarfBuzz libraries were not found:") - foreach (found ${HarfBuzz_LIBS_NOT_FOUND}) - message(STATUS " ${found}") - endforeach () - endif () -endif () - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(HarfBuzz - FOUND_VAR HarfBuzz_FOUND - REQUIRED_VARS HarfBuzz_INCLUDE_DIR HarfBuzz_LIBRARY _HarfBuzz_REQUIRED_LIBS_FOUND - VERSION_VAR HarfBuzz_VERSION -) - -if (HarfBuzz_LIBRARY AND NOT TARGET HarfBuzz::HarfBuzz) - add_library(HarfBuzz::HarfBuzz UNKNOWN IMPORTED GLOBAL) - set_target_properties(HarfBuzz::HarfBuzz PROPERTIES - IMPORTED_LOCATION "${HarfBuzz_LIBRARY}" - INTERFACE_COMPILE_OPTIONS "${HarfBuzz_COMPILE_OPTIONS}" - INTERFACE_INCLUDE_DIRECTORIES "${HarfBuzz_INCLUDE_DIR}" - ) -endif () - -if (HarfBuzz_ICU_LIBRARY AND NOT TARGET HarfBuzz::ICU) - add_library(HarfBuzz::ICU UNKNOWN IMPORTED GLOBAL) - set_target_properties(HarfBuzz::ICU PROPERTIES - IMPORTED_LOCATION "${HarfBuzz_ICU_LIBRARY}" - INTERFACE_COMPILE_OPTIONS "${HarfBuzz_ICU_COMPILE_OPTIONS}" - INTERFACE_INCLUDE_DIRECTORIES "${HarfBuzz_ICU_INCLUDE_DIR}" - ) -endif () - -mark_as_advanced( - HarfBuzz_INCLUDE_DIR - HarfBuzz_ICU_INCLUDE_DIR - HarfBuzz_LIBRARY - HarfBuzz_ICU_LIBRARY -) - -if (HarfBuzz_FOUND) - set(HarfBuzz_LIBRARIES ${HarfBuzz_LIBRARY} ${HarfBuzz_ICU_LIBRARY}) - set(HarfBuzz_INCLUDE_DIRS ${HarfBuzz_INCLUDE_DIR} ${HarfBuzz_ICU_INCLUDE_DIR}) -endif () diff --git a/cmake/MapnikExport.cmake b/cmake/MapnikExport.cmake index 90711ab28..5d63f0050 100644 --- a/cmake/MapnikExport.cmake +++ b/cmake/MapnikExport.cmake @@ -27,7 +27,6 @@ install( FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindCairo.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindWebP.cmake" - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindHarfBuzz.cmake" DESTINATION ${MAPNIK_CMAKE_DIR}/Modules ) diff --git a/include/mapnik/make_unique.hpp b/include/mapnik/make_unique.hpp deleted file mode 100644 index 08324f84d..000000000 --- a/include/mapnik/make_unique.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2021 Artem Pavlenko - * - * 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 - * - *****************************************************************************/ - -#ifndef MAPNIK_MAKE_UNIQUE_HPP -#define MAPNIK_MAKE_UNIQUE_HPP - -// http://stackoverflow.com/questions/14131454/visual-studio-2012-cplusplus-and-c-11 -#if defined(_MSC_VER) && _MSC_VER < 1800 || !defined(_MSC_VER) && __cplusplus <= 201103L - -#include - -namespace std { - -// C++14 backfill from http://herbsutter.com/gotw/_102/ -template -inline std::unique_ptr make_unique(Args&& ...args) { - return std::unique_ptr(new T(std::forward(args)...)); -} - -} -#endif - -#endif // MAPNIK_MAKE_UNIQUE_HPP diff --git a/include/mapnik/mapped_memory_cache.hpp b/include/mapnik/mapped_memory_cache.hpp index 515f1fdce..132d372c4 100644 --- a/include/mapnik/mapped_memory_cache.hpp +++ b/include/mapnik/mapped_memory_cache.hpp @@ -54,6 +54,14 @@ class MAPNIK_DECL mapped_memory_cache : std::unordered_map cache_; public: bool insert(std::string const& key, mapped_region_ptr); + /** + * @brief removes the resource identified by key from the cache, if exists + * + * @param key unique identifier for the resource + * @return true if the resource was removed + * @return false if the resource was not removed or wasn't in the cache + */ + bool remove(std::string const& key); boost::optional find(std::string const& key, bool update_cache = false); void clear(); }; diff --git a/include/mapnik/pool.hpp b/include/mapnik/pool.hpp index 85dfbb666..66f3e29e5 100644 --- a/include/mapnik/pool.hpp +++ b/include/mapnik/pool.hpp @@ -75,7 +75,7 @@ public: typename ContType::iterator itr=pool_.begin(); while ( itr!=pool_.end()) { - if (!itr->unique()) + if (itr->use_count() > 1) { ++itr; } diff --git a/include/mapnik/quad_tree.hpp b/include/mapnik/quad_tree.hpp index e0cb2d58a..86a79b9ce 100644 --- a/include/mapnik/quad_tree.hpp +++ b/include/mapnik/quad_tree.hpp @@ -26,7 +26,6 @@ // mapnik #include #include -#include // stl #include diff --git a/include/mapnik/util/file_io.hpp b/include/mapnik/util/file_io.hpp index 8bb39f1fb..8c7a34c36 100644 --- a/include/mapnik/util/file_io.hpp +++ b/include/mapnik/util/file_io.hpp @@ -24,7 +24,6 @@ #define MAPNIK_FILE_IO_HPP // mapnik -#include #include #include diff --git a/include/mapnik/util/geometry_to_wkb.hpp b/include/mapnik/util/geometry_to_wkb.hpp index bd52f7bd9..cb3193807 100644 --- a/include/mapnik/util/geometry_to_wkb.hpp +++ b/include/mapnik/util/geometry_to_wkb.hpp @@ -25,7 +25,6 @@ // mapnik #include -#include #include #include #include diff --git a/include/mapnik/util/mapped_memory_file.hpp b/include/mapnik/util/mapped_memory_file.hpp new file mode 100644 index 000000000..dae7260d8 --- /dev/null +++ b/include/mapnik/util/mapped_memory_file.hpp @@ -0,0 +1,78 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2021 Artem Pavlenko + * + * 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 + * + *****************************************************************************/ + +#ifndef MAPNIK_MEMORY_MAPPED_FILE_HPP +#define MAPNIK_MEMORY_MAPPED_FILE_HPP + +#include +#include + +#if defined(MAPNIK_MEMORY_MAPPED_FILE) +#include +#include +#include +#else +#include +#endif + +#include + +namespace mapnik { namespace util { + +/** + * @brief memory mapped file abstraction. Implementation depends on MAPNIK_MEMORY_MAPPED_FILE. + * Might be a simple file wrapper, if MAPNIK_MEMORY_MAPPED_FILE=0 + * + */ +class MAPNIK_DECL mapped_memory_file : public noncopyable { + public: +#ifdef MAPNIK_MEMORY_MAPPED_FILE + using file_source_type = boost::interprocess::ibufferstream; +#else + using file_source_type = std::ifstream; +#endif + + public: + mapped_memory_file(); + explicit mapped_memory_file(std::string const& file_name); + virtual ~mapped_memory_file(); + + file_source_type& file(); + bool is_open() const; + void skip(std::streampos bytes); + + /** + * @brief deletes the file identified by file_name. Might also remove the file from any caches. + */ + static void deleteFile(std::string const& file_name); + protected: + const std::string file_name_; +#ifdef MAPNIK_MEMORY_MAPPED_FILE + mapnik::mapped_region_ptr mapped_region_; +#endif + file_source_type file_; +}; + + +} } + +#endif diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index 9ae7d755a..ed6bbb12d 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #if defined(MAPNIK_MEMORY_MAPPED_FILE) @@ -54,6 +53,7 @@ MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_POP #include #endif +#include // stl #include @@ -121,35 +121,8 @@ csv_datasource::csv_datasource(parameters const& params) } else { -#if defined (MAPNIK_MEMORY_MAPPED_FILE) - using file_source_type = boost::interprocess::ibufferstream; - file_source_type in; - mapnik::mapped_region_ptr mapped_region; - boost::optional memory = - mapnik::mapped_memory_cache::instance().find(filename_, true); - if (memory) - { - mapped_region = *memory; - in.buffer(static_cast(mapped_region->get_address()),mapped_region->get_size()); - } - else - { - throw std::runtime_error("could not create file mapping for " + filename_); - } -#elif defined (_WIN32) - std::ifstream in(mapnik::utf8_to_utf16(filename_),std::ios_base::in | std::ios_base::binary); - if (!in.is_open()) - { - throw mapnik::datasource_exception("CSV Plugin: could not open: '" + filename_ + "'"); - } -#else - std::ifstream in(filename_.c_str(),std::ios_base::in | std::ios_base::binary); - if (!in.is_open()) - { - throw mapnik::datasource_exception("CSV Plugin: could not open: '" + filename_ + "'"); - } -#endif - parse_csv(in); + mapnik::util::mapped_memory_file in_file{filename_}; + parse_csv(in_file.file()); if (has_disk_index_ && !extent_initialized_) { diff --git a/plugins/input/geobuf/geobuf_datasource.cpp b/plugins/input/geobuf/geobuf_datasource.cpp index 7866d099d..3dbdc93fc 100644 --- a/plugins/input/geobuf/geobuf_datasource.cpp +++ b/plugins/input/geobuf/geobuf_datasource.cpp @@ -43,7 +43,6 @@ #include #include #include -#include #include using mapnik::datasource; diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index ad83befd1..62952e9ce 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -48,7 +48,6 @@ MAPNIK_DISABLE_WARNING_POP #include #include #include -#include #include #include #include diff --git a/plugins/input/shape/dbfile.cpp b/plugins/input/shape/dbfile.cpp index 5bc46c3e2..c57fbfbf4 100644 --- a/plugins/input/shape/dbfile.cpp +++ b/plugins/input/shape/dbfile.cpp @@ -51,31 +51,12 @@ dbf_file::dbf_file() record_(0) {} dbf_file::dbf_file(std::string const& file_name) - :num_records_(0), + :mapped_memory_file{file_name}, + num_records_(0), num_fields_(0), record_length_(0), -#if defined(MAPNIK_MEMORY_MAPPED_FILE) - file_(), -#elif defined(_WIN32) - file_(mapnik::utf8_to_utf16(file_name), std::ios::in | std::ios::binary), -#else - file_(file_name.c_str() ,std::ios::in | std::ios::binary), -#endif record_(0) { - -#if defined(MAPNIK_MEMORY_MAPPED_FILE) - boost::optional memory = mapnik::mapped_memory_cache::instance().find(file_name,true); - if (memory) - { - mapped_region_ = *memory; - file_.buffer(static_cast((*memory)->get_address()),(*memory)->get_size()); - } - else - { - throw std::runtime_error("could not create file mapping for "+file_name); - } -#endif if (file_) { read_header(); @@ -88,16 +69,6 @@ dbf_file::~dbf_file() ::operator delete(record_); } - -bool dbf_file::is_open() -{ -#if defined(MAPNIK_MEMORY_MAPPED_FILE) - return (file_.buffer().second > 0); -#else - return file_.is_open(); -#endif -} - int dbf_file::num_records() const { return num_records_; @@ -274,8 +245,3 @@ int dbf_file::read_int() mapnik::read_int32_ndr(b,val); return val; } - -void dbf_file::skip(int bytes) -{ - file_.seekg(bytes,std::ios::cur); -} diff --git a/plugins/input/shape/dbfile.hpp b/plugins/input/shape/dbfile.hpp index bb16f9f3c..ff2cce4a5 100644 --- a/plugins/input/shape/dbfile.hpp +++ b/plugins/input/shape/dbfile.hpp @@ -28,14 +28,7 @@ #include #include -#if defined(MAPNIK_MEMORY_MAPPED_FILE) -#include -#include -MAPNIK_DISABLE_WARNING_PUSH -#include -#include -MAPNIK_DISABLE_WARNING_POP -#endif +#include // stl #include @@ -54,25 +47,18 @@ struct field_descriptor }; -class dbf_file : private mapnik::util::noncopyable +class dbf_file : public mapnik::util::mapped_memory_file { private: int num_records_; int num_fields_; std::size_t record_length_; std::vector fields_; -#if defined(MAPNIK_MEMORY_MAPPED_FILE) - boost::interprocess::ibufferstream file_; - mapnik::mapped_region_ptr mapped_region_; -#else - std::ifstream file_; -#endif char* record_; public: dbf_file(); dbf_file(std::string const& file_name); ~dbf_file(); - bool is_open(); int num_records() const; int num_fields() const; field_descriptor const& descriptor(int col) const; @@ -83,7 +69,6 @@ private: void read_header(); int read_short(); int read_int(); - void skip(int bytes); }; #endif //DBFFILE_HPP diff --git a/plugins/input/shape/shape_datasource.cpp b/plugins/input/shape/shape_datasource.cpp index 1065710eb..21a8d5867 100644 --- a/plugins/input/shape/shape_datasource.cpp +++ b/plugins/input/shape/shape_datasource.cpp @@ -33,7 +33,6 @@ MAPNIK_DISABLE_WARNING_POP // mapnik #include -#include #include #include #include diff --git a/plugins/input/shape/shape_io.cpp b/plugins/input/shape/shape_io.cpp index 92dfee667..4934089f8 100644 --- a/plugins/input/shape/shape_io.cpp +++ b/plugins/input/shape/shape_io.cpp @@ -24,7 +24,6 @@ // mapnik #include -#include #include #include #include diff --git a/plugins/input/shape/shapefile.hpp b/plugins/input/shape/shapefile.hpp index 72ad4be7f..cf233de1a 100644 --- a/plugins/input/shape/shapefile.hpp +++ b/plugins/input/shape/shapefile.hpp @@ -35,16 +35,12 @@ #include #if defined(MAPNIK_MEMORY_MAPPED_FILE) -#include -MAPNIK_DISABLE_WARNING_PUSH -#include #include -#include -MAPNIK_DISABLE_WARNING_POP -#include #endif #include +#include + using mapnik::box2d; using mapnik::read_int32_ndr; using mapnik::read_int32_xdr; @@ -143,64 +139,24 @@ struct shape_record std::size_t length() {return size;} }; -class shape_file : mapnik::util::noncopyable +class shape_file : public mapnik::util::mapped_memory_file { public: - #if defined(MAPNIK_MEMORY_MAPPED_FILE) - using file_source_type = boost::interprocess::ibufferstream; using record_type = shape_record; - mapnik::mapped_region_ptr mapped_region_; #else - using file_source_type = std::ifstream; using record_type = shape_record; #endif - file_source_type file_; - shape_file() {} - shape_file(std::string const& file_name) : -#if defined(MAPNIK_MEMORY_MAPPED_FILE) - file_() -#elif defined(_WIN32) - file_(mapnik::utf8_to_utf16(file_name), std::ios::in | std::ios::binary) -#else - file_(file_name.c_str(), std::ios::in | std::ios::binary) -#endif + shape_file(std::string const& file_name) + : mapped_memory_file(file_name) { -#if defined(MAPNIK_MEMORY_MAPPED_FILE) - boost::optional memory = - mapnik::mapped_memory_cache::instance().find(file_name,true); - - if (memory) - { - mapped_region_ = *memory; - file_.buffer(static_cast(mapped_region_->get_address()),mapped_region_->get_size()); - } - else - { - throw std::runtime_error("could not create file mapping for "+file_name); - } -#endif } ~shape_file() {} - inline file_source_type& file() - { - return file_; - } - - inline bool is_open() const - { -#if defined(MAPNIK_MEMORY_MAPPED_FILE) - return (file_.buffer().second > 0); -#else - return file_.is_open(); -#endif - } - inline void read_record(record_type& rec) { #if defined(MAPNIK_MEMORY_MAPPED_FILE) @@ -241,11 +197,6 @@ public: file_.read(reinterpret_cast(&envelope), sizeof(envelope)); } - inline void skip(std::streampos bytes) - { - file_.seekg(bytes, std::ios::cur); - } - inline void rewind() { seek(100); diff --git a/plugins/input/topojson/topojson_datasource.cpp b/plugins/input/topojson/topojson_datasource.cpp index c67c47d92..fd0d55cf6 100644 --- a/plugins/input/topojson/topojson_datasource.cpp +++ b/plugins/input/topojson/topojson_datasource.cpp @@ -38,7 +38,6 @@ #include #include #include -#include using mapnik::datasource; using mapnik::parameters; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 831563072..e21672ae8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -223,6 +223,7 @@ target_sources(mapnik PRIVATE target_sources(mapnik PRIVATE util/math.cpp util/utf_conv_win.cpp + util/mapped_memory_file.cpp ) if(USE_CAIRO) diff --git a/src/agg/agg_renderer.cpp b/src/agg/agg_renderer.cpp index f9956616e..e03ddcaee 100644 --- a/src/agg/agg_renderer.cpp +++ b/src/agg/agg_renderer.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include MAPNIK_DISABLE_WARNING_PUSH diff --git a/src/agg/process_building_symbolizer.cpp b/src/agg/process_building_symbolizer.cpp index 345bbea45..88147163d 100644 --- a/src/agg/process_building_symbolizer.cpp +++ b/src/agg/process_building_symbolizer.cpp @@ -21,7 +21,6 @@ *****************************************************************************/ // mapnik -#include #include #include #include diff --git a/src/build.py b/src/build.py index 9227c1089..ac35d44f0 100644 --- a/src/build.py +++ b/src/build.py @@ -274,6 +274,7 @@ source = Split( renderer_common/render_thunk_extractor.cpp renderer_common/pattern_alignment.cpp util/math.cpp + util/mapped_memory_file.cpp value.cpp """ ) diff --git a/src/cairo/process_building_symbolizer.cpp b/src/cairo/process_building_symbolizer.cpp index 65fdef503..b583fca99 100644 --- a/src/cairo/process_building_symbolizer.cpp +++ b/src/cairo/process_building_symbolizer.cpp @@ -23,7 +23,6 @@ #if defined(HAVE_CAIRO) // mapnik -#include #include #include #include diff --git a/src/cairo/process_line_pattern_symbolizer.cpp b/src/cairo/process_line_pattern_symbolizer.cpp index 07dc3c1ce..0c6971335 100644 --- a/src/cairo/process_line_pattern_symbolizer.cpp +++ b/src/cairo/process_line_pattern_symbolizer.cpp @@ -23,7 +23,6 @@ #if defined(HAVE_CAIRO) // mapnik -#include #include #include #include diff --git a/src/cairo/process_raster_symbolizer.cpp b/src/cairo/process_raster_symbolizer.cpp index f8d37b1e6..251238de6 100644 --- a/src/cairo/process_raster_symbolizer.cpp +++ b/src/cairo/process_raster_symbolizer.cpp @@ -23,7 +23,6 @@ #if defined(HAVE_CAIRO) // mapnik -#include #include #include #include diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index 0f23f36fb..6caadd04d 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include MAPNIK_DISABLE_WARNING_PUSH diff --git a/src/grid/process_building_symbolizer.cpp b/src/grid/process_building_symbolizer.cpp index 93e39eb7b..4bb05c335 100644 --- a/src/grid/process_building_symbolizer.cpp +++ b/src/grid/process_building_symbolizer.cpp @@ -23,7 +23,6 @@ #if defined(GRID_RENDERER) // mapnik -#include #include #include #include diff --git a/src/mapped_memory_cache.cpp b/src/mapped_memory_cache.cpp index 241dc8c1e..834d8c032 100644 --- a/src/mapped_memory_cache.cpp +++ b/src/mapped_memory_cache.cpp @@ -56,6 +56,14 @@ bool mapped_memory_cache::insert(std::string const& uri, mapped_region_ptr mem) return cache_.emplace(uri,mem).second; } +bool mapped_memory_cache::remove(std::string const& key) +{ +#ifdef MAPNIK_THREADSAFE + std::lock_guard lock(mutex_); +#endif + return cache_.erase(key) > 0; +} + boost::optional mapped_memory_cache::find(std::string const& uri, bool update_cache) { #ifdef MAPNIK_THREADSAFE diff --git a/src/renderer_common/render_thunk_extractor.cpp b/src/renderer_common/render_thunk_extractor.cpp index 7b96ca777..6f0924901 100644 --- a/src/renderer_common/render_thunk_extractor.cpp +++ b/src/renderer_common/render_thunk_extractor.cpp @@ -22,7 +22,6 @@ // mapnik #include -#include #include #include diff --git a/src/text/text_layout.cpp b/src/text/text_layout.cpp index e1672b1d1..2c8a42be3 100644 --- a/src/text/text_layout.cpp +++ b/src/text/text_layout.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include MAPNIK_DISABLE_WARNING_PUSH diff --git a/src/text/text_properties.cpp b/src/text/text_properties.cpp index df3d38f91..1c9a5e9d6 100644 --- a/src/text/text_properties.cpp +++ b/src/text/text_properties.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include MAPNIK_DISABLE_WARNING_PUSH diff --git a/src/util/mapped_memory_file.cpp b/src/util/mapped_memory_file.cpp new file mode 100644 index 000000000..3c9f99518 --- /dev/null +++ b/src/util/mapped_memory_file.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#ifdef _WIN32 +#include +#endif + +namespace mapnik +{ + namespace util + { + mapped_memory_file::mapped_memory_file() {} + + mapped_memory_file::mapped_memory_file(std::string const &file_name) + : file_name_{file_name}, +#if defined(MAPNIK_MEMORY_MAPPED_FILE) + file_() +#elif defined(_WIN32) + file_(mapnik::utf8_to_utf16(file_name), std::ios::in | std::ios::binary) +#else + file_(file_name.c_str(), std::ios::in | std::ios::binary) +#endif + { +#if defined(MAPNIK_MEMORY_MAPPED_FILE) + boost::optional memory = + mapnik::mapped_memory_cache::instance().find(file_name, true); + + if (memory) + { + mapped_region_ = *memory; + file_.buffer(static_cast(mapped_region_->get_address()),mapped_region_->get_size()); + } + else + { + throw std::runtime_error("could not create file mapping for "+file_name); + } +#endif + + } + + mapped_memory_file::file_source_type& mapped_memory_file::file() + { + return file_; + } + + bool mapped_memory_file::is_open() const + { + #if defined(MAPNIK_MEMORY_MAPPED_FILE) + return (file_.buffer().second > 0); + #else + return file_.is_open(); + #endif + } + + void mapped_memory_file::skip(std::streampos bytes) + { + file_.seekg(bytes, std::ios::cur); + } + + void mapped_memory_file::deleteFile(std::string const &file_name) + { +#ifdef MAPNIK_MEMORY_MAPPED_FILE + mapped_memory_cache::instance().remove(file_name); +#endif + if(util::exists(file_name)) { + util::remove(file_name); + } + + } + + mapped_memory_file::~mapped_memory_file() + { + } + + } +} diff --git a/src/vertex_cache.cpp b/src/vertex_cache.cpp index 12c50bb94..160ed4ad1 100644 --- a/src/vertex_cache.cpp +++ b/src/vertex_cache.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include namespace mapnik { diff --git a/src/webp_reader.cpp b/src/webp_reader.cpp index 095d3b004..d09d996ba 100644 --- a/src/webp_reader.cpp +++ b/src/webp_reader.cpp @@ -21,7 +21,6 @@ *****************************************************************************/ // mapnik -#include #include #include diff --git a/src/wkb.cpp b/src/wkb.cpp index 9da6f7afa..6899d88a8 100644 --- a/src/wkb.cpp +++ b/src/wkb.cpp @@ -21,7 +21,6 @@ *****************************************************************************/ // mapnik -#include #include #include #include diff --git a/src/xml_tree.cpp b/src/xml_tree.cpp index dc723de97..823d3e649 100644 --- a/src/xml_tree.cpp +++ b/src/xml_tree.cpp @@ -22,7 +22,6 @@ //mapnik #include -#include #include #include #include diff --git a/test/unit/datasource/shapeindex.cpp b/test/unit/datasource/shapeindex.cpp index 22d391ad1..c0256a1d6 100644 --- a/test/unit/datasource/shapeindex.cpp +++ b/test/unit/datasource/shapeindex.cpp @@ -33,6 +33,7 @@ MAPNIK_DISABLE_WARNING_PUSH #include #include MAPNIK_DISABLE_WARNING_POP +#include namespace { @@ -107,10 +108,7 @@ TEST_CASE("invalid shapeindex") std::string path = "test/data/shp/boundaries.shp"; std::string index_path = path.substr(0, path.rfind(".")) + ".index"; // remove *.index if present - if (mapnik::util::exists(index_path)) - { - mapnik::util::remove(index_path); - } + mapnik::util::mapped_memory_file::deleteFile(index_path); // count features std::size_t feature_count = count_shapefile_features(path); @@ -132,10 +130,7 @@ TEST_CASE("invalid shapeindex") CHECK(feature_count_indexed == 0); } // remove *.index if present - if (mapnik::util::exists(index_path)) - { - mapnik::util::remove(index_path); - } + mapnik::util::mapped_memory_file::deleteFile(index_path); } } } @@ -159,10 +154,7 @@ TEST_CASE("shapeindex") std::string index_path = path.substr(0, path.rfind(".")) + ".index"; // remove *.index if present - if (mapnik::util::exists(index_path)) - { - mapnik::util::remove(index_path); - } + mapnik::util::mapped_memory_file::deleteFile(index_path); // count features std::size_t feature_count = count_shapefile_features(path); // create *.index @@ -180,10 +172,7 @@ TEST_CASE("shapeindex") // ensure number of features are the same REQUIRE(feature_count == feature_count_indexed); // remove *.index if present - if (mapnik::util::exists(index_path)) - { - mapnik::util::remove(index_path); - } + mapnik::util::mapped_memory_file::deleteFile(index_path); } } } diff --git a/test/unit/imaging/image_io_test.cpp b/test/unit/imaging/image_io_test.cpp index f22bf74ca..e059fda2b 100644 --- a/test/unit/imaging/image_io_test.cpp +++ b/test/unit/imaging/image_io_test.cpp @@ -19,6 +19,7 @@ MAPNIK_DISABLE_WARNING_PUSH #include #include MAPNIK_DISABLE_WARNING_POP +#include inline void make_directory(std::string const& dir) { boost::filesystem::create_directories(dir); @@ -205,10 +206,7 @@ SECTION("image_util : save_to_file/save_to_stream/save_to_string") CHECK(0 == std::memcmp(im2.bytes(), im.bytes(), im.width() * im.height())); } } - if (mapnik::util::exists(filename)) - { - mapnik::util::remove(filename); - } + mapnik::util::mapped_memory_file::deleteFile(filename); } } diff --git a/utils/mapnik-index/process_csv_file.cpp b/utils/mapnik-index/process_csv_file.cpp index 11739073a..1c89bc38d 100644 --- a/utils/mapnik-index/process_csv_file.cpp +++ b/utils/mapnik-index/process_csv_file.cpp @@ -28,15 +28,9 @@ #include #if defined(MAPNIK_MEMORY_MAPPED_FILE) -#include -MAPNIK_DISABLE_WARNING_PUSH -#include #include -#include -#include -MAPNIK_DISABLE_WARNING_POP -#include #endif +#include #include #include @@ -53,37 +47,11 @@ std::pair process_csv_file(T & boxes, s p.separator_ = separator; p.quote_ = quote; -#if defined(MAPNIK_MEMORY_MAPPED_FILE) - using file_source_type = boost::interprocess::ibufferstream; - file_source_type csv_file; - mapnik::mapped_region_ptr mapped_region; - boost::optional memory = - mapnik::mapped_memory_cache::instance().find(filename, true); - if (memory) - { - mapped_region = *memory; - csv_file.buffer(static_cast(mapped_region->get_address()),mapped_region->get_size()); - } - else - { - std::clog << "Error : cannot mmap " << filename << std::endl; - return std::make_pair(false, box_type(p.extent_)); - } -#else - #if defined(_WIN32) - std::ifstream csv_file(mapnik::utf8_to_utf16(filename),std::ios_base::in | std::ios_base::binary); - #else - std::ifstream csv_file(filename.c_str(),std::ios_base::in | std::ios_base::binary); - #endif - if (!csv_file.is_open()) - { - std::clog << "Error : cannot open " << filename << std::endl; - return std::make_pair(false, box_type(p.extent_)); - } -#endif + + util::mapped_memory_file csv_file{filename}; try { - p.parse_csv_and_boxes(csv_file, boxes); + p.parse_csv_and_boxes(csv_file.file(), boxes); return std::make_pair(true, box_type(p.extent_)); } catch (std::exception const& ex) diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 000000000..e3553d412 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,69 @@ +{ + "name": "mapnik", + "version-string": "master", + "description": "Mapnik is an open source toolkit for developing mapping applications.", + "homepage": "https://github.com/mapnik/mapnik", + "dependencies": [ + "boost-assign", + "boost-bimap", + "boost-filesystem", + "boost-geometry", + "boost-gil", + "boost-interprocess", + { + "name": "boost-locale", + "features": [ + "icu" + ] + }, + "boost-msm", + "boost-program-options", + "boost-property-tree", + { + "name": "boost-regex", + "features": [ + "icu" + ] + }, + "boost-spirit", + "boost-system", + "cairo", + "cairomm", + { + "name": "freetype", + "features": [ + "bzip2", + "png" + ] + }, + "gdal", + { + "name": "harfbuzz", + "features": [ + "icu" + ] + }, + { + "name": "harfbuzz", + "features": [ + "coretext" + ], + "platform": "osx" + }, + "icu", + "libjpeg-turbo", + "libodb-pgsql", + "libpng", + "libpq", + "libwebp", + "libxml2", + "mapbox-geometry", + "mapbox-polylabel", + "mapbox-variant", + "proj4", + "protozero", + "sqlite3", + "tiff", + "zlib" + ] +}