mapnik::geometry - refactor karma adaper into separate header for re-use
This commit is contained in:
parent
9853353353
commit
beee2fd539
3 changed files with 100 additions and 69 deletions
2
deps/mapbox/variant
vendored
2
deps/mapbox/variant
vendored
|
@ -1 +1 @@
|
|||
Subproject commit e5818212a8f7ef89df0aa76d5244eca78b8dbb8d
|
||||
Subproject commit aaddee9270e3956cee98cdd7d04aea848d69f5f0
|
96
include/mapnik/geometry/boost_spirit_karma_adapter.hpp
Normal file
96
include/mapnik/geometry/boost_spirit_karma_adapter.hpp
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2016 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_BOOST_SPIRIT_KARMA_ADAPTER_HPP
|
||||
#define MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP
|
||||
|
||||
#include <mapnik/geometry.hpp>
|
||||
|
||||
namespace boost { using mapbox::util::get; }
|
||||
|
||||
#include <boost/spirit/home/karma/domain.hpp>
|
||||
#include <boost/spirit/home/support/attributes.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
template <>
|
||||
struct not_is_variant<mapnik::geometry::geometry<double>, karma::domain>
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct variant_which< mapnik::geometry::geometry<double> >
|
||||
{
|
||||
static int call(mapnik::geometry::geometry<double> const& v)
|
||||
{
|
||||
return v.which();
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename T, typename Tuple>
|
||||
struct has_type;
|
||||
|
||||
template <typename T>
|
||||
struct has_type<T, std::tuple<>> : std::false_type {};
|
||||
|
||||
template <typename T, typename U, typename... Types>
|
||||
struct has_type<T, std::tuple<U, Types...>> : has_type<T, std::tuple<Types...>> {};
|
||||
|
||||
template <typename T, typename... Types>
|
||||
struct has_type<T, std::tuple<T, Types...>> : std::true_type {};
|
||||
|
||||
template <typename T, typename Tuple>
|
||||
struct index;
|
||||
|
||||
template <typename T, typename... Types>
|
||||
struct index<T, std::tuple<T, Types...>>
|
||||
{
|
||||
static const std::size_t value = 0;
|
||||
};
|
||||
|
||||
template <typename T, typename U, typename... Types>
|
||||
struct index<T, std::tuple<U, Types...>>
|
||||
{
|
||||
static const std::size_t value = 1 + index<T, std::tuple<Types...>>::value;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <typename Expected>
|
||||
struct compute_compatible_component_variant<mapnik::geometry::geometry<double>, Expected>
|
||||
: detail::has_type<Expected, mapnik::geometry::geometry<double>::types>
|
||||
{
|
||||
using compatible_type = Expected;
|
||||
static bool is_compatible(int index)
|
||||
{
|
||||
return (index == detail::index<compatible_type, mapnik::geometry::geometry<double>::types>::value);
|
||||
}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
|
||||
|
||||
#endif //MAPNIK_BOOST_SPIRIT_KARMA_ADAPTER_HPP
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 Artem Pavlenko
|
||||
* Copyright (C) 2016 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -19,79 +19,14 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace boost { using mapbox::util::get; }
|
||||
|
||||
#include <mapnik/geometry/boost_spirit_karma_adapter.hpp>
|
||||
#include <mapnik/wkt/wkt_generator_grammar_impl.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
template <>
|
||||
struct not_is_variant<mapnik::geometry::geometry<double>, karma::domain>
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct variant_which< mapnik::geometry::geometry<double> >
|
||||
{
|
||||
static int call(mapnik::geometry::geometry<double> const& v)
|
||||
{
|
||||
return v.which();
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename T, typename Tuple>
|
||||
struct has_type;
|
||||
|
||||
template <typename T>
|
||||
struct has_type<T, std::tuple<>> : std::false_type {};
|
||||
|
||||
template <typename T, typename U, typename... Types>
|
||||
struct has_type<T, std::tuple<U, Types...>> : has_type<T, std::tuple<Types...>> {};
|
||||
|
||||
template <typename T, typename... Types>
|
||||
struct has_type<T, std::tuple<T, Types...>> : std::true_type {};
|
||||
|
||||
template <typename T, typename Tuple>
|
||||
struct index;
|
||||
|
||||
template <typename T, typename... Types>
|
||||
struct index<T, std::tuple<T, Types...>>
|
||||
{
|
||||
static const std::size_t value = 0;
|
||||
};
|
||||
|
||||
template <typename T, typename U, typename... Types>
|
||||
struct index<T, std::tuple<U, Types...>>
|
||||
{
|
||||
static const std::size_t value = 1 + index<T, std::tuple<Types...>>::value;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <typename Expected>
|
||||
struct compute_compatible_component_variant<mapnik::geometry::geometry<double>, Expected>
|
||||
: detail::has_type<Expected, mapnik::geometry::geometry<double>::types>
|
||||
{
|
||||
using compatible_type = Expected;
|
||||
static bool is_compatible(int index)
|
||||
{
|
||||
return (index == detail::index<compatible_type, mapnik::geometry::geometry<double>::types>::value);
|
||||
}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
|
||||
namespace mapnik { namespace wkt {
|
||||
|
||||
using sink_type = std::back_insert_iterator<std::string>;
|
||||
template struct wkt_generator_grammar<sink_type, mapnik::geometry::geometry<double>>;
|
||||
template struct wkt_generator_grammar<sink_type, mapnik::geometry::geometry<std::int64_t>>;
|
||||
//template struct wkt_generator_grammar<sink_type, mapnik::geometry::geometry<std::int64_t>>;
|
||||
|
||||
}}
|
||||
|
|
Loading…
Add table
Reference in a new issue