From b5c06965acfbb92047157e195960775494d09945 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 8 Jan 2013 14:17:31 -0800 Subject: [PATCH] refactor expression and value type usage to speed up compile time --- include/mapnik/attribute.hpp | 2 +- include/mapnik/expression.hpp | 11 +- include/mapnik/expression_grammar.hpp | 27 ++- include/mapnik/expression_node.hpp | 157 +----------------- include/mapnik/feature_factory.hpp | 2 +- include/mapnik/params.hpp | 2 +- include/mapnik/parse_path.hpp | 109 +----------- include/mapnik/path_expression_grammar.hpp | 2 +- .../mapnik/transform_expression_grammar.hpp | 2 +- plugins/input/csv/csv_datasource.cpp | 2 +- plugins/input/csv/csv_datasource.hpp | 2 +- plugins/input/gdal/gdal_datasource.cpp | 2 +- plugins/input/geos/geos_datasource.cpp | 2 +- plugins/input/occi/occi_datasource.cpp | 2 +- plugins/input/occi/occi_datasource.hpp | 2 +- plugins/input/ogr/ogr_featureset.cpp | 2 +- plugins/input/ogr/ogr_index_featureset.cpp | 2 +- plugins/input/osm/osm.h | 2 +- plugins/input/osm/osmparser.h | 2 +- plugins/input/postgis/build.py | 2 +- plugins/input/postgis/postgis_datasource.cpp | 2 +- plugins/input/postgis/postgis_datasource.hpp | 2 +- plugins/input/postgis/postgis_featureset.cpp | 2 +- plugins/input/shape/dbfile.cpp | 2 +- plugins/input/shape/shape_datasource.cpp | 2 +- plugins/input/shape/shape_datasource.hpp | 2 +- plugins/input/shape/shape_featureset.hpp | 2 +- .../input/shape/shape_index_featureset.hpp | 2 +- plugins/input/sqlite/sqlite_datasource.hpp | 2 +- src/conversions.cpp | 2 +- src/expression.cpp | 2 + src/expression_grammar.cpp | 16 ++ src/params.cpp | 2 +- src/parse_path.cpp | 97 +++++++++++ src/raster_colorizer.cpp | 2 +- src/transform_expression_grammar.cpp | 5 +- 36 files changed, 173 insertions(+), 307 deletions(-) diff --git a/include/mapnik/attribute.hpp b/include/mapnik/attribute.hpp index d7c1c0e8c..4247e6b49 100644 --- a/include/mapnik/attribute.hpp +++ b/include/mapnik/attribute.hpp @@ -24,7 +24,7 @@ #define MAPNIK_ATTRIBUTE_HPP // mapnik -#include +#include #include // stl diff --git a/include/mapnik/expression.hpp b/include/mapnik/expression.hpp index 18a8903d4..c1894ae01 100644 --- a/include/mapnik/expression.hpp +++ b/include/mapnik/expression.hpp @@ -25,8 +25,10 @@ // mapnik #include -#include -#include +#include + +// boost +#include // stl #include @@ -35,13 +37,14 @@ namespace mapnik { +// fwd declare to reduce compile time +template struct expression_grammar; typedef boost::shared_ptr expression_ptr; typedef std::set expression_set; MAPNIK_DECL expression_ptr parse_expression (std::string const& wkt, std::string const& encoding = "UTF8"); -MAPNIK_DECL expression_ptr parse_expression (std::string const& wkt, - mapnik::expression_grammar const& g); +MAPNIK_DECL expression_ptr parse_expression (std::string const& wkt, mapnik::expression_grammar const& g); } diff --git a/include/mapnik/expression_grammar.hpp b/include/mapnik/expression_grammar.hpp index 706a0bd21..28f2c8a30 100644 --- a/include/mapnik/expression_grammar.hpp +++ b/include/mapnik/expression_grammar.hpp @@ -24,29 +24,22 @@ #define MAPNIK_EXPRESSIONS_GRAMMAR_HPP // mapnik -#include +#include #include #include -// boost -#include -#include -#include - // spirit2 -#include -#include - -// fusion -#include +#include // for qi +#include // for grammar +#include // for rule +#include // for int_parser +#include // for real_parser +#include +#include +#include // for locals // phoenix -#include -#include -#include -#include -#include -#include +#include namespace mapnik { diff --git a/include/mapnik/expression_node.hpp b/include/mapnik/expression_node.hpp index 56b70a9ef..104341aa4 100644 --- a/include/mapnik/expression_node.hpp +++ b/include/mapnik/expression_node.hpp @@ -26,6 +26,7 @@ // mapnik #include #include +#include // boost #include @@ -33,167 +34,11 @@ #include #endif #include -#include #include namespace mapnik { -namespace tags { -struct negate -{ - static const char* str() - { - return "-"; - } -}; - -struct plus -{ - static const char* str() - { - return "+"; - } -}; - -struct minus -{ - static const char* str() - { - return "-"; - } -}; - -struct mult -{ - static const char* str() - { - return "*"; - } -}; - -struct div -{ - static const char* str() - { - return "/"; - } -}; - - -struct mod -{ - static const char* str() - { - return "%"; - } -}; - -struct less -{ - static const char* str() - { - return "<"; - } -}; - -struct less_equal -{ - static const char* str() - { - return "<="; - } -}; - -struct greater -{ - static const char* str() - { - return ">"; - } -}; - -struct greater_equal -{ - static const char* str() - { - return ">="; - } -}; - -struct equal_to -{ - static const char* str() - { - return "="; - } -}; - -struct not_equal_to -{ - static const char* str() - { - return "!="; - } -}; - -struct logical_not -{ - static const char* str() - { - return "not "; - } -}; - -struct logical_and -{ - static const char* str() - { - return " and "; - } -}; - -struct logical_or -{ - static const char* str() - { - return " or "; - } -}; - -} // end operation tags - - -template struct binary_node; -template struct unary_node; -struct regex_match_node; -struct regex_replace_node; - -typedef mapnik::value value_type; - -typedef boost::variant < -value_type, -attribute, -geometry_type_attribute, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper >, -boost::recursive_wrapper, -boost::recursive_wrapper -> expr_node; - template struct make_op; template <> struct make_op { typedef std::negate type;}; template <> struct make_op { typedef std::plus type;}; diff --git a/include/mapnik/feature_factory.hpp b/include/mapnik/feature_factory.hpp index b3e91a64a..9a6574932 100644 --- a/include/mapnik/feature_factory.hpp +++ b/include/mapnik/feature_factory.hpp @@ -25,7 +25,7 @@ // mapnik #include -#include +#include // boost #include diff --git a/include/mapnik/params.hpp b/include/mapnik/params.hpp index a75bdcf83..79e0c9cd9 100644 --- a/include/mapnik/params.hpp +++ b/include/mapnik/params.hpp @@ -28,7 +28,7 @@ #include // mapnik -#include +#include // stl #include diff --git a/include/mapnik/parse_path.hpp b/include/mapnik/parse_path.hpp index 3d64e7d1d..d260bbf2c 100644 --- a/include/mapnik/parse_path.hpp +++ b/include/mapnik/parse_path.hpp @@ -25,121 +25,30 @@ // mapnik #include -#include -#include -#include #include -#include - -// boost -#include -#include -#include // stl #include -#include +#include namespace mapnik { +// fwd declare to reduce compile time +template struct path_expression_grammar; +class feature_impl; + MAPNIK_DECL path_expression_ptr parse_path(std::string const & str); MAPNIK_DECL path_expression_ptr parse_path(std::string const & str, path_expression_grammar const& g); -template struct path_processor { - typedef T feature_type; - struct path_visitor_ : boost::static_visitor - { - path_visitor_ (std::string & filename, feature_type const& f) - : filename_(filename), - feature_(f) {} - - void operator() (std::string const& token) const - { - filename_ += token; - } - - void operator() (attribute const& attr) const - { - // convert mapnik::value to std::string - value const& val = feature_.get(attr.name()); - filename_ += val.to_string(); - } - - std::string & filename_; - feature_type const& feature_; - }; - - struct to_string_ : boost::static_visitor - { - to_string_ (std::string & str) - : str_(str) {} - - void operator() (std::string const& token) const - { - str_ += token; - } - - void operator() (attribute const& attr) const - { - str_ += "["; - str_ += attr.name(); - str_ += "]"; - } - - std::string & str_; - }; - - template - struct collect_ : boost::static_visitor - { - collect_ (T1 & cont) - : cont_(cont) {} - - void operator() (std::string const& token) const - { - boost::ignore_unused_variable_warning(token); - } - - void operator() (attribute const& attr) const - { - cont_.insert(attr.name()); - } - - T1 & cont_; - }; - - static std::string evaluate(path_expression const& path,feature_type const& f) - { - std::string out; - path_visitor_ eval(out,f); - BOOST_FOREACH( mapnik::path_component const& token, path) - boost::apply_visitor(eval,token); - return out; - } - - static std::string to_string(path_expression const& path) - { - std::string str; - to_string_ visitor(str); - BOOST_FOREACH( mapnik::path_component const& token, path) - boost::apply_visitor(visitor,token); - return str; - } - - template - static void collect_attributes(path_expression const& path, T2 & names) - { - typedef T2 cont_type; - collect_ visitor(names); - BOOST_FOREACH( mapnik::path_component const& token, path) - boost::apply_visitor(visitor,token); - } + static std::string evaluate(path_expression const& path, feature_impl const& f); + static std::string to_string(path_expression const& path); + static void collect_attributes(path_expression const& path, std::set& names); }; -typedef mapnik::path_processor path_processor_type; +typedef mapnik::path_processor path_processor_type; } diff --git a/include/mapnik/path_expression_grammar.hpp b/include/mapnik/path_expression_grammar.hpp index 763f6bf54..a03511215 100644 --- a/include/mapnik/path_expression_grammar.hpp +++ b/include/mapnik/path_expression_grammar.hpp @@ -36,7 +36,7 @@ namespace mapnik { - + using namespace boost; namespace qi = boost::spirit::qi; namespace phoenix = boost::phoenix; diff --git a/include/mapnik/transform_expression_grammar.hpp b/include/mapnik/transform_expression_grammar.hpp index d389ec788..886ffaa1f 100644 --- a/include/mapnik/transform_expression_grammar.hpp +++ b/include/mapnik/transform_expression_grammar.hpp @@ -28,7 +28,7 @@ #include // spirit -#include +#include namespace mapnik { diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index 6e799d638..b98fdb188 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include // stl #include diff --git a/plugins/input/csv/csv_datasource.hpp b/plugins/input/csv/csv_datasource.hpp index c01caefe8..96931878c 100644 --- a/plugins/input/csv/csv_datasource.hpp +++ b/plugins/input/csv/csv_datasource.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include // boost #include diff --git a/plugins/input/gdal/gdal_datasource.cpp b/plugins/input/gdal/gdal_datasource.cpp index 82c2e6489..aefcfcef3 100644 --- a/plugins/input/gdal/gdal_datasource.cpp +++ b/plugins/input/gdal/gdal_datasource.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include diff --git a/plugins/input/geos/geos_datasource.cpp b/plugins/input/geos/geos_datasource.cpp index b26048759..ef38c79cd 100644 --- a/plugins/input/geos/geos_datasource.cpp +++ b/plugins/input/geos/geos_datasource.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include // boost #include diff --git a/plugins/input/occi/occi_datasource.cpp b/plugins/input/occi/occi_datasource.cpp index 72da797c0..b3e800dd6 100644 --- a/plugins/input/occi/occi_datasource.cpp +++ b/plugins/input/occi/occi_datasource.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include // boost #include diff --git a/plugins/input/occi/occi_datasource.hpp b/plugins/input/occi/occi_datasource.hpp index 92b1c8c08..18478f738 100644 --- a/plugins/input/occi/occi_datasource.hpp +++ b/plugins/input/occi/occi_datasource.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include // boost #include diff --git a/plugins/input/ogr/ogr_featureset.cpp b/plugins/input/ogr/ogr_featureset.cpp index b2cd7ba56..afa5bc40e 100644 --- a/plugins/input/ogr/ogr_featureset.cpp +++ b/plugins/input/ogr/ogr_featureset.cpp @@ -22,7 +22,7 @@ // mapnik #include -#include +#include #include #include #include diff --git a/plugins/input/ogr/ogr_index_featureset.cpp b/plugins/input/ogr/ogr_index_featureset.cpp index 9fa9d75e7..4823b0a76 100644 --- a/plugins/input/ogr/ogr_index_featureset.cpp +++ b/plugins/input/ogr/ogr_index_featureset.cpp @@ -21,7 +21,7 @@ *****************************************************************************/ // mapnik -#include +#include #include #include #include diff --git a/plugins/input/osm/osm.h b/plugins/input/osm/osm.h index 0227c9f61..f4db4c65e 100644 --- a/plugins/input/osm/osm.h +++ b/plugins/input/osm/osm.h @@ -23,7 +23,7 @@ #ifndef OSM_H #define OSM_H -#include +#include #include #include #include diff --git a/plugins/input/osm/osmparser.h b/plugins/input/osm/osmparser.h index acbe2ceb2..4e8d0f3d3 100644 --- a/plugins/input/osm/osmparser.h +++ b/plugins/input/osm/osmparser.h @@ -23,7 +23,7 @@ #ifndef OSMPARSER_H #define OSMPARSER_H -#include +#include #include #include #include diff --git a/plugins/input/postgis/build.py b/plugins/input/postgis/build.py index 8f79fa408..271de7caf 100644 --- a/plugins/input/postgis/build.py +++ b/plugins/input/postgis/build.py @@ -41,7 +41,7 @@ plugin_env['LIBS'].append('mapnik') plugin_env['LIBS'].append('boost_system%s' % env['BOOST_APPEND']) plugin_env['LIBS'].append(env['ICU_LIB_NAME']) if env['THREADING'] == 'multi': - plugin_env['LIBS'].append('boost_thread%s' % env['BOOST_APPEND']) + plugin_env['LIBS'].append('boost_thread%s' % env['BOOST_APPEND']) if env['RUNTIME_LINK'] == 'static': #cmd = 'pg_config --libs' diff --git a/plugins/input/postgis/postgis_datasource.cpp b/plugins/input/postgis/postgis_datasource.cpp index 21bf69d31..7376cca31 100644 --- a/plugins/input/postgis/postgis_datasource.cpp +++ b/plugins/input/postgis/postgis_datasource.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include // boost #include diff --git a/plugins/input/postgis/postgis_datasource.hpp b/plugins/input/postgis/postgis_datasource.hpp index d4ed1e9be..d0f5a2beb 100644 --- a/plugins/input/postgis/postgis_datasource.hpp +++ b/plugins/input/postgis/postgis_datasource.hpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include // boost #include diff --git a/plugins/input/postgis/postgis_featureset.cpp b/plugins/input/postgis/postgis_featureset.cpp index 9ec75aa4e..b8c146dad 100644 --- a/plugins/input/postgis/postgis_featureset.cpp +++ b/plugins/input/postgis/postgis_featureset.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/plugins/input/shape/dbfile.cpp b/plugins/input/shape/dbfile.cpp index ee7578f33..feb6ba8ea 100644 --- a/plugins/input/shape/dbfile.cpp +++ b/plugins/input/shape/dbfile.cpp @@ -20,7 +20,7 @@ * *****************************************************************************/ // mapnik -#include +#include #include #include #include diff --git a/plugins/input/shape/shape_datasource.cpp b/plugins/input/shape/shape_datasource.cpp index f62e26ac4..a98121ec8 100644 --- a/plugins/input/shape/shape_datasource.cpp +++ b/plugins/input/shape/shape_datasource.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include // stl #include diff --git a/plugins/input/shape/shape_datasource.hpp b/plugins/input/shape/shape_datasource.hpp index 43d2572e9..9f98e3065 100644 --- a/plugins/input/shape/shape_datasource.hpp +++ b/plugins/input/shape/shape_datasource.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include // boost #include diff --git a/plugins/input/shape/shape_featureset.hpp b/plugins/input/shape/shape_featureset.hpp index bb362de13..b373c1377 100644 --- a/plugins/input/shape/shape_featureset.hpp +++ b/plugins/input/shape/shape_featureset.hpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include "shape_io.hpp" diff --git a/plugins/input/shape/shape_index_featureset.hpp b/plugins/input/shape/shape_index_featureset.hpp index 1f8a81944..5863b3246 100644 --- a/plugins/input/shape/shape_index_featureset.hpp +++ b/plugins/input/shape/shape_index_featureset.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include // boost #include diff --git a/plugins/input/sqlite/sqlite_datasource.hpp b/plugins/input/sqlite/sqlite_datasource.hpp index 5d504ceaf..37241fbab 100644 --- a/plugins/input/sqlite/sqlite_datasource.hpp +++ b/plugins/input/sqlite/sqlite_datasource.hpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include // boost #include diff --git a/src/conversions.cpp b/src/conversions.cpp index 3887b32ae..8c93e39b2 100644 --- a/src/conversions.cpp +++ b/src/conversions.cpp @@ -22,7 +22,7 @@ // mapnik #include -#include +#include // boost #include diff --git a/src/expression.cpp b/src/expression.cpp index e30505c70..3210e16fb 100644 --- a/src/expression.cpp +++ b/src/expression.cpp @@ -24,7 +24,9 @@ #include #include #include +#include #include +#include // boost #include diff --git a/src/expression_grammar.cpp b/src/expression_grammar.cpp index 28d9b0444..110240637 100644 --- a/src/expression_grammar.cpp +++ b/src/expression_grammar.cpp @@ -20,7 +20,23 @@ * *****************************************************************************/ +// mapnik #include +#include +#include +#include + +// boost +#include +#include +#include +#include + +// fwd declare +namespace mapnik { + struct attribute; + struct geometry_type_attribute; +} namespace mapnik { diff --git a/src/params.cpp b/src/params.cpp index ab744a08a..74ef19fbb 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -23,7 +23,7 @@ // mapnik #include #include -#include +#include // boost #include diff --git a/src/parse_path.cpp b/src/parse_path.cpp index 4d815e795..ba42624a0 100644 --- a/src/parse_path.cpp +++ b/src/parse_path.cpp @@ -23,6 +23,15 @@ #include #include +#include +#include +#include +#include +#include + +// boost +#include +#include #include namespace mapnik { @@ -51,4 +60,92 @@ path_expression_ptr parse_path(std::string const& str, } } +namespace path_processor_detail { + struct path_visitor_ : boost::static_visitor + { + path_visitor_ (std::string & filename, feature_impl const& f) + : filename_(filename), + feature_(f) {} + + void operator() (std::string const& token) const + { + filename_ += token; + } + + void operator() (attribute const& attr) const + { + // convert mapnik::value to std::string + value const& val = feature_.get(attr.name()); + filename_ += val.to_string(); + } + + std::string & filename_; + feature_impl const& feature_; + }; + + struct to_string_ : boost::static_visitor + { + to_string_ (std::string & str) + : str_(str) {} + + void operator() (std::string const& token) const + { + str_ += token; + } + + void operator() (attribute const& attr) const + { + str_ += "["; + str_ += attr.name(); + str_ += "]"; + } + + std::string & str_; + }; + + struct collect_ : boost::static_visitor + { + collect_ (std::set & cont) + : cont_(cont) {} + + void operator() (std::string const& token) const + { + boost::ignore_unused_variable_warning(token); + } + + void operator() (attribute const& attr) const + { + cont_.insert(attr.name()); + } + + std::set & cont_; + }; +} + +std::string path_processor::evaluate(path_expression const& path,feature_impl const& f) +{ + std::string out; + path_processor_detail::path_visitor_ eval(out,f); + BOOST_FOREACH( mapnik::path_component const& token, path) + boost::apply_visitor(eval,token); + return out; +} + +std::string path_processor::to_string(path_expression const& path) +{ + std::string str; + path_processor_detail::to_string_ visitor(str); + BOOST_FOREACH( mapnik::path_component const& token, path) + boost::apply_visitor(visitor,token); + return str; +} + +void path_processor::collect_attributes(path_expression const& path, std::set& names) +{ + path_processor_detail::collect_ visitor(names); + BOOST_FOREACH( mapnik::path_component const& token, path) + boost::apply_visitor(visitor,token); +} + + } diff --git a/src/raster_colorizer.cpp b/src/raster_colorizer.cpp index 3c9120f4a..817999921 100644 --- a/src/raster_colorizer.cpp +++ b/src/raster_colorizer.cpp @@ -22,7 +22,7 @@ // mapnik #include -#include +#include #include #include #include diff --git a/src/transform_expression_grammar.cpp b/src/transform_expression_grammar.cpp index 05f4e44a1..03e4a553e 100644 --- a/src/transform_expression_grammar.cpp +++ b/src/transform_expression_grammar.cpp @@ -25,10 +25,11 @@ // boost #include - -// spirit +#include +#include #include + namespace mapnik { namespace qi = boost::spirit::qi;