Use std::string_view instead of boost::string_view

This commit is contained in:
Mathis Logemann 2024-04-19 18:34:06 +02:00
parent 4114824e6b
commit e1feef5a79
3 changed files with 6 additions and 61 deletions

View file

@ -35,11 +35,7 @@
#include <tuple> #include <tuple>
#include <stdexcept> #include <stdexcept>
#include <map> #include <map>
#if __cpp_lib_string_view >= 201606L
#include <string_view> #include <string_view>
#endif
#include <mapnik/warning.hpp>
namespace mapnik { namespace mapnik {
@ -62,60 +58,9 @@ class illegal_enum_value : public std::exception
}; };
namespace detail { namespace detail {
#if __cpp_lib_string_view >= 201606L
using mapnik_string_view = std::string_view;
#else
class mapnik_string_view // use std::string_view in C++17
{
public:
template<std::size_t N>
constexpr mapnik_string_view(const char (&s)[N])
: size_(N)
, data_(s)
{}
constexpr mapnik_string_view(const char* s, std::size_t N)
: size_(N)
, data_(s)
{}
constexpr char operator[](std::size_t index) const
{
return (index >= size_) ? throw std::out_of_range("Invalid index.") : data_[index];
}
constexpr char const* data() const { return data_; }
private:
std::size_t size_;
const char* data_;
};
constexpr bool mapnik_string_view_equals(mapnik_string_view const& a, char const* b, std::size_t i)
{
if (a[i] != b[i])
{
return false;
}
else if (a[i] == 0 || b[i] == 0)
{
return true;
}
else
{
return mapnik_string_view_equals(a, b, i + 1);
}
}
constexpr bool operator==(mapnik_string_view const& a, char const* b)
{
return mapnik_string_view_equals(a, b, 0);
}
#endif
template<class EnumT> template<class EnumT>
using EnumStringT = std::tuple<EnumT, mapnik_string_view>; using EnumStringT = std::tuple<EnumT, std::string_view>;
template<class EnumT, std::size_t N> template<class EnumT, std::size_t N>
using EnumMapT = std::array<EnumStringT<EnumT>, N>; using EnumMapT = std::array<EnumStringT<EnumT>, N>;

View file

@ -26,14 +26,14 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore.hpp> #include <mapnik/warning_ignore.hpp>
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
#include <boost/utility/string_view.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
#include <string_view>
namespace mapnik { namespace mapnik {
namespace proj_transform_cache { namespace proj_transform_cache {
namespace { namespace {
using key_type = std::pair<std::string, std::string>; using key_type = std::pair<std::string, std::string>;
using compatible_key_type = std::pair<boost::string_view, boost::string_view>; using compatible_key_type = std::pair<std::string_view, std::string_view>;
struct compatible_hash struct compatible_hash
{ {
@ -59,7 +59,7 @@ thread_local static cache_type cache_ = {};
void init(std::string const& source, std::string const& dest) void init(std::string const& source, std::string const& dest)
{ {
compatible_key_type key = std::make_pair<boost::string_view, boost::string_view>(source, dest); compatible_key_type key = std::make_pair<std::string_view, std::string_view>(source, dest);
auto itr = cache_.find(key, compatible_hash{}, compatible_predicate{}); auto itr = cache_.find(key, compatible_hash{}, compatible_predicate{});
if (itr == cache_.end()) if (itr == cache_.end())
{ {
@ -71,7 +71,7 @@ void init(std::string const& source, std::string const& dest)
proj_transform const* get(std::string const& source, std::string const& dest) proj_transform const* get(std::string const& source, std::string const& dest)
{ {
compatible_key_type key = std::make_pair<boost::string_view, boost::string_view>(source, dest); compatible_key_type key = std::make_pair<std::string_view, std::string_view>(source, dest);
auto itr = cache_.find(key, compatible_hash{}, compatible_predicate{}); auto itr = cache_.find(key, compatible_hash{}, compatible_predicate{});
if (itr == cache_.end()) if (itr == cache_.end())
{ {

View file

@ -72,7 +72,7 @@ boost::optional<bool> is_known_geographic(std::string const& srs)
using well_known_srs_e_str = mapnik::detail::EnumStringT<well_known_srs_enum>; using well_known_srs_e_str = mapnik::detail::EnumStringT<well_known_srs_enum>;
constexpr detail::EnumMapT<well_known_srs_enum, 3> well_known_srs_e_map{{ constexpr detail::EnumMapT<well_known_srs_enum, 3> well_known_srs_e_map{{
well_known_srs_e_str{well_known_srs_enum::WGS_84, detail::mapnik_string_view{MAPNIK_GEOGRAPHIC_PROJ_STR}}, well_known_srs_e_str{well_known_srs_enum::WGS_84, MAPNIK_GEOGRAPHIC_PROJ_STR},
well_known_srs_e_str{well_known_srs_enum::WEB_MERC, MAPNIK_WEBMERCATOR_PROJ_STR}, well_known_srs_e_str{well_known_srs_enum::WEB_MERC, MAPNIK_WEBMERCATOR_PROJ_STR},
well_known_srs_e_str{well_known_srs_enum::well_known_srs_enum_MAX, ""}, well_known_srs_e_str{well_known_srs_enum::well_known_srs_enum_MAX, ""},
}}; }};