mirror of
https://github.com/mapnik/mapnik.git
synced 2025-12-08 20:13:09 +00:00
+ symbolizers: add hash impl
This commit is contained in:
parent
79f0f18f3c
commit
ad39c9a16a
@ -23,12 +23,19 @@
|
||||
#include <boost/python.hpp>
|
||||
#include "mapnik_enumeration.hpp"
|
||||
#include <mapnik/line_symbolizer.hpp>
|
||||
#include <mapnik/symbolizer_hash.hpp>
|
||||
|
||||
using namespace mapnik;
|
||||
using mapnik::line_symbolizer;
|
||||
using mapnik::stroke;
|
||||
using mapnik::color;
|
||||
|
||||
std::size_t line_symbolizer_hash(line_symbolizer const& sym)
|
||||
{
|
||||
return symbolizer_hash::value(sym);
|
||||
}
|
||||
|
||||
|
||||
void export_line_symbolizer()
|
||||
{
|
||||
using namespace boost::python;
|
||||
@ -68,5 +75,6 @@ void export_line_symbolizer()
|
||||
&line_symbolizer::smooth,
|
||||
&line_symbolizer::set_smooth,
|
||||
"smooth value (0..1.0)")
|
||||
.def("__hash__", line_symbolizer_hash)
|
||||
;
|
||||
}
|
||||
|
||||
@ -22,11 +22,17 @@
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <mapnik/polygon_symbolizer.hpp>
|
||||
#include <mapnik/symbolizer_hash.hpp>
|
||||
|
||||
using namespace mapnik;
|
||||
using mapnik::polygon_symbolizer;
|
||||
using mapnik::color;
|
||||
|
||||
std::size_t polygon_symbolizer_hash(polygon_symbolizer const& sym)
|
||||
{
|
||||
return symbolizer_hash::value(sym);
|
||||
}
|
||||
|
||||
void export_polygon_symbolizer()
|
||||
{
|
||||
using namespace boost::python;
|
||||
@ -64,6 +70,7 @@ void export_polygon_symbolizer()
|
||||
&polygon_symbolizer::simplify_tolerance,
|
||||
&polygon_symbolizer::set_simplify_tolerance,
|
||||
"simplfication tolerance measure")
|
||||
.def("__hash__", polygon_symbolizer_hash)
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
// mapnik
|
||||
//symbolizer typdef here rather than mapnik/symbolizer.hpp
|
||||
#include <mapnik/rule.hpp>
|
||||
#include <mapnik/symbolizer_hash.hpp>
|
||||
|
||||
using mapnik::symbolizer;
|
||||
|
||||
@ -169,6 +170,20 @@ const markers_symbolizer& markers_( const symbolizer& symbol )
|
||||
return boost::get<markers_symbolizer>(symbol);
|
||||
}
|
||||
|
||||
struct symbolizer_hash_visitor : public boost::static_visitor<std::size_t>
|
||||
{
|
||||
template <typename T>
|
||||
std::size_t operator() (T const& sym) const
|
||||
{
|
||||
return mapnik::symbolizer_hash::value(sym);
|
||||
}
|
||||
};
|
||||
|
||||
std::size_t hash_impl(symbolizer const& sym)
|
||||
{
|
||||
return boost::apply_visitor(symbolizer_hash_visitor(), sym);
|
||||
}
|
||||
|
||||
void export_symbolizer()
|
||||
{
|
||||
using namespace boost::python;
|
||||
@ -177,6 +192,8 @@ void export_symbolizer()
|
||||
|
||||
.def("type",get_symbol_type)
|
||||
|
||||
.def("__hash__",hash_impl)
|
||||
|
||||
.def("point",point_,
|
||||
return_value_policy<copy_const_reference>())
|
||||
|
||||
|
||||
66
include/mapnik/symbolizer_hash.hpp
Normal file
66
include/mapnik/symbolizer_hash.hpp
Normal file
@ -0,0 +1,66 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2013 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_SYMBOLIZER_HASH_HPP
|
||||
#define MAPNIK_SYMBOLIZER_HASH_HPP
|
||||
|
||||
#include <mapnik/map.hpp>
|
||||
#include <mapnik/feature_type_style.hpp>
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/variant/static_visitor.hpp>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
struct symbolizer_hash
|
||||
{
|
||||
template <typename T>
|
||||
static std::size_t value(T const& sym)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
return seed;
|
||||
}
|
||||
// specialisation for polygon_symbolizer
|
||||
static std::size_t value(polygon_symbolizer const& sym)
|
||||
{
|
||||
std::size_t seed = Polygon;
|
||||
boost::hash_combine(seed, sym.get_fill().rgba());
|
||||
boost::hash_combine(seed, sym.get_opacity());
|
||||
return seed;
|
||||
}
|
||||
|
||||
// specialisation for line_symbolizer
|
||||
static std::size_t value(line_symbolizer const& sym)
|
||||
{
|
||||
std::size_t seed = LineString;
|
||||
boost::hash_combine(seed, sym.get_stroke().get_color().rgba());
|
||||
boost::hash_combine(seed, sym.get_stroke().get_width());
|
||||
boost::hash_combine(seed, sym.get_stroke().get_opacity());
|
||||
boost::hash_combine(seed, static_cast<int>(sym.get_stroke().get_line_cap()));
|
||||
boost::hash_combine(seed, static_cast<int>(sym.get_stroke().get_line_join()));
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // MAPNIK_SYMBOLIZER_HASH_HPP
|
||||
Loading…
x
Reference in New Issue
Block a user