2009-12-16 21:02:06 +01:00
|
|
|
/*****************************************************************************
|
2012-02-02 02:53:35 +01:00
|
|
|
*
|
2009-12-16 21:02:06 +01:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2011-10-23 15:04:25 +02:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2009-12-16 21:02:06 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2012-04-08 02:45:01 +02:00
|
|
|
// mapnik
|
2013-01-11 04:52:24 +01:00
|
|
|
|
|
|
|
#include <mapnik/config.hpp> // needed by msvc
|
|
|
|
#include <mapnik/expression_string.hpp> // needed by msvc
|
|
|
|
#include <mapnik/expression_node_types.hpp>
|
2013-01-09 00:12:39 +01:00
|
|
|
#include <mapnik/expression_node.hpp>
|
|
|
|
#include <mapnik/attribute.hpp>
|
2013-08-14 00:52:04 +02:00
|
|
|
#include <mapnik/value_types.hpp>
|
2013-01-09 00:12:39 +01:00
|
|
|
#include <mapnik/value.hpp>
|
2012-04-08 02:45:01 +02:00
|
|
|
// boost
|
2013-01-11 04:52:24 +01:00
|
|
|
#if defined(BOOST_REGEX_HAS_ICU)
|
|
|
|
#include <boost/regex/icu.hpp> // for u32regex
|
|
|
|
#endif
|
2010-01-29 20:22:15 +01:00
|
|
|
|
2009-12-16 21:02:06 +01:00
|
|
|
namespace mapnik
|
|
|
|
{
|
|
|
|
|
2014-08-12 14:40:45 +02:00
|
|
|
struct expression_string : util::static_visitor<void>
|
2009-12-16 21:02:06 +01:00
|
|
|
{
|
|
|
|
explicit expression_string(std::string & str)
|
2010-01-30 01:44:35 +01:00
|
|
|
: str_(str) {}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2009-12-16 21:02:06 +01:00
|
|
|
void operator() (value_type const& x) const
|
2012-02-02 02:53:35 +01:00
|
|
|
{
|
|
|
|
str_ += x.to_expression_string() ;
|
2009-12-16 21:02:06 +01:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2009-12-16 21:02:06 +01:00
|
|
|
void operator() (attribute const& attr) const
|
|
|
|
{
|
|
|
|
str_ += "[";
|
2010-01-30 01:44:35 +01:00
|
|
|
str_ += attr.name();
|
|
|
|
str_ += "]";
|
2009-12-16 21:02:06 +01:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
void operator() (global_attribute const& attr) const
|
|
|
|
{
|
|
|
|
str_ += "@";
|
|
|
|
str_ += attr.name;
|
|
|
|
}
|
|
|
|
|
2013-07-23 21:51:22 +02:00
|
|
|
void operator() (geometry_type_attribute const& /*attr*/) const
|
2012-07-20 13:28:25 +02:00
|
|
|
{
|
|
|
|
str_ += "[mapnik::geometry_type]";
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
template <typename Tag>
|
2009-12-16 21:02:06 +01:00
|
|
|
void operator() (binary_node<Tag> const& x) const
|
|
|
|
{
|
|
|
|
if (x.type() != tags::mult::str() && x.type() != tags::div::str())
|
|
|
|
{
|
|
|
|
str_ += "(";
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2014-08-26 12:00:42 +02:00
|
|
|
util::apply_visitor(*this,x.left);
|
2009-12-16 21:02:06 +01:00
|
|
|
str_ += x.type();
|
2014-08-26 12:00:42 +02:00
|
|
|
util::apply_visitor(*this,x.right);
|
2009-12-16 21:02:06 +01:00
|
|
|
if (x.type() != tags::mult::str() && x.type() != tags::div::str())
|
|
|
|
{
|
|
|
|
str_ += ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Tag>
|
|
|
|
void operator() (unary_node<Tag> const& x) const
|
|
|
|
{
|
2010-01-30 01:44:35 +01:00
|
|
|
str_ += Tag::str();
|
|
|
|
str_ += "(";
|
2014-08-26 12:00:42 +02:00
|
|
|
util::apply_visitor(*this,x.expr);
|
2010-01-30 01:44:35 +01:00
|
|
|
str_ += ")";
|
2009-12-16 21:02:06 +01:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2009-12-16 21:02:06 +01:00
|
|
|
void operator() (regex_match_node const & x) const
|
|
|
|
{
|
2014-08-26 12:00:42 +02:00
|
|
|
util::apply_visitor(*this,x.expr);
|
2010-06-29 13:56:42 +02:00
|
|
|
str_ +=".match('";
|
2011-02-28 21:00:56 +01:00
|
|
|
#if defined(BOOST_REGEX_HAS_ICU)
|
2010-01-30 01:44:35 +01:00
|
|
|
std::string utf8;
|
2013-08-14 00:52:04 +02:00
|
|
|
mapnik::value_unicode_string ustr = mapnik::value_unicode_string::fromUTF32( &x.pattern.str()[0] ,x.pattern.str().length());
|
2010-01-30 01:44:35 +01:00
|
|
|
to_utf8(ustr,utf8);
|
|
|
|
str_ += utf8;
|
2011-02-28 21:00:56 +01:00
|
|
|
#else
|
|
|
|
str_ += x.pattern.str();
|
2010-01-29 20:22:15 +01:00
|
|
|
#endif
|
2011-02-28 21:00:56 +01:00
|
|
|
str_ +="')";
|
2009-12-16 21:02:06 +01:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2009-12-16 21:02:06 +01:00
|
|
|
void operator() (regex_replace_node const & x) const
|
|
|
|
{
|
2014-08-26 12:00:42 +02:00
|
|
|
util::apply_visitor(*this,x.expr);
|
2010-01-30 01:44:35 +01:00
|
|
|
str_ +=".replace(";
|
2011-02-28 21:00:56 +01:00
|
|
|
str_ += "'";
|
|
|
|
#if defined(BOOST_REGEX_HAS_ICU)
|
2010-01-30 01:44:35 +01:00
|
|
|
std::string utf8;
|
2013-08-14 00:52:04 +02:00
|
|
|
mapnik::value_unicode_string ustr = mapnik::value_unicode_string::fromUTF32( &x.pattern.str()[0] ,x.pattern.str().length());
|
2010-01-30 01:44:35 +01:00
|
|
|
to_utf8(ustr,utf8);
|
|
|
|
str_ += utf8;
|
|
|
|
str_ +="','";
|
|
|
|
to_utf8(x.format ,utf8);
|
|
|
|
str_ += utf8;
|
2011-02-28 21:00:56 +01:00
|
|
|
#else
|
|
|
|
str_ += x.pattern.str();
|
|
|
|
str_ +="','";
|
2012-11-01 18:31:45 +01:00
|
|
|
str_ += x.format;
|
2010-01-29 20:22:15 +01:00
|
|
|
#endif
|
2011-02-28 21:00:56 +01:00
|
|
|
str_ +="')";
|
2009-12-16 21:02:06 +01:00
|
|
|
}
|
|
|
|
|
2014-08-25 15:17:18 +02:00
|
|
|
void operator() (unary_function_call const& call) const
|
2014-08-22 13:30:25 +02:00
|
|
|
{
|
2014-08-26 11:51:55 +02:00
|
|
|
str_ += unary_function_name(call.fun);
|
|
|
|
str_ += "(";
|
2014-08-26 12:00:42 +02:00
|
|
|
util::apply_visitor(*this,call.arg);
|
2014-08-26 11:51:55 +02:00
|
|
|
str_ += ")";
|
|
|
|
|
2014-08-25 15:17:18 +02:00
|
|
|
}
|
|
|
|
void operator() (binary_function_call const& call) const
|
|
|
|
{
|
2014-08-26 11:51:55 +02:00
|
|
|
str_ += binary_function_name(call.fun);
|
|
|
|
str_ += "(";
|
2014-08-26 12:00:42 +02:00
|
|
|
util::apply_visitor(*this,call.arg1);
|
2014-08-26 11:51:55 +02:00
|
|
|
str_ += ",";
|
2014-08-26 12:00:42 +02:00
|
|
|
util::apply_visitor(*this,call.arg2);
|
2014-08-26 11:51:55 +02:00
|
|
|
str_ += ")";
|
|
|
|
|
2014-08-22 13:30:25 +02:00
|
|
|
}
|
2009-12-16 21:02:06 +01:00
|
|
|
private:
|
2010-06-18 12:53:42 +02:00
|
|
|
std::string & str_;
|
2009-12-16 21:02:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
std::string to_expression_string(expr_node const& node)
|
|
|
|
{
|
|
|
|
std::string str;
|
|
|
|
expression_string functor(str);
|
2014-08-12 14:40:45 +02:00
|
|
|
util::apply_visitor(std::ref(functor),node);
|
2009-12-16 21:02:06 +01:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|