From 47dc1e197b54b944ada43e8ecb86525d46e00434 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Wed, 16 Dec 2009 20:02:06 +0000 Subject: [PATCH] + merge mapnik2 to trunk --- CHANGELOG | 2 + SConstruct | 17 +- bindings/python/mapnik/__init__.py | 42 +- bindings/python/mapnik/ogcserver/common.py | 4 +- bindings/python/mapnik/ogcserver/wms130.py | 4 +- bindings/python/mapnik_datasource.cpp | 2 +- bindings/python/mapnik_envelope.cpp | 114 +- bindings/python/mapnik_expression.cpp | 86 + bindings/python/mapnik_feature.cpp | 405 +++-- bindings/python/mapnik_image.cpp | 55 +- bindings/python/mapnik_image_view.cpp | 18 +- bindings/python/mapnik_layer.cpp | 74 +- .../python/mapnik_line_pattern_symbolizer.cpp | 20 +- bindings/python/mapnik_map.cpp | 38 +- bindings/python/mapnik_point_symbolizer.cpp | 29 +- .../mapnik_polygon_pattern_symbolizer.cpp | 15 +- bindings/python/mapnik_proj_transform.cpp | 8 +- bindings/python/mapnik_projection.cpp | 8 +- bindings/python/mapnik_python.cpp | 25 +- bindings/python/mapnik_query.cpp | 6 +- bindings/python/mapnik_rule.cpp | 26 +- bindings/python/mapnik_shield_symbolizer.cpp | 20 +- bindings/python/mapnik_text_symbolizer.cpp | 15 +- bindings/python/mapnik_view_transform.cpp | 8 +- boost/property_tree/cmdline_parser.hpp | 85 - .../detail/file_parser_error.hpp | 88 - .../detail/info_parser_error.hpp | 32 - .../property_tree/detail/info_parser_read.hpp | 369 ---- .../detail/info_parser_utils.hpp | 32 - .../detail/info_parser_write.hpp | 131 -- .../detail/json_parser_error.hpp | 33 - .../property_tree/detail/json_parser_read.hpp | 316 ---- .../detail/json_parser_write.hpp | 163 -- .../detail/ptree_implementation.hpp | 1002 ----------- .../property_tree/detail/ptree_interface.hpp | 198 --- boost/property_tree/detail/ptree_utils.hpp | 72 - .../property_tree/detail/xml_parser_error.hpp | 33 - .../property_tree/detail/xml_parser_flags.hpp | 26 - .../detail/xml_parser_read_spirit.hpp | 737 -------- .../detail/xml_parser_read_tinyxml.hpp | 82 - .../property_tree/detail/xml_parser_utils.hpp | 119 -- .../property_tree/detail/xml_parser_write.hpp | 145 -- boost/property_tree/info_parser.hpp | 77 - boost/property_tree/ini_parser.hpp | 196 --- boost/property_tree/json_parser.hpp | 76 - boost/property_tree/ptree.hpp | 16 - boost/property_tree/ptree_fwd.hpp | 54 - boost/property_tree/registry_parser.hpp | 520 ------ boost/property_tree/xml_parser.hpp | 86 - demo/c++/rundemo.cpp | 44 +- demo/python/rundemo.py | 22 +- demo/test/charplacement.py | 2 +- demo/test/displacement.py | 2 +- demo/test/overlap.py | 2 +- demo/test/textspacing.py | 2 +- demo/viewer/layerlistmodel.cpp | 10 +- demo/viewer/layerlistmodel.hpp | 2 +- demo/viewer/layerwidget.cpp | 2 +- demo/viewer/main.cpp | 4 +- demo/viewer/mainwindow.cpp | 4 +- demo/viewer/mainwindow.hpp | 2 +- demo/viewer/mapwidget.cpp | 33 +- demo/viewer/mapwidget.hpp | 4 +- demo/viewer/styles_model.cpp | 18 +- demo/viewer/viewer.pro | 8 +- include/mapnik/agg_renderer.hpp | 4 +- include/mapnik/arrow.hpp | 4 +- include/mapnik/attribute.hpp | 222 --- include/mapnik/attribute_collector.hpp | 202 ++- include/mapnik/boolean_filter.hpp | 77 - include/mapnik/{envelope.hpp => box2d.hpp} | 50 +- include/mapnik/cairo_renderer.hpp | 4 +- include/mapnik/color.hpp | 1 - include/mapnik/color_factory.hpp | 78 +- include/mapnik/comparison.hpp | 149 -- include/mapnik/css_color_grammar.hpp | 338 ++++ include/mapnik/css_color_parser.hpp | 442 ----- include/mapnik/ctrans.hpp | 16 +- include/mapnik/datasource.hpp | 2 +- include/mapnik/expression.hpp | 132 -- include/mapnik/expression_evaluator.hpp | 93 + include/mapnik/expression_grammar.hpp | 244 +++ include/mapnik/expression_node.hpp | 353 ++++ ...lter_visitor.hpp => expression_string.hpp} | 29 +- include/mapnik/feature.hpp | 242 +-- include/mapnik/feature_style_processor.hpp | 351 ++-- include/mapnik/filter.hpp | 90 - include/mapnik/filter_expression.hpp | 67 - include/mapnik/filter_factory.hpp | 51 +- include/mapnik/filter_parser.hpp | 548 ------ include/mapnik/font_engine_freetype.hpp | 8 +- include/mapnik/font_set.hpp | 12 +- include/mapnik/geom_util.hpp | 12 +- include/mapnik/geometry.hpp | 4 +- include/mapnik/graphics.hpp | 708 ++++---- .../mapnik/image_cache.hpp | 58 +- include/mapnik/image_data.hpp | 4 +- include/mapnik/image_reader.hpp | 48 +- include/mapnik/image_util.hpp | 45 +- include/mapnik/label_collision_detector.hpp | 44 +- include/mapnik/layer.hpp | 24 +- include/mapnik/line_pattern_symbolizer.hpp | 6 +- include/mapnik/logical.hpp | 172 -- include/mapnik/map.hpp | 44 +- include/mapnik/markers_converter.hpp | 4 +- include/mapnik/math_expr.hpp | 141 -- include/mapnik/memory_datasource.hpp | 2 +- include/mapnik/memory_featureset.hpp | 4 +- include/mapnik/octree.hpp | 1 - include/mapnik/path_expression_grammar.hpp | 217 +++ include/mapnik/placement_finder.hpp | 146 +- include/mapnik/png_io.hpp | 22 +- include/mapnik/point_symbolizer.hpp | 37 +- include/mapnik/polygon_pattern_symbolizer.hpp | 22 +- include/mapnik/projection.hpp | 2 +- include/mapnik/ptree_helpers.hpp | 12 +- include/mapnik/quad_tree.hpp | 36 +- include/mapnik/query.hpp | 12 +- include/mapnik/raster.hpp | 6 +- include/mapnik/regex_filter.hpp | 86 - include/mapnik/rule.hpp | 385 +++-- include/mapnik/shield_symbolizer.hpp | 48 +- include/mapnik/spatial.hpp | 153 -- include/mapnik/symbolizer.hpp | 43 +- include/mapnik/text_symbolizer.hpp | 29 +- include/mapnik/value.hpp | 54 +- include/mapnik/vertex_transform.hpp | 4 +- include/mapnik/wall_clock_timer.hpp | 7 +- plugins/input/gdal/gdal_datasource.cpp | 9 +- plugins/input/gdal/gdal_datasource.hpp | 4 +- plugins/input/gdal/gdal_featureset.cpp | 62 +- plugins/input/kismet/kismet_datasource.cpp | 8 +- plugins/input/kismet/kismet_datasource.hpp | 4 +- plugins/input/kismet/kismet_featureset.cpp | 2 +- plugins/input/occi/occi_datasource.cpp | 6 +- plugins/input/occi/occi_datasource.hpp | 6 +- plugins/input/occi/occi_featureset.cpp | 4 +- plugins/input/ogr/ogr_converter.cpp | 4 +- plugins/input/ogr/ogr_datasource.cpp | 4 +- plugins/input/ogr/ogr_datasource.hpp | 4 +- plugins/input/ogr/ogr_featureset.cpp | 6 +- plugins/input/ogr/ogr_featureset.hpp | 2 +- plugins/input/ogr/ogr_index.hpp | 10 +- plugins/input/ogr/ogr_index_featureset.cpp | 4 +- plugins/input/osm/demo/MapSource.cpp | 32 +- plugins/input/osm/osm_datasource.cpp | 4 +- plugins/input/osm/osm_datasource.hpp | 8 +- plugins/input/osm/osm_featureset.cpp | 2 +- plugins/input/osm/osm_featureset.hpp | 6 +- plugins/input/osm/render.cpp | 10 +- plugins/input/postgis/postgis.cpp | 21 +- plugins/input/postgis/postgis.hpp | 12 +- plugins/input/raster/raster_datasource.cpp | 10 +- plugins/input/raster/raster_datasource.hpp | 6 +- plugins/input/raster/raster_featureset.cpp | 14 +- plugins/input/raster/raster_featureset.hpp | 16 +- plugins/input/raster/raster_info.cpp | 2 +- plugins/input/raster/raster_info.hpp | 8 +- plugins/input/rasterlite/Makefile.am | 32 + plugins/input/rasterlite/SConscript | 42 + .../rasterlite/rasterlite_datasource.cpp | 183 ++ .../rasterlite/rasterlite_datasource.hpp | 55 + .../rasterlite/rasterlite_featureset.cpp | 154 ++ .../rasterlite/rasterlite_featureset.hpp | 50 + .../input/rasterlite/rasterlite_include.hpp | 32 + plugins/input/shape/shape.cpp | 4 +- plugins/input/shape/shape.hpp | 6 +- plugins/input/shape/shape_featureset.hpp | 6 +- .../input/shape/shape_index_featureset.hpp | 2 +- plugins/input/shape/shape_io.cpp | 2 +- plugins/input/shape/shape_io.hpp | 4 +- plugins/input/shape/shapefile.hpp | 6 +- plugins/input/shape/shp_index.hpp | 10 +- plugins/input/sqlite/sqlite_datasource.cpp | 6 +- plugins/input/sqlite/sqlite_datasource.hpp | 4 +- plugins/input/sqlite/sqlite_featureset.cpp | 4 +- src/SConscript | 4 +- src/agg_renderer.cpp | 1275 +++++++------- src/arrow.cpp | 4 +- src/{envelope.cpp => box2d.cpp} | 70 +- src/cairo_renderer.cpp | 1509 +++++++++-------- src/color.cpp | 8 +- src/expression_string.cpp | 112 ++ src/filter_factory.cpp | 47 +- src/font_set.cpp | 18 +- src/graphics.cpp | 24 +- src/image_cache.cpp | 95 ++ src/image_reader.cpp | 39 +- src/image_util.cpp | 19 +- src/layer.cpp | 66 +- src/libxml2_loader.cpp | 6 +- src/line_pattern_symbolizer.cpp | 16 +- src/load_map.cpp | 89 +- src/map.cpp | 46 +- src/memory_datasource.cpp | 8 +- src/placement_finder.cpp | 52 +- src/png_reader.cpp | 40 +- src/point_symbolizer.cpp | 18 +- src/polygon_pattern_symbolizer.cpp | 23 +- src/save_map.cpp | 67 +- src/shield_symbolizer.cpp | 92 +- src/symbolizer.cpp | 50 +- src/text_symbolizer.cpp | 822 ++++----- src/tiff_reader.cpp | 53 +- src/unicode.cpp | 202 +-- tests/data/broken_maps/mapnik_min_version.xml | 2 - tests/data/good_maps/entities.xml | 22 - tests/data/good_maps/mapnik_min_version.xml | 2 - tests/data/inc/entities.xml.inc | 7 - tests/data/inc/expected.xml | 0 tests/data/inc/fontset-settings.xml.inc | 12 - tests/data/inc/scales.xml.inc | 37 - tests/python_tests/object_test.py | 12 +- tests/python_tests/projection_test.py | 4 +- tests/python_tests/render_test.py | 2 +- utils/ogrindex/ogrindex.cpp | 6 +- utils/pgsql2sqlite/pgsql2sqlite.hpp | 4 +- utils/shapeindex/SConscript | 2 +- utils/shapeindex/quadtree.hpp | 30 +- utils/shapeindex/shapeindex.cpp | 10 +- 220 files changed, 6656 insertions(+), 11603 deletions(-) create mode 100644 bindings/python/mapnik_expression.cpp delete mode 100644 boost/property_tree/cmdline_parser.hpp delete mode 100644 boost/property_tree/detail/file_parser_error.hpp delete mode 100644 boost/property_tree/detail/info_parser_error.hpp delete mode 100644 boost/property_tree/detail/info_parser_read.hpp delete mode 100644 boost/property_tree/detail/info_parser_utils.hpp delete mode 100644 boost/property_tree/detail/info_parser_write.hpp delete mode 100644 boost/property_tree/detail/json_parser_error.hpp delete mode 100644 boost/property_tree/detail/json_parser_read.hpp delete mode 100644 boost/property_tree/detail/json_parser_write.hpp delete mode 100644 boost/property_tree/detail/ptree_implementation.hpp delete mode 100644 boost/property_tree/detail/ptree_interface.hpp delete mode 100644 boost/property_tree/detail/ptree_utils.hpp delete mode 100644 boost/property_tree/detail/xml_parser_error.hpp delete mode 100644 boost/property_tree/detail/xml_parser_flags.hpp delete mode 100644 boost/property_tree/detail/xml_parser_read_spirit.hpp delete mode 100644 boost/property_tree/detail/xml_parser_read_tinyxml.hpp delete mode 100644 boost/property_tree/detail/xml_parser_utils.hpp delete mode 100644 boost/property_tree/detail/xml_parser_write.hpp delete mode 100644 boost/property_tree/info_parser.hpp delete mode 100644 boost/property_tree/ini_parser.hpp delete mode 100644 boost/property_tree/json_parser.hpp delete mode 100644 boost/property_tree/ptree.hpp delete mode 100644 boost/property_tree/ptree_fwd.hpp delete mode 100644 boost/property_tree/registry_parser.hpp delete mode 100644 boost/property_tree/xml_parser.hpp delete mode 100644 include/mapnik/attribute.hpp delete mode 100644 include/mapnik/boolean_filter.hpp rename include/mapnik/{envelope.hpp => box2d.hpp} (67%) delete mode 100644 include/mapnik/comparison.hpp create mode 100644 include/mapnik/css_color_grammar.hpp delete mode 100644 include/mapnik/css_color_parser.hpp delete mode 100644 include/mapnik/expression.hpp create mode 100644 include/mapnik/expression_evaluator.hpp create mode 100644 include/mapnik/expression_grammar.hpp create mode 100644 include/mapnik/expression_node.hpp rename include/mapnik/{filter_visitor.hpp => expression_string.hpp} (59%) delete mode 100644 include/mapnik/filter.hpp delete mode 100644 include/mapnik/filter_expression.hpp delete mode 100644 include/mapnik/filter_parser.hpp rename bindings/python/mapnik_filter.cpp => include/mapnik/image_cache.hpp (50%) delete mode 100644 include/mapnik/logical.hpp delete mode 100644 include/mapnik/math_expr.hpp create mode 100644 include/mapnik/path_expression_grammar.hpp delete mode 100644 include/mapnik/regex_filter.hpp delete mode 100644 include/mapnik/spatial.hpp create mode 100644 plugins/input/rasterlite/Makefile.am create mode 100644 plugins/input/rasterlite/SConscript create mode 100644 plugins/input/rasterlite/rasterlite_datasource.cpp create mode 100644 plugins/input/rasterlite/rasterlite_datasource.hpp create mode 100644 plugins/input/rasterlite/rasterlite_featureset.cpp create mode 100644 plugins/input/rasterlite/rasterlite_featureset.hpp create mode 100644 plugins/input/rasterlite/rasterlite_include.hpp rename src/{envelope.cpp => box2d.cpp} (78%) create mode 100644 src/expression_string.cpp create mode 100644 src/image_cache.cpp delete mode 100644 tests/data/broken_maps/mapnik_min_version.xml delete mode 100644 tests/data/good_maps/entities.xml delete mode 100644 tests/data/good_maps/mapnik_min_version.xml delete mode 100644 tests/data/inc/entities.xml.inc delete mode 100644 tests/data/inc/expected.xml delete mode 100644 tests/data/inc/fontset-settings.xml.inc delete mode 100644 tests/data/inc/scales.xml.inc diff --git a/CHANGELOG b/CHANGELOG index 2e34b8f59..f4aaab9c4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,8 @@ Mapnik 0.7.0 Release - Gdal Plugin: Add support for Gdal overviews, enabling fast loading of > 1GB rasters (#54) +- Rasterlite Plugin: Experimental support for Rasterlite, to practically use sqlite database with wavelet compressed rasters + - PostGIS: Added an optional 'geometry_table' parameter. This is used by Mapnik to look up metadata in the geometry_columns and calculate extents (when the 'geometry_field' and 'srid' parameters are not supplied). If 'geometry_table' is not specified Mapnik will attempt to determine the name of the table to query based diff --git a/SConstruct b/SConstruct index 9061a1e5c..57c922a0e 100644 --- a/SConstruct +++ b/SConstruct @@ -93,6 +93,7 @@ PLUGINS = { # plugins with external dependencies 'ogr': {'default':False,'path':None,'inc':'ogrsf_frmts.h','lib':'gdal','lang':'C++'}, 'occi': {'default':False,'path':'OCCI','inc':'occi.h','lib':'ociei','lang':'C++'}, 'sqlite': {'default':False,'path':'SQLITE','inc':'sqlite3.h','lib':'sqlite3','lang':'C'}, + 'rasterlite': {'default':False,'path':'RASTERLITE','inc':['sqlite3.h','rasterlite.h'],'lib':'rasterlite','lang':'C'}, # plugins without external dependencies requiring CheckLibWithHeader... # note: osm plugin does depend on libxml2 @@ -169,6 +170,8 @@ opts.AddVariables( PathVariable('OCCI_LIBS', 'Search path for OCCI library files', '/usr/lib/oracle/10.2.0.3/client/'+ LIBDIR_SCHEMA, PathVariable.PathAccept), PathVariable('SQLITE_INCLUDES', 'Search path for SQLITE include files', '/usr/include/', PathVariable.PathAccept), PathVariable('SQLITE_LIBS', 'Search path for SQLITE library files', '/usr/' + LIBDIR_SCHEMA, PathVariable.PathAccept), + PathVariable('RASTERLITE_INCLUDES', 'Search path for RASTERLITE include files', '/usr/include/', PathVariable.PathAccept), + PathVariable('RASTERLITE_LIBS', 'Search path for RASTERLITE library files', '/usr/' + LIBDIR_SCHEMA, PathVariable.PathAccept), # Other variables BoolVariable('SHAPE_MEMORY_MAPPED_FILE', 'Utilize memory-mapped files in Shapefile Plugin (higher memory usage, better performance)', 'True'), @@ -375,7 +378,7 @@ def FindBoost(context, prefixes, thread_flag): search_lib = 'libboost_thread' else: search_lib = 'libboost_filesystem' - + prefixes.insert(0,os.path.dirname(env['BOOST_INCLUDES'])) prefixes.insert(0,os.path.dirname(env['BOOST_LIBS'])) for searchDir in prefixes: @@ -698,11 +701,11 @@ if not preconfigured: BOOST_LIBSHEADERS.append(['thread', 'boost/thread/mutex.hpp', True]) # if the user is not setting custom boost configuration - # enforce boost version greater than or equal to 1.34 - if not conf.CheckBoost('1.34'): - color_print (1,'Boost version 1.34 or greater is requred') + # enforce boost version greater than or equal to 1.41 + if not conf.CheckBoost('1.41'): + color_print (1,'Boost version 1.41 or greater is requred') if not env['BOOST_VERSION']: - env['MISSING_DEPS'].append('boost version >=1.34') + env['MISSING_DEPS'].append('boost version >=1.41') else: color_print (4,'Found boost lib version... %s' % boost_lib_version_from_header ) @@ -783,7 +786,7 @@ if not preconfigured: if env['SKIPPED_DEPS']: color_print(4,'\nAlso, these optional dependencies were not found:\n - %s' % '\n - '.join(env['SKIPPED_DEPS'])) color_print(4,"\nSet custom paths to these libraries and header files on the command-line or in a file called '%s'" % SCONS_LOCAL_CONFIG) - color_print(4," ie. $ python scons/scons.py BOOST_INCLUDES=/usr/local/include/boost-1_37 BOOST_LIBS=/usr/local/lib") + color_print(4," ie. $ python scons/scons.py BOOST_INCLUDES=/usr/local/include BOOST_LIBS=/usr/local/lib") color_print(4, "\nOnce all required dependencies are found a local '%s' will be saved and then install:" % SCONS_LOCAL_CONFIG) color_print(4," $ sudo python scons/scons.py install") color_print(4,"\nTo view available path variables:\n $ python scons/scons.py --help or -h") @@ -866,7 +869,7 @@ if not preconfigured: env.Append(CXXFLAGS = common_cxx_flags + '-O %s' % ndebug_flags) else: # Common flags for GCC. - gcc_cxx_flags = '-ansi -Wall %s -ftemplate-depth-100 %s' % (pthread, common_cxx_flags) + gcc_cxx_flags = '-ansi -Wall %s -ftemplate-depth-200 %s' % (pthread, common_cxx_flags) if env['DEBUG']: env.Append(CXXFLAGS = gcc_cxx_flags + '-O0 -fno-inline %s' % debug_flags) diff --git a/bindings/python/mapnik/__init__.py b/bindings/python/mapnik/__init__.py index 50aa277f8..4c01c112c 100644 --- a/bindings/python/mapnik/__init__.py +++ b/bindings/python/mapnik/__init__.py @@ -137,12 +137,12 @@ class _Coord(Coord,_injector): """ return inverse_(self, projection) -class _Envelope(Envelope,_injector): +class _Box2d(Box2d,_injector): """ Represents a spatial envelope (i.e. bounding box). - Following operators are defined for Envelope: + Following operators are defined for Box2d: Addition: e1 + e2 is equvalent to e1.expand_to_include(e2) but yields @@ -165,7 +165,7 @@ class _Envelope(Envelope,_injector): Equality: two envelopes are equal if their corner points are equal. """ def __repr__(self): - return 'Envelope(%s,%s,%s,%s)' % \ + return 'Box2d(%s,%s,%s,%s)' % \ (self.minx,self.miny,self.maxx,self.maxy) def forward(self, projection): """ @@ -193,21 +193,21 @@ class _Projection(Projection,_injector): return "Projection('%s')" % self.params() def forward(self,obj): """ - Projects the given object (Envelope or Coord) + Projects the given object (Box2d or Coord) from the geographic space into the cartesian space. See also: - Envelope.forward(self, projection), + Box2d.forward(self, projection), Coord.forward(self, projection). """ return forward_(obj,self) def inverse(self,obj): """ - Projects the given object (Envelope or Coord) + Projects the given object (Box2d or Coord) from the cartesian space into the geographic space. See also: - Envelope.inverse(self, projection), + Box2d.inverse(self, projection), Coord.inverse(self, projection). """ return inverse_(obj,self) @@ -337,7 +337,7 @@ def Raster(**keywords): hix -- highest (max) x/longitude of tiff extent hiy -- highest (max) y/latitude of tiff extent - Hint: lox,loy,hix,hiy make a Mapnik Envelope + Hint: lox,loy,hix,hiy make a Mapnik Box2d Optional keyword arguments: base -- path prefix (default None) @@ -450,6 +450,26 @@ def SQLite(**keywords): keywords['type'] = 'sqlite' return CreateDatasource(keywords) +def Rasterlite(**keywords): + """Create a Rasterlite Datasource. + + Required keyword arguments: + file -- path to Rasterlite database file + table -- table name or subselect query + + Optional keyword arguments: + base -- path prefix (default None) + extent -- manually specified data extent (comma delimited string, default None) + + >>> from mapnik import Rasterlite, Layer + >>> rasterlite = Rasterlite(base='/home/mapnik/data',file='osm.db',table='osm',extent='-20037508,-19929239,20037508,19929239') + >>> lyr = Layer('Rasterlite Layer') + >>> lyr.datasource = rasterlite + + """ + keywords['type'] = 'rasterlite' + return CreateDatasource(keywords) + def Osm(**keywords): """Create a Osm Datasource. @@ -524,7 +544,7 @@ __all__ = [ # classes 'Color', 'Coord', 'DatasourceCache', - 'Envelope', + 'Box2d', 'Feature', 'Featureset', 'FontEngine', 'Geometry2d', 'Image', 'ImageView', @@ -537,7 +557,6 @@ __all__ = [ 'PolygonPatternSymbolizer', 'PolygonSymbolizer', 'ProjTransform', 'Projection', - 'Properties', 'Query', 'RasterSymbolizer', 'Rule', 'Rules', @@ -562,7 +581,8 @@ __all__ = [ 'mapnik_version_string', 'mapnik_version', 'mapnik_svn_revision', 'has_cairo', 'has_pycairo', # factory methods - 'Filter', + 'Expression', + 'PathExpression', # load/save/render 'load_map', 'load_map_from_string', 'save_map', 'save_map_to_string', 'render', 'render_tile_to_file', 'render_to_file', diff --git a/bindings/python/mapnik/ogcserver/common.py b/bindings/python/mapnik/ogcserver/common.py index 3d458ef63..c55a042f2 100644 --- a/bindings/python/mapnik/ogcserver/common.py +++ b/bindings/python/mapnik/ogcserver/common.py @@ -22,7 +22,7 @@ """Core OGCServer classes and functions.""" from exceptions import OGCException, ServerConfigurationError -from mapnik import Map, Color, Envelope, render, Image, Layer, Style, Projection as MapnikProjection, Coord +from mapnik import Map, Color, Box2d, render, Image, Layer, Style, Projection as MapnikProjection, Coord from PIL.Image import new from PIL.ImageDraw import Draw from StringIO import StringIO @@ -409,7 +409,7 @@ class WMSBaseServiceHandler(BaseServiceHandler): else: raise ServerConfigurationError('Layer "%s" refers to non-existent style "%s".' % (layername, stylename)) m.layers.append(layer) - m.zoom_to_box(Envelope(params['bbox'][0], params['bbox'][1], params['bbox'][2], params['bbox'][3])) + m.zoom_to_box(Box2d(params['bbox'][0], params['bbox'][1], params['bbox'][2], params['bbox'][3])) return m class BaseExceptionHandler: diff --git a/bindings/python/mapnik/ogcserver/wms130.py b/bindings/python/mapnik/ogcserver/wms130.py index 052209147..609da66b3 100644 --- a/bindings/python/mapnik/ogcserver/wms130.py +++ b/bindings/python/mapnik/ogcserver/wms130.py @@ -23,7 +23,7 @@ from common import ParameterDefinition, Response, Version, ListFactory, \ ColorFactory, CRSFactory, CRS, WMSBaseServiceHandler, \ - BaseExceptionHandler, Projection, Envelope + BaseExceptionHandler, Projection, Box2d from exceptions import OGCException, ServerConfigurationError from mapnik import Coord @@ -238,7 +238,7 @@ class ServiceHandler(WMSBaseServiceHandler): m = WMSBaseServiceHandler._buildMap(self, params) # for range of epsg codes reverse axis if params['crs'].code >= 4000 and params['crs'].code < 5000: - m.zoom_to_box(Envelope(params['bbox'][1], params['bbox'][0], params['bbox'][3], params['bbox'][2])) + m.zoom_to_box(Box2d(params['bbox'][1], params['bbox'][0], params['bbox'][3], params['bbox'][2])) return m class ExceptionHandler(BaseExceptionHandler): diff --git a/bindings/python/mapnik_datasource.cpp b/bindings/python/mapnik_datasource.cpp index 3aff2e499..93b9d2795 100644 --- a/bindings/python/mapnik_datasource.cpp +++ b/bindings/python/mapnik_datasource.cpp @@ -28,7 +28,7 @@ #include // mapnik -#include +#include #include #include #include diff --git a/bindings/python/mapnik_envelope.cpp b/bindings/python/mapnik_envelope.cpp index 46c6d0512..d97a8421f 100644 --- a/bindings/python/mapnik_envelope.cpp +++ b/bindings/python/mapnik_envelope.cpp @@ -25,15 +25,15 @@ #include // mapnik -#include +#include using mapnik::coord; -using mapnik::Envelope; +using mapnik::box2d; struct envelope_pickle_suite : boost::python::pickle_suite { static boost::python::tuple - getinitargs(const Envelope& e) + getinitargs(const box2d& e) { using namespace boost::python; return boost::python::make_tuple(e.minx(),e.miny(),e.maxx(),e.maxy()); @@ -41,135 +41,135 @@ struct envelope_pickle_suite : boost::python::pickle_suite }; //define overloads here -void (Envelope::*width_p1)(double) = &Envelope::width; -double (Envelope::*width_p2)() const = &Envelope::width; +void (box2d::*width_p1)(double) = &box2d::width; +double (box2d::*width_p2)() const = &box2d::width; -void (Envelope::*height_p1)(double) = &Envelope::height; -double (Envelope::*height_p2)() const = &Envelope::height; +void (box2d::*height_p1)(double) = &box2d::height; +double (box2d::*height_p2)() const = &box2d::height; -void (Envelope::*expand_to_include_p1)(double,double) = &Envelope::expand_to_include; -void (Envelope::*expand_to_include_p2)(coord const& ) = &Envelope::expand_to_include; -void (Envelope::*expand_to_include_p3)(Envelope const& ) = &Envelope::expand_to_include; +void (box2d::*expand_to_include_p1)(double,double) = &box2d::expand_to_include; +void (box2d::*expand_to_include_p2)(coord const& ) = &box2d::expand_to_include; +void (box2d::*expand_to_include_p3)(box2d const& ) = &box2d::expand_to_include; -bool (Envelope::*contains_p1)(double,double) const = &Envelope::contains; -bool (Envelope::*contains_p2)(coord const&) const = &Envelope::contains; -bool (Envelope::*contains_p3)(Envelope const&) const = &Envelope::contains; +bool (box2d::*contains_p1)(double,double) const = &box2d::contains; +bool (box2d::*contains_p2)(coord const&) const = &box2d::contains; +bool (box2d::*contains_p3)(box2d const&) const = &box2d::contains; //intersects -bool (Envelope::*intersects_p1)(double,double) const = &Envelope::intersects; -bool (Envelope::*intersects_p2)(coord const&) const = &Envelope::intersects; -bool (Envelope::*intersects_p3)(Envelope const&) const = &Envelope::intersects; +bool (box2d::*intersects_p1)(double,double) const = &box2d::intersects; +bool (box2d::*intersects_p2)(coord const&) const = &box2d::intersects; +bool (box2d::*intersects_p3)(box2d const&) const = &box2d::intersects; // intersect -Envelope (Envelope::*intersect)(Envelope const&) const = &Envelope::intersect; +box2d (box2d::*intersect)(box2d const&) const = &box2d::intersect; void export_envelope() { using namespace boost::python; - class_ >("Envelope", - // class docstring is in mapnik/__init__.py, class _Coord - init( + class_ >("Box2d", + // class docstring is in mapnik/__init__.py, class _Coord + init( (arg("minx"),arg("miny"),arg("maxx"),arg("maxy")), "Constructs a new envelope from the coordinates\n" "of its lower left and upper right corner points.\n")) - .def(init<>("Equivalent to Envelope(0, 0, -1, -1).\n")) + .def(init<>("Equivalent to box2d(0, 0, -1, -1).\n")) .def(init&, const coord&>( - (arg("ll"),arg("ur")), - "Equivalent to Envelope(ll.x, ll.y, ur.x, ur.y).\n")) - .add_property("minx", &Envelope::minx, + (arg("ll"),arg("ur")), + "Equivalent to box2d(ll.x, ll.y, ur.x, ur.y).\n")) + .add_property("minx", &box2d::minx, "X coordinate for the lower left corner") - .add_property("miny", &Envelope::miny, + .add_property("miny", &box2d::miny, "Y coordinate for the lower left corner") - .add_property("maxx", &Envelope::maxx, + .add_property("maxx", &box2d::maxx, "X coordinate for the upper right corner") - .add_property("maxy", &Envelope::maxy, + .add_property("maxy", &box2d::maxy, "Y coordinate for the upper right corner") - .def("center", &Envelope::center, + .def("center", &box2d::center, "Returns the coordinates of the center of the bounding box.\n" "\n" "Example:\n" - ">>> e = Envelope(0, 0, 100, 100)\n" + ">>> e = box2d(0, 0, 100, 100)\n" ">>> e.center()\n" "Coord(50, 50)\n") - .def("center", &Envelope::re_center, + .def("center", &box2d::re_center, (arg("x"), arg("y")), "Moves the envelope so that the given coordinates become its new center.\n" "The width and the height are preserved.\n" "\n " "Example:\n" - ">>> e = Envelope(0, 0, 100, 100)\n" + ">>> e = box2d(0, 0, 100, 100)\n" ">>> e.center(60, 60)\n" ">>> e.center()\n" "Coord(60.0,60.0)\n" ">>> (e.width(), e.height())\n" "(100.0, 100.0)\n" ">>> e\n" - "Envelope(10.0, 10.0, 110.0, 110.0)\n" - ) + "box2d(10.0, 10.0, 110.0, 110.0)\n" + ) .def("width", width_p1, (arg("new_width")), "Sets the width to new_width of the envelope preserving its center.\n" "\n " "Example:\n" - ">>> e = Envelope(0, 0, 100, 100)\n" + ">>> e = box2d(0, 0, 100, 100)\n" ">>> e.width(120)\n" ">>> e.center()\n" "Coord(50.0,50.0)\n" ">>> e\n" - "Envelope(-10.0, 0.0, 110.0, 100.0)\n" - ) + "box2d(-10.0, 0.0, 110.0, 100.0)\n" + ) .def("width", width_p2, "Returns the width of this envelope.\n" - ) + ) .def("height", height_p1, (arg("new_height")), "Sets the height to new_height of the envelope preserving its center.\n" "\n " "Example:\n" - ">>> e = Envelope(0, 0, 100, 100)\n" + ">>> e = box2d(0, 0, 100, 100)\n" ">>> e.height(120)\n" ">>> e.center()\n" "Coord(50.0,50.0)\n" ">>> e\n" - "Envelope(0.0, -10.0, 100.0, 110.0)\n" - ) + "box2d(0.0, -10.0, 100.0, 110.0)\n" + ) .def("height", height_p2, "Returns the height of this envelope.\n" - ) + ) .def("expand_to_include",expand_to_include_p1, (arg("x"),arg("y")), "Expands this envelope to include the point given by x and y.\n" "\n" "Example:\n", - ">>> e = Envelope(0, 0, 100, 100)\n" + ">>> e = box2d(0, 0, 100, 100)\n" ">>> e.expand_to_include(110, 110)\n" ">>> e\n" - "Envelope(0.0, 00.0, 110.0, 110.0)\n" - ) + "box2d(0.0, 00.0, 110.0, 110.0)\n" + ) .def("expand_to_include",expand_to_include_p2, (arg("p")), "Equivalent to expand_to_include(p.x, p.y)\n" - ) + ) .def("expand_to_include",expand_to_include_p3, (arg("other")), "Equivalent to:\n" " expand_to_include(other.minx, other.miny)\n" " expand_to_include(other.maxx, other.maxy)\n" - ) + ) .def("contains",contains_p1, (arg("x"),arg("y")), "Returns True iff this envelope contains the point\n" "given by x and y.\n" - ) + ) .def("contains",contains_p2, (arg("p")), "Equivalent to contains(p.x, p.y)\n" - ) + ) .def("contains",contains_p3, (arg("other")), "Equivalent to:\n" " contains(other.minx, other.miny) and contains(other.maxx, other.maxy)\n" - ) + ) .def("intersects",intersects_p1, (arg("x"),arg("y")), "Returns True iff this envelope intersects the point\n" @@ -178,7 +178,7 @@ void export_envelope() "Note: For points, intersection is equivalent\n" "to containment, i.e. the following holds:\n" " e.contains(x, y) == e.intersects(x, y)\n" - ) + ) .def("intersects",intersects_p2, (arg("p")), "Equivalent to contains(p.x, p.y)\n") @@ -188,24 +188,24 @@ void export_envelope() "This relationship is symmetric." "\n" "Example:\n" - ">>> e1 = Envelope(0, 0, 100, 100)\n" - ">>> e2 = Envelope(50, 50, 150, 150)\n" + ">>> e1 = box2d(0, 0, 100, 100)\n" + ">>> e2 = box2d(50, 50, 150, 150)\n" ">>> e1.intersects(e2)\n" "True\n" ">>> e1.contains(e2)\n" "False\n" - ) + ) .def("intersect",intersect, (arg("other")), "Returns the overlap of this envelope and the other envelope\n" "as a new envelope.\n" "\n" "Example:\n" - ">>> e1 = Envelope(0, 0, 100, 100)\n" - ">>> e2 = Envelope(50, 50, 150, 150)\n" + ">>> e1 = box2d(0, 0, 100, 100)\n" + ">>> e2 = box2d(50, 50, 150, 150)\n" ">>> e1.intersect(e2)\n" - "Envelope(50.0, 50.0, 100.0, 100.0)\n" - ) + "box2d(50.0, 50.0, 100.0, 100.0)\n" + ) .def(self == self) // __eq__ .def(self + self) // __add__ .def(self - self) // __sub__ diff --git a/bindings/python/mapnik_expression.cpp b/bindings/python/mapnik_expression.cpp new file mode 100644 index 000000000..037ec2f58 --- /dev/null +++ b/bindings/python/mapnik_expression.cpp @@ -0,0 +1,86 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon + * + * 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 + * + *****************************************************************************/ +//$Id$ + +#include +// mapnik +#include +#include +#include +#include + +#include + +using mapnik::expression_ptr; +using mapnik::parse_expression; +using mapnik::to_expression_string; +using mapnik::path_expression_ptr; + +// expression +expression_ptr parse_expression_(std::string const& wkt) +{ + return parse_expression(wkt,"utf8"); +} + +std::string expression_evaluate_(mapnik::expr_node const& expr, mapnik::Feature const& f) +{ + mapnik::value result = boost::apply_visitor(mapnik::evaluate(f),expr); + return result.to_string(); +} + +// path expression +path_expression_ptr parse_path_(std::string const& path) +{ + return mapnik::parse_path(path); +} + +std::string path_to_string_(mapnik::path_expression const& expr) +{ + return mapnik::path_processor_type::to_string(expr); +} + +std::string path_evaluate_(mapnik::path_expression const& expr, mapnik::Feature const& f) +{ + return mapnik::path_processor_type::evaluate(expr, f); +} + +void export_expression() +{ + using namespace boost::python; + class_("Expression", + "TODO" + "",no_init) + .def("evaluate", &expression_evaluate_) + .def("__str__",&to_expression_string); + ; + + def("Expression",&parse_expression_); + + class_("PathExpression", + "TODO" + "",no_init) + .def("evaluate", &path_evaluate_) // note: "pass" is a reserved word in Python + .def("__str__",&path_to_string_); + ; + + def("PathExpression",&parse_path_); +} diff --git a/bindings/python/mapnik_feature.cpp b/bindings/python/mapnik_feature.cpp index 734a90f2e..86107afe7 100644 --- a/bindings/python/mapnik_feature.cpp +++ b/bindings/python/mapnik_feature.cpp @@ -30,197 +30,246 @@ #include // mapnik #include +#include mapnik::geometry2d & (mapnik::Feature::*get_geom1)(unsigned) = &mapnik::Feature::get_geometry; namespace boost { namespace python { - struct value_converter : public boost::static_visitor - { - PyObject * operator() (int val) const - { - return ::PyInt_FromLong(val); - } +struct value_converter : public boost::static_visitor +{ + PyObject * operator() (int val) const + { + return ::PyInt_FromLong(val); + } - PyObject * operator() (double val) const - { - return ::PyFloat_FromDouble(val); - } + PyObject * operator() (double val) const + { + return ::PyFloat_FromDouble(val); + } - PyObject * operator() (UnicodeString const& s) const - { - std::string buffer; - mapnik::to_utf8(s,buffer); - PyObject *obj = Py_None; - obj = ::PyUnicode_DecodeUTF8(buffer.c_str(),implicit_cast(buffer.length()),0); - return obj; - } + PyObject * operator() (UnicodeString const& s) const + { + std::string buffer; + mapnik::to_utf8(s,buffer); + PyObject *obj = Py_None; + obj = ::PyUnicode_DecodeUTF8(buffer.c_str(),implicit_cast(buffer.length()),0); + return obj; + } - PyObject * operator() (mapnik::value_null const& s) const - { - return NULL; - } - }; + PyObject * operator() (mapnik::value_null const& s) const + { + return NULL; + } +}; - struct mapnik_value_to_python - { - static PyObject* convert(mapnik::value const& v) - { - return boost::apply_visitor(value_converter(),v.base()); - } - }; +struct mapnik_value_to_python +{ + static PyObject* convert(mapnik::value const& v) + { + return boost::apply_visitor(value_converter(),v.base()); + } +}; - // Forward declaration - template - class map_indexing_suite2; +// Forward declaration +template +class map_indexing_suite2; - namespace detail - { - template - class final_map_derived_policies - : public map_indexing_suite2 > {}; - } - - template < - class Container, - bool NoProxy = false, - class DerivedPolicies - = detail::final_map_derived_policies > - class map_indexing_suite2 - : public indexing_suite< - Container - , DerivedPolicies - , NoProxy - , true - , typename Container::value_type::second_type - , typename Container::key_type - , typename Container::key_type - > - { - public: - - typedef typename Container::value_type value_type; - typedef typename Container::value_type::second_type data_type; - typedef typename Container::key_type key_type; - typedef typename Container::key_type index_type; - typedef typename Container::size_type size_type; - typedef typename Container::difference_type difference_type; - - template - static void - extension_def(Class& cl) - { - - } - - static data_type& - get_item(Container& container, index_type i_) - { - typename Container::iterator i = container.find(i_); - if (i == container.end()) - { - PyErr_SetString(PyExc_KeyError, "Invalid key"); - throw_error_already_set(); - } - return i->second; - } - - static void - set_item(Container& container, index_type i, data_type const& v) - { - container[i] = v; - } - - static void - delete_item(Container& container, index_type i) - { - container.erase(i); - } - - static size_t - size(Container& container) - { - return container.size(); - } - - static bool - contains(Container& container, key_type const& key) - { - return container.find(key) != container.end(); - } - - static bool - compare_index(Container& container, index_type a, index_type b) - { - return container.key_comp()(a, b); - } - - static index_type - convert_index(Container& /*container*/, PyObject* i_) - { - extract i(i_); - if (i.check()) - { - return i(); - } - else - { - extract i(i_); - if (i.check()) - return i(); - } - - PyErr_SetString(PyExc_TypeError, "Invalid index type"); - throw_error_already_set(); - return index_type(); - } - }; - - - template - struct std_pair_to_tuple - { - static PyObject* convert(std::pair const& p) - { - return boost::python::incref( - boost::python::make_tuple(p.first, p.second).ptr()); - } - }; - - template - struct std_pair_to_python_converter - { - std_pair_to_python_converter() - { - boost::python::to_python_converter< - std::pair, - std_pair_to_tuple >(); - } - }; - } +namespace detail +{ +template +class final_map_derived_policies + : public map_indexing_suite2 > {}; } + +template < +class Container, +bool NoProxy = false, +class DerivedPolicies += detail::final_map_derived_policies > +class map_indexing_suite2 + : public indexing_suite< +Container +, DerivedPolicies +, NoProxy +, true +, typename Container::value_type::second_type +, typename Container::key_type +, typename Container::key_type +> +{ +public: + + typedef typename Container::value_type value_type; + typedef typename Container::value_type::second_type data_type; + typedef typename Container::key_type key_type; + typedef typename Container::key_type index_type; + typedef typename Container::size_type size_type; + typedef typename Container::difference_type difference_type; + + template + static void + extension_def(Class& cl) + { + + } + + static data_type& + get_item(Container& container, index_type i_) + { + typename Container::iterator i = container.props().find(i_); + if (i == container.end()) + { + PyErr_SetString(PyExc_KeyError, "Invalid key"); + throw_error_already_set(); + } + return i->second; + } + + static void + set_item(Container& container, index_type i, data_type const& v) + { + container[i] = v; + } + + static void + delete_item(Container& container, index_type i) + { + container.props().erase(i); + } + + static size_t + size(Container& container) + { + return container.props().size(); + } + + static bool + contains(Container& container, key_type const& key) + { + return container.props().find(key) != container.end(); + } + + static bool + compare_index(Container& container, index_type a, index_type b) + { + return container.props().key_comp()(a, b); + } + + static index_type + convert_index(Container& /*container*/, PyObject* i_) + { + extract i(i_); + if (i.check()) + { + return i(); + } + else + { + extract i(i_); + if (i.check()) + return i(); + } + + PyErr_SetString(PyExc_TypeError, "Invalid index type"); + throw_error_already_set(); + return index_type(); + } +}; + + +template +struct std_pair_to_tuple +{ + static PyObject* convert(std::pair const& p) + { + return boost::python::incref( + boost::python::make_tuple(p.first, p.second).ptr()); + } +}; + +template +struct std_pair_to_python_converter +{ + std_pair_to_python_converter() + { + boost::python::to_python_converter< + std::pair, + std_pair_to_tuple >(); + } +}; +} +} + +mapnik::feature_ptr create_feature_(int id) +{ + return mapnik::feature_ptr(new mapnik::Feature(id)); +} + +struct UnicodeString_from_python_str +{ + UnicodeString_from_python_str() + { + boost::python::converter::registry::push_back( + &convertible, + &construct, + boost::python::type_id()); + } + + static void* convertible(PyObject* obj_ptr) + { + if (!PyString_Check(obj_ptr)) return 0; + return obj_ptr; + } + + static void construct( + PyObject* obj_ptr, + boost::python::converter::rvalue_from_python_stage1_data* data) + { + const char* value = PyString_AsString(obj_ptr); + if (value == 0) boost::python::throw_error_already_set(); + void* storage = ( + (boost::python::converter::rvalue_from_python_storage*) + data)->storage.bytes; + new (storage) UnicodeString(value); + data->convertible = storage; + } +}; void export_feature() { - using namespace boost::python; - using mapnik::Feature; - - std_pair_to_python_converter(); - to_python_converter(); - class_, - boost::noncopyable>("Feature",no_init) - .def("id",&Feature::id) - .def("__str__",&Feature::to_string) - .add_property("properties", - make_function(&Feature::props,return_value_policy())) -// .def("add_geometry", // TODO define more mapnik::Feature methods - .def("num_geometries",&Feature::num_geometries) - .def("get_geometry", make_function(get_geom1,return_value_policy())) - .def("envelope", &Feature::envelope) - ; + using namespace boost::python; + using mapnik::Feature; + + implicitly_convertible(); + implicitly_convertible(); + implicitly_convertible(); + implicitly_convertible(); - class_ >("Properties") - .def(map_indexing_suite2, true >()) - .def("iteritems",iterator > ()) - ; + std_pair_to_python_converter(); + to_python_converter(); + UnicodeString_from_python_str(); + + class_, + boost::noncopyable>("Feature",no_init) + .def("id",&Feature::id) + .def("__str__",&Feature::to_string) +// .add_property("properties", +// make_function(&Feature::props,return_value_policy())) + // .def("add_geometry", // TODO define more mapnik::Feature methods + .def("num_geometries",&Feature::num_geometries) + .def("get_geometry", make_function(get_geom1,return_value_policy())) + .def("envelope", &Feature::envelope) + .def("create",create_feature_) + .staticmethod("create") + .def(map_indexing_suite2()) + .def("iteritems",iterator ()) + ; + +//def("Feature", &create_feature_); + +//class_ >("Properties") +// .def(map_indexing_suite2, true >()) +// .def("iteritems",iterator > ()) +// ; } diff --git a/bindings/python/mapnik_image.cpp b/bindings/python/mapnik_image.cpp index 27d827411..f3232426c 100644 --- a/bindings/python/mapnik_image.cpp +++ b/bindings/python/mapnik_image.cpp @@ -43,52 +43,57 @@ extern "C" #include #endif -using mapnik::Image32; -using mapnik::ImageReader; +using mapnik::image_32; +using mapnik::image_reader; using mapnik::get_image_reader; using mapnik::type_from_filename; using namespace boost::python; using mapnik::save_to_file; // output 'raw' pixels -PyObject* tostring1( Image32 const& im) +PyObject* tostring1( image_32 const& im) { int size = im.width() * im.height() * 4; return ::PyString_FromStringAndSize((const char*)im.raw_data(),size); } // encode (png,jpeg) -PyObject* tostring2(Image32 const & im, std::string const& format) +PyObject* tostring2(image_32 const & im, std::string const& format) { std::string s = save_to_string(im, format); return ::PyString_FromStringAndSize(s.data(),s.size()); } -void (*save_to_file1)( mapnik::Image32 const&, std::string const&,std::string const&) = mapnik::save_to_file; -void (*save_to_file2)( mapnik::Image32 const&, std::string const&) = mapnik::save_to_file; +void (*save_to_file1)( mapnik::image_32 const&, std::string const&,std::string const&) = mapnik::save_to_file; +void (*save_to_file2)( mapnik::image_32 const&, std::string const&) = mapnik::save_to_file; -boost::shared_ptr open_from_file(std::string const& filename) +boost::shared_ptr open_from_file(std::string const& filename) { - std::auto_ptr reader(get_image_reader(filename,type_from_filename(filename))); - if (reader.get()) - { - boost::shared_ptr image_ptr(new Image32(reader->width(),reader->height())); - reader->read(0,0,image_ptr->data()); - return image_ptr; - } - throw mapnik::ImageReaderException("FIXME: " + filename); + boost::optional type = type_from_filename(filename); + if (type) + { + std::auto_ptr reader(get_image_reader(filename,*type)); + if (reader.get()) + { + boost::shared_ptr image_ptr(new image_32(reader->width(),reader->height())); + reader->read(0,0,image_ptr->data()); + return image_ptr; + } + throw mapnik::image_reader_exception("Failed to load: " + filename); + } + throw mapnik::image_reader_exception("Unsupported image format:" + filename); } - -void blend (Image32 & im, unsigned x, unsigned y, Image32 const& im2, float opacity) + +void blend (image_32 & im, unsigned x, unsigned y, image_32 const& im2, float opacity) { im.set_rectangle_alpha2(im2.data(),x,y,opacity); } #if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO) -boost::shared_ptr from_cairo(PycairoSurface* surface) +boost::shared_ptr from_cairo(PycairoSurface* surface) { Cairo::RefPtr s(new Cairo::ImageSurface(surface->surface)); - boost::shared_ptr image_ptr(new Image32(s)); + boost::shared_ptr image_ptr(new image_32(s)); return image_ptr; } #endif @@ -96,13 +101,13 @@ boost::shared_ptr from_cairo(PycairoSurface* surface) void export_image() { using namespace boost::python; - class_ >("Image","This class represents a 32 bit RGBA image.",init()) - .def("width",&Image32::width) - .def("height",&Image32::height) - .def("view",&Image32::get_view) + class_ >("Image","This class represents a 32 bit RGBA image.",init()) + .def("width",&image_32::width) + .def("height",&image_32::height) + .def("view",&image_32::get_view) .add_property("background",make_function - (&Image32::getBackground,return_value_policy()), - &Image32::setBackground, "The background color of the image.") + (&image_32::get_background,return_value_policy()), + &image_32::set_background, "The background color of the image.") .def("blend",&blend) .def("tostring",&tostring1) .def("tostring",&tostring2) diff --git a/bindings/python/mapnik_image_view.cpp b/bindings/python/mapnik_image_view.cpp index 816ef6c74..8d8214b59 100644 --- a/bindings/python/mapnik_image_view.cpp +++ b/bindings/python/mapnik_image_view.cpp @@ -33,38 +33,38 @@ extern "C" #include #include -using mapnik::ImageData32; +using mapnik::image_data_32; using mapnik::image_view; using mapnik::save_to_file; // output 'raw' pixels -PyObject* view_tostring1(image_view const& view) +PyObject* view_tostring1(image_view const& view) { std::ostringstream ss(std::ios::out|std::ios::binary); for (unsigned i=0;i(view.getRow(i)), - view.width() * sizeof(image_view::pixel_type)); + view.width() * sizeof(image_view::pixel_type)); } return ::PyString_FromStringAndSize((const char*)ss.str().c_str(),ss.str().size()); } // encode (png,jpeg) -PyObject* view_tostring2(image_view const & view, std::string const& format) +PyObject* view_tostring2(image_view const & view, std::string const& format) { std::string s = save_to_string(view, format); return ::PyString_FromStringAndSize(s.data(),s.size()); } -void (*save_view1)(image_view const&, std::string const&,std::string const&) = mapnik::save_to_file; -void (*save_view2)(image_view const&, std::string const&) = mapnik::save_to_file; +void (*save_view1)(image_view const&, std::string const&,std::string const&) = mapnik::save_to_file; +void (*save_view2)(image_view const&, std::string const&) = mapnik::save_to_file; void export_image_view() { using namespace boost::python; - class_ >("ImageView","A view into an image.",no_init) - .def("width",&image_view::width) - .def("height",&image_view::height) + class_ >("ImageView","A view into an image.",no_init) + .def("width",&image_view::width) + .def("height",&image_view::height) .def("tostring",&view_tostring1) .def("tostring",&view_tostring2) .def("save",save_view1) diff --git a/bindings/python/mapnik_layer.cpp b/bindings/python/mapnik_layer.cpp index d0f67d91a..c315b3417 100644 --- a/bindings/python/mapnik_layer.cpp +++ b/bindings/python/mapnik_layer.cpp @@ -32,7 +32,7 @@ #include #include -using mapnik::Layer; +using mapnik::layer; using mapnik::parameters; using mapnik::datasource_cache; @@ -40,13 +40,13 @@ using mapnik::datasource_cache; struct layer_pickle_suite : boost::python::pickle_suite { static boost::python::tuple - getinitargs(const Layer& l) + getinitargs(const layer& l) { return boost::python::make_tuple(l.name(),l.srs()); } static boost::python::tuple - getstate(const Layer& l) + getstate(const layer& l) { boost::python::list s; std::vector const& style_names = l.styles(); @@ -58,7 +58,7 @@ struct layer_pickle_suite : boost::python::pickle_suite } static void - setstate (Layer& l, boost::python::tuple state) + setstate (layer& l, boost::python::tuple state) { using namespace boost::python; if (len(state) != 8) @@ -114,7 +114,7 @@ struct layer_pickle_suite : boost::python::pickle_suite } }; -std::vector & (mapnik::Layer::*_styles_)() = &mapnik::Layer::styles; +std::vector & (mapnik::layer::*_styles_)() = &mapnik::layer::styles; void export_layer() { @@ -123,7 +123,7 @@ void export_layer() .def(vector_indexing_suite,true >()) ; - class_("Layer", "A Mapnik map layer.", init >( + class_("Layer", "A Mapnik map layer.", init >( "Create a Layer with a named string and, optionally, an srs string.\n" "\n" "The srs can be either a Proj.4 epsg code ('+init=epsg:') or\n" @@ -139,7 +139,7 @@ void export_layer() .def_pickle(layer_pickle_suite()) - .def("envelope",&Layer::envelope, + .def("envelope",&layer::envelope, "Return the geographic envelope/bounding box." "\n" "Determined based on the layer datasource.\n" @@ -148,10 +148,10 @@ void export_layer() ">>> from mapnik import Layer\n" ">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n" ">>> lyr.envelope()\n" - "Envelope(-1.0,-1.0,0.0,0.0) # default until a datasource is loaded\n" + "box2d(-1.0,-1.0,0.0,0.0) # default until a datasource is loaded\n" ) - .def("visible", &Layer::isVisible, + .def("visible", &layer::isVisible, "Return True if this layer's data is active and visible at a given scale.\n" "\n" "Otherwise returns False.\n" @@ -172,8 +172,8 @@ void export_layer() ) .add_property("abstract", - make_function(&Layer::abstract,return_value_policy()), - &Layer::set_abstract, + make_function(&layer::abstract,return_value_policy()), + &layer::set_abstract, "Get/Set the abstract of the layer.\n" "\n" "Usage:\n" @@ -187,8 +187,8 @@ void export_layer() ) .add_property("active", - &Layer::isActive, - &Layer::setActive, + &layer::isActive, + &layer::setActive, "Get/Set whether this layer is active and will be rendered.\n" "\n" "Usage:\n" @@ -202,8 +202,8 @@ void export_layer() ) .add_property("clear_label_cache", - &Layer::clear_label_cache, - &Layer::set_clear_label_cache, + &layer::clear_label_cache, + &layer::set_clear_label_cache, "Get/Set whether this layer's labels are cached.\n" "\n" "Usage:\n" @@ -211,8 +211,8 @@ void export_layer() ) .add_property("datasource", - &Layer::datasource, - &Layer::set_datasource, + &layer::datasource, + &layer::set_datasource, "The datasource attached to this layer.\n" "\n" "Usage:\n" @@ -224,8 +224,8 @@ void export_layer() ) .add_property("maxzoom", - &Layer::getMaxZoom, - &Layer::setMaxZoom, + &layer::getMaxZoom, + &layer::setMaxZoom, "Get/Set the maximum zoom lever of the layer.\n" "\n" "Usage:\n" @@ -239,8 +239,8 @@ void export_layer() ) .add_property("minzoom", - &Layer::getMinZoom, - &Layer::setMinZoom, + &layer::getMinZoom, + &layer::setMinZoom, "Get/Set the minimum zoom lever of the layer.\n" "\n" "Usage:\n" @@ -254,8 +254,8 @@ void export_layer() ) .add_property("name", - make_function(&Layer::name, return_value_policy()), - &Layer::set_name, + make_function(&layer::name, return_value_policy()), + &layer::set_name, "Get/Set the name of the layer.\n" "\n" "Usage:\n" @@ -269,13 +269,13 @@ void export_layer() ) .add_property("queryable", - &Layer::isQueryable, - &Layer::setQueryable, + &layer::isQueryable, + &layer::setQueryable, "Get/Set whether this layer is queryable.\n" "\n" "Usage:\n" - ">>> from mapnik import Layer\n" - ">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n" + ">>> from mapnik import layer\n" + ">>> lyr = layer('My layer','+proj=latlong +datum=WGS84')\n" ">>> lyr.queryable\n" "False # Not queryable by default\n" ">>> lyr.queryable = True\n" @@ -284,13 +284,13 @@ void export_layer() ) .add_property("srs", - make_function(&Layer::srs,return_value_policy()), - &Layer::set_srs, + make_function(&layer::srs,return_value_policy()), + &layer::set_srs, "Get/Set the SRS of the layer.\n" "\n" "Usage:\n" - ">>> from mapnik import Layer\n" - ">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n" + ">>> from mapnik import layer\n" + ">>> lyr = layer('My layer','+proj=latlong +datum=WGS84')\n" ">>> lyr.srs\n" "'+proj=latlong +datum=WGS84' # The default srs if not initialized with custom srs\n" ">>> # set to google mercator with Proj.4 literal\n" @@ -303,8 +303,8 @@ void export_layer() "The styles list attached to this layer.\n" "\n" "Usage:\n" - ">>> from mapnik import Layer\n" - ">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n" + ">>> from mapnik import layer\n" + ">>> lyr = layer('My layer','+proj=latlong +datum=WGS84')\n" ">>> lyr.styles\n" "\n" ">>> len(lyr.styles)\n" @@ -317,13 +317,13 @@ void export_layer() ) .add_property("title", - make_function(&Layer::title, return_value_policy()), - &Layer::set_title, + make_function(&layer::title, return_value_policy()), + &layer::set_title, "Get/Set the title of the layer.\n" "\n" "Usage:\n" - ">>> from mapnik import Layer\n" - ">>> lyr = Layer('My Layer','+proj=latlong +datum=WGS84')\n" + ">>> from mapnik import layer\n" + ">>> lyr = layer('My layer','+proj=latlong +datum=WGS84')\n" ">>> lyr.title\n" "''\n" ">>> lyr.title = 'My first layer'\n" diff --git a/bindings/python/mapnik_line_pattern_symbolizer.cpp b/bindings/python/mapnik_line_pattern_symbolizer.cpp index 3e0265834..084f2e622 100644 --- a/bindings/python/mapnik_line_pattern_symbolizer.cpp +++ b/bindings/python/mapnik_line_pattern_symbolizer.cpp @@ -22,19 +22,25 @@ //$Id$ #include -#include + #include +#include +#include using mapnik::line_pattern_symbolizer; +using mapnik::path_processor_type; +using mapnik::path_expression_ptr; +using mapnik::guess_type; + struct line_pattern_symbolizer_pickle_suite : boost::python::pickle_suite { static boost::python::tuple getinitargs(const line_pattern_symbolizer& l) { - boost::shared_ptr img = l.get_image(); - const std::string & filename = l.get_filename(); - return boost::python::make_tuple(filename,mapnik::guess_type(filename),img->width(),img->height()); + std::string filename = path_processor_type::to_string(*l.get_filename()); + // FIXME : Do we need "type" parameter at all ? + return boost::python::make_tuple(filename, guess_type(filename)); } }; @@ -43,8 +49,8 @@ void export_line_pattern_symbolizer() using namespace boost::python; class_("LinePatternSymbolizer", - init("TODO")) - .def_pickle(line_pattern_symbolizer_pickle_suite()) + init + ("")) + //.def_pickle(line_pattern_symbolizer_pickle_suite()) ; } diff --git a/bindings/python/mapnik_map.cpp b/bindings/python/mapnik_map.cpp index dc36bae7b..99c8499db 100644 --- a/bindings/python/mapnik_map.cpp +++ b/bindings/python/mapnik_map.cpp @@ -36,8 +36,8 @@ using mapnik::color; using mapnik::coord; -using mapnik::Envelope; -using mapnik::Layer; +using mapnik::box2d; +using mapnik::layer; using mapnik::Map; struct map_pickle_suite : boost::python::pickle_suite @@ -84,7 +84,7 @@ struct map_pickle_suite : boost::python::pickle_suite throw_error_already_set(); } - Envelope ext = extract >(state[0]); + box2d ext = extract >(state[0]); m.zoomToBox(ext); if (state[1]) { @@ -95,7 +95,7 @@ struct map_pickle_suite : boost::python::pickle_suite boost::python::list l=extract(state[2]); for (int i=0;i(l[i])); + m.addLayer(extract(l[i])); } boost::python::list s=extract(state[3]); @@ -109,8 +109,8 @@ struct map_pickle_suite : boost::python::pickle_suite } }; -std::vector& (Map::*layers_nonconst)() = &Map::layers; -std::vector const& (Map::*layers_const)() const = &Map::layers; +std::vector& (Map::*layers_nonconst)() = &Map::layers; +std::vector const& (Map::*layers_const)() const = &Map::layers; mapnik::feature_type_style find_style (mapnik::Map const& m, std::string const& name) @@ -141,8 +141,8 @@ void export_map() ; python_optional (); - class_ >("Layers") - .def(vector_indexing_suite >()) + class_ >("Layers") + .def(vector_indexing_suite >()) ; class_("Map","The map object.",init >( @@ -178,30 +178,30 @@ void export_map() .def("buffered_envelope", &Map::get_buffered_extent, - "Get the Envelope() of the Map given\n" + "Get the box2d() of the Map given\n" "the Map.buffer_size.\n" "\n" "Usage:\n" ">>> m = Map(600,400)\n" ">>> m.envelope()\n" - "Envelope(-1.0,-1.0,0.0,0.0)\n" + "box2d(-1.0,-1.0,0.0,0.0)\n" ">>> m.buffered_envelope()\n" - "Envelope(-1.0,-1.0,0.0,0.0)\n" + "box2d(-1.0,-1.0,0.0,0.0)\n" ">>> m.buffer_size = 1\n" ">>> m.buffered_envelope()\n" - "Envelope(-1.02222222222,-1.02222222222,0.0222222222222,0.0222222222222)\n" + "box2d(-1.02222222222,-1.02222222222,0.0222222222222,0.0222222222222)\n" ) .def("envelope", make_function(&Map::getCurrentExtent, return_value_policy()), - "Return the Map Envelope object\n" + "Return the Map box2d object\n" "and print the string representation\n" "of the current extent of the map.\n" "\n" "Usage:\n" ">>> m.envelope()\n" - "Envelope(-0.185833333333,-0.96,0.189166666667,-0.71)\n" + "box2d(-0.185833333333,-0.96,0.189166666667,-0.71)\n" ">>> dir(m.envelope())\n" "...'center', 'contains', 'expand_to_include', 'forward',\n" "...'height', 'intersect', 'intersects', 'inverse', 'maxx',\n" @@ -285,7 +285,7 @@ void export_map() ) .def("remove_all",&Map::remove_all, - "Remove all Mapnik Styles and Layers from the Map.\n" + "Remove all Mapnik Styles and layers from the Map.\n" "\n" "Usage:\n" ">>> m.remove_all()\n" @@ -343,10 +343,10 @@ void export_map() .def("zoom_to_box",&Map::zoomToBox, "Set the geographical extent of the map\n" - "by specifying a Mapnik Envelope.\n" + "by specifying a Mapnik box2d.\n" "\n" "Usage:\n" - ">>> extext = Envelope(-180.0, -90.0, 180.0, 90.0)\n" + ">>> extext = box2d(-180.0, -90.0, 180.0, 90.0)\n" ">>> m.zoom_to_box(extent)\n" ) @@ -401,9 +401,9 @@ void export_map() "\n" "Usage:\n" ">>> m.layers\n" - "" + "" ">>> m.layers[0]\n" - "\n" + "\n" ) .add_property("srs", diff --git a/bindings/python/mapnik_point_symbolizer.cpp b/bindings/python/mapnik_point_symbolizer.cpp index 736b8c035..62f68738b 100644 --- a/bindings/python/mapnik_point_symbolizer.cpp +++ b/bindings/python/mapnik_point_symbolizer.cpp @@ -25,25 +25,19 @@ #include #include #include - +#include using mapnik::point_symbolizer; using mapnik::symbolizer_with_image; +using mapnik::path_processor_type; struct point_symbolizer_pickle_suite : boost::python::pickle_suite { static boost::python::tuple getinitargs(const point_symbolizer& p) { - boost::shared_ptr img = p.get_image(); - const std::string & filename = p.get_filename(); - - if ( ! filename.empty() ) { - return boost::python::make_tuple(filename,mapnik::guess_type(filename),img->width(),img->height()); - } else { - return boost::python::make_tuple(); - } - + std::string filename = path_processor_type::to_string(*p.get_filename()); + return boost::python::make_tuple(filename,mapnik::guess_type(filename)); } static boost::python::tuple @@ -74,12 +68,12 @@ struct point_symbolizer_pickle_suite : boost::python::pickle_suite namespace { - using namespace boost::python; +using namespace boost::python; +const std::string get_filename(mapnik::point_symbolizer& symbolizer) +{ + return path_processor_type::to_string(*symbolizer.get_filename()); +} - const char *get_filename(mapnik::point_symbolizer& symbolizer) - { - return symbolizer.get_filename().c_str(); - } } void export_point_symbolizer() @@ -88,9 +82,8 @@ void export_point_symbolizer() class_("PointSymbolizer", init<>("Default Point Symbolizer - 4x4 black square")) - .def (init("TODO")) - .def_pickle(point_symbolizer_pickle_suite()) + .def (init("")) + //.def_pickle(point_symbolizer_pickle_suite()) .add_property("filename", // DS - Using workaround as the normal make_function does not work for unknown reasons... //make_function(&point_symbolizer::get_filename,return_value_policy()), diff --git a/bindings/python/mapnik_polygon_pattern_symbolizer.cpp b/bindings/python/mapnik_polygon_pattern_symbolizer.cpp index 0d731a4c7..a5f0dfece 100644 --- a/bindings/python/mapnik_polygon_pattern_symbolizer.cpp +++ b/bindings/python/mapnik_polygon_pattern_symbolizer.cpp @@ -24,17 +24,20 @@ #include #include #include +#include using mapnik::polygon_pattern_symbolizer; +using mapnik::path_expression_ptr; +using mapnik::path_processor_type; +using mapnik::guess_type; struct polygon_pattern_symbolizer_pickle_suite : boost::python::pickle_suite { static boost::python::tuple getinitargs(const polygon_pattern_symbolizer& p) - { - boost::shared_ptr img = p.get_image(); - const std::string & filename = p.get_filename(); - return boost::python::make_tuple(filename,mapnik::guess_type(filename),img->width(),img->height()); + { + std::string filename = path_processor_type::to_string(*p.get_filename()); + return boost::python::make_tuple(filename,guess_type(filename)); } }; @@ -43,8 +46,6 @@ void export_polygon_pattern_symbolizer() using namespace boost::python; class_("PolygonPatternSymbolizer", - init("TODO")) + init("")) .def_pickle(polygon_pattern_symbolizer_pickle_suite()) ; } diff --git a/bindings/python/mapnik_proj_transform.cpp b/bindings/python/mapnik_proj_transform.cpp index 3e06130e7..fbf999281 100644 --- a/bindings/python/mapnik_proj_transform.cpp +++ b/bindings/python/mapnik_proj_transform.cpp @@ -59,7 +59,7 @@ namespace { return mapnik::coord2d(x,y); } - mapnik::Envelope forward_transform_env(mapnik::proj_transform& t, mapnik::Envelope const & box) + mapnik::box2d forward_transform_env(mapnik::proj_transform& t, mapnik::box2d const & box) { double minx = box.minx(); double miny = box.miny(); @@ -68,10 +68,10 @@ namespace { double z = 0.0; t.forward(minx,miny,z); t.forward(maxx,maxy,z); - return mapnik::Envelope(minx,miny,maxx,maxy); + return mapnik::box2d(minx,miny,maxx,maxy); } - mapnik::Envelope backward_transform_env(mapnik::proj_transform& t, mapnik::Envelope const & box) + mapnik::box2d backward_transform_env(mapnik::proj_transform& t, mapnik::box2d const & box) { double minx = box.minx(); double miny = box.miny(); @@ -80,7 +80,7 @@ namespace { double z = 0.0; t.backward(minx,miny,z); t.backward(maxx,maxy,z); - return mapnik::Envelope(minx,miny,maxx,maxy); + return mapnik::box2d(minx,miny,maxx,maxy); } } diff --git a/bindings/python/mapnik_projection.cpp b/bindings/python/mapnik_projection.cpp index 9e246a446..db55b2cd4 100644 --- a/bindings/python/mapnik_projection.cpp +++ b/bindings/python/mapnik_projection.cpp @@ -59,7 +59,7 @@ namespace { return mapnik::coord2d(x,y); } - mapnik::Envelope forward_env(mapnik::Envelope const & box, + mapnik::box2d forward_env(mapnik::box2d const & box, mapnik::projection const& prj) { double minx = box.minx(); @@ -68,10 +68,10 @@ namespace { double maxy = box.maxy(); prj.forward(minx,miny); prj.forward(maxx,maxy); - return mapnik::Envelope(minx,miny,maxx,maxy); + return mapnik::box2d(minx,miny,maxx,maxy); } - mapnik::Envelope inverse_env(mapnik::Envelope const & box, + mapnik::box2d inverse_env(mapnik::box2d const & box, mapnik::projection const& prj) { double minx = box.minx(); @@ -80,7 +80,7 @@ namespace { double maxy = box.maxy(); prj.inverse(minx,miny); prj.inverse(maxx,maxy); - return mapnik::Envelope(minx,miny,maxx,maxy); + return mapnik::box2d(minx,miny,maxx,maxy); } } diff --git a/bindings/python/mapnik_python.cpp b/bindings/python/mapnik_python.cpp index 3d0e7d158..0695e7577 100644 --- a/bindings/python/mapnik_python.cpp +++ b/bindings/python/mapnik_python.cpp @@ -38,7 +38,7 @@ void export_image(); void export_image_view(); void export_map(); void export_python(); -void export_filter(); +void export_expression(); void export_rule(); void export_style(); void export_stroke(); @@ -77,12 +77,12 @@ void export_view_transform(); static Pycairo_CAPI_t *Pycairo_CAPI; #endif -void render(const mapnik::Map& map,mapnik::Image32& image, unsigned offset_x = 0, unsigned offset_y = 0) +void render(const mapnik::Map& map,mapnik::image_32& image, unsigned offset_x = 0, unsigned offset_y = 0) { Py_BEGIN_ALLOW_THREADS try { - mapnik::agg_renderer ren(map,image,offset_x, offset_y); + mapnik::agg_renderer ren(map,image,offset_x, offset_y); ren.apply(); } catch (...) @@ -93,12 +93,12 @@ void render(const mapnik::Map& map,mapnik::Image32& image, unsigned offset_x = 0 Py_END_ALLOW_THREADS } -void render2(const mapnik::Map& map,mapnik::Image32& image) +void render2(const mapnik::Map& map,mapnik::image_32& image) { Py_BEGIN_ALLOW_THREADS try { - mapnik::agg_renderer ren(map,image); + mapnik::agg_renderer ren(map,image); ren.apply(); } catch (...) @@ -187,7 +187,7 @@ void render_tile_to_file(const mapnik::Map& map, const std::string& file, const std::string& format) { - mapnik::Image32 image(width,height); + mapnik::image_32 image(width,height); render(map,image,offset_x, offset_y); mapnik::save_to_file(image.data(),file,format); } @@ -196,7 +196,7 @@ void render_to_file1(const mapnik::Map& map, const std::string& filename, const std::string& format) { - mapnik::Image32 image(map.getWidth(),map.getHeight()); + mapnik::image_32 image(map.getWidth(),map.getHeight()); render(map,image,0,0); mapnik::save_to_file(image,filename,format); } @@ -204,7 +204,7 @@ void render_to_file1(const mapnik::Map& map, void render_to_file2(const mapnik::Map& map, const std::string& filename) { - mapnik::Image32 image(map.getWidth(),map.getHeight()); + mapnik::image_32 image(map.getWidth(),map.getHeight()); render(map,image,0,0); mapnik::save_to_file(image,filename); } @@ -289,7 +289,7 @@ BOOST_PYTHON_MODULE(_mapnik) export_envelope(); export_image(); export_image_view(); - export_filter(); + export_expression(); export_rule(); export_style(); export_layer(); @@ -350,7 +350,7 @@ BOOST_PYTHON_MODULE(_mapnik) def("render",&render, "\n" - "Render Map to an AGG Image32 using offsets\n" + "Render Map to an AGG image_32 using offsets\n" "\n" "Usage:\n" ">>> from mapnik import Map, Image, render, load_map\n" @@ -363,7 +363,7 @@ BOOST_PYTHON_MODULE(_mapnik) def("render",&render2, "\n" - "Render Map to an AGG Image32\n" + "Render Map to an AGG image_32\n" "\n" "Usage:\n" ">>> from mapnik import Map, Image, render, load_map\n" @@ -473,5 +473,6 @@ BOOST_PYTHON_MODULE(_mapnik) def("has_cairo", &has_cairo, "Get cairo library status"); def("has_pycairo", &has_pycairo, "Get pycairo module status"); - register_ptr_to_python(); + register_ptr_to_python(); + register_ptr_to_python(); } diff --git a/bindings/python/mapnik_query.cpp b/bindings/python/mapnik_query.cpp index d28d0acf2..9e3bbfa7a 100644 --- a/bindings/python/mapnik_query.cpp +++ b/bindings/python/mapnik_query.cpp @@ -23,9 +23,9 @@ #include #include -#include +#include using mapnik::query; -using mapnik::Envelope; +using mapnik::box2d; struct query_pickle_suite : boost::python::pickle_suite { @@ -41,7 +41,7 @@ void export_query() using namespace boost::python; class_("Query", "a spatial query data object", - init,double>() ) + init,double>() ) .def_pickle(query_pickle_suite()) .add_property("resolution", &query::resolution) .add_property("bbox", make_function(&query::get_bbox, diff --git a/bindings/python/mapnik_rule.cpp b/bindings/python/mapnik_rule.cpp index 87ddc26f4..d0c446745 100644 --- a/bindings/python/mapnik_rule.cpp +++ b/bindings/python/mapnik_rule.cpp @@ -28,11 +28,11 @@ #include #include +#include using mapnik::rule_type; -using mapnik::filter; -using mapnik::filter_ptr; -using mapnik::filter_factory; +using mapnik::expr_node; +using mapnik::expression_ptr; using mapnik::Feature; using mapnik::point_symbolizer; using mapnik::line_symbolizer; @@ -45,7 +45,7 @@ using mapnik::text_symbolizer; using mapnik::building_symbolizer; using mapnik::markers_symbolizer; using mapnik::symbolizer; -using mapnik::symbolizers; +using mapnik::to_expression_string; struct pickle_symbolizer : public boost::static_visitor<> { @@ -93,14 +93,14 @@ struct rule_pickle_suite : boost::python::pickle_suite { boost::python::list syms; - symbolizers::const_iterator begin = r.get_symbolizers().begin(); - symbolizers::const_iterator end = r.get_symbolizers().end(); + rule_type::symbolizers::const_iterator begin = r.get_symbolizers().begin(); + rule_type::symbolizers::const_iterator end = r.get_symbolizers().end(); pickle_symbolizer serializer( syms ); std::for_each( begin, end , boost::apply_visitor( serializer )); - // Here the filter string is used rather than the actual Filter object - // Need to look into how to get the Filter object - std::string filter_expr = r.get_filter()->to_string(); + // We serialize filter expressions AST as strings + std::string filter_expr = to_expression_string(*r.get_filter()); + return boost::python::make_tuple(r.get_abstract(),filter_expr,r.has_else_filter(),syms); } @@ -126,10 +126,10 @@ struct rule_pickle_suite : boost::python::pickle_suite { rule_type dfl; std::string filter = extract(state[1]); - std::string default_filter = dfl.get_filter()->to_string(); + std::string default_filter = "";//dfl.get_filter()->to_string(); if ( filter != default_filter) { - r.set_filter(mapnik::create_filter(filter,"utf8")); + r.set_filter(mapnik::parse_expression(filter,"utf8")); } } @@ -162,8 +162,8 @@ void export_rule() implicitly_convertible(); implicitly_convertible(); - class_("Symbolizers",init<>("TODO")) - .def(vector_indexing_suite()) + class_("Symbolizers",init<>("TODO")) + .def(vector_indexing_suite()) ; class_("Rule",init<>("default constructor")) diff --git a/bindings/python/mapnik_shield_symbolizer.cpp b/bindings/python/mapnik_shield_symbolizer.cpp index 04ea6a4e9..6e5eebf33 100644 --- a/bindings/python/mapnik_shield_symbolizer.cpp +++ b/bindings/python/mapnik_shield_symbolizer.cpp @@ -25,22 +25,26 @@ #include #include #include +#include using mapnik::color; using mapnik::shield_symbolizer; using mapnik::text_symbolizer; using mapnik::symbolizer_with_image; +using mapnik::path_processor_type; +using mapnik::path_expression_ptr; +using mapnik::guess_type; +using mapnik::expression_ptr; struct shield_symbolizer_pickle_suite : boost::python::pickle_suite { static boost::python::tuple getinitargs(const shield_symbolizer& s) { - - boost::shared_ptr img = s.get_image(); - const std::string & filename = s.get_filename(); - //(name, font name, font size, font color, image file, image type, width, height) - return boost::python::make_tuple(s.get_name(),s.get_face_name(),s.get_text_size(),s.get_fill(),filename,mapnik::guess_type(filename),img->width(),img->height()); + std::string filename = path_processor_type::to_string(*s.get_filename()); + //(name, font name, font size, font color, image file, image type, width, height) + return boost::python::make_tuple( "TODO",//s.get_name(), + s.get_face_name(),s.get_text_size(),s.get_fill(),filename,guess_type(filename)); } @@ -75,9 +79,9 @@ void export_shield_symbolizer() { using namespace boost::python; class_< shield_symbolizer, bases >("ShieldSymbolizer", - init< std::string const&, std::string const&, unsigned, mapnik::color const&, - std::string const&, std::string const&,unsigned,unsigned>("TODO")) - .def_pickle(shield_symbolizer_pickle_suite()) + init("TODO")) + //.def_pickle(shield_symbolizer_pickle_suite()) ; } diff --git a/bindings/python/mapnik_text_symbolizer.cpp b/bindings/python/mapnik_text_symbolizer.cpp index bb20e9827..1326d9295 100644 --- a/bindings/python/mapnik_text_symbolizer.cpp +++ b/bindings/python/mapnik_text_symbolizer.cpp @@ -62,8 +62,9 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite getinitargs(const text_symbolizer& t) { - return boost::python::make_tuple(t.get_name(),t.get_face_name(),t.get_text_size(),t.get_fill()); - + return boost::python::make_tuple("TODO",//t.get_name(), + t.get_face_name(),t.get_text_size(),t.get_fill()); + } static boost::python::tuple @@ -164,8 +165,8 @@ using namespace boost::python; .value("TOLOWER",TOLOWER) ; -class_("TextSymbolizer",init()) - .def_pickle(text_symbolizer_pickle_suite()) +class_("TextSymbolizer",init()) + //.def_pickle(text_symbolizer_pickle_suite()) .def("anchor",&text_symbolizer::set_anchor) .def("displacement",&text_symbolizer::set_displacement) .def("get_anchor",get_anchor_list) @@ -220,9 +221,9 @@ class_("TextSymbolizer",init()), - &text_symbolizer::set_name) + //.add_property("name", + // make_function(&text_symbolizer::get_name,return_value_policy()), + // &text_symbolizer::set_name) .add_property("text_convert", &text_symbolizer::get_text_convert, &text_symbolizer::set_text_convert, diff --git a/bindings/python/mapnik_view_transform.cpp b/bindings/python/mapnik_view_transform.cpp index ed636d706..3c2ee8d47 100644 --- a/bindings/python/mapnik_view_transform.cpp +++ b/bindings/python/mapnik_view_transform.cpp @@ -55,12 +55,12 @@ namespace { return out; } - mapnik::Envelope forward_envelope(mapnik::CoordTransform const& t, mapnik::Envelope const& in) + mapnik::box2d forward_envelope(mapnik::CoordTransform const& t, mapnik::box2d const& in) { return t.forward(in); } - mapnik::Envelope backward_envelope(mapnik::CoordTransform const& t, mapnik::Envelope const& in) + mapnik::box2d backward_envelope(mapnik::CoordTransform const& t, mapnik::box2d const& in) { return t.backward(in); } @@ -69,10 +69,10 @@ namespace { void export_view_transform() { using namespace boost::python; - using mapnik::Envelope; + using mapnik::box2d; using mapnik::coord2d; - class_("ViewTransform",init const& > ( + class_("ViewTransform",init const& > ( "Create a ViewTransform with a width and height as integers and extent")) .def_pickle(view_transform_pickle_suite()) .def("forward", forward_point) diff --git a/boost/property_tree/cmdline_parser.hpp b/boost/property_tree/cmdline_parser.hpp deleted file mode 100644 index 5c6f45324..000000000 --- a/boost/property_tree/cmdline_parser.hpp +++ /dev/null @@ -1,85 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_CMDLINE_PARSER_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_CMDLINE_PARSER_HPP_INCLUDED - -#include -#include - -namespace boost { namespace property_tree { namespace cmdline_parser -{ - - template - void read_cmdline(int argc, - typename Ptree::char_type *argv[], - const std::basic_string &metachars, - Ptree &pt) - { - - typedef typename Ptree::char_type Ch; - typedef std::basic_string Str; - - Ptree local; - - // For all arguments - for (int i = 0; i < argc; ++i) - { - Str text = detail::trim(argv[i]); - if (!text.empty()) - if (metachars.find(text[0]) != Str::npos) - { - if (text.size() == 1) - { - Ptree &child = local.put(text, Str()); - Str key; - if (child.size() < 10) - key.push_back(typename Ptree::char_type('0' + child.size())); - child.push_back(std::make_pair(key, Ptree(child.data()))); - } - else if (text.size() == 2) - { - Ptree &child = local.put(text.substr(1, 1), Str()); - Str key; - if (child.size() < 10) - key.push_back(typename Ptree::char_type('0' + child.size())); - child.push_back(std::make_pair(key, Ptree(child.data()))); - } - else - { - Ptree &child = local.put(text.substr(1, 1), detail::trim(text.substr(2, Str::npos))); - Str key; - if (child.size() < 10) - key.push_back(typename Ptree::char_type('0' + child.size())); - child.push_back(std::make_pair(key, Ptree(child.data()))); - } - } - else - { - Ptree &child = local.put(Str(), detail::trim(text)); - Str key; - if (child.size() < 10) - key.push_back(typename Ptree::char_type('0' + child.size())); - child.push_back(std::make_pair(key, Ptree(child.data()))); - } - } - - // Swap local and pt - pt.swap(local); - - } - -} } } - -namespace boost { namespace property_tree -{ - using cmdline_parser::read_cmdline; -} } - -#endif diff --git a/boost/property_tree/detail/file_parser_error.hpp b/boost/property_tree/detail/file_parser_error.hpp deleted file mode 100644 index d4378b385..000000000 --- a/boost/property_tree/detail/file_parser_error.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_FILE_PARSER_ERROR_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_FILE_PARSER_ERROR_HPP_INCLUDED - -#include -#include - -namespace boost { namespace property_tree -{ - - //! File parse error - class file_parser_error: public ptree_error - { - - public: - - /////////////////////////////////////////////////////////////////////// - // Construction & destruction - - // Construct error - file_parser_error(const std::string &message, - const std::string &filename, - unsigned long line): - ptree_error(format_what(message, filename, line)), - m_message(message), m_filename(filename), m_line(line) - { - } - - ~file_parser_error() throw() - // gcc 3.4.2 complains about lack of throw specifier on compiler generated dtor - { - } - - /////////////////////////////////////////////////////////////////////// - // Data access - - // Get error message (without line and file - use what() to get full message) - std::string message() - { - return m_message; - } - - // Get error filename - std::string filename() - { - return m_filename; - } - - // Get error line number - unsigned long line() - { - return m_line; - } - - private: - - std::string m_message; - std::string m_filename; - unsigned long m_line; - - // Format error message to be returned by std::runtime_error::what() - std::string format_what(const std::string &message, - const std::string &filename, - unsigned long line) - { - std::stringstream stream; - if (line > 0) - stream << (filename.empty() ? "" : filename.c_str()) << - '(' << line << "): " << message; - else - stream << (filename.empty() ? "" : filename.c_str()) << - ": " << message; - return stream.str(); - } - - }; - -} } - -#endif diff --git a/boost/property_tree/detail/info_parser_error.hpp b/boost/property_tree/detail/info_parser_error.hpp deleted file mode 100644 index 112a7da6f..000000000 --- a/boost/property_tree/detail/info_parser_error.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_INFO_PARSER_ERROR_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_INFO_PARSER_ERROR_HPP_INCLUDED - -#include -#include - -namespace boost { namespace property_tree { namespace info_parser -{ - - class info_parser_error: public file_parser_error - { - public: - info_parser_error(const std::string &message, - const std::string &filename, - unsigned long line): - file_parser_error(message, filename, line) - { - } - }; - -} } } - -#endif diff --git a/boost/property_tree/detail/info_parser_read.hpp b/boost/property_tree/detail/info_parser_read.hpp deleted file mode 100644 index 290b9e297..000000000 --- a/boost/property_tree/detail/info_parser_read.hpp +++ /dev/null @@ -1,369 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_INFO_PARSER_READ_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_INFO_PARSER_READ_HPP_INCLUDED - -#include "boost/property_tree/ptree.hpp" -#include "boost/property_tree/detail/info_parser_error.hpp" -#include "boost/property_tree/detail/info_parser_utils.hpp" -#include -#include -#include -#include -#include - -namespace boost { namespace property_tree { namespace info_parser -{ - - // Expand known escape sequences - template - std::basic_string::value_type> - expand_escapes(It b, It e) - { - typedef typename std::iterator_traits::value_type Ch; - std::basic_string result; - while (b != e) - { - if (*b == Ch('\\')) - { - ++b; - if (b == e) - throw info_parser_error("character expected after backslash", "", 0); - else if (*b == Ch('0')) result += Ch('\0'); - else if (*b == Ch('a')) result += Ch('\a'); - else if (*b == Ch('b')) result += Ch('\b'); - else if (*b == Ch('f')) result += Ch('\f'); - else if (*b == Ch('n')) result += Ch('\n'); - else if (*b == Ch('r')) result += Ch('\r'); - else if (*b == Ch('t')) result += Ch('\t'); - else if (*b == Ch('v')) result += Ch('\v'); - else if (*b == Ch('"')) result += Ch('"'); - else if (*b == Ch('\'')) result += Ch('\''); - else if (*b == Ch('\\')) result += Ch('\\'); - else - throw info_parser_error("unknown escape sequence", "", 0); - } - else - result += *b; - ++b; - } - return result; - } - - // Advance pointer past whitespace - template - void skip_whitespace(const Ch *&text) - { - using namespace std; - while (isspace(*text)) - ++text; - } - - // Extract word (whitespace delimited) and advance pointer accordingly - template - std::basic_string read_word(const Ch *&text) - { - using namespace std; - skip_whitespace(text); - const Ch *start = text; - while (!isspace(*text) && *text != Ch(';') && *text != Ch('\0')) - ++text; - return expand_escapes(start, text); - } - - // Extract line (eol delimited) and advance pointer accordingly - template - std::basic_string read_line(const Ch *&text) - { - using namespace std; - skip_whitespace(text); - const Ch *start = text; - while (*text != Ch('\0') && *text != Ch(';')) - ++text; - while (text > start && isspace(*(text - 1))) - --text; - return expand_escapes(start, text); - } - - // Extract string (inside ""), and advance pointer accordingly - // Set need_more_lines to true if \ continuator found - template - std::basic_string read_string(const Ch *&text, bool *need_more_lines) - { - skip_whitespace(text); - if (*text == Ch('\"')) - { - - // Skip " - ++text; - - // Find end of string, but skip escaped " - bool escaped = false; - const Ch *start = text; - while ((escaped || *text != Ch('\"')) && *text != Ch('\0')) - { - escaped = (!escaped && *text == Ch('\\')); - ++text; - } - - // If end of string found - if (*text == Ch('\"')) - { - std::basic_string result = expand_escapes(start, text++); - skip_whitespace(text); - if (*text == Ch('\\')) - { - if (!need_more_lines) - throw info_parser_error("unexpected \\", "", 0); - ++text; - skip_whitespace(text); - if (*text == Ch('\0') || *text == Ch(';')) - *need_more_lines = true; - else - throw info_parser_error("expected end of line after \\", "", 0); - } - else - if (need_more_lines) - *need_more_lines = false; - return result; - } - else - throw info_parser_error("unexpected end of line", "", 0); - - } - else - throw info_parser_error("expected \"", "", 0); - } - - // Extract key - template - std::basic_string read_key(const Ch *&text) - { - skip_whitespace(text); - if (*text == Ch('\"')) - return read_string(text, NULL); - else - return read_word(text); - } - - // Extract data - template - std::basic_string read_data(const Ch *&text, bool *need_more_lines) - { - skip_whitespace(text); - if (*text == Ch('\"')) - return read_string(text, need_more_lines); - else - { - *need_more_lines = false; - return read_word(text); - } - } - - // Build ptree from info stream - template - void read_info_internal(std::basic_istream &stream, - Ptree &pt, - const std::string &filename, - int include_depth) - { - - // Character type - typedef typename Ptree::char_type Ch; - - // Possible parser states - enum state_t { - s_key, // Parser expects key - s_data, // Parser expects data - s_data_cont // Parser expects data continuation - }; - - unsigned long line_no = 0; - state_t state = s_key; // Parser state - Ptree *last = NULL; // Pointer to last created ptree - std::basic_string line; // Define line here to minimize reallocations - - // Initialize ptree stack (used to handle nesting) - std::stack stack; - stack.push(&pt); // Push root ptree on stack initially - - try - { - - // While there are characters in the stream - while (stream.good()) - { - - // Read one line from stream - ++line_no; - std::getline(stream, line); - if (!stream.good() && !stream.eof()) - throw info_parser_error("read error", "", 0); - const Ch *text = line.c_str(); - - // If directive found - skip_whitespace(text); - if (*text == Ch('#')) - { - - // Determine directive type - ++text; // skip # - std::basic_string directive = read_word(text); - if (directive == convert_chtype("include")) // #include - { - if (include_depth > 100) - throw info_parser_error("include depth too large, probably recursive include", "", 0); - std::basic_string s = read_string(text, NULL); - std::string inc_name = convert_chtype(s.c_str()); - std::basic_ifstream inc_stream(inc_name.c_str()); - if (!inc_stream.good()) - throw info_parser_error("cannot open include file " + inc_name, "", 0); - read_info_internal(inc_stream, *stack.top(), inc_name, include_depth + 1); - } - else // Unknown directive - throw info_parser_error("unknown directive", "", 0); - - // Directive must be followed by end of line - skip_whitespace(text); - if (*text != Ch('\0')) - throw info_parser_error("expected end of line", "", 0); - - // Go to next line - continue; - - } - - // While there are characters left in line - while (1) - { - - // Stop parsing on end of line or comment - skip_whitespace(text); - if (*text == Ch('\0') || *text == Ch(';')) - { - if (state == s_data) // If there was no data set state to s_key - state = s_key; - break; - } - - // Process according to current parser state - switch (state) - { - - // Parser expects key - case s_key: - { - - if (*text == Ch('{')) // Brace opening found - { - if (!last) - throw info_parser_error("unexpected {", "", 0); - stack.push(last); - last = NULL; - ++text; - } - else if (*text == Ch('}')) // Brace closing found - { - if (stack.size() <= 1) - throw info_parser_error("unmatched }", "", 0); - stack.pop(); - last = NULL; - ++text; - } - else // Key text found - { - std::basic_string key = read_key(text); - last = &stack.top()->push_back(std::make_pair(key, Ptree()))->second; - state = s_data; - } - - }; break; - - // Parser expects data - case s_data: - { - - // Last ptree must be defined because we are going to add data to it - BOOST_ASSERT(last); - - if (*text == Ch('{')) // Brace opening found - { - stack.push(last); - last = NULL; - ++text; - state = s_key; - } - else if (*text == Ch('}')) // Brace closing found - { - if (stack.size() <= 1) - throw info_parser_error("unmatched }", "", 0); - stack.pop(); - last = NULL; - ++text; - state = s_key; - } - else // Data text found - { - bool need_more_lines; - std::basic_string data = read_data(text, &need_more_lines); - last->data() = data; - state = need_more_lines ? s_data_cont : s_key; - } - - - }; break; - - // Parser expects continuation of data after \ on previous line - case s_data_cont: - { - - // Last ptree must be defined because we are going to update its data - BOOST_ASSERT(last); - - if (*text == Ch('\"')) // Continuation must start with " - { - bool need_more_lines; - std::basic_string data = read_string(text, &need_more_lines); - last->put_own(last->template get_own >() + data); - state = need_more_lines ? s_data_cont : s_key; - } - else - throw info_parser_error("expected \" after \\ in previous line", "", 0); - - }; break; - - // Should never happen - default: - BOOST_ASSERT(0); - - } - } - } - - // Check if stack has initial size, otherwise some {'s have not been closed - if (stack.size() != 1) - throw info_parser_error("unmatched {", "", 0); - - } - catch (info_parser_error &e) - { - // If line undefined rethrow error with correct filename and line - if (e.line() == 0) - throw info_parser_error(e.message(), filename, line_no); - else - throw e; - - } - - } - -} } } - -#endif diff --git a/boost/property_tree/detail/info_parser_utils.hpp b/boost/property_tree/detail/info_parser_utils.hpp deleted file mode 100644 index 0fdef3ca8..000000000 --- a/boost/property_tree/detail/info_parser_utils.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_INFO_PARSER_CHCONV_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_INFO_PARSER_CHCONV_HPP_INCLUDED - -#include - -namespace boost { namespace property_tree { namespace info_parser -{ - - template - std::basic_string convert_chtype(const ChSrc *text) - { - std::basic_string result; - while (*text) - { - result += ChDest(*text); - ++text; - } - return result; - } - -} } } - -#endif diff --git a/boost/property_tree/detail/info_parser_write.hpp b/boost/property_tree/detail/info_parser_write.hpp deleted file mode 100644 index 4e023c1b9..000000000 --- a/boost/property_tree/detail/info_parser_write.hpp +++ /dev/null @@ -1,131 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_INFO_PARSER_WRITE_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_INFO_PARSER_WRITE_HPP_INCLUDED - -#include "boost/property_tree/ptree.hpp" -#include "boost/property_tree/detail/info_parser_utils.hpp" -#include - -namespace boost { namespace property_tree { namespace info_parser -{ - - // Create necessary escape sequences from illegal characters - template - std::basic_string create_escapes(const std::basic_string &s) - { - std::basic_string result; - typename std::basic_string::const_iterator b = s.begin(); - typename std::basic_string::const_iterator e = s.end(); - while (b != e) - { - if (*b == Ch('\0')) result += Ch('\\'), result += Ch('0'); - else if (*b == Ch('\a')) result += Ch('\\'), result += Ch('a'); - else if (*b == Ch('\b')) result += Ch('\\'), result += Ch('b'); - else if (*b == Ch('\f')) result += Ch('\\'), result += Ch('f'); - else if (*b == Ch('\n')) result += Ch('\\'), result += Ch('n'); - else if (*b == Ch('\r')) result += Ch('\\'), result += Ch('r'); - else if (*b == Ch('\v')) result += Ch('\\'), result += Ch('v'); - else if (*b == Ch('"')) result += Ch('\\'), result += Ch('"'); - else if (*b == Ch('\\')) result += Ch('\\'), result += Ch('\\'); - else - result += *b; - ++b; - } - return result; - } - - template - bool is_simple_key(const std::basic_string &key) - { - const static std::basic_string chars = convert_chtype(" \t{};\n\""); - return !key.empty() && key.find_first_of(chars) == key.npos; - } - - template - bool is_simple_data(const std::basic_string &data) - { - const static std::basic_string chars = convert_chtype(" \t{};\n\""); - return !data.empty() && data.find_first_of(chars) == data.npos; - } - - template - void write_info_helper(std::basic_ostream &stream, - const Ptree &pt, - int indent) - { - - // Character type - typedef typename Ptree::char_type Ch; - - // Write data - if (indent >= 0) - { - if (!pt.data().empty()) - { - std::basic_string data = create_escapes(pt.template get_own >()); - if (is_simple_data(data)) - stream << Ch(' ') << data << Ch('\n'); - else - stream << Ch(' ') << Ch('\"') << data << Ch('\"') << Ch('\n'); - } - else if (pt.empty()) - stream << Ch(' ') << Ch('\"') << Ch('\"') << Ch('\n'); - else - stream << Ch('\n'); - } - - // Write keys - if (!pt.empty()) - { - - // Open brace - if (indent >= 0) - stream << std::basic_string(4 * indent, Ch(' ')) << Ch('{') << Ch('\n'); - - // Write keys - typename Ptree::const_iterator it = pt.begin(); - for (; it != pt.end(); ++it) - { - - // Output key - std::basic_string key = create_escapes(it->first); - stream << std::basic_string(4 * (indent + 1), Ch(' ')); - if (is_simple_key(key)) - stream << key; - else - stream << Ch('\"') << key << Ch('\"'); - - // Output data and children - write_info_helper(stream, it->second, indent + 1); - - } - - // Close brace - if (indent >= 0) - stream << std::basic_string(4 * indent, Ch(' ')) << Ch('}') << Ch('\n'); - - } - } - - // Write ptree to info stream - template - void write_info_internal(std::basic_ostream &stream, - const Ptree &pt, - const std::string &filename) - { - write_info_helper(stream, pt, -1); - if (!stream.good()) - throw info_parser_error("write error", filename, 0); - } - -} } } - -#endif diff --git a/boost/property_tree/detail/json_parser_error.hpp b/boost/property_tree/detail/json_parser_error.hpp deleted file mode 100644 index c3fb29564..000000000 --- a/boost/property_tree/detail/json_parser_error.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_ERROR_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_ERROR_HPP_INCLUDED - -#include -#include - -namespace boost { namespace property_tree { namespace json_parser -{ - - //! Json parser error - class json_parser_error: public file_parser_error - { - public: - json_parser_error(const std::string &message, - const std::string &filename, - unsigned long line): - file_parser_error(message, filename, line) - { - } - }; - -} } } - -#endif diff --git a/boost/property_tree/detail/json_parser_read.hpp b/boost/property_tree/detail/json_parser_read.hpp deleted file mode 100644 index d72a7907f..000000000 --- a/boost/property_tree/detail/json_parser_read.hpp +++ /dev/null @@ -1,316 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_READ_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_READ_HPP_INCLUDED - -//#define BOOST_SPIRIT_DEBUG - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace boost { namespace property_tree { namespace json_parser -{ - - /////////////////////////////////////////////////////////////////////// - // Json parser context - - template - struct context - { - - typedef typename Ptree::char_type Ch; - typedef std::basic_string Str; - typedef typename std::vector::iterator It; - - Str string; - Str name; - Ptree root; - std::vector stack; - - struct a_object_s - { - context &c; - a_object_s(context &c): c(c) { } - void operator()(Ch) const - { - if (c.stack.empty()) - c.stack.push_back(&c.root); - else - { - Ptree *parent = c.stack.back(); - Ptree *child = &parent->push_back(std::make_pair(c.name, Ptree()))->second; - c.stack.push_back(child); - c.name.clear(); - } - } - }; - - struct a_object_e - { - context &c; - a_object_e(context &c): c(c) { } - void operator()(Ch) const - { - BOOST_ASSERT(c.stack.size() >= 1); - c.stack.pop_back(); - } - }; - - struct a_name - { - context &c; - a_name(context &c): c(c) { } - void operator()(It, It) const - { - c.name.swap(c.string); - c.string.clear(); - } - }; - - struct a_string_val - { - context &c; - a_string_val(context &c): c(c) { } - void operator()(It, It) const - { - BOOST_ASSERT(c.stack.size() >= 1); - c.stack.back()->push_back(std::make_pair(c.name, Ptree(c.string))); - c.name.clear(); - c.string.clear(); - } - }; - - struct a_literal_val - { - context &c; - a_literal_val(context &c): c(c) { } - void operator()(It b, It e) const - { - BOOST_ASSERT(c.stack.size() >= 1); - c.stack.back()->push_back(std::make_pair(c.name, Str(b, e))); - c.name.clear(); - c.string.clear(); - } - }; - - struct a_char - { - context &c; - a_char(context &c): c(c) { } - void operator()(It b, It e) const - { - c.string += *b; - } - }; - - struct a_escape - { - context &c; - a_escape(context &c): c(c) { } - void operator()(Ch ch) const - { - switch (ch) - { - case Ch('\"'): c.string += Ch('\"'); break; - case Ch('\\'): c.string += Ch('\\'); break; - case Ch('0'): c.string += Ch('\0'); break; - case Ch('b'): c.string += Ch('\b'); break; - case Ch('f'): c.string += Ch('\f'); break; - case Ch('n'): c.string += Ch('\n'); break; - case Ch('r'): c.string += Ch('\r'); break; - case Ch('t'): c.string += Ch('\t'); break; - default: BOOST_ASSERT(0); - } - } - }; - - struct a_unicode - { - context &c; - a_unicode(context &c): c(c) { } - void operator()(unsigned long u) const - { - u = (std::min)(u, static_cast((std::numeric_limits::max)())); - c.string += Ch(u); - } - }; - - }; - - /////////////////////////////////////////////////////////////////////// - // Json grammar - - template - struct json_grammar: public boost::spirit::grammar > - { - - typedef context Context; - typedef typename Ptree::char_type Ch; - - mutable Context c; - - template - struct definition - { - - boost::spirit::rule root, object, member, array, item, value, string, number; - boost::spirit::rule::type> character, escape; - - definition(const json_grammar &self) - { - - using namespace boost::spirit; - - // Assertions - assertion expect_object("expected object"); - assertion expect_eoi("expected end of input"); - assertion expect_objclose("expected ',' or '}'"); - assertion expect_arrclose("expected ',' or ']'"); - assertion expect_name("expected object name"); - assertion expect_colon("expected ':'"); - assertion expect_value("expected value"); - assertion expect_escape("invalid escape sequence"); - - // JSON grammar rules - root - = expect_object(object) - >> expect_eoi(end_p) - ; - - object - = ch_p('{')[typename Context::a_object_s(self.c)] - >> (ch_p('}')[typename Context::a_object_e(self.c)] - | (list_p(member, ch_p(',')) - >> expect_objclose(ch_p('}')[typename Context::a_object_e(self.c)]) - ) - ) - ; - - member - = expect_name(string[typename Context::a_name(self.c)]) - >> expect_colon(ch_p(':')) - >> expect_value(value) - ; - - array - = ch_p('[')[typename Context::a_object_s(self.c)] - >> (ch_p(']')[typename Context::a_object_e(self.c)] - | (list_p(item, ch_p(',')) - >> expect_arrclose(ch_p(']')[typename Context::a_object_e(self.c)]) - ) - ) - ; - - item - = expect_value(value) - ; - - value - = string[typename Context::a_string_val(self.c)] - | (number | str_p("true") | "false" | "null")[typename Context::a_literal_val(self.c)] - | object - | array - ; - - number - = strict_real_p - | int_p - ; - - string - = +(lexeme_d[confix_p('\"', *character, '\"')]) - ; - - character - = (anychar_p - "\\" - "\"")[typename Context::a_char(self.c)] - | ch_p("\\") >> expect_escape(escape) - ; - - escape - = chset_p(detail::widen("\"\\0bfnrt").c_str())[typename Context::a_escape(self.c)] - | 'u' >> uint_parser()[typename Context::a_unicode(self.c)] - ; - - // Debug - BOOST_SPIRIT_DEBUG_RULE(root); - BOOST_SPIRIT_DEBUG_RULE(object); - BOOST_SPIRIT_DEBUG_RULE(member); - BOOST_SPIRIT_DEBUG_RULE(array); - BOOST_SPIRIT_DEBUG_RULE(item); - BOOST_SPIRIT_DEBUG_RULE(value); - BOOST_SPIRIT_DEBUG_RULE(string); - BOOST_SPIRIT_DEBUG_RULE(number); - BOOST_SPIRIT_DEBUG_RULE(escape); - BOOST_SPIRIT_DEBUG_RULE(character); - - } - - const boost::spirit::rule &start() const - { - return root; - } - - }; - - }; - - template - unsigned long count_lines(It begin, It end) - { - return static_cast(std::count(begin, end, Ch('\n')) + 1); - } - - template - void read_json_internal(std::basic_istream &stream, - Ptree &pt, - const std::string &filename) - { - - using namespace boost::spirit; - typedef typename Ptree::char_type Ch; - typedef typename std::vector::iterator It; - - // Load data into vector - std::vector v(std::istreambuf_iterator(stream.rdbuf()), - std::istreambuf_iterator()); - if (!stream.good()) - throw json_parser_error("read error", filename, 0); - - // Prepare grammar - json_grammar g; - - // Parse - try - { - parse_info pi = parse(v.begin(), v.end(), g, - space_p | comment_p("//") | comment_p("/*", "*/")); - if (!pi.hit || !pi.full) - throw parser_error(v.begin(), "syntax error"); - } - catch (parser_error &e) - { - throw json_parser_error(e.descriptor, filename, count_lines(v.begin(), e.where)); - } - - // Swap grammar context root and pt - pt.swap(g.c.root); - - } - -} } } - -#endif diff --git a/boost/property_tree/detail/json_parser_write.hpp b/boost/property_tree/detail/json_parser_write.hpp deleted file mode 100644 index 2361a6952..000000000 --- a/boost/property_tree/detail/json_parser_write.hpp +++ /dev/null @@ -1,163 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_WRITE_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_WRITE_HPP_INCLUDED - -#include -#include -#include -#include - -namespace boost { namespace property_tree { namespace json_parser -{ - - // Create necessary escape sequences from illegal characters - template - std::basic_string create_escapes(const std::basic_string &s, - const std::locale &loc) - { - std::basic_string result; - typename std::basic_string::const_iterator b = s.begin(); - typename std::basic_string::const_iterator e = s.end(); - while (b != e) - { - if (*b == Ch('\0')) result += Ch('\\'), result += Ch('0'); - else if (*b == Ch('\b')) result += Ch('\\'), result += Ch('b'); - else if (*b == Ch('\f')) result += Ch('\\'), result += Ch('f'); - else if (*b == Ch('\n')) result += Ch('\\'), result += Ch('n'); - else if (*b == Ch('\r')) result += Ch('\\'), result += Ch('r'); - else if (*b == Ch('"')) result += Ch('\\'), result += Ch('"'); - else if (*b == Ch('\\')) result += Ch('\\'), result += Ch('\\'); - else - { - if (std::isprint(*b, loc)) - result += *b; - else - { - const char *hexdigits = "0123456789ABCDEF"; - unsigned long u = (std::min)(static_cast(*b), 0xFFFFul); - int d1 = u / 4096; u -= d1 * 4096; - int d2 = u / 256; u -= d2 * 256; - int d3 = u / 16; u -= d3 * 16; - int d4 = u; - result += Ch('\\'); result += Ch('u'); - result += Ch(hexdigits[d1]); result += Ch(hexdigits[d2]); - result += Ch(hexdigits[d3]); result += Ch(hexdigits[d4]); - } - } - ++b; - } - return result; - } - - template - void write_json_helper(std::basic_ostream &stream, - const Ptree &pt, - int indent) - { - - typedef typename Ptree::char_type Ch; - typedef typename std::basic_string Str; - - // Value or object or array - if (indent > 0 && pt.empty()) - { - - // Write value - Str data = create_escapes(pt.template get_own(), stream.getloc()); - stream << Ch('"') << data << Ch('"'); - - } - else if (indent > 0 && pt.count(Str()) == pt.size()) - { - - // Write array - stream << Ch('[') << Ch('\n'); - typename Ptree::const_iterator it = pt.begin(); - for (; it != pt.end(); ++it) - { - stream << Str(4 * (indent + 1), Ch(' ')); - write_json_helper(stream, it->second, indent + 1); - if (boost::next(it) != pt.end()) - stream << Ch(','); - stream << Ch('\n'); - } - stream << Str(4 * indent, Ch(' ')) << Ch(']'); - - } - else - { - - // Write object - stream << Ch('{') << Ch('\n'); - typename Ptree::const_iterator it = pt.begin(); - for (; it != pt.end(); ++it) - { - stream << Str(4 * (indent + 1), Ch(' ')); - stream << Ch('"') << create_escapes(it->first, stream.getloc()) << Ch('"') << Ch(':'); - if (it->second.empty()) - stream << Ch(' '); - else - stream << Ch('\n') << Str(4 * (indent + 1), Ch(' ')); - write_json_helper(stream, it->second, indent + 1); - if (boost::next(it) != pt.end()) - stream << Ch(','); - stream << Ch('\n'); - } - stream << Str(4 * indent, Ch(' ')) << Ch('}'); - - } - - } - - // Verify if ptree does not contain information that cannot be written to json - template - bool verify_json(const Ptree &pt, int depth) - { - - typedef typename Ptree::char_type Ch; - typedef typename std::basic_string Str; - - // Root ptree cannot have data - if (depth == 0 && !pt.template get_own().empty()) - return false; - - // Ptree cannot have both children and data - if (!pt.template get_own().empty() && !pt.empty()) - return false; - - // Check children - typename Ptree::const_iterator it = pt.begin(); - for (; it != pt.end(); ++it) - if (!verify_json(it->second, depth + 1)) - return false; - - // Success - return true; - - } - - // Write ptree to json stream - template - void write_json_internal(std::basic_ostream &stream, - const Ptree &pt, - const std::string &filename) - { - if (!verify_json(pt, 0)) - throw json_parser_error("ptree contains data that cannot be represented in JSON format", filename, 0); - write_json_helper(stream, pt, 0); - stream << std::endl; - if (!stream.good()) - throw json_parser_error("write error", filename, 0); - } - -} } } - -#endif diff --git a/boost/property_tree/detail/ptree_implementation.hpp b/boost/property_tree/detail/ptree_implementation.hpp deleted file mode 100644 index 590394b05..000000000 --- a/boost/property_tree/detail/ptree_implementation.hpp +++ /dev/null @@ -1,1002 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_PTREE_IMPLEMENTATION_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_PTREE_IMPLEMENTATION_HPP_INCLUDED - -#include -#include -#include -#include -#include -#include // for std::less -#include // for std::auto_ptr -#include -#include -#include -#include -#include // for boost::prior -#include - -////////////////////////////////////////////////////////////////////////////// -// Debug macros - -#ifdef BOOST_PROPERTY_TREE_DEBUG - - // Increment instances counter - #define BOOST_PROPERTY_TREE_DEBUG_INCREMENT_INSTANCES_COUNT() \ - { \ - typedef boost::detail::lightweight_mutex::scoped_lock lock; \ - lock l(debug_mutex); \ - ++debug_instances_count; \ - } - - // Decrement instances counter - #define BOOST_PROPERTY_TREE_DEBUG_DECREMENT_INSTANCES_COUNT() \ - { \ - typedef boost::detail::lightweight_mutex::scoped_lock lock; \ - lock l(debug_mutex); \ - BOOST_ASSERT(debug_instances_count > 0); \ - --debug_instances_count; \ - } - -#else // BOOST_PROPERTY_TREE_DEBUG - - #define BOOST_PROPERTY_TREE_DEBUG_INCREMENT_INSTANCES_COUNT() static_cast(0) - #define BOOST_PROPERTY_TREE_DEBUG_DECREMENT_INSTANCES_COUNT() static_cast(0) - -#endif // BOOST_PROPERTY_TREE_DEBUG - -namespace boost { namespace property_tree -{ - - namespace detail - { - - template - struct array_to_pointer_decay - { - typedef T type; - }; - - template - struct array_to_pointer_decay - { - typedef const T *type; - }; - - //////////////////////////////////////////////////////////////////////////// - // Extractor and inserter - - template - struct extractor - { - inline bool operator()(const std::basic_string &data, - Type &extracted, - const std::locale &loc) const - { - std::basic_istringstream stream(data); - stream.imbue(loc); - stream >> extracted >> std::ws; - return stream.eof() && !stream.fail() && !stream.bad(); - } - }; - - template - struct extractor > - { - inline bool operator()(const std::basic_string &data, - std::basic_string &extracted, - const std::locale &loc) const - { - extracted = data; - return true; - } - }; - - template - struct inserter - { - inline bool operator()(std::basic_string &data, - const Type &to_insert, - const std::locale &loc) const - { - typedef typename detail::array_to_pointer_decay::type Type2; - std::basic_ostringstream stream; - stream.imbue(loc); - if (std::numeric_limits::is_specialized) - stream.precision(std::numeric_limits::digits10 + 1); - stream << to_insert; - data = stream.str(); - return !stream.fail() && !stream.bad(); - } - }; - - template - struct inserter > - { - inline bool operator()(std::basic_string &data, - const std::basic_string &to_insert, - const std::locale &loc) const - { - data = to_insert; - return true; - } - }; - - } - - /////////////////////////////////////////////////////////////////////////// - // Impl - - template - struct basic_ptree::impl - { - data_type m_data; - container_type m_container; - index_type m_index; - }; - - //////////////////////////////////////////////////////////////////////////// - // Traits - - template - struct ptree_traits - { - typedef Ch char_type; - typedef std::basic_string key_type; - typedef std::basic_string data_type; - template - struct extractor: public detail::extractor { }; - template - struct inserter: public detail::inserter { }; - inline bool operator()(const key_type &key1, - const key_type &key2) const - { - return key1 < key2; - } - }; - - template - struct iptree_traits - { - std::locale loc; - typedef Ch char_type; - typedef std::basic_string key_type; - typedef std::basic_string data_type; - template - struct extractor: public detail::extractor { }; - template - struct inserter: public detail::inserter { }; - inline bool operator()(Ch c1, Ch c2) const // Helper for comparing characters - { - return std::toupper(c1, loc) < std::toupper(c2, loc); - } - inline bool operator()(const key_type &key1, - const key_type &key2) const - { - return std::lexicographical_compare(key1.begin(), key1.end(), key2.begin(), key2.end(), *this); - } - }; - - /////////////////////////////////////////////////////////////////////////// - // Exceptions - - class ptree_error: public std::runtime_error - { - public: - ptree_error(const std::string &what): std::runtime_error(what) { } - ~ptree_error() throw() { } - }; - - class ptree_bad_data: public ptree_error - { - public: - ptree_bad_data(const std::string &what): ptree_error(what) { } - ~ptree_bad_data() throw() { } - }; - - class ptree_bad_path: public ptree_error - { - public: - ptree_bad_path(const std::string &what): ptree_error(what) { } - ~ptree_bad_path() throw() { } - }; - - /////////////////////////////////////////////////////////////////////////// - // Construction & destruction - - template - basic_ptree::basic_ptree() - { - m_impl = new impl; - BOOST_PROPERTY_TREE_DEBUG_INCREMENT_INSTANCES_COUNT(); - } - - template - basic_ptree::basic_ptree(const data_type &rhs) - { - std::auto_ptr tmp(new impl); - tmp->m_data = rhs; - m_impl = tmp.release(); - BOOST_PROPERTY_TREE_DEBUG_INCREMENT_INSTANCES_COUNT(); - } - - template - basic_ptree::basic_ptree(const basic_ptree &rhs) - { - std::auto_ptr tmp(new impl); - tmp->m_data = rhs.data(); - m_impl = tmp.get(); - insert(end(), rhs.begin(), rhs.end()); - tmp.release(); - BOOST_PROPERTY_TREE_DEBUG_INCREMENT_INSTANCES_COUNT(); - } - - template - basic_ptree::~basic_ptree() - { - BOOST_PROPERTY_TREE_DEBUG_DECREMENT_INSTANCES_COUNT(); - delete m_impl; - } - - /////////////////////////////////////////////////////////////////////////// - // Iterator access - - template - typename basic_ptree::iterator - basic_ptree::begin() - { - return m_impl->m_container.begin(); - } - - template - typename basic_ptree::const_iterator - basic_ptree::begin() const - { - return m_impl->m_container.begin(); - } - - template - typename basic_ptree::iterator - basic_ptree::end() - { - return m_impl->m_container.end(); - } - - template - typename basic_ptree::const_iterator - basic_ptree::end() const - { - return m_impl->m_container.end(); - } - - template - typename basic_ptree::reverse_iterator - basic_ptree::rbegin() - { - return m_impl->m_container.rbegin(); - } - - template - typename basic_ptree::const_reverse_iterator - basic_ptree::rbegin() const - { - return m_impl->m_container.rbegin(); - } - - template - typename basic_ptree::reverse_iterator - basic_ptree::rend() - { - return m_impl->m_container.rend(); - } - - template - typename basic_ptree::const_reverse_iterator - basic_ptree::rend() const - { - return m_impl->m_container.rend(); - } - - /////////////////////////////////////////////////////////////////////////// - // Data access - - template - typename basic_ptree::size_type - basic_ptree::size() const - { - return m_impl->m_index.size(); - } - - template - bool basic_ptree::empty() const - { - return m_impl->m_index.empty(); - } - - template - typename basic_ptree::data_type & - basic_ptree::data() - { - return m_impl->m_data; - } - - template - const typename basic_ptree::data_type & - basic_ptree::data() const - { - return m_impl->m_data; - } - - template - typename basic_ptree::value_type & - basic_ptree::front() - { - return m_impl->m_container.front(); - } - - template - const typename basic_ptree::value_type & - basic_ptree::front() const - { - return m_impl->m_container.front(); - } - - template - typename basic_ptree::value_type & - basic_ptree::back() - { - return m_impl->m_container.back(); - } - - template - const typename basic_ptree::value_type & - basic_ptree::back() const - { - return m_impl->m_container.back(); - } - - /////////////////////////////////////////////////////////////////////////// - // Operators - - template - basic_ptree & - basic_ptree::operator =(const basic_ptree &rhs) - { - if (&rhs != this) - { - clear(); - data() = rhs.data(); - insert(end(), rhs.begin(), rhs.end()); - } - return *this; - } - - template - bool basic_ptree::operator ==(const basic_ptree &rhs) const - { - - // Data and sizes must be equal - if (size() != rhs.size() || data() != rhs.data()) - return false; - - // Keys and children must be equal - Tr tr; - const_iterator it = begin(); - const_iterator it_rhs = rhs.begin(); - const_iterator it_end = end(); - for (; it != it_end; ++it, ++it_rhs) - if (tr(it->first, it_rhs->first) || - tr(it_rhs->first, it->first) || - it->second != it_rhs->second) - return false; - - // Equal - return true; - - } - - template - bool basic_ptree::operator !=(const basic_ptree &rhs) const - { - return !operator ==(rhs); - } - - /////////////////////////////////////////////////////////////////////////// - // Container operations - - template - typename basic_ptree::iterator - basic_ptree::find(const key_type &key) - { - typename index_type::iterator it = m_impl->m_index.find(key); - return it == m_impl->m_index.end() ? end() : it->second; - } - - template - typename basic_ptree::const_iterator - basic_ptree::find(const key_type &key) const - { - typename index_type::const_iterator it = m_impl->m_index.find(key); - return it == m_impl->m_index.end() ? end() : it->second; - } - - template - typename basic_ptree::size_type - basic_ptree::count(const key_type &key) const - { - return m_impl->m_index.count(key); - } - - template - void basic_ptree::clear() - { - m_impl->m_data = data_type(); - m_impl->m_container.clear(); - m_impl->m_index.clear(); - } - - template - typename basic_ptree::iterator - basic_ptree::insert(iterator where, - const value_type &value) - { - - // Insert new value into container. If that throws nothing needs to be rolled back - where = m_impl->m_container.insert(where, value); - - // Update index. If that throws we need to rollback the insert - try { - m_impl->m_index.insert(typename index_type::value_type(where->first, where)); - } - catch (...) { - m_impl->m_container.erase(where); // rollback the insert - throw; - } - - return where; - } - - template - template - void basic_ptree::insert(iterator where, - It first, - It last) - { - for (; first != last; ++first, ++where) - where = insert(where, value_type(first->first, first->second)); - } - - template - typename basic_ptree::iterator - basic_ptree::erase(iterator where) - { - - // Remove from index - typename index_type::iterator lo = m_impl->m_index.lower_bound(where->first); - typename index_type::iterator hi = m_impl->m_index.upper_bound(where->first); - for (; lo != hi; ++lo) - if (lo->second == where) - { - m_impl->m_index.erase(lo); - break; - } - - // Remove from container - return m_impl->m_container.erase(where); - - } - - template - typename basic_ptree::size_type - basic_ptree::erase(const key_type &key) - { - size_type count = 0; - typename index_type::iterator lo = m_impl->m_index.lower_bound(key); - if (lo != m_impl->m_index.end()) - { - typename index_type::iterator hi = m_impl->m_index.upper_bound(key); - while (lo != hi) - { - typename index_type::iterator it = lo++; - erase(it->second); - ++count; - } - } - return count; - } - - template - template - typename basic_ptree::iterator - basic_ptree::erase(It first, - It last) - { - while (first != last) - first = erase(first); - return first; - } - - template - typename basic_ptree::iterator - basic_ptree::push_front(const value_type &value) - { - return insert(begin(), value); - } - - template - typename basic_ptree::iterator - basic_ptree::push_back(const value_type &value) - { - return insert(end(), value); - } - - template - void basic_ptree::pop_front() - { - erase(begin()); - } - - template - void basic_ptree::pop_back() - { - erase(boost::prior(end())); - } - - template - void basic_ptree::swap(basic_ptree &rhs) - { - std::swap(m_impl, rhs.m_impl); - } - - template - void basic_ptree::reverse() - { - m_impl->m_container.reverse(); - } - - template - template - void basic_ptree::sort(SortTr tr) - { - m_impl->m_container.sort(tr); - } - - /////////////////////////////////////////////////////////////////////////// - // ptree operations - - // Get child ptree with custom separator - template - basic_ptree & - basic_ptree::get_child(char_type separator, - const key_type &path) - { - if (optional &> result = get_child_optional(separator, path)) - return result.get(); - else - throw ptree_bad_path("key \"" + detail::narrow(path.c_str()) + "\" does not exist"); - } - - // Get child ptree with custom separator - template - const basic_ptree & - basic_ptree::get_child(char_type separator, - const key_type &path) const - { - basic_ptree *nc_this = const_cast *>(this); - return nc_this->get_child(separator, path); - } - - // Get child ptree with custom separator - template - basic_ptree & - basic_ptree::get_child(char_type separator, - const key_type &path, - basic_ptree &default_value) - { - if (optional &> result = get_child_optional(separator, path)) - return result.get(); - else - return default_value; - } - - // Get child ptree with custom separator - template - const basic_ptree & - basic_ptree::get_child(char_type separator, - const key_type &path, - const basic_ptree &default_value) const - { - basic_ptree *nc_this = const_cast *>(this); - basic_ptree &nc_default_value = const_cast &>(default_value); - return nc_this->get_child(separator, path, nc_default_value); - } - - - // Get child ptree with custom separator - template - optional &> - basic_ptree::get_child_optional(char_type separator, - const key_type &path) - { - typename key_type::size_type n = path.find(separator); - if (n != key_type::npos) - { - key_type head = path.substr(0, n); - key_type tail = path.substr(n + 1, key_type::npos); - iterator it = find(head); - if (it != end()) - return it->second.get_child_optional(separator, tail); - else - return optional &>(); - } - else - { - iterator it = find(path); - if (it != end()) - return it->second; - else - return optional &>(); - } - } - - // Get child ptree with custom separator - template - optional &> - basic_ptree::get_child_optional(char_type separator, const key_type &path) const - { - basic_ptree *nc_this = const_cast *>(this); - optional &> tmp = nc_this->get_child_optional(separator, path); - if (tmp) - return optional &>(tmp.get()); - else - return optional &>(); - } - - // Get child ptree with default separator - template - basic_ptree & - basic_ptree::get_child(const key_type &path) - { - return get_child(char_type('.'), path); - } - - // Get child ptree with default separator - template - const basic_ptree & - basic_ptree::get_child(const key_type &path) const - { - return get_child(char_type('.'), path); - } - - // Get child ptree with default separator - template - basic_ptree & - basic_ptree::get_child(const key_type &path, - basic_ptree &default_value) - { - return get_child(char_type('.'), path, default_value); - } - - // Get child ptree with default separator - template - const basic_ptree & - basic_ptree::get_child(const key_type &path, - const basic_ptree &default_value) const - { - return get_child(char_type('.'), path, default_value); - } - - // Get child ptree with default separator - template - optional &> - basic_ptree::get_child_optional(const key_type &path) - { - return get_child_optional(char_type('.'), path); - } - - // Get child ptree with default separator - template - optional &> - basic_ptree::get_child_optional(const key_type &path) const - { - return get_child_optional(char_type('.'), path); - } - - // Put child ptree with custom separator - template - basic_ptree & - basic_ptree::put_child(char_type separator, - const key_type &path, - const basic_ptree &value, - bool do_not_replace) - { - typename key_type::size_type n = path.find(separator); - if (n == key_type::npos) - { - if (do_not_replace) - return push_back(value_type(path, value))->second; - else - { - iterator it = find(path); - if (it == end()) - return push_back(value_type(path, value))->second; - else - { - it->second = value; - return it->second; - } - } - } - else - { - key_type head = path.substr(0, n); - key_type tail = path.substr(n + 1, key_type::npos); - iterator it = find(head); - if (it == end()) - it = push_back(value_type(head, basic_ptree())); - return it->second.put_child(separator, tail, value, do_not_replace); - } - } - - // Put child ptree with default separator - template - basic_ptree & - basic_ptree::put_child(const key_type &path, - const basic_ptree &value, - bool do_not_replace) - { - return put_child(char_type('.'), path, value, do_not_replace); - } - - // Get value from data of ptree - template - template - Type basic_ptree::get_own(const std::locale &loc) const - { - if (optional result = get_own_optional(loc)) - return result.get(); - else - throw ptree_bad_data(std::string("conversion of data into type '") + - typeid(Type).name() + "' failed"); - } - - // Get value from data of ptree - template - template - Type basic_ptree::get_own(const Type &default_value, - const std::locale &loc) const - { - if (optional result = get_own_optional(loc)) - return result.get(); - else - return default_value; - } - - // Get value from data of ptree - template - template - std::basic_string - basic_ptree::get_own(const CharType *default_value, - const std::locale &loc) const - { - BOOST_STATIC_ASSERT((boost::is_same::value == true)); // Character types must match - return get_own(std::basic_string(default_value), loc); - } - - // Get value from data of ptree - template - template - optional - basic_ptree::get_own_optional(const std::locale &loc) const - { - BOOST_STATIC_ASSERT(boost::is_pointer::value == false); // Disallow pointer types, they are unsafe - Type tmp; - if (typename traits_type::template extractor()(m_impl->m_data, tmp, loc)) - { - return optional(tmp); - } - else - return optional(); - } - - // Get value from data of child ptree (custom path separator) - template - template - Type basic_ptree::get(char_type separator, - const key_type &path, - const std::locale &loc) const - { - return get_child(separator, path).get_own(loc); - } - - // Get value from data of child ptree (custom path separator) - template - template - Type basic_ptree::get(char_type separator, - const key_type &path, - const Type &default_value, - const std::locale &loc) const - { - if (optional result = get_optional(separator, path, loc)) - return *result; - else - return default_value; - } - - // Get value from data of child ptree (custom path separator) - template - template - std::basic_string - basic_ptree::get(char_type separator, - const key_type &path, - const CharType *default_value, - const std::locale &loc) const - { - BOOST_STATIC_ASSERT((boost::is_same::value == true)); // Character types must match - return get(separator, path, std::basic_string(default_value), loc); - } - - // Get value from data of child ptree (custom path separator) - template - template - optional - basic_ptree::get_optional(char_type separator, - const key_type &path, - const std::locale &loc) const - { - if (optional &> child = get_child_optional(separator, path)) - return child.get().get_own_optional(loc); - else - return optional(); - } - - // Get value from data of child ptree (default path separator) - template - template - Type basic_ptree::get(const key_type &path, - const std::locale &loc) const - { - return get(char_type('.'), path, loc); - } - - // Get value from data of child ptree (default path separator) - template - template - Type basic_ptree::get(const key_type &path, - const Type &default_value, - const std::locale &loc) const - { - return get(char_type('.'), path, default_value, loc); - } - - // Get value from data of child ptree (default path separator) - template - template - std::basic_string - basic_ptree::get(const key_type &path, - const CharType *default_value, - const std::locale &loc) const - { - return get(char_type('.'), path, default_value, loc); - } - - // Get value from data of child ptree (default path separator) - template - template - optional - basic_ptree::get_optional(const key_type &path, - const std::locale &loc) const - { - return get_optional(char_type('.'), path, loc); - } - - // Put value in data of ptree - template - template - void basic_ptree::put_own(const Type &value, const std::locale &loc) - { - using namespace boost; - // Make sure that no pointer other than char_type * is allowed - BOOST_STATIC_ASSERT((is_pointer::value == false || - is_same::type>::type>::value == true)); -#ifdef __SUNPRO_CC - // For the Sun Studio compiler the declaration needs to be within a statement. - if (typename traits_type::template inserter()(m_impl->m_data, value, loc)){} -#else - typename traits_type::template inserter()(m_impl->m_data, value, loc); -#endif - } - - // Put value in data of child ptree (custom path separator) - template - template - basic_ptree & - basic_ptree::put(char_type separator, - const key_type &path, - const Type &value, - bool do_not_replace, - const std::locale &loc) - { - optional &> child; - if (!do_not_replace && - (child = get_child_optional(separator, path))) - { - child.get().put_own(value, loc); - return *child; - } - else - { - basic_ptree &child2 = put_child(separator, path, empty_ptree >(), do_not_replace); - child2.put_own(value, loc); - return child2; - } - } - - // Put value in data of child ptree (default path separator) - template - template - basic_ptree & - basic_ptree::put(const key_type &path, - const Type &value, - bool do_not_replace, - const std::locale &loc) - { - return put(char_type('.'), path, value, do_not_replace, loc); - } - - //////////////////////////////////////////////////////////////////////////// - // Debugging - -#ifdef BOOST_PROPERTY_TREE_DEBUG - - template - typename basic_ptree::size_type - basic_ptree::debug_get_instances_count() - { - empty_ptree >(); // Make sure empty ptree exists - return debug_instances_count - 1; // Do not count empty ptree - } - - template - typename basic_ptree::size_type - basic_ptree::debug_instances_count; - - template - boost::detail::lightweight_mutex - basic_ptree::debug_mutex; - -#endif - - /////////////////////////////////////////////////////////////////////////// - // Free functions - - template - inline const Ptree &empty_ptree() - { - static Ptree pt; - return pt; - } - - template - inline void swap(basic_ptree &pt1, basic_ptree &pt2) - { - pt1.swap(pt2); - } - -} } - -// Undefine debug macros -#ifdef BOOST_PROPERTY_TREE_DEBUG -# undef BOOST_PROPERTY_TREE_DEBUG_INCREMENT_INSTANCES_COUNT -# undef BOOST_PROPERTY_TREE_DEBUG_DECREMENT_INSTANCES_COUNT -#endif - -#endif diff --git a/boost/property_tree/detail/ptree_interface.hpp b/boost/property_tree/detail/ptree_interface.hpp deleted file mode 100644 index 9630709e5..000000000 --- a/boost/property_tree/detail/ptree_interface.hpp +++ /dev/null @@ -1,198 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_PTREE_INTERFACE_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_PTREE_INTERFACE_HPP_INCLUDED - -#include -#include -#include -#include -#include -#include // For std::pair -#include - -#include "boost/property_tree/ptree_fwd.hpp" - -#ifdef BOOST_PROPERTY_TREE_DEBUG -# include // For syncing debug instances counter -#endif - -namespace boost { namespace property_tree -{ - - /////////////////////////////////////////////////////////////////////////// - // basic_ptree class template - - template - class basic_ptree - { - - public: - - // Basic types - typedef Tr traits_type; - typedef typename traits_type::char_type char_type; - typedef typename traits_type::key_type key_type; - typedef typename traits_type::data_type data_type; - - // Container-related types - typedef std::pair > value_type; - typedef std::list container_type; - typedef typename container_type::size_type size_type; - typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; - typedef typename container_type::reverse_iterator reverse_iterator; - typedef typename container_type::const_reverse_iterator const_reverse_iterator; - - /////////////////////////////////////////////////////////////////////////// - // Construction & destruction - - basic_ptree(); - explicit basic_ptree(const data_type &data); - basic_ptree(const basic_ptree &rhs); - ~basic_ptree(); - - /////////////////////////////////////////////////////////////////////////// - // Iterator access - - iterator begin(); - const_iterator begin() const; - iterator end(); - const_iterator end() const; - reverse_iterator rbegin(); - const_reverse_iterator rbegin() const; - reverse_iterator rend(); - const_reverse_iterator rend() const; - - /////////////////////////////////////////////////////////////////////////// - // Data access - - size_type size() const; - bool empty() const; - - data_type &data(); - const data_type &data() const; - - value_type &front(); - const value_type &front() const; - value_type &back(); - const value_type &back() const; - - /////////////////////////////////////////////////////////////////////////// - // Operators - - basic_ptree &operator =(const basic_ptree &rhs); - - bool operator ==(const basic_ptree &rhs) const; - bool operator !=(const basic_ptree &rhs) const; - - /////////////////////////////////////////////////////////////////////////// - // Container operations - - iterator find(const key_type &key); - const_iterator find(const key_type &key) const; - - size_type count(const key_type &key) const; - - void clear(); - - iterator insert(iterator where, const value_type &value); - template void insert(iterator where, It first, It last); - - iterator erase(iterator where); - size_type erase(const key_type &key); - template iterator erase(It first, It last); - - iterator push_front(const value_type &value); - iterator push_back(const value_type &value); - - void pop_front(); - void pop_back(); - - void swap(basic_ptree &rhs); - - void reverse(); - template void sort(SortTr tr); - - /////////////////////////////////////////////////////////////////////////// - // ptree operations - - // Get child ptree with custom separator - basic_ptree &get_child(char_type separator, const key_type &path); - const basic_ptree &get_child(char_type separator, const key_type &path) const; - basic_ptree &get_child(char_type separator, const key_type &path, basic_ptree &default_value); - const basic_ptree &get_child(char_type separator, const key_type &path, const basic_ptree &default_value) const; - optional &> get_child_optional(char_type separator, const key_type &path); - optional &> get_child_optional(char_type separator, const key_type &path) const; - - // Get child ptree with default separator - basic_ptree &get_child(const key_type &path); - const basic_ptree &get_child(const key_type &path) const; - basic_ptree &get_child(const key_type &path, basic_ptree &default_value); - const basic_ptree &get_child(const key_type &path, const basic_ptree &default_value) const; - optional &> get_child_optional(const key_type &path); - optional &> get_child_optional(const key_type &path) const; - - // Put child ptree with custom separator - basic_ptree &put_child(char_type separator, const key_type &path, const basic_ptree &value, bool do_not_replace = false); - - // Put child ptree with default separator - basic_ptree &put_child(const key_type &path, const basic_ptree &value, bool do_not_replace = false); - - // Get value from data of ptree - template Type get_own(const std::locale &loc = std::locale()) const; - template Type get_own(const Type &default_value, const std::locale &loc = std::locale()) const; - template std::basic_string get_own(const CharType *default_value, const std::locale &loc = std::locale()) const; - template optional get_own_optional(const std::locale &loc = std::locale()) const; - - // Get value from data of child ptree (custom path separator) - template Type get(char_type separator, const key_type &path, const std::locale &loc = std::locale()) const; - template Type get(char_type separator, const key_type &path, const Type &default_value, const std::locale &loc = std::locale()) const; - template std::basic_string get(char_type separator, const key_type &path, const CharType *default_value, const std::locale &loc = std::locale()) const; - template optional get_optional(char_type separator, const key_type &path, const std::locale &loc = std::locale()) const; - - // Get value from data of child ptree (default path separator) - template Type get(const key_type &path, const std::locale &loc = std::locale()) const; - template Type get(const key_type &path, const Type &default_value, const std::locale &loc = std::locale()) const; - template std::basic_string get(const key_type &path, const CharType *default_value, const std::locale &loc = std::locale()) const; - template optional get_optional(const key_type &path, const std::locale &loc = std::locale()) const; - - // Put value in data of ptree - template void put_own(const Type &value, const std::locale &loc = std::locale()); - - // Put value in data of child ptree (custom path separator) - template basic_ptree &put(char_type separator, const key_type &path, const Type &value, bool do_not_replace = false, const std::locale &loc = std::locale()); - - // Put value in data of child ptree (default path separator) - template basic_ptree &put(const key_type &path, const Type &value, bool do_not_replace = false, const std::locale &loc = std::locale()); - - private: - - typedef std::multimap index_type; - - struct impl; - impl *m_impl; - - //////////////////////////////////////////////////////////////////////////// - // Debugging - -#ifdef BOOST_PROPERTY_TREE_DEBUG - private: - static boost::detail::lightweight_mutex debug_mutex; // Mutex for syncing instances counter - static size_type debug_instances_count; // Total number of instances of this ptree class - public: - static size_type debug_get_instances_count(); -#endif - - }; - -} } - -#endif diff --git a/boost/property_tree/detail/ptree_utils.hpp b/boost/property_tree/detail/ptree_utils.hpp deleted file mode 100644 index e5e2bb68e..000000000 --- a/boost/property_tree/detail/ptree_utils.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_PTREE_UTILS_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_PTREE_UTILS_HPP_INCLUDED - -#include -#include -#include - -namespace boost { namespace property_tree { namespace detail -{ - - // Naively convert narrow string to another character type - template - std::basic_string widen(const char *text) - { - std::locale loc; - std::basic_string result; - while (*text) - { - result += Ch(*text); - ++text; - } - return result; - } - - // Naively convert string to narrow character type - template - std::string narrow(const Ch *text) - { - std::locale loc; - std::string result; - while (*text) - { - if (*text < 0 || *text > (std::numeric_limits::max)()) - result += '*'; - else - result += char(*text); - ++text; - } - return result; - } - - // Remove trailing and leading spaces - template - std::basic_string trim(const std::basic_string &s, - const std::locale &loc = std::locale()) - { - typename std::basic_string::const_iterator first = s.begin(); - typename std::basic_string::const_iterator end = s.end(); - while (first != end && std::isspace(*first, loc)) - ++first; - if (first == end) - return std::basic_string(); - typename std::basic_string::const_iterator last = end; - do --last; while (std::isspace(*last, loc)); - if (first != s.begin() || last + 1 != end) - return std::basic_string(first, last + 1); - else - return s; - } - -} } } - -#endif diff --git a/boost/property_tree/detail/xml_parser_error.hpp b/boost/property_tree/detail/xml_parser_error.hpp deleted file mode 100644 index 4c7f49853..000000000 --- a/boost/property_tree/detail/xml_parser_error.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_ERROR_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_ERROR_HPP_INCLUDED - -#include -#include - -namespace boost { namespace property_tree { namespace xml_parser -{ - - //! Xml parser error - class xml_parser_error: public file_parser_error - { - public: - xml_parser_error(const std::string &message, - const std::string &filename, - unsigned long line): - file_parser_error(message, filename, line) - { - } - }; - -} } } - -#endif diff --git a/boost/property_tree/detail/xml_parser_flags.hpp b/boost/property_tree/detail/xml_parser_flags.hpp deleted file mode 100644 index 75ef67279..000000000 --- a/boost/property_tree/detail/xml_parser_flags.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_FLAGS_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_FLAGS_HPP_INCLUDED - -namespace boost { namespace property_tree { namespace xml_parser -{ - - static const int no_concat_text = 1; // Text elements should be put in separate keys, not concatenated in parent data - static const int no_comments = 2; // Comments should be omitted - - inline bool validate_flags(int flags) - { - return (flags & ~(no_concat_text | no_comments)) == 0; - } - -} } } - -#endif diff --git a/boost/property_tree/detail/xml_parser_read_spirit.hpp b/boost/property_tree/detail/xml_parser_read_spirit.hpp deleted file mode 100644 index 0fd593c27..000000000 --- a/boost/property_tree/detail/xml_parser_read_spirit.hpp +++ /dev/null @@ -1,737 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// Based on XML grammar by Daniel C. Nuffer -// http://spirit.sourceforge.net/repository/applications/xml.zip -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_READ_SPIRIT_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_READ_SPIRIT_HPP_INCLUDED - -//#define BOOST_SPIRIT_DEBUG -#include -#include -#include -#include -#include - -#if BOOST_VERSION < 103800 -#include -#include -#else -#define BOOST_SPIRIT_USE_OLD_NAMESPACE -#include -#include -#endif - -#include -#include -#include -#include - -namespace boost { namespace property_tree { namespace xml_parser -{ - - // XML parser context - template - struct context - { - - typedef typename Ptree::char_type Ch; - typedef std::basic_string Str; - typedef boost::spirit::position_iterator::const_iterator> It; - - int flags; - std::vector stack; - - /////////////////////////////////////////////////////////////////////// - // Actions - - struct a_key_s - { - context &c; - a_key_s(context &c): c(c) { } - void operator()(It b, It e) const - { - if (c.stack.empty()) - throw xml_parser_error("xml parse error", - b.get_position().file, - b.get_position().line); - Str name(b, e); - Ptree *child = &c.stack.back()->push_back(std::make_pair(name, Ptree()))->second; - c.stack.push_back(child); - } - }; - - struct a_key_e - { - context &c; - a_key_e(context &c): c(c) { } - void operator()(It b, It e) const - { - if (c.stack.size() <= 1) - throw xml_parser_error("xml parse error", - b.get_position().file, - b.get_position().line); - c.stack.pop_back(); - } - }; - - struct a_content - { - context &c; - a_content(context &c): c(c) { } - void operator()(It b, It e) const - { - Str s = decode_char_entities(detail::trim(condense(Str(b, e)))); - if (!s.empty()) - { - if (c.flags & no_concat_text) - c.stack.back()->push_back(std::make_pair(xmltext(), Ptree(s))); - else - c.stack.back()->put_own(c.stack.back()->template get_own >() + s); - } - } - }; - - struct a_attr_key - { - context &c; - a_attr_key(context &c): c(c) { } - void operator()(It b, It e) const - { - c.stack.back()->put_child(Ch('/'), xmlattr() + Ch('/') + Str(b, e), empty_ptree()); - } - }; - - struct a_attr_data - { - context &c; - a_attr_data(context &c): c(c) { } - void operator()(It b, It e) const - { - Ptree &attr = c.stack.back()->get_child(xmlattr()); - attr.back().second.put_own(Str(b.base() + 1, e.base() - 1)); - } - }; - - struct a_comment - { - context &c; - a_comment(context &c): c(c) { } - void operator()(It b, It e) const - { - c.stack.back()->push_back(std::make_pair(xmlcomment(), Ptree(Str(b, e)))); - } - }; - - }; - - /////////////////////////////////////////////////////////////////////// - // Grammar - - template - struct xml_grammar: public boost::spirit::grammar > - { - - typedef context context_t; - - mutable context_t c; - - template - struct definition - { - - typedef typename ScannerT::value_t char_t; - typedef boost::spirit::chset chset_t; - - boost::spirit::rule - prolog, element, Misc, PEReference, Reference, PITarget, CData, - doctypedecl, XMLDecl, SDDecl, VersionInfo, EncodingDecl, VersionNum, - Eq, DeclSep, ExternalID, markupdecl, NotationDecl, EntityDecl, - AttlistDecl, elementdecl, TextDecl, extSubsetDecl, conditionalSect, - EmptyElemTag, STag, content, ETag, Attribute, contentspec, Mixed, - children, choice, seq, cp, AttDef, AttType, DefaultDecl, StringType, - TokenizedType, EnumeratedType, NotationType, Enumeration, EntityValue, - AttValue, SystemLiteral, PubidLiteral, CharDataChar, CharData, Comment, - PI, CDSect, extSubset, includeSect, ignoreSect, ignoreSectContents, - Ignore, CharRef, EntityRef, GEDecl, PEDecl, EntityDef, PEDef, - NDataDecl, extParsedEnt, EncName, PublicID, document, S, Name, Names, - Nmtoken, Nmtokens, STagB, STagE1, STagE2; - - definition(const xml_grammar &self) - { - - using namespace boost::spirit; - - // XML Char sets - chset_t Char("\x9\xA\xD\x20-\x7F"); - chset_t Sch("\x20\x9\xD\xA"); - chset_t Letter("\x41-\x5A\x61-\x7A"); - chset_t Digit("0-9"); - chset_t XDigit("0-9A-Fa-f"); - chset_t Extender("\xB7"); - chset_t NameChar = - Letter - | Digit - | (char_t)'.' - | (char_t)'-' - | (char_t)'_' - | (char_t)':' - | Extender; - - document = - prolog >> element >> *Misc - ; - - S = - +(Sch) - ; - - Name = - (Letter | '_' | ':') - >> *(NameChar) - ; - - Names = - Name >> *(S >> Name) - ; - - Nmtoken = - +NameChar - ; - - Nmtokens = - Nmtoken >> *(S >> Nmtoken) - ; - - EntityValue = - '"' >> *( (anychar_p - (chset_t(detail::widen("%&\"").c_str()))) - | PEReference - | Reference) - >> '"' - | '\'' >> *( (anychar_p - (chset_t("%&'"))) - | PEReference - | Reference) - >> '\'' - ; - - AttValue = - '"' >> *( (anychar_p - (chset_t("<&\""))) - | Reference) - >> '"' - | '\'' >> *( (anychar_p - (chset_t("<&'"))) - | Reference) - >> '\'' - ; - - SystemLiteral= - ('"' >> *(anychar_p - '"') >> '"') - | ('\'' >> *(anychar_p - '\'') >> '\'') - ; - - chset_t PubidChar("\x20\xD\xA'a-zA-Z0-9()+,./:=?;!*#@$_%-"); - - PubidLiteral = - '"' >> *PubidChar >> '"' - | '\'' >> *(PubidChar - '\'') >> '\'' - ; - - CharDataChar = - //anychar_p - (chset_t("<&")) - anychar_p - (chset_t("<")) - ; - - CharData = - *(CharDataChar - "]]>") - ; - - Comment = - "" - ; - - PI = - "> PITarget >> !(S >> (*(Char - "?>"))) >> "?>" - ; - - PITarget = - Name - (as_lower_d["xml"]) - ; - - CDSect = - "> CData >> "]]>" - ; - - CData = - *(Char - "]]>") - ; - - prolog = - !XMLDecl >> *Misc >> !(doctypedecl >> *Misc) - ; - - XMLDecl = - "> VersionInfo >> !EncodingDecl >> !SDDecl - >> !S >> "?>" - ; - - VersionInfo = - S >> "version" >> Eq >> - ( - '\'' >> VersionNum >> '\'' - | '"' >> VersionNum >> '"' - ) - ; - - Eq = - !S >> '=' >> !S - ; - - chset_t VersionNumCh("a-zA-Z0-9_.:-"); - - VersionNum = - +(VersionNumCh) - ; - - Misc = - Comment - | PI - | S - ; - - doctypedecl = - "> S >> Name >> !(S >> ExternalID) >> !S >> - !( - '[' >> *(markupdecl | DeclSep) >> ']' >> !S - ) - >> '>' - ; - - DeclSep = - PEReference - | S - ; - - markupdecl = - elementdecl - | AttlistDecl - | EntityDecl - | NotationDecl - | PI - | Comment - ; - - extSubset = - !TextDecl >> extSubsetDecl - ; - - extSubsetDecl = - *( - markupdecl - | conditionalSect - | DeclSep - ) - ; - - SDDecl = - S >> "standalone" >> Eq >> - ( - ('\'' >> (str_p("yes") | "no") >> '\'') - | ('"' >> (str_p("yes") | "no") >> '"') - ) - ; - - /* - element = - EmptyElemTag - | STag >> content >> ETag - ; - */ - element = - STagB >> (STagE2 | (STagE1 >> content >> ETag))[typename context_t::a_key_e(self.c)] - ; - - STag = - '<' >> Name >> *(S >> Attribute) >> !S >> '>' - ; - - STagB = - '<' - >> Name[typename context_t::a_key_s(self.c)] - >> *(S >> Attribute) - >> !S - ; - - STagE1 = - ch_p(">") - ; - - STagE2 = - str_p("/>") - ; - - Attribute = - Name[typename context_t::a_attr_key(self.c)] - >> Eq - >> AttValue[typename context_t::a_attr_data(self.c)] - ; - - ETag = - "> Name >> !S >> '>' - ; - - content = - !(CharData[typename context_t::a_content(self.c)]) >> - *( - ( - element - // | Reference - | CDSect - | PI - | Comment - ) >> - !(CharData[typename context_t::a_content(self.c)]) - ) - ; - - EmptyElemTag = - '<' >> Name >> *(S >> Attribute) >> !S >> "/>" - ; - - elementdecl = - "> S >> Name >> S >> contentspec >> !S >> '>' - ; - - contentspec = - str_p("EMPTY") - | "ANY" - | Mixed - | children - ; - - children = - (choice | seq) >> !(ch_p('?') | '*' | '+') - ; - - cp = - (Name | choice | seq) >> !(ch_p('?') | '*' | '+') - ; - - choice = - '(' >> !S >> cp - >> +(!S >> '|' >> !S >> cp) - >> !S >> ')' - ; - - seq = - '(' >> !S >> cp >> - *(!S >> ',' >> !S >> cp) - >> !S >> ')' - ; - - Mixed = - '(' >> !S >> "#PCDATA" - >> *(!S >> '|' >> !S >> Name) - >> !S >> ")*" - | '(' >> !S >> "#PCDATA" >> !S >> ')' - ; - - AttlistDecl = - "> S >> Name >> *AttDef >> !S >> '>' - ; - - AttDef = - S >> Name >> S >> AttType >> S >> DefaultDecl - ; - - AttType = - StringType - | TokenizedType - | EnumeratedType - ; - - StringType = - str_p("CDATA") - ; - - TokenizedType = - longest_d[ - str_p("ID") - | "IDREF" - | "IDREFS" - | "ENTITY" - | "ENTITIES" - | "NMTOKEN" - | "NMTOKENS" - ] - ; - - EnumeratedType = - NotationType - | Enumeration - ; - - NotationType = - "NOTATION" >> S >> '(' >> !S >> Name - >> *(!S >> '|' >> !S >> Name) - >> !S >> ')' - ; - - Enumeration = - '(' >> !S >> Nmtoken - >> *(!S >> '|' >> !S >> Nmtoken) - >> !S >> ')' - ; - - DefaultDecl = - str_p("#REQUIRED") - | "#IMPLIED" - | !("#FIXED" >> S) >> AttValue - ; - - conditionalSect = - includeSect - | ignoreSect - ; - - includeSect = - "> !S >> "INCLUDE" >> !S - >> '[' >> extSubsetDecl >> "]]>" - ; - - ignoreSect = - "> !S >> "IGNORE" >> !S - >> '[' >> *ignoreSectContents >> "]]>" - ; - - ignoreSectContents = - Ignore >> *("> ignoreSectContents >> "]]>" >> Ignore) - ; - - Ignore = - *(Char - (str_p("")) - ; - - CharRef = - "&#" >> +Digit >> ';' - | "&#x" >> +XDigit >> ';' - ; - - Reference = - EntityRef - | CharRef - ; - - EntityRef = - '&' >> Name >> ';' - ; - - PEReference = - '%' >> Name >> ';' - ; - - EntityDecl = - GEDecl - | PEDecl - ; - - GEDecl = - "> S >> Name >> S >> EntityDef >> !S >> '>' - ; - - PEDecl = - "> S >> '%' >> S >> Name >> S >> PEDef - >> !S >> '>' - ; - - EntityDef = - EntityValue - | ExternalID >> !NDataDecl - ; - - PEDef = - EntityValue - | ExternalID - ; - - ExternalID = - "SYSTEM" >> S >> SystemLiteral - | "PUBLIC" >> S >> PubidLiteral >> S >> SystemLiteral - ; - - NDataDecl = - S >> "NDATA" >> S >> Name - ; - - TextDecl = - "> !VersionInfo >> EncodingDecl >> !S >> "?>" - ; - - extParsedEnt = - !TextDecl >> content - ; - - EncodingDecl = - S >> "encoding" >> Eq - >> ( '"' >> EncName >> '"' - | '\'' >> EncName >> '\'' - ) - ; - - EncName = - Letter >> *(Letter | Digit | '.' | '_' | '-') - ; - - NotationDecl = - "> S >> Name >> S - >> (ExternalID | PublicID) >> !S >> '>' - ; - - PublicID = - "PUBLIC" >> S >> PubidLiteral - ; - - BOOST_SPIRIT_DEBUG_RULE(document); - BOOST_SPIRIT_DEBUG_RULE(prolog); - BOOST_SPIRIT_DEBUG_RULE(element); - BOOST_SPIRIT_DEBUG_RULE(Misc); - BOOST_SPIRIT_DEBUG_RULE(PEReference); - BOOST_SPIRIT_DEBUG_RULE(Reference); - BOOST_SPIRIT_DEBUG_RULE(PITarget); - BOOST_SPIRIT_DEBUG_RULE(CData); - BOOST_SPIRIT_DEBUG_RULE(doctypedecl); - BOOST_SPIRIT_DEBUG_RULE(XMLDecl); - BOOST_SPIRIT_DEBUG_RULE(SDDecl); - BOOST_SPIRIT_DEBUG_RULE(VersionInfo); - BOOST_SPIRIT_DEBUG_RULE(EncodingDecl); - BOOST_SPIRIT_DEBUG_RULE(VersionNum); - BOOST_SPIRIT_DEBUG_RULE(Eq); - BOOST_SPIRIT_DEBUG_RULE(DeclSep); - BOOST_SPIRIT_DEBUG_RULE(ExternalID); - BOOST_SPIRIT_DEBUG_RULE(markupdecl); - BOOST_SPIRIT_DEBUG_RULE(NotationDecl); - BOOST_SPIRIT_DEBUG_RULE(EntityDecl); - BOOST_SPIRIT_DEBUG_RULE(AttlistDecl); - BOOST_SPIRIT_DEBUG_RULE(elementdecl); - BOOST_SPIRIT_DEBUG_RULE(TextDecl); - BOOST_SPIRIT_DEBUG_RULE(extSubsetDecl); - BOOST_SPIRIT_DEBUG_RULE(conditionalSect); - BOOST_SPIRIT_DEBUG_RULE(EmptyElemTag); - BOOST_SPIRIT_DEBUG_RULE(STag); - BOOST_SPIRIT_DEBUG_RULE(content); - BOOST_SPIRIT_DEBUG_RULE(ETag); - BOOST_SPIRIT_DEBUG_RULE(Attribute); - BOOST_SPIRIT_DEBUG_RULE(contentspec); - BOOST_SPIRIT_DEBUG_RULE(Mixed); - BOOST_SPIRIT_DEBUG_RULE(children); - BOOST_SPIRIT_DEBUG_RULE(choice); - BOOST_SPIRIT_DEBUG_RULE(seq); - BOOST_SPIRIT_DEBUG_RULE(cp); - BOOST_SPIRIT_DEBUG_RULE(AttDef); - BOOST_SPIRIT_DEBUG_RULE(AttType); - BOOST_SPIRIT_DEBUG_RULE(DefaultDecl); - BOOST_SPIRIT_DEBUG_RULE(StringType); - BOOST_SPIRIT_DEBUG_RULE(TokenizedType); - BOOST_SPIRIT_DEBUG_RULE(EnumeratedType); - BOOST_SPIRIT_DEBUG_RULE(NotationType); - BOOST_SPIRIT_DEBUG_RULE(Enumeration); - BOOST_SPIRIT_DEBUG_RULE(EntityValue); - BOOST_SPIRIT_DEBUG_RULE(AttValue); - BOOST_SPIRIT_DEBUG_RULE(SystemLiteral); - BOOST_SPIRIT_DEBUG_RULE(PubidLiteral); - BOOST_SPIRIT_DEBUG_RULE(CharDataChar); - BOOST_SPIRIT_DEBUG_RULE(CharData); - BOOST_SPIRIT_DEBUG_RULE(Comment); - BOOST_SPIRIT_DEBUG_RULE(PI); - BOOST_SPIRIT_DEBUG_RULE(CDSect); - BOOST_SPIRIT_DEBUG_RULE(extSubset); - BOOST_SPIRIT_DEBUG_RULE(includeSect); - BOOST_SPIRIT_DEBUG_RULE(ignoreSect); - BOOST_SPIRIT_DEBUG_RULE(ignoreSectContents); - BOOST_SPIRIT_DEBUG_RULE(Ignore); - BOOST_SPIRIT_DEBUG_RULE(CharRef); - BOOST_SPIRIT_DEBUG_RULE(EntityRef); - BOOST_SPIRIT_DEBUG_RULE(GEDecl); - BOOST_SPIRIT_DEBUG_RULE(PEDecl); - BOOST_SPIRIT_DEBUG_RULE(EntityDef); - BOOST_SPIRIT_DEBUG_RULE(PEDef); - BOOST_SPIRIT_DEBUG_RULE(NDataDecl); - BOOST_SPIRIT_DEBUG_RULE(extParsedEnt); - BOOST_SPIRIT_DEBUG_RULE(EncName); - BOOST_SPIRIT_DEBUG_RULE(PublicID); - BOOST_SPIRIT_DEBUG_RULE(document); - BOOST_SPIRIT_DEBUG_RULE(S); - BOOST_SPIRIT_DEBUG_RULE(Name); - BOOST_SPIRIT_DEBUG_RULE(Names); - BOOST_SPIRIT_DEBUG_RULE(Nmtoken); - BOOST_SPIRIT_DEBUG_RULE(Nmtokens); - BOOST_SPIRIT_DEBUG_RULE(STagB); - BOOST_SPIRIT_DEBUG_RULE(STagE1); - BOOST_SPIRIT_DEBUG_RULE(STagE2); - - } - - const boost::spirit::rule &start() const - { - return document; - } - - }; - - }; - - template - void read_xml_internal(std::basic_istream &stream, - Ptree &pt, - int flags, - const std::string &filename) - { - - typedef typename Ptree::char_type Ch; - typedef boost::spirit::position_iterator::const_iterator> It; - - BOOST_ASSERT(validate_flags(flags)); - - // Load data into vector - std::vector v(std::istreambuf_iterator(stream.rdbuf()), - std::istreambuf_iterator()); - if (!stream.good()) - throw xml_parser_error("read error", filename, 0); - - // Initialize iterators - It begin(v.begin(), v.end()); - It end(v.end(), v.end()); - begin.set_position(filename); - - // Prepare grammar - Ptree local; - xml_grammar g; - g.c.stack.push_back(&local); // Push root ptree on context stack - g.c.flags = flags; - - // Parse into local - boost::spirit::parse_info result = boost::spirit::parse(begin, end, g); - if (!result.full || g.c.stack.size() != 1) - throw xml_parser_error("xml parse error", - result.stop.get_position().file, - result.stop.get_position().line); - - // Swap local and pt - pt.swap(local); - } - -} } } - -#endif diff --git a/boost/property_tree/detail/xml_parser_read_tinyxml.hpp b/boost/property_tree/detail/xml_parser_read_tinyxml.hpp deleted file mode 100644 index 92a057cae..000000000 --- a/boost/property_tree/detail/xml_parser_read_tinyxml.hpp +++ /dev/null @@ -1,82 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_READ_TINYXML_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_READ_TINYXML_HPP_INCLUDED - -#include -#include -#include -#include - -#ifndef TIXML_USE_STL -#define TIXML_USE_STL -#endif - -#include - -namespace boost { namespace property_tree { namespace xml_parser -{ - - template - void read_xml_node(TiXmlNode *node, Ptree &pt, int flags) - { - - typedef typename Ptree::char_type Ch; - - if (TiXmlElement *elem = node->ToElement()) - { - Ptree &tmp = pt.push_back(std::make_pair(elem->Value(), Ptree()))->second; - for (TiXmlAttribute *attr = elem->FirstAttribute(); attr; attr = attr->Next()) - tmp.put(Ch('/'), xmlattr() + "/" + attr->Name(), attr->Value()); - for (TiXmlNode *child = node->FirstChild(); child; child = child->NextSibling()) - read_xml_node(child, tmp, flags); - } - else if (TiXmlText *text = node->ToText()) - { - if (flags & no_concat_text) - pt.push_back(std::make_pair(xmltext(), Ptree(text->Value()))); - else - pt.data() += text->Value(); - } - else if (TiXmlComment *comment = node->ToComment()) - { - if (!(flags & no_comments)) - pt.push_back(std::make_pair(xmlcomment(), Ptree(comment->Value()))); - } - } - - template - void read_xml_internal(std::basic_istream &stream, - Ptree &pt, - int flags, - const std::string &filename) - { - - // Create and load document from stream - TiXmlDocument doc; - stream >> doc; - if (!stream.good()) - throw xml_parser_error("read error", filename, 0); - if (doc.Error()) - throw xml_parser_error(doc.ErrorDesc(), filename, doc.ErrorRow()); - - // Create ptree from nodes - Ptree local; - for (TiXmlNode *child = doc.FirstChild(); child; child = child->NextSibling()) - read_xml_node(child, local, flags); - - // Swap local and result ptrees - pt.swap(local); - - } - -} } } - -#endif diff --git a/boost/property_tree/detail/xml_parser_utils.hpp b/boost/property_tree/detail/xml_parser_utils.hpp deleted file mode 100644 index f2df027aa..000000000 --- a/boost/property_tree/detail/xml_parser_utils.hpp +++ /dev/null @@ -1,119 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_UTILS_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_UTILS_HPP_INCLUDED - -#include -#include -#include -#include -#include - -namespace boost { namespace property_tree { namespace xml_parser -{ - - template - std::basic_string condense(const std::basic_string &s) - { - std::basic_string r; - std::locale loc; - bool space = false; - typename std::basic_string::const_iterator end = s.end(); - for (typename std::basic_string::const_iterator it = s.begin(); - it != end; ++it) - { - if (isspace(*it, loc) || *it == Ch('\n')) - { - if (!space) - r += Ch(' '), space = true; - } - else - r += *it, space = false; - } - return r; - } - - template - std::basic_string encode_char_entities(const std::basic_string &s) - { - typedef typename std::basic_string Str; - Str r; - typename Str::const_iterator end = s.end(); - for (typename Str::const_iterator it = s.begin(); it != end; ++it) - { - switch (*it) - { - case Ch('<'): r += detail::widen("<"); break; - case Ch('>'): r += detail::widen(">"); break; - case Ch('&'): r += detail::widen("&"); break; - default: r += *it; break; - } - } - return r; - } - - template - std::basic_string decode_char_entities(const std::basic_string &s) - { - typedef typename std::basic_string Str; - Str r; - typename Str::const_iterator end = s.end(); - for (typename Str::const_iterator it = s.begin(); it != end; ++it) - { - if (*it == Ch('&')) - { - typename Str::const_iterator semicolon = std::find(it + 1, end, Ch(';')); - if (semicolon == end) - throw xml_parser_error("invalid character entity", "", 0); - Str ent(it + 1, semicolon); - if (ent == detail::widen("lt")) r += Ch('<'); - else if (ent == detail::widen("gt")) r += Ch('>'); - else if (ent == detail::widen("amp")) r += Ch('&'); - else - throw xml_parser_error("invalid character entity", "", 0); - it = semicolon; - } - else - r += *it; - } - return r; - } - - template - const std::basic_string &xmldecl() - { - static std::basic_string s = detail::widen(""); - return s; - } - - template - const std::basic_string &xmlattr() - { - static std::basic_string s = detail::widen(""); - return s; - } - - template - const std::basic_string &xmlcomment() - { - static std::basic_string s = detail::widen(""); - return s; - } - - template - const std::basic_string &xmltext() - { - static std::basic_string s = detail::widen(""); - return s; - } - -} } } - -#endif diff --git a/boost/property_tree/detail/xml_parser_write.hpp b/boost/property_tree/detail/xml_parser_write.hpp deleted file mode 100644 index 0d56969c2..000000000 --- a/boost/property_tree/detail/xml_parser_write.hpp +++ /dev/null @@ -1,145 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_WRITE_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_WRITE_HPP_INCLUDED - -#include -#include -#include -#include -#include - -namespace boost { namespace property_tree { namespace xml_parser -{ - - template - void write_xml_comment(std::basic_ostream &stream, - const std::basic_string &s, - int indent) - { - typedef typename std::basic_string Str; - stream << Str(4 * indent, Ch(' ')); - stream << Ch('<') << Ch('!') << Ch('-') << Ch('-'); - stream << s; - stream << Ch('-') << Ch('-') << Ch('>') << std::endl; - } - - template - void write_xml_text(std::basic_ostream &stream, - const std::basic_string &s, - int indent, - bool separate_line) - { - typedef typename std::basic_string Str; - if (separate_line) - stream << Str(4 * indent, Ch(' ')); - stream << encode_char_entities(s); - if (separate_line) - stream << Ch('\n'); - } - - template - void write_xml_element(std::basic_ostream &stream, - const std::basic_string &key, - const Ptree &pt, - int indent) - { - - typedef typename Ptree::char_type Ch; - typedef typename std::basic_string Str; - typedef typename Ptree::const_iterator It; - - // Find if elements present - bool has_elements = false; - for (It it = pt.begin(), end = pt.end(); it != end; ++it) - if (it->first != xmlattr() && - it->first != xmltext()) - { - has_elements = true; - break; - } - - // Write element - if (pt.data().empty() && pt.empty()) // Empty key - { - if (indent >= 0) - stream << Str(4 * indent, Ch(' ')) << Ch('<') << key << - Ch('/') << Ch('>') << std::endl; - } - else // Nonempty key - { - - // Write opening tag, attributes and data - if (indent >= 0) - { - - // Write opening brace and key - stream << Str(4 * indent, Ch(' ')); - stream << Ch('<') << key; - - // Write attributes - if (optional attribs = pt.get_child_optional(xmlattr())) - for (It it = attribs.get().begin(); it != attribs.get().end(); ++it) - stream << Ch(' ') << it->first << Ch('=') << - Ch('"') << it->second.template get_own >() << Ch('"'); - - // Write closing brace - stream << Ch('>'); - - // Break line if needed - if (has_elements) - stream << Ch('\n'); - - } - - // Write data text, if present - if (!pt.data().empty()) - write_xml_text(stream, pt.template get_own >(), indent + 1, has_elements); - - // Write elements, comments and texts - for (It it = pt.begin(); it != pt.end(); ++it) - { - if (it->first == xmlattr()) - continue; - else if (it->first == xmlcomment()) - write_xml_comment(stream, it->second.template get_own >(), indent + 1); - else if (it->first == xmltext()) - write_xml_text(stream, it->second.template get_own >(), indent + 1, has_elements); - else - write_xml_element(stream, it->first, it->second, indent + 1); - } - - // Write closing tag - if (indent >= 0) - { - if (has_elements) - stream << Str(4 * indent, Ch(' ')); - stream << Ch('<') << Ch('/') << key << Ch('>') << std::endl; - } - - } - } - - template - void write_xml_internal(std::basic_ostream &stream, - const Ptree &pt, - const std::string &filename) - { - typedef typename Ptree::char_type Ch; - typedef typename std::basic_string Str; - stream << detail::widen("\n"); - write_xml_element(stream, Str(), pt, -1); - if (!stream) - throw xml_parser_error("write error", filename, 0); - } - -} } } - -#endif diff --git a/boost/property_tree/info_parser.hpp b/boost/property_tree/info_parser.hpp deleted file mode 100644 index fe8572776..000000000 --- a/boost/property_tree/info_parser.hpp +++ /dev/null @@ -1,77 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_INFO_PARSER_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_INFO_PARSER_HPP_INCLUDED - -#include -#include -#include -#include -#include - -namespace boost { namespace property_tree { namespace info_parser -{ - - // Read info from stream - template - void read_info(std::basic_istream &stream, - Ptree &pt) - { - Ptree local; - read_info_internal(stream, local, std::string(), 0); - pt.swap(local); - } - - // Read info from file - template - void read_info(const std::string &filename, - Ptree &pt, - const std::locale &loc = std::locale()) - { - std::basic_ifstream stream(filename.c_str()); - if (!stream) - throw info_parser_error("cannot open file for reading", filename, 0); - stream.imbue(loc); - Ptree local; - read_info_internal(stream, local, filename, 0); - pt.swap(local); - } - - // Write info to stream - template - void write_info(std::basic_ostream &stream, - const Ptree &pt) - { - write_info_internal(stream, pt, std::string()); - } - - // Write info to file - template - void write_info(const std::string &filename, - const Ptree &pt, - const std::locale &loc = std::locale()) - { - std::basic_ofstream stream(filename.c_str()); - if (!stream) - throw info_parser_error("cannot open file for writing", filename, 0); - stream.imbue(loc); - write_info_internal(stream, pt, filename); - } - -} } } - -namespace boost { namespace property_tree -{ - using info_parser::info_parser_error; - using info_parser::read_info; - using info_parser::write_info; -} } - -#endif diff --git a/boost/property_tree/ini_parser.hpp b/boost/property_tree/ini_parser.hpp deleted file mode 100644 index 2f6583060..000000000 --- a/boost/property_tree/ini_parser.hpp +++ /dev/null @@ -1,196 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_INI_PARSER_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_INI_PARSER_HPP_INCLUDED - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace boost { namespace property_tree { namespace ini_parser -{ - - static const int skip_ini_validity_check = 1; // Skip check if ptree is a valid ini - - inline bool validate_flags(int flags) - { - return (flags & ~skip_ini_validity_check) == 0; - } - - //! Ini parser error - class ini_parser_error: public file_parser_error - { - public: - ini_parser_error(const std::string &message, - const std::string &filename, - unsigned long line): - file_parser_error(message, filename, line) - { - } - }; - - //! Read ini from stream - template - void read_ini(std::basic_istream &stream, - Ptree &pt) - { - - typedef typename Ptree::char_type Ch; - typedef std::basic_string Str; - - Ptree local; - unsigned long line_no = 0; - Ptree *section = 0; - Str line; - - // For all lines - while (stream.good()) - { - - // Get line from stream - ++line_no; - std::getline(stream, line); - if (!stream.good() && !stream.eof()) - throw ini_parser_error("read error", "", line_no); - - // If line is non-empty - line = detail::trim(line, stream.getloc()); - if (!line.empty()) - { - - // Comment, section or key? - if (line[0] == Ch(';')) - { - // Ignore comments - } - else if (line[0] == Ch('[')) - { - typename Str::size_type end = line.find(Ch(']')); - if (end == Str::npos) - throw ini_parser_error("unmatched '['", "", line_no); - Str key = detail::trim(line.substr(1, end - 1), stream.getloc()); - if (local.find(key) != local.end()) - throw ini_parser_error("duplicate section name", "", line_no); - section = &local.push_back(std::make_pair(key, Ptree()))->second; - } - else - { - if (!section) - throw ini_parser_error("section expected", "", line_no); - typename Str::size_type eqpos = line.find(Ch('=')); - if (eqpos == Str::npos) - throw ini_parser_error("'=' character not found in line", "", line_no); - if (eqpos == 0) - throw ini_parser_error("key expected", "", line_no); - Str key = detail::trim(line.substr(0, eqpos), stream.getloc()); - Str data = detail::trim(line.substr(eqpos + 1, Str::npos), stream.getloc()); - if (section->find(key) != section->end()) - throw ini_parser_error("duplicate key name", "", line_no); - section->push_back(std::make_pair(key, Ptree(data))); - } - } - } - - // Swap local ptree with result ptree - pt.swap(local); - - } - - //! Read ini from file - template - void read_ini(const std::string &filename, - Ptree &pt, - const std::locale &loc = std::locale()) - { - std::basic_ifstream stream(filename.c_str()); - if (!stream) - throw ini_parser_error("cannot open file", filename, 0); - stream.imbue(loc); - try { - read_ini(stream, pt); - } - catch (ini_parser_error &e) { - throw ini_parser_error(e.message(), filename, e.line()); - } - } - - //! Write ini to stream - template - void write_ini(std::basic_ostream &stream, - const Ptree &pt, - int flags = 0) - { - - typedef typename Ptree::char_type Ch; - typedef std::basic_string Str; - - BOOST_ASSERT(validate_flags(flags)); - - // Verify if ptree is not too rich to be saved as ini - if (!(flags & skip_ini_validity_check)) - for (typename Ptree::const_iterator it = pt.begin(), end = pt.end(); it != end; ++it) - { - if (!it->second.data().empty()) - throw ini_parser_error("ptree has data on root level keys", "", 0); - if (pt.count(it->first) > 1) - throw ini_parser_error("duplicate section name", "", 0); - for (typename Ptree::const_iterator it2 = it->second.begin(), end2 = it->second.end(); it2 != end2; ++it2) - { - if (!it2->second.empty()) - throw ini_parser_error("ptree is too deep", "", 0); - if (it->second.count(it2->first) > 1) - throw ini_parser_error("duplicate key name", "", 0); - } - } - - // Write ini - for (typename Ptree::const_iterator it = pt.begin(), end = pt.end(); it != end; ++it) - { - stream << Ch('[') << it->first << Ch(']') << Ch('\n'); - for (typename Ptree::const_iterator it2 = it->second.begin(), end2 = it->second.end(); it2 != end2; ++it2) - stream << it2->first << Ch('=') << it2->second.template get_own >() << Ch('\n'); - } - - } - - // Write ini to file - template - void write_ini(const std::string &filename, - const Ptree &pt, - int flags = 0, - const std::locale &loc = std::locale()) - { - std::basic_ofstream stream(filename.c_str()); - if (!stream) - throw ini_parser_error("cannot open file", filename, 0); - stream.imbue(loc); - try { - write_ini(stream, pt, flags); - } - catch (ini_parser_error &e) { - throw ini_parser_error(e.message(), filename, e.line()); - } - } - -} } } - -namespace boost { namespace property_tree -{ - using ini_parser::ini_parser_error; - using ini_parser::read_ini; - using ini_parser::write_ini; -} } - -#endif diff --git a/boost/property_tree/json_parser.hpp b/boost/property_tree/json_parser.hpp deleted file mode 100644 index 4f3a7e5af..000000000 --- a/boost/property_tree/json_parser.hpp +++ /dev/null @@ -1,76 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_JSON_PARSER_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_JSON_PARSER_HPP_INCLUDED - -#include -#include -#include -#include - -#include -#include -#include - -namespace boost { namespace property_tree { namespace json_parser -{ - - // Read json from stream - template - void read_json(std::basic_istream &stream, - Ptree &pt) - { - read_json_internal(stream, pt, std::string()); - } - - // Read json from file - template - void read_json(const std::string &filename, - Ptree &pt, - const std::locale &loc = std::locale()) - { - std::basic_ifstream stream(filename.c_str()); - if (!stream) - throw json_parser_error("cannot open file", filename, 0); - stream.imbue(loc); - read_json_internal(stream, pt, filename); - } - - // Write json to stream - template - void write_json(std::basic_ostream &stream, - const Ptree &pt) - { - write_json_internal(stream, pt, std::string()); - } - - // Write json to file - template - void write_json(const std::string &filename, - const Ptree &pt, - const std::locale &loc = std::locale()) - { - std::basic_ofstream stream(filename.c_str()); - if (!stream) - throw json_parser_error("cannot open file", filename, 0); - stream.imbue(loc); - write_json_internal(stream, pt, filename); - } - -} } } - -namespace boost { namespace property_tree -{ - using json_parser::read_json; - using json_parser::write_json; - using json_parser::json_parser_error; -} } - -#endif diff --git a/boost/property_tree/ptree.hpp b/boost/property_tree/ptree.hpp deleted file mode 100644 index 2fe57b5ba..000000000 --- a/boost/property_tree/ptree.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_PTREE_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_PTREE_HPP_INCLUDED - -#include -#include - -#endif diff --git a/boost/property_tree/ptree_fwd.hpp b/boost/property_tree/ptree_fwd.hpp deleted file mode 100644 index 54e06bbc7..000000000 --- a/boost/property_tree/ptree_fwd.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_PTREE_FWD_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_PTREE_FWD_HPP_INCLUDED - -#include - -namespace boost { namespace property_tree -{ - - //////////////////////////////////////////////////////////////////////////// - // Traits - - template struct ptree_traits; - template struct iptree_traits; - - /////////////////////////////////////////////////////////////////////////// - // Exceptions - - class ptree_error; - class bad_ptree_data; - class bad_ptree_path; - - /////////////////////////////////////////////////////////////////////////// - // basic_ptree class template - - template class basic_ptree; - - //////////////////////////////////////////////////////////////////////////// - // Typedefs - - typedef basic_ptree > ptree; // case sensitive, narrow char - typedef basic_ptree > iptree; // case insensitive, narrow char -#ifndef BOOST_NO_CWCHAR - typedef basic_ptree > wptree; // case sensitive, wide char - typedef basic_ptree > wiptree; // case insensitive, wide char -#endif - - /////////////////////////////////////////////////////////////////////////// - // Free functions - - template void swap(basic_ptree &pt1, basic_ptree &pt2); - template const Ptree &empty_ptree(); - -} } - -#endif diff --git a/boost/property_tree/registry_parser.hpp b/boost/property_tree/registry_parser.hpp deleted file mode 100644 index c505a34e6..000000000 --- a/boost/property_tree/registry_parser.hpp +++ /dev/null @@ -1,520 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_REGISTRY_PARSER_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_REGISTRY_PARSER_HPP_INCLUDED - -// Include minimal version of windows.h if not included yet -#ifndef _WINDOWS_ -#ifndef NOMINMAX - #define NOMINMAX -#endif -#define STRICT -#define WIN32_LEAN_AND_MEAN -#define VC_EXTRALEAN -#define NOGDICAPMASKS -#define NOVIRTUALKEYCODES -#define NOWINMESSAGES -#define NOWINSTYLES -#define NOSYSMETRICS -#define NOMENUS -#define NOICONS -#define NOKEYSTATES -#define NOSYSCOMMANDS -#define NORASTEROPS -#define NOSHOWWINDOW -#define OEMRESOURCE -#define NOATOM -#define NOCLIPBOARD -#define NOCOLOR -#define NOCTLMGR -#define NODRAWTEXT -#define NOGDI -#define NOKERNEL -#define NOUSER -#define NONLS -#define NOMB -#define NOMEMMGR -#define NOMETAFILE -#define NOMSG -#define NOOPENFILE -#define NOSCROLL -#define NOSERVICE -#define NOSOUND -#define NOTEXTMETRIC -#define NOWH -#define NOWINOFFSETS -#define NOCOMM -#define NOKANJI -#define NOHELP -#define NOPROFILER -#define NODEFERWINDOWPOS -#define NOMCX -#include -#endif - -#include -#include -#include // for 64 bit int -#include -#include -#include -#include -#include - -namespace boost { namespace property_tree { namespace registry_parser -{ - - //! Registry parser error - class registry_parser_error: public ptree_error - { - public: - - // Construct error - registry_parser_error(const std::string &message, DWORD windows_error): - ptree_error(format_what(message, windows_error)), - m_windows_error(windows_error) - { - } - - // Get windows error - DWORD windows_error() - { - return m_windows_error; - } - - private: - - DWORD m_windows_error; - - // Format error message to be returned by std::runtime_error::what() - std::string format_what(const std::string &message, - DWORD windows_error) - { - std::stringstream stream; - if (windows_error) - stream << message << " (windows error 0x" << std::hex << windows_error << ")"; - else - stream << message; - return stream.str(); - } - - }; - - // Translate from binary buffer to string - template - std::basic_string translate(DWORD type, const std::vector &data) - { - - typedef std::basic_string Str; - typedef std::basic_stringstream Stream; - - Str value; - switch (type) - { - - // No data - case REG_NONE: - break; - - // Binary data - case REG_BINARY: - if (!data.empty()) - { - Stream stream; - stream << std::hex << std::setfill(Ch('0')); - for (std::vector::const_iterator it = data.begin(), end = data.end(); - it != end; ++it) - stream << std::setw(2) << static_cast(*it) << Ch(' '); - value = stream.str(); - value.resize(value.size() - 1); // remove final space - } - break; - - // DWORD value - case REG_DWORD: - if (!data.empty()) - { - Stream stream; - stream << *reinterpret_cast(&data.front()); - value = stream.str(); - } - break; - - // QWORD value - case REG_QWORD: - if (!data.empty()) - { - Stream stream; - stream << *reinterpret_cast(&data.front()); - value = stream.str(); - } - break; - - // Zero terminated string - case REG_SZ: case REG_EXPAND_SZ: - if (!data.empty()) - value.assign(reinterpret_cast(&data.front())); - break; - - // Unknown data type - default: - throw registry_parser_error("unsupported data type", 0); - - }; - return value; - } - - // Translate from string to binary buffer - template - std::vector translate(DWORD type, const std::basic_string &s) - { - - typedef std::basic_string Str; - typedef std::basic_stringstream Stream; - - std::vector data; - switch (type) - { - - // No data - case REG_NONE: - break; - - // Binary data - case REG_BINARY: - { - int v; - Stream stream(s); - stream >> std::hex; - while (1) - { - stream >> v >> std::ws; - if (stream.fail() || stream.bad()) - throw registry_parser_error("bad REG_BINARY value", 0); - data.push_back(v); - if (stream.eof()) - break; - } - } - break; - - // DWORD value - case REG_DWORD: - { - DWORD v; - Stream stream(s); - stream >> v >> std::ws; - if (!stream.eof() || stream.fail() || stream.bad()) - throw registry_parser_error("bad REG_DWORD value", 0); - for (size_t i = 0; i < sizeof(v); ++i) - data.push_back(*(reinterpret_cast(&v) + i)); - } - break; - - // QWORD value - case REG_QWORD: - { - boost::uint64_t v; - Stream stream(s); - stream >> v; - if (!stream.eof() || stream.fail() || stream.bad()) - throw registry_parser_error("bad REG_QWORD value", 0); - for (size_t i = 0; i < sizeof(v); ++i) - data.push_back(*(reinterpret_cast(&v) + i)); - } - break; - - // Zero terminated string - case REG_SZ: case REG_EXPAND_SZ: - { - const Ch *sz = s.c_str(); - size_t len = (s.size() + 1) * sizeof(Ch); - for (size_t i = 0; i < len; ++i) - data.push_back(*(reinterpret_cast(sz) + i)); - } - break; - - // Unknown data type - default: - throw registry_parser_error("unsupported data type", 0); - - }; - return data; - } - - ///////////////////////////////////////////////////////////////////////////// - // Registry functions wrappers - - template - inline LONG reg_create_key_ex(HKEY hkey, const Ch *subkey, REGSAM sam, HKEY *result); - - template<> - inline LONG reg_create_key_ex(HKEY hkey, const char *subkey, REGSAM sam, HKEY *result) - { - return RegCreateKeyExA(hkey, subkey, 0, NULL, REG_OPTION_NON_VOLATILE, sam, NULL, result, NULL); - } - - template<> - inline LONG reg_create_key_ex(HKEY hkey, const wchar_t *subkey, REGSAM sam, HKEY *result) - { - return RegCreateKeyExW(hkey, subkey, 0, NULL, REG_OPTION_NON_VOLATILE, sam, NULL, result, NULL); - } - - template - inline LONG reg_set_value_ex(HKEY hkey, const Ch *name, DWORD type, const BYTE *data, DWORD size); - - template<> - inline LONG reg_set_value_ex(HKEY hkey, const char *name, DWORD type, const BYTE *data, DWORD size) - { - return RegSetValueExA(hkey, name, 0, type, data, size); - } - - template<> - inline LONG reg_set_value_ex(HKEY hkey, const wchar_t *name, DWORD type, const BYTE *data, DWORD size) - { - return RegSetValueExW(hkey, name, 0, type, data, size); - } - - template - inline LONG reg_open_key_ex(HKEY hkey, const Ch *subkey, REGSAM sam, HKEY *result); - - template<> - inline LONG reg_open_key_ex(HKEY hkey, const char *subkey, REGSAM sam, HKEY *result) - { - return RegOpenKeyExA(hkey, subkey, 0, sam, result); - } - - template<> - inline LONG reg_open_key_ex(HKEY hkey, const wchar_t *subkey, REGSAM sam, HKEY *result) - { - return RegOpenKeyExW(hkey, subkey, 0, sam, result); - } - - template - inline LONG reg_enum_key_ex(HKEY hkey, DWORD index, Ch *name, DWORD *size); - - template<> - inline LONG reg_enum_key_ex(HKEY hkey, DWORD index, char *name, DWORD *size) - { - FILETIME ft; - return RegEnumKeyExA(hkey, index, name, size, 0, NULL, NULL, &ft); - } - - template<> - inline LONG reg_enum_key_ex(HKEY hkey, DWORD index, wchar_t *name, DWORD *size) - { - FILETIME ft; - return RegEnumKeyExW(hkey, index, name, size, 0, NULL, NULL, &ft); - } - - template - inline LONG reg_enum_value(HKEY hkey, DWORD index, Ch *name, DWORD *name_size, DWORD *type, BYTE *data, DWORD *data_size); - - template<> - inline LONG reg_enum_value(HKEY hkey, DWORD index, char *name, DWORD *name_size, DWORD *type, BYTE *data, DWORD *data_size) - { - return RegEnumValueA(hkey, index, name, name_size, NULL, type, data, data_size); - } - - template<> - inline LONG reg_enum_value(HKEY hkey, DWORD index, wchar_t *name, DWORD *name_size, DWORD *type, BYTE *data, DWORD *data_size) - { - return RegEnumValueW(hkey, index, name, name_size, NULL, type, data, data_size); - } - - template - inline LONG reg_query_info_key(HKEY hkey, DWORD *max_subkey_len, DWORD *max_name_len, DWORD *max_value_len); - - template<> - inline LONG reg_query_info_key(HKEY hkey, DWORD *max_subkey_len, DWORD *max_name_len, DWORD *max_value_len) - { - return RegQueryInfoKeyA(hkey, NULL, NULL, NULL, NULL, max_subkey_len, NULL, NULL, max_name_len, max_value_len, NULL, NULL); - } - - template<> - inline LONG reg_query_info_key(HKEY hkey, DWORD *max_subkey_len, DWORD *max_name_len, DWORD *max_value_len) - { - return RegQueryInfoKeyW(hkey, NULL, NULL, NULL, NULL, max_subkey_len, NULL, NULL, max_name_len, max_value_len, NULL, NULL); - } - - ///////////////////////////////////////////////////////////////////////////// - // Registry key handle wrapper - - template - class reg_key - { - public: - typedef std::basic_string Str; - reg_key(HKEY root, const std::basic_string &key, bool create): - hkey(0) - { - if (create) - { - LONG result = reg_create_key_ex(root, key.c_str(), KEY_WRITE, &hkey); - if (result != ERROR_SUCCESS) - throw registry_parser_error("RegCreateKeyEx failed", result); - } - else - { - LONG result = reg_open_key_ex(root, key.c_str(), KEY_READ, &hkey); - if (result != ERROR_SUCCESS) - throw registry_parser_error("RegOpenKeyEx failed", result); - } - BOOST_ASSERT(hkey); - } - ~reg_key() - { - BOOST_ASSERT(hkey); - RegCloseKey(hkey); - } - HKEY handle() - { - BOOST_ASSERT(hkey); - return hkey; - } - private: - HKEY hkey; - }; - - ///////////////////////////////////////////////////////////////////////////// - // Registry parser - - //! Read registry - template - void read_registry(HKEY root, - const std::basic_string &key, - Ptree &pt) - { - - typedef typename Ptree::char_type Ch; - typedef std::basic_string Str; - typedef std::basic_stringstream Stream; - - Ptree local; - - // Open key - reg_key rk(root, key, false); - - // Query key info - DWORD max_subkey_len, max_name_len, max_value_len; - LONG result = reg_query_info_key(rk.handle(), &max_subkey_len, &max_name_len, &max_value_len); - if (result != ERROR_SUCCESS) - throw registry_parser_error("RegQueryInfoKey failed", result); - - // For all subkeys - std::vector subkey(max_subkey_len + 1); - for (DWORD index = 0; true; ++index) - { - - // Get subkey name - DWORD size = static_cast(subkey.size()); - LONG result = reg_enum_key_ex(rk.handle(), index, &subkey.front(), &size); - if (result == ERROR_NO_MORE_ITEMS) - break; - if (result != ERROR_SUCCESS) - throw registry_parser_error("RegEnumKeyEx failed", result); - - // Parse recursively - Ptree &child = local.push_back(typename Ptree::value_type(&subkey.front(), Ptree()))->second; - read_registry(rk.handle(), &subkey.front(), child); - - } - - // For all values - for (DWORD index = 0; true; ++index) - { - - // Resize data to max size - std::vector name(max_name_len + 1); - std::vector data(max_value_len + 1); - - // Get name and value from registry - DWORD name_size = static_cast(name.size()); - DWORD data_size = static_cast(data.size()); - DWORD type; - result = reg_enum_value(rk.handle(), index, &name.front(), &name_size, &type, &data.front(), &data_size); - if (result == ERROR_NO_MORE_ITEMS) - break; - if (result != ERROR_SUCCESS) - throw registry_parser_error("RegEnumValue failed", result); - - // Truncate data to actual size - name.resize(name_size + 1); - data.resize(data_size); - - // Translate and put value in tree - Str value = translate(type, data); - if (name_size > 0) - { - local.put(Str(detail::widen("\\values.") + &name.front()), value); - local.put(Str(detail::widen("\\types.") + &name.front()), type); - } - else - local.data() = value; - - } - - // Swap pt and local - pt.swap(local); - - } - - //! Write registry - template - void write_registry(HKEY root, - const std::basic_string &key, - const Ptree &pt) - { - - typedef typename Ptree::char_type Ch; - typedef std::basic_string Str; - typedef std::basic_stringstream Stream; - - // Create key - reg_key rk(root, key, true); - - // Set default key value - if (!pt.data().empty()) - { - std::vector data = translate(REG_SZ, pt.data()); - reg_set_value_ex(rk.handle(), NULL, REG_SZ, - data.empty() ? NULL : &data.front(), - static_cast(data.size())); - } - - // Create values - const Ptree &values = pt.get_child(detail::widen("\\values"), empty_ptree()); - const Ptree &types = pt.get_child(detail::widen("\\types"), empty_ptree()); - for (typename Ptree::const_iterator it = values.begin(), end = values.end(); it != end; ++it) - { - DWORD type = types.get(it->first, REG_SZ); - std::vector data = translate(type, it->second.data()); - reg_set_value_ex(rk.handle(), it->first.c_str(), type, - data.empty() ? NULL : &data.front(), - static_cast(data.size())); - } - - // Create subkeys - for (typename Ptree::const_iterator it = pt.begin(), end = pt.end(); it != end; ++it) - if (&it->second != &values && &it->second != &types) - write_registry(rk.handle(), it->first, it->second); - - } - -} } } - -namespace boost { namespace property_tree -{ - using registry_parser::read_registry; - using registry_parser::write_registry; - using registry_parser::registry_parser_error; -} } - -#endif diff --git a/boost/property_tree/xml_parser.hpp b/boost/property_tree/xml_parser.hpp deleted file mode 100644 index 6178aa237..000000000 --- a/boost/property_tree/xml_parser.hpp +++ /dev/null @@ -1,86 +0,0 @@ -// ---------------------------------------------------------------------------- -// Copyright (C) 2002-2005 Marcin Kalicinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// For more information, see www.boost.org -// ---------------------------------------------------------------------------- -#ifndef BOOST_PROPERTY_TREE_XML_PARSER_HPP_INCLUDED -#define BOOST_PROPERTY_TREE_XML_PARSER_HPP_INCLUDED - -#include -#include -#include -#include - -// Include proper parser -#ifdef BOOST_PROPERTY_TREE_XML_PARSER_TINYXML -#include -#else -#include -#endif - -#include -#include -#include - -namespace boost { namespace property_tree { namespace xml_parser -{ - - // Read XML from stream - template - void read_xml(std::basic_istream &stream, - Ptree &pt, - int flags = 0) - { - read_xml_internal(stream, pt, flags, std::string()); - } - - // Read XML from file - template - void read_xml(const std::string &filename, - Ptree &pt, - int flags = 0, - const std::locale &loc = std::locale()) - { - BOOST_ASSERT(validate_flags(flags)); - std::basic_ifstream stream(filename.c_str()); - if (!stream) - throw xml_parser_error("cannot open file", filename, 0); - stream.imbue(loc); - read_xml_internal(stream, pt, flags, filename); - } - - // Write XML to stream - template - void write_xml(std::basic_ostream &stream, - const Ptree &pt) - { - write_xml_internal(stream, pt, std::string()); - } - - // Write XML to file - template - void write_xml(const std::string &filename, - const Ptree &pt, - const std::locale &loc = std::locale()) - { - std::basic_ofstream stream(filename.c_str()); - if (!stream) - throw xml_parser_error("cannot open file", filename, 0); - stream.imbue(loc); - write_xml_internal(stream, pt, filename); - } - -} } } - -namespace boost { namespace property_tree -{ - using xml_parser::read_xml; - using xml_parser::write_xml; - using xml_parser::xml_parser_error; -} } - -#endif diff --git a/demo/c++/rundemo.cpp b/demo/c++/rundemo.cpp index 4d341cbf6..e26cbff0c 100644 --- a/demo/c++/rundemo.cpp +++ b/demo/c++/rundemo.cpp @@ -66,12 +66,12 @@ int main ( int argc , char** argv) feature_type_style provpoly_style; rule_type provpoly_rule_on; - provpoly_rule_on.set_filter(create_filter("[NAME_EN] = 'Ontario'")); + provpoly_rule_on.set_filter(parse_expression("[NAME_EN] = 'Ontario'")); provpoly_rule_on.append(polygon_symbolizer(color(250, 190, 183))); provpoly_style.add_rule(provpoly_rule_on); rule_type provpoly_rule_qc; - provpoly_rule_qc.set_filter(create_filter("[NOM_FR] = 'Québec'")); + provpoly_rule_qc.set_filter(parse_expression("[NOM_FR] = 'Québec'")); provpoly_rule_qc.append(polygon_symbolizer(color(217, 235, 203))); provpoly_style.add_rule(provpoly_rule_qc); @@ -95,7 +95,7 @@ int main ( int argc , char** argv) feature_type_style qcdrain_style; rule_type qcdrain_rule; - qcdrain_rule.set_filter(create_filter("[HYC] = 8")); + qcdrain_rule.set_filter(parse_expression("[HYC] = 8")); qcdrain_rule.append(polygon_symbolizer(color(153, 204, 255))); qcdrain_style.add_rule(qcdrain_rule); @@ -104,7 +104,7 @@ int main ( int argc , char** argv) // Roads 3 and 4 (The "grey" roads) feature_type_style roads34_style; rule_type roads34_rule; - roads34_rule.set_filter(create_filter("[CLASS] = 3 or [CLASS] = 4")); + roads34_rule.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4")); stroke roads34_rule_stk(color(171,158,137),2.0); roads34_rule_stk.set_line_cap(ROUND_CAP); roads34_rule_stk.set_line_join(ROUND_JOIN); @@ -117,7 +117,7 @@ int main ( int argc , char** argv) // Roads 2 (The thin yellow ones) feature_type_style roads2_style_1; rule_type roads2_rule_1; - roads2_rule_1.set_filter(create_filter("[CLASS] = 2")); + roads2_rule_1.set_filter(parse_expression("[CLASS] = 2")); stroke roads2_rule_stk_1(color(171,158,137),4.0); roads2_rule_stk_1.set_line_cap(ROUND_CAP); roads2_rule_stk_1.set_line_join(ROUND_JOIN); @@ -128,7 +128,7 @@ int main ( int argc , char** argv) feature_type_style roads2_style_2; rule_type roads2_rule_2; - roads2_rule_2.set_filter(create_filter("[CLASS] = 2")); + roads2_rule_2.set_filter(parse_expression("[CLASS] = 2")); stroke roads2_rule_stk_2(color(255,250,115),2.0); roads2_rule_stk_2.set_line_cap(ROUND_CAP); roads2_rule_stk_2.set_line_join(ROUND_JOIN); @@ -140,7 +140,7 @@ int main ( int argc , char** argv) // Roads 1 (The big orange ones, the highways) feature_type_style roads1_style_1; rule_type roads1_rule_1; - roads1_rule_1.set_filter(create_filter("[CLASS] = 1")); + roads1_rule_1.set_filter(parse_expression("[CLASS] = 1")); stroke roads1_rule_stk_1(color(188,149,28),7.0); roads1_rule_stk_1.set_line_cap(ROUND_CAP); roads1_rule_stk_1.set_line_join(ROUND_JOIN); @@ -150,7 +150,7 @@ int main ( int argc , char** argv) feature_type_style roads1_style_2; rule_type roads1_rule_2; - roads1_rule_2.set_filter(create_filter("[CLASS] = 1")); + roads1_rule_2.set_filter(parse_expression("[CLASS] = 1")); stroke roads1_rule_stk_2(color(242,191,36),5.0); roads1_rule_stk_2.set_line_cap(ROUND_CAP); roads1_rule_stk_2.set_line_join(ROUND_JOIN); @@ -170,14 +170,14 @@ int main ( int argc , char** argv) m.insert_style("popplaces",popplaces_style ); - // Layers + // layers // Provincial polygons { parameters p; p["type"]="shape"; p["file"]="../data/boundaries"; - Layer lyr("Provinces"); + layer lyr("Provinces"); lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.add_style("provinces"); m.addLayer(lyr); @@ -188,7 +188,7 @@ int main ( int argc , char** argv) parameters p; p["type"]="shape"; p["file"]="../data/qcdrainage"; - Layer lyr("Quebec Hydrography"); + layer lyr("Quebec Hydrography"); lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.add_style("drainage"); m.addLayer(lyr); @@ -199,7 +199,7 @@ int main ( int argc , char** argv) p["type"]="shape"; p["file"]="../data/ontdrainage"; - Layer lyr("Ontario Hydrography"); + layer lyr("Ontario Hydrography"); lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.add_style("drainage"); m.addLayer(lyr); @@ -210,7 +210,7 @@ int main ( int argc , char** argv) parameters p; p["type"]="shape"; p["file"]="../data/boundaries_l"; - Layer lyr("Provincial borders"); + layer lyr("Provincial borders"); lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.add_style("provlines"); m.addLayer(lyr); @@ -221,7 +221,7 @@ int main ( int argc , char** argv) parameters p; p["type"]="shape"; p["file"]="../data/roads"; - Layer lyr("Roads"); + layer lyr("Roads"); lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.add_style("smallroads"); lyr.add_style("road-border"); @@ -237,22 +237,22 @@ int main ( int argc , char** argv) p["type"]="shape"; p["file"]="../data/popplaces"; p["encoding"] = "latin1"; - Layer lyr("Populated Places"); + layer lyr("Populated Places"); lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.add_style("popplaces"); m.addLayer(lyr); } - m.zoomToBox(Envelope(1405120.04127408,-247003.813399447, + m.zoomToBox(box2d(1405120.04127408,-247003.813399447, 1706357.31328276,-25098.593149577)); - Image32 buf(m.getWidth(),m.getHeight()); - agg_renderer ren(m,buf); + image_32 buf(m.getWidth(),m.getHeight()); + agg_renderer ren(m,buf); ren.apply(); - save_to_file(buf.data(),"demo.jpg","jpeg"); - save_to_file(buf.data(),"demo.png","png"); - save_to_file(buf.data(),"demo256.png","png256"); + save_to_file(buf.data(),"demo.jpg","jpeg"); + save_to_file(buf.data(),"demo.png","png"); + save_to_file(buf.data(),"demo256.png","png256"); std::cout << "Three maps have been rendered using AGG in the current directory:\n" "- demo.jpg\n" "- demo.png\n" @@ -267,7 +267,7 @@ int main ( int argc , char** argv) png_render.apply(); image_surface->write_to_png("cairo-demo.png"); - Image32 im(image_surface); + image_32 im(image_surface); save_to_file(im, "cairo-demo256.png","png256"); Cairo::RefPtr surface; diff --git a/demo/python/rundemo.py b/demo/python/rundemo.py index e5093f5db..cdab8f77f 100644 --- a/demo/python/rundemo.py +++ b/demo/python/rundemo.py @@ -77,11 +77,11 @@ provpoly_style = mapnik.Style() provpoly_rule_on = mapnik.Rule() -# A Filter() allows the selection of features to which the symbology will +# A Expression() allows the selection of features to which the symbology will # be applied. More on Mapnik expressions can be found in Tutorial #2. # A given feature can only match one filter per rule per style. -provpoly_rule_on.filter = mapnik.Filter("[NAME_EN] = 'Ontario'") +provpoly_rule_on.filter = mapnik.Expression("[NAME_EN] = 'Ontario'") # Here a symbolizer is defined. Available are: # - LineSymbolizer(Color(),) @@ -99,7 +99,7 @@ provpoly_rule_on.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color(250, 190, provpoly_style.rules.append(provpoly_rule_on) provpoly_rule_qc = mapnik.Rule() -provpoly_rule_qc.filter = mapnik.Filter("[NOM_FR] = 'Québec'") +provpoly_rule_qc.filter = mapnik.Expression("[NOM_FR] = 'Québec'") provpoly_rule_qc.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color(217, 235, 203))) provpoly_style.rules.append(provpoly_rule_qc) @@ -129,7 +129,7 @@ qcdrain_lyr.datasource = mapnik.Shapefile(file='../data/qcdrainage') qcdrain_style = mapnik.Style() qcdrain_rule = mapnik.Rule() -qcdrain_rule.filter = mapnik.Filter('[HYC] = 8') +qcdrain_rule.filter = mapnik.Expression('[HYC] = 8') qcdrain_rule.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color(153, 204, 255))) qcdrain_style.rules.append(qcdrain_rule) @@ -182,7 +182,7 @@ roads34_lyr.datasource = mapnik.Shapefile(file='../data/roads') roads34_style = mapnik.Style() roads34_rule = mapnik.Rule() -roads34_rule.filter = mapnik.Filter('[CLASS] = 3 or [CLASS] = 4') +roads34_rule.filter = mapnik.Expression('([CLASS] = 3) or ([CLASS] = 4)') # With lines of a certain width, you can control how the ends # are closed off using line_cap as below. @@ -215,7 +215,7 @@ roads2_lyr.datasource = roads34_lyr.datasource roads2_style_1 = mapnik.Style() roads2_rule_1 = mapnik.Rule() -roads2_rule_1.filter = mapnik.Filter('[CLASS] = 2') +roads2_rule_1.filter = mapnik.Expression('[CLASS] = 2') roads2_rule_stk_1 = mapnik.Stroke() roads2_rule_stk_1.color = mapnik.Color(171,158,137) roads2_rule_stk_1.line_cap = mapnik.line_cap.ROUND_CAP @@ -227,7 +227,7 @@ m.append_style('road-border', roads2_style_1) roads2_style_2 = mapnik.Style() roads2_rule_2 = mapnik.Rule() -roads2_rule_2.filter = mapnik.Filter('[CLASS] = 2') +roads2_rule_2.filter = mapnik.Expression('[CLASS] = 2') roads2_rule_stk_2 = mapnik.Stroke() roads2_rule_stk_2.color = mapnik.Color(255,250,115) roads2_rule_stk_2.line_cap = mapnik.line_cap.ROUND_CAP @@ -250,7 +250,7 @@ roads1_lyr.datasource = roads34_lyr.datasource roads1_style_1 = mapnik.Style() roads1_rule_1 = mapnik.Rule() -roads1_rule_1.filter = mapnik.Filter('[CLASS] = 1') +roads1_rule_1.filter = mapnik.Expression('[CLASS] = 1') roads1_rule_stk_1 = mapnik.Stroke() roads1_rule_stk_1.color = mapnik.Color(188,149,28) roads1_rule_stk_1.line_cap = mapnik.line_cap.ROUND_CAP @@ -261,7 +261,7 @@ m.append_style('highway-border', roads1_style_1) roads1_style_2 = mapnik.Style() roads1_rule_2 = mapnik.Rule() -roads1_rule_2.filter = mapnik.Filter('[CLASS] = 1') +roads1_rule_2.filter = mapnik.Expression('[CLASS] = 1') roads1_rule_stk_2 = mapnik.Stroke() roads1_rule_stk_2.color = mapnik.Color(242,191,36) roads1_rule_stk_2.line_cap = mapnik.line_cap.ROUND_CAP @@ -289,7 +289,7 @@ popplaces_rule = mapnik.Rule() # The first parameter is the name of the attribute to use as the source of the # text to label with. Then there is font size in points (I think?), and colour. -popplaces_text_symbolizer = mapnik.TextSymbolizer('GEONAME', +popplaces_text_symbolizer = mapnik.TextSymbolizer(mapnik.Expression("[GEONAME]"), 'DejaVu Sans Book', 10, mapnik.Color('black')) @@ -310,7 +310,7 @@ m.layers.append(popplaces_lyr) # Draw map # Set the initial extent of the map in 'master' spherical Mercator projection -m.zoom_to_box(mapnik.Envelope(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855)) +m.zoom_to_box(mapnik.Box2d(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855)) # Render two maps, two PNGs, one JPEG. im = mapnik.Image(m.width,m.height) diff --git a/demo/test/charplacement.py b/demo/test/charplacement.py index 3a137658d..64b45f193 100644 --- a/demo/test/charplacement.py +++ b/demo/test/charplacement.py @@ -69,7 +69,7 @@ m.layers.append(road_layer) # Draw map # Set the initial extent of the map. -m.zoom_to_box(Envelope(0,0,14,-14)) +m.zoom_to_box(Box2d(0,0,14,-14)) # Render diff --git a/demo/test/displacement.py b/demo/test/displacement.py index e63712b95..5f6dbac38 100644 --- a/demo/test/displacement.py +++ b/demo/test/displacement.py @@ -70,7 +70,7 @@ m.layers.append(road_layer) # Draw map # Set the initial extent of the map. -m.zoom_to_box(Envelope(0,0,14,-14)) +m.zoom_to_box(Box2d(0,0,14,-14)) # Render diff --git a/demo/test/overlap.py b/demo/test/overlap.py index 46b8c3887..50eb0083c 100644 --- a/demo/test/overlap.py +++ b/demo/test/overlap.py @@ -71,7 +71,7 @@ m.layers.append(road_layer) # Draw map # Set the initial extent of the map. -m.zoom_to_box(Envelope(0,0,14,-14)) +m.zoom_to_box(Box2d(0,0,14,-14)) # Render diff --git a/demo/test/textspacing.py b/demo/test/textspacing.py index 170c0836b..1c8e19b4b 100644 --- a/demo/test/textspacing.py +++ b/demo/test/textspacing.py @@ -69,7 +69,7 @@ m.layers.append(road_layer) # Draw map # Set the initial extent of the map. -m.zoom_to_box(Envelope(0,0,14,-14)) +m.zoom_to_box(Box2d(0,0,14,-14)) # Render diff --git a/demo/viewer/layerlistmodel.cpp b/demo/viewer/layerlistmodel.cpp index 70559a26a..259209392 100644 --- a/demo/viewer/layerlistmodel.cpp +++ b/demo/viewer/layerlistmodel.cpp @@ -90,7 +90,7 @@ bool LayerListModel::setData(const QModelIndex &index, if (index.isValid() && role == Qt::CheckStateRole) { int status = value.toInt(); - std::vector & layers = const_cast& >(map_->layers()); + std::vector & layers = const_cast& >(map_->layers()); layers.at(index.row()).setActive(status); emit dataChanged(index, index); return true; @@ -107,15 +107,15 @@ Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const return flags; } -boost::optional LayerListModel::map_layer(int i) +boost::optional LayerListModel::map_layer(int i) { if (map_) { - std::vector & layers = const_cast& >(map_->layers()); + std::vector & layers = const_cast& >(map_->layers()); if (i < layers.size()) - return boost::optional(layers[i]); + return boost::optional(layers[i]); } - return boost::optional(); + return boost::optional(); } diff --git a/demo/viewer/layerlistmodel.hpp b/demo/viewer/layerlistmodel.hpp index 6a6644859..30f126ba5 100644 --- a/demo/viewer/layerlistmodel.hpp +++ b/demo/viewer/layerlistmodel.hpp @@ -40,7 +40,7 @@ class LayerListModel : public QAbstractListModel bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); Qt::ItemFlags flags(QModelIndex const& index) const; - boost::optional map_layer(int i); + boost::optional map_layer(int i); private: boost::shared_ptr map_; diff --git a/demo/viewer/layerwidget.cpp b/demo/viewer/layerwidget.cpp index 6354fd930..15c49bb4a 100644 --- a/demo/viewer/layerwidget.cpp +++ b/demo/viewer/layerwidget.cpp @@ -79,7 +79,7 @@ void LayerTab::layerInfo2(QModelIndex const& index) QVector > params; unsigned i = index.row(); LayerListModel * model = static_cast(this->model()); - boost::optional layer = model->map_layer(i); + boost::optional layer = model->map_layer(i); if (layer) { diff --git a/demo/viewer/main.cpp b/demo/viewer/main.cpp index d06a4947a..193e2957f 100644 --- a/demo/viewer/main.cpp +++ b/demo/viewer/main.cpp @@ -41,8 +41,8 @@ int main( int argc, char **argv ) // modify this prefix based on your install location std::string mapnik_dir = "/opt/mapnik"; - datasource_cache::instance()->register_datasources(mapnik_dir + "/lib/mapnik/input"); - boost::filesystem::path path(mapnik_dir + "/lib/mapnik/fonts"); + datasource_cache::instance()->register_datasources(mapnik_dir + "/lib64/mapnik/input"); + boost::filesystem::path path(mapnik_dir + "/lib64/mapnik/fonts"); boost::filesystem::directory_iterator end_itr; diff --git a/demo/viewer/mainwindow.cpp b/demo/viewer/mainwindow.cpp index cf926ff6a..9e3590309 100644 --- a/demo/viewer/mainwindow.cpp +++ b/demo/viewer/mainwindow.cpp @@ -140,7 +140,7 @@ void MainWindow::reload() { if (!filename_.isEmpty()) { - mapnik::Envelope bbox = mapWidget_->getMap()->getCurrentExtent(); + mapnik::box2d bbox = mapWidget_->getMap()->getCurrentExtent(); load_map_file(filename_); mapWidget_->zoomToBox(bbox); setWindowTitle(tr("%1 - *Reloaded*").arg(filename_)); @@ -382,7 +382,7 @@ void MainWindow::set_default_extent(double x0,double y0, double x1, double y1) mapnik::projection prj(map_ptr->srs()); prj.forward(x0,y0); prj.forward(x1,y1); - default_extent_=mapnik::Envelope(x0,y0,x1,y1); + default_extent_=mapnik::box2d(x0,y0,x1,y1); mapWidget_->zoomToBox(default_extent_); std::cout << "SET DEFAULT EXT\n"; } diff --git a/demo/viewer/mainwindow.hpp b/demo/viewer/mainwindow.hpp index 9b8cef873..d807fc274 100644 --- a/demo/viewer/mainwindow.hpp +++ b/demo/viewer/mainwindow.hpp @@ -105,7 +105,7 @@ public slots: QStatusBar *status; QSlider * slider_; - mapnik::Envelope default_extent_; + mapnik::box2d default_extent_; }; diff --git a/demo/viewer/mapwidget.cpp b/demo/viewer/mapwidget.cpp index 3d9895cc1..fe0b2d96e 100644 --- a/demo/viewer/mapwidget.cpp +++ b/demo/viewer/mapwidget.cpp @@ -30,10 +30,10 @@ #include "mapwidget.hpp" #include "info_dialog.hpp" -using mapnik::Image32; +using mapnik::image_32; using mapnik::Map; -using mapnik::Layer; -using mapnik::Envelope; +using mapnik::layer; +using mapnik::box2d; using mapnik::coord2d; using mapnik::feature_ptr; using mapnik::geometry_ptr; @@ -149,7 +149,7 @@ void MapWidget::mousePressEvent(QMouseEvent* e) { if (int(index) != selectedLayer_) continue; - Layer & layer = map_->layers()[index]; + layer & layer = map_->layers()[index]; if (!layer.isVisible(scale_denom)) continue; std::string name = layer.name(); double x = e->x(); @@ -187,7 +187,7 @@ void MapWidget::mousePressEvent(QMouseEvent* e) double x,y; path.vertex(&x,&y); qpath.moveTo(x,y); - for (int j=1; j < geom.num_points(); ++j) + for (unsigned j = 1; j < geom.num_points(); ++j) { path.vertex(&x,&y); qpath.lineTo(x,y); @@ -216,7 +216,7 @@ void MapWidget::mousePressEvent(QMouseEvent* e) // remove annotation layer map_->layers().erase(remove_if(map_->layers().begin(), map_->layers().end(), - bind(&Layer::name,_1) == "*annotations*") + bind(&layer::name,_1) == "*annotations*") , map_->layers().end()); } } @@ -249,7 +249,7 @@ void MapWidget::mouseReleaseEvent(QMouseEvent* e) if (map_) { CoordTransform t(map_->getWidth(),map_->getHeight(),map_->getCurrentExtent()); - Envelope box = t.backward(Envelope(start_x_,start_y_,end_x_,end_y_)); + box2d box = t.backward(box2d(start_x_,start_y_,end_x_,end_y_)); map_->zoomToBox(box); updateMap(); } @@ -273,7 +273,7 @@ void MapWidget::mouseReleaseEvent(QMouseEvent* e) void MapWidget::keyPressEvent(QKeyEvent *e) { - std::cout << "key pressed:"<key()<<"\n"; + std::cout << "key pressed:"<< e->key()<<"\n"; switch (e->key()) { case Qt::Key_Minus: zoomOut(); @@ -324,11 +324,14 @@ void MapWidget::keyPressEvent(QKeyEvent *e) case 57: zoomToLevel(18); break; + default: + QWidget::keyPressEvent(e); } - QWidget::keyPressEvent(e); + + } -void MapWidget::zoomToBox(mapnik::Envelope const& bbox) +void MapWidget::zoomToBox(mapnik::box2d const& bbox) { if (map_) { @@ -416,14 +419,14 @@ void MapWidget::zoomToLevel(int level) { double scale_denom = scales[level]; std::cerr << "scale denominator = " << scale_denom << "\n"; - mapnik::Envelope ext = map_->getCurrentExtent(); + mapnik::box2d ext = map_->getCurrentExtent(); double width = static_cast(map_->getWidth()); double height= static_cast(map_->getHeight()); mapnik::coord2d pt = ext.center(); double res = scale_denom * 0.00028; - mapnik::Envelope box(pt.x - 0.5 * width * res, + mapnik::box2d box(pt.x - 0.5 * width * res, pt.y - 0.5 * height*res, pt.x + 0.5 * width * res, pt.y + 0.5 * height*res); @@ -434,7 +437,7 @@ void MapWidget::zoomToLevel(int level) void MapWidget::export_to_file(unsigned ,unsigned ,std::string const&,std::string const&) { - //Image32 image(width,height); + //image_32 image(width,height); //agg_renderer renderer(map,image); //renderer.apply(); //image.saveToFile(filename,type); @@ -448,8 +451,8 @@ void MapWidget::updateMap() unsigned width=map_->getWidth(); unsigned height=map_->getHeight(); - Image32 buf(width,height); - mapnik::agg_renderer ren(*map_,buf); + image_32 buf(width,height); + mapnik::agg_renderer ren(*map_,buf); ren.apply(); QImage image((uchar*)buf.raw_data(),width,height,QImage::Format_ARGB32); diff --git a/demo/viewer/mapwidget.hpp b/demo/viewer/mapwidget.hpp index a0153d4ce..79df68170 100644 --- a/demo/viewer/mapwidget.hpp +++ b/demo/viewer/mapwidget.hpp @@ -48,7 +48,7 @@ class MapWidget : public QWidget boost::shared_ptr map_; int selected_; QPixmap pix_; - mapnik::Envelope extent_; + mapnik::box2d extent_; eTool cur_tool_; int start_x_; int start_y_; @@ -65,7 +65,7 @@ class MapWidget : public QWidget inline QPixmap const& pixmap() const { return pix_;} void setMap(boost::shared_ptr map); void defaultView(); - void zoomToBox(mapnik::Envelope const& box); + void zoomToBox(mapnik::box2d const& box); void zoomIn(); void zoomOut(); void panLeft(); diff --git a/demo/viewer/styles_model.cpp b/demo/viewer/styles_model.cpp index cc0114911..e72b91b31 100644 --- a/demo/viewer/styles_model.cpp +++ b/demo/viewer/styles_model.cpp @@ -182,13 +182,17 @@ struct symbolizer_icon : public boost::static_visitor QIcon operator() (mapnik::point_symbolizer const& sym) const { - boost::shared_ptr symbol = sym.get_image(); - if (symbol) - { - QImage image(symbol->getBytes(),symbol->width(),symbol->height(),QImage::Format_ARGB32); + // FIXME! + /* + boost::shared_ptr symbol = sym.get_image(); + if (symbol) + { + QImage image(symbol->getBytes(), + symbol->width(),symbol->height(),QImage::Format_ARGB32); QPixmap pix = QPixmap::fromImage(image.rgbSwapped()); return QIcon(pix); } + */ return QIcon(); } QIcon operator() (mapnik::line_symbolizer const& sym) const @@ -243,9 +247,9 @@ class rule_node ~rule_node() {} QString name() const { - mapnik::filter_ptr filter = rule_.get_filter(); + mapnik::expression_ptr filter = rule_.get_filter(); - return QString(filter->to_string().c_str()); + return QString("TODO!");//filter->to_string().c_str()); } QIcon icon() const @@ -319,7 +323,7 @@ StyleModel::StyleModel(boost::shared_ptr map, QObject * parent) for ( ; itr2 != rules.end();++itr2) { node* rule_n = style_n->add_child(new node(rule_node(QString("Rule"),*itr2),style_n)); - mapnik::symbolizers::const_iterator itr3 = (*itr2).begin(); + mapnik::rule_type::symbolizers::const_iterator itr3 = (*itr2).begin(); for ( ; itr3 !=itr2->end();++itr3) { rule_n->add_child(new node(symbolizer_node(*itr3),rule_n)); diff --git a/demo/viewer/viewer.pro b/demo/viewer/viewer.pro index 58539f9d8..997230150 100644 --- a/demo/viewer/viewer.pro +++ b/demo/viewer/viewer.pro @@ -5,14 +5,14 @@ CC = g++ TEMPLATE = app INCLUDEPATH += /opt/mapnik/include -INCLUDEPATH += /opt/boost/include/boost-1_39 +INCLUDEPATH += /opt/boost/include/ INCLUDEPATH += /usr/X11/include/ INCLUDEPATH += /usr/X11/include/freetype2 INCLUDEPATH += . -#QMAKE_CXXFLAGS +=' -DDARWIN' -unix:LIBS = -L/opt/mapnik/lib -L/usr/X11/lib -lmapnik -lfreetype -L/usr/local/lib -licuuc -unix:LIBS += -lboost_system-xgcc40-mt -lboost_filesystem-xgcc40-mt -L/opt/boost/lib +QMAKE_CXXFLAGS +=' -DDARWIN -Wno-missing-field-initializers' +unix:LIBS = -L/opt/mapnik/lib64 -L/usr/X11/lib -lmapnik -lfreetype -L/usr/local/lib -licuuc +unix:LIBS += -lboost_system -lboost_filesystem -lboost_regex -L/opt/boost/lib # Input diff --git a/include/mapnik/agg_renderer.hpp b/include/mapnik/agg_renderer.hpp index b8fb7f846..296ba716b 100644 --- a/include/mapnik/agg_renderer.hpp +++ b/include/mapnik/agg_renderer.hpp @@ -51,8 +51,8 @@ namespace mapnik { ~agg_renderer(); void start_map_processing(Map const& map); void end_map_processing(Map const& map); - void start_layer_processing(Layer const& lay); - void end_layer_processing(Layer const& lay); + void start_layer_processing(layer const& lay); + void end_layer_processing(layer const& lay); void process(point_symbolizer const& sym, Feature const& feature, proj_transform const& prj_trans); diff --git a/include/mapnik/arrow.hpp b/include/mapnik/arrow.hpp index 57176adcd..88848bf11 100644 --- a/include/mapnik/arrow.hpp +++ b/include/mapnik/arrow.hpp @@ -25,7 +25,7 @@ #ifndef ARROW_HPP #define ARROW_HPP -#include +#include namespace mapnik { @@ -35,7 +35,7 @@ namespace mapnik { arrow(); void rewind(unsigned path_id); unsigned vertex(double* x, double* y); - Envelope extent() const; + box2d extent() const; private: unsigned pos_; double x_[7]; diff --git a/include/mapnik/attribute.hpp b/include/mapnik/attribute.hpp deleted file mode 100644 index d7daaf0bd..000000000 --- a/include/mapnik/attribute.hpp +++ /dev/null @@ -1,222 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2006 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 - * - *****************************************************************************/ - -//$Id: attribute.hpp 41 2005-04-13 20:21:56Z pavlenko $ - -#ifndef ATTRIBUTE_HPP -#define ATTRIBUTE_HPP - -// boost -#include -// stl -#include -#include -#include - -namespace mapnik { - template - struct attribute_traits - { - static std::string to_string(const T& value) - { - std::stringstream ss; - ss << value; - return ss.str(); - } - }; - - template <> - struct attribute_traits - { - static std::string to_string(const std::string& value) - { - return value; - } - }; - - class MAPNIK_DECL attribute - { - public: - attribute() - : base_(0) {} - - template - attribute(const T& value) - : base_(new attribute_impl(value)) - {} - - attribute(const attribute& rhs) - : base_(rhs.base_ ? rhs.base_->clone() : 0) - {} - - ~attribute() - { - delete base_; - } - - template - attribute& operator=(const T& rhs) - { - attribute(rhs).swap(*this); - return *this; - } - - attribute& operator=(const attribute& rhs) - { - attribute(rhs).swap(*this); - return *this; - } - - bool empty() const - { - return !base_; - } - - const std::type_info & type() const - { - return base_ ? base_->type() : typeid(void); - } - - const std::string to_string() const - { - return base_ ? base_->to_string() : ""; - } - private: - attribute& swap(attribute& rhs) - { - std::swap(base_,rhs.base_); - return *this; - } - - class attribute_base - { - public: - virtual ~attribute_base() {} - virtual attribute_base* clone() const=0; - virtual std::string to_string() const=0; - virtual const std::type_info& type() const=0; - }; - - template > - class attribute_impl : public attribute_base - { - public: - typedef T value_type; - attribute_impl(const value_type& value) - : value_(value) {} - - virtual std::string to_string() const - { - return ATraits::to_string(value_); - } - - virtual attribute_base* clone() const - { - return new attribute_impl(value_); - } - virtual const std::type_info& type() const - { - return typeid(value_); - } - value_type value_; - }; - private: - template - friend value_type* attribute_cast(attribute*); - attribute_base* base_; - }; - - - template - struct bad_attribute_cast : public std::bad_cast - { - virtual const char* what() const throw() - { - return "attribute::failed conversion"; - } - }; - - template - bool is_type(const attribute& attr) - { - return attr.type()==typeid(T); - } - - template - T* attribute_cast(attribute* attr) - { - return attr && attr->type() == typeid(T) - ? &static_cast*>(attr->base_)->value_ - : 0; - } - - template - const T* attribute_cast(const attribute* attr) - { - return attribute_cast(const_cast(attr)); - } - - template - T attribute_cast(const attribute& attr) - { - using namespace boost; - typedef BOOST_DEDUCED_TYPENAME remove_reference::type nonref; - const nonref * result=attribute_cast(&attr); - if (!result) - { - throw bad_attribute_cast(); - } - return *result; - } - - template - T attribute_cast(attribute& attr) - { - using namespace boost; - typedef BOOST_DEDUCED_TYPENAME remove_reference::type nonref; - nonref * result=attribute_cast(&attr); - if (!result) - throw bad_attribute_cast(); - return *result; - } - - - template - attribute attribute_from_string(const std::string& val) - { - std::istringstream is(val); - T t; - is >> t; - return attribute(t); - } - - template - inline std::basic_ostream& - operator << (std::basic_ostream& out, - const attribute& attr) - { - out << attr.to_string(); - return out; - } -} - -#endif //ATTRIBUTE_HPP diff --git a/include/mapnik/attribute_collector.hpp b/include/mapnik/attribute_collector.hpp index 029dd6272..bf770ed36 100644 --- a/include/mapnik/attribute_collector.hpp +++ b/include/mapnik/attribute_collector.hpp @@ -26,77 +26,157 @@ #define ATTRIBUTE_COLLECTOR_HPP // mapnik -#include -#include #include #include +#include + +// boost +#include +#include +#include // stl #include #include namespace mapnik { + +struct expression_attributes : boost::static_visitor +{ + explicit expression_attributes(std::set & names) + : names_(names) {} - struct symbolizer_attributes : public boost::static_visitor<> + void operator() (value_type const& x) const { - symbolizer_attributes(std::set& names) - : names_(names) {} - - template - void operator () (T const&) const {} - void operator () (text_symbolizer const& sym) - { - names_.insert(sym.get_name()); - } - void operator () (shield_symbolizer const& sym) - { - names_.insert(sym.get_name()); - } - private: - std::set& names_; - }; - - template - class attribute_collector : public filter_visitor + boost::ignore_unused_variable_warning(x); + } + + void operator() (attribute const& attr) const { - private: - std::set& names_; - public: - - attribute_collector(std::set& names) - : names_(names) {} - - void visit(filter& /*filter*/) - { - //not interested - } - - void visit(expression& exp) - { - property* pf; - if ((pf = dynamic_cast*>(&exp))) - { - names_.insert(pf->name()); - } - } - void visit(rule_type const& r) - { - const symbolizers& symbols = r.get_symbolizers(); - symbolizers::const_iterator symIter=symbols.begin(); - symbolizer_attributes attr(names_); - while (symIter != symbols.end()) - { - boost::apply_visitor(attr,*symIter++); - } - filter_ptr const& filter = r.get_filter(); - filter->accept(*this); - } + names_.insert(attr.name()); + } + + template + void operator() (binary_node const& x) const + { + boost::apply_visitor(expression_attributes(names_),x.left); + boost::apply_visitor(expression_attributes(names_),x.right); + + } - virtual ~attribute_collector() {} - private: - // no copying - attribute_collector(attribute_collector const&); - attribute_collector& operator=(attribute_collector const&); - }; -} + template + void operator() (unary_node const& x) const + { + boost::apply_visitor(expression_attributes(names_),x.expr); + } + + void operator() (regex_match_node const& x) const + { + boost::apply_visitor(expression_attributes(names_),x.expr); + } + + void operator() (regex_replace_node const& x) const + { + boost::apply_visitor(expression_attributes(names_),x.expr); + } + +private: + mutable std::set& names_; +}; + +struct symbolizer_attributes : public boost::static_visitor<> +{ + symbolizer_attributes(std::set& names) + : names_(names) {} + + template + void operator () (T const&) const {} + + void operator () (text_symbolizer const& sym) + { + expression_ptr const& name_expr = sym.get_name(); + if (name_expr) + { + expression_attributes f_attr(names_); + boost::apply_visitor(f_attr,*name_expr); + } + } + + void operator () (point_symbolizer const& sym) + { + path_expression_ptr const& filename_expr = sym.get_filename(); + if (filename_expr) + { + path_processor_type::collect_attributes(*filename_expr,names_); + } + } + + void operator () (line_pattern_symbolizer const& sym) + { + path_expression_ptr const& filename_expr = sym.get_filename(); + if (filename_expr) + { + path_processor_type::collect_attributes(*filename_expr,names_); + } + } + + void operator () (polygon_pattern_symbolizer const& sym) + { + path_expression_ptr const& filename_expr = sym.get_filename(); + if (filename_expr) + { + path_processor_type::collect_attributes(*filename_expr,names_); + } + } + + void operator () (shield_symbolizer const& sym) + { + expression_ptr const& name_expr = sym.get_name(); + if (name_expr) + { + expression_attributes name_attr(names_); + boost::apply_visitor(name_attr,*name_expr); + } + + path_expression_ptr const& filename_expr = sym.get_filename(); + if (filename_expr) + { + path_processor_type::collect_attributes(*filename_expr,names_); + } + } + + // TODO - support remaining syms + +private: + std::set& names_; +}; + + +class attribute_collector : public boost::noncopyable +{ +private: + std::set& names_; +public: + + attribute_collector(std::set& names) + : names_(names) {} + + template + void operator() (RuleType const& r) + { + typename RuleType::symbolizers const& symbols = r.get_symbolizers(); + typename RuleType::symbolizers::const_iterator symIter=symbols.begin(); + symbolizer_attributes s_attr(names_); + while (symIter != symbols.end()) + { + boost::apply_visitor(s_attr,*symIter++); + } + + expression_ptr const& expr = r.get_filter(); + expression_attributes f_attr(names_); + boost::apply_visitor(f_attr,*expr); + } +}; + +} // namespace mapnik #endif //ATTRIBUTE_COLLECTOR_HPP diff --git a/include/mapnik/boolean_filter.hpp b/include/mapnik/boolean_filter.hpp deleted file mode 100644 index 244f77a91..000000000 --- a/include/mapnik/boolean_filter.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2008 Tom Hughes - * - * 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 - * - *****************************************************************************/ - - -//$Id$ - -#ifndef BOOLEAN_FILTER_HPP -#define BOOLEAN_FILTER_HPP -// mapnik -#include -#include - -namespace mapnik -{ - template - struct boolean_filter : public filter - { - - boolean_filter(expression const& exp) - : filter(), - exp_(exp.clone()) {} - - boolean_filter(boolean_filter const& other) - : filter(), - exp_(other.exp_->clone()) {} - - bool pass(FeatureT const& feature) const - { - return exp_->get_value(feature).to_bool(); - } - - void accept(filter_visitor& v) - { - exp_->accept(v); - v.visit(*this); - } - - filter* clone() const - { - return new boolean_filter(*this); - } - std::string to_string() const - { - return exp_->to_string(); - } - ~boolean_filter() - { - delete exp_; - } - - private: - expression* exp_; - - }; -} - - -#endif //BOOLEAN_FILTER_HPP diff --git a/include/mapnik/envelope.hpp b/include/mapnik/box2d.hpp similarity index 67% rename from include/mapnik/envelope.hpp rename to include/mapnik/box2d.hpp index a25bb2b36..96a916e34 100644 --- a/include/mapnik/envelope.hpp +++ b/include/mapnik/box2d.hpp @@ -20,10 +20,10 @@ * *****************************************************************************/ -//$Id: envelope.hpp 39 2005-04-10 20:39:53Z pavlenko $ +//$Id: box2d.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef ENVELOPE_HPP -#define ENVELOPE_HPP +#ifndef MAPNIK_BOX2D_HPP +#define MAPNIK_BOX2D_HPP // mapnik #include @@ -38,24 +38,24 @@ namespace mapnik { /*! * A spatial envelope (i.e. bounding box) which also defines some basic operators. */ - template class MAPNIK_DECL Envelope - : boost::addable, - boost::subtractable, - boost::dividable2, T, - boost::multipliable2, T > > > > + template class MAPNIK_DECL box2d + : boost::addable, + boost::subtractable, + boost::dividable2, T, + boost::multipliable2, T > > > > { public: - typedef Envelope EnvelopeType; + typedef box2d box2d_type; private: T minx_; T miny_; T maxx_; T maxy_; public: - Envelope(); - Envelope(T minx,T miny,T maxx,T maxy); - Envelope(const coord& c0,const coord& c1); - Envelope(const EnvelopeType& rhs); + box2d(); + box2d(T minx,T miny,T maxx,T maxy); + box2d(const coord& c0,const coord& c1); + box2d(const box2d_type& rhs); T minx() const; T miny() const; T maxx() const; @@ -67,34 +67,34 @@ namespace mapnik { coord center() const; void expand_to_include(T x,T y); void expand_to_include(const coord& c); - void expand_to_include(const EnvelopeType& other); + void expand_to_include(const box2d_type& other); bool contains(const coord &c) const; bool contains(T x,T y) const; - bool contains(const EnvelopeType &other) const; + bool contains(const box2d_type &other) const; bool intersects(const coord &c) const; bool intersects(T x,T y) const; - bool intersects(const EnvelopeType &other) const; - EnvelopeType intersect(const EnvelopeType& other) const; - bool operator==(const EnvelopeType &other) const; + bool intersects(const box2d_type &other) const; + box2d_type intersect(const box2d_type& other) const; + bool operator==(const box2d_type &other) const; void re_center(T cx,T cy); void init(T x0,T y0,T x1,T y1); // define some operators - EnvelopeType& operator+=(EnvelopeType const& other); - EnvelopeType& operator-=(EnvelopeType const& other); - EnvelopeType& operator*=(T); - EnvelopeType& operator/=(T); + box2d_type& operator+=(box2d_type const& other); + box2d_type& operator-=(box2d_type const& other); + box2d_type& operator*=(T); + box2d_type& operator/=(T); }; template inline std::basic_ostream& operator << (std::basic_ostream& out, - const Envelope& e) + const box2d& e) { std::basic_ostringstream s; s.copyfmt(out); s.width(0); - s <<"Envelope(" << std::setprecision(16) + s <<"box2d(" << std::setprecision(16) << e.minx() << "," << e.miny() <<"," << e.maxx() << "," << e.maxy() <<")"; out << s.str(); @@ -102,4 +102,4 @@ namespace mapnik { } } -#endif // ENVELOPE_HPP +#endif // MAPNIK_BOX2D_HPP diff --git a/include/mapnik/cairo_renderer.hpp b/include/mapnik/cairo_renderer.hpp index fe7655a9b..7fbb18644 100644 --- a/include/mapnik/cairo_renderer.hpp +++ b/include/mapnik/cairo_renderer.hpp @@ -72,8 +72,8 @@ namespace mapnik { public: ~cairo_renderer_base(); void start_map_processing(Map const& map); - void start_layer_processing(Layer const& lay); - void end_layer_processing(Layer const& lay); + void start_layer_processing(layer const& lay); + void end_layer_processing(layer const& lay); void process(point_symbolizer const& sym, Feature const& feature, proj_transform const& prj_trans); diff --git a/include/mapnik/color.hpp b/include/mapnik/color.hpp index b7a96c2a1..6edbecd4c 100644 --- a/include/mapnik/color.hpp +++ b/include/mapnik/color.hpp @@ -30,7 +30,6 @@ #include //boost -#include #include // stl diff --git a/include/mapnik/color_factory.hpp b/include/mapnik/color_factory.hpp index ac84bf5a4..173e7d868 100644 --- a/include/mapnik/color_factory.hpp +++ b/include/mapnik/color_factory.hpp @@ -22,46 +22,60 @@ //$Id$ -#ifndef COLOR_FACTORY_HPP -#define COLOR_FACTORY_HPP +#ifndef MAPNIK_COLOR_FACTORY_HPP +#define MAPNIK_COLOR_FACTORY_HPP // mapnik #include #include -#include #include +#include -using namespace boost::spirit; +// boost +#include namespace mapnik { - class MAPNIK_DECL color_factory - { - public: - - static void init_from_string(color & c, char const* css_color) - { - actions a(c); - css_color_grammar > grammar(a); - parse_info<> info = parse(css_color, grammar, space_p); - if ( ! info.full) { - throw config_error(std::string("Failed to parse color value: ") + - "Expected a color, but got '" + css_color + "'"); - } - } - - static color from_string(char const* css_color) - { - color c; - init_from_string(c,css_color); - return c; - } - - private: - color_factory(); - color_factory(color_factory const&); - color_factory& operator=(color_factory const&); - }; +class MAPNIK_DECL color_factory : boost::noncopyable +{ +public: + + static void init_from_string(color & c, char const* css_color) + { + + typedef std::string::const_iterator iterator_type; + typedef mapnik::css_color_grammar css_color_grammar; + std::string str(css_color); + + css_color_grammar g; + iterator_type first = str.begin(); + iterator_type last = str.end(); + mapnik::css css_; + bool result = + boost::spirit::qi::phrase_parse(first, + last, + g, + boost::spirit::ascii::space, + css_); + if (!result) + { + throw config_error(std::string("Failed to parse color value: ") + + "Expected a color, but got '" + css_color + "'"); + } + // TODO: adapt mapnik::color into boost::fusion sequence + c.set_red(css_.r); + c.set_green(css_.g); + c.set_blue(css_.b); + c.set_alpha(css_.a); + } + + static color from_string(char const* css_color) + { + color c; + init_from_string(c,css_color); + return c; + } +}; } -#endif //COLOR_FACTORY_HPP +#endif //MAPNIK_COLOR_FACTORY_HPP diff --git a/include/mapnik/comparison.hpp b/include/mapnik/comparison.hpp deleted file mode 100644 index fa6e61050..000000000 --- a/include/mapnik/comparison.hpp +++ /dev/null @@ -1,149 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2006 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 - * - *****************************************************************************/ -//$Id$ - -#ifndef COMPARISON_HPP -#define COMPARISON_HPP - -#include -#include -#include - -namespace mapnik { - template - struct greater_than - { - bool operator() (T const& left, T const& right) const - { - return left > right; - } - static std::string to_string() - { - return ">"; - } - }; - - template - struct greater_than_or_equal - { - bool operator() (T const& left, T const& right) const - { - return left >= right; - } - static std::string to_string() - { - return ">="; - } - }; - template - struct less_than - { - bool operator() (T const& left, T const& right) const - { - return left < right; - } - static std::string to_string() - { - return "<"; - } - }; - template - struct less_than_or_equal - { - bool operator() (T const& left, T const& right) const - { - return left <= right; - } - static std::string to_string() - { - return "<="; - } - }; - template - struct equals - { - bool operator() (T const& left, T const& right) const - { - return left == right; - } - static std::string to_string() - { - return "="; - } - }; - - template - struct not_equals - { - bool operator() (T const& left, T const& right) const - { - return left != right; - } - static std::string to_string() - { - return "<>"; - } - }; - - template - struct compare_filter : public filter - { - compare_filter(expression const& left, - expression const& right) - : filter(), - left_(left.clone()), right_(right.clone()) {} - - compare_filter(compare_filter const& other) - : filter(), - left_(other.left_->clone()),right_(other.right_->clone()) {} - - bool pass(const FeatureT& feature) const - { - return Op()(left_->get_value(feature),right_->get_value(feature)); - } - void accept(filter_visitor& v) - { - left_->accept(v); - right_->accept(v); - v.visit(*this); - } - std::string to_string() const - { - return "("+left_->to_string()+Op::to_string()+right_->to_string()+")"; - } - - filter* clone() const - { - return new compare_filter(*this); - } - virtual ~compare_filter() - { - delete left_; - delete right_; - } - private: - expression* left_; - expression* right_; - }; -} - -#endif //COMPARISON_HPP diff --git a/include/mapnik/css_color_grammar.hpp b/include/mapnik/css_color_grammar.hpp new file mode 100644 index 000000000..bdabb443f --- /dev/null +++ b/include/mapnik/css_color_grammar.hpp @@ -0,0 +1,338 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2009 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 + * + *****************************************************************************/ + +//$Id$ + +#ifndef MAPNIK_CSS_COLOR_GRAMMAR_HPP +#define MAPNIK_CSS_COLOR_GRAMMAR_HPP + +// mapnik +#include +// spirit2 +#include +#include +#include +// phoenix +#include +#include +#include +#include +// fusion +#include + +// not in boost 1.41 +//#include + +// stl +#include + + +//BOOST_FUSION_ADAPT_CLASS( +// mapnik::color, +// (unsigned, unsigned, obj.red(), obj.set_red(val)) +// (unsigned, unsigned, obj.green(), obj.set_green(val)) +// (unsigned, unsigned, obj.blue(), obj.set_blue(val)) +// (unsigned, unsigned, obj.alpha(), obj.set_alpha(val)) +// ) + +namespace mapnik +{ +// temp workaround . TODO: adapt mapnik::color +struct css +{ + css () + : r(255),g(255),b(255),a(255) {} + css(unsigned r_,unsigned g_, unsigned b_,unsigned a_ = 0xff) + : r(r_),g(g_),b(b_),a(a_) {} + + unsigned r; + unsigned g; + unsigned b; + unsigned a; +}; + +} + +BOOST_FUSION_ADAPT_STRUCT( + mapnik::css, + (unsigned, r) + (unsigned, g) + (unsigned, b) + (unsigned, a) + ) + +namespace mapnik +{ + +namespace qi = boost::spirit::qi; +namespace phoenix = boost::phoenix; + +typedef boost::spirit::ascii::space_type ascii_space_type; + +struct named_colors_ : qi::symbols +{ + named_colors_() + { + add + ("aliceblue", mapnik::css(240, 248, 255)) + ("antiquewhite", mapnik::css(250, 235, 215)) + ("aqua", mapnik::css(0, 255, 255)) + ("aquamarine", mapnik::css(127, 255, 212)) + ("azure", mapnik::css(240, 255, 255)) + ("beige", mapnik::css(245, 245, 220)) + ("bisque", mapnik::css(255, 228, 196)) + ("black", mapnik::css(0, 0, 0)) + ("blanchedalmond", mapnik::css(255,235,205)) + ("blue", mapnik::css(0, 0, 255)) + ("blueviolet", mapnik::css(138, 43, 226)) + ("brown", mapnik::css(165, 42, 42)) + ("burlywood", mapnik::css(222, 184, 135)) + ("cadetblue", mapnik::css(95, 158, 160)) + ("chartreuse", mapnik::css(127, 255, 0)) + ("chocolate", mapnik::css(210, 105, 30)) + ("coral", mapnik::css(255, 127, 80)) + ("cornflowerblue", mapnik::css(100, 149, 237)) + ("cornsilk", mapnik::css(255, 248, 220)) + ("crimson", mapnik::css(220, 20, 60)) + ("cyan", mapnik::css(0, 255, 255)) + ("darkblue", mapnik::css(0, 0, 139)) + ("darkcyan", mapnik::css(0, 139, 139)) + ("darkgoldenrod", mapnik::css(184, 134, 11)) + ("darkgray", mapnik::css(169, 169, 169)) + ("darkgreen", mapnik::css(0, 100, 0)) + ("darkgrey", mapnik::css(169, 169, 169)) + ("darkkhaki", mapnik::css(189, 183, 107)) + ("darkmagenta", mapnik::css(139, 0, 139)) + ("darkolivegreen", mapnik::css(85, 107, 47)) + ("darkorange", mapnik::css(255, 140, 0)) + ("darkorchid", mapnik::css(153, 50, 204)) + ("darkred", mapnik::css(139, 0, 0)) + ("darksalmon", mapnik::css(233, 150, 122)) + ("darkseagreen", mapnik::css(143, 188, 143)) + ("darkslateblue", mapnik::css(72, 61, 139)) + ("darkslategrey", mapnik::css(47, 79, 79)) + ("darkturquoise", mapnik::css(0, 206, 209)) + ("darkviolet", mapnik::css(148, 0, 211)) + ("deeppink", mapnik::css(255, 20, 147)) + ("deepskyblue", mapnik::css(0, 191, 255)) + ("dimgray", mapnik::css(105, 105, 105)) + ("dimgrey", mapnik::css(105, 105, 105)) + ("dodgerblue", mapnik::css(30, 144, 255)) + ("firebrick", mapnik::css(178, 34, 34)) + ("floralwhite", mapnik::css(255, 250, 240)) + ("forestgreen", mapnik::css(34, 139, 34)) + ("fuchsia", mapnik::css(255, 0, 255)) + ("gainsboro", mapnik::css(220, 220, 220)) + ("ghostwhite", mapnik::css(248, 248, 255)) + ("gold", mapnik::css(255, 215, 0)) + ("goldenrod", mapnik::css(218, 165, 32)) + ("gray", mapnik::css(128, 128, 128)) + ("grey", mapnik::css(128, 128, 128)) + ("green", mapnik::css(0, 128, 0)) + ("greenyellow", mapnik::css(173, 255, 47)) + ("honeydew", mapnik::css(240, 255, 240)) + ("hotpink", mapnik::css(255, 105, 180)) + ("indianred", mapnik::css(205, 92, 92)) + ("indigo", mapnik::css(75, 0, 130)) + ("ivory", mapnik::css(255, 255, 240)) + ("khaki", mapnik::css(240, 230, 140)) + ("lavender", mapnik::css(230, 230, 250)) + ("lavenderblush", mapnik::css(255, 240, 245)) + ("lawngreen", mapnik::css(124, 252, 0)) + ("lemonchiffon", mapnik::css(255, 250, 205)) + ("lightblue", mapnik::css(173, 216, 230)) + ("lightcoral", mapnik::css(240, 128, 128)) + ("lightcyan", mapnik::css(224, 255, 255)) + ("lightgoldenrodyellow", mapnik::css(250, 250, 210)) + ("lightgray", mapnik::css(211, 211, 211)) + ("lightgreen", mapnik::css(144, 238, 144)) + ("lightgrey", mapnik::css(211, 211, 211)) + ("lightpink", mapnik::css(255, 182, 193)) + ("lightsalmon", mapnik::css(255, 160, 122)) + ("lightseagreen", mapnik::css(32, 178, 170)) + ("lightskyblue", mapnik::css(135, 206, 250)) + ("lightslategray", mapnik::css(119, 136, 153)) + ("lightslategrey", mapnik::css(119, 136, 153)) + ("lightsteelblue", mapnik::css(176, 196, 222)) + ("lightyellow", mapnik::css(255, 255, 224)) + ("lime", mapnik::css(0, 255, 0)) + ("limegreen", mapnik::css(50, 205, 50)) + ("linen", mapnik::css(250, 240, 230)) + ("magenta", mapnik::css(255, 0, 255)) + ("maroon", mapnik::css(128, 0, 0)) + ("mediumaquamarine", mapnik::css(102, 205, 170)) + ("mediumblue", mapnik::css(0, 0, 205)) + ("mediumorchid", mapnik::css(186, 85, 211)) + ("mediumpurple", mapnik::css(147, 112, 219)) + ("mediumseagreen", mapnik::css(60, 179, 113)) + ("mediumslateblue", mapnik::css(123, 104, 238)) + ("mediumspringgreen", mapnik::css(0, 250, 154)) + ("mediumturquoise", mapnik::css(72, 209, 204)) + ("mediumvioletred", mapnik::css(199, 21, 133)) + ("midnightblue", mapnik::css(25, 25, 112)) + ("mintcream", mapnik::css(245, 255, 250)) + ("mistyrose", mapnik::css(255, 228, 225)) + ("moccasin", mapnik::css(255, 228, 181)) + ("navajowhite", mapnik::css(255, 222, 173)) + ("navy", mapnik::css(0, 0, 128)) + ("oldlace", mapnik::css(253, 245, 230)) + ("olive", mapnik::css(128, 128, 0)) + ("olivedrab", mapnik::css(107, 142, 35)) + ("orange", mapnik::css(255, 165, 0)) + ("orangered", mapnik::css(255, 69, 0)) + ("orchid", mapnik::css(218, 112, 214)) + ("palegoldenrod", mapnik::css(238, 232, 170)) + ("palegreen", mapnik::css(152, 251, 152)) + ("paleturquoise", mapnik::css(175, 238, 238)) + ("palevioletred", mapnik::css(219, 112, 147)) + ("papayawhip", mapnik::css(255, 239, 213)) + ("peachpuff", mapnik::css(255, 218, 185)) + ("peru", mapnik::css(205, 133, 63)) + ("pink", mapnik::css(255, 192, 203)) + ("plum", mapnik::css(221, 160, 221)) + ("powderblue", mapnik::css(176, 224, 230)) + ("purple", mapnik::css(128, 0, 128)) + ("red", mapnik::css(255, 0, 0)) + ("rosybrown", mapnik::css(188, 143, 143)) + ("royalblue", mapnik::css(65, 105, 225)) + ("saddlebrown", mapnik::css(139, 69, 19)) + ("salmon", mapnik::css(250, 128, 114)) + ("sandybrown", mapnik::css(244, 164, 96)) + ("seagreen", mapnik::css(46, 139, 87)) + ("seashell", mapnik::css(255, 245, 238)) + ("sienna", mapnik::css(160, 82, 45)) + ("silver", mapnik::css(192, 192, 192)) + ("skyblue", mapnik::css(135, 206, 235)) + ("slateblue", mapnik::css(106, 90, 205)) + ("slategray", mapnik::css(112, 128, 144)) + ("slategrey", mapnik::css(112, 128, 144)) + ("snow", mapnik::css(255, 250, 250)) + ("springgreen", mapnik::css(0, 255, 127)) + ("steelblue", mapnik::css(70, 130, 180)) + ("tan", mapnik::css(210, 180, 140)) + ("teal", mapnik::css(0, 128, 128)) + ("thistle", mapnik::css(216, 191, 216)) + ("tomato", mapnik::css(255, 99, 71)) + ("turquoise", mapnik::css(64, 224, 208)) + ("violet", mapnik::css(238, 130, 238)) + ("wheat", mapnik::css(245, 222, 179)) + ("white", mapnik::css(255, 255, 255)) + ("whitesmoke", mapnik::css(245, 245, 245)) + ("yellow", mapnik::css(255, 255, 0)) + ("yellowgreen", mapnik::css(154, 205, 50)) + ("transparent", mapnik::css(0, 0, 0, 0)) + ; + } +} ; + +// clipper helper + +template +inline int clip_int(int val) +{ + if (val < MIN ) return MIN; + if (val > MAX ) return MAX; + return val; +} + +struct percent_conv_impl +{ + template + struct result + { + typedef unsigned type; + }; + + unsigned operator() (double val) const + { + return clip_int<0,255>(int((255.0 * val)/100.0 + 0.5)); + } +}; + +template +struct css_color_grammar : qi::grammar +{ + + css_color_grammar() + : css_color_grammar::base_type(css_color) + + { + using qi::lit; + using qi::_val; + using qi::double_; + using qi::_1; + using phoenix::at_c; + + css_color %= rgba_color + | rgba_percent_color + | hex_color + | hex_color_small + | named; + + hex_color %= lit('#') + >> hex2 + >> hex2 + >> hex2 + >> -hex2 + ; + + hex_color_small = lit('#') + >> hex1 [ at_c<0>(_val) = _1 | _1 << 4 ] + >> hex1 [ at_c<1>(_val) = _1 | _1 << 4 ] + >> hex1 [ at_c<2>(_val) = _1 | _1 << 4 ] + >> -hex1[ at_c<3>(_val) = _1 | _1 << 4 ] + ; + + rgba_color %= lit("rgb") >> -lit('a') + >> lit('(') + >> dec3 >> ',' + >> dec3 >> ',' + >> dec3 >> -(','>> -dec3) + >> lit(')') + ; + + rgba_percent_color = lit("rgb") >> -lit('a') + >> lit('(') + >> double_ [at_c<0>(_val) = percent_converter(_1)] >> '%' >> ',' + >> double_ [at_c<1>(_val) = percent_converter(_1)] >> '%' >> ',' + >> double_ [at_c<2>(_val) = percent_converter(_1)] >> '%' + >> -(','>> -double_ [at_c<3>(_val) = percent_converter(_1)] >> '%') + >> lit(')') + ; + } + + qi::uint_parser< unsigned, 16, 2, 2 > hex2 ; + qi::uint_parser< unsigned, 16, 1, 1 > hex1 ; + qi::uint_parser< unsigned, 10, 1, 3 > dec3 ; + qi::rule rgba_color; + qi::rule rgba_percent_color; + qi::rule hex_color; + qi::rule hex_color_small; + qi::rule css_color; + named_colors_ named; + phoenix::function percent_converter; + +}; + +} + +#endif //MAPNIK_CSS_COLOR_GRAMMAR_HPP diff --git a/include/mapnik/css_color_parser.hpp b/include/mapnik/css_color_parser.hpp deleted file mode 100644 index db954d641..000000000 --- a/include/mapnik/css_color_parser.hpp +++ /dev/null @@ -1,442 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2006 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 - * - *****************************************************************************/ - -//$Id$ - -#ifndef CSS_COLOR_PARSER_HPP -#define CSS_COLOR_PARSER_HPP - -// boost -#include - -#if BOOST_VERSION < 103800 - #include - #include -#else - #define BOOST_SPIRIT_USE_OLD_NAMESPACE - #include - #include -#endif - -using namespace boost::spirit; - -namespace mapnik { - - template - inline int clip_int(int val) - { - if (val < MIN ) return MIN; - if (val > MAX ) return MAX; - return val; - } - - template - struct named_colors : public symbols - { - named_colors() - { - symbols::add - ("aliceblue", ColorT(240, 248, 255)) - ("antiquewhite", ColorT(250, 235, 215)) - ("aqua", ColorT(0, 255, 255)) - ("aquamarine", ColorT(127, 255, 212)) - ("azure", ColorT(240, 255, 255)) - ("beige", ColorT(245, 245, 220)) - ("bisque", ColorT(255, 228, 196)) - ("black", ColorT(0, 0, 0)) - ("blanchedalmond", ColorT(255,235,205)) - ("blue", ColorT(0, 0, 255)) - ("blueviolet", ColorT(138, 43, 226)) - ("brown", ColorT(165, 42, 42)) - ("burlywood", ColorT(222, 184, 135)) - ("cadetblue", ColorT(95, 158, 160)) - ("chartreuse", ColorT(127, 255, 0)) - ("chocolate", ColorT(210, 105, 30)) - ("coral", ColorT(255, 127, 80)) - ("cornflowerblue", ColorT(100, 149, 237)) - ("cornsilk", ColorT(255, 248, 220)) - ("crimson", ColorT(220, 20, 60)) - ("cyan", ColorT(0, 255, 255)) - ("darkblue", ColorT(0, 0, 139)) - ("darkcyan", ColorT(0, 139, 139)) - ("darkgoldenrod", ColorT(184, 134, 11)) - ("darkgray", ColorT(169, 169, 169)) - ("darkgreen", ColorT(0, 100, 0)) - ("darkgrey", ColorT(169, 169, 169)) - ("darkkhaki", ColorT(189, 183, 107)) - ("darkmagenta", ColorT(139, 0, 139)) - ("darkolivegreen", ColorT(85, 107, 47)) - ("darkorange", ColorT(255, 140, 0)) - ("darkorchid", ColorT(153, 50, 204)) - ("darkred", ColorT(139, 0, 0)) - ("darksalmon", ColorT(233, 150, 122)) - ("darkseagreen", ColorT(143, 188, 143)) - ("darkslateblue", ColorT(72, 61, 139)) - ("darkslategrey", ColorT(47, 79, 79)) - ("darkturquoise", ColorT(0, 206, 209)) - ("darkviolet", ColorT(148, 0, 211)) - ("deeppink", ColorT(255, 20, 147)) - ("deepskyblue", ColorT(0, 191, 255)) - ("dimgray", ColorT(105, 105, 105)) - ("dimgrey", ColorT(105, 105, 105)) - ("dodgerblue", ColorT(30, 144, 255)) - ("firebrick", ColorT(178, 34, 34)) - ("floralwhite", ColorT(255, 250, 240)) - ("forestgreen", ColorT(34, 139, 34)) - ("fuchsia", ColorT(255, 0, 255)) - ("gainsboro", ColorT(220, 220, 220)) - ("ghostwhite", ColorT(248, 248, 255)) - ("gold", ColorT(255, 215, 0)) - ("goldenrod", ColorT(218, 165, 32)) - ("gray", ColorT(128, 128, 128)) - ("grey", ColorT(128, 128, 128)) - ("green", ColorT(0, 128, 0)) - ("greenyellow", ColorT(173, 255, 47)) - ("honeydew", ColorT(240, 255, 240)) - ("hotpink", ColorT(255, 105, 180)) - ("indianred", ColorT(205, 92, 92)) - ("indigo", ColorT(75, 0, 130)) - ("ivory", ColorT(255, 255, 240)) - ("khaki", ColorT(240, 230, 140)) - ("lavender", ColorT(230, 230, 250)) - ("lavenderblush", ColorT(255, 240, 245)) - ("lawngreen", ColorT(124, 252, 0)) - ("lemonchiffon", ColorT(255, 250, 205)) - ("lightblue", ColorT(173, 216, 230)) - ("lightcoral", ColorT(240, 128, 128)) - ("lightcyan", ColorT(224, 255, 255)) - ("lightgoldenrodyellow", ColorT(250, 250, 210)) - ("lightgray", ColorT(211, 211, 211)) - ("lightgreen", ColorT(144, 238, 144)) - ("lightgrey", ColorT(211, 211, 211)) - ("lightpink", ColorT(255, 182, 193)) - ("lightsalmon", ColorT(255, 160, 122)) - ("lightseagreen", ColorT(32, 178, 170)) - ("lightskyblue", ColorT(135, 206, 250)) - ("lightslategray", ColorT(119, 136, 153)) - ("lightslategrey", ColorT(119, 136, 153)) - ("lightsteelblue", ColorT(176, 196, 222)) - ("lightyellow", ColorT(255, 255, 224)) - ("lime", ColorT(0, 255, 0)) - ("limegreen", ColorT(50, 205, 50)) - ("linen", ColorT(250, 240, 230)) - ("magenta", ColorT(255, 0, 255)) - ("maroon", ColorT(128, 0, 0)) - ("mediumaquamarine", ColorT(102, 205, 170)) - ("mediumblue", ColorT(0, 0, 205)) - ("mediumorchid", ColorT(186, 85, 211)) - ("mediumpurple", ColorT(147, 112, 219)) - ("mediumseagreen", ColorT(60, 179, 113)) - ("mediumslateblue", ColorT(123, 104, 238)) - ("mediumspringgreen", ColorT(0, 250, 154)) - ("mediumturquoise", ColorT(72, 209, 204)) - ("mediumvioletred", ColorT(199, 21, 133)) - ("midnightblue", ColorT(25, 25, 112)) - ("mintcream", ColorT(245, 255, 250)) - ("mistyrose", ColorT(255, 228, 225)) - ("moccasin", ColorT(255, 228, 181)) - ("navajowhite", ColorT(255, 222, 173)) - ("navy", ColorT(0, 0, 128)) - ("oldlace", ColorT(253, 245, 230)) - ("olive", ColorT(128, 128, 0)) - ("olivedrab", ColorT(107, 142, 35)) - ("orange", ColorT(255, 165, 0)) - ("orangered", ColorT(255, 69, 0)) - ("orchid", ColorT(218, 112, 214)) - ("palegoldenrod", ColorT(238, 232, 170)) - ("palegreen", ColorT(152, 251, 152)) - ("paleturquoise", ColorT(175, 238, 238)) - ("palevioletred", ColorT(219, 112, 147)) - ("papayawhip", ColorT(255, 239, 213)) - ("peachpuff", ColorT(255, 218, 185)) - ("peru", ColorT(205, 133, 63)) - ("pink", ColorT(255, 192, 203)) - ("plum", ColorT(221, 160, 221)) - ("powderblue", ColorT(176, 224, 230)) - ("purple", ColorT(128, 0, 128)) - ("red", ColorT(255, 0, 0)) - ("rosybrown", ColorT(188, 143, 143)) - ("royalblue", ColorT(65, 105, 225)) - ("saddlebrown", ColorT(139, 69, 19)) - ("salmon", ColorT(250, 128, 114)) - ("sandybrown", ColorT(244, 164, 96)) - ("seagreen", ColorT(46, 139, 87)) - ("seashell", ColorT(255, 245, 238)) - ("sienna", ColorT(160, 82, 45)) - ("silver", ColorT(192, 192, 192)) - ("skyblue", ColorT(135, 206, 235)) - ("slateblue", ColorT(106, 90, 205)) - ("slategray", ColorT(112, 128, 144)) - ("slategrey", ColorT(112, 128, 144)) - ("snow", ColorT(255, 250, 250)) - ("springgreen", ColorT(0, 255, 127)) - ("steelblue", ColorT(70, 130, 180)) - ("tan", ColorT(210, 180, 140)) - ("teal", ColorT(0, 128, 128)) - ("thistle", ColorT(216, 191, 216)) - ("tomato", ColorT(255, 99, 71)) - ("turquoise", ColorT(64, 224, 208)) - ("violet", ColorT(238, 130, 238)) - ("wheat", ColorT(245, 222, 179)) - ("white", ColorT(255, 255, 255)) - ("whitesmoke", ColorT(245, 245, 245)) - ("yellow", ColorT(255, 255, 0)) - ("yellowgreen", ColorT(154, 205, 50)) - ("transparent", ColorT(0, 0, 0, 0)) - ; - } - }; - - template - struct css_color_grammar : public grammar > - { - css_color_grammar(ActionsT& actions_) - : actions(actions_) {} - - template - struct definition - { - definition(css_color_grammar const& self) - { - hex6 = ch_p('#') >> uint6x_p[self.actions.hex6_]; - hex3 = ch_p('#') >> uint3x_p[self.actions.hex3_]; - rgb = str_p("rgb") >> '(' >> int_p [self.actions.red_] - >> ',' >> int_p [self.actions.green_] - >> ',' >> int_p [self.actions.blue_] - >> ')'; - rgba = str_p("rgba") >> '(' >> int_p [self.actions.red_] - >> ',' >> int_p [self.actions.green_] - >> ',' >> int_p [self.actions.blue_] - >> ',' >> real_p[self.actions.alpha_] - >> ')'; - rgb_percent = str_p("rgb") >> '(' >> real_p[self.actions.red_p_] >> '%' - >> ',' >> real_p[self.actions.green_p_] >> '%' - >> ',' >> real_p[self.actions.blue_p_] >> '%' - >> ')'; - rgba_percent = str_p("rgba") >> '(' >> real_p[self.actions.red_p_] >> '%' - >> ',' >> real_p[self.actions.green_p_] >> '%' - >> ',' >> real_p[self.actions.blue_p_] >> '%' - >> ',' >> real_p[self.actions.alpha_] - >> ')'; - css_color = named_colors_p[self.actions.named_] | hex6 | hex3 | rgb_percent | rgba_percent | rgb | rgba; - } - boost::spirit::rule rgb; - boost::spirit::rule rgba; - boost::spirit::rule rgb_percent; - boost::spirit::rule rgba_percent; - boost::spirit::rule hex6; - boost::spirit::rule hex3; - boost::spirit::rule css_color; - boost::spirit::rule const& start() const - { - return css_color; - } - int_parser int_p; - uint_parser uint6x_p; - uint_parser uint3x_p; - real_parser > real_p; - named_colors named_colors_p; - - }; - ActionsT& actions; - }; - - template - struct named_color_action - { - named_color_action(ColorT& c) - : c_(c) {} - - void operator() (ColorT const&c) const - { - c_=c; - } - ColorT& c_; - }; - - template - struct hex6_action - { - hex6_action(ColorT& c) - : c_(c) {} - - void operator () (unsigned int hex) const - { - unsigned r = (hex >> 16) & 0xff; - unsigned g = (hex >> 8) & 0xff; - unsigned b = hex & 0xff; - c_.set_red(r); - c_.set_green(g); - c_.set_blue(b); - } - ColorT& c_; - }; - - template - struct hex3_action - { - hex3_action(ColorT& c) - : c_(c) {} - - void operator () (unsigned int hex) const - { - unsigned int r = (hex >> 8) & 0xf; - unsigned int g = (hex >> 4) & 0xf; - unsigned int b = hex & 0xf; - c_.set_red( r | r << 4); - c_.set_green(g | g << 4); - c_.set_blue(b | b << 4); - } - ColorT& c_; - }; - - template - struct red_action - { - red_action(ColorT& c) - : c_(c) {} - - void operator () (int r) const - { - c_.set_red(clip_int<0,255>(r)); - } - ColorT& c_; - }; - - template - struct green_action - { - green_action(ColorT& c) - : c_(c) {} - - void operator () (int g) const - { - c_.set_green(clip_int<0,255>(g)); - } - ColorT& c_; - }; - - template - struct blue_action - { - blue_action(ColorT& c) - : c_(c) {} - - void operator () (int b) const - { - c_.set_blue(clip_int<0,255>(b)); - } - ColorT& c_; - }; - - - template - struct alpha_action - { - alpha_action(ColorT& c) - : c_(c) {} - - void operator () (double a) const - { - if (a < 0.0) a = 0.0; - if (a > 1.0) a = 1.0; - c_.set_alpha(unsigned(a * 255.0 + 0.5)); - } - - ColorT& c_; - }; - - - template - struct red_action_p - { - red_action_p(ColorT& c) - : c_(c) {} - - void operator () (double r) const - { - c_.set_red(clip_int<0,255>(int((255.0 * r)/100.0 + 0.5))); - } - ColorT& c_; - }; - - template - struct green_action_p - { - green_action_p(ColorT& c) - : c_(c) {} - - void operator () (double g) const - { - c_.set_green(clip_int<0,255>(int((255.0 * g)/100.0 + 0.5))); - } - ColorT& c_; - }; - - template - struct blue_action_p - { - blue_action_p(ColorT& c) - : c_(c) {} - - void operator () (double b) const - { - c_.set_blue(clip_int<0,255>(int((255.0 * b)/100.0 + 0.5))); - } - ColorT& c_; - }; - - - template - struct actions - { - typedef ColorT color_type; - actions(ColorT& c) - : - named_(c), - hex6_(c), - hex3_(c), - red_(c), - green_(c), - blue_(c), - alpha_(c), - red_p_(c), - green_p_(c), - blue_p_(c) - { - c.set_alpha (255); - } - - named_color_action named_; - hex6_action hex6_; - hex3_action hex3_; - red_action red_; - green_action green_; - blue_action blue_; - alpha_action alpha_; - red_action_p red_p_; - green_action_p green_p_; - blue_action_p blue_p_; - }; -} - -#endif //CSS_COLOR_PARSER_HPP diff --git a/include/mapnik/ctrans.hpp b/include/mapnik/ctrans.hpp index 7ec2f662c..fed05118b 100644 --- a/include/mapnik/ctrans.hpp +++ b/include/mapnik/ctrans.hpp @@ -27,7 +27,7 @@ #include -#include +#include #include #include @@ -130,11 +130,11 @@ namespace mapnik { int height_; double sx_; double sy_; - Envelope extent_; + box2d extent_; double offset_x_; double offset_y_; public: - CoordTransform(int width,int height,const Envelope& extent, + CoordTransform(int width,int height,const box2d& extent, double offset_x = 0, double offset_y = 0) :width_(width),height_(height),extent_(extent),offset_x_(offset_x),offset_y_(offset_y) { @@ -186,7 +186,7 @@ namespace mapnik { return c; } - inline Envelope forward(const Envelope& e) const + inline box2d forward(const box2d& e) const { double x0 = e.minx(); double y0 = e.miny(); @@ -194,10 +194,10 @@ namespace mapnik { double y1 = e.maxy(); forward(&x0,&y0); forward(&x1,&y1); - return Envelope(x0,y0,x1,y1); + return box2d(x0,y0,x1,y1); } - inline Envelope backward(const Envelope& e) const + inline box2d backward(const box2d& e) const { double x0 = e.minx(); double y0 = e.miny(); @@ -205,7 +205,7 @@ namespace mapnik { double y1 = e.maxy(); backward(&x0,&y0); backward(&x1,&y1); - return Envelope(x0,y0,x1,y1); + return box2d(x0,y0,x1,y1); } inline CoordinateArray& forward(CoordinateArray& coords) const @@ -225,7 +225,7 @@ namespace mapnik { } return coords; } - inline Envelope const& extent() const + inline box2d const& extent() const { return extent_; } diff --git a/include/mapnik/datasource.hpp b/include/mapnik/datasource.hpp index 2c222f8bf..5eac5c9eb 100644 --- a/include/mapnik/datasource.hpp +++ b/include/mapnik/datasource.hpp @@ -95,7 +95,7 @@ namespace mapnik { virtual featureset_ptr features(const query& q) const=0; virtual featureset_ptr features_at_point(coord2d const& pt) const=0; - virtual Envelope envelope() const=0; + virtual box2d envelope() const=0; virtual layer_descriptor get_descriptor() const=0; virtual ~datasource() {}; protected: diff --git a/include/mapnik/expression.hpp b/include/mapnik/expression.hpp deleted file mode 100644 index d44068571..000000000 --- a/include/mapnik/expression.hpp +++ /dev/null @@ -1,132 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2006 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 - * - *****************************************************************************/ - -//$Id$ - -#ifndef EXPRESSION_HPP -#define EXPRESSION_HPP - -#include -#include - -namespace mapnik { - template class filter_visitor; - template - class expression - { - public: - virtual value get_value(FeatureT const& feature) const=0; - virtual void accept(filter_visitor& v)=0; - virtual expression* clone() const=0; - virtual std::string to_string() const=0; - virtual ~expression() {} - }; - - template - class literal : public expression - { - public: - literal(bool val) - : expression(), - value_(val) {} - literal(int val) - : expression(), - value_(val) {} - literal(double val) - : expression(), - value_(val) {} - literal(UnicodeString const& val) - : expression(), - value_(val) {} - literal(literal const& other) - : expression(), - value_(other.value_) {} - - value get_value(FeatureT const& /*feature*/) const - { - return value_; - } - - void accept(filter_visitor& v) - { - v.visit(*this); - } - - expression* clone() const - { - return new literal(*this); - } - - std::string to_string() const - { - return value_.to_expression_string(); - } - ~literal() {} - private: - value value_; - }; - - - template - class property : public expression - { - public: - property(std::string const& name) - : expression(), - name_(name) - {} - - property(property const& other) - : expression(), - name_(other.name_) - {} - - value get_value(FeatureT const& feature) const - { - return feature[name_]; - } - void accept(filter_visitor& v) - { - v.visit(*this); - } - expression* clone() const - { - return new property(*this); - } - std::string const& name() const - { - return name_; - } - - std::string to_string() const - { - return "["+name_+"]"; - } - - ~property() {} - - private: - std::string name_; - }; -} - -#endif //EXPRESSION_HPP diff --git a/include/mapnik/expression_evaluator.hpp b/include/mapnik/expression_evaluator.hpp new file mode 100644 index 000000000..6e1f18845 --- /dev/null +++ b/include/mapnik/expression_evaluator.hpp @@ -0,0 +1,93 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2009 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 + * + *****************************************************************************/ + +//$Id$ + +#ifndef MAPNIK_EXPRESSION_EVALUATOR_HPP +#define MAPNIK_EXPRESSION_EVALUATOR_HPP + +// boost +#include +#include + +namespace mapnik +{ +template +struct evaluate : boost::static_visitor +{ + typedef T0 feature_type; + typedef T1 value_type; + + explicit evaluate(feature_type const& f) + : feature_(f) {} + + value_type operator() (value_type x) const { return x; } + value_type operator() (attribute const& attr) const + { + return attr.value(feature_); + } + + + value_type operator() (binary_node const & x) const + { + return (boost::apply_visitor(evaluate(feature_),x.left).to_bool()) + && (boost::apply_visitor(evaluate(feature_),x.right).to_bool()); + } + + value_type operator() (binary_node const & x) const + { + return (boost::apply_visitor(evaluate(feature_),x.left).to_bool()) + || (boost::apply_visitor(evaluate(feature_),x.right).to_bool()); + } + + template + value_type operator() (binary_node const& x) const + { + typename make_op::type operation; + return operation(boost::apply_visitor(evaluate(feature_),x.left), + boost::apply_visitor(evaluate(feature_),x.right)); + } + + template + value_type operator() (unary_node const& x) const + { + return ! (boost::apply_visitor(evaluate(feature_),x.expr).to_bool()); + } + + value_type operator() (regex_match_node const& x) const + { + value_type v = boost::apply_visitor(evaluate(feature_),x.expr); + return boost::u32regex_match(v.to_unicode(),x.pattern); + } + + value_type operator() (regex_replace_node const& x) const + { + value_type v = boost::apply_visitor(evaluate(feature_),x.expr); + return boost::u32regex_replace(v.to_unicode(),x.pattern,x.format); + } + + feature_type const& feature_; +}; + +} + +#endif //MAPNIK_EXPRESSION_EVALUATOR_HPP diff --git a/include/mapnik/expression_grammar.hpp b/include/mapnik/expression_grammar.hpp new file mode 100644 index 000000000..b7632c74f --- /dev/null +++ b/include/mapnik/expression_grammar.hpp @@ -0,0 +1,244 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2009 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 + * + *****************************************************************************/ + +//$Id$ + +#ifndef MAPNIK_EXPRESSIONS_GRAMMAR_HPP +#define MAPNIK_EXPRESSIONS_GRAMMAR_HPP + +// mapnik +#include +#include + +// boost + +#include +#include +#include +//spirit2 +#include +#include +//fusion +#include +//phoenix +#include +#include +#include +#include +#include +#include + +namespace mapnik +{ + +namespace qi = boost::spirit::qi; +namespace standard_wide = boost::spirit::standard_wide; +using standard_wide::space_type; + +struct unicode_impl +{ + template + struct result + { + typedef UnicodeString type; + }; + + explicit unicode_impl(mapnik::transcoder const& tr) + : tr_(tr) {} + + UnicodeString operator()(std::string const& str) const + { + return tr_.transcode(str.c_str()); + } + + mapnik::transcoder const& tr_; +}; + +struct regex_match_impl +{ + template + struct result + { + typedef expr_node type; + }; + + explicit regex_match_impl(mapnik::transcoder const& tr) + : tr_(tr) {} + + template + expr_node operator() (T0 & node, T1 const& pattern) const + { + return regex_match_node(node,tr_.transcode(pattern.c_str())); + } + + mapnik::transcoder const& tr_; +}; + +struct regex_replace_impl +{ + template + struct result + { + typedef expr_node type; + }; + + explicit regex_replace_impl(mapnik::transcoder const& tr) + : tr_(tr) {} + + template + expr_node operator() (T0 & node, T1 const& pattern, T2 const& format) const + { + return regex_replace_node(node,tr_.transcode(pattern.c_str()),tr_.transcode(format.c_str())); + } + + mapnik::transcoder const& tr_; +}; + +template +struct expression_grammar : qi::grammar +{ + typedef qi::rule rule_type; + + explicit expression_grammar(mapnik::transcoder const& tr) + : expression_grammar::base_type(expr), + unicode_(unicode_impl(tr)), + regex_match_(regex_match_impl(tr)), + regex_replace_(regex_replace_impl(tr)) + { + using boost::phoenix::construct; + using qi::_1; + using qi::_a; + using qi::_b; + using qi::_r1; + using qi::lexeme; + using qi::_val; + using qi::lit; + using qi::int_; + using qi::double_; + using standard_wide::char_; + + expr = logical_expr.alias(); + + logical_expr = not_expr [_val = _1] + >> + *( ( ( lit("and") | lit("&&")) >> not_expr [_val && _1] ) + | (( lit("or") | lit("||")) >> not_expr [_val || _1]) + ) + ; + + not_expr = + cond_expr [_val = _1 ] + | ((lit("not") | lit('!')) >> cond_expr [ _val = !_1 ]) + ; + + cond_expr = equality_expr [_val = _1] | additive_expr [_val = _1] + ; + + equality_expr = + relational_expr [_val = _1] + >> *( ( (lit("=") | lit("eq")) >> relational_expr [_val == _1]) + | (( lit("!=") | lit("<>") | lit("neq") ) >> relational_expr [_val != _1]) + ) + ; + + regex_match_expr = lit(".match") + >> lit('(') + >> lit('\'') + >> ustring [_val = _1] + >> lit('\'') + >> lit(')') + ; + + regex_replace_expr = + lit(".replace") + >> lit('(') + >> lit('\'') + >> ustring [_a = _1] + >> lit('\'') >> lit(',') + >> lit('\'') + >> ustring [_b = _1] + >> lit('\'') + >> lit(')') [_val = regex_replace_(_r1,_a,_b)] + ; + + relational_expr = additive_expr[_val = _1] + >> + *( ( (lit("<=") | lit("le") ) >> additive_expr [ _val <= _1 ]) + | ( (lit('<') | lit("lt") ) >> additive_expr [ _val < _1 ]) + | ( (lit(">=") | lit("ge") ) >> additive_expr [ _val >= _1 ]) + | ( (lit('>') | lit("gt") ) >> additive_expr [ _val > _1 ]) + ) + ; + additive_expr = multiplicative_expr [_val = _1] + >> * ( '+' >> multiplicative_expr[_val += _1] + | '-' >> multiplicative_expr[_val -= _1] + ) + ; + + multiplicative_expr = primary_expr [_val = _1] + >> *( '*' >> primary_expr [_val *= _1] + | '/' >> primary_expr [_val /= _1] + | '%' >> primary_expr [_val %= _1] + | regex_match_expr[_val = regex_match_(_val, _1)] + | regex_replace_expr(_val) [_val = _1] + ) + ; + + + primary_expr = strict_double [_val = _1] + | int_ [_val = _1] + | lit("true") [_val = true] + | lit("false") [_val = false] + | '\'' >> ustring [_val = unicode_(_1) ] >> '\'' + | '[' >> attr [_val = construct( _1 ) ] >> ']' + | '(' >> expr [_val = _1 ] >> ')' + ; + + attr %= +(char_ - ']'); + + ustring %= lexeme[*(char_-'\'')]; + + } + + qi::real_parser > strict_double; + boost::phoenix::function unicode_; + boost::phoenix::function regex_match_; + boost::phoenix::function regex_replace_; + // + rule_type expr; + rule_type equality_expr; + rule_type cond_expr; + rule_type relational_expr; + rule_type logical_expr; + rule_type additive_expr; + rule_type multiplicative_expr; + rule_type not_expr; + rule_type primary_expr; + qi::rule regex_match_expr; + qi::rule, space_type> regex_replace_expr; + qi::rule attr; + qi::rule ustring; +}; + +}; + +#endif // MAPNIK_EXPRESSIONS_GRAMMAR_HPP diff --git a/include/mapnik/expression_node.hpp b/include/mapnik/expression_node.hpp new file mode 100644 index 000000000..b12219b3e --- /dev/null +++ b/include/mapnik/expression_node.hpp @@ -0,0 +1,353 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2009 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_EXPRESSION_NODE_HPP +#define MAPNIK_EXPRESSION_NODE_HPP + +// mapnik +#include +// boost +#include +#include +#include +#include +#include + +namespace mapnik +{ + +struct attribute +{ + std::string name_; + explicit attribute(std::string const& name) + : name_(name) {} + + template + V value(F const& f) const + { + return f[name_]; + } + std::string const& name() const { return name_;} +}; + + +namespace tags { +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, +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; + +typedef boost::shared_ptr expression_ptr; + +template struct make_op; +template <> struct make_op { typedef std::plus type;}; +template <> struct make_op { typedef std::minus type;}; +template <> struct make_op { typedef std::multiplies type;}; +template <> struct make_op { typedef std::divides type;}; +template <> struct make_op { typedef std::modulus type;}; +template <> struct make_op { typedef std::less type;}; +template <> struct make_op { typedef std::less_equal type;}; +template <> struct make_op { typedef std::greater type;}; +template <> struct make_op { typedef std::greater_equal type;}; +template <> struct make_op { typedef std::equal_to type;}; +template <> struct make_op { typedef std::not_equal_to type;}; +template <> struct make_op { typedef std::logical_not type;}; +template <> struct make_op { typedef std::logical_and type;}; +template <> struct make_op { typedef std::logical_or type;}; + +template +struct unary_node +{ + unary_node (expr_node const& a) + : expr(a) {} + + static const char* type() + { + return Tag::str(); + } + + expr_node expr; +}; + +template +struct binary_node +{ + binary_node(expr_node const& a, expr_node const& b) + : left(a), + right(b) {} + + static const char* type() + { + return Tag::str(); + } + expr_node left,right; +}; + +struct regex_match_node +{ + regex_match_node (expr_node const& a, UnicodeString const& ustr) + : expr(a), + pattern(boost::make_u32regex(ustr)) {} + + expr_node expr; + boost::u32regex pattern; +}; + +struct regex_replace_node +{ + regex_replace_node (expr_node const& a, UnicodeString const& ustr, UnicodeString const& f) + : expr(a), + pattern(boost::make_u32regex(ustr)), + format(f) {} + + expr_node expr; + boost::u32regex pattern; + UnicodeString format; +}; + + +struct function_call +{ + template + explicit function_call (expr_node const a, Fun f) + : expr(a), + call_(f) {} + + expr_node expr; + boost::function call_; +}; + +// ops + +inline expr_node & operator += ( expr_node &left ,const expr_node &right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator -= ( expr_node &left ,const expr_node &right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator *= ( expr_node &left ,const expr_node &right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator /= ( expr_node &left ,const expr_node &right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator %= ( expr_node &left ,const expr_node &right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator < ( expr_node &left, expr_node const& right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator <= ( expr_node &left, expr_node const& right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator > ( expr_node &left, expr_node const& right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator >= ( expr_node &left, expr_node const& right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator == ( expr_node &left, expr_node const& right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator != ( expr_node &left, expr_node const& right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator ! (expr_node & expr) +{ + return expr = unary_node(expr); +} + +inline expr_node & operator && ( expr_node &left, expr_node const& right) +{ + return left = binary_node(left,right); +} + +inline expr_node & operator || ( expr_node &left, expr_node const& right) +{ + return left = binary_node(left,right); +} + +} + + +#endif //MAPNIK_EXPRESSION_NODE_HPP diff --git a/include/mapnik/filter_visitor.hpp b/include/mapnik/expression_string.hpp similarity index 59% rename from include/mapnik/filter_visitor.hpp rename to include/mapnik/expression_string.hpp index 015cf0ede..e55ebbf53 100644 --- a/include/mapnik/filter_visitor.hpp +++ b/include/mapnik/expression_string.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * Copyright (C) 2009 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,27 +22,18 @@ //$Id$ -#ifndef FILTER_VISITOR_HPP -#define FILTER_VISITOR_HPP +#ifndef MAPNIK_EXPRESSION_STRING_HPP +#define MAPNIK_EXPRESSION_STRING_HPP -#include -#include +// mapnik +#include +#include +// stl +#include namespace mapnik { - template class filter; - template class expression; - template class expression; - template class Filter> class rule; - template - class filter_visitor - { - public: - virtual void visit(filter& filter)=0; - virtual void visit(expression&)=0; - virtual void visit(rule const& r)=0; - virtual ~filter_visitor() {} - }; +MAPNIK_DECL std::string to_expression_string(expr_node const& ); } -#endif //FILTER_VISITOR_HPP +#endif // MAPNIK_EXPRESSION_STRING_HPP diff --git a/include/mapnik/feature.hpp b/include/mapnik/feature.hpp index ea378247a..c653dfe29 100644 --- a/include/mapnik/feature.hpp +++ b/include/mapnik/feature.hpp @@ -43,130 +43,130 @@ #include namespace mapnik { - typedef boost::shared_ptr raster_ptr; - typedef boost::associative_property_map< - std::map > properties; +typedef boost::shared_ptr raster_ptr; +typedef boost::associative_property_map< +std::map > properties; - template - struct feature : public properties, - private boost::noncopyable - { - public: - typedef T1 geometry_type; - typedef T2 raster_type; - typedef std::map::value_type value_type; - typedef std::map::size_type size_type; - - private: - int id_; - boost::ptr_vector geom_cont_; - raster_type raster_; - std::map props_; - public: - typedef std::map::iterator iterator; - explicit feature(int id) - : properties(props_), - id_(id), - geom_cont_(), - raster_() {} - - //feature(int id,const geometry_type& geom) - // : properties(props_), - // id_(id), - // geom_(geom), - // raster_() {} - - int id() const - { - return id_; - } - - void add_geometry(geometry_type * geom) - { - geom_cont_.push_back(geom); - } - - unsigned num_geometries() const - { - return geom_cont_.size(); - } - - geometry_type const& get_geometry(unsigned index) const - { - return geom_cont_[index]; - } - - geometry_type& get_geometry(unsigned index) - { - return geom_cont_[index]; - } - - Envelope envelope() const - { - Envelope result; - for (unsigned i=0;i box = geom.envelope(); - result.init(box.minx(),box.miny(),box.maxx(),box.maxy()); - } - else - { - result.expand_to_include(geom.envelope()); - } - } - return result; - } - - const raster_type& get_raster() const - { - return raster_; - } - - void set_raster(raster_type const& raster) - { - raster_=raster; - } - - std::map const& props() const - { - return props_; - } - - iterator begin() const - { - return props_.begin(); - } - - iterator end() const - { - return props_.end(); - } - - std::string to_string() const - { - std::stringstream ss; - ss << "feature (" << std::endl; - for (std::map::const_iterator itr=props_.begin(); - itr != props_.end();++itr) - { - ss << " " << itr->first << ":" << itr->second << std::endl; - } - ss << ")" << std::endl; - return ss.str(); - } - }; +template +struct feature : public properties, + private boost::noncopyable +{ +public: + typedef T1 geometry_type; + typedef T2 raster_type; + typedef std::map::value_type value_type; + typedef std::map::size_type size_type; + typedef std::map::difference_type difference_type; + +private: + int id_; + boost::ptr_vector geom_cont_; + raster_type raster_; + std::map props_; +public: + typedef std::map::iterator iterator; + explicit feature(int id) + : properties(props_), + id_(id), + geom_cont_(), + raster_() {} + + int id() const + { + return id_; + } + + void add_geometry(geometry_type * geom) + { + geom_cont_.push_back(geom); + } + + unsigned num_geometries() const + { + return geom_cont_.size(); + } + + geometry_type const& get_geometry(unsigned index) const + { + return geom_cont_[index]; + } + + geometry_type& get_geometry(unsigned index) + { + return geom_cont_[index]; + } + + box2d envelope() const + { + box2d result; + for (unsigned i=0;i box = geom.envelope(); + result.init(box.minx(),box.miny(),box.maxx(),box.maxy()); + } + else + { + result.expand_to_include(geom.envelope()); + } + } + return result; + } + + const raster_type& get_raster() const + { + return raster_; + } + + void set_raster(raster_type const& raster) + { + raster_=raster; + } + + std::map const& props() const + { + return props_; + } + + std::map& props() + { + return props_; + } + + iterator begin() + { + return props_.begin(); + } + + iterator end() + { + return props_.end(); + } + + std::string to_string() const + { + std::stringstream ss; + ss << "feature (" << std::endl; + for (std::map::const_iterator itr=props_.begin(); + itr != props_.end();++itr) + { + ss << " " << itr->first << ":" << itr->second << std::endl; + } + ss << ")" << std::endl; + return ss.str(); + } +}; - typedef feature Feature; +typedef feature Feature; - inline std::ostream& operator<< (std::ostream & out,Feature const& f) - { - out << f.to_string(); - return out; - } +inline std::ostream& operator<< (std::ostream & out,Feature const& f) +{ + out << f.to_string(); + return out; +} } #endif //FEATURE_HPP diff --git a/include/mapnik/feature_style_processor.hpp b/include/mapnik/feature_style_processor.hpp index c85ffd028..05387d152 100644 --- a/include/mapnik/feature_style_processor.hpp +++ b/include/mapnik/feature_style_processor.hpp @@ -26,234 +26,229 @@ #define FEATURE_STYLE_PROCESSOR_HPP // mapnik -#include +#include #include #include #include #include +#include #include #include #include -/* #ifdef MAPNIK_DEBUG -#include +//#include #endif -*/ - //stl #include namespace mapnik { - template - class feature_style_processor - { - struct symbol_dispatch : public boost::static_visitor<> - { - symbol_dispatch (Processor & output, - Feature const& f, - proj_transform const& prj_trans) - : output_(output), - f_(f), - prj_trans_(prj_trans) {} +template +class feature_style_processor +{ + struct symbol_dispatch : public boost::static_visitor<> + { + symbol_dispatch (Processor & output, + Feature const& f, + proj_transform const& prj_trans) + : output_(output), + f_(f), + prj_trans_(prj_trans) {} - template - void operator () (T const& sym) const - { - output_.process(sym,f_,prj_trans_); - } + template + void operator () (T const& sym) const + { + output_.process(sym,f_,prj_trans_); + } - Processor & output_; - Feature const& f_; - proj_transform const& prj_trans_; - }; - public: - feature_style_processor(Map const& m) - : m_(m) {} + Processor & output_; + Feature const& f_; + proj_transform const& prj_trans_; + }; +public: + feature_style_processor(Map const& m) + : m_(m) {} - void apply() - { -/* + void apply() + { #ifdef MAPNIK_DEBUG - mapnik::wall_clock_progress_timer t(std::clog, "map rendering took: "); + //mapnik::wall_clock_progress_timer t(std::clog, "map rendering took: "); #endif -*/ - Processor & p = static_cast(*this); - p.start_map_processing(m_); + Processor & p = static_cast(*this); + p.start_map_processing(m_); - try - { - projection proj(m_.srs()); // map projection - double scale_denom = mapnik::scale_denominator(m_,proj.is_geographic()); + try + { + projection proj(m_.srs()); // map projection + double scale_denom = mapnik::scale_denominator(m_,proj.is_geographic()); #ifdef MAPNIK_DEBUG - std::clog << "scale denominator = " << scale_denom << "\n"; + std::clog << "scale denominator = " << scale_denom << "\n"; #endif - std::vector::const_iterator itr = m_.layers().begin(); - std::vector::const_iterator end = m_.layers().end(); + std::vector::const_iterator itr = m_.layers().begin(); + std::vector::const_iterator end = m_.layers().end(); - while (itr != end) - { - if (itr->isVisible(scale_denom)) - { - apply_to_layer(*itr, p, proj, scale_denom); - } - ++itr; - } - } - catch (proj_init_error& ex) - { - std::clog << "proj_init_error:" << ex.what() << "\n"; - } + while (itr != end) + { + if (itr->isVisible(scale_denom)) + { + apply_to_layer(*itr, p, proj, scale_denom); + } + ++itr; + } + } + catch (proj_init_error& ex) + { + std::clog << "proj_init_error:" << ex.what() << "\n"; + } - p.end_map_processing(m_); - } - private: - void apply_to_layer(Layer const& lay, Processor & p, - projection const& proj0,double scale_denom) - { -/* + p.end_map_processing(m_); + } +private: + void apply_to_layer(layer const& lay, Processor & p, + projection const& proj0,double scale_denom) + { #ifdef MAPNIK_DEBUG - wall_clock_progress_timer timer(clog, "end layer rendering: "); + //wall_clock_progress_timer timer(clog, "end layer rendering: "); #endif -*/ - p.start_layer_processing(lay); - boost::shared_ptr ds=lay.datasource(); - if (ds) - { - Envelope ext = m_.get_buffered_extent(); - projection proj1(lay.srs()); - proj_transform prj_trans(proj0,proj1); + p.start_layer_processing(lay); + boost::shared_ptr ds=lay.datasource(); + if (ds) + { + box2d ext = m_.get_buffered_extent(); + projection proj1(lay.srs()); + proj_transform prj_trans(proj0,proj1); - double mx0 = ext.minx(); - double my0 = ext.miny(); - double mz0 = 0.0; - double mx1 = ext.maxx(); - double my1 = ext.maxy(); - double mz1 = 0.0; + double mx0 = ext.minx(); + double my0 = ext.miny(); + double mz0 = 0.0; + double mx1 = ext.maxx(); + double my1 = ext.maxy(); + double mz1 = 0.0; - // project main map projection into layers extent - prj_trans.forward(mx0,my0,mz0); - prj_trans.forward(mx1,my1,mz1); + // project main map projection into layers extent + prj_trans.forward(mx0,my0,mz0); + prj_trans.forward(mx1,my1,mz1); - // if no intersection then nothing to do for layer - Envelope layer_ext = lay.envelope(); - if ( mx0 > layer_ext.maxx() || mx1 < layer_ext.minx() || my0 > layer_ext.maxy() || my1 < layer_ext.miny() ) - { - return; - } + // if no intersection then nothing to do for layer + box2d layer_ext = lay.envelope(); + if ( mx0 > layer_ext.maxx() || mx1 < layer_ext.minx() || my0 > layer_ext.maxy() || my1 < layer_ext.miny() ) + { + return; + } - // clip query bbox - mx0 = std::max(layer_ext.minx(),mx0); - my0 = std::max(layer_ext.miny(),my0); - mx1 = std::min(layer_ext.maxx(),mx1); - my1 = std::min(layer_ext.maxy(),my1); + // clip query bbox + mx0 = std::max(layer_ext.minx(),mx0); + my0 = std::max(layer_ext.miny(),my0); + mx1 = std::min(layer_ext.maxx(),mx1); + my1 = std::min(layer_ext.maxy(),my1); - Envelope bbox(mx0,my0,mx1,my1); + box2d bbox(mx0,my0,mx1,my1); - double resolution = m_.getWidth()/bbox.width(); - query q(bbox,resolution,scale_denom); //BBOX query + double resolution = m_.getWidth()/bbox.width(); + query q(bbox,resolution,scale_denom); //BBOX query - std::vector const& style_names = lay.styles(); - std::vector::const_iterator stylesIter = style_names.begin(); - std::vector::const_iterator stylesEnd = style_names.end(); - for (;stylesIter != stylesEnd; ++stylesIter) - { - std::set names; - attribute_collector collector(names); - std::vector if_rules; - std::vector else_rules; + std::vector const& style_names = lay.styles(); + std::vector::const_iterator stylesIter = style_names.begin(); + std::vector::const_iterator stylesEnd = style_names.end(); + for (;stylesIter != stylesEnd; ++stylesIter) + { + std::set names; + attribute_collector collector(names); + std::vector if_rules; + std::vector else_rules; - bool active_rules=false; + bool active_rules=false; - boost::optional style=m_.find_style(*stylesIter); - if (!style) continue; + boost::optional style=m_.find_style(*stylesIter); + if (!style) continue; - const std::vector& rules=(*style).get_rules(); - std::vector::const_iterator ruleIter=rules.begin(); - std::vector::const_iterator ruleEnd=rules.end(); + const std::vector& rules=(*style).get_rules(); + std::vector::const_iterator ruleIter=rules.begin(); + std::vector::const_iterator ruleEnd=rules.end(); - for (;ruleIter!=ruleEnd;++ruleIter) - { - if (ruleIter->active(scale_denom)) - { + for (;ruleIter!=ruleEnd;++ruleIter) + { + if (ruleIter->active(scale_denom)) + { active_rules=true; - ruleIter->accept(collector); - - if (ruleIter->has_else_filter()) + // collect unique attribute names + collector(*ruleIter); + if (ruleIter->has_else_filter()) { - else_rules.push_back(const_cast(&(*ruleIter))); + else_rules.push_back(const_cast(&(*ruleIter))); } else { - if_rules.push_back(const_cast(&(*ruleIter))); + if_rules.push_back(const_cast(&(*ruleIter))); } - } - } - std::set::const_iterator namesIter=names.begin(); - std::set::const_iterator namesEnd =names.end(); + } + } + std::set::const_iterator namesIter=names.begin(); + std::set::const_iterator namesEnd =names.end(); - // push all property names - for (;namesIter!=namesEnd;++namesIter) - { - q.add_property_name(*namesIter); - } - if (active_rules) - { - featureset_ptr fs=ds->features(q); - if (fs) - { + // push all property names + for (;namesIter!=namesEnd;++namesIter) + { + q.add_property_name(*namesIter); + } + if (active_rules) + { + featureset_ptr fs=ds->features(q); + if (fs) + { feature_ptr feature; while ((feature = fs->next())) { - bool do_else=true; - std::vector::const_iterator itr=if_rules.begin(); - std::vector::const_iterator end=if_rules.end(); - for (;itr != end;++itr) - { - filter_ptr const& filter=(*itr)->get_filter(); - if (filter->pass(*feature)) - { - do_else=false; - const symbolizers& symbols = (*itr)->get_symbolizers(); - symbolizers::const_iterator symIter=symbols.begin(); - symbolizers::const_iterator symEnd =symbols.end(); - for (;symIter != symEnd;++symIter) - { - boost::apply_visitor - (symbol_dispatch(p,*feature,prj_trans),*symIter); - } - } - } - if (do_else) - { - //else filter - std::vector::const_iterator itr= - else_rules.begin(); - std::vector::const_iterator end= - else_rules.end(); - for (;itr != end;++itr) - { - const symbolizers& symbols = (*itr)->get_symbolizers(); - symbolizers::const_iterator symIter= symbols.begin(); - symbolizers::const_iterator symEnd = symbols.end(); + bool do_else=true; + std::vector::const_iterator itr=if_rules.begin(); + std::vector::const_iterator end=if_rules.end(); + for (;itr != end;++itr) + { + expression_ptr const& expr=(*itr)->get_filter(); + value_type result = boost::apply_visitor(evaluate(*feature),*expr); + if (result.to_bool()) + { + do_else=false; + const rule_type::symbolizers& symbols = (*itr)->get_symbolizers(); + rule_type::symbolizers::const_iterator symIter=symbols.begin(); + rule_type::symbolizers::const_iterator symEnd =symbols.end(); + for (;symIter != symEnd;++symIter) + { + boost::apply_visitor + (symbol_dispatch(p,*feature,prj_trans),*symIter); + } + } + } + if (do_else) + { + //else filter + std::vector::const_iterator itr= + else_rules.begin(); + std::vector::const_iterator end= + else_rules.end(); + for (;itr != end;++itr) + { + const rule_type::symbolizers& symbols = (*itr)->get_symbolizers(); + rule_type::symbolizers::const_iterator symIter= symbols.begin(); + rule_type::symbolizers::const_iterator symEnd = symbols.end(); - for (;symIter!=symEnd;++symIter) - { - boost::apply_visitor - (symbol_dispatch(p,*feature,prj_trans),*symIter); - } - } - } + for (;symIter!=symEnd;++symIter) + { + boost::apply_visitor + (symbol_dispatch(p,*feature,prj_trans),*symIter); + } + } + } } - } - } - } - } - p.end_layer_processing(lay); - } - Map const& m_; - }; + } + } + } + } + p.end_layer_processing(lay); + } + Map const& m_; +}; } #endif //FEATURE_STYLE_PROCESSOR_HPP diff --git a/include/mapnik/filter.hpp b/include/mapnik/filter.hpp deleted file mode 100644 index 8005ac2e8..000000000 --- a/include/mapnik/filter.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2006 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 - * - *****************************************************************************/ - -//$Id$ - -#ifndef FILTER_HPP -#define FILTER_HPP - -#include -#include - -namespace mapnik -{ - template class filter_visitor; - template - class MAPNIK_DECL filter - { - public: - virtual bool pass(const FeatureT& feature) const=0; - virtual filter* clone() const=0; - virtual void accept(filter_visitor& v) = 0; - virtual std::string to_string() const=0; - virtual ~filter() {} - }; - - typedef boost::shared_ptr > filter_ptr; - - template - class all_filter : public filter - { - public: - bool pass (const FeatureT&) const - { - return true; - } - - filter* clone() const - { - return new all_filter; - } - std::string to_string() const - { - return "true"; - } - void accept(filter_visitor&) {} - virtual ~all_filter() {} - }; - - template - class none_filter : public filter - { - public: - bool pass (const FeatureT&) const - { - return false; - } - - filter* clone() const - { - return new none_filter; - } - std::string to_string() const - { - return "false"; - } - void accept(filter_visitor&) {} - virtual ~none_filter() {} - }; -} - -#endif //FILTER_HPP diff --git a/include/mapnik/filter_expression.hpp b/include/mapnik/filter_expression.hpp deleted file mode 100644 index 9d4a8a5b6..000000000 --- a/include/mapnik/filter_expression.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2006 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 - * - *****************************************************************************/ - -//$Id$ - -#ifndef FILTER_TO_STRING_HPP -#define FILTER_TO_STRING_HPP - -// mapnik -#include -#include -// stl -#include - -namespace mapnik -{ - template - class filter_to_string : public filter_visitor - { - private: - std::string text_; - public: - filter_to_string() {} - void visit(filter& /*filter*/) - { - //not interested - } - void visit(expression& exp) - { - property* pf; - if ((pf = dynamic_cast*>(&exp))) - { - names_.insert(pf->name()); - } - } - std::string const& text() const - { - return text_; - } - - virtual ~filter_to_string() {} - private: - filter_to_string(filter_to_string const&); - filter_to_string& operator=(filter_to_string const&); - }; -} - -#endif //FILTER_TO_STRING diff --git a/include/mapnik/filter_factory.hpp b/include/mapnik/filter_factory.hpp index c35534c40..8b729363a 100644 --- a/include/mapnik/filter_factory.hpp +++ b/include/mapnik/filter_factory.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * Copyright (C) 2006-2009 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,51 +22,18 @@ //$Id$ -#ifndef FILTER_FACTORY_HPP -#define FILTER_FACTORY_HPP +#ifndef MAPNIK_FILTER_FACTORY_HPP +#define MAPNIK_FILTER_FACTORY_HPP -#include -#include -#include +#include +#include namespace mapnik { - using std::string; - - template - class MAPNIK_DECL filter_factory - { - public: - static filter_ptr compile(string const& str,transcoder const& tr) - { - stack > > filters; - stack > > exps; - filter_grammar grammar(filters,exps,tr); - parse_info info = parse(str.begin(), str.end(), grammar, space_p); - if ( !info.full) - { - std::ostringstream os; - os << "Failed to parse filter expression:\n" - << str << "\nParsing aborted at '" << *info.stop << "'"; - - throw config_error( os.str() ); - } - - if ( ! filters.empty()) - { - return filters.top(); - } - else - { - // XXX: do we ever get here? [DS] - return filter_ptr(new none_filter()); - } - } - }; - - MAPNIK_DECL filter_ptr create_filter (std::string const& wkt, std::string const& encoding); - MAPNIK_DECL filter_ptr create_filter (std::string const& wkt); + +MAPNIK_DECL expression_ptr parse_expression (std::string const& wkt, std::string const& encoding); +MAPNIK_DECL expression_ptr parse_expression (std::string const& wkt); } -#endif //FILTER_FACTORY_HPP +#endif //MAPNIK_FILTER_FACTORY_HPP diff --git a/include/mapnik/filter_parser.hpp b/include/mapnik/filter_parser.hpp deleted file mode 100644 index f74f9de1b..000000000 --- a/include/mapnik/filter_parser.hpp +++ /dev/null @@ -1,548 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2006 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 - * - *****************************************************************************/ - - -//$Id$ - -#ifndef FILTER_PARSER_HPP -#define FILTER_PARSER_HPP -// mapnik -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// boost - -// XML Debugging output -#ifdef MAPNIK_XML_DEBUG -#define BOOST_SPIRIT_DEBUG -#endif - -#include -#include - -#if BOOST_VERSION < 103800 - #include - #include - #include - #include - #include -#else - #define BOOST_SPIRIT_USE_OLD_NAMESPACE - #include - #include - #include - #include - #include -#endif - -// stl -#include -#include - -using namespace boost::spirit; -using boost::shared_ptr; - -namespace mapnik -{ - using std::string; - using std::clog; - using std::stack; - - template - struct push_boolean - { - push_boolean(stack > >& exprs) - : exprs_(exprs) {} - - void operator() (std::string const& val) const - { - if (val == "true") - exprs_.push(shared_ptr > - ( new literal(true))); - else if (val == "false") - exprs_.push(shared_ptr > - ( new literal(false))); - } - stack > >& exprs_; - }; - - template - struct push_integer - { - push_integer(stack > >& exprs) - : exprs_(exprs) {} - - void operator() (int val) const - { - exprs_.push(shared_ptr > - ( new literal(val))); - } - stack > >& exprs_; - }; - - template - struct push_real - { - push_real(stack > >& exprs) - : exprs_(exprs) {} - void operator() (double val) const - { - exprs_.push(shared_ptr >(new literal(val))); - } - stack > >& exprs_; - }; - - template - struct push_string - { - push_string(stack > >& exprs, transcoder const& tr) - : exprs_(exprs), - tr_(tr) {} - - template - void operator() (Iter start,Iter end) const - { - UnicodeString unicode = tr_.transcode(std::string(start,end).c_str()); - exprs_.push(shared_ptr >(new literal(unicode))); - } - stack > >& exprs_; - transcoder const& tr_; - }; - - template - struct push_property - { - push_property(stack > >& exprs) - : exprs_(exprs) {} - - template - void operator() (Iter start,Iter end) const - { - string str(start,end); - exprs_.push(shared_ptr >(new property(str))); - } - stack > >& exprs_; - }; - - template - struct compose_expression - { - compose_expression(stack > >& exprs) - : exprs_(exprs) {} - - template - void operator() (Iter,Iter) const - { - if (exprs_.size()>=2) - { - shared_ptr > right = exprs_.top(); - exprs_.pop(); - shared_ptr > left = exprs_.top(); - exprs_.pop(); - if (left && right) - { - exprs_.push(shared_ptr > - (new mapnik::math_expr_b(*left,*right))); - } - } - } - stack > >& exprs_; - }; - - template - struct compose_regex - { - compose_regex(stack > >& filters, - stack > >& exprs) - : filters_(filters),exprs_(exprs) {} - - template - void operator() (Iter start,Iter end) const - { - if (exprs_.size()>=1) - { - shared_ptr > exp = exprs_.top(); - exprs_.pop(); - if (exp) - { - std::string pattern(start,end); - try - { - filters_.push(shared_ptr > - (new regex_filter(*exp,pattern))); - } - catch (...)//boost::regex_error& ex) - { - clog<<"error\n";//ex.what()<<"\n"; - } - - } - } - } - stack > >& filters_; - stack > >& exprs_; - }; - - - template - struct compose_filter - { - compose_filter(stack > >& filters, - stack > >& exprs) - : filters_(filters),exprs_(exprs) {} - - template - void operator() (Iter,Iter) const - { - if (exprs_.size()>=2) - { - shared_ptr > right = exprs_.top(); - exprs_.pop(); - shared_ptr > left = exprs_.top(); - exprs_.pop(); - if (left && right) - { - filters_.push(shared_ptr >(new compare_filter(*left,*right))); - } - } - } - stack > >& filters_; - stack > >& exprs_; - }; - - template - struct compose_boolean_filter - { - compose_boolean_filter(stack > >& filters, - stack > >& exprs) - : filters_(filters),exprs_(exprs) {} - - template - void operator() (Iter,Iter) const - { - if (exprs_.size()>=1) - { - shared_ptr > exp = exprs_.top(); - exprs_.pop(); - if (exp) - { - filters_.push(shared_ptr >(new boolean_filter(*exp))); - } - } - } - stack > >& filters_; - stack > >& exprs_; - }; - - template - struct compose_and_filter - { - compose_and_filter(stack > >& filters) - : filters_(filters) {} - - template - void operator() (Iter,Iter) const - { - if (filters_.size()>=2) - { - shared_ptr > right = filters_.top(); - filters_.pop(); - shared_ptr > left = filters_.top(); - filters_.pop(); - if (left && right) - { - filters_.push(shared_ptr > - (new logical_and(*left,*right))); - } - } - } - stack > >& filters_; - }; - - template - struct compose_or_filter - { - compose_or_filter(stack > >& filters) - : filters_(filters) {} - - template - void operator() (Iter,Iter) const - { - if (filters_.size()>=2) - { - shared_ptr > right = filters_.top(); - filters_.pop(); - shared_ptr > left = filters_.top(); - filters_.pop(); - if (left && right) - { - filters_.push(shared_ptr > - (new logical_or(*left,*right))); - } - } - } - stack > >& filters_; - }; - - template - struct compose_not_filter - { - compose_not_filter(stack > >& filters) - : filters_(filters) {} - - template - void operator() (Iter,Iter) const - { - if (filters_.size()>=1) - { - shared_ptr > filter_ = filters_.top(); - filters_.pop(); - if (filter_) - { - filters_.push(shared_ptr >(new logical_not(*filter_))); - } - } - } - stack > >& filters_; - }; - - template - struct filter_grammar : public grammar > - { - filter_grammar(stack > >& filters_, - stack > >& exprs_, - transcoder const& tr_) - : filters(filters_), - exprs(exprs_), - tr(tr_) {} - - template - struct definition - { - definition(filter_grammar const& self) - { - typedef boost::spirit::chset chset_t; - - func1_op = "sqrt","sin","cos"; - func2_op = "min","max"; - spatial_op = "Equals","Disjoint","Touches","Within","Overlaps", - "Crosses","Intersects","Contains","DWithin","Beyond","BBOX"; - boolean_const = "true","false"; - - chset_t BaseChar (L"\x41-\x5A\x61-\x7A\xC0-\xD6\xD8-\xF6\xF8-\xFF\x100-\x131\x134-\x13E" - L"\x141-\x148\x14A-\x17E\x180-\x1C3\x1CD-\x1F0\x1F4-\x1F5\x1FA-\x217" - L"\x250-\x2A8\x2BB-\x2C1\x386\x388-\x38A\x38C\x38E-\x3A1\x3A3-\x3CE" - L"\x3D0-\x3D6\x3DA\x3DC\x3DE\x3E0\x3E2-\x3F3\x401-\x40C\x40E-\x44F" - L"\x451-\x45C\x45E-\x481\x490-\x4C4\x4C7-\x4C8\x4CB-\x4CC\x4D0-\x4EB" - L"\x4EE-\x4F5\x4F8-\x4F9\x531-\x556\x559\x561-\x586\x5D0-\x5EA" - L"\x5F0-\x5F2\x621-\x63A\x641-\x64A\x671-\x6B7\x6BA-\x6BE\x6C0-\x6CE" - L"\x6D0-\x6D3\x6D5\x6E5-\x6E6\x905-\x939\x93D\x958-\x961\x985-\x98C" - L"\x98F-\x990\x993-\x9A8\x9AA-\x9B0\x9B2\x9B6-\x9B9\x9DC-\x9DD" - L"\x9DF-\x9E1\x9F0-\x9F1\xA05-\xA0A\xA0F-\xA10\xA13-\xA28\xA2A-\xA30" - L"\xA32-\xA33\xA35-\xA36\xA38-\xA39\xA59-\xA5C\xA5E\xA72-\xA74" - L"\xA85-\xA8B\xA8D\xA8F-\xA91\xA93-\xAA8\xAAA-\xAB0\xAB2-\xAB3" - L"\xAB5-\xAB9\xABD\xAE0\xB05-\xB0C\xB0F-\xB10\xB13-\xB28\xB2A-\xB30" - L"\xB32-\xB33\xB36-\xB39\xB3D\xB5C-\xB5D\xB5F-\xB61\xB85-\xB8A" - L"\xB8E-\xB90\xB92-\xB95\xB99-\xB9A\xB9C\xB9E-\xB9F\xBA3-\xBA4" - L"\xBA8-\xBAA\xBAE-\xBB5\xBB7-\xBB9\xC05-\xC0C\xC0E-\xC10\xC12-\xC28" - L"\xC2A-\xC33\xC35-\xC39\xC60-\xC61\xC85-\xC8C\xC8E-\xC90\xC92-\xCA8" - L"\xCAA-\xCB3\xCB5-\xCB9\xCDE\xCE0-\xCE1\xD05-\xD0C\xD0E-\xD10" - L"\xD12-\xD28\xD2A-\xD39\xD60-\xD61\xE01-\xE2E\xE30\xE32-\xE33" - L"\xE40-\xE45\xE81-\xE82\xE84\xE87-\xE88\xE8A\xE8D\xE94-\xE97" - L"\xE99-\xE9F\xEA1-\xEA3\xEA5\xEA7\xEAA-\xEAB\xEAD-\xEAE\xEB0" - L"\xEB2-\xEB3\xEBD\xEC0-\xEC4\xF40-\xF47\xF49-\xF69\x10A0-\x10C5" - L"\x10D0-\x10F6\x1100\x1102-\x1103\x1105-\x1107\x1109\x110B-\x110C" - L"\x110E-\x1112\x113C\x113E\x1140\x114C\x114E\x1150\x1154-\x1155" - L"\x1159\x115F-\x1161\x1163\x1165\x1167\x1169\x116D-\x116E" - L"\x1172-\x1173\x1175\x119E\x11A8\x11AB\x11AE-\x11AF\x11B7-\x11B8" - L"\x11BA\x11BC-\x11C2\x11EB\x11F0\x11F9\x1E00-\x1E9B\x1EA0-\x1EF9" - L"\x1F00-\x1F15\x1F18-\x1F1D\x1F20-\x1F45\x1F48-\x1F4D\x1F50-\x1F57" - L"\x1F59\x1F5B\x1F5D\x1F5F-\x1F7D\x1F80-\x1FB4\x1FB6-\x1FBC\x1FBE" - L"\x1FC2-\x1FC4\x1FC6-\x1FCC\x1FD0-\x1FD3\x1FD6-\x1FDB\x1FE0-\x1FEC" - L"\x1FF2-\x1FF4\x1FF6-\x1FFC\x2126\x212A-\x212B\x212E\x2180-\x2182" - L"\x3041-\x3094\x30A1-\x30FA\x3105-\x312C\xAC00-\xD7A3"); - - chset_t Ideographic(L"\x4E00-\x9FA5\x3007\x3021-\x3029"); - chset_t Letter = BaseChar | Ideographic; - - chset_t CombiningChar(L"\x0300-\x0345\x0360-\x0361\x0483-\x0486\x0591-\x05A1\x05A3-\x05B9" - L"\x05BB-\x05BD\x05BF\x05C1-\x05C2\x05C4\x064B-\x0652\x0670" - L"\x06D6-\x06DC\x06DD-\x06DF\x06E0-\x06E4\x06E7-\x06E8\x06EA-\x06ED" - L"\x0901-\x0903\x093C\x093E-\x094C\x094D\x0951-\x0954\x0962-\x0963" - L"\x0981-\x0983\x09BC\x09BE\x09BF\x09C0-\x09C4\x09C7-\x09C8" - L"\x09CB-\x09CD\x09D7\x09E2-\x09E3\x0A02\x0A3C\x0A3E\x0A3F" - L"\x0A40-\x0A42\x0A47-\x0A48\x0A4B-\x0A4D\x0A70-\x0A71\x0A81-\x0A83" - L"\x0ABC\x0ABE-\x0AC5\x0AC7-\x0AC9\x0ACB-\x0ACD\x0B01-\x0B03\x0B3C" - L"\x0B3E-\x0B43\x0B47-\x0B48\x0B4B-\x0B4D\x0B56-\x0B57\x0B82-\x0B83" - L"\x0BBE-\x0BC2\x0BC6-\x0BC8\x0BCA-\x0BCD\x0BD7\x0C01-\x0C03" - L"\x0C3E-\x0C44\x0C46-\x0C48\x0C4A-\x0C4D\x0C55-\x0C56\x0C82-\x0C83" - L"\x0CBE-\x0CC4\x0CC6-\x0CC8\x0CCA-\x0CCD\x0CD5-\x0CD6\x0D02-\x0D03" - L"\x0D3E-\x0D43\x0D46-\x0D48\x0D4A-\x0D4D\x0D57\x0E31\x0E34-\x0E3A" - L"\x0E47-\x0E4E\x0EB1\x0EB4-\x0EB9\x0EBB-\x0EBC\x0EC8-\x0ECD" - L"\x0F18-\x0F19\x0F35\x0F37\x0F39\x0F3E\x0F3F\x0F71-\x0F84" - L"\x0F86-\x0F8B\x0F90-\x0F95\x0F97\x0F99-\x0FAD\x0FB1-\x0FB7\x0FB9" - L"\x20D0-\x20DC\x20E1\x302A-\x302F\x3099\x309A"); - - chset_t Digit(L"\x0030-\x0039\x0660-\x0669\x06F0-\x06F9\x0966-\x096F\x09E6-\x09EF" - L"\x0A66-\x0A6F\x0AE6-\x0AEF\x0B66-\x0B6F\x0BE7-\x0BEF\x0C66-\x0C6F" - L"\x0CE6-\x0CEF\x0D66-\x0D6F\x0E50-\x0E59\x0ED0-\x0ED9\x0F20-\x0F29"); - - chset_t Extender(L"\x00B7\x02D0\x02D1\x0387\x0640\x0E46\x0EC6\x3005\x3031-\x3035" - L"\x309D-\x309E\x30FC-\x30FE"); - - chset_t NameChar = - Letter - | Digit - | L'.' - | L'-' - | L'_' - | L':' - | CombiningChar - | Extender; - - boolean = boolean_const [push_boolean(self.exprs)]; - - number = strict_real_p [push_real(self.exprs)] - | int_p [push_integer(self.exprs)]; - - string_ = confix_p(L'\'',(*lex_escape_ch_p) - [push_string(self.exprs,self.tr)], - L'\''); - - property = L'[' >> ( (Letter | Digit | L'_' | L':') - >> *NameChar )[push_property(self.exprs)] >> L']'; - - literal = boolean | number | string_ | property; - - function = literal | ( func1_op >> L'('>> literal >> L')') | - (func2_op >> L'(' >> literal >> L','>> literal >> L')'); - - factor = function - | L'(' >> or_expr >> L')' - | ( L'-' >> factor) - ; - term = factor - >> *((L'*' >> factor) [compose_expression >(self.exprs)] - | (L'/' >> factor) [compose_expression >(self.exprs)] - | (L'%' >> factor) [compose_expression >(self.exprs)]); - - expression = term >> *((L'+' >> term) [compose_expression >(self.exprs)] - | (L'-' >> term) [compose_expression >(self.exprs)]); - - regex = str_p(L".match")>>L'('>>confix_p(L'\'',(*lex_escape_ch_p) - [compose_regex(self.filters,self.exprs)], - L'\'') >>L')'; - - relation = expression - >> *((L">=" >> expression) - [compose_filter >(self.filters,self.exprs)] - | (L'>' >> expression) - [compose_filter >(self.filters,self.exprs)] - | (L'<' >> expression) - [compose_filter >(self.filters,self.exprs)] - | (L"<=" >> expression) - [compose_filter >(self.filters,self.exprs)] - | regex ); - - equation = relation >> *( ( L'=' >> relation) - [compose_filter >(self.filters,self.exprs)] - | ( L"<>" >> relation) - [compose_filter >(self.filters,self.exprs)] - | ( L"!=" >> relation) - [compose_filter >(self.filters,self.exprs)]); - - cond_expr = equation | (expression)[compose_boolean_filter(self.filters,self.exprs)]; - - not_expr = cond_expr | *(str_p(L"not") >> cond_expr)[compose_not_filter(self.filters)]; - - and_expr = not_expr >> *(L"and" >> not_expr)[compose_and_filter(self.filters)]; - - or_expr = and_expr >> *(L"or" >> and_expr)[compose_or_filter(self.filters)]; - - filter_statement = or_expr >> *(space_p) >> end_p; - -#ifdef BOOST_SPIRIT_DEBUG - BOOST_SPIRIT_DEBUG_RULE( factor ); - BOOST_SPIRIT_DEBUG_RULE( term ); - BOOST_SPIRIT_DEBUG_RULE( expression ); - BOOST_SPIRIT_DEBUG_RULE( relation ); - BOOST_SPIRIT_DEBUG_RULE( equation ); - BOOST_SPIRIT_DEBUG_RULE( cond_expr ); - BOOST_SPIRIT_DEBUG_RULE( not_expr ); - BOOST_SPIRIT_DEBUG_RULE( and_expr ); - BOOST_SPIRIT_DEBUG_RULE( or_expr ); - - BOOST_SPIRIT_DEBUG_RULE( filter_statement ); - BOOST_SPIRIT_DEBUG_RULE( literal ); - BOOST_SPIRIT_DEBUG_RULE( boolean ); - BOOST_SPIRIT_DEBUG_RULE( number ); - BOOST_SPIRIT_DEBUG_RULE( string_ ); - BOOST_SPIRIT_DEBUG_RULE( property ); - BOOST_SPIRIT_DEBUG_RULE( function ); - BOOST_SPIRIT_DEBUG_RULE( regex ); -#endif - } - - boost::spirit::rule const& start() const - { - return filter_statement; - } - - boost::spirit::rule factor; - boost::spirit::rule term; - boost::spirit::rule expression; - boost::spirit::rule relation; - boost::spirit::rule equation; - boost::spirit::rule cond_expr; - boost::spirit::rule not_expr; - boost::spirit::rule and_expr; - boost::spirit::rule or_expr; - - boost::spirit::rule filter_statement; - boost::spirit::rule literal; - boost::spirit::rule boolean; - boost::spirit::rule number; - boost::spirit::rule string_; - boost::spirit::rule property; - boost::spirit::rule function; - boost::spirit::rule regex; - symbols func1_op; - symbols func2_op; - symbols spatial_op; - symbols boolean_const; - - - }; - stack > >& filters; - stack > >& exprs; - transcoder const& tr; - }; -} - -#endif //FILTER_PARSER_HPP diff --git a/include/mapnik/font_engine_freetype.hpp b/include/mapnik/font_engine_freetype.hpp index 7b2b4aa68..66fbc8952 100644 --- a/include/mapnik/font_engine_freetype.hpp +++ b/include/mapnik/font_engine_freetype.hpp @@ -358,9 +358,9 @@ namespace mapnik return face_set; } - face_set_ptr get_face_set(FontSet const& fontset) + face_set_ptr get_face_set(font_set const& fset) { - std::vector const& names = fontset.get_face_names(); + std::vector const& names = fset.get_face_names(); face_set_ptr face_set(new font_face_set); for (std::vector::const_iterator name = names.begin(); name != names.end(); ++name) { @@ -422,7 +422,7 @@ namespace mapnik opacity_=opacity; } - Envelope prepare_glyphs(text_path *path) + box2d prepare_glyphs(text_path *path) { //clear glyphs glyphs_.clear(); @@ -495,7 +495,7 @@ namespace mapnik glyphs_.push_back(new glyph_t(image)); } - return Envelope(bbox.xMin, bbox.yMin, bbox.xMax, bbox.yMax); + return box2d(bbox.xMin, bbox.yMin, bbox.xMax, bbox.yMax); } void render(double x0, double y0) diff --git a/include/mapnik/font_set.hpp b/include/mapnik/font_set.hpp index 90b56a563..e7a249f76 100644 --- a/include/mapnik/font_set.hpp +++ b/include/mapnik/font_set.hpp @@ -34,18 +34,18 @@ namespace mapnik { - class MAPNIK_DECL FontSet + class MAPNIK_DECL font_set { public: - FontSet(); - FontSet(std::string const& name); - FontSet(FontSet const& rhs); - FontSet& operator=(FontSet const& rhs); + font_set(); + font_set(std::string const& name); + font_set(font_set const& rhs); + font_set& operator=(font_set const& rhs); unsigned size() const; std::string const& get_name() const; void add_face_name(std::string); std::vector const& get_face_names() const; - ~FontSet(); + ~font_set(); private: std::string name_; std::vector face_names_; diff --git a/include/mapnik/geom_util.hpp b/include/mapnik/geom_util.hpp index 2a7330f20..d025c6115 100644 --- a/include/mapnik/geom_util.hpp +++ b/include/mapnik/geom_util.hpp @@ -25,7 +25,7 @@ #ifndef GEOM_UTIL_HPP #define GEOM_UTIL_HPP // mapnik -#include +#include #include // boost #include @@ -55,7 +55,7 @@ namespace mapnik } template - bool clip_line(T& x0,T& y0,T& x1,T& y1,Envelope const& box) + bool clip_line(T& x0,T& y0,T& x1,T& y1,box2d const& box) { double tmin=0.0; double tmax=1.0; @@ -195,11 +195,11 @@ namespace mapnik // filters struct filter_in_box { - Envelope box_; - explicit filter_in_box(const Envelope& box) + box2d box_; + explicit filter_in_box(const box2d& box) : box_(box) {} - bool pass(const Envelope& extent) const + bool pass(const box2d& extent) const { return extent.intersects(box_); } @@ -210,7 +210,7 @@ namespace mapnik coord2d pt_; explicit filter_at_point(const coord2d& pt) : pt_(pt) {} - bool pass(const Envelope& extent) const + bool pass(const box2d& extent) const { return extent.contains(pt_); } diff --git a/include/mapnik/geometry.hpp b/include/mapnik/geometry.hpp index 07661f763..8b0eac123 100644 --- a/include/mapnik/geometry.hpp +++ b/include/mapnik/geometry.hpp @@ -51,9 +51,9 @@ namespace mapnik { public: geometry () {} - Envelope envelope() const + box2d envelope() const { - Envelope result; + box2d result; double x,y; rewind(0); for (unsigned i=0;i #include #include -#include +#include #include #include @@ -45,424 +45,424 @@ namespace mapnik { - struct Multiply - { - inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, - unsigned &r1, unsigned &g1, unsigned &b1) - { - r1 = r1*r0/255; - g1 = g1*g0/255; - b1 = b1*b0/255; - } - }; - struct Multiply2 - { - inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, - unsigned &r1, unsigned &g1, unsigned &b1) - { - r1 = r1*r0/128; - if (r1>255) r1=255; - g1 = g1*g0/128; - if (g1>255) g1=255; - b1 = b1*b0/128; - if (b1>255) b1=255; - } - }; - struct Divide - { - inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, - unsigned &r1, unsigned &g1, unsigned &b1) - { - r1 = r0*256/(r1+1); - g1 = g0*256/(g1+1); - b1 = b0*256/(b1+1); - } - }; - struct Divide2 - { - inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, - unsigned &r1, unsigned &g1, unsigned &b1) - { - r1 = r0*128/(r1+1); - g1 = g0*128/(g1+1); - b1 = b0*128/(b1+1); - } - }; - struct Screen - { - inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, - unsigned &r1, unsigned &g1, unsigned &b1) - { - r1 = 255 - (255-r0)*(255-r1)/255; - g1 = 255 - (255-g0)*(255-g1)/255; - b1 = 255 - (255-b0)*(255-b1)/255; - } - }; - struct HardLight - { - inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, - unsigned &r1, unsigned &g1, unsigned &b1) - { - r1 = (r1>128)?255-(255-r0)*(255-2*(r1-128))/256:r0*r1*2/256; - g1 = (g1>128)?255-(255-g0)*(255-2*(g1-128))/256:g0*g1*2/256; - b1 = (b1>128)?255-(255-b0)*(255-2*(b1-128))/256:b0*b1*2/256; - } - }; - struct MergeGrain - { - inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, - unsigned &r1, unsigned &g1, unsigned &b1) - { - r1 = (r1+r0>128)?r1+r0-128:0; - if (r1>255) r1=255; - g1 = (g1+g0>128)?g1+g0-128:0; - if (g1>255) g1=255; - b1 = (b1+b0>128)?b1+b0-128:0; - if (b1>255) b1=255; - } - }; - struct MergeGrain2 - { - inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, - unsigned &r1, unsigned &g1, unsigned &b1) - { - r1 = (2*r1+r0>256)?2*r1+r0-256:0; - if (r1>255) r1=255; - g1 = (2*g1+g0>256)?2*g1+g0-256:0; - if (g1>255) g1=255; - b1 = (2*b1+b0>256)?2*b1+b0-256:0; - if (b1>255) b1=255; - } - }; - - class MAPNIK_DECL Image32 +struct Multiply +{ + inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, + unsigned &r1, unsigned &g1, unsigned &b1) { - private: - unsigned width_; - unsigned height_; - color background_; - ImageData32 data_; - public: - Image32(int width,int height); - Image32(Image32 const& rhs); + r1 = r1*r0/255; + g1 = g1*g0/255; + b1 = b1*b0/255; + } +}; +struct Multiply2 +{ + inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, + unsigned &r1, unsigned &g1, unsigned &b1) + { + r1 = r1*r0/128; + if (r1>255) r1=255; + g1 = g1*g0/128; + if (g1>255) g1=255; + b1 = b1*b0/128; + if (b1>255) b1=255; + } +}; +struct Divide +{ + inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, + unsigned &r1, unsigned &g1, unsigned &b1) + { + r1 = r0*256/(r1+1); + g1 = g0*256/(g1+1); + b1 = b0*256/(b1+1); + } +}; +struct Divide2 +{ + inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, + unsigned &r1, unsigned &g1, unsigned &b1) + { + r1 = r0*128/(r1+1); + g1 = g0*128/(g1+1); + b1 = b0*128/(b1+1); + } +}; +struct Screen +{ + inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, + unsigned &r1, unsigned &g1, unsigned &b1) + { + r1 = 255 - (255-r0)*(255-r1)/255; + g1 = 255 - (255-g0)*(255-g1)/255; + b1 = 255 - (255-b0)*(255-b1)/255; + } +}; +struct HardLight +{ + inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, + unsigned &r1, unsigned &g1, unsigned &b1) + { + r1 = (r1>128)?255-(255-r0)*(255-2*(r1-128))/256:r0*r1*2/256; + g1 = (g1>128)?255-(255-g0)*(255-2*(g1-128))/256:g0*g1*2/256; + b1 = (b1>128)?255-(255-b0)*(255-2*(b1-128))/256:b0*b1*2/256; + } +}; +struct MergeGrain +{ + inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, + unsigned &r1, unsigned &g1, unsigned &b1) + { + r1 = (r1+r0>128)?r1+r0-128:0; + if (r1>255) r1=255; + g1 = (g1+g0>128)?g1+g0-128:0; + if (g1>255) g1=255; + b1 = (b1+b0>128)?b1+b0-128:0; + if (b1>255) b1=255; + } +}; +struct MergeGrain2 +{ + inline static void mergeRGB(unsigned const &r0, unsigned const &g0, unsigned const &b0, + unsigned &r1, unsigned &g1, unsigned &b1) + { + r1 = (2*r1+r0>256)?2*r1+r0-256:0; + if (r1>255) r1=255; + g1 = (2*g1+g0>256)?2*g1+g0-256:0; + if (g1>255) g1=255; + b1 = (2*b1+b0>256)?2*b1+b0-256:0; + if (b1>255) b1=255; + } +}; + +class MAPNIK_DECL image_32 +{ +private: + unsigned width_; + unsigned height_; + color background_; + image_data_32 data_; +public: + image_32(int width,int height); + image_32(image_32 const& rhs); #ifdef HAVE_CAIRO - Image32(Cairo::RefPtr rhs); + image_32(Cairo::RefPtr rhs); #endif - ~Image32(); - void setBackground(color const& background); - const color& getBackground() const; - const ImageData32& data() const; + ~image_32(); + void set_background(color const& background); + const color& get_background() const; + const image_data_32& data() const; - inline ImageData32& data() - { - return data_; - } + inline image_data_32& data() + { + return data_; + } - inline const unsigned char* raw_data() const - { - return data_.getBytes(); - } + inline const unsigned char* raw_data() const + { + return data_.getBytes(); + } - inline unsigned char* raw_data() - { - return data_.getBytes(); - } + inline unsigned char* raw_data() + { + return data_.getBytes(); + } - inline image_view get_view(unsigned x,unsigned y, unsigned w,unsigned h) - { - return image_view(x,y,w,h,data_); - } + inline image_view get_view(unsigned x,unsigned y, unsigned w,unsigned h) + { + return image_view(x,y,w,h,data_); + } - private: +private: - inline bool checkBounds(unsigned x, unsigned y) const - { - return (x < width_ && y < height_); - } + inline bool checkBounds(unsigned x, unsigned y) const + { + return (x < width_ && y < height_); + } - public: - inline void setPixel(int x,int y,unsigned int rgba) - { - if (checkBounds(x,y)) - { - data_(x,y)=rgba; - } - } - inline void blendPixel(int x,int y,unsigned int rgba1,int t) - { - blendPixel2(x,y,rgba1,t,1.0); // do not change opacity - } +public: + inline void setPixel(int x,int y,unsigned int rgba) + { + if (checkBounds(x,y)) + { + data_(x,y)=rgba; + } + } + inline void blendPixel(int x,int y,unsigned int rgba1,int t) + { + blendPixel2(x,y,rgba1,t,1.0); // do not change opacity + } - inline void blendPixel2(int x,int y,unsigned int rgba1,int t,double opacity) - { - if (checkBounds(x,y)) - { - unsigned rgba0 = data_(x,y); + inline void blendPixel2(int x,int y,unsigned int rgba1,int t,double opacity) + { + if (checkBounds(x,y)) + { + unsigned rgba0 = data_(x,y); #ifdef MAPNIK_BIG_ENDIAN - unsigned a1 = (int)((rgba1 & 0xff) * opacity) & 0xff; // adjust for desired opacity - a1 = (t*a1) / 255; - if (a1 == 0) return; - unsigned r1 = (rgba1 >> 24) & 0xff; - unsigned g1 = (rgba1 >> 16 ) & 0xff; - unsigned b1 = (rgba1 >> 8) & 0xff; + unsigned a1 = (int)((rgba1 & 0xff) * opacity) & 0xff; // adjust for desired opacity + a1 = (t*a1) / 255; + if (a1 == 0) return; + unsigned r1 = (rgba1 >> 24) & 0xff; + unsigned g1 = (rgba1 >> 16 ) & 0xff; + unsigned b1 = (rgba1 >> 8) & 0xff; - unsigned a0 = (rgba0 & 0xff); - unsigned r0 = ((rgba0 >> 24 ) & 0xff) * a0; - unsigned g0 = ((rgba0 >> 16 ) & 0xff) * a0; - unsigned b0 = ((rgba0 >> 8) & 0xff) * a0; + unsigned a0 = (rgba0 & 0xff); + unsigned r0 = ((rgba0 >> 24 ) & 0xff) * a0; + unsigned g0 = ((rgba0 >> 16 ) & 0xff) * a0; + unsigned b0 = ((rgba0 >> 8) & 0xff) * a0; - a0 = ((a1 + a0) << 8) - a0*a1; + a0 = ((a1 + a0) << 8) - a0*a1; - r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0); - g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0); - b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0); - a0 = a0 >> 8; - data_(x,y)= (a0)| (b0 << 8) | (g0 << 16) | (r0 << 24) ; + r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0); + g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0); + b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0); + a0 = a0 >> 8; + data_(x,y)= (a0)| (b0 << 8) | (g0 << 16) | (r0 << 24) ; #else - unsigned a1 = (int)(((rgba1 >> 24) & 0xff) * opacity) & 0xff; // adjust for desired opacity - a1 = (t*a1) / 255; - if (a1 == 0) return; - unsigned r1 = rgba1 & 0xff; - unsigned g1 = (rgba1 >> 8 ) & 0xff; - unsigned b1 = (rgba1 >> 16) & 0xff; + unsigned a1 = (int)(((rgba1 >> 24) & 0xff) * opacity) & 0xff; // adjust for desired opacity + a1 = (t*a1) / 255; + if (a1 == 0) return; + unsigned r1 = rgba1 & 0xff; + unsigned g1 = (rgba1 >> 8 ) & 0xff; + unsigned b1 = (rgba1 >> 16) & 0xff; - unsigned a0 = (rgba0 >> 24) & 0xff; - unsigned r0 = (rgba0 & 0xff) * a0; - unsigned g0 = ((rgba0 >> 8 ) & 0xff) * a0; - unsigned b0 = ((rgba0 >> 16) & 0xff) * a0; + unsigned a0 = (rgba0 >> 24) & 0xff; + unsigned r0 = (rgba0 & 0xff) * a0; + unsigned g0 = ((rgba0 >> 8 ) & 0xff) * a0; + unsigned b0 = ((rgba0 >> 16) & 0xff) * a0; - a0 = ((a1 + a0) << 8) - a0*a1; + a0 = ((a1 + a0) << 8) - a0*a1; - r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0); - g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0); - b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0); - a0 = a0 >> 8; - data_(x,y)= (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ; + r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0); + g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0); + b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0); + a0 = a0 >> 8; + data_(x,y)= (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ; #endif - } - } + } + } - inline unsigned width() const - { - return width_; - } + inline unsigned width() const + { + return width_; + } - inline unsigned height() const - { - return height_; - } + inline unsigned height() const + { + return height_; + } - inline void set_rectangle(int x0,int y0,ImageData32 const& data) - { - Envelope ext0(0,0,width_,height_); - Envelope ext1(x0,y0,x0+data.width(),y0+data.height()); + inline void set_rectangle(int x0,int y0,image_data_32 const& data) + { + box2d ext0(0,0,width_,height_); + box2d ext1(x0,y0,x0+data.width(),y0+data.height()); - if (ext0.intersects(ext1)) - { - Envelope box = ext0.intersect(ext1); - for (int y = box.miny(); y < box.maxy(); ++y) - { - unsigned int* row_to = data_.getRow(y); - unsigned int const * row_from = data.getRow(y-y0); + if (ext0.intersects(ext1)) + { + box2d box = ext0.intersect(ext1); + for (int y = box.miny(); y < box.maxy(); ++y) + { + unsigned int* row_to = data_.getRow(y); + unsigned int const * row_from = data.getRow(y-y0); - for (int x = box.minx(); x < box.maxx(); ++x) - { + for (int x = box.minx(); x < box.maxx(); ++x) + { #ifdef MAPNIK_BIG_ENDIAN - row_to[x] = row_from[x-x0]; + row_to[x] = row_from[x-x0]; #else - if (row_from[x-x0] & 0xff000000) - { + if (row_from[x-x0] & 0xff000000) + { row_to[x] = row_from[x-x0]; - } + } #endif - } - } - } - } + } + } + } + } - inline void set_rectangle_alpha(int x0,int y0,const ImageData32& data) - { - Envelope ext0(0,0,width_,height_); - Envelope ext1(x0,y0,x0 + data.width(),y0 + data.height()); + inline void set_rectangle_alpha(int x0,int y0,const image_data_32& data) + { + box2d ext0(0,0,width_,height_); + box2d ext1(x0,y0,x0 + data.width(),y0 + data.height()); - if (ext0.intersects(ext1)) - { - Envelope box = ext0.intersect(ext1); - for (int y = box.miny(); y < box.maxy(); ++y) - { - unsigned int* row_to = data_.getRow(y); - unsigned int const * row_from = data.getRow(y-y0); - for (int x = box.minx(); x < box.maxx(); ++x) - { - unsigned rgba0 = row_to[x]; - unsigned rgba1 = row_from[x-x0]; + if (ext0.intersects(ext1)) + { + box2d box = ext0.intersect(ext1); + for (int y = box.miny(); y < box.maxy(); ++y) + { + unsigned int* row_to = data_.getRow(y); + unsigned int const * row_from = data.getRow(y-y0); + for (int x = box.minx(); x < box.maxx(); ++x) + { + unsigned rgba0 = row_to[x]; + unsigned rgba1 = row_from[x-x0]; #ifdef MAPNIK_BIG_ENDIAN - unsigned a1 = rgba1 & 0xff; - if (a1 == 0) continue; - unsigned r1 = (rgba1 >> 24) & 0xff; - unsigned g1 = (rgba1 >> 16 ) & 0xff; - unsigned b1 = (rgba1 >> 8) & 0xff; + unsigned a1 = rgba1 & 0xff; + if (a1 == 0) continue; + unsigned r1 = (rgba1 >> 24) & 0xff; + unsigned g1 = (rgba1 >> 16 ) & 0xff; + unsigned b1 = (rgba1 >> 8) & 0xff; - unsigned a0 = rgba0 & 0xff; - unsigned r0 = ((rgba0 >> 24) & 0xff) * a0; - unsigned g0 = ((rgba0 >> 16 ) & 0xff) * a0; - unsigned b0 = ((rgba0 >> 8) & 0xff) * a0; + unsigned a0 = rgba0 & 0xff; + unsigned r0 = ((rgba0 >> 24) & 0xff) * a0; + unsigned g0 = ((rgba0 >> 16 ) & 0xff) * a0; + unsigned b0 = ((rgba0 >> 8) & 0xff) * a0; - a0 = ((a1 + a0) << 8) - a0*a1; + a0 = ((a1 + a0) << 8) - a0*a1; - r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0); - g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0); - b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0); - a0 = a0 >> 8; - row_to[x] = (a0) | (b0 << 8) | (g0 << 16) | (r0 << 24) ; + r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0); + g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0); + b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0); + a0 = a0 >> 8; + row_to[x] = (a0) | (b0 << 8) | (g0 << 16) | (r0 << 24) ; #else - unsigned a1 = (rgba1 >> 24) & 0xff; - if (a1 == 0) continue; - unsigned r1 = rgba1 & 0xff; - unsigned g1 = (rgba1 >> 8 ) & 0xff; - unsigned b1 = (rgba1 >> 16) & 0xff; + unsigned a1 = (rgba1 >> 24) & 0xff; + if (a1 == 0) continue; + unsigned r1 = rgba1 & 0xff; + unsigned g1 = (rgba1 >> 8 ) & 0xff; + unsigned b1 = (rgba1 >> 16) & 0xff; - unsigned a0 = (rgba0 >> 24) & 0xff; - unsigned r0 = (rgba0 & 0xff) * a0; - unsigned g0 = ((rgba0 >> 8 ) & 0xff) * a0; - unsigned b0 = ((rgba0 >> 16) & 0xff) * a0; + unsigned a0 = (rgba0 >> 24) & 0xff; + unsigned r0 = (rgba0 & 0xff) * a0; + unsigned g0 = ((rgba0 >> 8 ) & 0xff) * a0; + unsigned b0 = ((rgba0 >> 16) & 0xff) * a0; - a0 = ((a1 + a0) << 8) - a0*a1; + a0 = ((a1 + a0) << 8) - a0*a1; - r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0); - g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0); - b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0); - a0 = a0 >> 8; - row_to[x] = (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ; + r0 = ((((r1 << 8) - r0) * a1 + (r0 << 8)) / a0); + g0 = ((((g1 << 8) - g0) * a1 + (g0 << 8)) / a0); + b0 = ((((b1 << 8) - b0) * a1 + (b0 << 8)) / a0); + a0 = a0 >> 8; + row_to[x] = (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ; #endif - } - } - } - } + } + } + } + } - inline void set_rectangle_alpha2(ImageData32 const& data, unsigned x0, unsigned y0, float opacity) - { - Envelope ext0(0,0,width_,height_); - Envelope ext1(x0,y0,x0 + data.width(),y0 + data.height()); + inline void set_rectangle_alpha2(image_data_32 const& data, unsigned x0, unsigned y0, float opacity) + { + box2d ext0(0,0,width_,height_); + box2d ext1(x0,y0,x0 + data.width(),y0 + data.height()); - if (ext0.intersects(ext1)) - { - Envelope box = ext0.intersect(ext1); - for (int y = box.miny(); y < box.maxy(); ++y) - { - unsigned int* row_to = data_.getRow(y); - unsigned int const * row_from = data.getRow(y-y0); - for (int x = box.minx(); x < box.maxx(); ++x) - { - unsigned rgba0 = row_to[x]; - unsigned rgba1 = row_from[x-x0]; + if (ext0.intersects(ext1)) + { + box2d box = ext0.intersect(ext1); + for (int y = box.miny(); y < box.maxy(); ++y) + { + unsigned int* row_to = data_.getRow(y); + unsigned int const * row_from = data.getRow(y-y0); + for (int x = box.minx(); x < box.maxx(); ++x) + { + unsigned rgba0 = row_to[x]; + unsigned rgba1 = row_from[x-x0]; #ifdef MAPNIK_BIG_ENDIAN - unsigned a1 = int( (rgba1 & 0xff) * opacity ); - if (a1 == 0) continue; - unsigned r1 = (rgba1 >> 24) & 0xff; - unsigned g1 = (rgba1 >> 16 ) & 0xff; - unsigned b1 = (rgba1 >> 8) & 0xff; + unsigned a1 = int( (rgba1 & 0xff) * opacity ); + if (a1 == 0) continue; + unsigned r1 = (rgba1 >> 24) & 0xff; + unsigned g1 = (rgba1 >> 16 ) & 0xff; + unsigned b1 = (rgba1 >> 8) & 0xff; - unsigned a0 = rgba0 & 0xff; - unsigned r0 = (rgba0 >> 24) & 0xff ; - unsigned g0 = (rgba0 >> 16 ) & 0xff; - unsigned b0 = (rgba0 >> 8) & 0xff; + unsigned a0 = rgba0 & 0xff; + unsigned r0 = (rgba0 >> 24) & 0xff ; + unsigned g0 = (rgba0 >> 16 ) & 0xff; + unsigned b0 = (rgba0 >> 8) & 0xff; - r0 = uint8_t(((r1 - r0) * a1 + (r0 << 8)) >> 8); - g0 = uint8_t(((g1 - g0) * a1 + (g0 << 8)) >> 8); - b0 = uint8_t(((b1 - b0) * a1 + (b0 << 8)) >> 8); - a0 = uint8_t((a1 + a0) - ((a1 * a0 + 255) >> 8)); + r0 = uint8_t(((r1 - r0) * a1 + (r0 << 8)) >> 8); + g0 = uint8_t(((g1 - g0) * a1 + (g0 << 8)) >> 8); + b0 = uint8_t(((b1 - b0) * a1 + (b0 << 8)) >> 8); + a0 = uint8_t((a1 + a0) - ((a1 * a0 + 255) >> 8)); - row_to[x] = (a0)| (b0 << 8) | (g0 << 16) | (r0 << 24) ; + row_to[x] = (a0)| (b0 << 8) | (g0 << 16) | (r0 << 24) ; #else - unsigned a1 = int( ((rgba1 >> 24) & 0xff) * opacity ); - if (a1 == 0) continue; - unsigned r1 = rgba1 & 0xff; - unsigned g1 = (rgba1 >> 8 ) & 0xff; - unsigned b1 = (rgba1 >> 16) & 0xff; + unsigned a1 = int( ((rgba1 >> 24) & 0xff) * opacity ); + if (a1 == 0) continue; + unsigned r1 = rgba1 & 0xff; + unsigned g1 = (rgba1 >> 8 ) & 0xff; + unsigned b1 = (rgba1 >> 16) & 0xff; - unsigned a0 = (rgba0 >> 24) & 0xff; - unsigned r0 = rgba0 & 0xff ; - unsigned g0 = (rgba0 >> 8 ) & 0xff; - unsigned b0 = (rgba0 >> 16) & 0xff; + unsigned a0 = (rgba0 >> 24) & 0xff; + unsigned r0 = rgba0 & 0xff ; + unsigned g0 = (rgba0 >> 8 ) & 0xff; + unsigned b0 = (rgba0 >> 16) & 0xff; - r0 = uint8_t(((r1 - r0) * a1 + (r0 << 8)) >> 8); - g0 = uint8_t(((g1 - g0) * a1 + (g0 << 8)) >> 8); - b0 = uint8_t(((b1 - b0) * a1 + (b0 << 8)) >> 8); - a0 = uint8_t((a1 + a0) - ((a1 * a0 + 255) >> 8)); - - row_to[x] = (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ; + r0 = uint8_t(((r1 - r0) * a1 + (r0 << 8)) >> 8); + g0 = uint8_t(((g1 - g0) * a1 + (g0 << 8)) >> 8); + b0 = uint8_t(((b1 - b0) * a1 + (b0 << 8)) >> 8); + a0 = uint8_t((a1 + a0) - ((a1 * a0 + 255) >> 8)); + + row_to[x] = (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ; #endif - } - } - } - } + } + } + } + } - template - inline void merge_rectangle(ImageData32 const& data, unsigned x0, unsigned y0, float opacity) - { - Envelope ext0(0,0,width_,height_); - Envelope ext1(x0,y0,x0 + data.width(),y0 + data.height()); + template + inline void merge_rectangle(image_data_32 const& data, unsigned x0, unsigned y0, float opacity) + { + box2d ext0(0,0,width_,height_); + box2d ext1(x0,y0,x0 + data.width(),y0 + data.height()); - if (ext0.intersects(ext1)) - { - Envelope box = ext0.intersect(ext1); - for (int y = box.miny(); y < box.maxy(); ++y) - { - unsigned int* row_to = data_.getRow(y); - unsigned int const * row_from = data.getRow(y-y0); - for (int x = box.minx(); x < box.maxx(); ++x) - { - unsigned rgba0 = row_to[x]; - unsigned rgba1 = row_from[x-x0]; + if (ext0.intersects(ext1)) + { + box2d box = ext0.intersect(ext1); + for (int y = box.miny(); y < box.maxy(); ++y) + { + unsigned int* row_to = data_.getRow(y); + unsigned int const * row_from = data.getRow(y-y0); + for (int x = box.minx(); x < box.maxx(); ++x) + { + unsigned rgba0 = row_to[x]; + unsigned rgba1 = row_from[x-x0]; #ifdef MAPNIK_BIG_ENDIAN - unsigned a1 = int( (rgba1 & 0xff) * opacity ); - if (a1 == 0) continue; - unsigned r1 = (rgba1 >> 24)& 0xff; - unsigned g1 = (rgba1 >> 16 ) & 0xff; - unsigned b1 = (rgba1 >> 8) & 0xff; + unsigned a1 = int( (rgba1 & 0xff) * opacity ); + if (a1 == 0) continue; + unsigned r1 = (rgba1 >> 24)& 0xff; + unsigned g1 = (rgba1 >> 16 ) & 0xff; + unsigned b1 = (rgba1 >> 8) & 0xff; - unsigned a0 = rgba0 & 0xff; - unsigned r0 = (rgba0 >> 24) & 0xff ; - unsigned g0 = (rgba0 >> 16 ) & 0xff; - unsigned b0 = (rgba0 >> 8) & 0xff; + unsigned a0 = rgba0 & 0xff; + unsigned r0 = (rgba0 >> 24) & 0xff ; + unsigned g0 = (rgba0 >> 16 ) & 0xff; + unsigned b0 = (rgba0 >> 8) & 0xff; - unsigned a = (a1 * 255 + (255 - a1) * a0 + 127)/255; + unsigned a = (a1 * 255 + (255 - a1) * a0 + 127)/255; - MergeMethod::mergeRGB(r0,g0,b0,r1,g1,b1); + MergeMethod::mergeRGB(r0,g0,b0,r1,g1,b1); - r0 = (r1*a1 + (((255 - a1) * a0 + 127)/255) * r0 + 127)/a; - g0 = (g1*a1 + (((255 - a1) * a0 + 127)/255) * g0 + 127)/a; - b0 = (b1*a1 + (((255 - a1) * a0 + 127)/255) * b0 + 127)/a; + r0 = (r1*a1 + (((255 - a1) * a0 + 127)/255) * r0 + 127)/a; + g0 = (g1*a1 + (((255 - a1) * a0 + 127)/255) * g0 + 127)/a; + b0 = (b1*a1 + (((255 - a1) * a0 + 127)/255) * b0 + 127)/a; - row_to[x] = (a)| (b0 << 8) | (g0 << 16) | (r0 << 24) ; + row_to[x] = (a)| (b0 << 8) | (g0 << 16) | (r0 << 24) ; #else - unsigned a1 = int( ((rgba1 >> 24) & 0xff) * opacity ); - if (a1 == 0) continue; - unsigned r1 = rgba1 & 0xff; - unsigned g1 = (rgba1 >> 8 ) & 0xff; - unsigned b1 = (rgba1 >> 16) & 0xff; + unsigned a1 = int( ((rgba1 >> 24) & 0xff) * opacity ); + if (a1 == 0) continue; + unsigned r1 = rgba1 & 0xff; + unsigned g1 = (rgba1 >> 8 ) & 0xff; + unsigned b1 = (rgba1 >> 16) & 0xff; - unsigned a0 = (rgba0 >> 24) & 0xff; - unsigned r0 = rgba0 & 0xff ; - unsigned g0 = (rgba0 >> 8 ) & 0xff; - unsigned b0 = (rgba0 >> 16) & 0xff; + unsigned a0 = (rgba0 >> 24) & 0xff; + unsigned r0 = rgba0 & 0xff ; + unsigned g0 = (rgba0 >> 8 ) & 0xff; + unsigned b0 = (rgba0 >> 16) & 0xff; - unsigned a = (a1 * 255 + (255 - a1) * a0 + 127)/255; + unsigned a = (a1 * 255 + (255 - a1) * a0 + 127)/255; - MergeMethod::mergeRGB(r0,g0,b0,r1,g1,b1); + MergeMethod::mergeRGB(r0,g0,b0,r1,g1,b1); - r0 = (r1*a1 + (((255 - a1) * a0 + 127)/255) * r0 + 127)/a; - g0 = (g1*a1 + (((255 - a1) * a0 + 127)/255) * g0 + 127)/a; - b0 = (b1*a1 + (((255 - a1) * a0 + 127)/255) * b0 + 127)/a; + r0 = (r1*a1 + (((255 - a1) * a0 + 127)/255) * r0 + 127)/a; + g0 = (g1*a1 + (((255 - a1) * a0 + 127)/255) * g0 + 127)/a; + b0 = (b1*a1 + (((255 - a1) * a0 + 127)/255) * b0 + 127)/a; - row_to[x] = (a << 24)| (b0 << 16) | (g0 << 8) | (r0) ; + row_to[x] = (a << 24)| (b0 << 16) | (g0 << 8) | (r0) ; #endif - } - } - } - } - }; + } + } + } + } +}; } #endif //GRAPHICS_HPP diff --git a/bindings/python/mapnik_filter.cpp b/include/mapnik/image_cache.hpp similarity index 50% rename from bindings/python/mapnik_filter.cpp rename to include/mapnik/image_cache.hpp index cc5522f43..a5703b501 100644 --- a/bindings/python/mapnik_filter.cpp +++ b/include/mapnik/image_cache.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon + * Copyright (C) 2009 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,37 +19,41 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ + //$Id$ -#include +#ifndef MAPNIK_IMAGE_CACHE_HPP +#define MAPNIK_IMAGE_CACHE_HPP -#include -#include -#include -#include -#include -#include +// mapnik +#include +#include +#include -using mapnik::filter; -using mapnik::filter_ptr; -using mapnik::filter_factory; -using mapnik::Feature; -using mapnik::create_filter; +// boost +#include +#include +#include +#include +#include -filter_ptr create_filter_(std::string const& wkt) +namespace mapnik { - return create_filter(wkt,"utf8"); + +typedef boost::shared_ptr image_ptr; + +struct MAPNIK_DECL image_cache : + public singleton , + private boost::noncopyable +{ + + friend class CreateStatic; + static boost::mutex mutex_; + static boost::unordered_map cache_; + static bool insert(std::string const& key, image_ptr); + static boost::optional find(std::string const& key, bool update_cache = false); +}; + } -void export_filter() -{ - using namespace boost::python; - class_,boost::noncopyable>("Filter", - "An expression which allows " - "to select features.",no_init) - .def("passes", &filter::pass) // note: "pass" is a reserved word in Python - .def("__str__",&filter::to_string); - ; - - def("Filter",&create_filter_); -} +#endif // MAPNIK_IMAGE_CACHE_HPP diff --git a/include/mapnik/image_data.hpp b/include/mapnik/image_data.hpp index f16bb36d3..56925e2a7 100644 --- a/include/mapnik/image_data.hpp +++ b/include/mapnik/image_data.hpp @@ -135,8 +135,8 @@ namespace mapnik ImageData& operator=(const ImageData&); }; - typedef ImageData ImageData32; - typedef ImageData ImageData8; + typedef ImageData image_data_32; + typedef ImageData image_data_8; } #endif //IMAGE_DATA_HPP diff --git a/include/mapnik/image_reader.hpp b/include/mapnik/image_reader.hpp index 1d20d55b7..2e7b34e1b 100644 --- a/include/mapnik/image_reader.hpp +++ b/include/mapnik/image_reader.hpp @@ -33,33 +33,33 @@ namespace mapnik { - class ImageReaderException : public std::exception +class image_reader_exception : public std::exception +{ +private: + std::string message_; +public: + image_reader_exception(const std::string& message) + : message_(message) {} + + ~image_reader_exception() throw() {} + + virtual const char* what() const throw() { - private: - std::string message_; - public: - ImageReaderException(const std::string& message) - : message_(message) {} + return message_.c_str(); + } +}; - ~ImageReaderException() throw() {} +struct MAPNIK_DECL image_reader +{ + virtual unsigned width() const=0; + virtual unsigned height() const=0; + virtual void read(unsigned x,unsigned y,image_data_32& image)=0; + virtual ~image_reader() {} +}; - virtual const char* what() const throw() - { - return message_.c_str(); - } - }; - - struct MAPNIK_DECL ImageReader - { - virtual unsigned width() const=0; - virtual unsigned height() const=0; - virtual void read(unsigned x,unsigned y,ImageData32& image)=0; - virtual ~ImageReader() {} - }; - - bool register_image_reader(const std::string& type,ImageReader* (*)(const std::string&)); - MAPNIK_DECL ImageReader* get_image_reader(const std::string& file,const std::string& type); - MAPNIK_DECL ImageReader* get_image_reader(const std::string& file); +bool register_image_reader(const std::string& type,image_reader* (*)(const std::string&)); +MAPNIK_DECL image_reader* get_image_reader(const std::string& file,const std::string& type); +MAPNIK_DECL image_reader* get_image_reader(const std::string& file); } diff --git a/include/mapnik/image_util.hpp b/include/mapnik/image_util.hpp index 202eb3ce6..b7484a7b7 100644 --- a/include/mapnik/image_util.hpp +++ b/include/mapnik/image_util.hpp @@ -32,6 +32,8 @@ // boost #include #include +#include + // stl #include @@ -92,16 +94,17 @@ namespace mapnik { boost::algorithm::iends_with(filename,std::string(".tiff")); } - inline std::string type_from_filename(std::string const& filename) - { - if (is_png(filename)) return "png"; - if (is_jpeg(filename)) return "jpeg"; - if (is_tiff(filename)) return "tiff"; - return "unknown"; - } +inline boost::optional type_from_filename(std::string const& filename) +{ + typedef boost::optional result_type; + if (is_png(filename)) return result_type("png"); + if (is_jpeg(filename)) return result_type("jpeg"); + if (is_tiff(filename)) return result_type("tiff"); + return result_type(); +} - inline std::string guess_type( const std::string & filename ) - { +inline std::string guess_type( const std::string & filename ) +{ std::string::size_type idx = filename.find_last_of("."); if ( idx != std::string::npos ) { return filename.substr( idx + 1 ); @@ -413,42 +416,42 @@ namespace mapnik { } } - inline MAPNIK_DECL void save_to_file (Image32 const& image, + inline MAPNIK_DECL void save_to_file (image_32 const& image, std::string const& file, std::string const& type) { - save_to_file(image.data(),file,type); + save_to_file(image.data(),file,type); } - inline MAPNIK_DECL void save_to_file(Image32 const& image, + inline MAPNIK_DECL void save_to_file(image_32 const& image, std::string const& file) { - save_to_file(image.data(),file); + save_to_file(image.data(),file); } - inline MAPNIK_DECL std::string save_to_string(Image32 const& image, + inline MAPNIK_DECL std::string save_to_string(image_32 const& image, std::string const& type) { - return save_to_string(image.data(),type); + return save_to_string(image.data(),type); } #ifdef _MSC_VER - template MAPNIK_DECL void save_to_file(ImageData32 const&, + template MAPNIK_DECL void save_to_file(image_data_32 const&, std::string const&, std::string const&); - template MAPNIK_DECL void save_to_file(ImageData32 const&, + template MAPNIK_DECL void save_to_file(image_data_32 const&, std::string const&); - template MAPNIK_DECL std::string save_to_string(ImageData32 const&, + template MAPNIK_DECL std::string save_to_string(image_data_32 const&, std::string const&); - template MAPNIK_DECL void save_to_file > (image_view const&, + template MAPNIK_DECL void save_to_file > (image_view const&, std::string const&, std::string const&); - template MAPNIK_DECL void save_to_file > (image_view const&, + template MAPNIK_DECL void save_to_file > (image_view const&, std::string const&); - template MAPNIK_DECL std::string save_to_string > (image_view const&, + template MAPNIK_DECL std::string save_to_string > (image_view const&, std::string const&); #endif diff --git a/include/mapnik/label_collision_detector.hpp b/include/mapnik/label_collision_detector.hpp index cedde6c82..f04cd7540 100644 --- a/include/mapnik/label_collision_detector.hpp +++ b/include/mapnik/label_collision_detector.hpp @@ -38,9 +38,9 @@ namespace mapnik struct label_collision_detector { - typedef std::vector > label_placements; + typedef std::vector > label_placements; - bool has_plasement(Envelope const& box) + bool has_plasement(box2d const& box) { label_placements::const_iterator itr=labels_.begin(); for( ; itr !=labels_.end();++itr) @@ -66,14 +66,14 @@ namespace mapnik // quad_tree based label collision detector class label_collision_detector2 : boost::noncopyable { - typedef quad_tree > tree_t; + typedef quad_tree > tree_t; tree_t tree_; public: - explicit label_collision_detector2(Envelope const& extent) + explicit label_collision_detector2(box2d const& extent) : tree_(extent) {} - bool has_placement(Envelope const& box) + bool has_placement(box2d const& box) { tree_t::query_iterator itr = tree_.query_in_box(box); tree_t::query_iterator end = tree_.query_end(); @@ -100,14 +100,14 @@ namespace mapnik // quad_tree based label collision detector with seperate check/insert class label_collision_detector3 : boost::noncopyable { - typedef quad_tree< Envelope > tree_t; + typedef quad_tree< box2d > tree_t; tree_t tree_; public: - explicit label_collision_detector3(Envelope const& extent) + explicit label_collision_detector3(box2d const& extent) : tree_(extent) {} - bool has_placement(Envelope const& box) + bool has_placement(box2d const& box) { tree_t::query_iterator itr = tree_.query_in_box(box); tree_t::query_iterator end = tree_.query_end(); @@ -123,7 +123,7 @@ namespace mapnik return true; } - void insert(Envelope const& box) + void insert(box2d const& box) { tree_.insert(box, box); } @@ -140,24 +140,24 @@ namespace mapnik { struct label { - label(Envelope const& b) : box(b) {} - label(Envelope const& b, UnicodeString const& t) : box(b), text(t) {} + label(box2d const& b) : box(b) {} + label(box2d const& b, UnicodeString const& t) : box(b), text(t) {} - Envelope box; + box2d box; UnicodeString text; }; typedef quad_tree< label > tree_t; - Envelope extent_; + box2d extent_; tree_t tree_; public: - explicit label_collision_detector4(Envelope const& extent) + explicit label_collision_detector4(box2d const& extent) : extent_(extent), tree_(extent) {} - bool has_placement(Envelope const& box) + bool has_placement(box2d const& box) { tree_t::query_iterator itr = tree_.query_in_box(box); tree_t::query_iterator end = tree_.query_end(); @@ -173,9 +173,9 @@ namespace mapnik return true; } - bool has_placement(Envelope const& box, UnicodeString const& text, double distance) + bool has_placement(box2d const& box, UnicodeString const& text, double distance) { - Envelope bigger_box(box.minx() - distance, box.miny() - distance, box.maxx() + distance, box.maxy() + distance); + box2d bigger_box(box.minx() - distance, box.miny() - distance, box.maxx() + distance, box.maxy() + distance); tree_t::query_iterator itr = tree_.query_in_box(bigger_box); tree_t::query_iterator end = tree_.query_end(); @@ -190,9 +190,9 @@ namespace mapnik return true; } - bool has_point_placement(Envelope const& box, double distance) + bool has_point_placement(box2d const& box, double distance) { - Envelope bigger_box(box.minx() - distance, box.miny() - distance, box.maxx() + distance, box.maxy() + distance); + box2d bigger_box(box.minx() - distance, box.miny() - distance, box.maxx() + distance, box.maxy() + distance); tree_t::query_iterator itr = tree_.query_in_box(bigger_box); tree_t::query_iterator end = tree_.query_end(); @@ -207,12 +207,12 @@ namespace mapnik return true; } - void insert(Envelope const& box) + void insert(box2d const& box) { tree_.insert(label(box), box); } - void insert(Envelope const& box, UnicodeString const& text) + void insert(box2d const& box, UnicodeString const& text) { tree_.insert(label(box, text), box); } @@ -222,7 +222,7 @@ namespace mapnik tree_.clear(); } - Envelope const& extent() const + box2d const& extent() const { return extent_; } diff --git a/include/mapnik/layer.hpp b/include/mapnik/layer.hpp index 9f7787d76..e8e3417de 100644 --- a/include/mapnik/layer.hpp +++ b/include/mapnik/layer.hpp @@ -36,18 +36,18 @@ namespace mapnik /*! * @brief A Mapnik map layer. * - * Create a Layer with a named string and, optionally, an srs string either + * Create a layer with a named string and, optionally, an srs string either * with a Proj.4 epsg code ('+init=epsg:') or with a Proj.4 literal * ('+proj='). If no srs is specified it will default to * '+proj=latlong +datum=WGS84' */ - class MAPNIK_DECL Layer + class MAPNIK_DECL layer { public: - explicit Layer(std::string const& name, std::string const& srs="+proj=latlong +datum=WGS84"); - Layer(Layer const& l); - Layer& operator=(Layer const& l); - bool operator==(Layer const& other) const; + explicit layer(std::string const& name, std::string const& srs="+proj=latlong +datum=WGS84"); + layer(layer const& l); + layer& operator=(layer const& l); + bool operator==(layer const& other) const; /*! * @brief Set the name of the layer. @@ -70,12 +70,12 @@ namespace mapnik const std::string& title() const; /*! - * @brief Set the abstract of the Layer. + * @brief Set the abstract of the layer. */ void set_abstract(std::string const& abstract); /*! - * @return the abstract of the Layer. + * @return the abstract of the layer. */ const std::string& abstract() const; @@ -172,7 +172,7 @@ namespace mapnik bool clear_label_cache() const; /*! - * @brief Attach a datasource for this Layer. + * @brief Attach a datasource for this layer. * * @param ds The datasource to attach. */ @@ -186,11 +186,11 @@ namespace mapnik /*! * @return the geographic envelope/bounding box of the data in the layer. */ - Envelope envelope() const; + box2d envelope() const; - ~Layer(); + ~layer(); private: - void swap(const Layer& other); + void swap(const layer& other); std::string name_; std::string title_; diff --git a/include/mapnik/line_pattern_symbolizer.hpp b/include/mapnik/line_pattern_symbolizer.hpp index d054a3895..6f0da9516 100644 --- a/include/mapnik/line_pattern_symbolizer.hpp +++ b/include/mapnik/line_pattern_symbolizer.hpp @@ -24,7 +24,7 @@ #ifndef LINE_PATTERN_SYMBOLIZER_HPP #define LINE_PATTERN_SYMBOLIZER_HPP -#include +// mapnik #include #include @@ -33,9 +33,7 @@ namespace mapnik struct MAPNIK_DECL line_pattern_symbolizer : public symbolizer_with_image { - line_pattern_symbolizer(std::string const& file, - std::string const& type, - unsigned width,unsigned height); + line_pattern_symbolizer(path_expression_ptr file); line_pattern_symbolizer(line_pattern_symbolizer const& rhs); }; } diff --git a/include/mapnik/logical.hpp b/include/mapnik/logical.hpp deleted file mode 100644 index ebd2828fc..000000000 --- a/include/mapnik/logical.hpp +++ /dev/null @@ -1,172 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2006 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 - * - *****************************************************************************/ -//$Id$ - -#ifndef LOGICAL_HPP -#define LOGICAL_HPP - -#include - -namespace mapnik -{ - template - struct logical_and : public filter - { - logical_and(filter const& filter1, - filter const& filter2) - : filter(), - filter1_(filter1.clone()), - filter2_(filter2.clone()) {} - - logical_and(logical_and const& other) - : filter(), - filter1_(other.filter1_->clone()), - filter2_(other.filter2_->clone()) {} - - bool pass(const FeatureT& feature) const - { - return (filter1_->pass(feature) && - filter2_->pass(feature)); - } - std::string to_string() const - { - return "("+filter1_->to_string()+" and "+filter2_->to_string()+")"; - } - - filter* clone() const - { - return new logical_and(*this); - } - - void accept(filter_visitor& v) - { - filter1_->accept(v); - filter2_->accept(v); - v.visit(*this); - } - - virtual ~logical_and() - { - delete filter1_; - delete filter2_; - } - - private: - filter* filter1_; - filter* filter2_; - }; - - template - struct logical_or : public filter - { - - logical_or(const filter& filter1,const filter& filter2) - : filter(), - filter1_(filter1.clone()), - filter2_(filter2.clone()) {} - - logical_or(logical_or const& other) - : filter(), - filter1_(other.filter1_->clone()), - filter2_(other.filter2_->clone()) {} - - bool pass(const FeatureT& feature) const - { - if (filter1_->pass(feature)) - { - return true; - } - else - { - return filter2_->pass(feature); - } - } - filter* clone() const - { - return new logical_or(*this); - } - - void accept(filter_visitor& v) - { - filter1_->accept(v); - filter2_->accept(v); - v.visit(*this); - } - std::string to_string() const - { - return "("+filter1_->to_string()+" or "+filter2_->to_string()+")"; - } - virtual ~logical_or() - { - delete filter1_; - delete filter2_; - } - private: - filter* filter1_; - filter* filter2_; - }; - - template - struct logical_not : public filter - { - logical_not(filter const& _filter) - : filter(), - filter_(_filter.clone()) {} - logical_not(logical_not const& other) - : filter(), - filter_(other.filter_->clone()) {} - - int type() const - { - return filter::LOGICAL_OPS; - } - - bool pass(const FeatureT& feature) const - { - return !(filter_->pass(feature)); - } - - filter* clone() const - { - return new logical_not(*this); - } - - void accept(filter_visitor& v) - { - filter_->accept(v); - v.visit(*this); - } - std::string to_string() const - { - return "not ("+filter_->to_string()+")"; - } - - ~logical_not() - { - delete filter_; - } - private: - filter* filter_; - }; -} - -#endif //LOGICAL_HPP diff --git a/include/mapnik/map.hpp b/include/mapnik/map.hpp index 54973e2c4..dc5ef63b9 100644 --- a/include/mapnik/map.hpp +++ b/include/mapnik/map.hpp @@ -74,17 +74,17 @@ namespace mapnik int buffer_size_; boost::optional background_; std::map styles_; - std::map fontsets_; - std::vector layers_; + std::map fontsets_; + std::vector layers_; aspect_fix_mode aspectFixMode_; - Envelope currentExtent_; + box2d currentExtent_; public: typedef std::map::const_iterator const_style_iterator; typedef std::map::iterator style_iterator; - typedef std::map::const_iterator const_fontset_iterator; - typedef std::map::iterator fontset_iterator; + typedef std::map::const_iterator const_fontset_iterator; + typedef std::map::iterator fontset_iterator; /*! \brief Default constructor. * @@ -170,23 +170,23 @@ namespace mapnik * @return true If success. * @return false If failure. */ - bool insert_fontset(std::string const& name, FontSet const& fontset); + bool insert_fontset(std::string const& name, font_set const& fontset); /*! \brief Find a fontset. * @param name The name of the fontset. * @return The fontset if found. If not found return the default map fontset. */ - FontSet const& find_fontset(std::string const& name) const; + font_set const& find_fontset(std::string const& name) const; /*! \brief Get all fontsets * @return Const reference to fontsets */ - std::map const& fontsets() const; + std::map const& fontsets() const; /*! \brief Get all fontsets * @return Non-constant reference to fontsets */ - std::map & fontsets(); + std::map & fontsets(); /*! \brief Get number of all layers. */ @@ -195,34 +195,34 @@ namespace mapnik /*! \brief Add a layer to the map. * @param l The layer to add. */ - void addLayer(const Layer& l); + void addLayer(const layer& l); /*! \brief Get a layer. - * @param index Layer number. + * @param index layer number. * @return Constant layer. */ - const Layer& getLayer(size_t index) const; + const layer& getLayer(size_t index) const; /*! \brief Get a layer. - * @param index Layer number. + * @param index layer number. * @return Non-constant layer. */ - Layer& getLayer(size_t index); + layer& getLayer(size_t index); /*! \brief Remove a layer. - * @param index Layer number. + * @param index layer number. */ void removeLayer(size_t index); /*! \brief Get all layers. * @return Constant layers. */ - std::vector const& layers() const; + std::vector const& layers() const; /*! \brief Get all layers. * @return Non-constant layers. */ - std::vector & layers(); + std::vector & layers(); /*! \brief Remove all layers and styles from the map. */ @@ -290,7 +290,7 @@ namespace mapnik * Aspect is handled automatic if not fitting to width/height. * @param box The bounding box where to zoom. */ - void zoomToBox(const Envelope& box); + void zoomToBox(const box2d& box); /*! \brief Zoom the map to show all data. */ @@ -303,12 +303,12 @@ namespace mapnik /*! \brief Get current bounding box. * @return The current bounding box. */ - const Envelope& getCurrentExtent() const; + const box2d& getCurrentExtent() const; /*! \brief Get current buffered bounding box. * @return The current buffered bounding box. */ - Envelope get_buffered_extent() const; + box2d get_buffered_extent() const; /*! * @return The Map Scale. @@ -320,7 +320,7 @@ namespace mapnik CoordTransform view_transform() const; /*! - * @brief Query a Map Layer (by layer index) for features + * @brief Query a Map layer (by layer index) for features * * Intersecting the given x,y location in the coordinates * of map projection. @@ -333,7 +333,7 @@ namespace mapnik featureset_ptr query_point(unsigned index, double x, double y) const; /*! - * @brief Query a Map Layer (by layer index) for features + * @brief Query a Map layer (by layer index) for features * * Intersecting the given x,y location in the coordinates * of the pixmap or map surface. diff --git a/include/mapnik/markers_converter.hpp b/include/mapnik/markers_converter.hpp index 6dbc2711c..06b696ff5 100644 --- a/include/mapnik/markers_converter.hpp +++ b/include/mapnik/markers_converter.hpp @@ -115,7 +115,7 @@ namespace mapnik { double dx = x2 - x1; double dy = y2 - y1; double d = std::sqrt(dx * dx + dy * dy); - Envelope ext = shape_.extent(); + box2d ext = shape_.extent(); if (d > ext.width()) { mtx_ = transform_; @@ -132,7 +132,7 @@ namespace mapnik { mtx_.transform(&minx,&miny); mtx_.transform(&maxx,&maxy); - Envelope e0(minx,miny,maxx,maxy); + box2d e0(minx,miny,maxx,maxy); if (detector_.has_placement(e0)) { diff --git a/include/mapnik/math_expr.hpp b/include/mapnik/math_expr.hpp deleted file mode 100644 index c95f1c91d..000000000 --- a/include/mapnik/math_expr.hpp +++ /dev/null @@ -1,141 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2006 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 - * - *****************************************************************************/ -//$Id$ - -#ifndef MATH_EXPR_HPP -#define MATH_EXPR_HPP - -#include - -namespace mapnik -{ - template - struct add - { - T operator () (T const& left, T const& right) - { - return left + right; - } - static std::string to_string() - { - return "+"; - } - }; - - template - struct sub - { - T operator () (T const& left, T const& right) - { - return left - right; - } - static std::string to_string() - { - return "-"; - } - }; - - template - struct mult - { - T operator () (T const& left, T const& right) - { - return left * right; - } - static std::string to_string() - { - return "*"; - } - }; - - template - struct div - { - T operator () (T const& left, T const& right) - { - return left / right; - } - static std::string to_string() - { - return "/"; - } - }; - - template - struct mod - { - T operator () (T const& left, T const& right) - { - return left % right; - } - static std::string to_string() - { - return "%"; - } - }; - - template - struct math_expr_b : public expression - { - math_expr_b(expression const& left, - expression const& right) - : expression(), - left_(left.clone()), - right_(right.clone()) {} - math_expr_b(math_expr_b const& other) - : expression(), - left_(other.left_->clone()), - right_(other.right_->clone()) {} - - value get_value(FeatureT const& feature) const - { - return Op ()(left_->get_value(feature),right_->get_value(feature)); - } - - void accept(filter_visitor& v) - { - left_->accept(v); - right_->accept(v); - v.visit(*this); - } - - expression* clone() const - { - return new math_expr_b(*this); - } - std::string to_string() const - { - return "("+left_->to_string() + Op::to_string() + right_->to_string()+")"; - } - - ~math_expr_b() - { - delete left_; - delete right_; - } - private: - expression* left_; - expression* right_; - }; -} - -#endif // diff --git a/include/mapnik/memory_datasource.hpp b/include/mapnik/memory_datasource.hpp index c1ec67a55..3440b5fe6 100644 --- a/include/mapnik/memory_datasource.hpp +++ b/include/mapnik/memory_datasource.hpp @@ -41,7 +41,7 @@ namespace mapnik { int type() const; featureset_ptr features(const query& q) const; featureset_ptr features_at_point(coord2d const& pt) const; - Envelope envelope() const; + box2d envelope() const; layer_descriptor get_descriptor() const; size_t size() const; private: diff --git a/include/mapnik/memory_featureset.hpp b/include/mapnik/memory_featureset.hpp index d1375533a..71713d9b6 100644 --- a/include/mapnik/memory_featureset.hpp +++ b/include/mapnik/memory_featureset.hpp @@ -32,7 +32,7 @@ namespace mapnik { class memory_featureset : public Featureset, private boost::noncopyable { public: - memory_featureset(Envelope const& bbox, memory_datasource const& ds) + memory_featureset(box2d const& bbox, memory_datasource const& ds) : bbox_(bbox), pos_(ds.features_.begin()), end_(ds.features_.end()) @@ -57,7 +57,7 @@ namespace mapnik { } private: - Envelope const& bbox_; + box2d const& bbox_; std::vector::const_iterator pos_; std::vector::const_iterator end_; }; diff --git a/include/mapnik/octree.hpp b/include/mapnik/octree.hpp index 89b47bc0c..d01862a96 100644 --- a/include/mapnik/octree.hpp +++ b/include/mapnik/octree.hpp @@ -28,7 +28,6 @@ #include // boost -#include #include // stl diff --git a/include/mapnik/path_expression_grammar.hpp b/include/mapnik/path_expression_grammar.hpp new file mode 100644 index 000000000..f08d5437e --- /dev/null +++ b/include/mapnik/path_expression_grammar.hpp @@ -0,0 +1,217 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2009 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 + * + *****************************************************************************/ + +//$Id$ + +#ifndef MAPNIK_PATH_EXPRESSIONS_GRAMMAR_HPP +#define MAPNIK_PATH_EXPRESSIONS_GRAMMAR_HPP + +// mapnik +#include +#include +#include + +// boost +#include +#include +#include +#include +//spirit2 +#include +#include +//fusion +#include +//phoenix +#include +#include +#include +#include +#include +#include +// stl +#include +#include + +namespace mapnik +{ + +namespace qi = boost::spirit::qi; +namespace phoenix = boost::phoenix; +namespace standard_wide = boost::spirit::standard_wide; + +// +using standard_wide::space_type; +using standard_wide::space; + +typedef boost::variant path_component; +typedef std::vector path_expression; +typedef boost::shared_ptr path_expression_ptr; + +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 + filename_ += attr.value(feature_).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); + } +}; + +typedef mapnik::path_processor path_processor_type; + +template +struct path_expression_grammar : qi::grammar(), space_type> +{ + path_expression_grammar() + : path_expression_grammar::base_type(expr) + { + using boost::phoenix::construct; + using standard_wide::char_; + using qi::_1; + using qi::_val; + using qi::lit; + using qi::lexeme; + using phoenix::push_back; + + expr = + * ( + str [ push_back(_val, _1)] + | + ( '[' >> attr [ push_back(_val, construct( _1 )) ] >> ']') + ) + ; + + attr %= +(char_ - ']'); + str %= lexeme[+(char_ -'[')]; + } + + qi::rule() , space_type> expr; + qi::rule attr; + qi::rule str; +}; + + +inline path_expression_ptr parse_path(std::string const & str) +{ + path_expression_ptr path(new path_expression) ; + path_expression_grammar g; + + std::string::const_iterator itr = str.begin(); + std::string::const_iterator end = str.end(); + bool r = qi::phrase_parse(itr, end, g, space, *path); + if (r && itr == end) + { + return path; + } + else + { + throw std::runtime_error("Failed to parse path expression"); + } +} + + +} + +#endif // MAPNIK_PATH_EXPRESSIONS_GRAMMAR_HPP + diff --git a/include/mapnik/placement_finder.hpp b/include/mapnik/placement_finder.hpp index e9f92bc5b..852da810f 100644 --- a/include/mapnik/placement_finder.hpp +++ b/include/mapnik/placement_finder.hpp @@ -37,105 +37,105 @@ namespace mapnik { - typedef text_path placement_element; +typedef text_path placement_element; - struct placement : boost::noncopyable - { - placement(string_info & info_, shield_symbolizer const& sym, bool has_dimensions_= false); +struct placement : boost::noncopyable +{ + placement(string_info & info_, shield_symbolizer const& sym, unsigned w, unsigned h, bool has_dimensions_= false); - placement(string_info & info_, text_symbolizer const& sym); + placement(string_info & info_, text_symbolizer const& sym); - ~placement(); + ~placement(); - string_info & info; + string_info & info; - position displacement_; - label_placement_e label_placement; + position displacement_; + label_placement_e label_placement; - std::queue< Envelope > envelopes; + std::queue< box2d > envelopes; - //output - boost::ptr_vector placements; + //output + boost::ptr_vector placements; - int wrap_width; - bool wrap_before; // wraps text at wrap_char immediately before current word - unsigned char wrap_char; - int text_ratio; + int wrap_width; + bool wrap_before; // wraps text at wrap_char immediately before current word + unsigned char wrap_char; + int text_ratio; - int label_spacing; // distance between repeated labels on a single geometry - unsigned label_position_tolerance; //distance the label can be moved on the line to fit, if 0 the default is used - bool force_odd_labels; //Always try render an odd amount of labels + int label_spacing; // distance between repeated labels on a single geometry + unsigned label_position_tolerance; //distance the label can be moved on the line to fit, if 0 the default is used + bool force_odd_labels; //Always try render an odd amount of labels - double max_char_angle_delta; - double minimum_distance; - bool avoid_edges; - bool has_dimensions; - bool allow_overlap; - std::pair dimensions; - int text_size; - }; + double max_char_angle_delta; + double minimum_distance; + bool avoid_edges; + bool has_dimensions; + bool allow_overlap; + std::pair dimensions; + int text_size; +}; - template - class placement_finder : boost::noncopyable - { - public: - placement_finder(DetectorT & detector); +template +class placement_finder : boost::noncopyable +{ +public: + placement_finder(DetectorT & detector); - //Try place a single label at the given point - void find_point_placement(placement & p, double pos_x, double pos_y, vertical_alignment_e = MIDDLE, unsigned line_spacing=0, unsigned character_spacing=0, horizontal_alignment_e = H_MIDDLE, justify_alignment_e = J_MIDDLE); + //Try place a single label at the given point + void find_point_placement(placement & p, double pos_x, double pos_y, vertical_alignment_e = MIDDLE, unsigned line_spacing=0, unsigned character_spacing=0, horizontal_alignment_e = H_MIDDLE, justify_alignment_e = J_MIDDLE); - //Iterate over the given path, placing point labels with respect to label_spacing - template - void find_point_placements(placement & p, T & path); + //Iterate over the given path, placing point labels with respect to label_spacing + template + void find_point_placements(placement & p, T & path); - //Iterate over the given path, placing line-following labels with respect to label_spacing - template - void find_line_placements(placement & p, T & path); + //Iterate over the given path, placing line-following labels with respect to label_spacing + template + void find_line_placements(placement & p, T & path); - void update_detector(placement & p); + void update_detector(placement & p); - void clear(); + void clear(); - private: - ///Helpers for find_line_placement +private: + ///Helpers for find_line_placement - ///Returns a possible placement on the given line, does not test for collisions - //index: index of the node the current line ends on - //distance: distance along the given index that the placement should start at, this includes the offset, - // as such it may be > or < the length of the current line, so this must be checked for - //orientation: if set to != 0 the placement will be attempted with the given orientation - // otherwise it will autodetect the orientation. - // If >= 50% of the characters end up upside down, it will be retried the other way. - // RETURN: 1/-1 depending which way up the string ends up being. - std::auto_ptr get_placement_offset(placement & p, - const std::vector & path_positions, - const std::vector & path_distances, - int & orientation, unsigned index, double distance); + ///Returns a possible placement on the given line, does not test for collisions + //index: index of the node the current line ends on + //distance: distance along the given index that the placement should start at, this includes the offset, + // as such it may be > or < the length of the current line, so this must be checked for + //orientation: if set to != 0 the placement will be attempted with the given orientation + // otherwise it will autodetect the orientation. + // If >= 50% of the characters end up upside down, it will be retried the other way. + // RETURN: 1/-1 depending which way up the string ends up being. + std::auto_ptr get_placement_offset(placement & p, + const std::vector & path_positions, + const std::vector & path_distances, + int & orientation, unsigned index, double distance); - ///Tests wether the given placement_element be placed without a collision - // Returns true if it can - // NOTE: This edits p.envelopes so it can be used afterwards (you must clear it otherwise) - bool test_placement(placement & p, const std::auto_ptr & current_placement, const int & orientation); + ///Tests wether the given placement_element be placed without a collision + // Returns true if it can + // NOTE: This edits p.envelopes so it can be used afterwards (you must clear it otherwise) + bool test_placement(placement & p, const std::auto_ptr & current_placement, const int & orientation); - ///Does a line-circle intersect calculation - // NOTE: Follow the strict pre conditions - // Pre Conditions: x1,y1 is within radius distance of cx,cy. x2,y2 is outside radius distance of cx,cy - // This means there is exactly one intersect point - // Result is returned in ix, iy - void find_line_circle_intersection( - const double &cx, const double &cy, const double &radius, - const double &x1, const double &y1, const double &x2, const double &y2, - double &ix, double &iy); + ///Does a line-circle intersect calculation + // NOTE: Follow the strict pre conditions + // Pre Conditions: x1,y1 is within radius distance of cx,cy. x2,y2 is outside radius distance of cx,cy + // This means there is exactly one intersect point + // Result is returned in ix, iy + void find_line_circle_intersection( + const double &cx, const double &cy, const double &radius, + const double &x1, const double &y1, const double &x2, const double &y2, + double &ix, double &iy); - ///General Internals + ///General Internals - DetectorT & detector_; - Envelope const& dimensions_; - }; + DetectorT & detector_; + box2d const& dimensions_; +}; } #endif diff --git a/include/mapnik/png_io.hpp b/include/mapnik/png_io.hpp index e050f747b..b00d55ba8 100644 --- a/include/mapnik/png_io.hpp +++ b/include/mapnik/png_io.hpp @@ -92,14 +92,14 @@ namespace mapnik { } template - void reduce_8 (T const& in, ImageData8 & out, octree & tree) + void reduce_8 (T const& in, image_data_8 & out, octree & tree) { unsigned width = in.width(); unsigned height = in.height(); for (unsigned y = 0; y < height; ++y) { - mapnik::ImageData32::pixel_type const * row = in.getRow(y); - mapnik::ImageData8::pixel_type * row_out = out.getRow(y); + mapnik::image_data_32::pixel_type const * row = in.getRow(y); + mapnik::image_data_8::pixel_type * row_out = out.getRow(y); for (unsigned x = 0; x < width; ++x) { unsigned val = row[x]; @@ -118,15 +118,15 @@ namespace mapnik { } template - void reduce_4 (T const& in, ImageData8 & out, octree & tree) + void reduce_4 (T const& in, image_data_8 & out, octree & tree) { unsigned width = in.width(); unsigned height = in.height(); for (unsigned y = 0; y < height; ++y) { - mapnik::ImageData32::pixel_type const * row = in.getRow(y); - mapnik::ImageData8::pixel_type * row_out = out.getRow(y); + mapnik::image_data_32::pixel_type const * row = in.getRow(y); + mapnik::image_data_8::pixel_type * row_out = out.getRow(y); for (unsigned x = 0; x < width; ++x) { @@ -149,14 +149,14 @@ namespace mapnik { // 1-bit but only one color. template - void reduce_1(T const&, ImageData8 & out, octree &) + void reduce_1(T const&, image_data_8 & out, octree &) { out.set(0); // only one color!!! } template void save_as_png(T & file, std::vector & palette, - mapnik::ImageData8 const& image, + mapnik::image_data_8 const& image, unsigned width, unsigned height, unsigned color_depth, @@ -250,7 +250,7 @@ namespace mapnik { if (palette.size() > 16 ) { // >16 && <=256 colors -> write 8-bit color depth - ImageData8 reduced_image(width,height); + image_data_8 reduced_image(width,height); reduce_8(image,reduced_image,tree); save_as_png(file,palette,reduced_image,width,height,8,tree.hasAlfa()); } @@ -259,7 +259,7 @@ namespace mapnik { // 1 color image -> write 1-bit color depth PNG unsigned image_width = (int(0.125*width) + 7)&~7; unsigned image_height = height; - ImageData8 reduced_image(image_width,image_height); + image_data_8 reduced_image(image_width,image_height); reduce_1(image,reduced_image,tree); save_as_png(file,palette,reduced_image,width,height,1,tree.hasAlfa()); } @@ -268,7 +268,7 @@ namespace mapnik { // <=16 colors -> write 4-bit color depth PNG unsigned image_width = (int(0.5*width) + 3)&~3; unsigned image_height = height; - ImageData8 reduced_image(image_width,image_height); + image_data_8 reduced_image(image_width,image_height); reduce_4(image,reduced_image,tree); save_as_png(file,palette,reduced_image,width,height,4,tree.hasAlfa()); } diff --git a/include/mapnik/point_symbolizer.hpp b/include/mapnik/point_symbolizer.hpp index fcbc59f0b..c1c8cb1f6 100644 --- a/include/mapnik/point_symbolizer.hpp +++ b/include/mapnik/point_symbolizer.hpp @@ -21,31 +21,28 @@ *****************************************************************************/ //$Id: image_symbolizer.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef POINT_SYMBOLIZER_HPP -#define POINT_SYMBOLIZER_HPP +#ifndef MAPNIK_POINT_SYMBOLIZER_HPP +#define MAPNIK_POINT_SYMBOLIZER_HPP -#include +// mapnik #include -#include namespace mapnik { - struct MAPNIK_DECL point_symbolizer : +struct MAPNIK_DECL point_symbolizer : public symbolizer_with_image - { - explicit point_symbolizer(); - point_symbolizer(std::string const& file, - std::string const& type, - unsigned width,unsigned height); - point_symbolizer(point_symbolizer const& rhs); - void set_allow_overlap(bool overlap); - bool get_allow_overlap() const; - void set_opacity(float opacity); - float get_opacity() const; - private: - float opacity_; - bool overlap_; - }; +{ + explicit point_symbolizer(); + point_symbolizer(path_expression_ptr file); + point_symbolizer(point_symbolizer const& rhs); + void set_allow_overlap(bool overlap); + bool get_allow_overlap() const; + void set_opacity(float opacity); + float get_opacity() const; +private: + float opacity_; + bool overlap_; +}; } -#endif // POINT_SYMBOLIZER_HPP +#endif // MAPNIK_POINT_SYMBOLIZER_HPP diff --git a/include/mapnik/polygon_pattern_symbolizer.hpp b/include/mapnik/polygon_pattern_symbolizer.hpp index 3c39799b3..5186ca58f 100644 --- a/include/mapnik/polygon_pattern_symbolizer.hpp +++ b/include/mapnik/polygon_pattern_symbolizer.hpp @@ -22,24 +22,20 @@ //$Id$ #ifndef POLYGON_PATTERN_SYMBOLIZER_HPP -#define POLYGON_PATTERN_SYMBOLIZER_HPP +#define MAPNIK_POLYGON_PATTERN_SYMBOLIZER_HPP -#include +// mapnik #include -#include namespace mapnik { - struct MAPNIK_DECL polygon_pattern_symbolizer : - public symbolizer_with_image - { +struct MAPNIK_DECL polygon_pattern_symbolizer : + public symbolizer_with_image +{ - polygon_pattern_symbolizer(std::string const& file, - std::string const& type, - unsigned width,unsigned height); - - polygon_pattern_symbolizer(polygon_pattern_symbolizer const& rhs); - }; + polygon_pattern_symbolizer(path_expression_ptr file); + polygon_pattern_symbolizer(polygon_pattern_symbolizer const& rhs); +}; } -#endif //POLYGON_PATTERN_SYMBOLIZER_HPP +#endif //MAPNIK_POLYGON_PATTERN_SYMBOLIZER_HPP diff --git a/include/mapnik/projection.hpp b/include/mapnik/projection.hpp index 76a78163b..6c09341f1 100644 --- a/include/mapnik/projection.hpp +++ b/include/mapnik/projection.hpp @@ -26,7 +26,7 @@ #define PROJECTION_HPP // mapnik -#include +#include // boost #ifdef MAPNIK_THREADSAFE diff --git a/include/mapnik/ptree_helpers.hpp b/include/mapnik/ptree_helpers.hpp index 13e266b10..5887dd4d9 100644 --- a/include/mapnik/ptree_helpers.hpp +++ b/include/mapnik/ptree_helpers.hpp @@ -42,7 +42,7 @@ namespace mapnik { template T get(const boost::property_tree::ptree & node, const std::string & name, bool is_attribute); template - T get_own(const boost::property_tree::ptree & node, const std::string & name); + T get_value(const boost::property_tree::ptree & node, const std::string & name); template boost::optional get_optional(const boost::property_tree::ptree & node, const std::string & name, bool is_attribute); @@ -77,14 +77,14 @@ namespace mapnik { template T get_css( const boost::property_tree::ptree & node, const std::string & name ) { - return get_own( node, std::string("CSS parameter '") + name + "'"); + return get_value( node, std::string("CSS parameter '") + name + "'"); } // specialization for color type template <> inline color get_css (boost::property_tree::ptree const& node, std::string const& name) { - std::string str = get_own( node, std::string("CSS parameter '") + name + "'"); ; + std::string str = get_value( node, std::string("CSS parameter '") + name + "'"); ; try { return mapnik::color_factory::from_string(str.c_str()); @@ -190,7 +190,7 @@ namespace mapnik { boost::property_tree::ptree::value_type("CssParameter", boost::property_tree::ptree()))->second; css_node.put(".name", name ); - css_node.put_own( v ); + css_node.put_value( v ); } template @@ -341,11 +341,11 @@ namespace mapnik { } template - T get_own(const boost::property_tree::ptree & node, const std::string & name) + T get_value(const boost::property_tree::ptree & node, const std::string & name) { try { - return node.get_own(); + return node.get_value(); } catch (...) { diff --git a/include/mapnik/quad_tree.hpp b/include/mapnik/quad_tree.hpp index cb424ff74..73ad5289f 100644 --- a/include/mapnik/quad_tree.hpp +++ b/include/mapnik/quad_tree.hpp @@ -24,7 +24,7 @@ #ifndef QUAD_TREE_HPP #define QUAD_TREE_HPP // mapnik -#include +#include // boost #include #include @@ -43,17 +43,17 @@ namespace mapnik typedef std::vector cont_t; typedef typename cont_t::iterator iterator; typedef typename cont_t::const_iterator const_iterator; - Envelope extent_; + box2d extent_; cont_t cont_; node * children_[4]; - explicit node(Envelope const& ext) + explicit node(box2d const& ext) : extent_(ext) { std::memset(children_,0,4*sizeof(node*)); } - Envelope const& extent() const + box2d const& extent() const { return extent_; } @@ -96,7 +96,7 @@ namespace mapnik result_t query_result_; - explicit quad_tree(Envelope const& ext, + explicit quad_tree(box2d const& ext, unsigned int max_depth = 8, double ratio = 0.55) : max_depth_(max_depth), @@ -106,13 +106,13 @@ namespace mapnik root_ = &nodes_[0]; } - void insert(T data, Envelope const& box) + void insert(T data, box2d const& box) { unsigned int depth=0; do_insert_data(data,box,root_,depth); } - query_iterator query_in_box(Envelope const& box) + query_iterator query_in_box(box2d const& box) { query_result_.clear(); query_node(box,query_result_,root_); @@ -146,18 +146,18 @@ namespace mapnik void clear () { - Envelope ext = root_->extent_; + box2d ext = root_->extent_; nodes_.clear(); nodes_.push_back(new node(ext)); root_ = &nodes_[0]; } private: - void query_node(Envelope const& box, result_t & result, node * node_) const + void query_node(box2d const& box, result_t & result, node * node_) const { if (node_) { - Envelope const& node_extent = node_->extent(); + box2d const& node_extent = node_->extent(); if (box.intersects(node_extent)) { node_data_iterator i=node_->begin(); @@ -175,7 +175,7 @@ namespace mapnik } } - void do_insert_data(T data, Envelope const& box, node * n, unsigned int& depth) + void do_insert_data(T data, box2d const& box, node * n, unsigned int& depth) { if (++depth >= max_depth_) { @@ -183,8 +183,8 @@ namespace mapnik } else { - Envelope const& node_extent = n->extent(); - Envelope ext[4]; + box2d const& node_extent = n->extent(); + box2d ext[4]; split_box(node_extent,ext); for (int i=0;i<4;++i) { @@ -203,7 +203,7 @@ namespace mapnik } } - void split_box(Envelope const& node_extent,Envelope * ext) + void split_box(box2d const& node_extent,box2d * ext) { coord2d c=node_extent.center(); @@ -215,10 +215,10 @@ namespace mapnik double hix=node_extent.maxx(); double hiy=node_extent.maxy(); - ext[0]=Envelope(lox,loy,lox + width * ratio_,loy + height * ratio_); - ext[1]=Envelope(hix - width * ratio_,loy,hix,loy + height * ratio_); - ext[2]=Envelope(lox,hiy - height*ratio_,lox + width * ratio_,hiy); - ext[3]=Envelope(hix - width * ratio_,hiy - height*ratio_,hix,hiy); + ext[0]=box2d(lox,loy,lox + width * ratio_,loy + height * ratio_); + ext[1]=box2d(hix - width * ratio_,loy,hix,loy + height * ratio_); + ext[2]=box2d(lox,hiy - height*ratio_,lox + width * ratio_,hiy); + ext[3]=box2d(hix - width * ratio_,hiy - height*ratio_,hix,hiy); } }; } diff --git a/include/mapnik/query.hpp b/include/mapnik/query.hpp index bc72f7748..54145a36b 100644 --- a/include/mapnik/query.hpp +++ b/include/mapnik/query.hpp @@ -24,9 +24,9 @@ #ifndef QUERY_HPP #define QUERY_HPP + //mapnik -#include -#include +#include #include // stl #include @@ -36,19 +36,19 @@ namespace mapnik { class query { private: - Envelope bbox_; + box2d bbox_; double resolution_; double scale_denominator_; std::set names_; public: - explicit query(const Envelope& bbox, double resolution, double scale_denominator) + explicit query(const box2d& bbox, double resolution, double scale_denominator) : bbox_(bbox), resolution_(resolution), scale_denominator_(scale_denominator) {} - explicit query(const Envelope& bbox, double resolution) + explicit query(const box2d& bbox, double resolution) : bbox_(bbox), resolution_(resolution), scale_denominator_(0.0) @@ -81,7 +81,7 @@ namespace mapnik { return scale_denominator_; } - const Envelope& get_bbox() const + const box2d& get_bbox() const { return bbox_; } diff --git a/include/mapnik/raster.hpp b/include/mapnik/raster.hpp index b4a7c7f4a..321dfd7fb 100644 --- a/include/mapnik/raster.hpp +++ b/include/mapnik/raster.hpp @@ -29,9 +29,9 @@ namespace mapnik { struct raster { - Envelope ext_; - ImageData32 data_; - raster(Envelope const& ext,ImageData32& data) + box2d ext_; + image_data_32 data_; + raster(box2d const& ext,image_data_32& data) : ext_(ext), data_(data) {} }; diff --git a/include/mapnik/regex_filter.hpp b/include/mapnik/regex_filter.hpp deleted file mode 100644 index 4cb37950a..000000000 --- a/include/mapnik/regex_filter.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2006 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 - * - *****************************************************************************/ - - -//$Id$ - -#ifndef REGEX_FILTER_HPP -#define REGEX_FILTER_HPP -// mapnik -#include -#include -// boost -#include -#include - -namespace mapnik -{ - template - struct regex_filter : public filter - { - - regex_filter(expression const& exp, - std::string const& pattern) - : filter(), - exp_(exp.clone()), - pattern_(pattern) {} - - regex_filter(regex_filter const& other) - : filter(), - exp_(other.exp_->clone()), - pattern_(other.pattern_) {} - - bool pass(FeatureT const& feature) const - { - std::string text=exp_->get_value(feature).to_string(); - boost::trim_if(text, boost::is_any_of("'")); - return boost::regex_match(text,pattern_); - } - - void accept(filter_visitor& v) - { - exp_->accept(v); - v.visit(*this); - } - - filter* clone() const - { - return new regex_filter(*this); - } - std::string to_string() const - { - return exp_->to_string()+".match("+pattern_.str()+")"; - } - ~regex_filter() - { - delete exp_; - } - - private: - expression* exp_; - boost::regex pattern_; - - }; -} - - -#endif //REGEX_FILTER_HPP diff --git a/include/mapnik/rule.hpp b/include/mapnik/rule.hpp index 181475b63..77fcf8754 100644 --- a/include/mapnik/rule.hpp +++ b/include/mapnik/rule.hpp @@ -32,8 +32,8 @@ #include #include #include -#include -#include +#include +#include // boost #include @@ -113,203 +113,196 @@ namespace mapnik markers_symbolizer> symbolizer; - typedef std::vector symbolizers; - template class all_filter; +template +class rule +{ +public: + typedef std::vector symbolizers; +private: + + std::string name_; + std::string title_; + std::string abstract_; + double min_scale_; + double max_scale_; + symbolizers syms_; + expression_ptr filter_; + bool else_filter_; +public: + rule() + : name_(), + title_(), + abstract_(), + min_scale_(0), + max_scale_(std::numeric_limits::infinity()), + syms_(), + filter_(new mapnik::expr_node(true)), + else_filter_(false) {} + + rule(const std::string& name, + const std::string& title="", + double min_scale_denominator=0, + double max_scale_denominator=std::numeric_limits::infinity()) + : name_(name), + title_(title), + min_scale_(min_scale_denominator), + max_scale_(max_scale_denominator), + syms_(), + filter_(new mapnik::expr_node(true)), + else_filter_(false) {} + + rule(const rule& rhs) + : name_(rhs.name_), + title_(rhs.title_), + abstract_(rhs.abstract_), + min_scale_(rhs.min_scale_), + max_scale_(rhs.max_scale_), + syms_(rhs.syms_), + filter_(rhs.filter_), + else_filter_(rhs.else_filter_) {} + + rule& operator=(rule const& rhs) + { + rule tmp(rhs); + swap(tmp); + return *this; + } + bool operator==(rule const& other) + { + return (this == &other); + } + + void set_max_scale(double scale) + { + max_scale_=scale; + } + + double get_max_scale() const + { + return max_scale_; + } + + void set_min_scale(double scale) + { + min_scale_=scale; + } + + double get_min_scale() const + { + return min_scale_; + } + + void set_name(std::string const& name) + { + name_=name; + } + + std::string const& get_name() const + { + return name_; + } + + std::string const& get_title() const + { + return title_; + } + + void set_title(std::string const& title) + { + title_=title; + } + + void set_abstract(std::string const& abstract) + { + abstract_=abstract; + } + + std::string const& get_abstract() const + { + return abstract_; + } + + void append(const symbolizer& sym) + { + syms_.push_back(sym); + } + + void remove_at(size_t index) + { + if (index < syms_.size()) + { + syms_.erase(syms_.begin()+index); + } + } + + const symbolizers& get_symbolizers() const + { + return syms_; + } + + symbolizers::const_iterator begin() const + { + return syms_.begin(); + } + + symbolizers::const_iterator end() const + { + return syms_.end(); + } + + symbolizers::iterator begin() + { + return syms_.begin(); + } + + symbolizers::iterator end() + { + return syms_.end(); + } + + void set_filter(const expression_ptr& filter) + { + filter_=filter; + } + + expression_ptr const& get_filter() const + { + return filter_; + } + + void set_else(bool else_filter) + { + else_filter_=else_filter; + } + + bool has_else_filter() const + { + return else_filter_; + } + + bool active(double scale) const + { + return ( scale >= min_scale_ - 1e-6 && scale < max_scale_ + 1e-6); + } + +private: + + void swap(rule& rhs) throw() + { + name_=rhs.name_; + title_=rhs.title_; + abstract_=rhs.abstract_; + min_scale_=rhs.min_scale_; + max_scale_=rhs.max_scale_; + syms_=rhs.syms_; + filter_=rhs.filter_; + else_filter_=rhs.else_filter_; + } +}; - template class Filter> - class rule - { - typedef Filter filter_type; - typedef boost::shared_ptr filter_ptr; - private: +typedef rule rule_type; - std::string name_; - std::string title_; - std::string abstract_; - double min_scale_; - double max_scale_; - symbolizers syms_; - filter_ptr filter_; - bool else_filter_; - public: - rule() - : name_(), - title_(), - abstract_(), - min_scale_(0), - max_scale_(std::numeric_limits::infinity()), - syms_(), - filter_(new all_filter), - else_filter_(false) {} - - rule(const std::string& name, - const std::string& title="", - double min_scale_denominator=0, - double max_scale_denominator=std::numeric_limits::infinity()) - : name_(name), - title_(title), - min_scale_(min_scale_denominator), - max_scale_(max_scale_denominator), - syms_(), - filter_(new all_filter), - else_filter_(false) {} - - rule(const rule& rhs) - : name_(rhs.name_), - title_(rhs.title_), - abstract_(rhs.abstract_), - min_scale_(rhs.min_scale_), - max_scale_(rhs.max_scale_), - syms_(rhs.syms_), - filter_(rhs.filter_), - else_filter_(rhs.else_filter_) {} - - rule& operator=(rule const& rhs) - { - rule tmp(rhs); - swap(tmp); - return *this; - } - bool operator==(rule const& other) - { - return (this == &other); - } - - void set_max_scale(double scale) - { - max_scale_=scale; - } - - double get_max_scale() const - { - return max_scale_; - } - - void set_min_scale(double scale) - { - min_scale_=scale; - } - - double get_min_scale() const - { - return min_scale_; - } - - void set_name(std::string const& name) - { - name_=name; - } - - std::string const& get_name() const - { - return name_; - } - - std::string const& get_title() const - { - return title_; - } - - void set_title(std::string const& title) - { - title_=title; - } - - void set_abstract(std::string const& abstract) - { - abstract_=abstract; - } - - std::string const& get_abstract() const - { - return abstract_; - } - - void append(const symbolizer& sym) - { - syms_.push_back(sym); - } - - void remove_at(size_t index) - { - if (index < syms_.size()) - { - syms_.erase(syms_.begin()+index); - } - } - - const symbolizers& get_symbolizers() const - { - return syms_; - } - - symbolizers::const_iterator begin() const - { - return syms_.begin(); - } - - symbolizers::const_iterator end() const - { - return syms_.end(); - } - - symbolizers::iterator begin() - { - return syms_.begin(); - } - - symbolizers::iterator end() - { - return syms_.end(); - } - - void set_filter(const filter_ptr& filter) - { - filter_=filter; - } - - filter_ptr const& get_filter() const - { - return filter_; - } - - void set_else(bool else_filter) - { - else_filter_=else_filter; - } - - bool has_else_filter() const - { - return else_filter_; - } - - bool active(double scale) const - { - return ( scale >= min_scale_ - 1e-6 && scale < max_scale_ + 1e-6); - } - - void accept(filter_visitor& v) const - { - v.visit(*this); - } - - private: - - void swap(rule& rhs) throw() - { - name_=rhs.name_; - title_=rhs.title_; - abstract_=rhs.abstract_; - min_scale_=rhs.min_scale_; - max_scale_=rhs.max_scale_; - syms_=rhs.syms_; - filter_=rhs.filter_; - else_filter_=rhs.else_filter_; - } - }; - - typedef rule rule_type; } #endif //RULE_HPP diff --git a/include/mapnik/shield_symbolizer.hpp b/include/mapnik/shield_symbolizer.hpp index 28039e908..2b3642b4c 100644 --- a/include/mapnik/shield_symbolizer.hpp +++ b/include/mapnik/shield_symbolizer.hpp @@ -22,44 +22,40 @@ *****************************************************************************/ //$Id$ -#ifndef SHIELD_SYMBOLIZER_HPP -#define SHIELD_SYMBOLIZER_HPP +#ifndef MAPNIK_SHIELD_SYMBOLIZER_HPP +#define MAPNIK_SHIELD_SYMBOLIZER_HPP -#include -#include +// mapnik #include +#include +// boost #include namespace mapnik { - struct MAPNIK_DECL shield_symbolizer : public text_symbolizer, - public symbolizer_with_image - { - shield_symbolizer(std::string const& name, +struct MAPNIK_DECL shield_symbolizer : public text_symbolizer, + public symbolizer_with_image +{ + shield_symbolizer(expression_ptr name, std::string const& face_name, unsigned size, color const& fill, - std::string const& file, - std::string const& type, - unsigned width,unsigned height); - shield_symbolizer(std::string const& name, + path_expression_ptr file); + shield_symbolizer(expression_ptr name, unsigned size, color const& fill, - std::string const& file, - std::string const& type, - unsigned width,unsigned height); - - bool get_unlock_image() const; // image is not locked to the text placement - void set_unlock_image(bool unlock_image); - bool get_no_text() const; // do no render text - void set_no_text(bool unlock_image); - - private: - - bool unlock_image_; - bool no_text_; - }; + path_expression_ptr file); + + bool get_unlock_image() const; // image is not locked to the text placement + void set_unlock_image(bool unlock_image); + bool get_no_text() const; // do no render text + void set_no_text(bool unlock_image); + +private: + bool unlock_image_; + bool no_text_; +}; } #endif // SHIELD_SYMBOLIZER_HPP diff --git a/include/mapnik/spatial.hpp b/include/mapnik/spatial.hpp deleted file mode 100644 index d17a14aef..000000000 --- a/include/mapnik/spatial.hpp +++ /dev/null @@ -1,153 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2006 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 SPATIAL_HPP -#define SPATIAL_HPP - -#include -#include - -namespace mapnik -{ - - template - struct equals_ : public filter - { - - bool pass(const FeatureT& feature) const - { - return false; - } - - void accept(const filter_visitor& v) - { - v.visit(*this); - } - }; - - template - struct disjoint : public filter - { - - - bool pass(const FeatureT& feature) const - { - return false; - } - - void accept(const filter_visitor& v) - { - v.visit(*this); - } - }; - - template - struct touches : public filter - { - - - bool pass(const FeatureT& feature) const - { - return false; - } - - void accept(const filter_visitor& v) - { - v.visit(*this); - } - }; - - template - struct within : public filter - { - - bool pass(const FeatureT& feature) const - { - return false; - } - - void accept(const filter_visitor& v) - { - v.visit(*this); - } - }; - - template - struct overlaps : public filter - { - - bool pass(const FeatureT& feature) const - { - return false; - } - - void accept(const filter_visitor& v) - { - v.visit(*this); - } - }; - - template - struct crosses : public filter - { - - - bool pass(const FeatureT& feature) const - { - return false; - } - - void accept(const filter_visitor& v) - { - v.visit(*this); - } - }; - - template - struct bbox : public filter - { - private: - Envelope box_; - public: - bbox(const Envelope& box) - : box_(box) {} - - - bool pass(const FeatureT& feature) const - { - return box_.contains(feature.get_geometry()->bbox()); - } - - - filter* clone() const - { - return new bbox(box_); - } - void accept(const filter_visitor& v) - { - v.visit(*this); - } - - virtual ~bbox() {} - }; -} - -#endif //SPATIAL_HPP diff --git a/include/mapnik/symbolizer.hpp b/include/mapnik/symbolizer.hpp index 92e23855f..15d604d17 100644 --- a/include/mapnik/symbolizer.hpp +++ b/include/mapnik/symbolizer.hpp @@ -21,35 +21,28 @@ *****************************************************************************/ //$Id: symbolizer.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef SYMBOLIZER_HPP -#define SYMBOLIZER_HPP +#ifndef MAPNIK_SYMBOLIZER_HPP +#define MAPNIK_SYMBOLIZER_HPP -#include -#include +// mapnik +#include +#include + +// stl +#include namespace mapnik { - class MAPNIK_DECL symbolizer_with_image { - public: - boost::shared_ptr get_image() const; - const std::string & get_filename() const; - void set_filename(std::string const& image_filename); - void set_image( boost::shared_ptr symbol); - - virtual ~symbolizer_with_image() {}; - protected: - symbolizer_with_image(boost::shared_ptr img); - symbolizer_with_image(std::string const& file, - std::string const& type, - unsigned width,unsigned height); - - symbolizer_with_image(symbolizer_with_image const& rhs); - - boost::shared_ptr image_; - std::string image_filename_; - - }; +class MAPNIK_DECL symbolizer_with_image { +public: + path_expression_ptr get_filename() const; + void set_filename(path_expression_ptr filename); +protected: + symbolizer_with_image(path_expression_ptr filename); + symbolizer_with_image(symbolizer_with_image const& rhs); + path_expression_ptr image_filename_; +}; } -#endif //SYMBOLIZER_HPP +#endif //MAPNIK_SYMBOLIZER_HPP diff --git a/include/mapnik/text_symbolizer.hpp b/include/mapnik/text_symbolizer.hpp index 43c6d5ec2..9e3863dad 100644 --- a/include/mapnik/text_symbolizer.hpp +++ b/include/mapnik/text_symbolizer.hpp @@ -22,13 +22,16 @@ //$Id$ -#ifndef TEXT_SYMBOLIZER_HPP -#define TEXT_SYMBOLIZER_HPP +#ifndef MAPNIK_TEXT_SYMBOLIZER_HPP +#define MAPNIK_TEXT_SYMBOLIZER_HPP + // mapnik #include #include #include #include +#include + // boost #include #include @@ -90,13 +93,17 @@ namespace mapnik struct MAPNIK_DECL text_symbolizer { - text_symbolizer(std::string const& name,std::string const& face_name, + text_symbolizer(expression_ptr name, std::string const& face_name, unsigned size, color const& fill); - text_symbolizer(std::string const& name, unsigned size, color const& fill); + text_symbolizer(expression_ptr name, unsigned size, color const& fill); text_symbolizer(text_symbolizer const& rhs); text_symbolizer& operator=(text_symbolizer const& rhs); - std::string const& get_name() const; - void set_name(std::string name); + + // + expression_ptr get_name() const; + void set_name(expression_ptr expr); + // + unsigned get_text_ratio() const; // target ratio for text bounding box in pixels void set_text_ratio(unsigned ratio); unsigned get_wrap_width() const; // width to wrap text at, or trigger ratio @@ -123,8 +130,8 @@ namespace mapnik void set_text_size(unsigned size); std::string const& get_face_name() const; void set_face_name(std::string face_name); - FontSet const& get_fontset() const; - void set_fontset(FontSet const& fontset); + font_set const& get_fontset() const; + void set_fontset(font_set const& fset); color const& get_fill() const; void set_fill(color const& fill); void set_halo_fill(color const& fill); @@ -155,9 +162,9 @@ namespace mapnik justify_alignment_e get_justify_alignment() const; private: - std::string name_; + expression_ptr name_; std::string face_name_; - FontSet fontset_; + font_set fontset_; unsigned size_; unsigned text_ratio_; unsigned wrap_width_; @@ -186,4 +193,4 @@ namespace mapnik }; } -#endif //TEXT_SYMBOLIZER_HPP +#endif //MAPNIK_TEXT_SYMBOLIZER_HPP diff --git a/include/mapnik/value.hpp b/include/mapnik/value.hpp index 6a84eca90..5019399de 100644 --- a/include/mapnik/value.hpp +++ b/include/mapnik/value.hpp @@ -308,11 +308,7 @@ template struct add : public boost::static_visitor { typedef V value_type; - template - value_type operator() (T1 const& lhs, T2 const&) const - { - return lhs; - } + template value_type operator() (T lhs, T rhs) const { @@ -334,6 +330,28 @@ struct add : public boost::static_visitor { return lhs + rhs; } + + template + value_type operator() (UnicodeString const& lhs, R const& rhs) const + { + std::basic_ostringstream out; + out << rhs; + return lhs + UnicodeString(out.str().c_str()); + } + + template + value_type operator() (L const& lhs , UnicodeString const& rhs) const + { + std::basic_ostringstream out; + out << lhs; + return UnicodeString(out.str().c_str()) + rhs; + } + + template + value_type operator() (T1 const& lhs, T2 const&) const + { + return lhs; + } }; template @@ -489,18 +507,28 @@ struct mod: public boost::static_visitor struct to_bool : public boost::static_visitor { - - template - bool operator() (T val) const - { - boost::ignore_unused_variable_warning(val); - throw config_error("Boolean value expected"); - } - bool operator() (bool val) const { return val; } + + bool operator() (UnicodeString const& ustr) const + { + boost::ignore_unused_variable_warning(ustr); + return true; + } + + bool operator() (value_null const& val) const + { + boost::ignore_unused_variable_warning(val); + return false; + } + + template + bool operator() (T val) const + { + return bool(val); + } }; struct to_string : public boost::static_visitor diff --git a/include/mapnik/vertex_transform.hpp b/include/mapnik/vertex_transform.hpp index 6f7469d6a..5f5571183 100644 --- a/include/mapnik/vertex_transform.hpp +++ b/include/mapnik/vertex_transform.hpp @@ -25,7 +25,7 @@ #define VERTEX_TRANSFORM_HPP // mapnik -#include +#include #include namespace mapnik @@ -84,7 +84,7 @@ namespace mapnik }; template - struct view_transform,Envelope,Trans> + struct view_transform,box2d,Trans> { }; diff --git a/include/mapnik/wall_clock_timer.hpp b/include/mapnik/wall_clock_timer.hpp index bd471b988..2b93f1ab3 100644 --- a/include/mapnik/wall_clock_timer.hpp +++ b/include/mapnik/wall_clock_timer.hpp @@ -20,12 +20,11 @@ * *****************************************************************************/ - #ifndef MAPNIK_WALL_CLOCK_TIMER_INCLUDED #define MAPNIK_WALL_CLOCK_TIMER_INCLUDED -/* -#include +#include +#include namespace mapnik { @@ -90,6 +89,4 @@ namespace mapnik { }; }; - -*/ #endif // MAPNIK_WALL_CLOCK_TIMER_INCLUDED diff --git a/plugins/input/gdal/gdal_datasource.cpp b/plugins/input/gdal/gdal_datasource.cpp index f9713442d..2b229b68d 100644 --- a/plugins/input/gdal/gdal_datasource.cpp +++ b/plugins/input/gdal/gdal_datasource.cpp @@ -33,7 +33,7 @@ using mapnik::parameters; DATASOURCE_PLUGIN(gdal_datasource) -using mapnik::Envelope; +using mapnik::box2d; using mapnik::coord2d; using mapnik::query; using mapnik::featureset_ptr; @@ -68,7 +68,7 @@ gdal_datasource::gdal_datasource(parameters const& params) { #ifdef MAPNIK_DEBUG - std::cout << "\nGDAL Plugin: Initializing...\n"; + std::clog << "\nGDAL Plugin: Initializing...\n"; #endif GDALAllRegister(); @@ -103,7 +103,8 @@ gdal_datasource::gdal_datasource(parameters const& params) GDALClose(dataset); #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: RASTER SIZE("<< width_ << "," << height_ << ")\n"; + std::clog << "GDAL Plugin: Raster Size=" << width_ << "," << height_ << "\n"; + std::clog << "GDAL Plugin: Raster Extent=" << extent_ << "\n"; #endif } @@ -120,7 +121,7 @@ std::string gdal_datasource::name() return "gdal"; } -Envelope gdal_datasource::envelope() const +box2d gdal_datasource::envelope() const { return extent_; } diff --git a/plugins/input/gdal/gdal_datasource.hpp b/plugins/input/gdal/gdal_datasource.hpp index e3d957db2..c0f6cf13a 100644 --- a/plugins/input/gdal/gdal_datasource.hpp +++ b/plugins/input/gdal/gdal_datasource.hpp @@ -37,10 +37,10 @@ class gdal_datasource : public mapnik::datasource static std::string name(); mapnik::featureset_ptr features( mapnik::query const& q) const; mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::Envelope envelope() const; + mapnik::box2d envelope() const; mapnik::layer_descriptor get_descriptor() const; private: - mapnik::Envelope extent_; + mapnik::box2d extent_; std::string dataset_name_; int band_; mapnik::layer_descriptor desc_; diff --git a/plugins/input/gdal/gdal_featureset.cpp b/plugins/input/gdal/gdal_featureset.cpp index d062614d1..a3a4f612b 100644 --- a/plugins/input/gdal/gdal_featureset.cpp +++ b/plugins/input/gdal/gdal_featureset.cpp @@ -29,7 +29,7 @@ using mapnik::query; using mapnik::coord2d; -using mapnik::Envelope; +using mapnik::box2d; using mapnik::Feature; using mapnik::feature_ptr; using mapnik::CoordTransform; @@ -46,7 +46,7 @@ gdal_featureset::gdal_featureset(GDALDataset & dataset, int band, gdal_query q) gdal_featureset::~gdal_featureset() { #ifdef MAPNIK_DEBUG - std::clog << "GDAL Plugin: closing dataset = " << &dataset_ << "\n"; + std::clog << "GDAL Plugin: closing dataset = " << &dataset_ << "\n"; #endif GDALClose(&dataset_); } @@ -98,11 +98,11 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) double y0 = tr[3]; // miny double x1 = tr[0] + raster_width * dx + raster_height * tr[2]; // maxx double y1 = tr[3] + raster_width * tr[4] + raster_height * dy; // maxy - Envelope raster_extent(x0,y0,x1,y1); + box2d raster_extent(x0,y0,x1,y1); CoordTransform t(raster_width,raster_height,raster_extent,0,0); - Envelope intersect = raster_extent.intersect(q.get_bbox()); - Envelope box = t.forward(intersect); + box2d intersect = raster_extent.intersect(q.get_bbox()); + box2d box = t.forward(intersect); // TODO: error check this further... float x_off_f = (intersect.minx()-raster_extent.minx()) / fabs(dx); @@ -125,10 +125,10 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) int height = int(box.height() + 0.5); #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: Raster extent=" << raster_extent << "\n"; - std::cout << "GDAL Plugin: View extent=" << intersect << "\n"; - std::cout << "GDAL Plugin: Query resolution=" << q.resolution() << "\n"; - std::cout << boost::format("GDAL Plugin: StartX=%d StartY=%d Width=%d Height=%d \n") % x_off % y_off % width % height; + std::clog << "GDAL Plugin: Raster extent=" << raster_extent << "\n"; + std::clog << "GDAL Plugin: View extent=" << intersect << "\n"; + std::clog << "GDAL Plugin: Query resolution=" << q.resolution() << "\n"; + std::clog << boost::format("GDAL Plugin: StartX=%d StartY=%d Width=%d Height=%d \n") % x_off % y_off % width % height; #endif if (width > 0 && height > 0) @@ -144,12 +144,12 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) im_height = height; } - mapnik::ImageData32 image(im_width, im_height); + mapnik::image_data_32 image(im_width, im_height); image.set(0xffffffff); #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: Image Size=(" << im_width << "," << im_height << ")\n"; - std::cout << "GDAL Plugin: Reading band " << band_ << "\n"; + std::clog << "GDAL Plugin: Image Size=(" << im_width << "," << im_height << ")\n"; + std::clog << "GDAL Plugin: Reading band " << band_ << "\n"; #endif if (band_>0) // we are querying a single band @@ -179,38 +179,38 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) case GCI_RedBand: red = band; #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: Found red band" << "\n"; + std::clog << "GDAL Plugin: Found red band" << "\n"; #endif break; case GCI_GreenBand: green = band; #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: Found green band" << "\n"; + std::clog << "GDAL Plugin: Found green band" << "\n"; #endif break; case GCI_BlueBand: blue = band; #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: Found blue band" << "\n"; + std::clog << "GDAL Plugin: Found blue band" << "\n"; #endif break; case GCI_AlphaBand: alpha = band; #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: Found alpha band" << "\n"; + std::clog << "GDAL Plugin: Found alpha band" << "\n"; #endif break; case GCI_GrayIndex: grey = band; #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: Found gray band" << "\n"; + std::clog << "GDAL Plugin: Found gray band" << "\n"; #endif break; case GCI_PaletteIndex: { grey = band; #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: Found gray band, and colortable..." << "\n"; + std::clog << "GDAL Plugin: Found gray band, and colortable..." << "\n"; #endif GDALColorTable *color_table = band->GetColorTable(); @@ -218,14 +218,14 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) { int count = color_table->GetColorEntryCount(); #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: Color Table count = " << count << "\n"; + std::clog << "GDAL Plugin: Color Table count = " << count << "\n"; #endif for ( int i = 0; i < count; i++ ) { const GDALColorEntry *ce = color_table->GetColorEntry ( i ); if (!ce ) continue; #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: Color entry RGB (" << ce->c1 << "," <c2 << "," << ce->c3 << ")\n"; + std::clog << "GDAL Plugin: Color entry RGB (" << ce->c1 << "," <c2 << "," << ce->c3 << ")\n"; #endif } } @@ -233,13 +233,13 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) } case GCI_Undefined: #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: Found undefined band (assumming gray band)" << "\n"; + std::clog << "GDAL Plugin: Found undefined band (assumming gray band)" << "\n"; #endif grey = band; break; default: #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: band type unknown!" << "\n"; + std::clog << "GDAL Plugin: band type unknown!" << "\n"; #endif break; } @@ -248,7 +248,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) if (red && green && blue) { #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: processing rgb bands..." << "\n"; + std::clog << "GDAL Plugin: processing rgb bands..." << "\n"; #endif red->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 0, image.width(),image.height(),GDT_Byte,4,4*image.width()); @@ -260,7 +260,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) else if (grey) { #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: processing gray band..." << "\n"; + std::clog << "GDAL Plugin: processing gray band..." << "\n"; #endif grey->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 0, image.width(),image.height(),GDT_Byte, 4, 4 * image.width()); @@ -273,7 +273,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) if (alpha) { #ifdef MAPNIK_DEBUG - std::cout << "GDAL Plugin: processing alpha band..." << "\n"; + std::clog << "GDAL Plugin: processing alpha band..." << "\n"; #endif alpha->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 3, image.width(),image.height(),GDT_Byte,4,4*image.width()); @@ -308,8 +308,8 @@ feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt) if(0<=x && xGetOverviewCount(); if (band_overviews > 0) { - std::cout << "GDAL Plugin: "<< band_overviews << " overviews found!" << "\n"; + std::clog << "GDAL Plugin: "<< band_overviews << " overviews found!" << "\n"; for (int b = 0; b < band_overviews; b++) { GDALRasterBand * overview = band->GetOverview (b); - std::cout << boost::format("GDAL Plugin: Overview=%d Width=%d Height=%d \n") + std::clog << boost::format("GDAL Plugin: Overview=%d Width=%d Height=%d \n") % b % overview->GetXSize() % overview->GetYSize(); } } else { - std::cout << "GDAL Plugin: No overviews found!" << "\n"; + std::clog << "GDAL Plugin: No overviews found!" << "\n"; } int bsx,bsy; double scale; band->GetBlockSize(&bsx,&bsy); scale = band->GetScale(); - std::cout << boost::format("GDAL Plugin: Block=%dx%d Scale=%f Type=%s Color=%s \n") % bsx % bsy % scale + std::clog << boost::format("GDAL Plugin: Block=%dx%d Scale=%f Type=%s Color=%s \n") % bsx % bsy % scale % GDALGetDataTypeName(band->GetRasterDataType()) % GDALGetColorInterpretationName(band->GetColorInterpretation()); } diff --git a/plugins/input/kismet/kismet_datasource.cpp b/plugins/input/kismet/kismet_datasource.cpp index dcab30c40..4c0e2711a 100644 --- a/plugins/input/kismet/kismet_datasource.cpp +++ b/plugins/input/kismet/kismet_datasource.cpp @@ -57,7 +57,7 @@ using mapnik::parameters; DATASOURCE_PLUGIN(kismet_datasource) -using mapnik::Envelope; +using mapnik::box2d; using mapnik::coord2d; using mapnik::query; using mapnik::featureset_ptr; @@ -141,7 +141,7 @@ int kismet_datasource::type() const return type_; } -Envelope kismet_datasource::envelope() const +box2d kismet_datasource::envelope() const { //cout << "kismet_datasource::envelope()" << endl; return extent_; @@ -156,8 +156,8 @@ featureset_ptr kismet_datasource::features(query const& q) const { //cout << "kismet_datasource::features()" << endl; - // TODO: use Envelope to filter bbox before adding to featureset_ptr - //mapnik::Envelope const& e = q.get_bbox(); + // TODO: use box2d to filter bbox before adding to featureset_ptr + //mapnik::box2d const& e = q.get_bbox(); boost::mutex::scoped_lock lock(knd_list_mutex); return featureset_ptr (new kismet_featureset(knd_list, desc_.get_encoding())); diff --git a/plugins/input/kismet/kismet_datasource.hpp b/plugins/input/kismet/kismet_datasource.hpp index dc3b5210e..a18b216af 100644 --- a/plugins/input/kismet/kismet_datasource.hpp +++ b/plugins/input/kismet/kismet_datasource.hpp @@ -50,14 +50,14 @@ class kismet_datasource : public mapnik::datasource static std::string name(); mapnik::featureset_ptr features(mapnik::query const& q) const; mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::Envelope envelope() const; + mapnik::box2d envelope() const; mapnik::layer_descriptor get_descriptor() const; private: void run (const std::string &host, const unsigned int port); static const std::string name_; - mapnik::Envelope extent_; + mapnik::box2d extent_; mutable bool extent_initialized_; int type_; mapnik::layer_descriptor desc_; diff --git a/plugins/input/kismet/kismet_featureset.cpp b/plugins/input/kismet/kismet_featureset.cpp index 41df4ccc1..414e81242 100644 --- a/plugins/input/kismet/kismet_featureset.cpp +++ b/plugins/input/kismet/kismet_featureset.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include diff --git a/plugins/input/occi/occi_datasource.cpp b/plugins/input/occi/occi_datasource.cpp index 82ca1f040..42098f199 100644 --- a/plugins/input/occi/occi_datasource.cpp +++ b/plugins/input/occi/occi_datasource.cpp @@ -53,7 +53,7 @@ using mapnik::featureset_ptr; using mapnik::layer_descriptor; using mapnik::attribute_descriptor; using mapnik::datasource_exception; -using mapnik::Envelope; +using mapnik::box2d; using mapnik::coord2d; using oracle::occi::Environment; @@ -290,7 +290,7 @@ int occi_datasource::type() const return type_; } -Envelope occi_datasource::envelope() const +box2d occi_datasource::envelope() const { if (extent_initialized_) return extent_; @@ -407,7 +407,7 @@ featureset_ptr occi_datasource::features(query const& q) const { if (pool_) { - Envelope const& box=q.get_bbox(); + box2d const& box=q.get_bbox(); std::ostringstream s; s << "select " << geometry_field_ << " as geom"; diff --git a/plugins/input/occi/occi_datasource.hpp b/plugins/input/occi/occi_datasource.hpp index 1c0472827..35b22421c 100644 --- a/plugins/input/occi/occi_datasource.hpp +++ b/plugins/input/occi/occi_datasource.hpp @@ -26,7 +26,7 @@ // mapnik #include -#include +#include #include #include @@ -45,7 +45,7 @@ class occi_datasource : public mapnik::datasource static std::string name(); mapnik::featureset_ptr features(mapnik::query const& q) const; mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::Envelope envelope() const; + mapnik::box2d envelope() const; mapnik::layer_descriptor get_descriptor() const; private: const std::string uri_; @@ -57,7 +57,7 @@ class occi_datasource : public mapnik::datasource int type_; int srid_; mutable bool extent_initialized_; - mutable mapnik::Envelope extent_; + mutable mapnik::box2d extent_; const int row_limit_; const int row_prefetch_; mapnik::layer_descriptor desc_; diff --git a/plugins/input/occi/occi_featureset.cpp b/plugins/input/occi/occi_featureset.cpp index f4d02fd9d..08175295b 100644 --- a/plugins/input/occi/occi_featureset.cpp +++ b/plugins/input/occi/occi_featureset.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include @@ -37,7 +37,7 @@ using std::clog; using std::endl; using mapnik::query; -using mapnik::Envelope; +using mapnik::box2d; using mapnik::CoordTransform; using mapnik::Feature; using mapnik::feature_ptr; diff --git a/plugins/input/ogr/ogr_converter.cpp b/plugins/input/ogr/ogr_converter.cpp index 5cb5e1c79..41fc4e489 100644 --- a/plugins/input/ogr/ogr_converter.cpp +++ b/plugins/input/ogr/ogr_converter.cpp @@ -22,7 +22,7 @@ //$Id$ #include -#include +#include #include #include #include @@ -44,7 +44,7 @@ using mapnik::polygon_impl; /* using mapnik::query; -using mapnik::Envelope; +using mapnik::box2d; using mapnik::CoordTransform; using mapnik::Feature; */ diff --git a/plugins/input/ogr/ogr_datasource.cpp b/plugins/input/ogr/ogr_datasource.cpp index a7cc5efe7..425795546 100644 --- a/plugins/input/ogr/ogr_datasource.cpp +++ b/plugins/input/ogr/ogr_datasource.cpp @@ -44,7 +44,7 @@ using mapnik::parameters; DATASOURCE_PLUGIN(ogr_datasource) -using mapnik::Envelope; +using mapnik::box2d; using mapnik::coord2d; using mapnik::query; using mapnik::featureset_ptr; @@ -203,7 +203,7 @@ int ogr_datasource::type() const return type_; } -Envelope ogr_datasource::envelope() const +box2d ogr_datasource::envelope() const { return extent_; } diff --git a/plugins/input/ogr/ogr_datasource.hpp b/plugins/input/ogr/ogr_datasource.hpp index 4657d337e..9593c20e0 100644 --- a/plugins/input/ogr/ogr_datasource.hpp +++ b/plugins/input/ogr/ogr_datasource.hpp @@ -44,10 +44,10 @@ class ogr_datasource : public mapnik::datasource static std::string name(); mapnik::featureset_ptr features(mapnik::query const& q) const; mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::Envelope envelope() const; + mapnik::box2d envelope() const; mapnik::layer_descriptor get_descriptor() const; private: - mapnik::Envelope extent_; + mapnik::box2d extent_; int type_; std::string dataset_name_; std::string index_name_; diff --git a/plugins/input/ogr/ogr_featureset.cpp b/plugins/input/ogr/ogr_featureset.cpp index 8e8e14135..07fef9807 100644 --- a/plugins/input/ogr/ogr_featureset.cpp +++ b/plugins/input/ogr/ogr_featureset.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include @@ -39,7 +39,7 @@ using std::clog; using std::endl; using mapnik::query; -using mapnik::Envelope; +using mapnik::box2d; using mapnik::CoordTransform; using mapnik::Feature; using mapnik::feature_ptr; @@ -65,7 +65,7 @@ ogr_featureset::ogr_featureset(OGRDataSource & dataset, ogr_featureset::ogr_featureset(OGRDataSource & dataset, OGRLayer & layer, - const mapnik::Envelope & extent, + const mapnik::box2d & extent, const std::string& encoding, const bool multiple_geometries) : dataset_(dataset), diff --git a/plugins/input/ogr/ogr_featureset.hpp b/plugins/input/ogr/ogr_featureset.hpp index 2f38d13b4..f28a3e6ca 100644 --- a/plugins/input/ogr/ogr_featureset.hpp +++ b/plugins/input/ogr/ogr_featureset.hpp @@ -53,7 +53,7 @@ class ogr_featureset : public mapnik::Featureset ogr_featureset(OGRDataSource & dataset, OGRLayer & layer, - const mapnik::Envelope & extent, + const mapnik::box2d & extent, const std::string& encoding, const bool multiple_geometries); virtual ~ogr_featureset(); diff --git a/plugins/input/ogr/ogr_index.hpp b/plugins/input/ogr/ogr_index.hpp index 49a15ed69..bebcbd804 100644 --- a/plugins/input/ogr/ogr_index.hpp +++ b/plugins/input/ogr/ogr_index.hpp @@ -27,10 +27,10 @@ #include #include // mapnik -#include +#include #include -using mapnik::Envelope; +using mapnik::box2d; using mapnik::query; template @@ -44,7 +44,7 @@ private: ogr_index(const ogr_index&); ogr_index& operator=(const ogr_index&); static int read_ndr_integer(IStream & in); - static void read_envelope(IStream & in,Envelope &envelope); + static void read_envelope(IStream & in,box2d &envelope); static void query_node(const filterT& filter,IStream & in,std::vector& pos); }; @@ -60,7 +60,7 @@ void ogr_index::query_node(const filterT& filter,IStream & fil { int offset=read_ndr_integer(file); - Envelope node_ext; + box2d node_ext; read_envelope(file,node_ext); int num_shapes=read_ndr_integer(file); @@ -96,7 +96,7 @@ int ogr_index::read_ndr_integer(IStream & file) template -void ogr_index::read_envelope(IStream & file,Envelope& envelope) +void ogr_index::read_envelope(IStream & file,box2d& envelope) { file.read(reinterpret_cast(&envelope),sizeof(envelope)); } diff --git a/plugins/input/ogr/ogr_index_featureset.cpp b/plugins/input/ogr/ogr_index_featureset.cpp index 16deae23d..e3d6ba61a 100644 --- a/plugins/input/ogr/ogr_index_featureset.cpp +++ b/plugins/input/ogr/ogr_index_featureset.cpp @@ -24,7 +24,7 @@ // mapnik #include #include -#include +#include #include #include #include @@ -46,7 +46,7 @@ using std::clog; using std::endl; using mapnik::query; -using mapnik::Envelope; +using mapnik::box2d; using mapnik::CoordTransform; using mapnik::Feature; using mapnik::feature_ptr; diff --git a/plugins/input/osm/demo/MapSource.cpp b/plugins/input/osm/demo/MapSource.cpp index 951e7f57f..dc2da2490 100644 --- a/plugins/input/osm/demo/MapSource.cpp +++ b/plugins/input/osm/demo/MapSource.cpp @@ -236,7 +236,7 @@ void MapSource::generateMaps() cerr<<"x: " << tileX << " y: " << tileY <<" z: " << z << endl; - Image32 buf(m.getWidth(),m.getHeight()); + image_32 buf(m.getWidth(),m.getHeight()); double metres_w =( (tileX*256.0) * metres_per_pixel ) - 20037814.088; @@ -246,20 +246,20 @@ void MapSource::generateMaps() double metres_e = metres_w + (metres_per_pixel*256); double metres_n = metres_s + (metres_per_pixel*256); - Envelope bb + box2d bb (metres_w-32*metres_per_pixel, metres_s-32*metres_per_pixel, metres_e+32*metres_per_pixel, metres_n+32*metres_per_pixel); m.zoomToBox(bb); - agg_renderer r(m,buf); + agg_renderer r(m,buf); r.apply(); string filename=""; std::ostringstream str; str<< z<< "."<(buf.data(), + save_to_file(buf.data(), "tmp.png","png"); FILE *in=fopen("tmp.png","r"); FILE *out=fopen(str.str().c_str(),"w"); @@ -290,24 +290,24 @@ void MapSource::generateMaps() load_map(m,xmlfile); setOSMLayers(m,p); - Envelope latlon= + box2d latlon= (hasBbox()) ? - Envelope(w,s,e,n): + box2d(w,s,e,n): m.getLayer(0).envelope(); EarthPoint bottomL_LL = GoogleProjection::fromLLToGoog(latlon.minx(),latlon.miny()), topR_LL = GoogleProjection::fromLLToGoog(latlon.maxx(),latlon.maxy()); - Envelope bb = - Envelope(bottomL_LL.x,bottomL_LL.y, + box2d bb = + box2d(bottomL_LL.x,bottomL_LL.y, topR_LL.x,topR_LL.y); m.zoomToBox(bb); - Image32 buf (m.getWidth(), m.getHeight()); - agg_renderer r(m,buf); + image_32 buf (m.getWidth(), m.getHeight()); + agg_renderer r(m,buf); r.apply(); - save_to_file(buf.data(),outfile,"png"); + save_to_file(buf.data(),outfile,"png"); } } @@ -381,12 +381,12 @@ void MapSource::addSRTMLayers(Map& m,double w,double s,double e,double n) <<(lon>=0 ? lon:-lon)<<"c10"; p["file"] = str.str(); cerr<<"ADDING SRTM LAYER: " << p["file"] << endl; - Layer layer("srtm_" + str.str()); - layer.add_style("contours"); - layer.add_style("contours-text"); - layer.set_datasource + layer lyr("srtm_" + str.str()); + lyr.add_style("contours"); + lyr.add_style("contours-text"); + lyr.set_datasource (datasource_cache::instance()->create(p)); - m.addLayer(layer); + m.addLayer(lyr); } } } diff --git a/plugins/input/osm/osm_datasource.cpp b/plugins/input/osm/osm_datasource.cpp index 48916fca6..8345dc788 100644 --- a/plugins/input/osm/osm_datasource.cpp +++ b/plugins/input/osm/osm_datasource.cpp @@ -99,7 +99,7 @@ osm_datasource::osm_datasource(const parameters ¶ms) // Get the bounds of the data and set extent_ accordingly bounds b = osm_data_->get_bounds(); - extent_ = Envelope(b.w,b.s,b.e,b.n); + extent_ = box2d(b.w,b.s,b.e,b.n); } } @@ -156,7 +156,7 @@ featureset_ptr osm_datasource::features_at_point(coord2d const& pt) const desc_.get_encoding())); } -Envelope osm_datasource::envelope() const +box2d osm_datasource::envelope() const { return extent_; } diff --git a/plugins/input/osm/osm_datasource.hpp b/plugins/input/osm/osm_datasource.hpp index d5aadb440..2dd736de6 100644 --- a/plugins/input/osm/osm_datasource.hpp +++ b/plugins/input/osm/osm_datasource.hpp @@ -26,7 +26,7 @@ #define OSM_DATASOURCE_HPP #include -#include +#include #include "osm.h" @@ -37,7 +37,7 @@ using mapnik::query; using mapnik::featureset_ptr; using mapnik::layer_descriptor; using mapnik::coord2d; -using mapnik::Envelope; +using mapnik::box2d; class osm_datasource : public datasource { @@ -49,7 +49,7 @@ class osm_datasource : public datasource int type() const; featureset_ptr features(const query& q) const; featureset_ptr features_at_point(coord2d const& pt) const; - Envelope envelope() const; + box2d envelope() const; layer_descriptor get_descriptor() const; static std::string name() { return name_; } @@ -57,7 +57,7 @@ class osm_datasource : public datasource osm_datasource(const osm_datasource&); osm_datasource& operator=(const osm_datasource&); private: - Envelope extent_; + box2d extent_; osm_dataset * osm_data_; int type_; layer_descriptor desc_; diff --git a/plugins/input/osm/osm_featureset.cpp b/plugins/input/osm/osm_featureset.cpp index e33226e55..1a4c12e37 100644 --- a/plugins/input/osm/osm_featureset.cpp +++ b/plugins/input/osm/osm_featureset.cpp @@ -76,7 +76,7 @@ feature_ptr osm_featureset::next() // Loop until we find a feature which passes the filter while(cur_item != NULL && - !filter_.pass(Envelope(b.w,b.s,b.e,b.n))) + !filter_.pass(box2d(b.w,b.s,b.e,b.n))) { cur_item = dataset_->next_item(); if(cur_item!=NULL) diff --git a/plugins/input/osm/osm_featureset.hpp b/plugins/input/osm/osm_featureset.hpp index 905448c07..ccb20c02e 100644 --- a/plugins/input/osm/osm_featureset.hpp +++ b/plugins/input/osm/osm_featureset.hpp @@ -33,7 +33,7 @@ #include using mapnik::Featureset; -using mapnik::Envelope; +using mapnik::box2d; using mapnik::feature_ptr; using mapnik::transcoder; @@ -41,10 +41,10 @@ template class osm_featureset : public Featureset { filterT filter_; - Envelope query_ext_; + box2d query_ext_; boost::scoped_ptr tr_; std::vector attr_ids_; - mutable Envelope feature_ext_; + mutable box2d feature_ext_; mutable int total_geom_size; mutable int count_; osm_dataset *dataset_; diff --git a/plugins/input/osm/render.cpp b/plugins/input/osm/render.cpp index 5d00b315f..c071ff50e 100644 --- a/plugins/input/osm/render.cpp +++ b/plugins/input/osm/render.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -44,16 +44,16 @@ int main(int argc,char *argv[]) } } - Envelope bbox (atof(argv[2]),atof(argv[3]), + box2d bbox (atof(argv[2]),atof(argv[3]), atof(argv[4]),atof(argv[5])); m.zoomToBox(bbox); - Image32 buf (m.getWidth(), m.getHeight()); - agg_renderer r(m,buf); + image_32 buf (m.getWidth(), m.getHeight()); + agg_renderer r(m,buf); r.apply(); - save_to_file(buf.data(),"blah.png","png"); + save_to_file(buf.data(),"blah.png","png"); return 0; } diff --git a/plugins/input/postgis/postgis.cpp b/plugins/input/postgis/postgis.cpp index f929fc9d4..ff48532db 100644 --- a/plugins/input/postgis/postgis.cpp +++ b/plugins/input/postgis/postgis.cpp @@ -26,11 +26,9 @@ #include #include -/* #ifdef MAPNIK_DEBUG -#include +//#include #endif -*/ #include "connection_manager.hpp" #include "postgis.hpp" @@ -330,7 +328,7 @@ layer_descriptor postgis_datasource::get_descriptor() const } -std::string postgis_datasource::sql_bbox(Envelope const& env) const +std::string postgis_datasource::sql_bbox(box2d const& env) const { std::ostringstream b; if (srid_ > 0) @@ -350,7 +348,7 @@ std::string postgis_datasource::populate_tokens(const std::string& sql) const if ( boost::algorithm::icontains(sql,bbox_token_) ) { - Envelope max_env(-1 * FMAX,-1 * FMAX,FMAX,FMAX); + box2d max_env(-1 * FMAX,-1 * FMAX,FMAX,FMAX); std::string max_box = sql_bbox(max_env); boost::algorithm::replace_all(populated_sql,bbox_token_,max_box); } @@ -362,7 +360,7 @@ std::string postgis_datasource::populate_tokens(const std::string& sql) const return populated_sql; } -std::string postgis_datasource::populate_tokens(const std::string& sql, double const& scale_denom, Envelope const& env) const +std::string postgis_datasource::populate_tokens(const std::string& sql, double const& scale_denom, box2d const& env) const { std::string populated_sql = sql; std::string box = sql_bbox(env); @@ -452,14 +450,11 @@ boost::shared_ptr postgis_datasource::get_resultset(boost::shared_pt featureset_ptr postgis_datasource::features(const query& q) const { - -/* #ifdef MAPNIK_DEBUG - mapnik::wall_clock_progress_timer timer(clog, "end feature query: "); + //mapnik::wall_clock_progress_timer timer(clog, "end feature query: "); #endif -*/ - Envelope const& box = q.get_bbox(); + box2d const& box = q.get_bbox(); double scale_denom = q.scale_denominator(); ConnectionManager *mgr=ConnectionManager::instance(); shared_ptr > pool=mgr->getPool(creator_.id()); @@ -538,7 +533,7 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const ++size; } - Envelope box(pt.x,pt.y,pt.x,pt.y); + box2d box(pt.x,pt.y,pt.x,pt.y); std::string table_with_bbox = populate_tokens(table_,FMAX,box); s << " from " << table_with_bbox; @@ -554,7 +549,7 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const return featureset_ptr(); } -Envelope postgis_datasource::envelope() const +box2d postgis_datasource::envelope() const { if (extent_initialized_) return extent_; diff --git a/plugins/input/postgis/postgis.hpp b/plugins/input/postgis/postgis.hpp index c7300745a..9b79c9cff 100644 --- a/plugins/input/postgis/postgis.hpp +++ b/plugins/input/postgis/postgis.hpp @@ -27,7 +27,7 @@ #include -#include +#include #include #include #include @@ -40,7 +40,7 @@ using mapnik::transcoder; using mapnik::datasource; -using mapnik::Envelope; +using mapnik::box2d; using mapnik::layer_descriptor; using mapnik::featureset_ptr; using mapnik::feature_ptr; @@ -65,7 +65,7 @@ class postgis_datasource : public datasource int type_; int srid_; mutable bool extent_initialized_; - mutable mapnik::Envelope extent_; + mutable mapnik::box2d extent_; layer_descriptor desc_; ConnectionCreator creator_; bool multiple_geometries_; @@ -80,13 +80,13 @@ class postgis_datasource : public datasource int type() const; featureset_ptr features(const query& q) const; featureset_ptr features_at_point(coord2d const& pt) const; - mapnik::Envelope envelope() const; + mapnik::box2d envelope() const; layer_descriptor get_descriptor() const; postgis_datasource(const parameters ¶ms); ~postgis_datasource(); private: - std::string sql_bbox(Envelope const& env) const; - std::string populate_tokens(const std::string& sql, double const& scale_denom, Envelope const& env) const; + std::string sql_bbox(box2d const& env) const; + std::string populate_tokens(const std::string& sql, double const& scale_denom, box2d const& env) const; std::string populate_tokens(const std::string& sql) const; static std::string unquote(const std::string& sql); static std::string table_from_sql(const std::string& sql); diff --git a/plugins/input/raster/raster_datasource.cpp b/plugins/input/raster/raster_datasource.cpp index d24762830..e48c1dcf9 100644 --- a/plugins/input/raster/raster_datasource.cpp +++ b/plugins/input/raster/raster_datasource.cpp @@ -34,7 +34,7 @@ using mapnik::datasource; using mapnik::parameters; -using mapnik::ImageReader; +using mapnik::image_reader; DATASOURCE_PLUGIN(raster_datasource) @@ -82,7 +82,7 @@ raster_datasource::raster_datasource(const parameters& params) try { - std::auto_ptr reader(mapnik::get_image_reader(filename_, format_)); + std::auto_ptr reader(mapnik::get_image_reader(filename_, format_)); if (reader.get()) { width_ = reader->width(); @@ -111,7 +111,7 @@ std::string raster_datasource::name() return name_; } -mapnik::Envelope raster_datasource::envelope() const +mapnik::box2d raster_datasource::envelope() const { return extent_; } @@ -124,8 +124,8 @@ layer_descriptor raster_datasource::get_descriptor() const featureset_ptr raster_datasource::features(query const& q) const { mapnik::CoordTransform t(width_,height_,extent_,0,0); - mapnik::Envelope intersect=extent_.intersect(q.get_bbox()); - mapnik::Envelope ext=t.forward(intersect); + mapnik::box2d intersect=extent_.intersect(q.get_bbox()); + mapnik::box2d ext=t.forward(intersect); unsigned width = int(ext.width() + 0.5); unsigned height = int(ext.height() + 0.5); diff --git a/plugins/input/raster/raster_datasource.hpp b/plugins/input/raster/raster_datasource.hpp index 7b83c9fe0..befeb9fb8 100644 --- a/plugins/input/raster/raster_datasource.hpp +++ b/plugins/input/raster/raster_datasource.hpp @@ -24,7 +24,7 @@ #ifndef RASTER_DATASOURCE_HPP #define RASTER_DATASOURCE_HPP -#include +#include #include #include @@ -33,7 +33,7 @@ class raster_datasource : public mapnik::datasource private: std::string filename_; std::string format_; - mapnik::Envelope extent_; + mapnik::box2d extent_; mapnik::layer_descriptor desc_; unsigned width_; unsigned height_; @@ -45,7 +45,7 @@ public: static std::string name(); mapnik::featureset_ptr features(const mapnik::query& q) const; mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::Envelope envelope() const; + mapnik::box2d envelope() const; mapnik::layer_descriptor get_descriptor() const; private: //no copying diff --git a/plugins/input/raster/raster_featureset.cpp b/plugins/input/raster/raster_featureset.cpp index 600f10469..8ecb5a477 100644 --- a/plugins/input/raster/raster_featureset.cpp +++ b/plugins/input/raster/raster_featureset.cpp @@ -28,15 +28,15 @@ using mapnik::query; using mapnik::CoordTransform; -using mapnik::ImageReader; +using mapnik::image_reader; using mapnik::Feature; using mapnik::feature_ptr; -using mapnik::ImageData32; +using mapnik::image_data_32; using mapnik::raster; template raster_featureset::raster_featureset(LookupPolicy const& policy, - Envelope const& extent, + box2d const& extent, query const& q) : policy_(policy), id_(1), @@ -57,7 +57,7 @@ feature_ptr raster_featureset::next() feature_ptr feature(new Feature(++id_)); try { - std::auto_ptr reader(mapnik::get_image_reader(curIter_->file(),curIter_->format())); + std::auto_ptr reader(mapnik::get_image_reader(curIter_->file(),curIter_->format())); #ifdef MAPNIK_DEBUG std::cout << "Raster Plugin: READER = " << curIter_->format() << " " << curIter_->file() @@ -71,9 +71,9 @@ feature_ptr raster_featureset::next() if (image_width>0 && image_height>0) { CoordTransform t(image_width,image_height,extent_,0,0); - Envelope intersect=bbox_.intersect(curIter_->envelope()); - Envelope ext=t.forward(intersect); - ImageData32 image(int(ext.width()+0.5),int(ext.height()+0.5)); + box2d intersect=bbox_.intersect(curIter_->envelope()); + box2d ext=t.forward(intersect); + image_data_32 image(int(ext.width()+0.5),int(ext.height()+0.5)); reader->read(int(ext.minx()+0.5),int(ext.miny()+0.5),image); feature->set_raster(mapnik::raster_ptr(new raster(intersect,image))); } diff --git a/plugins/input/raster/raster_featureset.hpp b/plugins/input/raster/raster_featureset.hpp index f50bc92e1..d92331df9 100644 --- a/plugins/input/raster/raster_featureset.hpp +++ b/plugins/input/raster/raster_featureset.hpp @@ -82,7 +82,7 @@ public: return const_iterator(this); } - const_iterator query(const Envelope& box) + const_iterator query(const box2d& box) { if (box.intersects(info_.envelope())) { @@ -104,7 +104,7 @@ public: typedef std::vector::const_iterator const_iterator; tiled_file_policy(std::string const& file, std::string const& format, unsigned tile_size, - Envelope extent, Envelope bbox,unsigned width, unsigned height) + box2d extent, box2d bbox,unsigned width, unsigned height) { double lox = extent.minx(); @@ -120,7 +120,7 @@ public: std::cout << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")\n"; #endif - Envelope e = bbox.intersect(extent); + box2d e = bbox.intersect(extent); for (int x = 0 ; x < max_x ; ++x) { @@ -131,9 +131,9 @@ public: double x1 = x0 + tile_size*pixel_x; double y1 = y0 + tile_size*pixel_y; - if (e.intersects(Envelope(x0,y0,x1,y1))) + if (e.intersects(box2d(x0,y0,x1,y1))) { - Envelope tile_box = e.intersect(Envelope(x0,y0,x1,y1)); + box2d tile_box = e.intersect(box2d(x0,y0,x1,y1)); raster_info info(file,format,tile_box,tile_size,tile_size); infos_.push_back(info); } @@ -166,12 +166,12 @@ class raster_featureset : public mapnik::Featureset typedef typename LookupPolicy::const_iterator iterator_type; LookupPolicy policy_; size_t id_; - mapnik::Envelope extent_; - mapnik::Envelope bbox_; + mapnik::box2d extent_; + mapnik::box2d bbox_; iterator_type curIter_; iterator_type endIter_; public: - raster_featureset(LookupPolicy const& policy,Envelope const& exttent, mapnik::query const& q); + raster_featureset(LookupPolicy const& policy,box2d const& exttent, mapnik::query const& q); virtual ~raster_featureset(); mapnik::feature_ptr next(); }; diff --git a/plugins/input/raster/raster_info.cpp b/plugins/input/raster/raster_info.cpp index 52037532b..72ec49a59 100644 --- a/plugins/input/raster/raster_info.cpp +++ b/plugins/input/raster/raster_info.cpp @@ -24,7 +24,7 @@ #include "raster_info.hpp" raster_info::raster_info(std::string const& file, std::string const& format, - mapnik::Envelope const& extent, unsigned width, unsigned height) + mapnik::box2d const& extent, unsigned width, unsigned height) :file_(file), format_(format), extent_(extent), diff --git a/plugins/input/raster/raster_info.hpp b/plugins/input/raster/raster_info.hpp index 61cfcfb5e..63ff43e18 100644 --- a/plugins/input/raster/raster_info.hpp +++ b/plugins/input/raster/raster_info.hpp @@ -27,20 +27,20 @@ #include "raster_datasource.hpp" #include -using mapnik::Envelope; +using mapnik::box2d; class raster_info { std::string file_; std::string format_; - Envelope extent_; + box2d extent_; unsigned width_; unsigned height_; public: - raster_info(const std::string& file,const std::string& format, const Envelope& extent, unsigned width, unsigned height); + raster_info(const std::string& file,const std::string& format, const box2d& extent, unsigned width, unsigned height); raster_info(const raster_info& rhs); raster_info& operator=(const raster_info& rhs); - inline Envelope const& envelope() const {return extent_;} + inline box2d const& envelope() const {return extent_;} inline std::string const& file() const { return file_;} inline std::string const& format() const {return format_;} inline unsigned width() const { return width_;} diff --git a/plugins/input/rasterlite/Makefile.am b/plugins/input/rasterlite/Makefile.am new file mode 100644 index 000000000..648d88d02 --- /dev/null +++ b/plugins/input/rasterlite/Makefile.am @@ -0,0 +1,32 @@ +pkglibdir = $(libdir)/mapnik/input + +if HAVE_GDAL + +pkglib_LTLIBRARIES = \ + rasterlite.la + +rasterlite_la_SOURCES = \ + rasterlite_datasource.cpp\ + rasterlite_datasource.hpp\ + rasterlite_featureset.cpp\ + rasterlite_featureset.hpp\ + rasterlite_include.hpp + +rasterlite_la_LIBADD = \ + ${GDAL_LDFLAGS} + +rasterlite_la_CXXFLAGS = \ + -Wall \ + ${PROFILING_CFLAGS} \ + ${TRACING_CFLAGS} \ + ${GDAL_CFLAGS} \ + -I../../../include + +rasterlite_la_LDFLAGS = \ + -module \ + -avoid-version \ + -shrext .input + +endif + +## File created by the gnome-build tools diff --git a/plugins/input/rasterlite/SConscript b/plugins/input/rasterlite/SConscript new file mode 100644 index 000000000..362d39c2c --- /dev/null +++ b/plugins/input/rasterlite/SConscript @@ -0,0 +1,42 @@ +# +# This file is part of Mapnik (c++ mapping toolkit) +# +# Copyright (C) 2007 Artem Pavlenko, Jean-Francois Doyon +# +# Mapnik 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 +# +# $Id$ + +Import ('env') + +prefix = env['PREFIX'] +install_prefix = env['DESTDIR'] + '/' + prefix + +rasterlite_src = Split( + """ + rasterlite_datasource.cpp + rasterlite_featureset.cpp + """ + ) + +libraries = [env['PLUGINS']['rasterlite']['lib']] +if env['PLATFORM'] == 'Darwin': + libraries.append('mapnik') + libraries.append(env['ICU_LIB_NAME']) + +rasterlite_inputdriver = env.SharedLibrary('rasterlite', source=rasterlite_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries) + +env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', rasterlite_inputdriver) +env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input') diff --git a/plugins/input/rasterlite/rasterlite_datasource.cpp b/plugins/input/rasterlite/rasterlite_datasource.cpp new file mode 100644 index 000000000..eba9dbf9e --- /dev/null +++ b/plugins/input/rasterlite/rasterlite_datasource.cpp @@ -0,0 +1,183 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2007 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 + * + *****************************************************************************/ +// $Id$ + +#include "rasterlite_datasource.hpp" +#include "rasterlite_featureset.hpp" + +// boost +#include + +// mapnik +#include +#include + +using mapnik::datasource; +using mapnik::parameters; + +DATASOURCE_PLUGIN(rasterlite_datasource) + +using mapnik::box2d; +using mapnik::coord2d; +using mapnik::query; +using mapnik::featureset_ptr; +using mapnik::layer_descriptor; +using mapnik::datasource_exception; + + + +/* + * Opens a GDALDataset and returns a pointer to it. + * Caller is responsible for calling GDALClose on it + */ +inline void *rasterlite_datasource::open_dataset() const +{ + void *dataset = rasterliteOpen (dataset_name_.c_str(), table_name_.c_str()); + + if (! dataset) throw datasource_exception("Rasterlite Plugin: Error opening dataset"); + + if (rasterliteIsError (dataset)) + { + std::string error (rasterliteGetLastError(dataset)); + + rasterliteClose (dataset); + + throw datasource_exception(error); + } + + return dataset; +} + + + +rasterlite_datasource::rasterlite_datasource(parameters const& params) + : datasource(params), + desc_(*params.get("type"),"utf-8") +{ +#ifdef MAPNIK_DEBUG + std::clog << "\nRasterlite Plugin: Initializing...\n"; +#endif + + boost::optional file = params.get("file"); + if (!file) throw datasource_exception("missing parameter"); + + boost::optional table = params.get("table"); + if (!table) throw datasource_exception("missing parameter"); + + table_name_ = *table; + + boost::optional base = params.get("base"); + if (base) + dataset_name_ = *base + "/" + *file; + else + dataset_name_ = *file; + + if (!boost::filesystem::exists(dataset_name_)) throw datasource_exception(dataset_name_ + " does not exist"); + + void *dataset = open_dataset(); + + double x0, y0, x1, y1; + if (rasterliteGetExtent (dataset, &x0, &y0, &x1, &y1) != RASTERLITE_OK) + { + std::string error (rasterliteGetLastError(dataset)); + + rasterliteClose (dataset); + + throw datasource_exception(error); + } + + extent_.init(x0,y0,x1,y1); + +#ifdef MAPNIK_DEBUG + int srid, auth_srid; + const char *auth_name; + const char *ref_sys_name; + const char *proj4text; + + int tile_count; + double pixel_x_size, pixel_y_size; + int levels = rasterliteGetLevels (dataset); + + if (rasterliteGetSrid(dataset, &srid, &auth_name, &auth_srid, &ref_sys_name, &proj4text) != RASTERLITE_OK) + { + std::string error (rasterliteGetLastError(dataset)); + + rasterliteClose (dataset); + + throw datasource_exception(error); + } + + std::clog << "Rasterlite Plugin: Data Source=" << rasterliteGetTablePrefix(dataset) << "\n"; + std::clog << "Rasterlite Plugin: SRID=" << srid << "\n"; + std::clog << "Rasterlite Plugin: Authority=" << auth_name << "\n"; + std::clog << "Rasterlite Plugin: AuthSRID=" << auth_srid << "\n"; + std::clog << "Rasterlite Plugin: RefSys Name=" << ref_sys_name << "\n"; + std::clog << "Rasterlite Plugin: Proj4Text=" << proj4text << "\n"; + std::clog << "Rasterlite Plugin: Extent(" << x0 << "," << y0 << " " << x1 << "," << y1 << ")\n"; + std::clog << "Rasterlite Plugin: Levels=" << levels << "\n"; + + for (int i = 0; i < levels; i++) + { + if (rasterliteGetResolution(dataset, i, &pixel_x_size, &pixel_y_size, &tile_count) == RASTERLITE_OK) + { + std::clog << "Rasterlite Plugin: Level=" << i + << " x=" << pixel_x_size << " y=" << pixel_y_size << " tiles=" << tile_count << "\n"; + } + } +#endif + + rasterliteClose(dataset); +} + +rasterlite_datasource::~rasterlite_datasource() {} + +int rasterlite_datasource::type() const +{ + return datasource::Raster; +} + +std::string rasterlite_datasource::name() +{ + return "rasterlite"; +} + +box2d rasterlite_datasource::envelope() const +{ + return extent_; +} + +layer_descriptor rasterlite_datasource::get_descriptor() const +{ + return desc_; +} + +featureset_ptr rasterlite_datasource::features(query const& q) const +{ + rasterlite_query gq = q; + return featureset_ptr(new rasterlite_featureset(open_dataset(), gq)); +} + +featureset_ptr rasterlite_datasource::features_at_point(coord2d const& pt) const +{ + rasterlite_query gq = pt; + return featureset_ptr(new rasterlite_featureset(open_dataset(), gq)); +} diff --git a/plugins/input/rasterlite/rasterlite_datasource.hpp b/plugins/input/rasterlite/rasterlite_datasource.hpp new file mode 100644 index 000000000..839043a81 --- /dev/null +++ b/plugins/input/rasterlite/rasterlite_datasource.hpp @@ -0,0 +1,55 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2007 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 + * + *****************************************************************************/ +//$Id$ + +#ifndef RASTERLITE_DATASOURCE_HPP +#define RASTERLITE_DATASOURCE_HPP + +#include +#include + +#include "rasterlite_include.hpp" + + +class rasterlite_datasource : public mapnik::datasource +{ + public: + rasterlite_datasource(mapnik::parameters const& params); + virtual ~rasterlite_datasource (); + int type() const; + static std::string name(); + mapnik::featureset_ptr features(mapnik::query const& q) const; + mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; + mapnik::box2d envelope() const; + mapnik::layer_descriptor get_descriptor() const; + private: + inline void *open_dataset() const; + mapnik::box2d extent_; + std::string dataset_name_; + std::string table_name_; + mapnik::layer_descriptor desc_; + unsigned width_; + unsigned height_; +}; + + +#endif // RASTERLITE_DATASOURCE_HPP diff --git a/plugins/input/rasterlite/rasterlite_featureset.cpp b/plugins/input/rasterlite/rasterlite_featureset.cpp new file mode 100644 index 000000000..3a8dee8ac --- /dev/null +++ b/plugins/input/rasterlite/rasterlite_featureset.cpp @@ -0,0 +1,154 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2007 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 + * + *****************************************************************************/ +//$Id$ + +#include "rasterlite_featureset.hpp" + +// mapnik +#include + + +using mapnik::query; +using mapnik::coord2d; +using mapnik::box2d; +using mapnik::Feature; +using mapnik::feature_ptr; +using mapnik::CoordTransform; +using mapnik::point_impl; +using mapnik::geometry2d; +using mapnik::query; + + + +rasterlite_featureset::rasterlite_featureset(void* dataset, rasterlite_query q) + : dataset_(dataset), + gquery_(q), + first_(true) +{ + rasterliteSetBackgroundColor(dataset_, 255, 0, 255); + rasterliteSetTransparentColor(dataset_, 255, 0, 255); +} + +rasterlite_featureset::~rasterlite_featureset() +{ +#ifdef MAPNIK_DEBUG + std::clog << "Rasterlite Plugin: closing dataset" << "\n"; +#endif + + rasterliteClose(dataset_); +} + +feature_ptr rasterlite_featureset::next() +{ + if (first_) + { + first_ = false; + + query *q = boost::get(&gquery_); + if(q) { + return get_feature(*q); + } else { + coord2d *p = boost::get(&gquery_); + if(p) { + return get_feature_at_point(*p); + } + } + // should never reach here + } + return feature_ptr(); +} + +feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q) +{ +#ifdef MAPNIK_DEBUG + std::clog << "Rasterlite Plugin: get_feature" << "\n"; +#endif + + feature_ptr feature(new Feature(1)); + + double x0, y0, x1, y1; + rasterliteGetExtent (dataset_, &x0, &y0, &x1, &y1); + + box2d raster_extent(x0,y0,x1,y1); + box2d intersect = raster_extent.intersect(q.get_bbox()); + + int width = static_cast(q.resolution() * intersect.width() + 0.5); + int height = static_cast(q.resolution() * intersect.height() + 0.5); + + double pixel_size = (intersect.width() >= intersect.height()) ? + (intersect.width() / (double) width) : (intersect.height() / (double) height); + +#ifdef MAPNIK_DEBUG + std::clog << "Rasterlite Plugin: Raster extent=" << raster_extent << "\n"; + std::clog << "Rasterlite Plugin: View extent=" << q.get_bbox() << "\n"; + std::clog << "Rasterlite Plugin: Intersect extent=" << intersect << "\n"; + std::clog << "Rasterlite Plugin: Query resolution=" << q.resolution() << "\n"; + std::clog << "Rasterlite Plugin: Size=" << width << " " << height << "\n"; + std::clog << "Rasterlite Plugin: Pixel Size=" << pixel_size << "\n"; +#endif + + if (width > 0 && height > 0) + { + int size; + void *raster; + + if (rasterliteGetRawImageByRect(dataset_, + intersect.minx(), intersect.miny(), intersect.maxx(), intersect.maxy(), + pixel_size, width, height, GAIA_RGBA_ARRAY, &raster, &size) == RASTERLITE_OK) + { + if (size > 0) + { + mapnik::image_data_32 image(width, height); + image.set(0xffffffff); + + unsigned char* raster_data = static_cast(raster); + unsigned char* image_data = image.getBytes(); + + memcpy (image_data, raster_data, size); + + feature->set_raster(mapnik::raster_ptr(new mapnik::raster(intersect,image))); + + free (raster); + +#ifdef MAPNIK_DEBUG + std::clog << "Rasterlite Plugin: Done" << "\n"; +#endif + } + else + { +#ifdef MAPNIK_DEBUG + std::clog << "Rasterlite Plugin: Error=" << rasterliteGetLastError (dataset_) << "\n"; +#endif + } + } + + return feature; + } + return feature_ptr(); +} + + +feature_ptr rasterlite_featureset::get_feature_at_point(mapnik::coord2d const& pt) +{ + return feature_ptr(); +} + diff --git a/plugins/input/rasterlite/rasterlite_featureset.hpp b/plugins/input/rasterlite/rasterlite_featureset.hpp new file mode 100644 index 000000000..1afff7948 --- /dev/null +++ b/plugins/input/rasterlite/rasterlite_featureset.hpp @@ -0,0 +1,50 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2007 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 + * + *****************************************************************************/ +//$Id$ + +#ifndef RASTERLITE_FEATURESET_HPP +#define RASTERLITE_FEATURESET_HPP + +#include +#include + +#include "rasterlite_include.hpp" + + +typedef boost::variant rasterlite_query; + +class rasterlite_featureset : public mapnik::Featureset +{ + public: + + rasterlite_featureset(void* dataset, rasterlite_query q); + virtual ~rasterlite_featureset(); + mapnik::feature_ptr next(); + private: + mapnik::feature_ptr get_feature(mapnik::query const& q); + mapnik::feature_ptr get_feature_at_point(mapnik::coord2d const& p); + void* dataset_; + rasterlite_query gquery_; + bool first_; +}; + +#endif // RASTERLITE_FEATURESET_HPP diff --git a/plugins/input/rasterlite/rasterlite_include.hpp b/plugins/input/rasterlite/rasterlite_include.hpp new file mode 100644 index 000000000..b5dbcb682 --- /dev/null +++ b/plugins/input/rasterlite/rasterlite_include.hpp @@ -0,0 +1,32 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2007 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 + * + *****************************************************************************/ +//$Id$ + +#ifndef RASTERLITE_INCLUDE_HPP +#define RASTERLITE_INCLUDE_HPP + +extern "C" { + #include + #include +} + +#endif // RASTERLITE_FEATURESET_HPP diff --git a/plugins/input/shape/shape.cpp b/plugins/input/shape/shape.cpp index b206ed9bb..66cd26ebc 100644 --- a/plugins/input/shape/shape.cpp +++ b/plugins/input/shape/shape.cpp @@ -138,7 +138,7 @@ void shape_datasource::init(shape_io& shape) if (version!=1000) { - //invalid version number + //invalid version number throw datasource_exception((boost::format("invalid version number: %d") % version).str()); } @@ -239,7 +239,7 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt) const } } -Envelope shape_datasource::envelope() const +box2d shape_datasource::envelope() const { return extent_; } diff --git a/plugins/input/shape/shape.hpp b/plugins/input/shape/shape.hpp index 886410d3c..c3a74380d 100644 --- a/plugins/input/shape/shape.hpp +++ b/plugins/input/shape/shape.hpp @@ -26,7 +26,7 @@ #define SHAPE_HPP #include -#include +#include #include "shape_io.hpp" @@ -47,7 +47,7 @@ class shape_datasource : public datasource static std::string name(); featureset_ptr features(const query& q) const; featureset_ptr features_at_point(coord2d const& pt) const; - Envelope envelope() const; + box2d envelope() const; layer_descriptor get_descriptor() const; private: shape_datasource(const shape_datasource&); @@ -57,7 +57,7 @@ class shape_datasource : public datasource int type_; std::string shape_name_; long file_length_; - Envelope extent_; + box2d extent_; bool indexed_; layer_descriptor desc_; static const std::string name_; diff --git a/plugins/input/shape/shape_featureset.hpp b/plugins/input/shape/shape_featureset.hpp index f416b53fd..32ad3ead8 100644 --- a/plugins/input/shape/shape_featureset.hpp +++ b/plugins/input/shape/shape_featureset.hpp @@ -28,7 +28,7 @@ #include "shape.hpp" using mapnik::Featureset; -using mapnik::Envelope; +using mapnik::box2d; using mapnik::feature_ptr; template @@ -37,11 +37,11 @@ class shape_featureset : public Featureset filterT filter_; int shape_type_; shape_io shape_; - Envelope query_ext_; + box2d query_ext_; boost::scoped_ptr tr_; long file_length_; std::vector attr_ids_; - mutable Envelope feature_ext_; + mutable box2d feature_ext_; mutable int total_geom_size; mutable int count_; public: diff --git a/plugins/input/shape/shape_index_featureset.hpp b/plugins/input/shape/shape_index_featureset.hpp index b7da287c5..6f72dcc4e 100644 --- a/plugins/input/shape/shape_index_featureset.hpp +++ b/plugins/input/shape/shape_index_featureset.hpp @@ -38,7 +38,7 @@ class shape_index_featureset : public Featureset std::vector ids_; std::vector::iterator itr_; std::set attr_ids_; - mutable Envelope feature_ext_; + mutable box2d feature_ext_; mutable int total_geom_size; mutable int count_; diff --git a/plugins/input/shape/shape_io.cpp b/plugins/input/shape/shape_io.cpp index 630e4e09e..e366ab62e 100644 --- a/plugins/input/shape/shape_io.cpp +++ b/plugins/input/shape/shape_io.cpp @@ -74,7 +74,7 @@ int shape_io::type() const return type_; } -const Envelope& shape_io::current_extent() const +const box2d& shape_io::current_extent() const { return cur_extent_; } diff --git a/plugins/input/shape/shape_io.hpp b/plugins/input/shape/shape_io.hpp index 8a3db2338..e41e9d79b 100644 --- a/plugins/input/shape/shape_io.hpp +++ b/plugins/input/shape/shape_io.hpp @@ -44,7 +44,7 @@ struct shape_io : boost::noncopyable unsigned reclength_; unsigned id_; - Envelope cur_extent_; + box2d cur_extent_; public: enum shapeType @@ -72,7 +72,7 @@ struct shape_io : boost::noncopyable dbf_file& dbf(); void move_to(int id); int type() const; - const Envelope& current_extent() const; + const box2d& current_extent() const; geometry2d * read_polyline(); geometry2d * read_polylinem(); geometry2d * read_polylinez(); diff --git a/plugins/input/shape/shapefile.hpp b/plugins/input/shape/shapefile.hpp index a3dca85df..af9b37997 100644 --- a/plugins/input/shape/shapefile.hpp +++ b/plugins/input/shape/shapefile.hpp @@ -26,7 +26,7 @@ #define SHAPEFILE_HPP #include -#include +#include // boost #include #include @@ -37,7 +37,7 @@ #include -using mapnik::Envelope; +using mapnik::box2d; using mapnik::read_int32_ndr; using mapnik::read_int32_xdr; using mapnik::read_double_ndr; @@ -210,7 +210,7 @@ public: return val; } - inline void read_envelope(Envelope& envelope) + inline void read_envelope(box2d& envelope) { #ifndef MAPNIK_BIG_ENDIAN file_.read(reinterpret_cast(&envelope),sizeof(envelope)); diff --git a/plugins/input/shape/shp_index.hpp b/plugins/input/shape/shp_index.hpp index a9dbc5c59..de28c5eb1 100644 --- a/plugins/input/shape/shp_index.hpp +++ b/plugins/input/shape/shp_index.hpp @@ -27,10 +27,10 @@ #include #include // mapnik -#include +#include #include -using mapnik::Envelope; +using mapnik::box2d; using mapnik::query; template @@ -44,7 +44,7 @@ private: shp_index(const shp_index&); shp_index& operator=(const shp_index&); static int read_ndr_integer(IStream & in); - static void read_envelope(IStream & in,Envelope &envelope); + static void read_envelope(IStream & in,box2d &envelope); static void query_node(const filterT& filter,IStream & in,std::vector& pos); }; @@ -60,7 +60,7 @@ void shp_index::query_node(const filterT& filter,IStream & fil { int offset=read_ndr_integer(file); - Envelope node_ext; + box2d node_ext; read_envelope(file,node_ext); int num_shapes=read_ndr_integer(file); @@ -96,7 +96,7 @@ int shp_index::read_ndr_integer(IStream & file) template -void shp_index::read_envelope(IStream & file,Envelope& envelope) +void shp_index::read_envelope(IStream & file,box2d& envelope) { file.read(reinterpret_cast(&envelope),sizeof(envelope)); } diff --git a/plugins/input/sqlite/sqlite_datasource.cpp b/plugins/input/sqlite/sqlite_datasource.cpp index a2e3132bf..08ee402ec 100644 --- a/plugins/input/sqlite/sqlite_datasource.cpp +++ b/plugins/input/sqlite/sqlite_datasource.cpp @@ -44,7 +44,7 @@ using mapnik::parameters; DATASOURCE_PLUGIN(sqlite_datasource) -using mapnik::Envelope; +using mapnik::box2d; using mapnik::coord2d; using mapnik::query; using mapnik::featureset_ptr; @@ -249,7 +249,7 @@ int sqlite_datasource::type() const return type_; } -Envelope sqlite_datasource::envelope() const +box2d sqlite_datasource::envelope() const { return extent_; } @@ -263,7 +263,7 @@ featureset_ptr sqlite_datasource::features(query const& q) const { if (dataset_) { - mapnik::Envelope const& e = q.get_bbox(); + mapnik::box2d const& e = q.get_bbox(); std::ostringstream s; diff --git a/plugins/input/sqlite/sqlite_datasource.hpp b/plugins/input/sqlite/sqlite_datasource.hpp index 3b6f9c0ef..390dc17c9 100644 --- a/plugins/input/sqlite/sqlite_datasource.hpp +++ b/plugins/input/sqlite/sqlite_datasource.hpp @@ -46,11 +46,11 @@ class sqlite_datasource : public mapnik::datasource static std::string name(); mapnik::featureset_ptr features(mapnik::query const& q) const; mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::Envelope envelope() const; + mapnik::box2d envelope() const; mapnik::layer_descriptor get_descriptor() const; private: static const std::string name_; - mapnik::Envelope extent_; + mapnik::box2d extent_; mutable bool extent_initialized_; int type_; std::string dataset_name_; diff --git a/plugins/input/sqlite/sqlite_featureset.cpp b/plugins/input/sqlite/sqlite_featureset.cpp index 6b889b965..eb0c10c7c 100644 --- a/plugins/input/sqlite/sqlite_featureset.cpp +++ b/plugins/input/sqlite/sqlite_featureset.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include @@ -37,7 +37,7 @@ using std::clog; using std::endl; using mapnik::query; -using mapnik::Envelope; +using mapnik::box2d; using mapnik::CoordTransform; using mapnik::Feature; using mapnik::feature_ptr; diff --git a/src/SConscript b/src/SConscript index 65e3626b1..c5a30608d 100644 --- a/src/SConscript +++ b/src/SConscript @@ -74,12 +74,14 @@ source = Split( """ agg_renderer.cpp datasource_cache.cpp + box2d.cpp color.cpp - envelope.cpp + expression_string.cpp filter_factory.cpp font_engine_freetype.cpp font_set.cpp graphics.cpp + image_cache.cpp image_reader.cpp image_util.cpp layer.cpp diff --git a/src/agg_renderer.cpp b/src/agg_renderer.cpp index 56777524c..1b9b2e9fc 100644 --- a/src/agg_renderer.cpp +++ b/src/agg_renderer.cpp @@ -24,12 +24,14 @@ // mapnik #include #include +#include #include #include #include #include #include #include +#include // agg #define AGG_RENDERING_BUFFER row_ptr_cache @@ -76,170 +78,170 @@ namespace mapnik { - class pattern_source : private boost::noncopyable - { - public: - pattern_source(ImageData32 const& pattern) - : pattern_(pattern) {} +class pattern_source : private boost::noncopyable +{ +public: + pattern_source(image_data_32 const& pattern) + : pattern_(pattern) {} - unsigned int width() const - { - return pattern_.width(); - } - unsigned int height() const - { - return pattern_.height(); - } - agg::rgba8 pixel(int x, int y) const - { - unsigned c = pattern_(x,y); - return agg::rgba8(c & 0xff, - (c >> 8) & 0xff, - (c >> 16) & 0xff, - (c >> 24) & 0xff); - } - private: - ImageData32 const& pattern_; - }; + unsigned int width() const + { + return pattern_.width(); + } + unsigned int height() const + { + return pattern_.height(); + } + agg::rgba8 pixel(int x, int y) const + { + unsigned c = pattern_(x,y); + return agg::rgba8(c & 0xff, + (c >> 8) & 0xff, + (c >> 16) & 0xff, + (c >> 24) & 0xff); + } +private: + image_data_32 const& pattern_; +}; - struct rasterizer : agg::rasterizer_scanline_aa<>, boost::noncopyable {}; +struct rasterizer : agg::rasterizer_scanline_aa<>, boost::noncopyable {}; - template - agg_renderer::agg_renderer(Map const& m, T & pixmap, unsigned offset_x, unsigned offset_y) - : feature_style_processor(m), - pixmap_(pixmap), - width_(pixmap_.width()), - height_(pixmap_.height()), - t_(m.getWidth(),m.getHeight(),m.getCurrentExtent(),offset_x,offset_y), - font_engine_(), - font_manager_(font_engine_), - detector_(Envelope(-m.buffer_size(), -m.buffer_size(), m.getWidth() + m.buffer_size() ,m.getHeight() + m.buffer_size())), - ras_ptr(new rasterizer) - { - boost::optional bg = m.background(); - if (bg) pixmap_.setBackground(*bg); +template +agg_renderer::agg_renderer(Map const& m, T & pixmap, unsigned offset_x, unsigned offset_y) + : feature_style_processor(m), + pixmap_(pixmap), + width_(pixmap_.width()), + height_(pixmap_.height()), + t_(m.getWidth(),m.getHeight(),m.getCurrentExtent(),offset_x,offset_y), + font_engine_(), + font_manager_(font_engine_), + detector_(box2d(-m.buffer_size(), -m.buffer_size(), m.getWidth() + m.buffer_size() ,m.getHeight() + m.buffer_size())), + ras_ptr(new rasterizer) +{ + boost::optional bg = m.background(); + if (bg) pixmap_.set_background(*bg); #ifdef MAPNIK_DEBUG - std::clog << "scale=" << m.scale() << "\n"; + std::clog << "scale=" << m.scale() << "\n"; #endif - } +} - template - agg_renderer::~agg_renderer() {} +template +agg_renderer::~agg_renderer() {} - template - void agg_renderer::start_map_processing(Map const& map) - { +template +void agg_renderer::start_map_processing(Map const& map) +{ #ifdef MAPNIK_DEBUG - std::clog << "start map processing bbox=" - << map.getCurrentExtent() << "\n"; + std::clog << "start map processing bbox=" + << map.getCurrentExtent() << "\n"; #endif - ras_ptr->clip_box(0,0,width_,height_); - } + ras_ptr->clip_box(0,0,width_,height_); +} - template - void agg_renderer::end_map_processing(Map const& ) - { +template +void agg_renderer::end_map_processing(Map const& ) +{ #ifdef MAPNIK_DEBUG - std::clog << "end map processing\n"; + std::clog << "end map processing\n"; #endif - } +} - template - void agg_renderer::start_layer_processing(Layer const& lay) - { +template +void agg_renderer::start_layer_processing(layer const& lay) +{ #ifdef MAPNIK_DEBUG - std::clog << "start layer processing : " << lay.name() << "\n"; - std::clog << "datasource = " << lay.datasource().get() << "\n"; + std::clog << "start layer processing : " << lay.name() << "\n"; + std::clog << "datasource = " << lay.datasource().get() << "\n"; #endif - if (lay.clear_label_cache()) - { - detector_.clear(); - } - } + if (lay.clear_label_cache()) + { + detector_.clear(); + } +} - template - void agg_renderer::end_layer_processing(Layer const&) - { +template +void agg_renderer::end_layer_processing(layer const&) +{ #ifdef MAPNIK_DEBUG - std::clog << "end layer processing\n"; + std::clog << "end layer processing\n"; #endif - } +} - template - void agg_renderer::process(polygon_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; - typedef agg::renderer_base ren_base; - typedef agg::renderer_scanline_aa_solid renderer; +template +void agg_renderer::process(polygon_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; + typedef agg::renderer_base ren_base; + typedef agg::renderer_scanline_aa_solid renderer; - color const& fill_ = sym.get_fill(); - agg::scanline_u8 sl; + color const& fill_ = sym.get_fill(); + agg::scanline_u8 sl; - agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); - agg::pixfmt_rgba32_plain pixf(buf); + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); - ren_base renb(pixf); - unsigned r=fill_.red(); - unsigned g=fill_.green(); - unsigned b=fill_.blue(); - unsigned a=fill_.alpha(); - renderer ren(renb); + ren_base renb(pixf); + unsigned r=fill_.red(); + unsigned g=fill_.green(); + unsigned b=fill_.blue(); + unsigned a=fill_.alpha(); + renderer ren(renb); - ras_ptr->reset(); + ras_ptr->reset(); - for (unsigned i=0;i 2) - { + for (unsigned i=0;i 2) + { path_type path(t_,geom,prj_trans); ras_ptr->add_path(path); - } - } - ren.color(agg::rgba8(r, g, b, int(a * sym.get_opacity()))); - agg::render_scanlines(*ras_ptr, sl, ren); - } + } + } + ren.color(agg::rgba8(r, g, b, int(a * sym.get_opacity()))); + agg::render_scanlines(*ras_ptr, sl, ren); +} - typedef boost::tuple segment_t; - bool y_order(segment_t const& first,segment_t const& second) - { - double miny0 = std::min(first.get<1>(),first.get<3>()); - double miny1 = std::min(second.get<1>(),second.get<3>()); - return miny0 > miny1; - } +typedef boost::tuple segment_t; +bool y_order(segment_t const& first,segment_t const& second) +{ + double miny0 = std::min(first.get<1>(),first.get<3>()); + double miny1 = std::min(second.get<1>(),second.get<3>()); + return miny0 > miny1; +} - template - void agg_renderer::process(building_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; - typedef coord_transform3 path_type_roof; - typedef agg::renderer_base ren_base; - typedef agg::renderer_scanline_aa_solid renderer; +template +void agg_renderer::process(building_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; + typedef coord_transform3 path_type_roof; + typedef agg::renderer_base ren_base; + typedef agg::renderer_scanline_aa_solid renderer; - agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); - agg::pixfmt_rgba32_plain pixf(buf); - ren_base renb(pixf); + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); + ren_base renb(pixf); - color const& fill_ = sym.get_fill(); - unsigned r=fill_.red(); - unsigned g=fill_.green(); - unsigned b=fill_.blue(); - unsigned a=fill_.alpha(); - renderer ren(renb); - agg::scanline_u8 sl; + color const& fill_ = sym.get_fill(); + unsigned r=fill_.red(); + unsigned g=fill_.green(); + unsigned b=fill_.blue(); + unsigned a=fill_.alpha(); + renderer ren(renb); + agg::scanline_u8 sl; - ras_ptr->reset(); - double height = 0.7071 * sym.height(); // height in meters + ras_ptr->reset(); + double height = 0.7071 * sym.height(); // height in meters - for (unsigned i=0;i 2) - { + for (unsigned i=0;i 2) + { boost::scoped_ptr frame(new line_string_impl); boost::scoped_ptr roof(new polygon_impl); std::deque face_segments; @@ -248,58 +250,58 @@ namespace mapnik unsigned cm = geom.vertex(&x0,&y0); for (unsigned j=1;jmove_to(x,y); - } - else if (cm == SEG_LINETO) - { - frame->line_to(x,y); - } - if (j!=0) - { - face_segments.push_back(segment_t(x0,y0,x,y)); - } - x0 = x; - y0 = y; + double x,y; + cm = geom.vertex(&x,&y); + if (cm == SEG_MOVETO) + { + frame->move_to(x,y); + } + else if (cm == SEG_LINETO) + { + frame->line_to(x,y); + } + if (j!=0) + { + face_segments.push_back(segment_t(x0,y0,x,y)); + } + x0 = x; + y0 = y; } std::sort(face_segments.begin(),face_segments.end(), y_order); std::deque::const_iterator itr=face_segments.begin(); for (;itr!=face_segments.end();++itr) { - boost::scoped_ptr faces(new polygon_impl); - faces->move_to(itr->get<0>(),itr->get<1>()); - faces->line_to(itr->get<2>(),itr->get<3>()); - faces->line_to(itr->get<2>(),itr->get<3>() + height); - faces->line_to(itr->get<0>(),itr->get<1>() + height); + boost::scoped_ptr faces(new polygon_impl); + faces->move_to(itr->get<0>(),itr->get<1>()); + faces->line_to(itr->get<2>(),itr->get<3>()); + faces->line_to(itr->get<2>(),itr->get<3>() + height); + faces->line_to(itr->get<0>(),itr->get<1>() + height); - path_type faces_path (t_,*faces,prj_trans); - ras_ptr->add_path(faces_path); - ren.color(agg::rgba8(int(r*0.8), int(g*0.8), int(b*0.8), int(a * sym.get_opacity()))); - agg::render_scanlines(*ras_ptr, sl, ren); - ras_ptr->reset(); + path_type faces_path (t_,*faces,prj_trans); + ras_ptr->add_path(faces_path); + ren.color(agg::rgba8(int(r*0.8), int(g*0.8), int(b*0.8), int(a * sym.get_opacity()))); + agg::render_scanlines(*ras_ptr, sl, ren); + ras_ptr->reset(); - frame->move_to(itr->get<0>(),itr->get<1>()); - frame->line_to(itr->get<0>(),itr->get<1>()+height); + frame->move_to(itr->get<0>(),itr->get<1>()); + frame->line_to(itr->get<0>(),itr->get<1>()+height); } geom.rewind(0); for (unsigned j=0;jmove_to(x,y+height); - roof->move_to(x,y+height); - } - else if (cm == SEG_LINETO) - { - frame->line_to(x,y+height); - roof->line_to(x,y+height); - } + double x,y; + unsigned cm = geom.vertex(&x,&y); + if (cm == SEG_MOVETO) + { + frame->move_to(x,y+height); + roof->move_to(x,y+height); + } + else if (cm == SEG_LINETO) + { + frame->line_to(x,y+height); + roof->line_to(x,y+height); + } } path_type path(t_,*frame,prj_trans); agg::conv_stroke stroke(path); @@ -312,183 +314,194 @@ namespace mapnik ras_ptr->add_path(roof_path); ren.color(agg::rgba8(r, g, b, int(a * sym.get_opacity()))); agg::render_scanlines(*ras_ptr, sl, ren); - } - } - } + } + } +} - template - void agg_renderer::process(line_symbolizer const& sym, +template +void agg_renderer::process(line_symbolizer const& sym, Feature const& feature, proj_transform const& prj_trans) - { - typedef agg::renderer_base ren_base; - typedef coord_transform2 path_type; - typedef agg::renderer_outline_aa renderer_oaa; - typedef agg::rasterizer_outline_aa rasterizer_outline_aa; - typedef agg::renderer_scanline_aa_solid renderer; +{ + typedef agg::renderer_base ren_base; + typedef coord_transform2 path_type; + typedef agg::renderer_outline_aa renderer_oaa; + typedef agg::rasterizer_outline_aa rasterizer_outline_aa; + typedef agg::renderer_scanline_aa_solid renderer; - agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); - agg::pixfmt_rgba32_plain pixf(buf); + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); - ren_base renb(pixf); - mapnik::stroke const& stroke_ = sym.get_stroke(); - color const& col = stroke_.get_color(); - unsigned r=col.red(); - unsigned g=col.green(); - unsigned b=col.blue(); - unsigned a=col.alpha(); - renderer ren(renb); - ras_ptr->reset(); - agg::scanline_p8 sl; + ren_base renb(pixf); + mapnik::stroke const& stroke_ = sym.get_stroke(); + color const& col = stroke_.get_color(); + unsigned r=col.red(); + unsigned g=col.green(); + unsigned b=col.blue(); + unsigned a=col.alpha(); + renderer ren(renb); + ras_ptr->reset(); + agg::scanline_p8 sl; - for (unsigned i=0;i 1) - { + for (unsigned i=0;i 1) + { path_type path(t_,geom,prj_trans); if (stroke_.has_dash()) { - agg::conv_dash dash(path); - dash_array const& d = stroke_.get_dash_array(); - dash_array::const_iterator itr = d.begin(); - dash_array::const_iterator end = d.end(); - for (;itr != end;++itr) - { - dash.add_dash(itr->first, itr->second); - } + agg::conv_dash dash(path); + dash_array const& d = stroke_.get_dash_array(); + dash_array::const_iterator itr = d.begin(); + dash_array::const_iterator end = d.end(); + for (;itr != end;++itr) + { + dash.add_dash(itr->first, itr->second); + } - agg::conv_stroke > stroke(dash); + agg::conv_stroke > stroke(dash); - line_join_e join=stroke_.get_line_join(); - if ( join == MITER_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == MITER_REVERT_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == ROUND_JOIN) - stroke.generator().line_join(agg::round_join); - else - stroke.generator().line_join(agg::bevel_join); + line_join_e join=stroke_.get_line_join(); + if ( join == MITER_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == MITER_REVERT_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == ROUND_JOIN) + stroke.generator().line_join(agg::round_join); + else + stroke.generator().line_join(agg::bevel_join); - line_cap_e cap=stroke_.get_line_cap(); - if (cap == BUTT_CAP) - stroke.generator().line_cap(agg::butt_cap); - else if (cap == SQUARE_CAP) - stroke.generator().line_cap(agg::square_cap); - else - stroke.generator().line_cap(agg::round_cap); + line_cap_e cap=stroke_.get_line_cap(); + if (cap == BUTT_CAP) + stroke.generator().line_cap(agg::butt_cap); + else if (cap == SQUARE_CAP) + stroke.generator().line_cap(agg::square_cap); + else + stroke.generator().line_cap(agg::round_cap); - stroke.generator().miter_limit(4.0); - stroke.generator().width(stroke_.get_width()); + stroke.generator().miter_limit(4.0); + stroke.generator().width(stroke_.get_width()); - ras_ptr->add_path(stroke); + ras_ptr->add_path(stroke); } else { - agg::conv_stroke stroke(path); - line_join_e join=stroke_.get_line_join(); - if ( join == MITER_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == MITER_REVERT_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == ROUND_JOIN) - stroke.generator().line_join(agg::round_join); - else - stroke.generator().line_join(agg::bevel_join); + agg::conv_stroke stroke(path); + line_join_e join=stroke_.get_line_join(); + if ( join == MITER_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == MITER_REVERT_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == ROUND_JOIN) + stroke.generator().line_join(agg::round_join); + else + stroke.generator().line_join(agg::bevel_join); - line_cap_e cap=stroke_.get_line_cap(); - if (cap == BUTT_CAP) - stroke.generator().line_cap(agg::butt_cap); - else if (cap == SQUARE_CAP) - stroke.generator().line_cap(agg::square_cap); - else - stroke.generator().line_cap(agg::round_cap); + line_cap_e cap=stroke_.get_line_cap(); + if (cap == BUTT_CAP) + stroke.generator().line_cap(agg::butt_cap); + else if (cap == SQUARE_CAP) + stroke.generator().line_cap(agg::square_cap); + else + stroke.generator().line_cap(agg::round_cap); - stroke.generator().miter_limit(4.0); - stroke.generator().width(stroke_.get_width()); - ras_ptr->add_path(stroke); + stroke.generator().miter_limit(4.0); + stroke.generator().width(stroke_.get_width()); + ras_ptr->add_path(stroke); } - } - } - ren.color(agg::rgba8(r, g, b, int(a*stroke_.get_opacity()))); - agg::render_scanlines(*ras_ptr, sl, ren); - } + } + } + ren.color(agg::rgba8(r, g, b, int(a*stroke_.get_opacity()))); + agg::render_scanlines(*ras_ptr, sl, ren); +} - template - void agg_renderer::process(point_symbolizer const& sym, +template +void agg_renderer::process(point_symbolizer const& sym, Feature const& feature, proj_transform const& prj_trans) - { - double x; - double y; - double z=0; - boost::shared_ptr const& data = sym.get_image(); - if ( data ) - { - for (unsigned i=0;i data = mapnik::image_cache::instance()->find(filename,true); + + if ( data ) + { + for (unsigned i=0;iwidth(); - int h = data->height(); + int w = (*data)->width(); + int h = (*data)->height(); int px=int(floor(x - 0.5 * w)); int py=int(floor(y - 0.5 * h)); - Envelope label_ext (floor(x - 0.5 * w), - floor(y - 0.5 * h), - ceil (x + 0.5 * w), - ceil (y + 0.5 * h)); + box2d label_ext (floor(x - 0.5 * w), + floor(y - 0.5 * h), + ceil (x + 0.5 * w), + ceil (y + 0.5 * h)); if (sym.get_allow_overlap() || detector_.has_placement(label_ext)) { - pixmap_.set_rectangle_alpha2(*data,px,py,sym.get_opacity()); - detector_.insert(label_ext); + pixmap_.set_rectangle_alpha2(*(*data),px,py,sym.get_opacity()); + detector_.insert(label_ext); } - } - } - } + } + } +} - template - void agg_renderer::process(shield_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; +template +void agg_renderer::process(shield_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; - UnicodeString text; - if( sym.get_no_text() ) - text = UnicodeString( " " ); // use 'space' as the text to render - else - text = feature[sym.get_name()].to_unicode(); // use text from feature to render + UnicodeString text; + if( sym.get_no_text() ) + text = UnicodeString( " " ); // TODO: fix->use 'space' as the text to render + else + { + expression_ptr name_expr = sym.get_name(); + if (!name_expr) return; + value_type result = boost::apply_visitor(evaluate(feature),*name_expr); + text = result.to_unicode(); + } + + if ( sym.get_text_convert() == TOUPPER) + { + text = text.toUpper(); + } + else if ( sym.get_text_convert() == TOLOWER) + { + text = text.toLower(); + } + + std::string filename = path_processor_type::evaluate( *sym.get_filename(), feature); + boost::optional data = mapnik::image_cache::instance()->find(filename,true); + + if (text.length() > 0 && data) + { + face_set_ptr faces; - if ( sym.get_text_convert() == TOUPPER) - { - text = text.toUpper(); - } - else if ( sym.get_text_convert() == TOLOWER) - { - text = text.toLower(); - } - boost::shared_ptr const& data = sym.get_image(); - if (text.length() > 0 && data) - { - face_set_ptr faces; - - if (sym.get_fontset().size() > 0) - { + if (sym.get_fontset().size() > 0) + { faces = font_manager_.get_face_set(sym.get_fontset()); - } - else - { + } + else + { faces = font_manager_.get_face_set(sym.get_face_name()); - } + } - if (faces->size() > 0) - { + if (faces->size() > 0) + { text_renderer ren(pixmap_, faces); ren.set_pixel_size(sym.get_text_size()); @@ -503,334 +516,346 @@ namespace mapnik faces->get_string_info(info); - int w = data->width(); - int h = data->height(); + int w = (*data)->width(); + int h = (*data)->height(); unsigned num_geom = feature.num_geometries(); for (unsigned i=0;i 0 ) - { - path_type path(t_,geom,prj_trans); + geometry2d const& geom = feature.get_geometry(i); + if (geom.num_points() > 0 ) + { + path_type path(t_,geom,prj_trans); - label_placement_enum how_placed = sym.get_label_placement(); - if (how_placed == POINT_PLACEMENT || how_placed == VERTEX_PLACEMENT) - { - // for every vertex, try and place a shield/text - geom.rewind(0); - for( unsigned jj = 0; jj < geom.num_points(); jj++ ) - { - double label_x; - double label_y; - double z=0.0; - placement text_placement(info, sym, false); - text_placement.avoid_edges = sym.get_avoid_edges(); - text_placement.allow_overlap = sym.get_allow_overlap(); - if( how_placed == VERTEX_PLACEMENT ) - geom.vertex(&label_x,&label_y); // by vertex - else - geom.label_position(&label_x, &label_y); // by middle of line or by point - prj_trans.backward(label_x,label_y, z); - t_.forward(&label_x,&label_y); + label_placement_enum how_placed = sym.get_label_placement(); + if (how_placed == POINT_PLACEMENT || how_placed == VERTEX_PLACEMENT) + { + // for every vertex, try and place a shield/text + geom.rewind(0); + for( unsigned jj = 0; jj < geom.num_points(); jj++ ) + { + double label_x; + double label_y; + double z=0.0; + placement text_placement(info, sym, w, h, false); + text_placement.avoid_edges = sym.get_avoid_edges(); + text_placement.allow_overlap = sym.get_allow_overlap(); + if( how_placed == VERTEX_PLACEMENT ) + geom.vertex(&label_x,&label_y); // by vertex + else + geom.label_position(&label_x, &label_y); // by middle of line or by point + prj_trans.backward(label_x,label_y, z); + t_.forward(&label_x,&label_y); - finder.find_point_placement( text_placement,label_x,label_y,sym.get_vertical_alignment(),sym.get_line_spacing(), - sym.get_character_spacing(),sym.get_horizontal_alignment(),sym.get_justify_alignment() ); + finder.find_point_placement( text_placement,label_x,label_y,sym.get_vertical_alignment(),sym.get_line_spacing(), + sym.get_character_spacing(),sym.get_horizontal_alignment(),sym.get_justify_alignment() ); - // check to see if image overlaps anything too, there is only ever 1 placement found for points and verticies - if( text_placement.placements.size() > 0) - { - double x = text_placement.placements[0].starting_x; - double y = text_placement.placements[0].starting_y; - int px; - int py; - Envelope label_ext; + // check to see if image overlaps anything too, there is only ever 1 placement found for points and verticies + if( text_placement.placements.size() > 0) + { + double x = text_placement.placements[0].starting_x; + double y = text_placement.placements[0].starting_y; + int px; + int py; + box2d label_ext; - if( !sym.get_unlock_image() ) - { // center image at text center position - // remove displacement from image label - position pos = sym.get_displacement(); - double lx = x - boost::get<0>(pos); - double ly = y - boost::get<1>(pos); - px=int(floor(lx - (0.5 * w))) ; - py=int(floor(ly - (0.5 * h))) ; - label_ext.init( floor(lx - 0.5 * w), floor(ly - 0.5 * h), ceil (lx + 0.5 * w), ceil (ly + 0.5 * h) ); - } - else - { // center image at reference location - px=int(floor(label_x - 0.5 * w)); - py=int(floor(label_y - 0.5 * h)); - label_ext.init( floor(label_x - 0.5 * w), floor(label_y - 0.5 * h), ceil (label_x + 0.5 * w), ceil (label_y + 0.5 * h)); - } + if( !sym.get_unlock_image() ) + { // center image at text center position + // remove displacement from image label + position pos = sym.get_displacement(); + double lx = x - boost::get<0>(pos); + double ly = y - boost::get<1>(pos); + px=int(floor(lx - (0.5 * w))) ; + py=int(floor(ly - (0.5 * h))) ; + label_ext.init( floor(lx - 0.5 * w), floor(ly - 0.5 * h), ceil (lx + 0.5 * w), ceil (ly + 0.5 * h) ); + } + else + { // center image at reference location + px=int(floor(label_x - 0.5 * w)); + py=int(floor(label_y - 0.5 * h)); + label_ext.init( floor(label_x - 0.5 * w), floor(label_y - 0.5 * h), ceil (label_x + 0.5 * w), ceil (label_y + 0.5 * h)); + } - if ( sym.get_allow_overlap() || detector_.has_placement(label_ext) ) - { - //pixmap_.set_rectangle_alpha(px,py,*data); - pixmap_.set_rectangle_alpha2(*data,px,py,sym.get_opacity()); - Envelope dim = ren.prepare_glyphs(&text_placement.placements[0]); - ren.render(x,y); - detector_.insert(label_ext); - finder.update_detector(text_placement); - } - } - } - } + if ( sym.get_allow_overlap() || detector_.has_placement(label_ext) ) + { + //pixmap_.set_rectangle_alpha(px,py,*data); + pixmap_.set_rectangle_alpha2(*(*data),px,py,sym.get_opacity()); + box2d dim = ren.prepare_glyphs(&text_placement.placements[0]); + ren.render(x,y); + detector_.insert(label_ext); + finder.update_detector(text_placement); + } + } + } + } - else if (geom.num_points() > 1 && sym.get_label_placement() == LINE_PLACEMENT) - { - placement text_placement(info, sym, true); - text_placement.avoid_edges = sym.get_avoid_edges(); - finder.find_point_placements(text_placement,path); + else if (geom.num_points() > 1 && sym.get_label_placement() == LINE_PLACEMENT) + { + placement text_placement(info, sym, w, h, true); + text_placement.avoid_edges = sym.get_avoid_edges(); + finder.find_point_placements(text_placement,path); - for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii) - { - int w = data->width(); - int h = data->height(); - double x = text_placement.placements[ii].starting_x; - double y = text_placement.placements[ii].starting_y; - - int px=int(x - (w/2)); - int py=int(y - (h/2)); - - pixmap_.set_rectangle_alpha(px,py,*data); - - Envelope dim = ren.prepare_glyphs(&text_placement.placements[ii]); - ren.render(x,y); - } - finder.update_detector(text_placement); - } - } + for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii) + { + int w = (*data)->width(); + int h = (*data)->height(); + double x = text_placement.placements[ii].starting_x; + double y = text_placement.placements[ii].starting_y; + + int px=int(x - (w/2)); + int py=int(y - (h/2)); + + pixmap_.set_rectangle_alpha(px,py,*(*data)); + + box2d dim = ren.prepare_glyphs(&text_placement.placements[ii]); + ren.render(x,y); + } + finder.update_detector(text_placement); + } + } } - } - } - } + } + } +} - template - void agg_renderer::process(line_pattern_symbolizer const& sym, +template +void agg_renderer::process(line_pattern_symbolizer const& sym, Feature const& feature, proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; - typedef agg::line_image_pattern pattern_type; - typedef agg::renderer_base renderer_base; - typedef agg::renderer_outline_image renderer_type; - typedef agg::rasterizer_outline_aa rasterizer_type; +{ + typedef coord_transform2 path_type; + typedef agg::line_image_pattern pattern_type; + typedef agg::renderer_base renderer_base; + typedef agg::renderer_outline_image renderer_type; + typedef agg::rasterizer_outline_aa rasterizer_type; - agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); - agg::pixfmt_rgba32_plain pixf(buf); + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); + + std::string filename = path_processor_type::evaluate( *sym.get_filename(), feature); + boost::optional pat = mapnik::image_cache::instance()->find(filename,true); - ImageData32 pat = * sym.get_image(); - renderer_base ren_base(pixf); - agg::pattern_filter_bilinear_rgba8 filter; - pattern_source source(pat); - pattern_type pattern (filter,source); - renderer_type ren(ren_base, pattern); - ren.clip_box(0,0,width_,height_); - rasterizer_type ras(ren); + if (!pat) return; + + renderer_base ren_base(pixf); + agg::pattern_filter_bilinear_rgba8 filter; + pattern_source source(*(*pat)); + pattern_type pattern (filter,source); + renderer_type ren(ren_base, pattern); + ren.clip_box(0,0,width_,height_); + rasterizer_type ras(ren); - for (unsigned i=0;i 1) - { + for (unsigned i=0;i 1) + { path_type path(t_,geom,prj_trans); ras.add_path(path); - } - } - } + } + } +} - template - void agg_renderer::process(polygon_pattern_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; - typedef agg::renderer_base ren_base; - typedef agg::wrap_mode_repeat wrap_x_type; - typedef agg::wrap_mode_repeat wrap_y_type; - typedef agg::pixfmt_alpha_blend_rgba, agg::pixel32_type> rendering_buffer; - typedef agg::image_accessor_wrap img_source_type; +template +void agg_renderer::process(polygon_pattern_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; + typedef agg::renderer_base ren_base; + typedef agg::wrap_mode_repeat wrap_x_type; + typedef agg::wrap_mode_repeat wrap_y_type; + typedef agg::pixfmt_alpha_blend_rgba, agg::pixel32_type> rendering_buffer; + typedef agg::image_accessor_wrap img_source_type; - typedef agg::span_pattern_rgba span_gen_type; + typedef agg::span_pattern_rgba span_gen_type; - typedef agg::renderer_scanline_aa, - span_gen_type> renderer_type; + typedef agg::renderer_scanline_aa, + span_gen_type> renderer_type; - agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); - agg::pixfmt_rgba32_plain pixf(buf); - ren_base renb(pixf); + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); + ren_base renb(pixf); + + agg::scanline_u8 sl; + ras_ptr->reset(); - agg::scanline_u8 sl; - ras_ptr->reset(); + std::string filename = path_processor_type::evaluate( *sym.get_filename(), feature); + boost::optional pat = mapnik::image_cache::instance()->find(filename,true); - ImageData32 const& pattern = * sym.get_image(); - unsigned w=pattern.width(); - unsigned h=pattern.height(); - agg::row_accessor pattern_rbuf((agg::int8u*)pattern.getBytes(),w,h,w*4); - agg::span_allocator sa; - agg::pixfmt_alpha_blend_rgba, agg::pixel32_type> pixf_pattern(pattern_rbuf); - img_source_type img_src(pixf_pattern); + if (!pat) return; + + unsigned w=(*pat)->width(); + unsigned h=(*pat)->height(); + agg::row_accessor pattern_rbuf((agg::int8u*)(*pat)->getBytes(),w,h,w*4); + agg::span_allocator sa; + agg::pixfmt_alpha_blend_rgba, agg::pixel32_type> pixf_pattern(pattern_rbuf); + img_source_type img_src(pixf_pattern); + + double x0=0,y0=0; + unsigned num_geometries = feature.num_geometries(); + if (num_geometries>0) + { + path_type path(t_,feature.get_geometry(0),prj_trans); + path.vertex(&x0,&y0); + } + unsigned offset_x = unsigned(width_-x0); + unsigned offset_y = unsigned(height_-y0); + span_gen_type sg(img_src, offset_x, offset_y); + renderer_type rp(renb,sa, sg); + for (unsigned i=0;i 2) + { + path_type path(t_,geom,prj_trans); + ras_ptr->add_path(path); + } + } + agg::render_scanlines(*ras_ptr, sl, rp); +} - double x0=0,y0=0; - unsigned num_geometries = feature.num_geometries(); - if (num_geometries>0) - { - path_type path(t_,feature.get_geometry(0),prj_trans); - path.vertex(&x0,&y0); - } - unsigned offset_x = unsigned(width_-x0); - unsigned offset_y = unsigned(height_-y0); - span_gen_type sg(img_src, offset_x, offset_y); - renderer_type rp(renb,sa, sg); - for (unsigned i=0;i 2) - { - path_type path(t_,geom,prj_trans); - ras_ptr->add_path(path); - } - } - agg::render_scanlines(*ras_ptr, sl, rp); - } +template +void agg_renderer::process(raster_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + raster_ptr const& raster=feature.get_raster(); + if (raster) + { + box2d ext=t_.forward(raster->ext_); + image_data_32 target(int(ceil(ext.width())),int(ceil(ext.height()))); + int start_x = int(ext.minx()+0.5); + int start_y = int(ext.miny()+0.5); + + if (sym.get_scaling() == "fast") { + scale_image(target,raster->data_); + } else if (sym.get_scaling() == "bilinear"){ + scale_image_bilinear(target,raster->data_); + } else if (sym.get_scaling() == "bilinear8"){ + scale_image_bilinear8(target,raster->data_); + } else { + scale_image(target,raster->data_); + } + + if (sym.get_mode() == "normal"){ + if (sym.get_opacity() == 1.0) { + pixmap_.set_rectangle(start_x,start_y,target); + } else { + pixmap_.set_rectangle_alpha2(target,start_x,start_y, sym.get_opacity()); + } + } else if (sym.get_mode() == "grain_merge"){ + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); + } else if (sym.get_mode() == "grain_merge2"){ + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); + } else if (sym.get_mode() == "multiply"){ + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); + } else if (sym.get_mode() == "multiply2"){ + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); + } else if (sym.get_mode() == "divide"){ + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); + } else if (sym.get_mode() == "divide2"){ + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); + } else if (sym.get_mode() == "screen"){ + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); + } else if (sym.get_mode() == "hard_light"){ + pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); + } else { + if (sym.get_opacity() == 1.0){ + pixmap_.set_rectangle(start_x,start_y,target); + } else { + pixmap_.set_rectangle_alpha2(target,start_x,start_y, sym.get_opacity()); + } + } + // TODO: other modes? (add,diff,sub,...) + } +} - template - void agg_renderer::process(raster_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - raster_ptr const& raster=feature.get_raster(); - if (raster) - { - Envelope ext=t_.forward(raster->ext_); - ImageData32 target(int(ceil(ext.width())),int(ceil(ext.height()))); - int start_x = int(ext.minx()+0.5); - int start_y = int(ext.miny()+0.5); +template +void agg_renderer::process(markers_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; + typedef agg::renderer_base ren_base; + typedef agg::renderer_scanline_aa_solid renderer; + arrow arrow_; + ras_ptr->reset(); - if (sym.get_scaling() == "fast") { - scale_image(target,raster->data_); - } else if (sym.get_scaling() == "bilinear"){ - scale_image_bilinear(target,raster->data_); - } else if (sym.get_scaling() == "bilinear8"){ - scale_image_bilinear8(target,raster->data_); - } else { - scale_image(target,raster->data_); - } + agg::scanline_u8 sl; + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); + ren_base renb(pixf); - if (sym.get_mode() == "normal"){ - if (sym.get_opacity() == 1.0) { - pixmap_.set_rectangle(start_x,start_y,target); - } else { - pixmap_.set_rectangle_alpha2(target,start_x,start_y, sym.get_opacity()); - } - } else if (sym.get_mode() == "grain_merge"){ - pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); - } else if (sym.get_mode() == "grain_merge2"){ - pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); - } else if (sym.get_mode() == "multiply"){ - pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); - } else if (sym.get_mode() == "multiply2"){ - pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); - } else if (sym.get_mode() == "divide"){ - pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); - } else if (sym.get_mode() == "divide2"){ - pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); - } else if (sym.get_mode() == "screen"){ - pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); - } else if (sym.get_mode() == "hard_light"){ - pixmap_.template merge_rectangle (target,start_x,start_y, sym.get_opacity()); - } else { - if (sym.get_opacity() == 1.0){ - pixmap_.set_rectangle(start_x,start_y,target); - } else { - pixmap_.set_rectangle_alpha2(target,start_x,start_y, sym.get_opacity()); - } - } - // TODO: other modes? (add,diff,sub,...) - } - } - - template - void agg_renderer::process(markers_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; - typedef agg::renderer_base ren_base; - typedef agg::renderer_scanline_aa_solid renderer; - arrow arrow_; - ras_ptr->reset(); - - agg::scanline_u8 sl; - agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); - agg::pixfmt_rgba32_plain pixf(buf); - ren_base renb(pixf); - - unsigned r = 0;// fill_.red(); - unsigned g = 0; //fill_.green(); - unsigned b = 255; //fill_.blue(); - unsigned a = 255; //fill_.alpha(); - renderer ren(renb); - for (unsigned i=0;i 1) - { + unsigned r = 0;// fill_.red(); + unsigned g = 0; //fill_.green(); + unsigned b = 255; //fill_.blue(); + unsigned a = 255; //fill_.alpha(); + renderer ren(renb); + for (unsigned i=0;i 1) + { path_type path(t_,geom,prj_trans); agg::conv_dash dash(path); dash.add_dash(20.0,200.0); markers_converter, - arrow, - label_collision_detector4> - marker(dash, arrow_, detector_); + arrow, + label_collision_detector4> + marker(dash, arrow_, detector_); ras_ptr->add_path(marker); - } - } - ren.color(agg::rgba8(r, g, b, a)); - agg::render_scanlines(*ras_ptr, sl, ren); - } + } + } + ren.color(agg::rgba8(r, g, b, a)); + agg::render_scanlines(*ras_ptr, sl, ren); +} - template - void agg_renderer::process(text_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; +template +void agg_renderer::process(text_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; - UnicodeString text = feature[sym.get_name()].to_unicode(); - if ( sym.get_text_convert() == TOUPPER) - { - text = text.toUpper(); - } - else if ( sym.get_text_convert() == TOLOWER) - { - text = text.toLower(); - } + expression_ptr name_expr = sym.get_name(); + if (!name_expr) return; + value_type result = boost::apply_visitor(evaluate(feature),*name_expr); + UnicodeString text = result.to_unicode(); + + if ( sym.get_text_convert() == TOUPPER) + { + text = text.toUpper(); + } + else if ( sym.get_text_convert() == TOLOWER) + { + text = text.toLower(); + } - if ( text.length() > 0 ) - { - color const& fill = sym.get_fill(); + if ( text.length() > 0 ) + { + color const& fill = sym.get_fill(); - face_set_ptr faces; + face_set_ptr faces; - if (sym.get_fontset().size() > 0) - { + if (sym.get_fontset().size() > 0) + { faces = font_manager_.get_face_set(sym.get_fontset()); - } - else - { + } + else + { faces = font_manager_.get_face_set(sym.get_face_name()); - } + } - if (faces->size() > 0) - { + if (faces->size() > 0) + { text_renderer ren(pixmap_, faces); ren.set_pixel_size(sym.get_text_size()); ren.set_fill(fill); @@ -846,42 +871,42 @@ namespace mapnik unsigned num_geom = feature.num_geometries(); for (unsigned i=0;i 0) // don't bother with empty geometries - { - path_type path(t_,geom,prj_trans); - placement text_placement(info,sym); - text_placement.avoid_edges = sym.get_avoid_edges(); - if (sym.get_label_placement() == POINT_PLACEMENT) - { - double label_x, label_y, z=0.0; - geom.label_position(&label_x, &label_y); - prj_trans.backward(label_x,label_y, z); - t_.forward(&label_x,&label_y); - finder.find_point_placement(text_placement,label_x,label_y,sym.get_vertical_alignment(),sym.get_line_spacing(), - sym.get_character_spacing(),sym.get_horizontal_alignment(),sym.get_justify_alignment()); - finder.update_detector(text_placement); - } - else if ( geom.num_points() > 1 && sym.get_label_placement() == LINE_PLACEMENT) - { - finder.find_line_placements(text_placement,path); - } + geometry2d const& geom = feature.get_geometry(i); + if (geom.num_points() > 0) // don't bother with empty geometries + { + path_type path(t_,geom,prj_trans); + placement text_placement(info,sym); + text_placement.avoid_edges = sym.get_avoid_edges(); + if (sym.get_label_placement() == POINT_PLACEMENT) + { + double label_x, label_y, z=0.0; + geom.label_position(&label_x, &label_y); + prj_trans.backward(label_x,label_y, z); + t_.forward(&label_x,&label_y); + finder.find_point_placement(text_placement,label_x,label_y,sym.get_vertical_alignment(),sym.get_line_spacing(), + sym.get_character_spacing(),sym.get_horizontal_alignment(),sym.get_justify_alignment()); + finder.update_detector(text_placement); + } + else if ( geom.num_points() > 1 && sym.get_label_placement() == LINE_PLACEMENT) + { + finder.find_line_placements(text_placement,path); + } - for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ii) - { - double x = text_placement.placements[ii].starting_x; - double y = text_placement.placements[ii].starting_y; - Envelope dim = ren.prepare_glyphs(&text_placement.placements[ii]); - ren.render(x,y); - } - } + for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ii) + { + double x = text_placement.placements[ii].starting_x; + double y = text_placement.placements[ii].starting_y; + box2d dim = ren.prepare_glyphs(&text_placement.placements[ii]); + ren.render(x,y); + } + } } - } - else - { + } + else + { throw config_error("Unable to find specified font face '" + sym.get_face_name() + "'"); - } - } - } - template class agg_renderer; + } + } +} +template class agg_renderer; } diff --git a/src/arrow.cpp b/src/arrow.cpp index 613fb937e..228e168f3 100644 --- a/src/arrow.cpp +++ b/src/arrow.cpp @@ -58,9 +58,9 @@ namespace mapnik { return agg::path_cmd_stop; } - Envelope arrow::extent() const + box2d arrow::extent() const { - return Envelope(-7,-3,7,3); + return box2d(-7,-3,7,3); } } diff --git a/src/envelope.cpp b/src/box2d.cpp similarity index 78% rename from src/envelope.cpp rename to src/box2d.cpp index 7b43a1609..f3f34a623 100644 --- a/src/envelope.cpp +++ b/src/box2d.cpp @@ -21,28 +21,28 @@ *****************************************************************************/ //$Id: envelope.cpp 17 2005-03-08 23:58:43Z pavlenko $ -#include +#include namespace mapnik { template - Envelope::Envelope() + box2d::box2d() :minx_(0),miny_(0),maxx_(-1),maxy_(-1) {} template - Envelope::Envelope(T minx_,T miny_,T maxx_,T maxy_) + box2d::box2d(T minx_,T miny_,T maxx_,T maxy_) { init(minx_,miny_,maxx_,maxy_); } template - Envelope::Envelope(const coord &c0,const coord &c1) + box2d::box2d(const coord &c0,const coord &c1) { init(c0.x,c0.y,c1.x,c1.y); } template - Envelope::Envelope(const Envelope &rhs) + box2d::box2d(const box2d &rhs) { init(rhs.minx_,rhs.miny_,rhs.maxx_,rhs.maxy_); } @@ -51,7 +51,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - bool Envelope::operator==(const Envelope& other) const + bool box2d::operator==(const box2d& other) const { return minx_==other.minx_ && miny_==other.miny_ && @@ -63,7 +63,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - T Envelope::minx() const + T box2d::minx() const { return minx_; } @@ -72,7 +72,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - T Envelope::maxx() const + T box2d::maxx() const { return maxx_; } @@ -81,7 +81,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - T Envelope::miny() const + T box2d::miny() const { return miny_; } @@ -90,7 +90,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - T Envelope::maxy() const + T box2d::maxy() const { return maxy_; } @@ -99,7 +99,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - T Envelope::width() const + T box2d::width() const { return maxx_-minx_; } @@ -108,7 +108,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - T Envelope::height() const + T box2d::height() const { return maxy_-miny_; } @@ -117,7 +117,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - void Envelope::width(T w) + void box2d::width(T w) { T cx=center().x; minx_=static_cast(cx-w*0.5); @@ -128,7 +128,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - void Envelope::height(T h) + void box2d::height(T h) { T cy=center().y; miny_=static_cast(cy-h*0.5); @@ -139,7 +139,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - coord Envelope::center() const + coord box2d::center() const { return coord(static_cast(0.5*(minx_+maxx_)), static_cast(0.5*(miny_+maxy_))); @@ -149,7 +149,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - void Envelope::expand_to_include(const coord& c) + void box2d::expand_to_include(const coord& c) { expand_to_include(c.x,c.y); } @@ -158,7 +158,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - void Envelope::expand_to_include(T x,T y) + void box2d::expand_to_include(T x,T y) { if (xmaxx_) maxx_=x; @@ -167,7 +167,7 @@ namespace mapnik } template - void Envelope::expand_to_include(const Envelope &other) + void box2d::expand_to_include(const box2d &other) { if (other.minx_maxx_) maxx_=other.maxx_; @@ -179,7 +179,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - bool Envelope::contains(const coord &c) const + bool box2d::contains(const coord &c) const { return contains(c.x,c.y); } @@ -188,7 +188,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - bool Envelope::contains(T x,T y) const + bool box2d::contains(T x,T y) const { return x>=minx_ && x<=maxx_ && y>=miny_ && y<=maxy_; } @@ -197,7 +197,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - bool Envelope::contains(const Envelope &other) const + bool box2d::contains(const box2d &other) const { return other.minx_>=minx_ && other.maxx_<=maxx_ && @@ -209,7 +209,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - bool Envelope::intersects(const coord &c) const + bool box2d::intersects(const coord &c) const { return intersects(c.x,c.y); } @@ -218,7 +218,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - bool Envelope::intersects(T x,T y) const + bool box2d::intersects(T x,T y) const { return !(x>maxx_ || xmaxy_ || y::intersects(const Envelope &other) const + bool box2d::intersects(const box2d &other) const { return !(other.minx_>maxx_ || other.maxx_maxy_ || other.maxy_ Envelope::intersect(const EnvelopeType& other) const + box2d box2d::intersect(const box2d_type& other) const { if (intersects(other)) { T x0=std::max(minx_,other.minx_); @@ -246,9 +246,9 @@ namespace mapnik T x1=std::min(maxx_,other.maxx_); T y1=std::min(maxy_,other.maxy_); - return Envelope(x0,y0,x1,y1); + return box2d(x0,y0,x1,y1); } else { - return Envelope(); + return box2d(); } } @@ -256,7 +256,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - void Envelope::re_center(T cx,T cy) + void box2d::re_center(T cx,T cy) { T dx=cx-center().x; T dy=cy-center().y; @@ -270,7 +270,7 @@ namespace mapnik #if !defined(__SUNPRO_CC) inline #endif - void Envelope::init(T x0,T y0,T x1,T y1) + void box2d::init(T x0,T y0,T x1,T y1) { if (x0 - Envelope& Envelope::operator+=(Envelope const& other) + box2d& box2d::operator+=(box2d const& other) { expand_to_include(other); return *this; } template - Envelope& Envelope::operator-=(Envelope const& other) + box2d& box2d::operator-=(box2d const& other) { // not sure what to do here. intersect? return *this; } template - Envelope& Envelope::operator*=(T t) + box2d& box2d::operator*=(T t) { coord c = center(); T sx = static_cast(0.5 * width() * t); @@ -318,7 +318,7 @@ namespace mapnik } template - Envelope& Envelope::operator/=(T t) + box2d& box2d::operator/=(T t) { coord c = center(); T sx = static_cast(0.5 * width() / t); @@ -330,6 +330,6 @@ namespace mapnik return *this; } - template class Envelope; - template class Envelope; + template class box2d; + template class box2d; } diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index 8b901f8fb..7fb19eafa 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -31,7 +31,8 @@ #include #include #include - +#include +#include // cairo #include #include @@ -48,563 +49,563 @@ namespace mapnik { - class cairo_pattern : private boost::noncopyable - { - public: - cairo_pattern(ImageData32 const& data) - { - int pixels = data.width() * data.height(); - const unsigned int *in_ptr = data.getData(); - const unsigned int *in_end = in_ptr + pixels; - unsigned int *out_ptr; +class cairo_pattern : private boost::noncopyable +{ +public: + cairo_pattern(image_data_32 const& data) + { + int pixels = data.width() * data.height(); + const unsigned int *in_ptr = data.getData(); + const unsigned int *in_end = in_ptr + pixels; + unsigned int *out_ptr; - out_ptr = data_ = new unsigned int[pixels]; + out_ptr = data_ = new unsigned int[pixels]; - while (in_ptr < in_end) - { - unsigned int in = *in_ptr++; - unsigned int r = (in >> 0) & 0xff; - unsigned int g = (in >> 8) & 0xff; - unsigned int b = (in >> 16) & 0xff; - unsigned int a = (in >> 24) & 0xff; + while (in_ptr < in_end) + { + unsigned int in = *in_ptr++; + unsigned int r = (in >> 0) & 0xff; + unsigned int g = (in >> 8) & 0xff; + unsigned int b = (in >> 16) & 0xff; + unsigned int a = (in >> 24) & 0xff; - r = r * a / 255; - g = g * a / 255; - b = b * a / 255; + r = r * a / 255; + g = g * a / 255; + b = b * a / 255; - *out_ptr++ = (a << 24) | (r << 16) | (g << 8) | b; - } + *out_ptr++ = (a << 24) | (r << 16) | (g << 8) | b; + } - surface_ = Cairo::ImageSurface::create(reinterpret_cast(data_), Cairo::FORMAT_ARGB32, data.width(), data.height(), data.width() * 4); - pattern_ = Cairo::SurfacePattern::create(surface_); - } + surface_ = Cairo::ImageSurface::create(reinterpret_cast(data_), Cairo::FORMAT_ARGB32, data.width(), data.height(), data.width() * 4); + pattern_ = Cairo::SurfacePattern::create(surface_); + } - ~cairo_pattern(void) - { - delete [] data_; - } + ~cairo_pattern(void) + { + delete [] data_; + } - void set_matrix(Cairo::Matrix const& matrix) - { - pattern_->set_matrix(matrix); - } + void set_matrix(Cairo::Matrix const& matrix) + { + pattern_->set_matrix(matrix); + } - void set_origin(double x, double y) - { - Cairo::Matrix matrix; + void set_origin(double x, double y) + { + Cairo::Matrix matrix; - pattern_->get_matrix(matrix); + pattern_->get_matrix(matrix); - matrix.x0 = -x; - matrix.y0 = -y; + matrix.x0 = -x; + matrix.y0 = -y; - pattern_->set_matrix(matrix); - } + pattern_->set_matrix(matrix); + } - void set_extend(Cairo::Extend extend) - { - pattern_->set_extend(extend); - } + void set_extend(Cairo::Extend extend) + { + pattern_->set_extend(extend); + } - void set_filter(Cairo::Filter filter) - { - pattern_->set_filter(filter); - } + void set_filter(Cairo::Filter filter) + { + pattern_->set_filter(filter); + } - Cairo::RefPtr const& pattern(void) const - { - return pattern_; - } + Cairo::RefPtr const& pattern(void) const + { + return pattern_; + } - private: - unsigned int *data_; - Cairo::RefPtr surface_; - Cairo::RefPtr pattern_; - }; +private: + unsigned int *data_; + Cairo::RefPtr surface_; + Cairo::RefPtr pattern_; +}; - class cairo_face : private boost::noncopyable - { - public: - cairo_face(boost::shared_ptr const& engine, face_ptr const& face) - : face_(face) - { - static cairo_user_data_key_t key; - cairo_font_face_t *c_face; +class cairo_face : private boost::noncopyable +{ +public: + cairo_face(boost::shared_ptr const& engine, face_ptr const& face) + : face_(face) + { + static cairo_user_data_key_t key; + cairo_font_face_t *c_face; - c_face = cairo_ft_font_face_create_for_ft_face(face->get_face(), FT_LOAD_NO_HINTING); - cairo_font_face_set_user_data(c_face, &key, new handle(engine, face), destroy); + c_face = cairo_ft_font_face_create_for_ft_face(face->get_face(), FT_LOAD_NO_HINTING); + cairo_font_face_set_user_data(c_face, &key, new handle(engine, face), destroy); - cairo_face_ = Cairo::RefPtr(new Cairo::FontFace(c_face)); - } + cairo_face_ = Cairo::RefPtr(new Cairo::FontFace(c_face)); + } - Cairo::RefPtr const& face(void) const - { - return cairo_face_; - } + Cairo::RefPtr const& face(void) const + { + return cairo_face_; + } - private: - class handle - { - public: - handle(boost::shared_ptr const& engine, face_ptr const& face) - : engine_(engine), face_(face) {} +private: + class handle + { + public: + handle(boost::shared_ptr const& engine, face_ptr const& face) + : engine_(engine), face_(face) {} - private: - boost::shared_ptr engine_; - face_ptr face_; - }; + private: + boost::shared_ptr engine_; + face_ptr face_; + }; - static void destroy(void *data) - { - handle *h = static_cast(data); + static void destroy(void *data) + { + handle *h = static_cast(data); - delete h; - } + delete h; + } - private: - face_ptr face_; - Cairo::RefPtr cairo_face_; - }; +private: + face_ptr face_; + Cairo::RefPtr cairo_face_; +}; - cairo_face_manager::cairo_face_manager(boost::shared_ptr engine, - face_manager & manager) - : font_engine_(engine), - font_manager_(manager) - { - } +cairo_face_manager::cairo_face_manager(boost::shared_ptr engine, + face_manager & manager) + : font_engine_(engine), + font_manager_(manager) +{ +} - cairo_face_ptr cairo_face_manager::get_face(face_ptr face) - { - cairo_face_cache::iterator itr = cache_.find(face); - cairo_face_ptr entry; +cairo_face_ptr cairo_face_manager::get_face(face_ptr face) +{ + cairo_face_cache::iterator itr = cache_.find(face); + cairo_face_ptr entry; - if (itr != cache_.end()) - { - entry = itr->second; - } - else - { - entry = cairo_face_ptr(new cairo_face(font_engine_, face)); + if (itr != cache_.end()) + { + entry = itr->second; + } + else + { + entry = cairo_face_ptr(new cairo_face(font_engine_, face)); - cache_.insert(std::make_pair(face, entry)); - } + cache_.insert(std::make_pair(face, entry)); + } - return entry; - } + return entry; +} - class cairo_context : private boost::noncopyable - { - public: - cairo_context(Cairo::RefPtr const& context) - : context_(context) - { - context_->save(); - } +class cairo_context : private boost::noncopyable +{ +public: + cairo_context(Cairo::RefPtr const& context) + : context_(context) + { + context_->save(); + } - ~cairo_context(void) - { - context_->restore(); - } + ~cairo_context(void) + { + context_->restore(); + } - void set_color(color const &color, double opacity = 1.0) - { - set_color(color.red(), color.green(), color.blue(), color.alpha() * opacity / 255.0); - } + void set_color(color const &color, double opacity = 1.0) + { + set_color(color.red(), color.green(), color.blue(), color.alpha() * opacity / 255.0); + } - void set_color(int r, int g, int b, double opacity = 1.0) - { - context_->set_source_rgba(r / 255.0, g / 255.0, b / 255.0, opacity); - } + void set_color(int r, int g, int b, double opacity = 1.0) + { + context_->set_source_rgba(r / 255.0, g / 255.0, b / 255.0, opacity); + } - void set_line_join(line_join_e join) - { - if (join == MITER_JOIN) - context_->set_line_join(Cairo::LINE_JOIN_MITER); - else if (join == MITER_REVERT_JOIN) - context_->set_line_join(Cairo::LINE_JOIN_MITER); - else if (join == ROUND_JOIN) - context_->set_line_join(Cairo::LINE_JOIN_ROUND); - else - context_->set_line_join(Cairo::LINE_JOIN_BEVEL); - } + void set_line_join(line_join_e join) + { + if (join == MITER_JOIN) + context_->set_line_join(Cairo::LINE_JOIN_MITER); + else if (join == MITER_REVERT_JOIN) + context_->set_line_join(Cairo::LINE_JOIN_MITER); + else if (join == ROUND_JOIN) + context_->set_line_join(Cairo::LINE_JOIN_ROUND); + else + context_->set_line_join(Cairo::LINE_JOIN_BEVEL); + } - void set_line_cap(line_cap_e cap) - { - if (cap == BUTT_CAP) - context_->set_line_cap(Cairo::LINE_CAP_BUTT); - else if (cap == SQUARE_CAP) - context_->set_line_cap(Cairo::LINE_CAP_SQUARE); - else - context_->set_line_cap(Cairo::LINE_CAP_ROUND); - } + void set_line_cap(line_cap_e cap) + { + if (cap == BUTT_CAP) + context_->set_line_cap(Cairo::LINE_CAP_BUTT); + else if (cap == SQUARE_CAP) + context_->set_line_cap(Cairo::LINE_CAP_SQUARE); + else + context_->set_line_cap(Cairo::LINE_CAP_ROUND); + } - void set_miter_limit(double limit) - { - context_->set_miter_limit(limit); - } + void set_miter_limit(double limit) + { + context_->set_miter_limit(limit); + } - void set_line_width(double width) - { - context_->set_line_width(width); - } + void set_line_width(double width) + { + context_->set_line_width(width); + } - void set_dash(dash_array const &dashes) - { - std::valarray d(dashes.size() * 2); - dash_array::const_iterator itr = dashes.begin(); - dash_array::const_iterator end = dashes.end(); - int index = 0; + void set_dash(dash_array const &dashes) + { + std::valarray d(dashes.size() * 2); + dash_array::const_iterator itr = dashes.begin(); + dash_array::const_iterator end = dashes.end(); + int index = 0; - for (; itr != end; ++itr) - { - d[index++] = itr->first; - d[index++] = itr->second; - } + for (; itr != end; ++itr) + { + d[index++] = itr->first; + d[index++] = itr->second; + } - context_->set_dash(d, 0.0); - } + context_->set_dash(d, 0.0); + } - void move_to(double x, double y) - { + void move_to(double x, double y) + { #if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 6, 0) - if (x < -32767.0) x = -32767.0; - else if (x > 32767.0) x = 32767.0; - if (y < -32767.0) y = -32767.0; - else if (y > 32767.0) y = 32767.0; + if (x < -32767.0) x = -32767.0; + else if (x > 32767.0) x = 32767.0; + if (y < -32767.0) y = -32767.0; + else if (y > 32767.0) y = 32767.0; #endif - context_->move_to(x, y); - } + context_->move_to(x, y); + } - void line_to(double x, double y) - { + void line_to(double x, double y) + { #if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 6, 0) - if (x < -32767.0) x = -32767.0; - else if (x > 32767.0) x = 32767.0; - if (y < -32767.0) y = -32767.0; - else if (y > 32767.0) y = 32767.0; + if (x < -32767.0) x = -32767.0; + else if (x > 32767.0) x = 32767.0; + if (y < -32767.0) y = -32767.0; + else if (y > 32767.0) y = 32767.0; #endif - context_->line_to(x, y); - } + context_->line_to(x, y); + } - template - void add_path(T path) - { - double x, y; + template + void add_path(T path) + { + double x, y; - path.rewind(0); + path.rewind(0); - for (unsigned cm = path.vertex(&x, &y); cm != SEG_END; cm = path.vertex(&x, &y)) - { - if (cm == SEG_MOVETO) - { - move_to(x, y); - } - else if (cm == SEG_LINETO) - { - line_to(x, y); - } - } - } + for (unsigned cm = path.vertex(&x, &y); cm != SEG_END; cm = path.vertex(&x, &y)) + { + if (cm == SEG_MOVETO) + { + move_to(x, y); + } + else if (cm == SEG_LINETO) + { + line_to(x, y); + } + } + } - void rectangle(double x, double y, double w, double h) - { - context_->rectangle(x, y, w, h); - } + void rectangle(double x, double y, double w, double h) + { + context_->rectangle(x, y, w, h); + } - void stroke(void) - { - context_->stroke(); - } + void stroke(void) + { + context_->stroke(); + } - void fill(void) - { - context_->fill(); - } + void fill(void) + { + context_->fill(); + } - void paint(void) - { - context_->paint(); - } + void paint(void) + { + context_->paint(); + } - void set_pattern(cairo_pattern const& pattern) - { - context_->set_source(pattern.pattern()); - } + void set_pattern(cairo_pattern const& pattern) + { + context_->set_source(pattern.pattern()); + } - void add_image(double x, double y, ImageData32 & data, double opacity = 1.0) - { - cairo_pattern pattern(data); + void add_image(double x, double y, image_data_32 & data, double opacity = 1.0) + { + cairo_pattern pattern(data); - pattern.set_origin(x, y); + pattern.set_origin(x, y); - context_->save(); - context_->set_source(pattern.pattern()); - context_->paint_with_alpha(opacity); - context_->restore(); - } + context_->save(); + context_->set_source(pattern.pattern()); + context_->paint_with_alpha(opacity); + context_->restore(); + } - void set_font_face(cairo_face_manager & manager, face_ptr face) - { - context_->set_font_face(manager.get_face(face)->face()); - } + void set_font_face(cairo_face_manager & manager, face_ptr face) + { + context_->set_font_face(manager.get_face(face)->face()); + } - void set_font_matrix(Cairo::Matrix const& matrix) - { - context_->set_font_matrix(matrix); - } + void set_font_matrix(Cairo::Matrix const& matrix) + { + context_->set_font_matrix(matrix); + } - void show_glyph(unsigned long index, double x, double y) - { - Cairo::Glyph glyph; + void show_glyph(unsigned long index, double x, double y) + { + Cairo::Glyph glyph; - glyph.index = index; - glyph.x = x; - glyph.y = y; + glyph.index = index; + glyph.x = x; + glyph.y = y; - std::vector glyphs; + std::vector glyphs; - glyphs.push_back(glyph); + glyphs.push_back(glyph); - context_->show_glyphs(glyphs); - } + context_->show_glyphs(glyphs); + } - void glyph_path(unsigned long index, double x, double y) - { - Cairo::Glyph glyph; + void glyph_path(unsigned long index, double x, double y) + { + Cairo::Glyph glyph; - glyph.index = index; - glyph.x = x; - glyph.y = y; + glyph.index = index; + glyph.x = x; + glyph.y = y; - std::vector glyphs; + std::vector glyphs; - glyphs.push_back(glyph); + glyphs.push_back(glyph); - context_->glyph_path(glyphs); - } + context_->glyph_path(glyphs); + } - void add_text(text_symbolizer const& sym, text_path & path, - cairo_face_manager & manager, - face_set_ptr const& faces) - { - unsigned text_size = sym.get_text_size(); - double sx = path.starting_x; - double sy = path.starting_y; + void add_text(text_symbolizer const& sym, text_path & path, + cairo_face_manager & manager, + face_set_ptr const& faces) + { + unsigned text_size = sym.get_text_size(); + double sx = path.starting_x; + double sy = path.starting_y; - path.rewind(); + path.rewind(); - for (int iii = 0; iii < path.num_nodes(); iii++) - { - int c; - double x, y, angle; + for (int iii = 0; iii < path.num_nodes(); iii++) + { + int c; + double x, y, angle; - path.vertex(&c, &x, &y, &angle); + path.vertex(&c, &x, &y, &angle); - glyph_ptr glyph = faces->get_glyph(c); + glyph_ptr glyph = faces->get_glyph(c); - if (glyph) - { - Cairo::Matrix matrix; + if (glyph) + { + Cairo::Matrix matrix; - matrix.xx = text_size * cos(angle); - matrix.xy = text_size * sin(angle); - matrix.yx = text_size * -sin(angle); - matrix.yy = text_size * cos(angle); - matrix.x0 = 0; - matrix.y0 = 0; + matrix.xx = text_size * cos(angle); + matrix.xy = text_size * sin(angle); + matrix.yx = text_size * -sin(angle); + matrix.yy = text_size * cos(angle); + matrix.x0 = 0; + matrix.y0 = 0; - set_font_matrix(matrix); + set_font_matrix(matrix); - set_font_face(manager, glyph->get_face()); + set_font_face(manager, glyph->get_face()); - glyph_path(glyph->get_index(), sx + x, sy - y); - } - } + glyph_path(glyph->get_index(), sx + x, sy - y); + } + } - set_line_width(sym.get_halo_radius()); - set_line_join(ROUND_JOIN); - set_color(sym.get_halo_fill()); - stroke(); + set_line_width(sym.get_halo_radius()); + set_line_join(ROUND_JOIN); + set_color(sym.get_halo_fill()); + stroke(); - set_color(sym.get_fill()); + set_color(sym.get_fill()); - path.rewind(); + path.rewind(); - for (int iii = 0; iii < path.num_nodes(); iii++) - { - int c; - double x, y, angle; + for (int iii = 0; iii < path.num_nodes(); iii++) + { + int c; + double x, y, angle; - path.vertex(&c, &x, &y, &angle); + path.vertex(&c, &x, &y, &angle); - glyph_ptr glyph = faces->get_glyph(c); + glyph_ptr glyph = faces->get_glyph(c); - if (glyph) - { - Cairo::Matrix matrix; + if (glyph) + { + Cairo::Matrix matrix; - matrix.xx = text_size * cos(angle); - matrix.xy = text_size * sin(angle); - matrix.yx = text_size * -sin(angle); - matrix.yy = text_size * cos(angle); - matrix.x0 = 0; - matrix.y0 = 0; + matrix.xx = text_size * cos(angle); + matrix.xy = text_size * sin(angle); + matrix.yx = text_size * -sin(angle); + matrix.yy = text_size * cos(angle); + matrix.x0 = 0; + matrix.y0 = 0; - set_font_matrix(matrix); + set_font_matrix(matrix); - set_font_face(manager, glyph->get_face()); + set_font_face(manager, glyph->get_face()); - show_glyph(glyph->get_index(), sx + x, sy - y); - } - } - } + show_glyph(glyph->get_index(), sx + x, sy - y); + } + } + } - private: - Cairo::RefPtr context_; - }; +private: + Cairo::RefPtr context_; +}; - cairo_renderer_base::cairo_renderer_base(Map const& m, Cairo::RefPtr const& context, unsigned offset_x, unsigned offset_y) - : m_(m), - context_(context), - t_(m.getWidth(),m.getHeight(),m.getCurrentExtent(),offset_x,offset_y), - font_engine_(new freetype_engine()), - font_manager_(*font_engine_), - face_manager_(font_engine_,font_manager_), - detector_(Envelope(-m.buffer_size() ,-m.buffer_size() , m.getWidth() + m.buffer_size() ,m.getHeight() + m.buffer_size())) - { +cairo_renderer_base::cairo_renderer_base(Map const& m, Cairo::RefPtr const& context, unsigned offset_x, unsigned offset_y) + : m_(m), + context_(context), + t_(m.getWidth(),m.getHeight(),m.getCurrentExtent(),offset_x,offset_y), + font_engine_(new freetype_engine()), + font_manager_(*font_engine_), + face_manager_(font_engine_,font_manager_), + detector_(box2d(-m.buffer_size() ,-m.buffer_size() , m.getWidth() + m.buffer_size() ,m.getHeight() + m.buffer_size())) +{ #ifdef MAPNIK_DEBUG - std::clog << "scale=" << m.scale() << "\n"; + std::clog << "scale=" << m.scale() << "\n"; #endif - } +} - template <> - cairo_renderer::cairo_renderer(Map const& m, Cairo::RefPtr const& context, unsigned offset_x, unsigned offset_y) - : feature_style_processor(m), - cairo_renderer_base(m,context,offset_x,offset_y) - { - } +template <> +cairo_renderer::cairo_renderer(Map const& m, Cairo::RefPtr const& context, unsigned offset_x, unsigned offset_y) + : feature_style_processor(m), + cairo_renderer_base(m,context,offset_x,offset_y) +{ +} - template <> - cairo_renderer::cairo_renderer(Map const& m, Cairo::RefPtr const& surface, unsigned offset_x, unsigned offset_y) - : feature_style_processor(m), - cairo_renderer_base(m,Cairo::Context::create(surface),offset_x,offset_y) - { - } +template <> +cairo_renderer::cairo_renderer(Map const& m, Cairo::RefPtr const& surface, unsigned offset_x, unsigned offset_y) + : feature_style_processor(m), + cairo_renderer_base(m,Cairo::Context::create(surface),offset_x,offset_y) +{ +} - cairo_renderer_base::~cairo_renderer_base() {} +cairo_renderer_base::~cairo_renderer_base() {} - void cairo_renderer_base::start_map_processing(Map const& map) - { +void cairo_renderer_base::start_map_processing(Map const& map) +{ #ifdef MAPNIK_DEBUG - std::clog << "start map processing bbox=" - << map.getCurrentExtent() << "\n"; + std::clog << "start map processing bbox=" + << map.getCurrentExtent() << "\n"; #endif #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 6, 0) - Envelope bounds = t_.forward(t_.extent()); - context_->rectangle(bounds.minx(), bounds.miny(), bounds.maxx(), bounds.maxy()); - context_->clip(); + box2d bounds = t_.forward(t_.extent()); + context_->rectangle(bounds.minx(), bounds.miny(), bounds.maxx(), bounds.maxy()); + context_->clip(); #endif - boost::optional bg = m_.background(); - if (bg) - { - cairo_context context(context_); - context.set_color(*bg); - context.paint(); - } - } + boost::optional bg = m_.background(); + if (bg) + { + cairo_context context(context_); + context.set_color(*bg); + context.paint(); + } +} - template <> - void cairo_renderer::end_map_processing(Map const& ) - { +template <> +void cairo_renderer::end_map_processing(Map const& ) +{ #ifdef MAPNIK_DEBUG - std::clog << "end map processing\n"; + std::clog << "end map processing\n"; #endif - } +} - template <> - void cairo_renderer::end_map_processing(Map const& ) - { +template <> +void cairo_renderer::end_map_processing(Map const& ) +{ #ifdef MAPNIK_DEBUG - std::clog << "end map processing\n"; + std::clog << "end map processing\n"; #endif - context_->show_page(); - } + context_->show_page(); +} - void cairo_renderer_base::start_layer_processing(Layer const& lay) - { +void cairo_renderer_base::start_layer_processing(layer const& lay) +{ #ifdef MAPNIK_DEBUG - std::clog << "start layer processing : " << lay.name() << "\n"; - std::clog << "datasource = " << lay.datasource().get() << "\n"; + std::clog << "start layer processing : " << lay.name() << "\n"; + std::clog << "datasource = " << lay.datasource().get() << "\n"; #endif - if (lay.clear_label_cache()) - { - detector_.clear(); - } - } + if (lay.clear_label_cache()) + { + detector_.clear(); + } +} - void cairo_renderer_base::end_layer_processing(Layer const&) - { +void cairo_renderer_base::end_layer_processing(layer const&) +{ #ifdef MAPNIK_DEBUG - std::clog << "end layer processing\n"; + std::clog << "end layer processing\n"; #endif - } +} - void cairo_renderer_base::process(polygon_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; +void cairo_renderer_base::process(polygon_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; - cairo_context context(context_); + cairo_context context(context_); - context.set_color(sym.get_fill(), sym.get_opacity()); + context.set_color(sym.get_fill(), sym.get_opacity()); - for (unsigned i = 0; i < feature.num_geometries(); ++i) - { - geometry2d const& geom = feature.get_geometry(i); + for (unsigned i = 0; i < feature.num_geometries(); ++i) + { + geometry2d const& geom = feature.get_geometry(i); - if (geom.num_points() > 2) - { + if (geom.num_points() > 2) + { path_type path(t_, geom, prj_trans); context.add_path(path); context.fill(); - } - } - } + } + } +} - typedef boost::tuple segment_t; - bool cairo_y_order(segment_t const& first,segment_t const& second) - { - double miny0 = std::min(first.get<1>(), first.get<3>()); - double miny1 = std::min(second.get<1>(), second.get<3>()); - return miny0 > miny1; - } +typedef boost::tuple segment_t; +bool cairo_y_order(segment_t const& first,segment_t const& second) +{ + double miny0 = std::min(first.get<1>(), first.get<3>()); + double miny1 = std::min(second.get<1>(), second.get<3>()); + return miny0 > miny1; +} - void cairo_renderer_base::process(building_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; - typedef coord_transform3 path_type_roof; +void cairo_renderer_base::process(building_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; + typedef coord_transform3 path_type_roof; - cairo_context context(context_); + cairo_context context(context_); - color const& fill = sym.get_fill(); - double height = 0.7071 * sym.height(); // height in meters + color const& fill = sym.get_fill(); + double height = 0.7071 * sym.height(); // height in meters - for (unsigned i = 0; i < feature.num_geometries(); ++i) - { - geometry2d const& geom = feature.get_geometry(i); + for (unsigned i = 0; i < feature.num_geometries(); ++i) + { + geometry2d const& geom = feature.get_geometry(i); - if (geom.num_points() > 2) - { + if (geom.num_points() > 2) + { boost::scoped_ptr frame(new line_string_impl); boost::scoped_ptr roof(new polygon_impl); std::deque face_segments; @@ -614,47 +615,47 @@ namespace mapnik for (unsigned j = 1; j < geom.num_points(); ++j) { - double x,y; + double x,y; - cm = geom.vertex(&x,&y); + cm = geom.vertex(&x,&y); - if (cm == SEG_MOVETO) - { - frame->move_to(x,y); - } - else if (cm == SEG_LINETO) - { - frame->line_to(x,y); - } + if (cm == SEG_MOVETO) + { + frame->move_to(x,y); + } + else if (cm == SEG_LINETO) + { + frame->line_to(x,y); + } - if (j != 0) - { - face_segments.push_back(segment_t(x0, y0, x, y)); - } + if (j != 0) + { + face_segments.push_back(segment_t(x0, y0, x, y)); + } - x0 = x; - y0 = y; + x0 = x; + y0 = y; } std::sort(face_segments.begin(), face_segments.end(), cairo_y_order); std::deque::const_iterator itr = face_segments.begin(); for (; itr != face_segments.end(); ++itr) { - boost::scoped_ptr faces(new polygon_impl); + boost::scoped_ptr faces(new polygon_impl); - faces->move_to(itr->get<0>(), itr->get<1>()); - faces->line_to(itr->get<2>(), itr->get<3>()); - faces->line_to(itr->get<2>(), itr->get<3>() + height); - faces->line_to(itr->get<0>(), itr->get<1>() + height); + faces->move_to(itr->get<0>(), itr->get<1>()); + faces->line_to(itr->get<2>(), itr->get<3>()); + faces->line_to(itr->get<2>(), itr->get<3>() + height); + faces->line_to(itr->get<0>(), itr->get<1>() + height); - path_type faces_path(t_, *faces, prj_trans); - context.set_color(int(fill.red() * 0.8), int(fill.green() * 0.8), - int(fill.blue() * 0.8), fill.alpha() * sym.get_opacity() / 255.0); - context.add_path(faces_path); - context.fill(); + path_type faces_path(t_, *faces, prj_trans); + context.set_color(int(fill.red() * 0.8), int(fill.green() * 0.8), + int(fill.blue() * 0.8), fill.alpha() * sym.get_opacity() / 255.0); + context.add_path(faces_path); + context.fill(); - frame->move_to(itr->get<0>(), itr->get<1>()); - frame->line_to(itr->get<0>(), itr->get<1>() + height); + frame->move_to(itr->get<0>(), itr->get<1>()); + frame->line_to(itr->get<0>(), itr->get<1>() + height); } @@ -662,19 +663,19 @@ namespace mapnik for (unsigned j = 0; j < geom.num_points(); ++j) { - double x, y; - unsigned cm = geom.vertex(&x, &y); + double x, y; + unsigned cm = geom.vertex(&x, &y); - if (cm == SEG_MOVETO) - { - frame->move_to(x, y + height); - roof->move_to(x, y + height); - } - else if (cm == SEG_LINETO) - { - frame->line_to(x, y + height); - roof->line_to(x, y + height); - } + if (cm == SEG_MOVETO) + { + frame->move_to(x, y + height); + roof->move_to(x, y + height); + } + else if (cm == SEG_LINETO) + { + frame->line_to(x, y + height); + roof->line_to(x, y + height); + } } path_type path(t_, *frame, prj_trans); @@ -686,33 +687,33 @@ namespace mapnik context.set_color(sym.get_fill(), sym.get_opacity()); context.add_path(roof_path); context.fill(); - } - } + } } +} - void cairo_renderer_base::process(line_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; +void cairo_renderer_base::process(line_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; - cairo_context context(context_); - mapnik::stroke const& stroke_ = sym.get_stroke(); + cairo_context context(context_); + mapnik::stroke const& stroke_ = sym.get_stroke(); - context.set_color(stroke_.get_color(), stroke_.get_opacity()); + context.set_color(stroke_.get_color(), stroke_.get_opacity()); - for (unsigned i = 0; i < feature.num_geometries(); ++i) - { - geometry2d const& geom = feature.get_geometry(i); + for (unsigned i = 0; i < feature.num_geometries(); ++i) + { + geometry2d const& geom = feature.get_geometry(i); - if (geom.num_points() > 1) - { + if (geom.num_points() > 1) + { cairo_context context(context_); path_type path(t_, geom, prj_trans); if (stroke_.has_dash()) { - context.set_dash(stroke_.get_dash_array()); + context.set_dash(stroke_.get_dash_array()); } context.set_line_join(stroke_.get_line_join()); @@ -721,75 +722,81 @@ namespace mapnik context.set_line_width(stroke_.get_width()); context.add_path(path); context.stroke(); - } - } - } + } + } +} - void cairo_renderer_base::process(point_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - boost::shared_ptr const& data = sym.get_image(); - - if ( data ) - { - for (unsigned i = 0; i < feature.num_geometries(); ++i) - { - geometry2d const& geom = feature.get_geometry(i); - double x; - double y; - double z = 0; - - geom.label_position(&x, &y); - prj_trans.backward(x, y, z); - t_.forward(&x, &y); - - int w = data->width(); - int h = data->height(); - - Envelope label_ext (floor(x - 0.5 * w), - floor(y - 0.5 * h), - ceil (x + 0.5 * w), - ceil (y + 0.5 * h)); +void cairo_renderer_base::process(point_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + std::string filename = path_processor_type::evaluate( *sym.get_filename(), feature); + boost::optional data = mapnik::image_cache::instance()->find(filename,true); + + if ( data ) + { + for (unsigned i = 0; i < feature.num_geometries(); ++i) + { + geometry2d const& geom = feature.get_geometry(i); + double x; + double y; + double z = 0; + + geom.label_position(&x, &y); + prj_trans.backward(x, y, z); + t_.forward(&x, &y); + + int w = (*data)->width(); + int h = (*data)->height(); + + box2d label_ext (floor(x - 0.5 * w), + floor(y - 0.5 * h), + ceil (x + 0.5 * w), + ceil (y + 0.5 * h)); if (sym.get_allow_overlap() || detector_.has_placement(label_ext)) { - cairo_context context(context_); - int px = int(floor(x - 0.5 * w)); - int py = int(floor(y - 0.5 * h)); + cairo_context context(context_); + int px = int(floor(x - 0.5 * w)); + int py = int(floor(y - 0.5 * h)); - context.add_image(px, py, *data, sym.get_opacity()); - detector_.insert(label_ext); + context.add_image(px, py, *(*data), sym.get_opacity()); + detector_.insert(label_ext); } - } - } - } + } + } +} - void cairo_renderer_base::process(shield_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; +void cairo_renderer_base::process(shield_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; - UnicodeString text = feature[sym.get_name()].to_unicode(); - boost::shared_ptr const& data = sym.get_image(); + expression_ptr name_expr = sym.get_name(); + if (!name_expr) return; + value_type result = boost::apply_visitor(evaluate(feature),*name_expr); + UnicodeString text = result.to_unicode(); + + std::string filename = path_processor_type::evaluate( *sym.get_filename(), feature); + boost::optional data = mapnik::image_cache::instance()->find(filename,true); + + if (text.length() > 0 && data) + { + face_set_ptr faces; - if (text.length() > 0 && data) - { - face_set_ptr faces; - - if (sym.get_fontset().size() > 0) - { + if (sym.get_fontset().size() > 0) + { faces = font_manager_.get_face_set(sym.get_fontset()); - } - else - { + } + else + { faces = font_manager_.get_face_set(sym.get_face_name()); - } + } - if (faces->size() > 0) - { + if (faces->size() > 0) + { cairo_context context(context_); string_info info(text); @@ -798,102 +805,105 @@ namespace mapnik placement_finder finder(detector_); - int w = data->width(); - int h = data->height(); + int w = (*data)->width(); + int h = (*data)->height(); for (unsigned i = 0; i < feature.num_geometries(); ++i) { - geometry2d const& geom = feature.get_geometry(i); + geometry2d const& geom = feature.get_geometry(i); - if (geom.num_points() > 0) // don't bother with empty geometries - { - path_type path(t_, geom, prj_trans); + if (geom.num_points() > 0) // don't bother with empty geometries + { + path_type path(t_, geom, prj_trans); - if (sym.get_label_placement() == POINT_PLACEMENT) - { - double label_x; - double label_y; - double z = 0.0; - placement text_placement(info, sym, false); + if (sym.get_label_placement() == POINT_PLACEMENT) + { + double label_x; + double label_y; + double z = 0.0; + placement text_placement(info, sym, w, h, false); - text_placement.avoid_edges = sym.get_avoid_edges(); - geom.label_position(&label_x, &label_y); - prj_trans.backward(label_x, label_y, z); - t_.forward(&label_x, &label_y); - finder.find_point_placement(text_placement, label_x, label_y); + text_placement.avoid_edges = sym.get_avoid_edges(); + geom.label_position(&label_x, &label_y); + prj_trans.backward(label_x, label_y, z); + t_.forward(&label_x, &label_y); + finder.find_point_placement(text_placement, label_x, label_y); - for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii) - { - double x = text_placement.placements[ii].starting_x; - double y = text_placement.placements[ii].starting_y; - // remove displacement from image label - position pos = sym.get_displacement(); - double lx = x - boost::get<0>(pos); - double ly = y - boost::get<1>(pos); - int px = int(lx - (0.5 * w)) ; - int py = int(ly - (0.5 * h)) ; - Envelope label_ext (floor(lx - 0.5 * w), floor(ly - 0.5 * h), ceil (lx + 0.5 * w), ceil (ly + 0.5 * h)); + for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii) + { + double x = text_placement.placements[ii].starting_x; + double y = text_placement.placements[ii].starting_y; + // remove displacement from image label + position pos = sym.get_displacement(); + double lx = x - boost::get<0>(pos); + double ly = y - boost::get<1>(pos); + int px = int(lx - (0.5 * w)) ; + int py = int(ly - (0.5 * h)) ; + box2d label_ext (floor(lx - 0.5 * w), floor(ly - 0.5 * h), ceil (lx + 0.5 * w), ceil (ly + 0.5 * h)); - if (detector_.has_placement(label_ext)) - { - context.add_image(px, py, *data); - context.add_text(sym, text_placement.placements[ii], face_manager_, faces); + if (detector_.has_placement(label_ext)) + { + context.add_image(px, py, *(*data)); + context.add_text(sym, text_placement.placements[ii], face_manager_, faces); - detector_.insert(label_ext); - } - } + detector_.insert(label_ext); + } + } - finder.update_detector(text_placement); - } - else if (geom.num_points() > 1 && sym.get_label_placement() == LINE_PLACEMENT) - { - placement text_placement(info, sym, true); + finder.update_detector(text_placement); + } + else if (geom.num_points() > 1 && sym.get_label_placement() == LINE_PLACEMENT) + { + placement text_placement(info, sym, w, h, true); - text_placement.avoid_edges = sym.get_avoid_edges(); - finder.find_point_placements(text_placement, path); + text_placement.avoid_edges = sym.get_avoid_edges(); + finder.find_point_placements(text_placement, path); - for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii) - { - double x = text_placement.placements[ii].starting_x; - double y = text_placement.placements[ii].starting_y; - int px = int(x - (w/2)); - int py = int(y - (h/2)); + for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii) + { + double x = text_placement.placements[ii].starting_x; + double y = text_placement.placements[ii].starting_y; + int px = int(x - (w/2)); + int py = int(y - (h/2)); - context.add_image(px, py, *data); - context.add_text(sym, text_placement.placements[ii], face_manager_, faces); - } + context.add_image(px, py, *(*data)); + context.add_text(sym, text_placement.placements[ii], face_manager_, faces); + } - finder.update_detector(text_placement); - } - } + finder.update_detector(text_placement); + } + } } - } - } - } + } + } +} - void cairo_renderer_base::process(line_pattern_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; +void cairo_renderer_base::process(line_pattern_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; + + std::string filename = path_processor_type::evaluate( *sym.get_filename(), feature); + boost::optional image = mapnik::image_cache::instance()->find(filename,true); + if (!image) return; + + unsigned width((*image)->width()); + unsigned height((*image)->height()); - boost::shared_ptr const& image = sym.get_image(); - unsigned width(image->width()); - unsigned height(image->height()); + cairo_context context(context_); + cairo_pattern pattern(*(*image)); - cairo_context context(context_); - cairo_pattern pattern(*image); + pattern.set_extend(Cairo::EXTEND_REPEAT); + pattern.set_filter(Cairo::FILTER_BILINEAR); + context.set_line_width(height); - pattern.set_extend(Cairo::EXTEND_REPEAT); - pattern.set_filter(Cairo::FILTER_BILINEAR); - context.set_line_width(height); + for (unsigned i = 0; i < feature.num_geometries(); ++i) + { + geometry2d const& geom = feature.get_geometry(i); - for (unsigned i = 0; i < feature.num_geometries(); ++i) - { - geometry2d const& geom = feature.get_geometry(i); - - if (geom.num_points() > 1) - { + if (geom.num_points() > 1) + { path_type path(t_, geom, prj_trans); double length(0); double x0(0), y0(0); @@ -901,135 +911,144 @@ namespace mapnik for (unsigned cm = path.vertex(&x, &y); cm != SEG_END; cm = path.vertex(&x, &y)) { - if (cm == SEG_MOVETO) - { - length = 0.0; - } - else if (cm == SEG_LINETO) - { - double dx = x - x0; - double dy = y - y0; - double angle = atan2(dy, dx); - double offset = fmod(length, width); + if (cm == SEG_MOVETO) + { + length = 0.0; + } + else if (cm == SEG_LINETO) + { + double dx = x - x0; + double dy = y - y0; + double angle = atan2(dy, dx); + double offset = fmod(length, width); - Cairo::Matrix matrix; - cairo_matrix_init_identity(&matrix); - cairo_matrix_translate(&matrix,x0,y0); - cairo_matrix_rotate(&matrix,angle); - cairo_matrix_translate(&matrix,-offset,0.5*height); - cairo_matrix_invert(&matrix); + Cairo::Matrix matrix; + cairo_matrix_init_identity(&matrix); + cairo_matrix_translate(&matrix,x0,y0); + cairo_matrix_rotate(&matrix,angle); + cairo_matrix_translate(&matrix,-offset,0.5*height); + cairo_matrix_invert(&matrix); - pattern.set_matrix(matrix); + pattern.set_matrix(matrix); - context.set_pattern(pattern); + context.set_pattern(pattern); - context.move_to(x0, y0); - context.line_to(x, y); - context.stroke(); + context.move_to(x0, y0); + context.line_to(x, y); + context.stroke(); - length = length + hypot(x - x0, y - y0); - } + length = length + hypot(x - x0, y - y0); + } - x0 = x; - y0 = y; + x0 = x; + y0 = y; } - } - } - } + } + } +} - void cairo_renderer_base::process(polygon_pattern_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; +void cairo_renderer_base::process(polygon_pattern_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; - cairo_context context(context_); - cairo_pattern pattern(*sym.get_image()); - pattern.set_extend(Cairo::EXTEND_REPEAT); + cairo_context context(context_); + std::string filename = path_processor_type::evaluate( *sym.get_filename(), feature); + boost::optional image = mapnik::image_cache::instance()->find(filename,true); - context.set_pattern(pattern); + if (!image) return; - for (unsigned i = 0; i < feature.num_geometries(); ++i) - { - geometry2d const& geom = feature.get_geometry(i); + cairo_pattern pattern(*(*image)); - if (geom.num_points() > 2) - { + pattern.set_extend(Cairo::EXTEND_REPEAT); + + context.set_pattern(pattern); + + for (unsigned i = 0; i < feature.num_geometries(); ++i) + { + geometry2d const& geom = feature.get_geometry(i); + + if (geom.num_points() > 2) + { path_type path(t_, geom, prj_trans); context.add_path(path); context.fill(); - } - } - } + } + } +} - void cairo_renderer_base::process(raster_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - // TODO -- at the moment raster_symbolizer is an empty class - // used for type dispatching, but we can have some fancy raster - // processing in a future (filters??). Just copy raster into pixmap for now. - raster_ptr const& raster = feature.get_raster(); - if (raster) - { - Envelope ext = t_.forward(raster->ext_); - ImageData32 target(int(ext.width() + 0.5), int(ext.height() + 0.5)); - //TODO -- use cairo matrix transformation for scaling - if (sym.get_scaling() == "fast"){ - scale_image(target, raster->data_); - } else if (sym.get_scaling() == "bilinear"){ - scale_image_bilinear(target,raster->data_); - } else if (sym.get_scaling() == "bilinear8"){ - scale_image_bilinear8(target,raster->data_); - } else { - scale_image(target,raster->data_); - } +void cairo_renderer_base::process(raster_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + // TODO -- at the moment raster_symbolizer is an empty class + // used for type dispatching, but we can have some fancy raster + // processing in a future (filters??). Just copy raster into pixmap for now. + raster_ptr const& raster = feature.get_raster(); + if (raster) + { + box2d ext = t_.forward(raster->ext_); + image_data_32 target(int(ext.width() + 0.5), int(ext.height() + 0.5)); + //TODO -- use cairo matrix transformation for scaling + if (sym.get_scaling() == "fast"){ + scale_image(target, raster->data_); + } else if (sym.get_scaling() == "bilinear"){ + scale_image_bilinear(target,raster->data_); + } else if (sym.get_scaling() == "bilinear8"){ + scale_image_bilinear8(target,raster->data_); + } else { + scale_image(target,raster->data_); + } - cairo_context context(context_); + cairo_context context(context_); - //TODO -- support for advanced image merging - context.add_image(int(ext.minx()+0.5), int(ext.miny()+0.5), target, sym.get_opacity()); - } - } + //TODO -- support for advanced image merging + context.add_image(int(ext.minx()+0.5), int(ext.miny()+0.5), target, sym.get_opacity()); + } +} - void cairo_renderer_base::process(markers_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - } +void cairo_renderer_base::process(markers_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ +} - void cairo_renderer_base::process(text_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) - { - typedef coord_transform2 path_type; +void cairo_renderer_base::process(text_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans) +{ + typedef coord_transform2 path_type; + expression_ptr name_expr = sym.get_name(); + if (!name_expr) return; + value_type result = boost::apply_visitor(evaluate(feature),*name_expr); + UnicodeString text = result.to_unicode(); + + if ( sym.get_text_convert() == TOUPPER) + { + text = text.toUpper(); + } + else if ( sym.get_text_convert() == TOLOWER) + { + text = text.toLower(); + } - UnicodeString text = feature[sym.get_name()].to_unicode(); - if ( sym.get_text_convert() == TOUPPER) - { - text = text.toUpper(); - } - else if ( sym.get_text_convert() == TOLOWER) - { - text = text.toLower(); - } + if (text.length() > 0) + { + face_set_ptr faces; - if (text.length() > 0) - { - face_set_ptr faces; - - if (sym.get_fontset().size() > 0) - { + if (sym.get_fontset().size() > 0) + { faces = font_manager_.get_face_set(sym.get_fontset()); - } - else - { + } + else + { faces = font_manager_.get_face_set(sym.get_face_name()); - } + } - if (faces->size() > 0) - { + if (faces->size() > 0) + { cairo_context context(context_); string_info info(text); @@ -1040,44 +1059,44 @@ namespace mapnik for (unsigned i = 0; i < feature.num_geometries(); ++i) { - geometry2d const& geom = feature.get_geometry(i); + geometry2d const& geom = feature.get_geometry(i); - if (geom.num_points() > 0) // don't bother with empty geometries - { - path_type path(t_, geom, prj_trans); - placement text_placement(info, sym); + if (geom.num_points() > 0) // don't bother with empty geometries + { + path_type path(t_, geom, prj_trans); + placement text_placement(info, sym); - if (sym.get_label_placement() == POINT_PLACEMENT) - { - double label_x, label_y, z = 0.0; + if (sym.get_label_placement() == POINT_PLACEMENT) + { + double label_x, label_y, z = 0.0; - geom.label_position(&label_x, &label_y); - prj_trans.backward(label_x, label_y, z); - t_.forward(&label_x, &label_y); - finder.find_point_placement(text_placement, label_x, label_y); - finder.update_detector(text_placement); - } - else //LINE_PLACEMENT - { - finder.find_line_placements(text_placement, path); - } + geom.label_position(&label_x, &label_y); + prj_trans.backward(label_x, label_y, z); + t_.forward(&label_x, &label_y); + finder.find_point_placement(text_placement, label_x, label_y); + finder.update_detector(text_placement); + } + else //LINE_PLACEMENT + { + finder.find_line_placements(text_placement, path); + } - for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ii) - { - context.add_text(sym, text_placement.placements[ii], face_manager_, faces); - } - } + for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ii) + { + context.add_text(sym, text_placement.placements[ii], face_manager_, faces); + } + } } - } - else - { + } + else + { throw config_error("Unable to find specified font face '" + sym.get_face_name() + "'"); - } - } - } + } + } +} - template class cairo_renderer; - template class cairo_renderer; +template class cairo_renderer; +template class cairo_renderer; } #endif diff --git a/src/color.cpp b/src/color.cpp index 32980fd33..bcab2257e 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -57,10 +57,10 @@ namespace mapnik { std::string color::to_hex_string() const { - return (boost::format("#%1$02x%2$02x%3$02x") - % red() - % green() - % blue() ).str(); + return (boost::format("#%1$02x%2$02x%3$02x") + % red() + % green() + % blue() ).str(); } } diff --git a/src/expression_string.cpp b/src/expression_string.cpp new file mode 100644 index 000000000..b15f1bb88 --- /dev/null +++ b/src/expression_string.cpp @@ -0,0 +1,112 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2009 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 + * + *****************************************************************************/ + +//$Id$ + +#include +#include + +namespace mapnik +{ + +struct expression_string : boost::static_visitor +{ + explicit expression_string(std::string & str) + : str_(str) {} + + void operator() (value_type const& x) const + { + str_ += x.to_expression_string() ; + } + + void operator() (attribute const& attr) const + { + str_ += "["; + str_ += attr.name(); + str_ += "]"; + } + + template + void operator() (binary_node const& x) const + { + if (x.type() != tags::mult::str() && x.type() != tags::div::str()) + { + str_ += "("; + } + + boost::apply_visitor(expression_string(str_),x.left); + str_ += x.type(); + boost::apply_visitor(expression_string(str_),x.right); + if (x.type() != tags::mult::str() && x.type() != tags::div::str()) + { + str_ += ")"; + } + } + + template + void operator() (unary_node const& x) const + { + str_ += Tag::str(); + str_ += "("; + boost::apply_visitor(expression_string(str_),x.expr); + str_ += ")"; + } + + void operator() (regex_match_node const & x) const + { + boost::apply_visitor(expression_string(str_),x.expr); + str_ +=".match("; + std::string utf8; + UnicodeString ustr = UnicodeString::fromUTF32( &x.pattern.str()[0] ,x.pattern.str().length()); + to_utf8(ustr,utf8); + str_ += utf8; + str_ +=")"; + } + + void operator() (regex_replace_node const & x) const + { + boost::apply_visitor(expression_string(str_),x.expr); + str_ +=".replace("; + std::string utf8; + UnicodeString ustr = UnicodeString::fromUTF32( &x.pattern.str()[0] ,x.pattern.str().length()); + to_utf8(ustr,utf8); + str_ += "'"; + str_ += utf8; + str_ +="','"; + to_utf8(x.format ,utf8); + str_ += utf8; + str_ +="')"; + } + +private: + mutable std::string & str_; +}; + +std::string to_expression_string(expr_node const& node) +{ + std::string str; + expression_string functor(str); + boost::apply_visitor(functor,node); + return str; +} + +} diff --git a/src/filter_factory.cpp b/src/filter_factory.cpp index 8c178c212..04ea97298 100644 --- a/src/filter_factory.cpp +++ b/src/filter_factory.cpp @@ -22,17 +22,44 @@ //$Id$ #include +#include +#include + namespace mapnik { - filter_ptr create_filter (std::string const& wkt,std::string const& encoding) - { - transcoder tr(encoding); - return filter_factory::compile(wkt,tr); - } - - filter_ptr create_filter (std::string const& wkt) - { - return create_filter(wkt,"utf8"); - } + +class filter_factory +{ +public: + static expression_ptr compile(std::string const& str,transcoder const& tr) + { + expression_ptr expr(new expr_node(true)); + + std::string::const_iterator itr = str.begin(); + std::string::const_iterator end = str.end(); + mapnik::expression_grammar g(tr); + + bool r = boost::spirit::qi::phrase_parse(itr,end,g, boost::spirit::standard_wide::space,*expr); + if (r && itr==end) + { + return expr; + } + else + { + throw config_error( "Failed to parse filter expression:\""+str+"\"" ); + } + } +}; + +expression_ptr parse_expression (std::string const& wkt,std::string const& encoding) +{ + transcoder tr(encoding); + return filter_factory::compile(wkt,tr); +} + +expression_ptr parse_expression (std::string const& wkt) +{ + return parse_expression(wkt,"utf8"); +} } diff --git a/src/font_set.cpp b/src/font_set.cpp index 3a145111e..e52ca9ae4 100644 --- a/src/font_set.cpp +++ b/src/font_set.cpp @@ -30,17 +30,17 @@ namespace mapnik { - FontSet::FontSet() + font_set::font_set() : name_("") {} - FontSet::FontSet(std::string const& name) + font_set::font_set(std::string const& name) : name_(name) {} - FontSet::FontSet(FontSet const& rhs) + font_set::font_set(font_set const& rhs) : name_(rhs.name_), face_names_(rhs.face_names_) {} - FontSet& FontSet::operator=(FontSet const& other) + font_set& font_set::operator=(font_set const& other) { if (this == &other) return *this; @@ -50,24 +50,24 @@ namespace mapnik return *this; } - FontSet::~FontSet() {} + font_set::~font_set() {} - unsigned FontSet::size() const + unsigned font_set::size() const { return face_names_.size(); } - void FontSet::add_face_name(std::string face_name) + void font_set::add_face_name(std::string face_name) { face_names_.push_back(face_name); } - std::string const& FontSet::get_name() const + std::string const& font_set::get_name() const { return name_; } - std::vector const& FontSet::get_face_names() const + std::vector const& font_set::get_face_names() const { return face_names_; } diff --git a/src/graphics.cpp b/src/graphics.cpp index 60768c5ef..dbc1e779a 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -34,18 +34,18 @@ namespace mapnik { - Image32::Image32(int width,int height) + image_32::image_32(int width,int height) :width_(width), height_(height), data_(width,height) {} - Image32::Image32(const Image32& rhs) + image_32::image_32(const image_32& rhs) :width_(rhs.width_), height_(rhs.height_), data_(rhs.data_) {} #ifdef HAVE_CAIRO - Image32::Image32(Cairo::RefPtr rhs) + image_32::image_32(Cairo::RefPtr rhs) :width_(rhs->get_width()), height_(rhs->get_height()), data_(rhs->get_width(),rhs->get_height()) @@ -71,12 +71,12 @@ namespace mapnik unsigned int g = (in >> 8) & 0xff; unsigned int b = (in >> 0) & 0xff; -#define DE_ALPHA(x) do { \ - if (a == 0) x = 0; \ - else x = x * 255 / a; \ - if (x > 255) x = 255; \ +#define DE_ALPHA(x) do { \ + if (a == 0) x = 0; \ + else x = x * 255 / a; \ + if (x > 255) x = 255; \ } while(0) - + DE_ALPHA(r); DE_ALPHA(g); DE_ALPHA(b); @@ -88,20 +88,20 @@ namespace mapnik } #endif - Image32::~Image32() {} + image_32::~image_32() {} - const ImageData32& Image32::data() const + const image_data_32& image_32::data() const { return data_; } - void Image32::setBackground(const color& background) + void image_32::set_background(const color& background) { background_=background; data_.set(background_.rgba()); } - const color& Image32::getBackground() const + const color& image_32::get_background() const { return background_; } diff --git a/src/image_cache.cpp b/src/image_cache.cpp new file mode 100644 index 000000000..b586954d3 --- /dev/null +++ b/src/image_cache.cpp @@ -0,0 +1,95 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2009 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 + * + *****************************************************************************/ + +//$Id$ + +// mapnik +#include +#include + +// boost +#include +#include +#include + +namespace mapnik +{ + +boost::unordered_map image_cache::cache_; + +bool image_cache::insert (std::string const& uri, image_ptr img) +{ +#ifdef MAPNIK_THREADSAFE + mutex::scoped_lock lock(mutex_); +#endif + return cache_.insert(std::make_pair(uri,img)).second; +} + +boost::optional image_cache::find(std::string const& uri, bool update_cache) +{ +#ifdef MAPNIK_THREADSAFE + mutex::scoped_lock lock(mutex_); +#endif + typedef boost::unordered_map::const_iterator iterator_type; + boost::optional result; + iterator_type itr = cache_.find(uri); + if (itr != cache_.end()) + { + result.reset(itr->second); + return result; + } + + // we can't find image in cache, lets try to load it from filesystem + boost::filesystem::path path(uri); + if (exists(path)) + { + try + { + std::auto_ptr reader(mapnik::get_image_reader(uri)); + if (reader.get()) + { + unsigned width = reader->width(); + unsigned height = reader->height(); + BOOST_ASSERT(width > 0 && height > 0); + mapnik::image_ptr image(new mapnik::image_data_32(width,height)); + reader->read(0,0,*image); + result.reset(image); + if (update_cache) + { + cache_.insert(std::make_pair(uri,image)); + } + } + } + + catch (...) + { + std::cerr << "Exception caught while loading image: " << uri << std::endl; + } + } + return result; +} + +#ifdef MAPNIK_THREADSAFE + boost::mutex image_cache::mutex_; +#endif + +} diff --git a/src/image_reader.cpp b/src/image_reader.cpp index 61b173ddc..90f486b58 100644 --- a/src/image_reader.cpp +++ b/src/image_reader.cpp @@ -27,23 +27,28 @@ namespace mapnik { - typedef factory ImageReaderFactory; +typedef factory ImageReaderFactory; - bool register_image_reader(const std::string& type,ImageReader* (* fun)(const std::string&)) - { - return ImageReaderFactory::instance()->register_product(type,fun); - } - - ImageReader* get_image_reader(const std::string& filename,const std::string& type) - { - return ImageReaderFactory::instance()->create_object(type,filename); - } - - ImageReader* get_image_reader(const std::string& filename) - { - std::string type = type_from_filename(filename); - return ImageReaderFactory::instance()->create_object(filename,type); - } +bool register_image_reader(const std::string& type,image_reader* (* fun)(const std::string&)) +{ + return ImageReaderFactory::instance()->register_product(type,fun); +} + +image_reader* get_image_reader(const std::string& filename,const std::string& type) +{ + return ImageReaderFactory::instance()->create_object(type,filename); +} + +image_reader* get_image_reader(const std::string& filename) +{ + boost::optional type = type_from_filename(filename); + if (type) + { + return ImageReaderFactory::instance()->create_object(*type,filename); + } + return 0; +} + } diff --git a/src/image_util.cpp b/src/image_util.cpp index c9c2f26c3..32a91bd69 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -109,29 +109,32 @@ namespace mapnik template void save_to_file(T const& image,std::string const& filename) { - std::string type = type_from_filename(filename); - save_to_file(image,filename,type); + boost::optional type = type_from_filename(filename); + if (type) + { + save_to_file(image,filename,*type); + } } - template void save_to_file(ImageData32 const&, + template void save_to_file(image_data_32 const&, std::string const&, std::string const&); - template void save_to_file(ImageData32 const&, + template void save_to_file(image_data_32 const&, std::string const&); - template std::string save_to_string(ImageData32 const&, + template std::string save_to_string(image_data_32 const&, std::string const&); - template void save_to_file > (image_view const&, + template void save_to_file > (image_view const&, std::string const&, std::string const&); - template void save_to_file > (image_view const&, + template void save_to_file > (image_view const&, std::string const&); - template std::string save_to_string > (image_view const&, + template std::string save_to_string > (image_view const&, std::string const&); } diff --git a/src/layer.cpp b/src/layer.cpp index 8e955ad7f..3487df582 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -39,7 +39,7 @@ using boost::shared_ptr; namespace mapnik { - Layer::Layer(std::string const& name, std::string const& srs) + layer::layer(std::string const& name, std::string const& srs) : name_(name), title_(""), abstract_(""), @@ -51,7 +51,7 @@ namespace mapnik clear_label_cache_(false), ds_() {} - Layer::Layer(const Layer& rhs) + layer::layer(const layer& rhs) : name_(rhs.name_), title_(rhs.title_), abstract_(rhs.abstract_), @@ -64,19 +64,19 @@ namespace mapnik styles_(rhs.styles_), ds_(rhs.ds_) {} - Layer& Layer::operator=(const Layer& rhs) + layer& layer::operator=(const layer& rhs) { - Layer tmp(rhs); + layer tmp(rhs); swap(tmp); return *this; } - bool Layer::operator==(Layer const& other) const + bool layer::operator==(layer const& other) const { return (this == &other); } - void Layer::swap(const Layer& rhs) + void layer::swap(const layer& rhs) { name_=rhs.name_; title_=rhs.title_; @@ -91,130 +91,130 @@ namespace mapnik ds_=rhs.ds_; } - Layer::~Layer() {} + layer::~layer() {} - void Layer::set_name( std::string const& name) + void layer::set_name( std::string const& name) { name_ = name; } - string const& Layer::name() const + string const& layer::name() const { return name_; } - void Layer::set_title( std::string const& title) + void layer::set_title( std::string const& title) { title_ = title; } - string const& Layer::title() const + string const& layer::title() const { return title_; } - void Layer::set_abstract( std::string const& abstract) + void layer::set_abstract( std::string const& abstract) { abstract_ = abstract; } - string const& Layer::abstract() const + string const& layer::abstract() const { return abstract_; } - void Layer::set_srs(std::string const& srs) + void layer::set_srs(std::string const& srs) { srs_ = srs; } - std::string const& Layer::srs() const + std::string const& layer::srs() const { return srs_; } - void Layer::add_style(std::string const& stylename) + void layer::add_style(std::string const& stylename) { styles_.push_back(stylename); } - std::vector const& Layer::styles() const + std::vector const& layer::styles() const { return styles_; } - std::vector & Layer::styles() + std::vector & layer::styles() { return styles_; } - void Layer::setMinZoom(double minZoom) + void layer::setMinZoom(double minZoom) { minZoom_=minZoom; } - void Layer::setMaxZoom(double maxZoom) + void layer::setMaxZoom(double maxZoom) { maxZoom_=maxZoom; } - double Layer::getMinZoom() const + double layer::getMinZoom() const { return minZoom_; } - double Layer::getMaxZoom() const + double layer::getMaxZoom() const { return maxZoom_; } - void Layer::setActive(bool active) + void layer::setActive(bool active) { active_=active; } - bool Layer::isActive() const + bool layer::isActive() const { return active_; } - bool Layer::isVisible(double scale) const + bool layer::isVisible(double scale) const { return isActive() && scale >= minZoom_ - 1e-6 && scale < maxZoom_ + 1e-6; } - void Layer::setQueryable(bool queryable) + void layer::setQueryable(bool queryable) { queryable_=queryable; } - bool Layer::isQueryable() const + bool layer::isQueryable() const { return queryable_; } - datasource_ptr Layer::datasource() const + datasource_ptr layer::datasource() const { return ds_; } - void Layer::set_datasource(datasource_ptr const& ds) + void layer::set_datasource(datasource_ptr const& ds) { ds_ = ds; } - Envelope Layer::envelope() const + box2d layer::envelope() const { if (ds_) return ds_->envelope(); - return Envelope(); + return box2d(); } - void Layer::set_clear_label_cache(bool clear) + void layer::set_clear_label_cache(bool clear) { clear_label_cache_ = clear; } - bool Layer::clear_label_cache() const + bool layer::clear_label_cache() const { return clear_label_cache_; } diff --git a/src/libxml2_loader.cpp b/src/libxml2_loader.cpp index a453e7a8f..c82f379b8 100644 --- a/src/libxml2_loader.cpp +++ b/src/libxml2_loader.cpp @@ -165,7 +165,7 @@ namespace mapnik { ptree::iterator it = attr_list.push_back( ptree::value_type( (char*)cur_attr->name, ptree() )); - it->second.put_own( (char*) cur_attr->children->content ); + it->second.put_value( (char*) cur_attr->children->content ); } } } @@ -187,13 +187,13 @@ namespace mapnik } break; case XML_TEXT_NODE: - pt.put_own( (char*) cur_node->content ); + pt.put_value( (char*) cur_node->content ); break; case XML_COMMENT_NODE: { ptree::iterator it = pt.push_back( ptree::value_type( "", ptree() )); - it->second.put_own( (char*) cur_node->content ); + it->second.put_value( (char*) cur_node->content ); } break; default: diff --git a/src/line_pattern_symbolizer.cpp b/src/line_pattern_symbolizer.cpp index eaea4b694..c4ffc902a 100644 --- a/src/line_pattern_symbolizer.cpp +++ b/src/line_pattern_symbolizer.cpp @@ -21,23 +21,17 @@ *****************************************************************************/ //$Id$ + // mapnik #include -#include -// stl -#include - namespace mapnik { - line_pattern_symbolizer::line_pattern_symbolizer(std::string const& file, - std::string const& type, - unsigned width,unsigned height) - : symbolizer_with_image( file, type, width, height ) - { } +line_pattern_symbolizer::line_pattern_symbolizer(path_expression_ptr file) + : symbolizer_with_image(file) {} - line_pattern_symbolizer::line_pattern_symbolizer(line_pattern_symbolizer const& rhs) - : symbolizer_with_image(rhs) {} +line_pattern_symbolizer::line_pattern_symbolizer(line_pattern_symbolizer const& rhs) + : symbolizer_with_image(rhs) {} } diff --git a/src/load_map.cpp b/src/load_map.cpp index e0476449b..9a76758f5 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -26,7 +26,7 @@ #include #include #include -#include + #include #include #include @@ -35,6 +35,9 @@ #include #include +#include +#include + // boost #include #include @@ -65,7 +68,7 @@ namespace mapnik map_parser( bool strict, std::string const& filename = "" ) : strict_( strict ), filename_( filename ), - relative_to_xml_(true), + relative_to_xml_(false), font_manager_(font_engine_) {} void parse_map( Map & map, ptree const & sty); @@ -74,7 +77,7 @@ namespace mapnik void parse_layer( Map & map, ptree const & lay); void parse_fontset(Map & map, ptree const & fset); - void parse_font(FontSet & fset, ptree const & f); + void parse_font(font_set & fset, ptree const & f); void parse_rule( feature_type_style & style, ptree const & r); @@ -100,7 +103,7 @@ namespace mapnik freetype_engine font_engine_; face_manager font_manager_; std::map file_sources_; - std::map fontsets_; + std::map fontsets_; }; void load_map(Map & map, std::string const& filename, bool strict) @@ -238,7 +241,7 @@ namespace mapnik else if (v.first == "FileSource") { std::string name = get_attr( v.second, "name"); - std::string value = get_own( v.second, ""); + std::string value = get_value( v.second, ""); file_sources_[name] = value; } else if (v.first == "Datasource") @@ -254,7 +257,7 @@ namespace mapnik if (paramIter->first == "Parameter") { std::string name = get_attr(param, "name"); - std::string value = get_own( param, + std::string value = get_value( param, "datasource parameter"); params[name] = value; } @@ -324,7 +327,7 @@ namespace mapnik try { name = get_attr(fset, "name"); - FontSet fontset(name); + font_set fontset(name); ptree::const_iterator itr = fset.begin(); ptree::const_iterator end = fset.end(); @@ -349,7 +352,7 @@ namespace mapnik // XXX Hack because map object isn't accessible by text_symbolizer // when it's parsed - fontsets_.insert(pair(name, fontset)); + fontsets_.insert(pair(name, fontset)); } catch (const config_error & ex) { if ( ! name.empty() ) { ex.append_context(string("in FontSet '") + name + "'"); @@ -358,7 +361,7 @@ namespace mapnik } } - void map_parser::parse_font(FontSet & fset, ptree const & f) + void map_parser::parse_font(font_set & fset, ptree const & f) { std::string face_name = get_attr(f, "face_name", string()); @@ -380,7 +383,7 @@ namespace mapnik // XXX if no projection is given inherit from map? [DS] std::string srs = get_attr(lay, "srs", map.srs()); - Layer lyr(name, srs); + layer lyr(name, srs); optional status = get_opt_attr(lay, "status"); if (status) @@ -458,7 +461,7 @@ namespace mapnik if (paramIter->first == "Parameter") { std::string name = get_attr(param, "name"); - std::string value = get_own( param, + std::string value = get_value( param, "datasource parameter"); params[name] = value; } @@ -548,7 +551,7 @@ namespace mapnik if (filter_expr) { // can we use encoding defined for XML document for filter expressions? - rule.set_filter(create_filter(*filter_expr,"utf8")); + rule.set_filter(parse_expression(*filter_expr,"utf8")); } optional else_filter = @@ -656,11 +659,8 @@ namespace mapnik get_opt_attr(sym, "allow_overlap"); optional opacity = get_opt_attr(sym, "opacity"); - - optional width = get_opt_attr(sym, "width"); - optional height = get_opt_attr(sym, "height"); - - if (file && type && width && height) + + if (file && type) { try { @@ -682,8 +682,9 @@ namespace mapnik std::clog << "\nFound relative paths in xml, leaving unchanged...\n"; } #endif - - point_symbolizer symbol(*file,*type,*width,*height); + + point_symbolizer symbol(parse_path(*file)); + if (allow_overlap) { symbol.set_allow_overlap( * allow_overlap ); @@ -694,7 +695,7 @@ namespace mapnik } rule.append(symbol); } - catch (ImageReaderException const & ex ) + catch (image_reader_exception const & ex ) { string msg("Failed to load image file '" + * file + "': " + ex.what()); @@ -709,14 +710,12 @@ namespace mapnik } } - else if (file || type || width || height) + else if (file || type) { std::ostringstream os; os << "Missing required attributes: "; if ( ! file ) os << "file "; if ( ! type ) os << "type "; - if ( ! width ) os << "width "; - if ( ! height ) os << "height "; throw config_error( os.str() ); } else @@ -738,10 +737,8 @@ namespace mapnik std::string file = get_attr(sym, "file"); optional base = get_opt_attr(sym, "base"); std::string type = get_attr(sym, "type"); - unsigned width = get_attr(sym, "width"); - unsigned height = get_attr(sym, "height"); - - try + + try { if( base ) { @@ -762,10 +759,10 @@ namespace mapnik #endif - line_pattern_symbolizer symbol(file,type,width,height); + line_pattern_symbolizer symbol(parse_path(file)); rule.append(symbol); } - catch (ImageReaderException const & ex ) + catch (image_reader_exception const & ex ) { string msg("Failed to load image file '" + file + "': " + ex.what()); @@ -794,9 +791,7 @@ namespace mapnik std::string file = get_attr(sym, "file"); optional base = get_opt_attr(sym, "base"); std::string type = get_attr(sym, "type"); - unsigned width = get_attr(sym, "width"); - unsigned height = get_attr(sym, "height"); - + try { if( base ) @@ -816,11 +811,11 @@ namespace mapnik std::clog << "\nFound relative paths in xml, leaving unchanged...\n"; } #endif - - polygon_pattern_symbolizer symbol(file,type,width,height); + + polygon_pattern_symbolizer symbol(parse_path(file)); rule.append(symbol); } - catch (ImageReaderException const & ex ) + catch (image_reader_exception const & ex ) { string msg("Failed to load image file '" + file + "': " + ex.what()); @@ -846,7 +841,7 @@ namespace mapnik try { std::string name = get_attr(sym, "name"); - + optional face_name = get_opt_attr(sym, "face_name"); @@ -857,15 +852,15 @@ namespace mapnik color c = get_attr(sym, "fill", color(0,0,0)); - text_symbolizer text_symbol = text_symbolizer(name, size, c); - + text_symbolizer text_symbol = text_symbolizer(parse_expression(name, "utf8"), size, c); + if (fontset_name && face_name) { throw config_error(std::string("Can't have both face_name and fontset_name")); } else if (fontset_name) { - std::map::const_iterator itr = fontsets_.find(*fontset_name); + std::map::const_iterator itr = fontsets_.find(*fontset_name); if (itr != fontsets_.end()) { text_symbol.set_fontset(itr->second); @@ -1042,10 +1037,7 @@ namespace mapnik std::string image_file = get_attr(sym, "file"); optional base = get_opt_attr(sym, "base"); - std::string type = get_attr(sym, "type"); - unsigned width = get_attr(sym, "width"); - unsigned height = get_attr(sym, "height"); - + try { if( base ) @@ -1067,16 +1059,15 @@ namespace mapnik } #endif - shield_symbolizer shield_symbol(name,size,fill, - image_file,type,width,height); - - if (fontset_name && face_name) + shield_symbolizer shield_symbol(parse_expression(name, "utf8"),size,fill,parse_path(image_file)); + + if (fontset_name && face_name) { throw config_error(std::string("Can't have both face_name and fontset_name")); } else if (fontset_name) { - std::map::const_iterator itr = fontsets_.find(*fontset_name); + std::map::const_iterator itr = fontsets_.find(*fontset_name); if (itr != fontsets_.end()) { shield_symbol.set_fontset(itr->second); @@ -1230,7 +1221,7 @@ namespace mapnik rule.append(shield_symbol); } - catch (ImageReaderException const & ex ) + catch (image_reader_exception const & ex ) { string msg("Failed to load image file '" + image_file + "': " + ex.what()); diff --git a/src/map.cpp b/src/map.cpp index 718a7b63f..7e78c7b77 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -126,26 +126,26 @@ namespace mapnik styles_.erase(name); } - bool Map::insert_fontset(std::string const& name, FontSet const& fontset) + bool Map::insert_fontset(std::string const& name, font_set const& fontset) { return fontsets_.insert(make_pair(name, fontset)).second; } - FontSet const& Map::find_fontset(std::string const& name) const + font_set const& Map::find_fontset(std::string const& name) const { - std::map::const_iterator itr = fontsets_.find(name); + std::map::const_iterator itr = fontsets_.find(name); if (itr!=fontsets_.end()) return itr->second; - static FontSet default_fontset; + static font_set default_fontset; return default_fontset; } - std::map const& Map::fontsets() const + std::map const& Map::fontsets() const { return fontsets_; } - std::map & Map::fontsets() + std::map & Map::fontsets() { return fontsets_; } @@ -164,7 +164,7 @@ namespace mapnik return layers_.size(); } - void Map::addLayer(const Layer& l) + void Map::addLayer(const layer& l) { layers_.push_back(l); } @@ -179,22 +179,22 @@ namespace mapnik styles_.clear(); } - const Layer& Map::getLayer(size_t index) const + const layer& Map::getLayer(size_t index) const { return layers_[index]; } - Layer& Map::getLayer(size_t index) + layer& Map::getLayer(size_t index) { return layers_[index]; } - std::vector const& Map::layers() const + std::vector const& Map::layers() const { return layers_; } - std::vector & Map::layers() + std::vector & Map::layers() { return layers_; } @@ -273,7 +273,7 @@ namespace mapnik coord2d center = currentExtent_.center(); double w = factor * currentExtent_.width(); double h = factor * currentExtent_.height(); - currentExtent_ = Envelope(center.x - 0.5 * w, + currentExtent_ = box2d(center.x - 0.5 * w, center.y - 0.5 * h, center.x + 0.5 * w, center.y + 0.5 * h); @@ -285,17 +285,17 @@ namespace mapnik try { projection proj0(srs_); - Envelope ext; + box2d ext; bool first = true; - std::vector::const_iterator itr = layers_.begin(); - std::vector::const_iterator end = layers_.end(); + std::vector::const_iterator itr = layers_.begin(); + std::vector::const_iterator end = layers_.end(); while (itr != end) { std::string const& layer_srs = itr->srs(); projection proj1(layer_srs); proj_transform prj_trans(proj0,proj1); - Envelope layerExt = itr->envelope(); + box2d layerExt = itr->envelope(); double x0 = layerExt.minx(); double y0 = layerExt.miny(); double z0 = 0.0; @@ -305,7 +305,7 @@ namespace mapnik prj_trans.backward(x0,y0,z0); prj_trans.backward(x1,y1,z1); - Envelope layerExt2(x0,y0,x1,y1); + box2d layerExt2(x0,y0,x1,y1); #ifdef MAPNIK_DEBUG std::clog << " layer1 - > " << layerExt << "\n"; std::clog << " layer2 - > " << layerExt2 << "\n"; @@ -329,7 +329,7 @@ namespace mapnik } } - void Map::zoomToBox(const Envelope &box) + void Map::zoomToBox(const box2d &box) { currentExtent_=box; fixAspectRatio(); @@ -388,15 +388,15 @@ namespace mapnik } } - const Envelope& Map::getCurrentExtent() const + const box2d& Map::getCurrentExtent() const { return currentExtent_; } - Envelope Map::get_buffered_extent() const + box2d Map::get_buffered_extent() const { double extra = 2.0 * scale() * buffer_size_; - Envelope ext(currentExtent_); + box2d ext(currentExtent_); ext.width(currentExtent_.width() + extra); ext.height(currentExtent_.height() + extra); return ext; @@ -442,7 +442,7 @@ namespace mapnik { if ( index< layers_.size()) { - mapnik::Layer const& layer = layers_[index]; + mapnik::layer const& layer = layers_[index]; try { double z = 0; @@ -484,7 +484,7 @@ namespace mapnik { if ( index< layers_.size()) { - mapnik::Layer const& layer = layers_[index]; + mapnik::layer const& layer = layers_[index]; CoordTransform tr = view_transform(); tr.backward(&x,&y); diff --git a/src/memory_datasource.cpp b/src/memory_datasource.cpp index 542ee9632..293e5f720 100644 --- a/src/memory_datasource.cpp +++ b/src/memory_datasource.cpp @@ -30,7 +30,7 @@ namespace mapnik { struct accumulate_extent { - accumulate_extent(Envelope & ext) + accumulate_extent(box2d & ext) : ext_(ext),first_(true) {} void operator() (feature_ptr feat) @@ -50,7 +50,7 @@ namespace mapnik { } } - Envelope & ext_; + box2d & ext_; bool first_; }; @@ -79,9 +79,9 @@ namespace mapnik { return featureset_ptr(); } - Envelope memory_datasource::envelope() const + box2d memory_datasource::envelope() const { - Envelope ext; + box2d ext; accumulate_extent func(ext); std::for_each(features_.begin(),features_.end(),func); return ext; diff --git a/src/placement_finder.cpp b/src/placement_finder.cpp index af33b2be4..eb4d6e349 100644 --- a/src/placement_finder.cpp +++ b/src/placement_finder.cpp @@ -49,28 +49,25 @@ namespace mapnik { - placement::placement(string_info & info_, - shield_symbolizer const& sym, bool has_dimensions_) - : info(info_), - displacement_(sym.get_displacement()), - label_placement(sym.get_label_placement()), - wrap_width(sym.get_wrap_width()), - wrap_before(sym.get_wrap_before()), - wrap_char(sym.get_wrap_char()), - text_ratio(sym.get_text_ratio()), - label_spacing(sym.get_label_spacing()), - label_position_tolerance(sym.get_label_position_tolerance()), - force_odd_labels(sym.get_force_odd_labels()), - max_char_angle_delta(sym.get_max_char_angle_delta()), - minimum_distance(sym.get_minimum_distance()), - avoid_edges(sym.get_avoid_edges()), - has_dimensions(has_dimensions_), - allow_overlap(false), - dimensions(std::make_pair(sym.get_image()->width(), - sym.get_image()->height())), - text_size(sym.get_text_size()) - { - } +placement::placement(string_info & info_, shield_symbolizer const& sym, + unsigned w, unsigned h, bool has_dimensions_) + : info(info_), + displacement_(sym.get_displacement()), + label_placement(sym.get_label_placement()), + wrap_width(sym.get_wrap_width()), + wrap_before(sym.get_wrap_before()), + wrap_char(sym.get_wrap_char()), + text_ratio(sym.get_text_ratio()), + label_spacing(sym.get_label_spacing()), + label_position_tolerance(sym.get_label_position_tolerance()), + force_odd_labels(sym.get_force_odd_labels()), + max_char_angle_delta(sym.get_max_char_angle_delta()), + minimum_distance(sym.get_minimum_distance()), + avoid_edges(sym.get_avoid_edges()), + has_dimensions(has_dimensions_), + allow_overlap(false), + dimensions(std::make_pair(w,h)), + text_size(sym.get_text_size()) {} placement::placement(string_info & info_, text_symbolizer const& sym) @@ -93,7 +90,8 @@ namespace mapnik text_size(sym.get_text_size()) {} - placement::~placement() {} + +placement::~placement() {} template std::pair get_position_at_distance(double target_distance, T & shape_path) @@ -353,7 +351,7 @@ namespace mapnik x = (string_width / 2.0) - line_width; // save each character rendering position and build envelope as go thru loop - std::queue< Envelope > c_envelopes; + std::queue< box2d > c_envelopes; for (unsigned i = 0; i < p.info.num_characters(); i++) { @@ -381,7 +379,7 @@ namespace mapnik // compute the Bounding Box for each character and test for: // overlap, minimum distance or edge avoidance - exit if condition occurs - Envelope e; + box2d e; if (p.has_dimensions) { e.init(current_placement->starting_x - (p.dimensions.first/2.0), // Top Left @@ -801,7 +799,7 @@ namespace mapnik angle += M_PI; } - Envelope e; + box2d e; if (p.has_dimensions) { e.init(x, y, x + p.dimensions.first, y + p.dimensions.second); @@ -893,7 +891,7 @@ namespace mapnik { while (!p.envelopes.empty()) { - Envelope e = p.envelopes.front(); + box2d e = p.envelopes.front(); detector_.insert(e, p.info.get_string()); p.envelopes.pop(); } diff --git a/src/png_reader.cpp b/src/png_reader.cpp index 24ae5043b..483eb33c5 100644 --- a/src/png_reader.cpp +++ b/src/png_reader.cpp @@ -38,7 +38,7 @@ extern "C" namespace mapnik { - class PngReader : public ImageReader, boost::noncopyable + class png_reader : public image_reader, boost::noncopyable { private: std::string fileName_; @@ -47,25 +47,25 @@ namespace mapnik int bit_depth_; int color_type_; public: - explicit PngReader(const std::string& fileName); - ~PngReader(); + explicit png_reader(const std::string& fileName); + ~png_reader(); unsigned width() const; unsigned height() const; - void read(unsigned x,unsigned y,ImageData32& image); + void read(unsigned x,unsigned y,image_data_32& image); private: void init(); }; namespace { - ImageReader* createPngReader(const std::string& file) + image_reader* create_png_reader(const std::string& file) { - return new PngReader(file); + return new png_reader(file); } - const bool registered = register_image_reader("png",createPngReader); + const bool registered = register_image_reader("png",create_png_reader); } - PngReader::PngReader(const std::string& fileName) + png_reader::png_reader(const std::string& fileName) : fileName_(fileName), width_(0), height_(0), @@ -75,7 +75,7 @@ namespace mapnik init(); } - PngReader::~PngReader() {} + png_reader::~png_reader() {} static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) @@ -91,10 +91,10 @@ namespace mapnik } - void PngReader::init() + void png_reader::init() { FILE *fp=fopen(fileName_.c_str(),"rb"); - if (!fp) throw ImageReaderException("cannot open image file "+fileName_); + if (!fp) throw image_reader_exception("cannot open image file "+fileName_); png_byte header[8]; memset(header,0,8); fread(header,1,8,fp); @@ -102,7 +102,7 @@ namespace mapnik if (!is_png) { fclose(fp); - throw ImageReaderException(fileName_ + " is not a png file"); + throw image_reader_exception(fileName_ + " is not a png file"); } png_structp png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,0,0,0); @@ -110,14 +110,14 @@ namespace mapnik if (!png_ptr) { fclose(fp); - throw ImageReaderException("failed to allocate png_ptr"); + throw image_reader_exception("failed to allocate png_ptr"); } png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr,0,0); fclose(fp); - throw ImageReaderException("failed to create info_ptr"); + throw image_reader_exception("failed to create info_ptr"); } png_set_read_fn(png_ptr, (png_voidp)fp, png_read_data); @@ -137,20 +137,20 @@ namespace mapnik fclose(fp); } - unsigned PngReader::width() const + unsigned png_reader::width() const { return width_; } - unsigned PngReader::height() const + unsigned png_reader::height() const { return height_; } - void PngReader::read(unsigned x0, unsigned y0,ImageData32& image) + void png_reader::read(unsigned x0, unsigned y0,image_data_32& image) { FILE *fp=fopen(fileName_.c_str(),"rb"); - if (!fp) throw ImageReaderException("cannot open image file "+fileName_); + if (!fp) throw image_reader_exception("cannot open image file "+fileName_); png_structp png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,0,0,0); @@ -158,7 +158,7 @@ namespace mapnik if (!png_ptr) { fclose(fp); - throw ImageReaderException("failed to allocate png_ptr"); + throw image_reader_exception("failed to allocate png_ptr"); } png_infop info_ptr = png_create_info_struct(png_ptr); @@ -166,7 +166,7 @@ namespace mapnik { png_destroy_read_struct(&png_ptr,0,0); fclose(fp); - throw ImageReaderException("failed to create info_ptr"); + throw image_reader_exception("failed to create info_ptr"); } png_set_read_fn(png_ptr, (png_voidp)fp, png_read_data); diff --git a/src/point_symbolizer.cpp b/src/point_symbolizer.cpp index df3e6fd7c..b4866e2bf 100644 --- a/src/point_symbolizer.cpp +++ b/src/point_symbolizer.cpp @@ -34,19 +34,13 @@ namespace mapnik { point_symbolizer::point_symbolizer() - : symbolizer_with_image(boost::shared_ptr(new ImageData32(4,4))), + : symbolizer_with_image(path_expression_ptr(new path_expression)), // FIXME opacity_(1.0), - overlap_(false) - -{ - //default point symbol is black 4x4px square - image_->set(0xff000000); -} + overlap_(false) +{} -point_symbolizer::point_symbolizer(std::string const& file, - std::string const& type, - unsigned width,unsigned height) - : symbolizer_with_image(file, type, width, height), +point_symbolizer::point_symbolizer(path_expression_ptr file) + : symbolizer_with_image(file), opacity_(1.0), overlap_(false) @@ -57,7 +51,7 @@ point_symbolizer::point_symbolizer(point_symbolizer const& rhs) opacity_(rhs.opacity_), overlap_(rhs.overlap_) {} - + void point_symbolizer::set_allow_overlap(bool overlap) { overlap_ = overlap; diff --git a/src/polygon_pattern_symbolizer.cpp b/src/polygon_pattern_symbolizer.cpp index 237fa6d43..4af1c14fe 100644 --- a/src/polygon_pattern_symbolizer.cpp +++ b/src/polygon_pattern_symbolizer.cpp @@ -20,23 +20,20 @@ * *****************************************************************************/ //$Id$ + // mapnik #include -#include -// stl -#include - namespace mapnik { - polygon_pattern_symbolizer::polygon_pattern_symbolizer(std::string const& file, - std::string const& type, - unsigned width,unsigned height) - : symbolizer_with_image( file, type, width, height ) - { - } - polygon_pattern_symbolizer::polygon_pattern_symbolizer(polygon_pattern_symbolizer const& rhs) - : symbolizer_with_image(rhs) {} - + +polygon_pattern_symbolizer::polygon_pattern_symbolizer(path_expression_ptr file) + : symbolizer_with_image(file) +{ +} + +polygon_pattern_symbolizer::polygon_pattern_symbolizer(polygon_pattern_symbolizer const& rhs) + : symbolizer_with_image(rhs) {} + } diff --git a/src/save_map.cpp b/src/save_map.cpp index 3031858ef..6dbcd1522 100644 --- a/src/save_map.cpp +++ b/src/save_map.cpp @@ -20,10 +20,12 @@ * *****************************************************************************/ // $Id$ + // mapnik #include #include #include +#include // boost #include @@ -172,7 +174,10 @@ namespace mapnik // to avoid printing of attributes with default values without // repeating the default values here. // maybe add a real, explicit default-ctor? - shield_symbolizer sym_dfl("", "", 0, color(0,0,0), "", "", 0, 0 ); + + //FIXME pls + /* + shield_symbolizer sym_dfl("", "", 0, color(0,0,0), "", ""); if (sym.get_unlock_image() != sym_dfl.get_unlock_image() || explicit_defaults_ ) { set_attr( sym_node, "unlock_image", sym.get_unlock_image() ); @@ -181,6 +186,7 @@ namespace mapnik { set_attr( sym_node, "no_text", sym.get_no_text() ); } + */ } void operator () ( const text_symbolizer & sym ) @@ -221,29 +227,18 @@ namespace mapnik serialize_symbolizer(); void add_image_attributes(ptree & node, const symbolizer_with_image & sym) { - const std::string & filename = sym.get_filename(); - if ( ! filename.empty() ) { - set_attr( node, "file", filename ); - set_attr( node, "type", guess_type( filename ) ); - - boost::shared_ptr img = sym.get_image(); - if ( img ) - { - if ( img->width() > 0) - { - set_attr( node, "width", img->width() ); - } - if ( img->height() > 0) - { - set_attr( node, "height", img->height() ); - } - } - - } + std::string filename = path_processor_type::to_string( *sym.get_filename()); +// FIXME pls + //if ( ! filename.empty() ) { + set_attr( node, "file", filename ); + //set_attr( node, "type", guess_type( filename ) ); + //} } void add_font_attributes(ptree & node, const text_symbolizer & sym) { - const std::string & name = sym.get_name(); + std::string name = to_expression_string(sym.get_name()); + + //const std::string & name = sym.get_name(); if ( ! name.empty() ) { set_attr( node, "name", name ); } @@ -263,7 +258,8 @@ namespace mapnik // to avoid printing ofattributes with default values without // repeating the default values here. // maybe add a real, explicit default-ctor? - text_symbolizer dfl("", "", + // FIXME + text_symbolizer dfl(expression_ptr(), "", 0, color(0,0,0) ); position displacement = sym.get_displacement(); @@ -379,31 +375,34 @@ namespace mapnik else { // filters are not comparable, so compare strings for now - std::string filter = rule.get_filter()->to_string(); + // TODO !!!!! +/* + std::string filter = rule.get_filter()->to_string(); std::string default_filter = dfl.get_filter()->to_string(); if ( filter != default_filter) { rule_node.push_back( ptree::value_type( - "Filter", ptree()))->second.put_own( filter ); + "Filter", ptree()))->second.put_value( filter ); } + */ } if (rule.get_min_scale() != dfl.get_min_scale() ) { ptree & min_scale = rule_node.push_back( ptree::value_type( "MinScaleDenominator", ptree()))->second; - min_scale.put_own( rule.get_min_scale() ); + min_scale.put_value( rule.get_min_scale() ); } if (rule.get_max_scale() != dfl.get_max_scale() ) { ptree & max_scale = rule_node.push_back( ptree::value_type( "MaxScaleDenominator", ptree()))->second; - max_scale.put_own( rule.get_max_scale() ); + max_scale.put_value( rule.get_max_scale() ); } - symbolizers::const_iterator begin = rule.get_symbolizers().begin(); - symbolizers::const_iterator end = rule.get_symbolizers().end(); + rule_type::symbolizers::const_iterator begin = rule.get_symbolizers().begin(); + rule_type::symbolizers::const_iterator end = rule.get_symbolizers().end(); serialize_symbolizer serializer( rule_node, explicit_defaults); std::for_each( begin, end , boost::apply_visitor( serializer )); } @@ -429,11 +428,11 @@ namespace mapnik void serialize_fontset( ptree & map_node, Map::const_fontset_iterator fontset_it ) { - const FontSet & fontset = fontset_it->second; + const font_set & fontset = fontset_it->second; const std::string & name = fontset_it->first; ptree & fontset_node = map_node.push_back( - ptree::value_type("FontSet", ptree()))->second; + ptree::value_type("font_set", ptree()))->second; set_attr(fontset_node, "name", name); @@ -461,12 +460,12 @@ namespace mapnik boost::property_tree::ptree::value_type("Parameter", boost::property_tree::ptree()))->second; param_node.put(".name", it->first ); - param_node.put_own( it->second ); + param_node.put_value( it->second ); } } - void serialize_layer( ptree & map_node, const Layer & layer, bool explicit_defaults ) + void serialize_layer( ptree & map_node, const layer & layer, bool explicit_defaults ) { ptree & layer_node = map_node.push_back( ptree::value_type("Layer", ptree()))->second; @@ -521,7 +520,7 @@ namespace mapnik boost::property_tree::ptree & style_node = layer_node.push_back( boost::property_tree::ptree::value_type("StyleName", boost::property_tree::ptree()))->second; - style_node.put_own( style_names[i] ); + style_node.put_value( style_names[i] ); } datasource_ptr datasource = layer.datasource(); @@ -560,7 +559,7 @@ namespace mapnik serialize_style( map_node, it, explicit_defaults); } - std::vector const & layers = map.layers(); + std::vector const & layers = map.layers(); for (unsigned i = 0; i < layers.size(); ++i ) { serialize_layer( map_node, layers[i], explicit_defaults ); diff --git a/src/shield_symbolizer.cpp b/src/shield_symbolizer.cpp index ffc9400d1..189870752 100644 --- a/src/shield_symbolizer.cpp +++ b/src/shield_symbolizer.cpp @@ -34,53 +34,51 @@ namespace mapnik { - shield_symbolizer::shield_symbolizer( - std::string const& name, - std::string const& face_name, - unsigned size, - color const& fill, - std::string const& file, - std::string const& type, - unsigned width,unsigned height) - : text_symbolizer(name, face_name, size, fill), - symbolizer_with_image( file, type, width, height ), - unlock_image_(false), - no_text_(false) - { - } - shield_symbolizer::shield_symbolizer( - std::string const& name, - unsigned size, - color const& fill, - std::string const& file, - std::string const& type, - unsigned width,unsigned height) - : text_symbolizer(name, size, fill), - symbolizer_with_image( file, type, width, height ), - unlock_image_(false), - no_text_(false) - { - } - - void shield_symbolizer::set_unlock_image(bool unlock_image) - { - unlock_image_ = unlock_image; - } - - bool shield_symbolizer::get_unlock_image() const - { - return unlock_image_; - } - - void shield_symbolizer::set_no_text(bool no_text) - { - no_text_ = no_text; - } - - bool shield_symbolizer::get_no_text() const - { - return no_text_; - } +shield_symbolizer::shield_symbolizer( + expression_ptr name, + std::string const& face_name, + unsigned size, + color const& fill, + path_expression_ptr file) + : text_symbolizer(name, face_name, size, fill), + symbolizer_with_image(file), + unlock_image_(false), + no_text_(false) +{ +} + +shield_symbolizer::shield_symbolizer( + expression_ptr name, + unsigned size, + color const& fill, + path_expression_ptr file) + : text_symbolizer(name, size, fill), + symbolizer_with_image(file), + unlock_image_(false), + no_text_(false) +{ +} + +void shield_symbolizer::set_unlock_image(bool unlock_image) +{ + unlock_image_ = unlock_image; +} + +bool shield_symbolizer::get_unlock_image() const +{ + return unlock_image_; +} + +void shield_symbolizer::set_no_text(bool no_text) +{ + no_text_ = no_text; +} + +bool shield_symbolizer::get_no_text() const +{ + return no_text_; +} + } diff --git a/src/symbolizer.cpp b/src/symbolizer.cpp index 9eb8f3dd1..2b4d2feb0 100644 --- a/src/symbolizer.cpp +++ b/src/symbolizer.cpp @@ -21,49 +21,27 @@ *****************************************************************************/ //$Id$ +//mapnik #include -#include - -#include - namespace mapnik { - symbolizer_with_image::symbolizer_with_image(boost::shared_ptr img) : - image_( img ) {} +symbolizer_with_image::symbolizer_with_image(path_expression_ptr file) + : image_filename_( file ) {} - symbolizer_with_image::symbolizer_with_image(std::string const& file, - std::string const& type, unsigned width,unsigned height) - : image_(new ImageData32(width,height)), - image_filename_( file ) - { - std::auto_ptr reader(get_image_reader(file,type)); - if (reader.get()) - reader->read(0,0,*image_); - } +symbolizer_with_image::symbolizer_with_image( symbolizer_with_image const& rhs) + : image_filename_(rhs.image_filename_) {} - symbolizer_with_image::symbolizer_with_image( symbolizer_with_image const& rhs) - : image_(rhs.image_), image_filename_(rhs.image_filename_) {} - - - boost::shared_ptr symbolizer_with_image::get_image() const - { - return image_; - } - void symbolizer_with_image::set_image(boost::shared_ptr image) - { - image_ = image; - } - - std::string const& symbolizer_with_image::get_filename() const - { - return image_filename_; - } - void symbolizer_with_image::set_filename(std::string const& image_filename) - { - image_filename_ = image_filename; - } +path_expression_ptr symbolizer_with_image::get_filename() const +{ + return image_filename_; +} + +void symbolizer_with_image::set_filename(path_expression_ptr image_filename) +{ + image_filename_ = image_filename; +} } // end of namespace mapnik diff --git a/src/text_symbolizer.cpp b/src/text_symbolizer.cpp index dae9d7da6..73954a330 100644 --- a/src/text_symbolizer.cpp +++ b/src/text_symbolizer.cpp @@ -80,418 +80,418 @@ IMPLEMENT_ENUM( mapnik::text_convert_e, text_convert_strings ); namespace mapnik { - text_symbolizer::text_symbolizer(std::string const& name, std::string const& face_name, unsigned size, color const& fill) - : name_(name), - face_name_(face_name), - //fontset_(default_fontset), - size_(size), - text_ratio_(0), - wrap_width_(0), - wrap_char_(' '), - text_convert_(NONE), - line_spacing_(0), - character_spacing_(0), - label_spacing_(0), - label_position_tolerance_(0), - force_odd_labels_(false), - max_char_angle_delta_(0.0), - fill_(fill), - halo_fill_(color(255,255,255)), - halo_radius_(0), - label_p_(POINT_PLACEMENT), - valign_(BOTTOM), - anchor_(0.0,0.5), - displacement_(0.0,0.0), - avoid_edges_(false), - minimum_distance_(0.0), - overlap_(false), - opacity_(1.0), - wrap_before_(false), - halign_(H_MIDDLE), - jalign_(J_MIDDLE) {} +text_symbolizer::text_symbolizer(expression_ptr name, std::string const& face_name, unsigned size, color const& fill) + : name_(name), + face_name_(face_name), + //fontset_(default_fontset), + size_(size), + text_ratio_(0), + wrap_width_(0), + wrap_char_(' '), + text_convert_(NONE), + line_spacing_(0), + character_spacing_(0), + label_spacing_(0), + label_position_tolerance_(0), + force_odd_labels_(false), + max_char_angle_delta_(0.0), + fill_(fill), + halo_fill_(color(255,255,255)), + halo_radius_(0), + label_p_(POINT_PLACEMENT), + valign_(BOTTOM), + anchor_(0.0,0.5), + displacement_(0.0,0.0), + avoid_edges_(false), + minimum_distance_(0.0), + overlap_(false), + opacity_(1.0), + wrap_before_(false), + halign_(H_MIDDLE), + jalign_(J_MIDDLE) {} - text_symbolizer::text_symbolizer(std::string const& name, unsigned size, color const& fill) - : name_(name), - //face_name_(""), - //fontset_(default_fontset), - size_(size), - text_ratio_(0), - wrap_width_(0), - wrap_char_(' '), - text_convert_(NONE), - line_spacing_(0), - character_spacing_(0), - label_spacing_(0), - label_position_tolerance_(0), - force_odd_labels_(false), - max_char_angle_delta_(0.0), - fill_(fill), - halo_fill_(color(255,255,255)), - halo_radius_(0), - label_p_(POINT_PLACEMENT), - valign_(BOTTOM), - anchor_(0.0,0.5), - displacement_(0.0,0.0), - avoid_edges_(false), - minimum_distance_(0.0), - overlap_(false), - opacity_(1.0), - wrap_before_(false), - halign_(H_MIDDLE), - jalign_(J_MIDDLE) {} +text_symbolizer::text_symbolizer(expression_ptr name, unsigned size, color const& fill) + : name_(name), + //face_name_(""), + //fontset_(default_fontset), + size_(size), + text_ratio_(0), + wrap_width_(0), + wrap_char_(' '), + text_convert_(NONE), + line_spacing_(0), + character_spacing_(0), + label_spacing_(0), + label_position_tolerance_(0), + force_odd_labels_(false), + max_char_angle_delta_(0.0), + fill_(fill), + halo_fill_(color(255,255,255)), + halo_radius_(0), + label_p_(POINT_PLACEMENT), + valign_(BOTTOM), + anchor_(0.0,0.5), + displacement_(0.0,0.0), + avoid_edges_(false), + minimum_distance_(0.0), + overlap_(false), + opacity_(1.0), + wrap_before_(false), + halign_(H_MIDDLE), + jalign_(J_MIDDLE) {} - text_symbolizer::text_symbolizer(text_symbolizer const& rhs) - : name_(rhs.name_), - face_name_(rhs.face_name_), - fontset_(rhs.fontset_), - size_(rhs.size_), - text_ratio_(rhs.text_ratio_), - wrap_width_(rhs.wrap_width_), - wrap_char_(rhs.wrap_char_), - text_convert_(rhs.text_convert_), - line_spacing_(rhs.line_spacing_), - character_spacing_(rhs.character_spacing_), - label_spacing_(rhs.label_spacing_), - label_position_tolerance_(rhs.label_position_tolerance_), - force_odd_labels_(rhs.force_odd_labels_), - max_char_angle_delta_(rhs.max_char_angle_delta_), - fill_(rhs.fill_), - halo_fill_(rhs.halo_fill_), - halo_radius_(rhs.halo_radius_), - label_p_(rhs.label_p_), - valign_(rhs.valign_), - anchor_(rhs.anchor_), - displacement_(rhs.displacement_), - avoid_edges_(rhs.avoid_edges_), - minimum_distance_(rhs.minimum_distance_), - overlap_(rhs.overlap_), - opacity_(rhs.opacity_), - wrap_before_(rhs.wrap_before_), - halign_(rhs.halign_), - jalign_(rhs.jalign_) {} +text_symbolizer::text_symbolizer(text_symbolizer const& rhs) + : name_(rhs.name_), + face_name_(rhs.face_name_), + fontset_(rhs.fontset_), + size_(rhs.size_), + text_ratio_(rhs.text_ratio_), + wrap_width_(rhs.wrap_width_), + wrap_char_(rhs.wrap_char_), + text_convert_(rhs.text_convert_), + line_spacing_(rhs.line_spacing_), + character_spacing_(rhs.character_spacing_), + label_spacing_(rhs.label_spacing_), + label_position_tolerance_(rhs.label_position_tolerance_), + force_odd_labels_(rhs.force_odd_labels_), + max_char_angle_delta_(rhs.max_char_angle_delta_), + fill_(rhs.fill_), + halo_fill_(rhs.halo_fill_), + halo_radius_(rhs.halo_radius_), + label_p_(rhs.label_p_), + valign_(rhs.valign_), + anchor_(rhs.anchor_), + displacement_(rhs.displacement_), + avoid_edges_(rhs.avoid_edges_), + minimum_distance_(rhs.minimum_distance_), + overlap_(rhs.overlap_), + opacity_(rhs.opacity_), + wrap_before_(rhs.wrap_before_), + halign_(rhs.halign_), + jalign_(rhs.jalign_) {} - text_symbolizer& text_symbolizer::operator=(text_symbolizer const& other) - { - if (this == &other) - return *this; - name_ = other.name_; - face_name_ = other.face_name_; - fontset_ = other.fontset_; - size_ = other.size_; - text_ratio_ = other.text_ratio_; - wrap_width_ = other.wrap_width_; - wrap_char_ = other.wrap_char_; - text_convert_ = other.text_convert_; - line_spacing_ = other.line_spacing_; - character_spacing_ = other.character_spacing_; - label_spacing_ = other.label_spacing_; - label_position_tolerance_ = other.label_position_tolerance_; - force_odd_labels_ = other.force_odd_labels_; - max_char_angle_delta_ = other.max_char_angle_delta_; - fill_ = other.fill_; - halo_fill_ = other.halo_fill_; - halo_radius_ = other.halo_radius_; - label_p_ = other.label_p_; - valign_ = other.valign_; - anchor_ = other.anchor_; - displacement_ = other.displacement_; - avoid_edges_ = other.avoid_edges_; - minimum_distance_ = other.minimum_distance_; - overlap_ = other.overlap_; - opacity_ = other.opacity_; - wrap_before_ = other.wrap_before_; - halign_ = other.halign_; - jalign_ = other.jalign_; - return *this; - } - - std::string const& text_symbolizer::get_name() const - { - return name_; - } - - void text_symbolizer::set_name(std::string name) - { - name_ = name; - } - - std::string const& text_symbolizer::get_face_name() const - { - return face_name_; - } - - void text_symbolizer::set_face_name(std::string face_name) - { - face_name_ = face_name; - } - - void text_symbolizer::set_fontset(FontSet const& fontset) - { - fontset_ = fontset; - } - - FontSet const& text_symbolizer::get_fontset() const - { - return fontset_; - } - - unsigned text_symbolizer::get_text_ratio() const - { - return text_ratio_; - } - - void text_symbolizer::set_text_ratio(unsigned ratio) - { - text_ratio_ = ratio; - } - - unsigned text_symbolizer::get_wrap_width() const - { - return wrap_width_; - } - - void text_symbolizer::set_wrap_width(unsigned width) - { - wrap_width_ = width; - } - - bool text_symbolizer::get_wrap_before() const - { - return wrap_before_; - } - - void text_symbolizer::set_wrap_before(bool wrap_before) - { - wrap_before_ = wrap_before; - } - - unsigned char text_symbolizer::get_wrap_char() const - { - return wrap_char_; - } - - std::string text_symbolizer::get_wrap_char_string() const - { - return std::string(1, wrap_char_); - } - - void text_symbolizer::set_wrap_char(unsigned char character) - { - wrap_char_ = character; - } - - void text_symbolizer::set_wrap_char_from_string(std::string const& character) - { - wrap_char_ = (character)[0]; - } - - text_convert_e text_symbolizer::get_text_convert() const - { - return text_convert_; - } - - void text_symbolizer::set_text_convert(text_convert_e convert) - { - text_convert_ = convert; - } - - unsigned text_symbolizer::get_line_spacing() const - { - return line_spacing_; - } - - void text_symbolizer::set_line_spacing(unsigned spacing) - { - line_spacing_ = spacing; - } - - unsigned text_symbolizer::get_character_spacing() const - { - return character_spacing_; - } - - void text_symbolizer::set_character_spacing(unsigned spacing) - { - character_spacing_ = spacing; - } - - unsigned text_symbolizer::get_label_spacing() const - { - return label_spacing_; - } - - void text_symbolizer::set_label_spacing(unsigned spacing) - { - label_spacing_ = spacing; - } - - unsigned text_symbolizer::get_label_position_tolerance() const - { - return label_position_tolerance_; - } - - void text_symbolizer::set_label_position_tolerance(unsigned tolerance) - { - label_position_tolerance_ = tolerance; - } - - bool text_symbolizer::get_force_odd_labels() const - { - return force_odd_labels_; - } - - void text_symbolizer::set_force_odd_labels(bool force) - { - force_odd_labels_ = force; - } - - double text_symbolizer::get_max_char_angle_delta() const - { - return max_char_angle_delta_; - } - - void text_symbolizer::set_max_char_angle_delta(double angle) - { - max_char_angle_delta_ = angle; - } - - void text_symbolizer::set_text_size(unsigned size) - { - size_ = size; - } - - unsigned text_symbolizer::get_text_size() const - { - return size_; - } - - void text_symbolizer::set_fill(color const& fill) - { - fill_ = fill; - } - - color const& text_symbolizer::get_fill() const - { - return fill_; - } - - void text_symbolizer::set_halo_fill(color const& fill) - { - halo_fill_ = fill; - } - - color const& text_symbolizer::get_halo_fill() const - { - return halo_fill_; - } - - void text_symbolizer::set_halo_radius(unsigned radius) - { - halo_radius_ = radius; - } - - unsigned text_symbolizer::get_halo_radius() const - { - return halo_radius_; - } - - void text_symbolizer::set_label_placement(label_placement_e label_p) - { - label_p_ = label_p; - } - - label_placement_e text_symbolizer::get_label_placement() const - { - return label_p_; - } - - void text_symbolizer::set_vertical_alignment(vertical_alignment_e valign) - { - valign_ = valign; - } - - vertical_alignment_e text_symbolizer::get_vertical_alignment() const - { - return valign_; - } - - void text_symbolizer::set_anchor(double x, double y) - { - anchor_ = boost::make_tuple(x,y); - } - - position const& text_symbolizer::get_anchor() const - { - return anchor_; - } - - void text_symbolizer::set_displacement(double x, double y) - { - displacement_ = boost::make_tuple(x,y); - } - - position const& text_symbolizer::get_displacement() const - { - return displacement_; - } - - bool text_symbolizer::get_avoid_edges() const - { - return avoid_edges_; - } - - void text_symbolizer::set_avoid_edges(bool avoid) - { - avoid_edges_ = avoid; - } - - double text_symbolizer::get_minimum_distance() const - { - return minimum_distance_; - } - - void text_symbolizer::set_minimum_distance(double distance) - { - minimum_distance_ = distance; - } - - void text_symbolizer::set_allow_overlap(bool overlap) - { - overlap_ = overlap; - } - - bool text_symbolizer::get_allow_overlap() const - { - return overlap_; - } - - void text_symbolizer::set_opacity(double opacity) - { - opacity_ = opacity; - } - - double text_symbolizer::get_opacity() const - { - return opacity_; - } - - void text_symbolizer::set_horizontal_alignment(horizontal_alignment_e halign) - { - halign_ = halign; - } - - horizontal_alignment_e text_symbolizer::get_horizontal_alignment() const - { - return halign_; - } - - void text_symbolizer::set_justify_alignment(justify_alignment_e jalign) - { - jalign_ = jalign; - } - - justify_alignment_e text_symbolizer::get_justify_alignment() const - { - return jalign_; - } +text_symbolizer& text_symbolizer::operator=(text_symbolizer const& other) +{ + if (this == &other) + return *this; + name_ = other.name_; + face_name_ = other.face_name_; + fontset_ = other.fontset_; + size_ = other.size_; + text_ratio_ = other.text_ratio_; + wrap_width_ = other.wrap_width_; + wrap_char_ = other.wrap_char_; + text_convert_ = other.text_convert_; + line_spacing_ = other.line_spacing_; + character_spacing_ = other.character_spacing_; + label_spacing_ = other.label_spacing_; + label_position_tolerance_ = other.label_position_tolerance_; + force_odd_labels_ = other.force_odd_labels_; + max_char_angle_delta_ = other.max_char_angle_delta_; + fill_ = other.fill_; + halo_fill_ = other.halo_fill_; + halo_radius_ = other.halo_radius_; + label_p_ = other.label_p_; + valign_ = other.valign_; + anchor_ = other.anchor_; + displacement_ = other.displacement_; + avoid_edges_ = other.avoid_edges_; + minimum_distance_ = other.minimum_distance_; + overlap_ = other.overlap_; + opacity_ = other.opacity_; + wrap_before_ = other.wrap_before_; + halign_ = other.halign_; + jalign_ = other.jalign_; + return *this; +} + +expression_ptr text_symbolizer::get_name() const +{ + return name_; +} + +void text_symbolizer::set_name(expression_ptr name) +{ + name_ = name; +} + +std::string const& text_symbolizer::get_face_name() const +{ + return face_name_; +} + +void text_symbolizer::set_face_name(std::string face_name) +{ + face_name_ = face_name; +} + +void text_symbolizer::set_fontset(font_set const& fontset) +{ + fontset_ = fontset; +} + +font_set const& text_symbolizer::get_fontset() const +{ + return fontset_; +} + +unsigned text_symbolizer::get_text_ratio() const +{ + return text_ratio_; +} + +void text_symbolizer::set_text_ratio(unsigned ratio) +{ + text_ratio_ = ratio; +} + +unsigned text_symbolizer::get_wrap_width() const +{ + return wrap_width_; +} + +void text_symbolizer::set_wrap_width(unsigned width) +{ + wrap_width_ = width; +} + +bool text_symbolizer::get_wrap_before() const +{ + return wrap_before_; +} + +void text_symbolizer::set_wrap_before(bool wrap_before) +{ + wrap_before_ = wrap_before; +} + +unsigned char text_symbolizer::get_wrap_char() const +{ + return wrap_char_; +} + +std::string text_symbolizer::get_wrap_char_string() const +{ + return std::string(1, wrap_char_); +} + +void text_symbolizer::set_wrap_char(unsigned char character) +{ + wrap_char_ = character; +} + +void text_symbolizer::set_wrap_char_from_string(std::string const& character) +{ + wrap_char_ = (character)[0]; +} + +text_convert_e text_symbolizer::get_text_convert() const +{ + return text_convert_; +} + +void text_symbolizer::set_text_convert(text_convert_e convert) +{ + text_convert_ = convert; +} + +unsigned text_symbolizer::get_line_spacing() const +{ + return line_spacing_; +} + +void text_symbolizer::set_line_spacing(unsigned spacing) +{ + line_spacing_ = spacing; +} + +unsigned text_symbolizer::get_character_spacing() const +{ + return character_spacing_; +} + +void text_symbolizer::set_character_spacing(unsigned spacing) +{ + character_spacing_ = spacing; +} + +unsigned text_symbolizer::get_label_spacing() const +{ + return label_spacing_; +} + +void text_symbolizer::set_label_spacing(unsigned spacing) +{ + label_spacing_ = spacing; +} + +unsigned text_symbolizer::get_label_position_tolerance() const +{ + return label_position_tolerance_; +} + +void text_symbolizer::set_label_position_tolerance(unsigned tolerance) +{ + label_position_tolerance_ = tolerance; +} + +bool text_symbolizer::get_force_odd_labels() const +{ + return force_odd_labels_; +} + +void text_symbolizer::set_force_odd_labels(bool force) +{ + force_odd_labels_ = force; +} + +double text_symbolizer::get_max_char_angle_delta() const +{ + return max_char_angle_delta_; +} + +void text_symbolizer::set_max_char_angle_delta(double angle) +{ + max_char_angle_delta_ = angle; +} + +void text_symbolizer::set_text_size(unsigned size) +{ + size_ = size; +} + +unsigned text_symbolizer::get_text_size() const +{ + return size_; +} + +void text_symbolizer::set_fill(color const& fill) +{ + fill_ = fill; +} + +color const& text_symbolizer::get_fill() const +{ + return fill_; +} + +void text_symbolizer::set_halo_fill(color const& fill) +{ + halo_fill_ = fill; +} + +color const& text_symbolizer::get_halo_fill() const +{ + return halo_fill_; +} + +void text_symbolizer::set_halo_radius(unsigned radius) +{ + halo_radius_ = radius; +} + +unsigned text_symbolizer::get_halo_radius() const +{ + return halo_radius_; +} + +void text_symbolizer::set_label_placement(label_placement_e label_p) +{ + label_p_ = label_p; +} + +label_placement_e text_symbolizer::get_label_placement() const +{ + return label_p_; +} + +void text_symbolizer::set_vertical_alignment(vertical_alignment_e valign) +{ + valign_ = valign; +} + +vertical_alignment_e text_symbolizer::get_vertical_alignment() const +{ + return valign_; +} + +void text_symbolizer::set_anchor(double x, double y) +{ + anchor_ = boost::make_tuple(x,y); +} + +position const& text_symbolizer::get_anchor() const +{ + return anchor_; +} + +void text_symbolizer::set_displacement(double x, double y) +{ + displacement_ = boost::make_tuple(x,y); +} + +position const& text_symbolizer::get_displacement() const +{ + return displacement_; +} + +bool text_symbolizer::get_avoid_edges() const +{ + return avoid_edges_; +} + +void text_symbolizer::set_avoid_edges(bool avoid) +{ + avoid_edges_ = avoid; +} + +double text_symbolizer::get_minimum_distance() const +{ + return minimum_distance_; +} + +void text_symbolizer::set_minimum_distance(double distance) +{ + minimum_distance_ = distance; +} + +void text_symbolizer::set_allow_overlap(bool overlap) +{ + overlap_ = overlap; +} + +bool text_symbolizer::get_allow_overlap() const +{ + return overlap_; +} + +void text_symbolizer::set_opacity(double opacity) +{ + opacity_ = opacity; +} + +double text_symbolizer::get_opacity() const +{ + return opacity_; +} + +void text_symbolizer::set_horizontal_alignment(horizontal_alignment_e halign) +{ + halign_ = halign; +} + +horizontal_alignment_e text_symbolizer::get_horizontal_alignment() const +{ + return halign_; +} + +void text_symbolizer::set_justify_alignment(justify_alignment_e jalign) +{ + jalign_ = jalign; +} + +justify_alignment_e text_symbolizer::get_justify_alignment() const +{ + return jalign_; +} } diff --git a/src/tiff_reader.cpp b/src/tiff_reader.cpp index ce646d907..6afe37293 100644 --- a/src/tiff_reader.cpp +++ b/src/tiff_reader.cpp @@ -23,7 +23,8 @@ //$Id: tiff_reader.cpp 17 2005-03-08 23:58:43Z pavlenko $ // mapnik #include -#include "boost/filesystem/operations.hpp" +#include + extern "C" { #include @@ -37,7 +38,7 @@ namespace mapnik using std::min; using std::max; - class TiffReader : public ImageReader + class tiff_reader : public image_reader { private: std::string file_name_; @@ -53,32 +54,32 @@ namespace mapnik stripped, tiled }; - explicit TiffReader(const std::string& file_name); - virtual ~TiffReader(); + explicit tiff_reader(const std::string& file_name); + virtual ~tiff_reader(); unsigned width() const; unsigned height() const; - void read(unsigned x,unsigned y,ImageData32& image); + void read(unsigned x,unsigned y,image_data_32& image); private: - TiffReader(const TiffReader&); - TiffReader& operator=(const TiffReader&); + tiff_reader(const tiff_reader&); + tiff_reader& operator=(const tiff_reader&); void init(); - void read_generic(unsigned x,unsigned y,ImageData32& image); - void read_stripped(unsigned x,unsigned y,ImageData32& image); - void read_tiled(unsigned x,unsigned y,ImageData32& image); + void read_generic(unsigned x,unsigned y,image_data_32& image); + void read_stripped(unsigned x,unsigned y,image_data_32& image); + void read_tiled(unsigned x,unsigned y,image_data_32& image); TIFF* load_if_exists(const std::string& filename); }; namespace { - ImageReader* createTiffReader(const std::string& file) + image_reader* create_tiff_reader(const std::string& file) { - return new TiffReader(file); + return new tiff_reader(file); } - - const bool registered = register_image_reader("tiff",createTiffReader); + + const bool registered = register_image_reader("tiff",create_tiff_reader); } - TiffReader::TiffReader(const std::string& file_name) + tiff_reader::tiff_reader(const std::string& file_name) : file_name_(file_name), read_method_(generic), width_(0), @@ -91,7 +92,7 @@ namespace mapnik } - void TiffReader::init() + void tiff_reader::init() { // TODO: error handling TIFFSetWarningHandler(0); @@ -119,30 +120,30 @@ namespace mapnik else { TIFFClose(tif); - throw ImageReaderException(msg); + throw image_reader_exception(msg); } } - TiffReader::~TiffReader() + tiff_reader::~tiff_reader() { // } - unsigned TiffReader::width() const + unsigned tiff_reader::width() const { return width_; } - unsigned TiffReader::height() const + unsigned tiff_reader::height() const { return height_; } - void TiffReader::read(unsigned x,unsigned y,ImageData32& image) + void tiff_reader::read(unsigned x,unsigned y,image_data_32& image) { if (read_method_==stripped) { @@ -159,18 +160,18 @@ namespace mapnik } - void TiffReader::read_generic(unsigned x,unsigned y,ImageData32& image) + void tiff_reader::read_generic(unsigned x,unsigned y,image_data_32& image) { TIFF* tif = load_if_exists(file_name_); if (tif) { - std::clog<<"TODO:tiff is not stripped or tiled\n"; + std::clog << "TODO:tiff is not stripped or tiled\n"; TIFFClose(tif); } } - void TiffReader::read_tiled(unsigned x0,unsigned y0,ImageData32& image) + void tiff_reader::read_tiled(unsigned x0,unsigned y0,image_data_32& image) { TIFF* tif = load_if_exists(file_name_); if (tif) @@ -215,7 +216,7 @@ namespace mapnik } - void TiffReader::read_stripped(unsigned x0,unsigned y0,ImageData32& image) + void tiff_reader::read_stripped(unsigned x0,unsigned y0,image_data_32& image) { TIFF* tif = load_if_exists(file_name_); if (tif) @@ -255,7 +256,7 @@ namespace mapnik } } - TIFF* TiffReader::load_if_exists(std::string const& filename) + TIFF* tiff_reader::load_if_exists(std::string const& filename) { TIFF * tif = 0; boost::filesystem::path path(file_name_); diff --git a/src/unicode.cpp b/src/unicode.cpp index 874943d33..4b308be7b 100644 --- a/src/unicode.cpp +++ b/src/unicode.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * Copyright (C) 2006,2009 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -25,10 +25,6 @@ #include #include -#ifdef USE_FRIBIDI -#include -#endif - #include #ifdef MAPNIK_DEBUG @@ -36,188 +32,32 @@ #endif namespace mapnik { + +transcoder::transcoder (std::string const& encoding) + : ok_(false), + conv_(0) +{ + UErrorCode err = U_ZERO_ERROR; + conv_ = ucnv_open(encoding.c_str(),&err); + if (U_SUCCESS(err)) ok_ = true; + // TODO ?? +} + +UnicodeString transcoder::transcode(const char* data) const +{ -/* -** Use FRIBIDI to encode the string. -** The return value must be freed by the caller. -*/ - -#ifdef USE_FRIBIDI - inline wchar_t* bidi_string(const wchar_t *logical) + UErrorCode err = U_ZERO_ERROR; + + UnicodeString ustr(data,-1,conv_,err); + if (ustr.isBogus()) { - FriBidiCharType base = FRIBIDI_TYPE_ON; - size_t len; - - len = wcslen(logical); - - FriBidiChar *visual; - - FriBidiStrIndex *ltov, *vtol; - FriBidiLevel *levels; - FriBidiStrIndex new_len; - fribidi_boolean log2vis; - - visual = (FriBidiChar *) calloc (sizeof (FriBidiChar), len + 1); - ltov = 0; - vtol = 0; - levels = 0; - - /* Create a bidi string. */ - log2vis = fribidi_log2vis ((FriBidiChar *)logical, len, &base, - /* output */ - visual, ltov, vtol, levels); - - if (!log2vis) { - return 0; - } - - new_len = len; - - return (wchar_t *)visual; + ustr.remove(); } -#endif - -/* - inline std::wstring to_unicode(std::string const& text) - { - std::wstring out; - unsigned long code = 0; - int expect = 0; - std::string::const_iterator itr=text.begin(); - std::string::const_iterator end=text.end(); - while ( itr != end) - { - unsigned p = (*itr++) & 0xff; - if ( p >= 0xc0) - { - if ( p < 0xe0) // U+0080 - U+07ff - { - expect = 1; - code = p & 0x1f; - } - else if ( p < 0xf0) // U+0800 - U+ffff - { - expect = 2; - code = p & 0x0f; - } - else if ( p < 0xf8) // U+1000 - U+10ffff - { - expect = 3; - code = p & 0x07; - } - continue; - } - else if (p >= 0x80) - { - --expect; - if (expect >= 0) - { - code <<= 6; - code += p & 0x3f; - } - if (expect > 0) - continue; - expect = 0; - } - else - { - code = p; // U+0000 - U+007f (ascii) - } - out.push_back(wchar_t(code)); - } -#ifdef USE_FRIBIDI - wchar_t *bidi_text = bidi_string(out.c_str()); - out = bidi_text; - free(bidi_text); -#endif - - return out; - } - - inline std::wstring latin1_to_unicode(std::string const& text) - { - std::wstring out; - std::string::const_iterator itr=text.begin(); - std::string::const_iterator end=text.end(); - while ( itr != end) - { - unsigned p = (*itr++) & 0xff; - out.push_back(wchar_t(p)); - } - return out; + return ustr; } - inline std::string latin1_to_unicode2(std::string const& text) - { - std::string out; - std::string::const_iterator itr=text.begin(); - std::string::const_iterator end=text.end(); - while ( itr != end) - { - out.push_back(0x00); - out.push_back(*itr++); - } - return out; - } - -*/ - transcoder::transcoder (std::string const& encoding) - : ok_(false), - conv_(0) - { - -//#ifndef WORDS_BIGENDIAN - // desc_ = iconv_open("UCS-4LE",encoding.c_str()); -//#else - // desc_ = iconv_open("UCS-4BE",encoding.c_str()); -//#endif - - UErrorCode err = U_ZERO_ERROR; - conv_ = ucnv_open(encoding.c_str(),&err); - if (U_SUCCESS(err)) ok_ = true; - // TODO - } - - UnicodeString transcoder::transcode(const char* data) const - { - - UErrorCode err = U_ZERO_ERROR; - - UnicodeString ustr(data,-1,conv_,err); - if (ustr.isBogus()) - { - ustr.remove(); - } - return ustr; -/* - if (desc_ == iconv_t(-1)) return to_unicode(input); - size_t inleft = input.size(); - std::wstring output(inleft,0); - size_t outleft = inleft * sizeof(wchar_t); -#if (!defined(OSX_LEOPARD) && defined(DARWIN)) || defined(SUNOS) || defined(FREEBSD) - const char * in = input.c_str(); -#else - char * in = const_cast(input.data()); -#endif - char * out = const_cast(reinterpret_cast(output.data())); - iconv(desc_,&in,&inleft,&out,&outleft); - output = output.substr(0,output.size()-(outleft/sizeof(wchar_t))); -#ifdef USE_FRIBIDI - if (output.length() > 0) - { - wchar_t *bidi_text = bidi_string(output.c_str()); - output = bidi_text; - free(bidi_text); - } -#endif - return output; -*/ - } - transcoder::~transcoder() { - // if (desc_ != iconv_t(-1)) iconv_close(desc_); - if (conv_) - ucnv_close(conv_); + if (conv_) ucnv_close(conv_); } } diff --git a/tests/data/broken_maps/mapnik_min_version.xml b/tests/data/broken_maps/mapnik_min_version.xml deleted file mode 100644 index d0162b71b..000000000 --- a/tests/data/broken_maps/mapnik_min_version.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/tests/data/good_maps/entities.xml b/tests/data/good_maps/entities.xml deleted file mode 100644 index 11aa3d932..000000000 --- a/tests/data/good_maps/entities.xml +++ /dev/null @@ -1,22 +0,0 @@ - - -%entities; -]> - - &fontset-settings; - - - turning_circle - - \ No newline at end of file diff --git a/tests/data/good_maps/mapnik_min_version.xml b/tests/data/good_maps/mapnik_min_version.xml deleted file mode 100644 index 3a657e523..000000000 --- a/tests/data/good_maps/mapnik_min_version.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/tests/data/inc/entities.xml.inc b/tests/data/inc/entities.xml.inc deleted file mode 100644 index a9b2dd399..000000000 --- a/tests/data/inc/entities.xml.inc +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - -%scales; \ No newline at end of file diff --git a/tests/data/inc/expected.xml b/tests/data/inc/expected.xml deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/data/inc/fontset-settings.xml.inc b/tests/data/inc/fontset-settings.xml.inc deleted file mode 100644 index 51094cc2d..000000000 --- a/tests/data/inc/fontset-settings.xml.inc +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/tests/data/inc/scales.xml.inc b/tests/data/inc/scales.xml.inc deleted file mode 100644 index f5f5a2556..000000000 --- a/tests/data/inc/scales.xml.inc +++ /dev/null @@ -1,37 +0,0 @@ -250000000000"> -500000000"> -200000000"> -200000000"> -100000000"> -100000000"> -50000000"> -50000000"> -25000000"> -25000000"> -12500000"> -12500000"> -6500000"> -6500000"> -3000000"> -3000000"> -1500000"> -1500000"> -750000"> -750000"> -400000"> -400000"> -200000"> -200000"> -100000"> -100000"> -50000"> -50000"> -25000"> -25000"> -12500"> -12500"> -5000"> -5000"> -2500"> -2500"> -1000"> \ No newline at end of file diff --git a/tests/python_tests/object_test.py b/tests/python_tests/object_test.py index 8fa9f5122..672686800 100644 --- a/tests/python_tests/object_test.py +++ b/tests/python_tests/object_test.py @@ -441,9 +441,9 @@ def test_coord_multiplication(): eq_(c.x, 200) eq_(c.y, 200) -# Envelope initialization +# Box2d initialization def test_envelope_init(): - e = mapnik.Envelope(100, 100, 200, 200) + e = mapnik.Box2d(100, 100, 200, 200) assert_true(e.contains(100, 100)) assert_true(e.contains(100, 200)) @@ -471,15 +471,15 @@ def test_envelope_init(): eq_(c.x, 150) eq_(c.y, 150) -# Envelope pickling +# Box2d pickling def test_envelope_pickle(): - e = mapnik.Envelope(100, 100, 200, 200) + e = mapnik.Box2d(100, 100, 200, 200) eq_(pickle.loads(pickle.dumps(e)), e) -# Envelope multiplication +# Box2d multiplication def test_envelope_multiplication(): - e = mapnik.Envelope(100, 100, 200, 200) + e = mapnik.Box2d(100, 100, 200, 200) e *= 2 assert_true(e.contains(50, 50)) diff --git a/tests/python_tests/projection_test.py b/tests/python_tests/projection_test.py index 5b9c648ac..ffdb52eb3 100644 --- a/tests/python_tests/projection_test.py +++ b/tests/python_tests/projection_test.py @@ -11,7 +11,7 @@ def test_wgs84_inverse_forward(): p = mapnik.Projection('+init=epsg:4326') c = mapnik.Coord(3.01331418311, 43.3333092669) - e = mapnik.Envelope(-122.54345245, 45.12312553, 68.2335581353, 48.231231233) + e = mapnik.Box2d(-122.54345245, 45.12312553, 68.2335581353, 48.231231233) # It appears that the y component changes very slightly, is this OK? # so we test for 'almost equal float values' @@ -38,4 +38,4 @@ def test_wgs84_inverse_forward(): assert_almost_equal(e.inverse(p).center().x, e.center().x) assert_almost_equal(e.forward(p).center().y, e.center().y) - assert_almost_equal(e.forward(p).center().x, e.center().x) \ No newline at end of file + assert_almost_equal(e.forward(p).center().x, e.center().x) diff --git a/tests/python_tests/render_test.py b/tests/python_tests/render_test.py index daa63ed0b..b43f85875 100644 --- a/tests/python_tests/render_test.py +++ b/tests/python_tests/render_test.py @@ -100,7 +100,7 @@ def test_render_points(): m.append_style('places_labels',s) m.layers.append(lyr) p = mapnik.Projection(projs[projdescr]) - m.zoom_to_box(p.forward(mapnik.Envelope(ul_lonlat,lr_lonlat))) + m.zoom_to_box(p.forward(mapnik.Box2d(ul_lonlat,lr_lonlat))) # Render to SVG so that it can be checked how many points are there with string comparison import StringIO svg_memory_file = StringIO.StringIO() diff --git a/utils/ogrindex/ogrindex.cpp b/utils/ogrindex/ogrindex.cpp index 3da5f0d7c..901cef617 100644 --- a/utils/ogrindex/ogrindex.cpp +++ b/utils/ogrindex/ogrindex.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include @@ -146,7 +146,7 @@ int main (int argc,char** argv) ogr_datasource ogr (params); - Envelope extent = ogr.envelope(); + box2d extent = ogr.envelope(); quadtree tree (extent, depth, ratio); int count=0; @@ -165,7 +165,7 @@ int main (int argc,char** argv) break; } - Envelope item_ext = fp->envelope(); + box2d item_ext = fp->envelope(); tree.insert (count, item_ext); if (verbose) { diff --git a/utils/pgsql2sqlite/pgsql2sqlite.hpp b/utils/pgsql2sqlite/pgsql2sqlite.hpp index 6e9ac18cf..89fd2d8ee 100644 --- a/utils/pgsql2sqlite/pgsql2sqlite.hpp +++ b/utils/pgsql2sqlite/pgsql2sqlite.hpp @@ -103,7 +103,7 @@ namespace mapnik { } }; - bool valid_envelope(mapnik::Envelope const& e) + bool valid_envelope(mapnik::box2d const& e) { return (e.minx() <= e.maxx() && e.miny() <= e.maxy()) ; } @@ -360,7 +360,7 @@ namespace mapnik { if (feat.num_geometries() > 0) { geometry2d const& geom=feat.get_geometry(0); - Envelope bbox = geom.envelope(); + box2d bbox = geom.envelope(); if (valid_envelope(bbox)) { sqlite::record_type rec; diff --git a/utils/shapeindex/SConscript b/utils/shapeindex/SConscript index e34f38e06..f97afab9e 100644 --- a/utils/shapeindex/SConscript +++ b/utils/shapeindex/SConscript @@ -29,7 +29,7 @@ install_prefix = env['DESTDIR'] + '/' + prefix source = Split( """ shapeindex.cpp - #src/envelope.cpp + #src/box2d.cpp #plugins/input/shape/shapefile.cpp """ ) diff --git a/utils/shapeindex/quadtree.hpp b/utils/shapeindex/quadtree.hpp index ba67628cd..87ee9253f 100644 --- a/utils/shapeindex/quadtree.hpp +++ b/utils/shapeindex/quadtree.hpp @@ -29,18 +29,18 @@ #include #include // mapnik -#include +#include -using mapnik::Envelope; +using mapnik::box2d; using mapnik::coord2d; template struct quadtree_node { - Envelope ext_; + box2d ext_; std::vector data_; quadtree_node* children_[4]; - quadtree_node(const Envelope& ext) + quadtree_node(const box2d& ext) : ext_(ext),data_() { memset(children_,0,sizeof(quadtree_node*)*4); @@ -79,7 +79,7 @@ private: const int maxdepth_; const double ratio_; public: - quadtree(const Envelope& extent,int maxdepth,double ratio) + quadtree(const box2d& extent,int maxdepth,double ratio) : root_(new quadtree_node(extent)), maxdepth_(maxdepth), ratio_(ratio) {} @@ -89,7 +89,7 @@ public: if (root_) delete root_; } - void insert(const T& data,const Envelope& item_ext) + void insert(const T& data,const box2d& item_ext) { insert(data,item_ext,root_,maxdepth_); } @@ -191,7 +191,7 @@ private: { if (node->children_[i]) { - offset +=sizeof(Envelope)+(node->children_[i]->data_.size()*sizeof(T))+3*sizeof(int); + offset +=sizeof(box2d)+(node->children_[i]->data_.size()*sizeof(T))+3*sizeof(int); offset +=subnode_offset(node->children_[i]); } } @@ -204,11 +204,11 @@ private: { int offset=subnode_offset(node); int shape_count=node->data_.size(); - int recsize=sizeof(Envelope) + 3 * sizeof(int) + shape_count * sizeof(T); + int recsize=sizeof(box2d) + 3 * sizeof(int) + shape_count * sizeof(T); char* node_record=new char[recsize]; memset(node_record,0,recsize); memcpy(node_record,&offset,4); - memcpy(node_record+4,&node->ext_,sizeof(Envelope)); + memcpy(node_record+4,&node->ext_,sizeof(box2d)); memcpy(node_record+36,&shape_count,4); for (int i=0;i& item_ext,quadtree_node* node,int maxdepth) + void insert(const T& data,const box2d& item_ext,quadtree_node* node,int maxdepth) { if (node && node->ext_.contains(item_ext)) { @@ -272,11 +272,11 @@ private: double hix=node->ext_.maxx(); double hiy=node->ext_.maxy(); - Envelope ext[4]; - ext[0]=Envelope(lox,loy,lox + width * ratio_,loy + height * ratio_); - ext[1]=Envelope(hix - width * ratio_,loy,hix,loy + height * ratio_); - ext[2]=Envelope(lox,hiy - height*ratio_,lox + width * ratio_,hiy); - ext[3]=Envelope(hix - width * ratio_,hiy - height*ratio_,hix,hiy); + box2d ext[4]; + ext[0]=box2d(lox,loy,lox + width * ratio_,loy + height * ratio_); + ext[1]=box2d(hix - width * ratio_,loy,hix,loy + height * ratio_); + ext[2]=box2d(lox,hiy - height*ratio_,lox + width * ratio_,hiy); + ext[3]=box2d(hix - width * ratio_,hiy - height*ratio_,hix,hiy); if (maxdepth > 1) { diff --git a/utils/shapeindex/shapeindex.cpp b/utils/shapeindex/shapeindex.cpp index e0e6bffa2..53a28ec1f 100644 --- a/utils/shapeindex/shapeindex.cpp +++ b/utils/shapeindex/shapeindex.cpp @@ -139,7 +139,7 @@ int main (int argc,char** argv) int file_length=shp.read_xdr_integer(); int version=shp.read_ndr_integer(); int shape_type=shp.read_ndr_integer(); - Envelope extent; + box2d extent; shp.read_envelope(extent); @@ -164,12 +164,12 @@ int main (int argc,char** argv) shp.skip(4); //std::clog << "offset= "<< offset << std::endl; - Envelope item_ext; + box2d item_ext; if (shape_type==shape_io::shape_point) { double x=shp.read_double(); double y=shp.read_double(); - item_ext=Envelope(x,y,x,y); + item_ext=box2d(x,y,x,y); } else if (shape_type==shape_io::shape_pointm) @@ -177,7 +177,7 @@ int main (int argc,char** argv) double x=shp.read_double(); double y=shp.read_double(); shp.read_double(); - item_ext=Envelope(x,y,x,y); + item_ext=box2d(x,y,x,y); } else if (shape_type==shape_io::shape_pointz) @@ -186,7 +186,7 @@ int main (int argc,char** argv) double y=shp.read_double(); shp.read_double(); shp.read_double(); - item_ext=Envelope(x,y,x,y); + item_ext=box2d(x,y,x,y); } else