From ee58762bd9b0c175f843de17b1191fb4390d349a Mon Sep 17 00:00:00 2001 From: artemp Date: Mon, 21 Jul 2014 11:19:26 +0100 Subject: [PATCH] add property_serializer impl --- include/mapnik/text/properties_util.hpp | 2 + src/build.py | 1 + src/text/properties_util.cpp | 76 +++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/text/properties_util.cpp diff --git a/include/mapnik/text/properties_util.hpp b/include/mapnik/text/properties_util.hpp index e03ef782a..11db24886 100644 --- a/include/mapnik/text/properties_util.hpp +++ b/include/mapnik/text/properties_util.hpp @@ -53,6 +53,8 @@ void set_property_from_xml(T1 & val, char const* name, xml_node const& node) } } +void serialize_property(std::string const& name, symbolizer_base::value_type const& val, boost::property_tree::ptree & node); + } // namespace mapnik #endif // MAPNIK_PROPERTIES_UTIL_HPP diff --git a/src/build.py b/src/build.py index d036f653a..94af4eecb 100644 --- a/src/build.py +++ b/src/build.py @@ -220,6 +220,7 @@ source = Split( text/scrptrun.cpp text/face.cpp text/placement_finder.cpp + text/properties_util.cpp text/renderer.cpp text/symbolizer_helpers.cpp text/text_properties.cpp diff --git a/src/text/properties_util.cpp b/src/text/properties_util.cpp new file mode 100644 index 000000000..d05dd3a21 --- /dev/null +++ b/src/text/properties_util.cpp @@ -0,0 +1,76 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2014 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 + * + *****************************************************************************/ + +#include +#include + +namespace mapnik { namespace detail { + +struct property_serializer : public boost::static_visitor<> +{ + property_serializer(std::string const& name, boost::property_tree::ptree & node) + : name_(name), + node_(node) {} + + void operator() (expression_ptr const& expr) const + { + if (expr) node_.put("." + name_, to_expression_string(*expr)); + } + + void operator() (value_bool val) const + { + node_.put("." + name_, val ); + } + + void operator() (value_integer val) const + { + node_.put("." + name_, val ); + } + + void operator() (value_double val) const + { + node_.put("." + name_, val ); + } + + void operator() (std::string const& val) const + { + node_.put("." + name_, val ); + } + + + template + void operator() (T const& val) const + { + std::cerr << "NOOP" << std::endl; + } + + std::string const& name_; + boost::property_tree::ptree & node_; +}; +} + +void serialize_property(std::string const& name, symbolizer_base::value_type const& val, boost::property_tree::ptree & node) +{ + boost::apply_visitor(detail::property_serializer(name,node), val); +} + +}