support optionally compiling with -std=c++11 on OSX / clang / apple libc++ / boost 1.53 - refs #1683

This commit is contained in:
Dane Springmeyer 2013-07-27 01:57:24 -04:00
parent 4eda02592e
commit 76f111cc97
16 changed files with 347 additions and 28 deletions

View file

@ -1656,6 +1656,13 @@ if not preconfigured:
debug_defines = ['-DDEBUG', '-DMAPNIK_DEBUG']
ndebug_defines = ['-DNDEBUG']
# c++11 support / https://github.com/mapnik/mapnik/issues/1683
# - workaround boost gil channel_algorithm.hpp narrowing error
# - upgrade to PHOENIX_V3 since that is needed for c++11 compile
if 'c++11' in env['CUSTOM_CXXFLAGS']:
env.Append(CXXFLAGS = '-Wno-c++11-narrowing')
env.Append(CPPDEFINES = '-DBOOST_SPIRIT_USE_PHOENIX_V3=1')
# Enable logging in debug mode (always) and release mode (when specified)
if env['DEFAULT_LOG_SEVERITY']:
if env['DEFAULT_LOG_SEVERITY'] not in severities:

View file

@ -108,7 +108,11 @@ struct alpha_conv_impl
struct hsl_conv_impl
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template<typename T>
#else
template<typename T0,typename T1, typename T2, typename T3>
#endif
struct result
{
typedef void type;

View file

@ -65,7 +65,11 @@ struct unicode_impl
struct regex_match_impl
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T>
#else
template <typename T0, typename T1>
#endif
struct result
{
typedef expr_node type;
@ -82,7 +86,12 @@ struct regex_match_impl
struct regex_replace_impl
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T>
#else
template <typename T0, typename T1, typename T2>
#endif
struct result
{
typedef expr_node type;

View file

@ -66,6 +66,31 @@ public:
mapnik::transcoder const& tr_;
};
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
struct put_property
{
typedef void result_type;
explicit put_property(mapnik::transcoder const& tr)
: tr_(tr) {}
template <typename T0,typename T1, typename T2>
result_type operator() (T0 & feature, T1 const& key, T2 const& val) const
{
mapnik::value v = boost::apply_visitor(attribute_value_visitor(tr_),val); // TODO: optimize
feature.put_new(key, v);
}
mapnik::transcoder const& tr_;
};
struct extract_geometry
{
typedef boost::ptr_vector<mapnik::geometry_type>& result_type;
template <typename T>
result_type operator() (T & feature) const
{
return feature.paths();
}
};
#else
struct put_property
{
template <typename T0,typename T1, typename T2>
@ -100,6 +125,7 @@ struct extract_geometry
return feature.paths();
}
};
#endif
template <typename Iterator, typename FeatureType>
struct feature_grammar :

View file

@ -0,0 +1,57 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 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_FEATURE_PARSER_HPP
#define MAPNIK_FEATURE_PARSER_HPP
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/noncopyable.hpp>
#include <mapnik/unicode.hpp>
// boost
#include <boost/scoped_ptr.hpp>
// stl
#include <vector>
namespace mapnik { namespace json {
template <typename Iterator, typename FeatureType> struct feature_grammar;
template <typename Iterator>
class MAPNIK_DECL feature_parser : private mapnik::noncopyable
{
typedef Iterator iterator_type;
typedef mapnik::feature_impl feature_type;
public:
feature_parser(mapnik::transcoder const& tr);
~feature_parser();
bool parse(iterator_type first, iterator_type last, mapnik::feature_impl & f);
private:
boost::scoped_ptr<feature_grammar<iterator_type,feature_type> > grammar_;
};
}}
#endif //MAPNIK_FEATURE_PARSER_HPP

View file

@ -39,10 +39,7 @@
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
#include <boost/fusion/include/boost_tuple.hpp>
#include <boost/math/special_functions/trunc.hpp> // trunc to avoid needing C++11
//#define BOOST_SPIRIT_USE_PHOENIX_V3 1
#include <boost/math/special_functions/trunc.hpp> // for vc++
namespace boost { namespace spirit { namespace traits {
@ -61,6 +58,52 @@ namespace phoenix = boost::phoenix;
namespace {
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
struct get_type
{
typedef int result_type;
result_type operator() (geometry_type const& geom) const
{
return static_cast<int>(geom.type());
}
};
struct get_first
{
typedef geometry_type::value_type const result_type;
result_type operator() (geometry_type const& geom) const
{
geometry_type::value_type coord;
boost::get<0>(coord) = geom.vertex(0,&boost::get<1>(coord),&boost::get<2>(coord));
return coord;
}
};
struct multi_geometry_type
{
typedef boost::tuple<unsigned,bool> result_type;
result_type operator() (geometry_container const& geom) const
{
unsigned type = 0u;
bool collection = false;
geometry_container::const_iterator itr = geom.begin();
geometry_container::const_iterator end = geom.end();
for ( ; itr != end; ++itr)
{
if (type != 0u && itr->type() != type)
{
collection = true;
break;
}
type = itr->type();
}
if (geom.size() > 1) type +=3;
return boost::tuple<unsigned,bool>(type, collection);
}
};
#else
struct get_type
{
template <typename T>
@ -111,6 +154,7 @@ struct multi_geometry_type
return boost::tuple<unsigned,bool>(type, collection);
}
};
#endif
template <typename T>
@ -123,7 +167,7 @@ struct json_coordinate_policy : karma::real_policies<T>
{
if (n == 0.0) return 0;
using namespace boost::spirit;
return static_cast<unsigned>(15 - boost::math::trunc(log10(traits::get_absolute_value(n))));
return static_cast<unsigned>(14 - boost::math::trunc(log10(traits::get_absolute_value(n))));
}
template <typename OutputIterator>
@ -187,7 +231,10 @@ struct geometry_generator_grammar :
polygon_coord %= ( &uint_(mapnik::SEG_MOVETO) << eps[_r1 += 1]
<< karma::string[ if_ (_r1 > 1) [_1 = "],["]
.else_[_1 = '[' ]] | &uint_ << lit(','))
.else_[_1 = '[' ]]
|
&uint_(mapnik::SEG_LINETO))
<< lit(',')
<< lit('[') << coord_type
<< lit(',')
<< coord_type << lit(']')
@ -258,9 +305,9 @@ struct multi_geometry_generator_grammar :
geometry = (lit("{\"type\":")
<< geometry_types[_1 = phoenix::at_c<0>(_a)][_a = _multi_type(_val)]
<< lit(",\"coordinates\":")
<< karma::string[ if_ (phoenix::at_c<0>(_a) > 3) [_1 = '[']]
<< karma::string[ phoenix::if_ (phoenix::at_c<0>(_a) > 3) [_1 = '['].else_[_1 = ""]]
<< coordinates
<< karma::string[ if_ (phoenix::at_c<0>(_a) > 3) [_1 = ']']]
<< karma::string[ phoenix::if_ (phoenix::at_c<0>(_a) > 3) [_1 = ']'].else_[_1 = ""]]
<< lit('}')) | lit("null")
;

View file

@ -37,6 +37,55 @@ namespace qi = boost::spirit::qi;
namespace standard_wide = boost::spirit::standard_wide;
using standard_wide::space_type;
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
struct push_vertex
{
typedef void result_type;
template <typename T0,typename T1, typename T2, typename T3>
result_type operator() (T0 c, T1 path, T2 x, T3 y) const
{
BOOST_ASSERT( path!=0 );
path->push_vertex(x,y,c);
}
};
struct close_path
{
typedef void result_type;
template <typename T>
result_type operator() (T path) const
{
BOOST_ASSERT( path!=0 );
path->close_path();
}
};
struct cleanup
{
typedef void result_type;
template <typename T0>
void operator() (T0 & path) const
{
if (path) delete path, path=0;
}
};
struct where_message
{
typedef std::string result_type;
template <typename Iterator>
std::string operator() (Iterator first, Iterator last, std::size_t size) const
{
std::string str(first, last);
if (str.length() > size)
return str.substr(0, size) + "..." ;
return str;
}
};
#else
struct push_vertex
{
template <typename T0,typename T1, typename T2, typename T3>
@ -101,6 +150,7 @@ struct where_message
return str;
}
};
#endif
template <typename Iterator>

View file

@ -45,7 +45,12 @@ inline double deg2rad(double deg)
template <typename PathType>
struct move_to
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1>
#endif
struct result
{
typedef void type;
@ -66,7 +71,11 @@ struct move_to
template <typename PathType>
struct hline_to
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1>
#endif
struct result
{
typedef void type;
@ -88,7 +97,11 @@ struct hline_to
template <typename PathType>
struct vline_to
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1>
#endif
struct result
{
typedef void type;
@ -109,7 +122,11 @@ struct vline_to
template <typename PathType>
struct line_to
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1>
#endif
struct result
{
typedef void type;
@ -131,7 +148,11 @@ struct line_to
template <typename PathType>
struct curve4
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1, typename T2, typename T3>
#endif
struct result
{
typedef void type;
@ -156,7 +177,11 @@ struct curve4
template <typename PathType>
struct curve4_smooth
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1, typename T2>
#endif
struct result
{
typedef void type;
@ -178,7 +203,11 @@ struct curve4_smooth
template <typename PathType>
struct curve3
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1, typename T2>
#endif
struct result
{
typedef void type;
@ -201,7 +230,11 @@ struct curve3
template <typename PathType>
struct curve3_smooth
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1>
#endif
struct result
{
typedef void type;
@ -223,7 +256,11 @@ struct curve3_smooth
template <typename PathType>
struct arc_to
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
#endif
struct result
{
typedef void type;

View file

@ -50,7 +50,11 @@ namespace mapnik { namespace svg {
template <typename TransformType>
struct process_matrix
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
#endif
struct result
{
typedef void type;
@ -70,7 +74,11 @@ namespace mapnik { namespace svg {
template <typename TransformType>
struct process_rotate
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1, typename T2>
#endif
struct result
{
typedef void type;
@ -101,7 +109,11 @@ namespace mapnik { namespace svg {
template <typename TransformType>
struct process_translate
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1>
#endif
struct result
{
typedef void type;
@ -123,7 +135,11 @@ namespace mapnik { namespace svg {
template <typename TransformType>
struct process_scale
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1>
#endif
struct result
{
typedef void type;
@ -146,7 +162,11 @@ namespace mapnik { namespace svg {
template <typename TransformType>
struct process_skew
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T0>
#else
template <typename T0, typename T1>
#endif
struct result
{
typedef void type;

View file

@ -23,6 +23,7 @@
#ifndef MAPNIK_GEOMETRY_SVG_GENERATOR_HPP
#define MAPNIK_GEOMETRY_SVG_GENERATOR_HPP
// mapnik
#include <mapnik/global.hpp>
#include <mapnik/geometry.hpp> // for container stuff
@ -41,8 +42,6 @@
#include <boost/fusion/include/boost_tuple.hpp>
#include <boost/type_traits/remove_pointer.hpp>
//#define BOOST_SPIRIT_USE_PHOENIX_V3 1
/*!
* adapted to conform to the concepts
* required by Karma to be recognized as a container of

View file

@ -40,7 +40,6 @@
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/math/special_functions/trunc.hpp> // trunc to avoid needing C++11
//#define BOOST_SPIRIT_USE_PHOENIX_V3 1
namespace boost { namespace spirit { namespace traits {

View file

@ -40,12 +40,15 @@
namespace mapnik { namespace wkt {
using namespace boost::spirit;
using namespace boost::fusion;
using namespace boost::phoenix;
struct push_vertex
{
#ifdef BOOST_SPIRIT_USE_PHOENIX_V3
template <typename T>
#else
template <typename T0,typename T1, typename T2, typename T3>
#endif
struct result
{
typedef void type;

View file

@ -23,8 +23,10 @@
// TODO https://github.com/mapnik/mapnik/issues/1658
#include <boost/version.hpp>
#if BOOST_VERSION >= 105200
#ifndef BOOST_SPIRIT_USE_PHOENIX_V3
#define BOOST_SPIRIT_USE_PHOENIX_V3
#endif
#endif
// mapnik
#include <mapnik/json/feature_collection_parser.hpp>
@ -68,4 +70,3 @@ namespace mapnik { namespace json {
template class feature_collection_parser<boost::spirit::multi_pass<std::istreambuf_iterator<char> > >;
}}

View file

@ -0,0 +1,61 @@
/*****************************************************************************
*
* 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
*
*****************************************************************************/
#include <boost/version.hpp>
// mapnik
#include <mapnik/json/feature_parser.hpp>
#include <mapnik/json/feature_grammar.hpp>
// boost
#include <boost/version.hpp>
#include <boost/spirit/include/qi.hpp>
namespace mapnik { namespace json {
#if BOOST_VERSION >= 104700
template <typename Iterator>
feature_parser<Iterator>::feature_parser(mapnik::transcoder const& tr)
: grammar_(new feature_grammar<iterator_type,feature_type>(tr)) {}
template <typename Iterator>
feature_parser<Iterator>::~feature_parser() {}
#endif
template <typename Iterator>
bool feature_parser<Iterator>::parse(iterator_type first, iterator_type last, mapnik::feature_impl & f)
{
#if BOOST_VERSION >= 104700
using namespace boost::spirit;
return qi::phrase_parse(first, last, (*grammar_)(boost::phoenix::ref(f)), standard_wide::space);
#else
std::ostringstream s;
s << BOOST_VERSION/100000 << "." << BOOST_VERSION/100 % 1000 << "." << BOOST_VERSION % 100;
throw std::runtime_error("mapnik::feature_parser::parse() requires at least boost 1.47 while your build was compiled against boost " + s.str());
return false;
#endif
}
template class feature_parser<std::string::const_iterator>;
}}

View file

@ -44,7 +44,6 @@ bool feature_generator::generate(std::string & geojson, mapnik::feature_impl con
return karma::generate(sink, *grammar_,f);
}
geometry_generator::geometry_generator()
: grammar_(new multi_geometry_generator_grammar<sink_type>()) {}