1. move include to mapnik/include

2. update demos,bibdibgs etc.
This commit is contained in:
Artem Pavlenko 2006-10-04 11:22:18 +00:00
parent 6a6c794c22
commit 992af4747d
160 changed files with 4384 additions and 4312 deletions

View file

@ -22,37 +22,34 @@
import os, sys, platform
if platform.uname()[4] == 'x86_64':
LIB_PLATFORM = 'lib64'
else :
LIB_PLATFORM = 'lib'
LIBDIR_SCHEMA='lib64'
else:
LIBDIR_SCHEMA='lib'
opts = Options()
opts.Add('PREFIX', 'The install path "prefix"', '/usr/local')
opts.Add(PathOption('BOOST_INCLUDES', 'Search path for boost include files', '/usr/include'))
opts.Add(PathOption('BOOST_LIBS', 'Search path for boost library files', '/usr/' + LIB_PLATFORM))
opts.Add(PathOption('BOOST_LIBS', 'Search path for boost library files', '/usr/' + LIBDIR_SCHEMA))
opts.Add(PathOption('FREETYPE_CONFIG', 'The path to the freetype-config executable.', '/usr/bin/freetype-config'))
opts.Add(PathOption('PNG_INCLUDES', 'Search path for libpng include files', '/usr/include'))
opts.Add(PathOption('PNG_LIBS', 'Search path for libpng include files', '/usr/' + LIB_PLATFORM))
opts.Add(PathOption('PNG_LIBS','Search path for libpng include files','/usr/' + LIBDIR_SCHEMA))
opts.Add(PathOption('JPEG_INCLUDES', 'Search path for libjpeg include files', '/usr/include'))
opts.Add(PathOption('JPEG_LIBS', 'Search path for libjpeg library files', '/usr/' + LIB_PLATFORM))
opts.Add(PathOption('JPEG_LIBS', 'Search path for libjpeg library files', '/usr/' + LIBDIR_SCHEMA))
opts.Add(PathOption('TIFF_INCLUDES', 'Search path for libtiff include files', '/usr/include'))
opts.Add(PathOption('TIFF_LIBS', 'Search path for libtiff library files', '/usr/' + LIB_PLATFORM))
opts.Add(PathOption('TIFF_LIBS', 'Search path for libtiff library files', '/usr/' + LIBDIR_SCHEMA))
opts.Add(PathOption('PGSQL_INCLUDES', 'Search path for PostgreSQL include files', '/usr/include'))
opts.Add(PathOption('PGSQL_LIBS', 'Search path for PostgreSQL library files', '/usr/' + LIB_PLATFORM))
opts.Add(PathOption('PGSQL_LIBS', 'Search path for PostgreSQL library files', '/usr/' + LIBDIR_SCHEMA))
opts.Add(PathOption('PROJ_INCLUDES', 'Search path for PROJ.4 include files', '/usr/local/include'))
opts.Add(PathOption('PROJ_LIBS', 'Search path for PROJ.4 include files', '/usr/local/' + LIB_PLATFORM))
opts.Add(PathOption('PROJ_LIBS', 'Search path for PROJ.4 include files', '/usr/local/' + LIBDIR_SCHEMA))
opts.Add(PathOption('PYTHON','Python executable', sys.executable))
opts.Add(ListOption('INPUT_PLUGINS','Input drivers to include','all',['postgis','shape','raster']))
opts.Add(ListOption('BINDINGS','Language bindings to build','all',['python']))
opts.Add('DEBUG', 'Compile a debug version of mapnik', '')
env = Environment(ENV=os.environ, options=opts)
env['LIB_PLATFORM'] = LIB_PLATFORM
env['LIBDIR_SCHEMA'] = LIBDIR_SCHEMA
Help(opts.GenerateHelpText(env))

View file

@ -23,7 +23,7 @@ import glob
Import('env')
prefix = env['PYTHON_PREFIX'] + '/'+env['LIB_PLATFORM']+ '/python' + env['PYTHON_VERSION'] + '/site-packages/'
prefix = env['PYTHON_PREFIX'] + '/'+ 'lib' + '/python' + env['PYTHON_VERSION'] + '/site-packages/'
libraries = ['mapnik', 'boost_python%s' % env['BOOST_APPEND']]
headers = [env['PYTHON_PREFIX'] + '/include/python' + env['PYTHON_VERSION']] + env['CPPPATH']
@ -36,7 +36,7 @@ inputpluginspath = mapniklibpath + '/input'
fontscollectionpath = mapniklibpath + '/fonts'
"""
file('mapnik/paths.py','w').write(paths % (env['PREFIX'] + '/'+env['LIB_PLATFORM']+'/mapnik',))
file('mapnik/paths.py','w').write(paths % (env['PREFIX'] + '/'+env['LIBDIR_SCHEMA']+'/mapnik',))
pymapnik = glob.glob('mapnik/*.py')
env.Alias(target='install', source=env.Install(prefix+'/mapnik', pymapnik))

View file

@ -59,8 +59,8 @@ class _Envelope(Envelope,_injector):
return 'Envelope(%s,%s,%s,%s)' % \
(self.minx,self.miny,self.maxx,self.maxy)
def Layer (**keywords):
return CreateLayer(keywords)
def Datasource (**keywords):
return CreateDatasource(keywords)
#register datasources

View file

@ -23,8 +23,8 @@
#include <boost/python.hpp>
#include <color.hpp>
#include <color_factory.hpp>
#include <mapnik/color.hpp>
#include <mapnik/color_factory.hpp>
using mapnik::Color;
using mapnik::color_factory;

View file

@ -23,7 +23,7 @@
//$Id$
#include <boost/python.hpp>
#include "datasource_cache.hpp"
#include <mapnik/datasource_cache.hpp>
void export_datasource_cache()
{

View file

@ -22,7 +22,7 @@
//$Id: mapnik_envelope.cc 27 2005-03-30 21:45:40Z pavlenko $
#include <boost/python.hpp>
#include <envelope.hpp>
#include <mapnik/envelope.hpp>
using mapnik::coord;
using mapnik::Envelope;

View file

@ -22,12 +22,13 @@
//$Id$
#include <boost/python.hpp>
#include <spatial.hpp>
#include <logical.hpp>
#include <comparison.hpp>
#include <regex_filter.hpp>
#include <filter.hpp>
#include <filter_factory.hpp>
#include <mapnik/spatial.hpp>
#include <mapnik/logical.hpp>
#include <mapnik/comparison.hpp>
#include <mapnik/regex_filter.hpp>
#include <mapnik/filter.hpp>
#include <mapnik/filter_factory.hpp>
using mapnik::filter;
using mapnik::filter_ptr;

View file

@ -22,7 +22,7 @@
//$Id$
#include <boost/python.hpp>
#include <font_engine_freetype.hpp>
#include <mapnik/font_engine_freetype.hpp>
void export_font_engine()
{

View file

@ -24,14 +24,11 @@
#include <boost/python.hpp>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <graphics.hpp>
#include <mapnik/graphics.hpp>
using mapnik::Image32;
using namespace boost::python;
PyObject* rawdata( Image32 const& im)
{
int size = im.width() * im.height() * 4;

View file

@ -25,7 +25,7 @@
#include <boost/python.hpp>
#include <boost/python/detail/api_placeholder.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <layer.hpp>
#include <mapnik/layer.hpp>
using mapnik::Layer;
using mapnik::parameters;

View file

@ -22,7 +22,7 @@
//$Id$
#include <boost/python.hpp>
#include <line_pattern_symbolizer.hpp>
#include <mapnik/line_pattern_symbolizer.hpp>
using mapnik::line_pattern_symbolizer;

View file

@ -22,7 +22,7 @@
//$Id$
#include <boost/python.hpp>
#include <line_symbolizer.hpp>
#include <mapnik/line_symbolizer.hpp>
using mapnik::line_symbolizer;
using mapnik::stroke;

View file

@ -26,8 +26,8 @@
#include <boost/python/detail/api_placeholder.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <layer.hpp>
#include <map.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/map.hpp>
using mapnik::Color;
using mapnik::coord;

View file

@ -23,7 +23,7 @@
#include <boost/python.hpp>
#include <boost/python/detail/api_placeholder.hpp>
#include <params.hpp>
#include <mapnik/params.hpp>
using mapnik::parameter;
using mapnik::parameters;

View file

@ -22,7 +22,7 @@
//$Id$
#include <boost/python.hpp>
#include <point_symbolizer.hpp>
#include <mapnik/point_symbolizer.hpp>
void export_point_symbolizer()
{

View file

@ -22,7 +22,7 @@
//$Id$
#include <boost/python.hpp>
#include <polygon_pattern_symbolizer.hpp>
#include <mapnik/polygon_pattern_symbolizer.hpp>
void export_polygon_pattern_symbolizer()
{

View file

@ -22,7 +22,7 @@
//$Id$
#include <boost/python.hpp>
#include <polygon_symbolizer.hpp>
#include <mapnik/polygon_symbolizer.hpp>
void export_polygon_symbolizer()
{

View file

@ -47,12 +47,12 @@ void export_raster_symbolizer();
void export_text_symbolizer();
void export_font_engine();
#include <map.hpp>
#include <agg_renderer.hpp>
#include <graphics.hpp>
#include <datasource_cache.hpp>
#include <load_map.hpp>
#include <save_map.hpp>
#include <mapnik/map.hpp>
#include <mapnik/agg_renderer.hpp>
#include <mapnik/graphics.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/load_map.hpp>
#include <mapnik/save_map.hpp>
void render_to_file(const mapnik::Map& map,
const std::string& file,

View file

@ -22,7 +22,7 @@
//$Id$
#include <boost/python.hpp>
#include <query.hpp>
#include <mapnik/query.hpp>
void export_query()
{

View file

@ -22,7 +22,7 @@
//$Id$
#include <boost/python.hpp>
#include <raster_symbolizer.hpp>
#include <mapnik/raster_symbolizer.hpp>
void export_raster_symbolizer()
{

View file

@ -21,12 +21,11 @@
*****************************************************************************/
//$Id$
#include <boost/python.hpp>
#include <boost/python/implicit.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <rule.hpp>
#include <mapnik/rule.hpp>
void export_rule()
{

View file

@ -22,7 +22,8 @@
//$Id$
#include <boost/python.hpp>
#include <stroke.hpp>
#include <mapnik/stroke.hpp>
void export_stroke ()
{

View file

@ -23,7 +23,8 @@
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <feature_type_style.hpp>
#include <mapnik/feature_type_style.hpp>
void export_style()
{

View file

@ -22,7 +22,8 @@
//$Id$
#include <boost/python.hpp>
#include <text_symbolizer.hpp>
#include <mapnik/text_symbolizer.hpp>
void export_text_symbolizer()
{

View file

@ -21,14 +21,13 @@
*****************************************************************************/
// $Id$
#include <map.hpp>
#include <datasource_cache.hpp>
#include <font_engine_freetype.hpp>
#include <agg_renderer.hpp>
#include <filter_factory.hpp>
#include <color_factory.hpp>
#include <image_util.hpp>
#include <mapnik/map.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/agg_renderer.hpp>
#include <mapnik/filter_factory.hpp>
#include <mapnik/color_factory.hpp>
#include <mapnik/image_util.hpp>
#include <iostream>
@ -231,7 +230,8 @@ int main ( int argc , char** argv)
m.addLayer(lyr);
}
m.zoomToBox(Envelope<double>(1405120.04127408,-247003.813399447,1706357.31328276,-25098.593149577));
m.zoomToBox(Envelope<double>(1405120.04127408,-247003.813399447,
1706357.31328276,-25098.593149577));
Image32 buf(m.getWidth(),m.getHeight());
agg_renderer<Image32> ren(m,buf);

View file

@ -24,4 +24,4 @@ Import('env')
prefix = env['PREFIX']
includes = glob.glob('*/*.ttf')
env.Alias(target='install', source=env.Install(prefix+'/' + env['LIB_PLATFORM'] + '/mapnik/fonts', includes))
env.Alias(target='install', source=env.Install(prefix+'/' + env['LIBDIR_SCHEMA'] + '/mapnik/fonts', includes))

View file

@ -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
#include <typeinfo>
#include <sstream>
#include <map>
#include <boost/any.hpp>
namespace mapnik
{
template <typename T>
struct attribute_traits
{
static std::string to_string(const T& value)
{
std::stringstream ss;
ss << value;
return ss.str();
}
};
template <>
struct attribute_traits<std::string>
{
static std::string to_string(const std::string& value)
{
return value;
}
};
class MAPNIK_DECL attribute
{
public:
attribute()
: base_(0) {}
template <typename T>
attribute(const T& value)
: base_(new attribute_impl<T>(value))
{}
attribute(const attribute& rhs)
: base_(rhs.base_ ? rhs.base_->clone() : 0)
{}
~attribute()
{
delete base_;
}
template<typename T>
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 <typename T,typename ATraits=attribute_traits<T> >
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<typename value_type>
friend value_type* attribute_cast(attribute*);
attribute_base* base_;
};
template<typename T>
struct bad_attribute_cast : public std::bad_cast
{
virtual const char* what() const throw()
{
return "attribute::failed conversion";
}
};
template <typename T>
bool is_type(const attribute& attr)
{
return attr.type()==typeid(T);
}
template <typename T>
T* attribute_cast(attribute* attr)
{
return attr && attr->type() == typeid(T)
? &static_cast<attribute::attribute_impl<T>*>(attr->base_)->value_
: 0;
}
template <typename T>
const T* attribute_cast(const attribute* attr)
{
return attribute_cast<T>(const_cast<attribute*>(attr));
}
template <typename T>
T attribute_cast(const attribute& attr)
{
using namespace boost;
typedef BOOST_DEDUCED_TYPENAME remove_reference<T>::type nonref;
const nonref * result=attribute_cast<nonref>(&attr);
if (!result)
{
throw bad_attribute_cast<T>();
}
return *result;
}
template <typename T>
T attribute_cast(attribute& attr)
{
using namespace boost;
typedef BOOST_DEDUCED_TYPENAME remove_reference<T>::type nonref;
nonref * result=attribute_cast<nonref>(&attr);
if (!result)
throw bad_attribute_cast<T>();
return *result;
}
template <typename T>
attribute attribute_from_string(const std::string& val)
{
std::istringstream is(val);
T t;
is >> t;
return attribute(t);
}
template <typename charT, typename traits>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
const attribute& attr)
{
out << attr.to_string();
return out;
}
}
#endif //ATTRIBUTE_HPP

View file

@ -1,98 +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 ATTRIBUTE_COLLECTOR_HPP
#define ATTRIBUTE_COLLECTOR_HPP
#include "filter.hpp"
#include "expression.hpp"
#include "feature_layer_desc.hpp"
#include "rule.hpp"
#include <set>
#include <iostream>
namespace mapnik
{
struct symbolizer_attributes : public boost::static_visitor<>
{
symbolizer_attributes(std::set<std::string>& names)
: names_(names) {}
template <typename T>
void operator () (T const&) const {}
void operator () (text_symbolizer const& sym)
{
names_.insert(sym.get_name());
}
private:
std::set<std::string>& names_;
};
template <typename FeatureT>
class attribute_collector : public filter_visitor<FeatureT>
{
private:
std::set<std::string>& names_;
public:
attribute_collector(std::set<std::string>& names)
: names_(names) {}
void visit(filter<FeatureT>& /*filter*/)
{
//not interested
}
void visit(expression<FeatureT>& exp)
{
property<FeatureT>* pf;
if ((pf = dynamic_cast<property<FeatureT>*>(&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);
}
virtual ~attribute_collector() {}
private:
// no copying
attribute_collector(attribute_collector const&);
attribute_collector& operator=(attribute_collector const&);
};
}
#endif //ATTRIBUTE_COLLECTOR_HPP

View file

@ -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
*
*****************************************************************************/
//$Id$
#ifndef COMPARISON_HPP
#define COMPARISON_HPP
#include "filter.hpp"
#include "expression.hpp"
#include "attribute.hpp"
#include <iostream>
namespace mapnik
{
template <typename T>
struct greater_than
{
bool operator() (T const& left, T const& right) const
{
return left > right;
}
static std::string to_string()
{
return ">";
}
};
template <typename T>
struct greater_than_or_equal
{
bool operator() (T const& left, T const& right) const
{
return left >= right;
}
static std::string to_string()
{
return ">=";
}
};
template <typename T>
struct less_than
{
bool operator() (T const& left, T const& right) const
{
return left < right;
}
static std::string to_string()
{
return "<";
}
};
template <typename T>
struct less_than_or_equal
{
bool operator() (T const& left, T const& right) const
{
return left <= right;
}
static std::string to_string()
{
return "<=";
}
};
template <typename T>
struct equals
{
bool operator() (T const& left, T const& right) const
{
return left == right;
}
static std::string to_string()
{
return "=";
}
};
template <typename T>
struct not_equals
{
bool operator() (T const& left, T const& right) const
{
return left != right;
}
static std::string to_string()
{
return "<>";
}
};
template <typename FeatureT,typename Op>
struct compare_filter : public filter<FeatureT>
{
compare_filter(expression<FeatureT> const& left,
expression<FeatureT> const& right)
: filter<FeatureT>(),
left_(left.clone()), right_(right.clone()) {}
compare_filter(compare_filter const& other)
: filter<FeatureT>(),
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<FeatureT>& 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<FeatureT>* clone() const
{
return new compare_filter<FeatureT,Op>(*this);
}
virtual ~compare_filter()
{
delete left_;
delete right_;
}
private:
expression<FeatureT>* left_;
expression<FeatureT>* right_;
};
}
#endif //COMPARISON_HPP

View file

@ -1,92 +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: coord_array.hpp 39 2005-04-10 20:39:53Z pavlenko $
#ifndef COORD_ARRAY_HPP
#define COORD_ARRAY_HPP
#include "coord.hpp"
#include <cassert>
namespace mapnik
{
template <typename T>
class coord_array
{
typedef T coord_type;
coord_type* pt_;
const unsigned size_;
public:
coord_array(unsigned size=0)
: pt_(static_cast<coord_type*>(size==0?0: ::operator new (sizeof(coord_type)*size))),
size_(size) {}
coord_array(const coord_array& rhs)
: pt_(static_cast<coord_type*>(rhs.size_==0?0: ::operator new (sizeof(coord_type)*rhs.size_))),
size_(rhs.size_) {
memcpy(pt_,rhs.pt_,sizeof(coord_type)*rhs.size_);
}
~coord_array()
{
::operator delete (pt_);
}
unsigned size() const
{
return size_;
}
void set(unsigned index,double x,double y)
{
assert(index<size_);
pt_[index].x=x;
pt_[index].y=y;
}
const coord_type& at(unsigned index) const
{
assert(index<size_);
return pt_[index];
}
const coord_type& operator[] (unsigned index) const
{
assert (index<size_);
return pt_[index];
}
coord_type& operator[] (unsigned index)
{
assert (index<size_);
return pt_[index];
}
private:
coord_array& operator=(const coord_array&);
};
}
#endif //COORD_ARRAY_HPP

View file

@ -1,388 +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
#include <boost/spirit/core.hpp>
#include <boost/spirit/symbols.hpp>
using namespace boost::spirit;
namespace mapnik
{
template <typename ColorT>
struct named_colors : public symbols<ColorT>
{
named_colors()
{
symbols<ColorT>::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))
;
}
};
template <typename ActionsT>
struct css_color_grammar : public grammar<css_color_grammar<ActionsT> >
{
css_color_grammar(ActionsT& actions_)
: actions(actions_) {}
template <typename ScannerT>
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") >> '(' >> uint3_p[self.actions.red_]
>> ',' >> uint3_p[self.actions.green_]
>> ',' >> uint3_p[self.actions.blue_]
>> ')';
rgb_percent = str_p("rgb") >> '(' >> ureal_p[self.actions.red_p_] >> '%'
>> ',' >> ureal_p[self.actions.green_p_] >> '%'
>> ',' >> ureal_p[self.actions.blue_p_] >> '%'
>> ')';
css_color = named_colors_p[self.actions.named_] | hex6 | hex3 | rgb_percent | rgb;
}
boost::spirit::rule<ScannerT> rgb;
boost::spirit::rule<ScannerT> rgb_percent;
boost::spirit::rule<ScannerT> hex6;
boost::spirit::rule<ScannerT> hex3;
boost::spirit::rule<ScannerT> css_color;
boost::spirit::rule<ScannerT> const& start() const
{
return css_color;
}
uint_parser<unsigned, 10, 1, 3> uint3_p;
uint_parser<unsigned, 16, 6, 6> uint6x_p;
uint_parser<unsigned, 16, 3, 3> uint3x_p;
named_colors<typename ActionsT::color_type> named_colors_p;
};
ActionsT& actions;
};
template <typename ColorT>
struct named_color_action
{
named_color_action(ColorT& c)
: c_(c) {}
void operator() (ColorT const&c) const
{
c_=c;
}
ColorT& c_;
};
template <typename ColorT>
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 <typename ColorT>
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 <typename ColorT>
struct red_action
{
red_action(ColorT& c)
: c_(c) {}
void operator () (unsigned int r) const
{
c_.set_red(r);
}
ColorT& c_;
};
template <typename ColorT>
struct green_action
{
green_action(ColorT& c)
: c_(c) {}
void operator () (unsigned int g) const
{
c_.set_green(g);
}
ColorT& c_;
};
template <typename ColorT>
struct blue_action
{
blue_action(ColorT& c)
: c_(c) {}
void operator () (unsigned int b) const
{
c_.set_blue(b);
}
ColorT& c_;
};
template <typename ColorT>
struct red_action_p
{
red_action_p(ColorT& c)
: c_(c) {}
void operator () (double r) const
{
c_.set_red(unsigned((255.0 * r)/100.0 + 0.5));
}
ColorT& c_;
};
template <typename ColorT>
struct green_action_p
{
green_action_p(ColorT& c)
: c_(c) {}
void operator () (double g) const
{
c_.set_green(unsigned((255.0 * g)/100.0 + 0.5));
}
ColorT& c_;
};
template <typename ColorT>
struct blue_action_p
{
blue_action_p(ColorT& c)
: c_(c) {}
void operator () (double b) const
{
c_.set_blue(unsigned((255.0 * b)/100.0 + 0.5));
}
ColorT& c_;
};
template <typename ColorT>
struct actions
{
typedef ColorT color_type;
actions(ColorT& c)
: named_(c),
hex6_(c),
hex3_(c),
red_(c),
green_(c),
blue_(c),
red_p_(c),
green_p_(c),
blue_p_(c) {}
named_color_action<ColorT> named_;
hex6_action<ColorT> hex6_;
hex3_action<ColorT> hex3_;
red_action<ColorT> red_;
green_action<ColorT> green_;
blue_action<ColorT> blue_;
red_action_p<ColorT> red_p_;
green_action_p<ColorT> green_p_;
blue_action_p<ColorT> blue_p_;
};
}
#endif //CSS_COLOR_PARSER_HPP

View file

@ -1,169 +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: ctrans.hpp 39 2005-04-10 20:39:53Z pavlenko $
#ifndef CTRANS_HPP
#define CTRANS_HPP
#include "envelope.hpp"
#include "coord_array.hpp"
namespace mapnik
{
typedef coord_array<coord2d> CoordinateArray;
template <typename Transform,typename Geometry>
struct MAPNIK_DECL coord_transform
{
coord_transform(Transform const& t,Geometry& geom)
: t_(t), geom_(geom) {}
unsigned vertex(double *x , double *y) const
{
unsigned command = geom_.vertex(x,y);
*x = t_.forward_x_(x);
*y = t_.forward_y_(y);
return command;
}
void rewind (unsigned pos)
{
geom_.rewind(pos);
}
private:
Transform const& t_;
Geometry& geom_;
};
class CoordTransform
{
private:
int width;
int height;
double scale_;
Envelope<double> extent;
public:
CoordTransform(int width,int height,const Envelope<double>& extent)
:width(width),height(height),extent(extent)
{
double sx=((double)width)/extent.width();
double sy=((double)height)/extent.height();
scale_=std::min(sx,sy);
}
inline double scale() const
{
return scale_;
}
inline void forward_x(double* x) const
{
*x = (*x - extent.minx() ) * scale_;
}
inline void forward_y(double* y) const
{
*y = (extent.maxy() - *y) * scale_;
}
inline double forward_x_(double* x) const
{
return (*x - extent.minx() ) * scale_;
}
inline double forward_y_(double* y) const
{
return (extent.maxy() - *y) * scale_;
}
inline void backward_x(double* x) const
{
*x = extent.minx() + *x/scale_;
}
inline void backward_y(double* y) const
{
*y = extent.maxy() - *y/scale_;
}
inline coord2d& forward(coord2d& c) const
{
forward_x(&c.x);
forward_y(&c.y);
return c;
}
inline coord2d& backward(coord2d& c) const
{
backward_x(&c.x);
backward_y(&c.y);
return c;
}
inline Envelope<double> forward(const Envelope<double>& e) const
{
double x0 = e.minx();
double y0 = e.miny();
double x1 = e.maxx();
double y1 = e.maxy();
forward_x(&x0);
forward_y(&y0);
forward_x(&x1);
forward_y(&y1);
return Envelope<double>(x0,y0,x1,y1);
}
inline Envelope<double> backward(const Envelope<double>& e) const
{
double x0 = e.minx();
double y0 = e.miny();
double x1 = e.maxx();
double y1 = e.maxy();
backward_x(&x0);
backward_y(&y0);
backward_x(&x1);
backward_y(&y1);
return Envelope<double>(x0,y0,x1,y1);
}
inline CoordinateArray& forward(CoordinateArray& coords) const
{
for (unsigned i=0;i<coords.size();++i)
{
forward(coords[i]);
}
return coords;
}
inline CoordinateArray& backward(CoordinateArray& coords) const
{
for (unsigned i=0;i<coords.size();++i)
{
backward(coords[i]);
}
return coords;
}
};
}
#endif //CTRANS_HPP

View file

@ -1,127 +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 "value.hpp"
#include "filter_visitor.hpp"
namespace mapnik
{
template <typename FeatureT> class filter_visitor;
template <typename FeatureT>
class expression
{
public:
virtual value get_value(FeatureT const& feature) const=0;
virtual void accept(filter_visitor<FeatureT>& v)=0;
virtual expression<FeatureT>* clone() const=0;
virtual std::string to_string() const=0;
virtual ~expression() {}
};
template <typename FeatureT>
class literal : public expression<FeatureT>
{
public:
literal(int val)
: expression<FeatureT>(),
value_(val) {}
literal(double val)
: expression<FeatureT>(),
value_(val) {}
literal(std::string const& val)
: expression<FeatureT>(),
value_(val) {}
literal(literal const& other)
: expression<FeatureT>(),
value_(other.value_) {}
value get_value(FeatureT const& /*feature*/) const
{
return value_;
}
void accept(filter_visitor<FeatureT>& v)
{
v.visit(*this);
}
expression<FeatureT>* clone() const
{
return new literal(*this);
}
std::string to_string() const
{
return value_.to_expression_string();
}
~literal() {}
private:
value value_;
};
template <typename FeatureT>
class property : public expression<FeatureT>
{
public:
property(std::string const& name)
: expression<FeatureT>(),
name_(name)
{}
property(property const& other)
: expression<FeatureT>(),
name_(other.name_)
{}
value get_value(FeatureT const& feature) const
{
return feature[name_];
}
void accept(filter_visitor<FeatureT>& v)
{
v.visit(*this);
}
expression<FeatureT>* 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

View file

@ -1,118 +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: feature.hpp 40 2005-04-13 20:20:46Z pavlenko $
#ifndef FEATURE_HPP
#define FEATURE_HPP
#include "geometry.hpp"
#include "raster.hpp"
#include "value.hpp"
#include <map>
#include <boost/property_map.hpp>
#include <boost/utility.hpp>
namespace mapnik
{
typedef boost::shared_ptr<raster> raster_ptr;
//typedef std::vector<value> properties;
typedef boost::associative_property_map<std::map<std::string,value> > properties;
template <typename T1,typename T2>
struct feature : public properties,
private boost::noncopyable
{
public:
typedef T1 geometry_type;
typedef T2 raster_type;
private:
int id_;
geometry_type geom_;
raster_type raster_;
std::map<std::string,value> props_;
public:
explicit feature(int id)
: properties(props_),
id_(id),
geom_(),
raster_() {}
feature(int id,const geometry_type& geom)
: properties(props_),
id_(id),
geom_(geom),
raster_() {}
int id() const
{
return id_;
}
void set_geometry(geometry_type& geom)
{
geom_=geom;
}
geometry_type const& get_geometry() const
{
return geom_;
}
const raster_type& get_raster() const
{
return raster_;
}
void set_raster(raster_type const& raster)
{
raster_=raster;
}
const properties& get_properties() const
{
return props_;
}
std::string to_string() const
{
std::stringstream ss;
ss << "feature (" << std::endl;
for (std::map<std::string,value>::const_iterator itr=props_.begin();
itr != props_.end();++itr)
{
ss << " " << itr->first << ":" << itr->second << std::endl;
}
ss << ")" << std::endl;
return ss.str();
}
};
typedef feature<geometry_ptr,raster_ptr> Feature;
inline std::ostream& operator<< (std::ostream & out,Feature const& f)
{
out << f.to_string();
return out;
}
}
#endif //FEATURE_HPP

View file

@ -1,250 +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 FEATURE_LAYER_DESC_HPP
#define FEATURE_LAYER_DESC_HPP
#include <string>
#include <vector>
#include <iostream>
namespace mapnik
{
using std::string;
using std::vector;
using std::clog;
using std::endl;
enum {
Integer=1,
Float =2,
Double =3,
String =4,
Geometry=5,
Object=6
};
class attribute_descriptor
{
public:
attribute_descriptor(string const& name,unsigned type,
bool primary_key=false,
int size=-1,
int precision=-1)
: name_(name),
type_(type),
primary_key_(primary_key),
size_(size),
precision_(precision) {}
attribute_descriptor(attribute_descriptor const& other)
: name_(other.name_),
type_(other.type_),
primary_key_(other.primary_key_),
size_(other.size_),
precision_(other.precision_) {}
attribute_descriptor& operator=(attribute_descriptor const& other)
{
if (this == &other)
return *this;
name_=other.name_;
type_=other.type_;
primary_key_=other.primary_key_;
size_=other.size_;
precision_=other.precision_;
return *this;
}
string const& get_name() const
{
return name_;
}
unsigned get_type() const
{
return type_;
}
bool is_primary_key() const
{
return primary_key_;
}
int get_size() const
{
return size_;
}
int get_precision() const
{
return precision_;
}
private:
string name_;
int type_;
bool primary_key_;
int size_;
int precision_;
};
template <typename charT,typename traits>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
attribute_descriptor const& ad)
{
out << "name=" << ad.get_name() << endl;
out << "type=" << ad.get_type() << endl;
out << "size=" << ad.get_size() << endl;
return out;
}
class layer_descriptor
{
public:
layer_descriptor(string const& name,int srid=-1)
: name_(name),
srid_(srid) {}
layer_descriptor(layer_descriptor const& other)
: name_(other.name_),
srid_(other.srid_),
desc_ar_(other.desc_ar_) {}
void set_name(string const& name)
{
name_=name;
}
string const& get_name() const
{
return name_;
}
void set_srid(int srid)
{
srid_=srid;
}
int get_srid() const
{
return srid_;
}
void add_descriptor(attribute_descriptor const& desc)
{
desc_ar_.push_back(desc);
}
vector<attribute_descriptor> const& get_descriptors() const
{
return desc_ar_;
}
vector<attribute_descriptor>& get_descriptors()
{
return desc_ar_;
}
private:
string name_;
int srid_;
vector<attribute_descriptor> desc_ar_;
};
template <typename charT,typename traits>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
layer_descriptor const& ld)
{
out << "name=" << ld.get_name() << endl;
out << "srid=" << ld.get_srid() << endl;
vector<attribute_descriptor> const& desc_ar=ld.get_descriptors();
vector<attribute_descriptor>::const_iterator pos=desc_ar.begin();
while (pos != desc_ar.end())
{
out << *pos++ << endl;
}
return out;
}
/*
bool layer_descriptor_to_wkb(layer_descriptor const& desc,array<>& wkb)
{
//srid
int srid = desc.get_srid();
wkb.write(&srid,sizeof(int));
//attribute descriptors
vector<attribute_descriptor> const& desc_ar = desc.get_descriptors();
vector<attribute_descriptor>::const_iterator itr=desc_ar.begin();
size_t num_desc = desc_ar.size();
wkb.write(&num_desc,sizeof(int));
while (itr != desc_ar.end())
{
string name = itr->get_name();
wkb.write(name.c_str(),name.size()+1);
unsigned type = static_cast<int>(itr->get_type());
wkb.write(&type,sizeof(unsigned));
bool prim_key = itr->is_primary_key();
wkb.write(&prim_key,sizeof(bool));
int size = itr->get_size();
wkb.write(&size,sizeof(int));
++itr;
}
return true;
}
bool layer_descriptor_from_wkb(const char* wkb, layer_descriptor &desc)
{
unsigned pos=0;
int srid;
memcpy(&srid,wkb+pos,sizeof(int));
desc.set_srid(srid);
pos+=sizeof(int);
int num_desc;
memcpy(&num_desc,wkb+pos,sizeof(int));
pos+=sizeof(int);
for (int i=0;i<num_desc;++i)
{
string name = wkb+pos;
pos += name.size()+1;
//std::clog<<"name="<<name<<"\n";
int type;
memcpy(&type,wkb+pos,sizeof(int));
pos += sizeof(int);
attribute_descriptor ad(name,type);
desc.add_descriptor(ad);
//todo!!!
pos += 4+1;
}
return true;
}
*/
}
#endif //FEATURE_LAYER_DESC_HPP

View file

@ -1,265 +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_AST_HPP
#define FILTER_PARSER_AST_HPP
#include <boost/spirit/core.hpp>
#include <boost/spirit/tree/ast.hpp>
#include <iostream>
using namespace std;
using namespace boost::spirit;
namespace mapnik
{
struct filter_grammar_ast : public grammar<filter_grammar_ast>
{
static const int integerID = 1;
static const int realID = 2;
static const int stringID = 3;
static const int propertyID = 4;
static const int factorID = 5;
static const int termID = 6;
static const int expressionID = 7;
static const int relationID = 8;
static const int equationID = 9;
static const int and_exprID = 10;
static const int or_exprID = 11;
template <typename ScannerT>
struct definition
{
definition(filter_grammar_ast const& /*self*/)
{
real = leaf_node_d[strict_real_p];
integer = leaf_node_d[int_p];
number = real | integer;
string_ = inner_node_d['\''>> leaf_node_d[( (alpha_p | '_') >>
* (alnum_p | '_' ))] >> '\''];
property = inner_node_d['[' >> leaf_node_d[ ( (alpha_p | '_') >> * (alnum_p | '_' )) ] >> ']'];
literal = number | string_ | property;
factor = literal
| (root_node_d[str_p("not")] >> literal)
| inner_node_d[ch_p('(') >> or_expr >> ch_p(')') ]
| (root_node_d[ch_p('-')] >> factor)
;
term = factor
>> *((root_node_d[ch_p('*')] >> factor) | (root_node_d[ch_p('/')] >> factor));
expression = term >> *((root_node_d[ch_p('+')] >> term) | (root_node_d[ch_p('-')] >> term));
relation = expression >> *((root_node_d[str_p(">=")] >> expression)
| (root_node_d[ch_p('>')] >> expression)
| (root_node_d[ch_p('<')] >> expression)
| (root_node_d[str_p("<=")] >> expression));
equation = relation >> *( (root_node_d[ch_p('=')] >> relation)
| (root_node_d[str_p("<>")] >> relation));
and_expr = equation >> *(root_node_d[str_p("and")] >> equation);
or_expr = and_expr >> *(root_node_d[str_p("or")] >> and_expr);
//spatial_op = str_p("Equals") | "Disjoint" | "Touches" | "Within"
// | "Overlaps" | "Crosses" | "Intersects" | "Contains" | "DWithin" | "Beyond" | "BBOX";
filter_statement = or_expr;
}
rule<ScannerT> const& start() const
{
return filter_statement;
}
rule<ScannerT,parser_context<>, parser_tag<factorID> > factor;
rule<ScannerT,parser_context<>, parser_tag<termID> > term;
rule<ScannerT,parser_context<>, parser_tag<expressionID> > expression;
rule<ScannerT,parser_context<>, parser_tag<relationID> > relation;
rule<ScannerT,parser_context<>, parser_tag<equationID> > equation;
rule<ScannerT,parser_context<>, parser_tag<and_exprID> > and_expr;
rule<ScannerT,parser_context<>, parser_tag<or_exprID> > or_expr;
rule<ScannerT> filter_statement;
rule<ScannerT> literal,number;
rule<ScannerT,parser_context<>, parser_tag<integerID> > integer;
rule<ScannerT,parser_context<>, parser_tag<realID> > real;
rule<ScannerT,parser_context<>, parser_tag<stringID> > string_;
rule<ScannerT,parser_context<>, parser_tag<propertyID> > property;
//rule<ScannerT> spatial_op;
};
};
class node_data
{
public:
enum {
Unknown=0,
Integer=1,
Real =2,
String =3,
Property=4
};
node_data()
: type_(Unknown) {}
node_data(int type)
: type_(type) {}
node_data(node_data const& other)
: type_(other.type_) {}
node_data& operator=(node_data const& other)
{
if (this==&other)
return *this;
type_=other.type_;
return *this;
}
~node_data() {}
private:
int type_;
};
typedef char const* iterator_t;
typedef node_val_data_factory<node_data> factory_t;
typedef tree_match<iterator_t,factory_t>::tree_iterator iter_t;
void process_node(iter_t const&,string&);
void walk_ast_tree(tree_parse_info<iterator_t,factory_t> info,string& text)
{
process_node(info.trees.begin(),text);
}
void process_node(iter_t const& i,string& text)
{
//clog << "In eval_expression. i->value = " <<
// string(i->value.begin(), i->value.end()) <<
// " i->children.size() = " << i->children.size() << endl;
//std::clog<<typeid(*i).name()<<"\n";
if (i->value.id() == filter_grammar_ast::integerID)
{
assert(i->children.size()==0);
string integer(i->value.begin(), i->value.end());
text+= integer;
}
else if (i->value.id() == filter_grammar_ast::realID)
{
assert(i->children.size()==0);
string real(i->value.begin(), i->value.end());
text += real;
}
else if (i->value.id() == filter_grammar_ast::stringID)
{
assert(i->children.size()==0);
string str(i->value.begin(), i->value.end());
text += str;
}
else if (i->value.id() == filter_grammar_ast::propertyID)
{
assert(i->children.size()==0);
string property_name(i->value.begin(), i->value.end());
text += property_name;
}
else if (i->value.id() == filter_grammar_ast::expressionID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
else if (i->value.id() == filter_grammar_ast::termID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
else if (i->value.id() == filter_grammar_ast::relationID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
else if (i->value.id() == filter_grammar_ast::equationID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
else if (i->value.id() == filter_grammar_ast::and_exprID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
else if (i->value.id() == filter_grammar_ast::or_exprID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
}
}
#endif //FILTER_PARSER_AST_HPP

View file

@ -1,432 +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$
#if !defined FONT_ENGINE_FREETYPE_HPP
#define FONT_ENGINE_FREETYPE_HPP
extern "C"
{
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
}
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/thread/mutex.hpp>
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <color.hpp>
#include <utils.hpp>
namespace mapnik
{
class font_face : boost::noncopyable
{
public:
font_face(FT_Face face)
: face_(face) {}
std::string family_name() const
{
return std::string(face_->family_name);
}
std::string style_name() const
{
return std::string(face_->style_name);
}
unsigned num_glyphs() const
{
return face_->num_glyphs;
}
FT_GlyphSlot glyph() const
{
return face_->glyph;
}
FT_Face get_face() const
{
return face_;
}
bool set_pixel_sizes(unsigned size)
{
if (! FT_Set_Pixel_Sizes( face_, 0, size ))
return true;
return false;
}
~font_face()
{
std::clog << "clean up face:" << family_name()<<":" << style_name() << std::endl;
FT_Done_Face(face_);
}
private:
FT_Face face_;
};
typedef boost::shared_ptr<font_face> face_ptr;
class MAPNIK_DECL freetype_engine : public mapnik::singleton<freetype_engine,mapnik::CreateStatic>,
private boost::noncopyable
{
friend class mapnik::CreateStatic<freetype_engine>;
public:
static bool register_font(std::string const& file_name);
static std::vector<std::string> face_names ();
static face_ptr create_face(std::string const& family_name);
private:
freetype_engine();
virtual ~freetype_engine();
static FT_Library library_;
static std::map<std::string,std::string> name2file_;
};
template <typename T>
class MAPNIK_DECL face_manager : private boost::noncopyable
{
typedef T font_engine_type;
typedef std::map<std::string,face_ptr> faces;
public:
face_ptr get_face(std::string const& name)
{
typename faces::iterator itr;
itr = faces_.find(name);
if (itr != faces_.end())
{
return itr->second;
}
else
{
face_ptr face = font_engine_type::instance()->create_face(name);
if (face)
{
faces_.insert(make_pair(name,face));
}
return face;
}
}
private:
faces faces_;
};
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();
while ( itr != text.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));
}
return out;
}
template <typename T>
struct text_renderer : private boost::noncopyable
{
struct glyph_t : boost::noncopyable
{
FT_Glyph image;
glyph_t(FT_Glyph image_) : image(image_) {}
~glyph_t () { FT_Done_Glyph(image);}
};
typedef boost::ptr_vector<glyph_t> glyphs_t;
typedef std::pair<unsigned,unsigned> dimension_t;
typedef T pixmap_type;
text_renderer (pixmap_type & pixmap, face_ptr face)
: pixmap_(pixmap),
face_(face),
fill_(0,0,0),
halo_fill_(255,255,255),
halo_radius_(0),
angle_(0.0) {}
void set_pixel_size(unsigned size)
{
face_->set_pixel_sizes(size);
}
void set_angle(float angle)
{
angle_=angle;
}
void set_fill(mapnik::Color const& fill)
{
fill_=fill;
}
void set_halo_fill(mapnik::Color const& halo)
{
halo_fill_=halo;
}
void set_halo_radius( int radius=1)
{
halo_radius_=radius;
}
dimension_t prepare_glyphs(std::string const& text)
{
//clear glyphs
glyphs_.clear();
FT_Matrix matrix;
FT_Vector pen;
FT_Error error;
FT_Face face = face_->get_face();
FT_GlyphSlot slot = face->glyph;
FT_Bool use_kerning;
FT_UInt previous = 0;
pen.x = 0;
pen.y = 0;
use_kerning = FT_HAS_KERNING(face)>0?true:false;
FT_BBox bbox;
bbox.xMin = bbox.yMin = 32000;
bbox.xMax = bbox.yMax = -32000; //hmm??
for (std::string::const_iterator i=text.begin();i!=text.end();++i)
{
FT_BBox glyph_bbox;
FT_Glyph image;
matrix.xx = (FT_Fixed)( cos( angle_ ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle_ ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle_ ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle_ ) * 0x10000L );
FT_Set_Transform (face,&matrix,&pen);
FT_UInt glyph_index = FT_Get_Char_Index( face, unsigned(*i) & 0xff );
if ( use_kerning && previous && glyph_index)
{
FT_Vector delta;
FT_Get_Kerning(face,previous,glyph_index,
FT_KERNING_DEFAULT,&delta);
pen.x += delta.x;
pen.y += delta.y;
}
error = FT_Load_Glyph (face,glyph_index,FT_LOAD_DEFAULT);
if ( error )
continue;
error = FT_Get_Glyph( face->glyph, &image);
if ( error )
continue;
FT_Glyph_Get_CBox(image,ft_glyph_bbox_pixels, &glyph_bbox);
if (glyph_bbox.xMin < bbox.xMin)
bbox.xMin = glyph_bbox.xMin;
if (glyph_bbox.yMin < bbox.yMin)
bbox.yMin = glyph_bbox.yMin;
if (glyph_bbox.xMax > bbox.xMax)
bbox.xMax = glyph_bbox.xMax;
if (glyph_bbox.yMax > bbox.yMax)
bbox.yMax = glyph_bbox.yMax;
if ( bbox.xMin > bbox.xMax )
{
bbox.xMin = 0;
bbox.yMin = 0;
bbox.xMax = 0;
bbox.yMax = 0;
}
pen.x += slot->advance.x;
pen.y += slot->advance.y;
previous = glyph_index;
// take ownership of the glyph
glyphs_.push_back(new glyph_t(image));
}
unsigned string_width = (bbox.xMax - bbox.xMin);
unsigned string_height = (bbox.yMax - bbox.yMin);
return dimension_t(string_width,string_height);
}
void render(double x0, double y0)
{
FT_Error error;
FT_Vector start;
unsigned height = pixmap_.height();
start.x = unsigned(x0 * (1 << 6));
start.y = unsigned((height - y0) * (1 << 6));
// now render transformed glyphs
typename glyphs_t::iterator pos;
if (halo_radius_ > 0)
{
//render halo
for ( pos = glyphs_.begin(); pos != glyphs_.end();++pos)
{
FT_Glyph_Transform(pos->image,0,&start);
error = FT_Glyph_To_Bitmap( &(pos->image),FT_RENDER_MODE_NORMAL,0,1);
if ( ! error )
{
FT_BitmapGlyph bit = (FT_BitmapGlyph)pos->image;
render_halo(&bit->bitmap, halo_fill_.rgba(),
bit->left,
height - bit->top,halo_radius_);
}
}
}
//render actual text
for ( pos = glyphs_.begin(); pos != glyphs_.end();++pos)
{
FT_Glyph_Transform(pos->image,0,&start);
error = FT_Glyph_To_Bitmap( &(pos->image),FT_RENDER_MODE_NORMAL,0,1);
if ( ! error )
{
FT_BitmapGlyph bit = (FT_BitmapGlyph)pos->image;
render_bitmap(&bit->bitmap, fill_.rgba(),
bit->left,
height - bit->top);
}
}
}
private:
void render_halo(FT_Bitmap *bitmap,unsigned rgba,int x,int y,int radius)
{
int x_max=x+bitmap->width;
int y_max=y+bitmap->rows;
int i,p,j,q;
for (i=x,p=0;i<x_max;++i,++p)
{
for (j=y,q=0;j<y_max;++j,++q)
{
int gray = bitmap->buffer[q*bitmap->width+p];
if (gray)
{
for (int n=-halo_radius_; n <=halo_radius_; ++n)
for (int m=-halo_radius_;m <= halo_radius_; ++m)
pixmap_.blendPixel(i+m,j+n,rgba,gray);
}
}
}
}
void render_bitmap(FT_Bitmap *bitmap,unsigned rgba,int x,int y)
{
int x_max=x+bitmap->width;
int y_max=y+bitmap->rows;
int i,p,j,q;
for (i=x,p=0;i<x_max;++i,++p)
{
for (j=y,q=0;j<y_max;++j,++q)
{
int gray=bitmap->buffer[q*bitmap->width+p];
if (gray)
{
pixmap_.blendPixel(i,j,rgba,gray);
}
}
}
}
pixmap_type & pixmap_;
face_ptr face_;
mapnik::Color fill_;
mapnik::Color halo_fill_;
int halo_radius_;
float angle_;
glyphs_t glyphs_;
};
}
#endif // FONT_ENGINE_FREETYPE_HPP

View file

@ -25,13 +25,16 @@
#ifndef AGG_RENDERER_HPP
#define AGG_RENDERER_HPP
#include "feature_style_processor.hpp"
// boost
#include <boost/utility.hpp>
#include "font_engine_freetype.hpp"
#include "label_collision_detector.hpp"
// mapnik
#include <mapnik/feature_style_processor.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/label_collision_detector.hpp>
#include <mapnik/map.hpp>
#include <mapnik/config.hpp>
namespace mapnik
{
namespace mapnik {
template <typename T>
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T> >,
private boost::noncopyable

View file

@ -0,0 +1,222 @@
/*****************************************************************************
*
* 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
// stl
#include <typeinfo>
#include <sstream>
#include <map>
// boost
#include <boost/any.hpp>
namespace mapnik {
template <typename T>
struct attribute_traits
{
static std::string to_string(const T& value)
{
std::stringstream ss;
ss << value;
return ss.str();
}
};
template <>
struct attribute_traits<std::string>
{
static std::string to_string(const std::string& value)
{
return value;
}
};
class MAPNIK_DECL attribute
{
public:
attribute()
: base_(0) {}
template <typename T>
attribute(const T& value)
: base_(new attribute_impl<T>(value))
{}
attribute(const attribute& rhs)
: base_(rhs.base_ ? rhs.base_->clone() : 0)
{}
~attribute()
{
delete base_;
}
template<typename T>
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 <typename T,typename ATraits=attribute_traits<T> >
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<typename value_type>
friend value_type* attribute_cast(attribute*);
attribute_base* base_;
};
template<typename T>
struct bad_attribute_cast : public std::bad_cast
{
virtual const char* what() const throw()
{
return "attribute::failed conversion";
}
};
template <typename T>
bool is_type(const attribute& attr)
{
return attr.type()==typeid(T);
}
template <typename T>
T* attribute_cast(attribute* attr)
{
return attr && attr->type() == typeid(T)
? &static_cast<attribute::attribute_impl<T>*>(attr->base_)->value_
: 0;
}
template <typename T>
const T* attribute_cast(const attribute* attr)
{
return attribute_cast<T>(const_cast<attribute*>(attr));
}
template <typename T>
T attribute_cast(const attribute& attr)
{
using namespace boost;
typedef BOOST_DEDUCED_TYPENAME remove_reference<T>::type nonref;
const nonref * result=attribute_cast<nonref>(&attr);
if (!result)
{
throw bad_attribute_cast<T>();
}
return *result;
}
template <typename T>
T attribute_cast(attribute& attr)
{
using namespace boost;
typedef BOOST_DEDUCED_TYPENAME remove_reference<T>::type nonref;
nonref * result=attribute_cast<nonref>(&attr);
if (!result)
throw bad_attribute_cast<T>();
return *result;
}
template <typename T>
attribute attribute_from_string(const std::string& val)
{
std::istringstream is(val);
T t;
is >> t;
return attribute(t);
}
template <typename charT, typename traits>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
const attribute& attr)
{
out << attr.to_string();
return out;
}
}
#endif //ATTRIBUTE_HPP

View file

@ -0,0 +1,98 @@
/*****************************************************************************
*
* 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 ATTRIBUTE_COLLECTOR_HPP
#define ATTRIBUTE_COLLECTOR_HPP
// stl
#include <set>
#include <iostream>
// mapnik
#include <mapnik/filter.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/feature_layer_desc.hpp>
#include <mapnik/rule.hpp>
namespace mapnik {
struct symbolizer_attributes : public boost::static_visitor<>
{
symbolizer_attributes(std::set<std::string>& names)
: names_(names) {}
template <typename T>
void operator () (T const&) const {}
void operator () (text_symbolizer const& sym)
{
names_.insert(sym.get_name());
}
private:
std::set<std::string>& names_;
};
template <typename FeatureT>
class attribute_collector : public filter_visitor<FeatureT>
{
private:
std::set<std::string>& names_;
public:
attribute_collector(std::set<std::string>& names)
: names_(names) {}
void visit(filter<FeatureT>& /*filter*/)
{
//not interested
}
void visit(expression<FeatureT>& exp)
{
property<FeatureT>* pf;
if ((pf = dynamic_cast<property<FeatureT>*>(&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);
}
virtual ~attribute_collector() {}
private:
// no copying
attribute_collector(attribute_collector const&);
attribute_collector& operator=(attribute_collector const&);
};
}
#endif //ATTRIBUTE_COLLECTOR_HPP

View file

@ -27,8 +27,7 @@
#include <string>
namespace mapnik
{
namespace mapnik {
struct attribute_desc
{
std::string name;
@ -36,4 +35,4 @@ namespace mapnik
};
}
#endif
#endif // ATTRIBUTE_DESCRIPTOR_HPP

View file

@ -25,9 +25,9 @@
#ifndef COLOR_HPP
#define COLOR_HPP
#include <boost/format.hpp>
#include "config.hpp"
#include <sstream>
#include <boost/format.hpp>
#include <mapnik/config.hpp>
namespace mapnik {

View file

@ -25,12 +25,12 @@
#ifndef COLOR_FACTORY_HPP
#define COLOR_FACTORY_HPP
#include "config.hpp"
#include "css_color_parser.hpp"
#include <mapnik/config.hpp>
#include <mapnik/css_color_parser.hpp>
namespace mapnik
{
using namespace boost::spirit;
using namespace boost::spirit;
namespace mapnik {
class MAPNIK_DECL color_factory
{
public:

View file

@ -0,0 +1,149 @@
/*****************************************************************************
*
* 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 <mapnik/filter.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/attribute.hpp>
namespace mapnik {
template <typename T>
struct greater_than
{
bool operator() (T const& left, T const& right) const
{
return left > right;
}
static std::string to_string()
{
return ">";
}
};
template <typename T>
struct greater_than_or_equal
{
bool operator() (T const& left, T const& right) const
{
return left >= right;
}
static std::string to_string()
{
return ">=";
}
};
template <typename T>
struct less_than
{
bool operator() (T const& left, T const& right) const
{
return left < right;
}
static std::string to_string()
{
return "<";
}
};
template <typename T>
struct less_than_or_equal
{
bool operator() (T const& left, T const& right) const
{
return left <= right;
}
static std::string to_string()
{
return "<=";
}
};
template <typename T>
struct equals
{
bool operator() (T const& left, T const& right) const
{
return left == right;
}
static std::string to_string()
{
return "=";
}
};
template <typename T>
struct not_equals
{
bool operator() (T const& left, T const& right) const
{
return left != right;
}
static std::string to_string()
{
return "<>";
}
};
template <typename FeatureT,typename Op>
struct compare_filter : public filter<FeatureT>
{
compare_filter(expression<FeatureT> const& left,
expression<FeatureT> const& right)
: filter<FeatureT>(),
left_(left.clone()), right_(right.clone()) {}
compare_filter(compare_filter const& other)
: filter<FeatureT>(),
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<FeatureT>& 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<FeatureT>* clone() const
{
return new compare_filter<FeatureT,Op>(*this);
}
virtual ~compare_filter()
{
delete left_;
delete right_;
}
private:
expression<FeatureT>* left_;
expression<FeatureT>* right_;
};
}
#endif //COMPARISON_HPP

View file

@ -36,4 +36,4 @@
# define MAPNIK_DECL
#endif
#endif
#endif // CONFIG_HPP

View file

@ -25,12 +25,10 @@
#ifndef COORD_HPP
#define COORD_HPP
#include <iostream>
#include <iomanip>
#include <sstream>
namespace mapnik
{
namespace mapnik {
template <typename T,int dim>
struct coord {
typedef T type;

View file

@ -0,0 +1,92 @@
/*****************************************************************************
*
* 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: coord_array.hpp 39 2005-04-10 20:39:53Z pavlenko $
#ifndef COORD_ARRAY_HPP
#define COORD_ARRAY_HPP
// stl
#include <cassert>
//mapnik
#include <mapnik/coord.hpp>
namespace mapnik {
template <typename T>
class coord_array
{
typedef T coord_type;
coord_type* pt_;
const unsigned size_;
public:
coord_array(unsigned size=0)
: pt_(static_cast<coord_type*>(size==0?0: ::operator new (sizeof(coord_type)*size))),
size_(size) {}
coord_array(const coord_array& rhs)
: pt_(static_cast<coord_type*>(rhs.size_==0?0: ::operator new (sizeof(coord_type)*rhs.size_))),
size_(rhs.size_) {
memcpy(pt_,rhs.pt_,sizeof(coord_type)*rhs.size_);
}
~coord_array()
{
::operator delete (pt_);
}
unsigned size() const
{
return size_;
}
void set(unsigned index,double x,double y)
{
assert(index<size_);
pt_[index].x=x;
pt_[index].y=y;
}
const coord_type& at(unsigned index) const
{
assert(index<size_);
return pt_[index];
}
const coord_type& operator[] (unsigned index) const
{
assert (index<size_);
return pt_[index];
}
coord_type& operator[] (unsigned index)
{
assert (index<size_);
return pt_[index];
}
private:
coord_array& operator=(const coord_array&);
};
}
#endif //COORD_ARRAY_HPP

View file

@ -0,0 +1,387 @@
/*****************************************************************************
*
* 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
#include <boost/spirit/core.hpp>
#include <boost/spirit/symbols.hpp>
using namespace boost::spirit;
namespace mapnik {
template <typename ColorT>
struct named_colors : public symbols<ColorT>
{
named_colors()
{
symbols<ColorT>::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))
;
}
};
template <typename ActionsT>
struct css_color_grammar : public grammar<css_color_grammar<ActionsT> >
{
css_color_grammar(ActionsT& actions_)
: actions(actions_) {}
template <typename ScannerT>
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") >> '(' >> uint3_p[self.actions.red_]
>> ',' >> uint3_p[self.actions.green_]
>> ',' >> uint3_p[self.actions.blue_]
>> ')';
rgb_percent = str_p("rgb") >> '(' >> ureal_p[self.actions.red_p_] >> '%'
>> ',' >> ureal_p[self.actions.green_p_] >> '%'
>> ',' >> ureal_p[self.actions.blue_p_] >> '%'
>> ')';
css_color = named_colors_p[self.actions.named_] | hex6 | hex3 | rgb_percent | rgb;
}
boost::spirit::rule<ScannerT> rgb;
boost::spirit::rule<ScannerT> rgb_percent;
boost::spirit::rule<ScannerT> hex6;
boost::spirit::rule<ScannerT> hex3;
boost::spirit::rule<ScannerT> css_color;
boost::spirit::rule<ScannerT> const& start() const
{
return css_color;
}
uint_parser<unsigned, 10, 1, 3> uint3_p;
uint_parser<unsigned, 16, 6, 6> uint6x_p;
uint_parser<unsigned, 16, 3, 3> uint3x_p;
named_colors<typename ActionsT::color_type> named_colors_p;
};
ActionsT& actions;
};
template <typename ColorT>
struct named_color_action
{
named_color_action(ColorT& c)
: c_(c) {}
void operator() (ColorT const&c) const
{
c_=c;
}
ColorT& c_;
};
template <typename ColorT>
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 <typename ColorT>
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 <typename ColorT>
struct red_action
{
red_action(ColorT& c)
: c_(c) {}
void operator () (unsigned int r) const
{
c_.set_red(r);
}
ColorT& c_;
};
template <typename ColorT>
struct green_action
{
green_action(ColorT& c)
: c_(c) {}
void operator () (unsigned int g) const
{
c_.set_green(g);
}
ColorT& c_;
};
template <typename ColorT>
struct blue_action
{
blue_action(ColorT& c)
: c_(c) {}
void operator () (unsigned int b) const
{
c_.set_blue(b);
}
ColorT& c_;
};
template <typename ColorT>
struct red_action_p
{
red_action_p(ColorT& c)
: c_(c) {}
void operator () (double r) const
{
c_.set_red(unsigned((255.0 * r)/100.0 + 0.5));
}
ColorT& c_;
};
template <typename ColorT>
struct green_action_p
{
green_action_p(ColorT& c)
: c_(c) {}
void operator () (double g) const
{
c_.set_green(unsigned((255.0 * g)/100.0 + 0.5));
}
ColorT& c_;
};
template <typename ColorT>
struct blue_action_p
{
blue_action_p(ColorT& c)
: c_(c) {}
void operator () (double b) const
{
c_.set_blue(unsigned((255.0 * b)/100.0 + 0.5));
}
ColorT& c_;
};
template <typename ColorT>
struct actions
{
typedef ColorT color_type;
actions(ColorT& c)
: named_(c),
hex6_(c),
hex3_(c),
red_(c),
green_(c),
blue_(c),
red_p_(c),
green_p_(c),
blue_p_(c) {}
named_color_action<ColorT> named_;
hex6_action<ColorT> hex6_;
hex3_action<ColorT> hex3_;
red_action<ColorT> red_;
green_action<ColorT> green_;
blue_action<ColorT> blue_;
red_action_p<ColorT> red_p_;
green_action_p<ColorT> green_p_;
blue_action_p<ColorT> blue_p_;
};
}
#endif //CSS_COLOR_PARSER_HPP

169
include/mapnik/ctrans.hpp Normal file
View file

@ -0,0 +1,169 @@
/*****************************************************************************
*
* 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: ctrans.hpp 39 2005-04-10 20:39:53Z pavlenko $
#ifndef CTRANS_HPP
#define CTRANS_HPP
#include <mapnik/envelope.hpp>
#include <mapnik/coord_array.hpp>
namespace mapnik {
typedef coord_array<coord2d> CoordinateArray;
template <typename Transform,typename Geometry>
struct MAPNIK_DECL coord_transform
{
coord_transform(Transform const& t,Geometry& geom)
: t_(t), geom_(geom) {}
unsigned vertex(double *x , double *y) const
{
unsigned command = geom_.vertex(x,y);
*x = t_.forward_x_(x);
*y = t_.forward_y_(y);
return command;
}
void rewind (unsigned pos)
{
geom_.rewind(pos);
}
private:
Transform const& t_;
Geometry& geom_;
};
class CoordTransform
{
private:
int width;
int height;
double scale_;
Envelope<double> extent;
public:
CoordTransform(int width,int height,const Envelope<double>& extent)
:width(width),height(height),extent(extent)
{
double sx=((double)width)/extent.width();
double sy=((double)height)/extent.height();
scale_=std::min(sx,sy);
}
inline double scale() const
{
return scale_;
}
inline void forward_x(double* x) const
{
*x = (*x - extent.minx() ) * scale_;
}
inline void forward_y(double* y) const
{
*y = (extent.maxy() - *y) * scale_;
}
inline double forward_x_(double* x) const
{
return (*x - extent.minx() ) * scale_;
}
inline double forward_y_(double* y) const
{
return (extent.maxy() - *y) * scale_;
}
inline void backward_x(double* x) const
{
*x = extent.minx() + *x/scale_;
}
inline void backward_y(double* y) const
{
*y = extent.maxy() - *y/scale_;
}
inline coord2d& forward(coord2d& c) const
{
forward_x(&c.x);
forward_y(&c.y);
return c;
}
inline coord2d& backward(coord2d& c) const
{
backward_x(&c.x);
backward_y(&c.y);
return c;
}
inline Envelope<double> forward(const Envelope<double>& e) const
{
double x0 = e.minx();
double y0 = e.miny();
double x1 = e.maxx();
double y1 = e.maxy();
forward_x(&x0);
forward_y(&y0);
forward_x(&x1);
forward_y(&y1);
return Envelope<double>(x0,y0,x1,y1);
}
inline Envelope<double> backward(const Envelope<double>& e) const
{
double x0 = e.minx();
double y0 = e.miny();
double x1 = e.maxx();
double y1 = e.maxy();
backward_x(&x0);
backward_y(&y0);
backward_x(&x1);
backward_y(&y1);
return Envelope<double>(x0,y0,x1,y1);
}
inline CoordinateArray& forward(CoordinateArray& coords) const
{
for (unsigned i=0;i<coords.size();++i)
{
forward(coords[i]);
}
return coords;
}
inline CoordinateArray& backward(CoordinateArray& coords) const
{
for (unsigned i=0;i<coords.size();++i)
{
backward(coords[i]);
}
return coords;
}
};
}
#endif //CTRANS_HPP

View file

@ -24,27 +24,31 @@
#ifndef DATASOURCE_HPP
#define DATASOURCE_HPP
// stl
#include <map>
#include <string>
#include "ctrans.hpp"
#include "params.hpp"
#include "feature.hpp"
#include "query.hpp"
#include "feature_layer_desc.hpp"
// boost
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/ctrans.hpp>
#include <mapnik/params.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/query.hpp>
#include <mapnik/feature_layer_desc.hpp>
namespace mapnik {
typedef MAPNIK_DECL boost::shared_ptr<Feature> feature_ptr;
namespace mapnik
{
typedef MAPNIK_DECL shared_ptr<Feature> feature_ptr;
struct MAPNIK_DECL Featureset
{
virtual feature_ptr next()=0;
virtual ~Featureset() {};
};
typedef shared_ptr<Featureset> featureset_ptr;
typedef boost::shared_ptr<Featureset> featureset_ptr;
class MAPNIK_DECL datasource_exception : public std::exception
{
private:
@ -100,8 +104,8 @@ namespace mapnik
typedef boost::shared_ptr<datasource> datasource_p;
///////////////////////////////////////////
#define DATASOURCE_PLUGIN(classname) \
#define DATASOURCE_PLUGIN(classname) \
extern "C" MAPNIK_DECL std::string datasource_name() \
{ \
return classname::name(); \
@ -114,6 +118,7 @@ namespace mapnik
{ \
delete ds; \
} \
///////////////////////////////////////////
//
}
#endif //DATASOURCE_HPP

View file

@ -25,17 +25,19 @@
#ifndef DATASOURCE_CACHE_HPP
#define DATASOURCE_CACHE_HPP
// stl
#include <map>
// boost
#include <boost/shared_ptr.hpp>
// mapnik
#include <mapnik/utils.hpp>
#include <mapnik/params.hpp>
#include <mapnik/plugin.hpp>
#include <mapnik/datasource.hpp>
#include "utils.hpp"
#include "params.hpp"
#include "plugin.hpp"
#include "datasource.hpp"
namespace mapnik
{
class MAPNIK_DECL datasource_cache : public singleton <datasource_cache,CreateStatic>
namespace mapnik {
class MAPNIK_DECL datasource_cache :
public singleton <datasource_cache,CreateStatic>
{
friend class CreateStatic<datasource_cache>;
private:
@ -51,4 +53,5 @@ namespace mapnik
static boost::shared_ptr<datasource> create(parameters const& params);
};
}
#endif //DATASOURCE_CACHE_HPP

View file

@ -25,13 +25,13 @@
#ifndef ENVELOPE_HPP
#define ENVELOPE_HPP
#include "config.hpp"
// stl
#include <iomanip>
#include "coord.hpp"
namespace mapnik
{
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/coord.hpp>
namespace mapnik {
template <class T> class MAPNIK_DECL Envelope
{
public:
@ -85,4 +85,5 @@ namespace mapnik
return out;
}
}
#endif // ENVELOPE_HPP

View file

@ -0,0 +1,126 @@
/*****************************************************************************
*
* 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 <mapnik/value.hpp>
#include <mapnik/filter_visitor.hpp>
namespace mapnik {
template <typename FeatureT> class filter_visitor;
template <typename FeatureT>
class expression
{
public:
virtual value get_value(FeatureT const& feature) const=0;
virtual void accept(filter_visitor<FeatureT>& v)=0;
virtual expression<FeatureT>* clone() const=0;
virtual std::string to_string() const=0;
virtual ~expression() {}
};
template <typename FeatureT>
class literal : public expression<FeatureT>
{
public:
literal(int val)
: expression<FeatureT>(),
value_(val) {}
literal(double val)
: expression<FeatureT>(),
value_(val) {}
literal(std::string const& val)
: expression<FeatureT>(),
value_(val) {}
literal(literal const& other)
: expression<FeatureT>(),
value_(other.value_) {}
value get_value(FeatureT const& /*feature*/) const
{
return value_;
}
void accept(filter_visitor<FeatureT>& v)
{
v.visit(*this);
}
expression<FeatureT>* clone() const
{
return new literal(*this);
}
std::string to_string() const
{
return value_.to_expression_string();
}
~literal() {}
private:
value value_;
};
template <typename FeatureT>
class property : public expression<FeatureT>
{
public:
property(std::string const& name)
: expression<FeatureT>(),
name_(name)
{}
property(property const& other)
: expression<FeatureT>(),
name_(other.name_)
{}
value get_value(FeatureT const& feature) const
{
return feature[name_];
}
void accept(filter_visitor<FeatureT>& v)
{
v.visit(*this);
}
expression<FeatureT>* 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

View file

@ -25,12 +25,13 @@
#ifndef FACTORY_HPP
#define FACTORY_HPP
// stl
#include <stdexcept>
#include <map>
#include "utils.hpp"
// mapnik
#include <mapnik/utils.hpp>
namespace mapnik
{
namespace mapnik {
template <typename key_type,
typename product_type>
class default_factory_error
@ -56,7 +57,9 @@ namespace mapnik
typename product_creator=product_type* (*)(),
template <typename,typename> class factory_error_policy=default_factory_error
>
class factory : public singleton<factory <product_type,key_type,product_creator,factory_error_policy> >,
class factory : public singleton<factory <product_type,
key_type,
product_creator,factory_error_policy> >,
factory_error_policy <key_type,product_type>
{
private:
@ -85,4 +88,5 @@ namespace mapnik
}
};
}
#endif //FACTORY_HPP

121
include/mapnik/feature.hpp Normal file
View file

@ -0,0 +1,121 @@
/*****************************************************************************
*
* 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: feature.hpp 40 2005-04-13 20:20:46Z pavlenko $
#ifndef FEATURE_HPP
#define FEATURE_HPP
// stl
#include <map>
// boost
#include <boost/property_map.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
// mapnik
#include <mapnik/value.hpp>
#include <mapnik/geometry.hpp>
#include <mapnik/raster.hpp>
namespace mapnik {
typedef boost::shared_ptr<raster> raster_ptr;
typedef boost::associative_property_map<
std::map<std::string,value
> > properties;
template <typename T1,typename T2>
struct feature : public properties,
private boost::noncopyable
{
public:
typedef T1 geometry_type;
typedef T2 raster_type;
private:
int id_;
geometry_type geom_;
raster_type raster_;
std::map<std::string,value> props_;
public:
explicit feature(int id)
: properties(props_),
id_(id),
geom_(),
raster_() {}
feature(int id,const geometry_type& geom)
: properties(props_),
id_(id),
geom_(geom),
raster_() {}
int id() const
{
return id_;
}
void set_geometry(geometry_type& geom)
{
geom_=geom;
}
geometry_type const& get_geometry() const
{
return geom_;
}
const raster_type& get_raster() const
{
return raster_;
}
void set_raster(raster_type const& raster)
{
raster_=raster;
}
const properties& get_properties() const
{
return props_;
}
std::string to_string() const
{
std::stringstream ss;
ss << "feature (" << std::endl;
for (std::map<std::string,value>::const_iterator itr=props_.begin();
itr != props_.end();++itr)
{
ss << " " << itr->first << ":" << itr->second << std::endl;
}
ss << ")" << std::endl;
return ss.str();
}
};
typedef feature<geometry_ptr,raster_ptr> Feature;
inline std::ostream& operator<< (std::ostream & out,Feature const& f)
{
out << f.to_string();
return out;
}
}
#endif //FEATURE_HPP

View file

@ -25,7 +25,8 @@
#ifndef FEATURE_FACTORY_HPP
#define FEATURE_FACTORY_HPP
#include "feature.hpp"
#include <mapnik/feature.hpp>
namespace mapnik
{
struct feature_factory
@ -37,5 +38,4 @@ namespace mapnik
};
}
#endif //FEATURE_FACTORY_HPP

View file

@ -0,0 +1,250 @@
/*****************************************************************************
*
* 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 FEATURE_LAYER_DESC_HPP
#define FEATURE_LAYER_DESC_HPP
#include <string>
#include <vector>
#include <iostream>
namespace mapnik
{
using std::string;
using std::vector;
using std::clog;
using std::endl;
enum {
Integer=1,
Float =2,
Double =3,
String =4,
Geometry=5,
Object=6
};
class attribute_descriptor
{
public:
attribute_descriptor(string const& name,unsigned type,
bool primary_key=false,
int size=-1,
int precision=-1)
: name_(name),
type_(type),
primary_key_(primary_key),
size_(size),
precision_(precision) {}
attribute_descriptor(attribute_descriptor const& other)
: name_(other.name_),
type_(other.type_),
primary_key_(other.primary_key_),
size_(other.size_),
precision_(other.precision_) {}
attribute_descriptor& operator=(attribute_descriptor const& other)
{
if (this == &other)
return *this;
name_=other.name_;
type_=other.type_;
primary_key_=other.primary_key_;
size_=other.size_;
precision_=other.precision_;
return *this;
}
string const& get_name() const
{
return name_;
}
unsigned get_type() const
{
return type_;
}
bool is_primary_key() const
{
return primary_key_;
}
int get_size() const
{
return size_;
}
int get_precision() const
{
return precision_;
}
private:
string name_;
int type_;
bool primary_key_;
int size_;
int precision_;
};
template <typename charT,typename traits>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
attribute_descriptor const& ad)
{
out << "name=" << ad.get_name() << endl;
out << "type=" << ad.get_type() << endl;
out << "size=" << ad.get_size() << endl;
return out;
}
class layer_descriptor
{
public:
layer_descriptor(string const& name,int srid=-1)
: name_(name),
srid_(srid) {}
layer_descriptor(layer_descriptor const& other)
: name_(other.name_),
srid_(other.srid_),
desc_ar_(other.desc_ar_) {}
void set_name(string const& name)
{
name_=name;
}
string const& get_name() const
{
return name_;
}
void set_srid(int srid)
{
srid_=srid;
}
int get_srid() const
{
return srid_;
}
void add_descriptor(attribute_descriptor const& desc)
{
desc_ar_.push_back(desc);
}
vector<attribute_descriptor> const& get_descriptors() const
{
return desc_ar_;
}
vector<attribute_descriptor>& get_descriptors()
{
return desc_ar_;
}
private:
string name_;
int srid_;
vector<attribute_descriptor> desc_ar_;
};
template <typename charT,typename traits>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
layer_descriptor const& ld)
{
out << "name=" << ld.get_name() << endl;
out << "srid=" << ld.get_srid() << endl;
vector<attribute_descriptor> const& desc_ar=ld.get_descriptors();
vector<attribute_descriptor>::const_iterator pos=desc_ar.begin();
while (pos != desc_ar.end())
{
out << *pos++ << endl;
}
return out;
}
/*
bool layer_descriptor_to_wkb(layer_descriptor const& desc,array<>& wkb)
{
//srid
int srid = desc.get_srid();
wkb.write(&srid,sizeof(int));
//attribute descriptors
vector<attribute_descriptor> const& desc_ar = desc.get_descriptors();
vector<attribute_descriptor>::const_iterator itr=desc_ar.begin();
size_t num_desc = desc_ar.size();
wkb.write(&num_desc,sizeof(int));
while (itr != desc_ar.end())
{
string name = itr->get_name();
wkb.write(name.c_str(),name.size()+1);
unsigned type = static_cast<int>(itr->get_type());
wkb.write(&type,sizeof(unsigned));
bool prim_key = itr->is_primary_key();
wkb.write(&prim_key,sizeof(bool));
int size = itr->get_size();
wkb.write(&size,sizeof(int));
++itr;
}
return true;
}
bool layer_descriptor_from_wkb(const char* wkb, layer_descriptor &desc)
{
unsigned pos=0;
int srid;
memcpy(&srid,wkb+pos,sizeof(int));
desc.set_srid(srid);
pos+=sizeof(int);
int num_desc;
memcpy(&num_desc,wkb+pos,sizeof(int));
pos+=sizeof(int);
for (int i=0;i<num_desc;++i)
{
string name = wkb+pos;
pos += name.size()+1;
//std::clog<<"name="<<name<<"\n";
int type;
memcpy(&type,wkb+pos,sizeof(int));
pos += sizeof(int);
attribute_descriptor ad(name,type);
desc.add_descriptor(ad);
//todo!!!
pos += 4+1;
}
return true;
}
*/
}
#endif //FEATURE_LAYER_DESC_HPP

View file

@ -25,15 +25,17 @@
#ifndef FEATURE_STYLE_PROCESSOR_HPP
#define FEATURE_STYLE_PROCESSOR_HPP
//stl
#include <vector>
#include <iostream>
// boost
#include <boost/progress.hpp>
#include "envelope.hpp"
#include "datasource.hpp"
#include "layer.hpp"
#include "map.hpp"
#include "attribute_collector.hpp"
#include "utils.hpp"
// mapnik
#include <mapnik/envelope.hpp>
#include <mapnik/datasource.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/map.hpp>
#include <mapnik/attribute_collector.hpp>
#include <mapnik/utils.hpp>
namespace mapnik
{
@ -149,7 +151,8 @@ namespace mapnik
symbolizers::const_iterator symIter=symbols.begin();
while (symIter!=symbols.end())
{
boost::apply_visitor(symbol_dispatch(p,*feature),*symIter++);
boost::apply_visitor
(symbol_dispatch(p,*feature),*symIter++);
}
}
++itr;
@ -157,14 +160,16 @@ namespace mapnik
if (do_else)
{
//else filter
std::vector<rule_type*>::const_iterator itr=else_rules.begin();
std::vector<rule_type*>::const_iterator itr=
else_rules.begin();
while (itr != else_rules.end())
{
const symbolizers& symbols = (*itr)->get_symbolizers();
symbolizers::const_iterator symIter=symbols.begin();
while (symIter!=symbols.end())
{
boost::apply_visitor(symbol_dispatch(p,*feature),*symIter++);
boost::apply_visitor
(symbol_dispatch(p,*feature),*symIter++);
}
++itr;
}

View file

@ -22,13 +22,13 @@
//$Id$
#ifndef FEATURE_TYPE_STYLE
#define FEATURE_TYPE_STYLE
#include "rule.hpp"
#include "feature.hpp"
#ifndef FEATURE_TYPE_STYLE_HPP
#define FEATURE_TYPE_STYLE_HPP
// stl
#include <vector>
// mapnik
#include <mapnik/rule.hpp>
#include <mapnik/feature.hpp>
namespace mapnik
{
@ -64,4 +64,4 @@ namespace mapnik
};
}
#endif //FEATURE_TYPE_STYLE
#endif //FEATURE_TYPE_STYLE_HPP

View file

@ -25,7 +25,8 @@
#ifndef FILTER_HPP
#define FILTER_HPP
#include "feature.hpp"
#include <mapnik/config.hpp>
#include <mapnik/feature.hpp>
namespace mapnik
{

View file

@ -25,9 +25,11 @@
#ifndef FILTER_TO_STRING_HPP
#define FILTER_TO_STRING_HPP
#include "filter.hpp"
#include "expression.hpp"
// stl
#include <set>
// mapnik
#include <mapnik/filter.hpp>
#include <mapnik/expression.hpp>
namespace mapnik
{

View file

@ -25,12 +25,12 @@
#ifndef FILTER_FACTORY_HPP
#define FILTER_FACTORY_HPP
#include "filter_parser.hpp"
using std::string;
#include <mapnik/filter_parser.hpp>
namespace mapnik
{
using std::string;
template<typename FeatureT>
class MAPNIK_DECL filter_factory
{

View file

@ -25,32 +25,34 @@
#ifndef FILTER_PARSER_HPP
#define FILTER_PARSER_HPP
// stl
#include <stack>
#include <iostream>
// boost
#include <boost/shared_ptr.hpp>
#include <boost/spirit/core.hpp>
#include <boost/spirit/symbols.hpp>
#include <boost/spirit/utility/confix.hpp>
#include <boost/spirit/utility/escape_char.hpp>
#include <boost/spirit/utility/chset.hpp>
#include "value.hpp"
#include "comparison.hpp"
#include "math_expr.hpp"
#include "expression.hpp"
#include "filter.hpp"
#include "regex_filter.hpp"
#include "logical.hpp"
// mapnik
#include <mapnik/value.hpp>
#include <mapnik/comparison.hpp>
#include <mapnik/math_expr.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/filter.hpp>
#include <mapnik/regex_filter.hpp>
#include <mapnik/logical.hpp>
using namespace boost::spirit;
using std::string;
using std::clog;
using std::stack;
using boost::shared_ptr;
namespace mapnik
{
using std::string;
using std::clog;
using std::stack;
template <typename FeatureT>
struct push_integer
{
@ -59,7 +61,8 @@ namespace mapnik
void operator() (int val) const
{
exprs_.push(shared_ptr<expression<FeatureT> >(new literal<FeatureT>(val)));
exprs_.push(shared_ptr<expression<FeatureT> >
( new literal<FeatureT>(val)));
}
stack<shared_ptr<expression<FeatureT> > >& exprs_;
};
@ -158,7 +161,8 @@ namespace mapnik
std::string pattern(start,end);
try
{
filters_.push(shared_ptr<filter<FeatureT> >(new regex_filter<FeatureT>(*exp,pattern)));
filters_.push(shared_ptr<filter<FeatureT> >
(new regex_filter<FeatureT>(*exp,pattern)));
}
catch (...)//boost::regex_error& ex)
{
@ -216,7 +220,8 @@ namespace mapnik
filters_.pop();
if (left && right)
{
filters_.push(shared_ptr<filter<FeatureT> >(new logical_and<FeatureT>(*left,*right)));
filters_.push(shared_ptr<filter<FeatureT> >
(new logical_and<FeatureT>(*left,*right)));
}
}
}
@ -240,7 +245,8 @@ namespace mapnik
filters_.pop();
if (left && right)
{
filters_.push(shared_ptr<filter<FeatureT> >(new logical_or<FeatureT>(*left,*right)));
filters_.push(shared_ptr<filter<FeatureT> >
(new logical_or<FeatureT>(*left,*right)));
}
}
}

View file

@ -0,0 +1,266 @@
/*****************************************************************************
*
* 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_AST_HPP
#define FILTER_PARSER_AST_HPP
// stl
#include <iostream>
// boost
#include <boost/spirit/core.hpp>
#include <boost/spirit/tree/ast.hpp>
using namespace std;
using namespace boost::spirit;
namespace mapnik
{
struct filter_grammar_ast : public grammar<filter_grammar_ast>
{
static const int integerID = 1;
static const int realID = 2;
static const int stringID = 3;
static const int propertyID = 4;
static const int factorID = 5;
static const int termID = 6;
static const int expressionID = 7;
static const int relationID = 8;
static const int equationID = 9;
static const int and_exprID = 10;
static const int or_exprID = 11;
template <typename ScannerT>
struct definition
{
definition(filter_grammar_ast const& /*self*/)
{
real = leaf_node_d[strict_real_p];
integer = leaf_node_d[int_p];
number = real | integer;
string_ = inner_node_d['\''>> leaf_node_d[( (alpha_p | '_') >>
* (alnum_p | '_' ))] >> '\''];
property = inner_node_d['[' >> leaf_node_d[ ( (alpha_p | '_') >> * (alnum_p | '_' )) ] >> ']'];
literal = number | string_ | property;
factor = literal
| (root_node_d[str_p("not")] >> literal)
| inner_node_d[ch_p('(') >> or_expr >> ch_p(')') ]
| (root_node_d[ch_p('-')] >> factor)
;
term = factor
>> *((root_node_d[ch_p('*')] >> factor) | (root_node_d[ch_p('/')] >> factor));
expression = term >> *((root_node_d[ch_p('+')] >> term) | (root_node_d[ch_p('-')] >> term));
relation = expression >> *((root_node_d[str_p(">=")] >> expression)
| (root_node_d[ch_p('>')] >> expression)
| (root_node_d[ch_p('<')] >> expression)
| (root_node_d[str_p("<=")] >> expression));
equation = relation >> *( (root_node_d[ch_p('=')] >> relation)
| (root_node_d[str_p("<>")] >> relation));
and_expr = equation >> *(root_node_d[str_p("and")] >> equation);
or_expr = and_expr >> *(root_node_d[str_p("or")] >> and_expr);
//spatial_op = str_p("Equals") | "Disjoint" | "Touches" | "Within"
// | "Overlaps" | "Crosses" | "Intersects" | "Contains" | "DWithin" | "Beyond" | "BBOX";
filter_statement = or_expr;
}
rule<ScannerT> const& start() const
{
return filter_statement;
}
rule<ScannerT,parser_context<>, parser_tag<factorID> > factor;
rule<ScannerT,parser_context<>, parser_tag<termID> > term;
rule<ScannerT,parser_context<>, parser_tag<expressionID> > expression;
rule<ScannerT,parser_context<>, parser_tag<relationID> > relation;
rule<ScannerT,parser_context<>, parser_tag<equationID> > equation;
rule<ScannerT,parser_context<>, parser_tag<and_exprID> > and_expr;
rule<ScannerT,parser_context<>, parser_tag<or_exprID> > or_expr;
rule<ScannerT> filter_statement;
rule<ScannerT> literal,number;
rule<ScannerT,parser_context<>, parser_tag<integerID> > integer;
rule<ScannerT,parser_context<>, parser_tag<realID> > real;
rule<ScannerT,parser_context<>, parser_tag<stringID> > string_;
rule<ScannerT,parser_context<>, parser_tag<propertyID> > property;
//rule<ScannerT> spatial_op;
};
};
class node_data
{
public:
enum {
Unknown=0,
Integer=1,
Real =2,
String =3,
Property=4
};
node_data()
: type_(Unknown) {}
node_data(int type)
: type_(type) {}
node_data(node_data const& other)
: type_(other.type_) {}
node_data& operator=(node_data const& other)
{
if (this==&other)
return *this;
type_=other.type_;
return *this;
}
~node_data() {}
private:
int type_;
};
typedef char const* iterator_t;
typedef node_val_data_factory<node_data> factory_t;
typedef tree_match<iterator_t,factory_t>::tree_iterator iter_t;
void process_node(iter_t const&,string&);
void walk_ast_tree(tree_parse_info<iterator_t,factory_t> info,string& text)
{
process_node(info.trees.begin(),text);
}
void process_node(iter_t const& i,string& text)
{
//clog << "In eval_expression. i->value = " <<
// string(i->value.begin(), i->value.end()) <<
// " i->children.size() = " << i->children.size() << endl;
//std::clog<<typeid(*i).name()<<"\n";
if (i->value.id() == filter_grammar_ast::integerID)
{
assert(i->children.size()==0);
string integer(i->value.begin(), i->value.end());
text+= integer;
}
else if (i->value.id() == filter_grammar_ast::realID)
{
assert(i->children.size()==0);
string real(i->value.begin(), i->value.end());
text += real;
}
else if (i->value.id() == filter_grammar_ast::stringID)
{
assert(i->children.size()==0);
string str(i->value.begin(), i->value.end());
text += str;
}
else if (i->value.id() == filter_grammar_ast::propertyID)
{
assert(i->children.size()==0);
string property_name(i->value.begin(), i->value.end());
text += property_name;
}
else if (i->value.id() == filter_grammar_ast::expressionID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
else if (i->value.id() == filter_grammar_ast::termID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
else if (i->value.id() == filter_grammar_ast::relationID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
else if (i->value.id() == filter_grammar_ast::equationID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
else if (i->value.id() == filter_grammar_ast::and_exprID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
else if (i->value.id() == filter_grammar_ast::or_exprID)
{
assert(i->children.size() == 2);
assert(!i->children.begin()->value.is_root());
process_node(i->children.begin(),text);
text += string(i->value.begin(), i->value.end());
process_node(i->children.begin()+1,text);
text +="\n";
}
}
}
#endif //FILTER_PARSER_AST_HPP

View file

@ -25,8 +25,8 @@
#ifndef FILTER_VISITOR_HPP
#define FILTER_VISITOR_HPP
#include "filter.hpp"
#include "expression.hpp"
#include <mapnik/filter.hpp>
#include <mapnik/expression.hpp>
namespace mapnik
{

View file

@ -0,0 +1,432 @@
/*****************************************************************************
*
* 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 FONT_ENGINE_FREETYPE_HPP
#define FONT_ENGINE_FREETYPE_HPP
// freetype2
extern "C"
{
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
}
// stl
#include <string>
#include <vector>
#include <map>
#include <iostream>
// boost
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/thread/mutex.hpp>
// mapnik
#include <mapnik/color.hpp>
#include <mapnik/utils.hpp>
namespace mapnik
{
class font_face : boost::noncopyable
{
public:
font_face(FT_Face face)
: face_(face) {}
std::string family_name() const
{
return std::string(face_->family_name);
}
std::string style_name() const
{
return std::string(face_->style_name);
}
unsigned num_glyphs() const
{
return face_->num_glyphs;
}
FT_GlyphSlot glyph() const
{
return face_->glyph;
}
FT_Face get_face() const
{
return face_;
}
bool set_pixel_sizes(unsigned size)
{
if (! FT_Set_Pixel_Sizes( face_, 0, size ))
return true;
return false;
}
~font_face()
{
std::clog << "clean up face:" << family_name()<<":" << style_name() << std::endl;
FT_Done_Face(face_);
}
private:
FT_Face face_;
};
typedef boost::shared_ptr<font_face> face_ptr;
class MAPNIK_DECL freetype_engine : public mapnik::singleton<freetype_engine,mapnik::CreateStatic>,
private boost::noncopyable
{
friend class mapnik::CreateStatic<freetype_engine>;
public:
static bool register_font(std::string const& file_name);
static std::vector<std::string> face_names ();
static face_ptr create_face(std::string const& family_name);
private:
freetype_engine();
virtual ~freetype_engine();
static FT_Library library_;
static std::map<std::string,std::string> name2file_;
};
template <typename T>
class MAPNIK_DECL face_manager : private boost::noncopyable
{
typedef T font_engine_type;
typedef std::map<std::string,face_ptr> faces;
public:
face_ptr get_face(std::string const& name)
{
typename faces::iterator itr;
itr = faces_.find(name);
if (itr != faces_.end())
{
return itr->second;
}
else
{
face_ptr face = font_engine_type::instance()->create_face(name);
if (face)
{
faces_.insert(make_pair(name,face));
}
return face;
}
}
private:
faces faces_;
};
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();
while ( itr != text.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));
}
return out;
}
template <typename T>
struct text_renderer : private boost::noncopyable
{
struct glyph_t : boost::noncopyable
{
FT_Glyph image;
glyph_t(FT_Glyph image_) : image(image_) {}
~glyph_t () { FT_Done_Glyph(image);}
};
typedef boost::ptr_vector<glyph_t> glyphs_t;
typedef std::pair<unsigned,unsigned> dimension_t;
typedef T pixmap_type;
text_renderer (pixmap_type & pixmap, face_ptr face)
: pixmap_(pixmap),
face_(face),
fill_(0,0,0),
halo_fill_(255,255,255),
halo_radius_(0),
angle_(0.0) {}
void set_pixel_size(unsigned size)
{
face_->set_pixel_sizes(size);
}
void set_angle(float angle)
{
angle_=angle;
}
void set_fill(mapnik::Color const& fill)
{
fill_=fill;
}
void set_halo_fill(mapnik::Color const& halo)
{
halo_fill_=halo;
}
void set_halo_radius( int radius=1)
{
halo_radius_=radius;
}
dimension_t prepare_glyphs(std::string const& text)
{
//clear glyphs
glyphs_.clear();
FT_Matrix matrix;
FT_Vector pen;
FT_Error error;
FT_Face face = face_->get_face();
FT_GlyphSlot slot = face->glyph;
FT_Bool use_kerning;
FT_UInt previous = 0;
pen.x = 0;
pen.y = 0;
use_kerning = FT_HAS_KERNING(face)>0?true:false;
FT_BBox bbox;
bbox.xMin = bbox.yMin = 32000;
bbox.xMax = bbox.yMax = -32000; //hmm??
for (std::string::const_iterator i=text.begin();i!=text.end();++i)
{
FT_BBox glyph_bbox;
FT_Glyph image;
matrix.xx = (FT_Fixed)( cos( angle_ ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle_ ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle_ ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle_ ) * 0x10000L );
FT_Set_Transform (face,&matrix,&pen);
FT_UInt glyph_index = FT_Get_Char_Index( face, unsigned(*i) & 0xff );
if ( use_kerning && previous && glyph_index)
{
FT_Vector delta;
FT_Get_Kerning(face,previous,glyph_index,
FT_KERNING_DEFAULT,&delta);
pen.x += delta.x;
pen.y += delta.y;
}
error = FT_Load_Glyph (face,glyph_index,FT_LOAD_DEFAULT);
if ( error )
continue;
error = FT_Get_Glyph( face->glyph, &image);
if ( error )
continue;
FT_Glyph_Get_CBox(image,ft_glyph_bbox_pixels, &glyph_bbox);
if (glyph_bbox.xMin < bbox.xMin)
bbox.xMin = glyph_bbox.xMin;
if (glyph_bbox.yMin < bbox.yMin)
bbox.yMin = glyph_bbox.yMin;
if (glyph_bbox.xMax > bbox.xMax)
bbox.xMax = glyph_bbox.xMax;
if (glyph_bbox.yMax > bbox.yMax)
bbox.yMax = glyph_bbox.yMax;
if ( bbox.xMin > bbox.xMax )
{
bbox.xMin = 0;
bbox.yMin = 0;
bbox.xMax = 0;
bbox.yMax = 0;
}
pen.x += slot->advance.x;
pen.y += slot->advance.y;
previous = glyph_index;
// take ownership of the glyph
glyphs_.push_back(new glyph_t(image));
}
unsigned string_width = (bbox.xMax - bbox.xMin);
unsigned string_height = (bbox.yMax - bbox.yMin);
return dimension_t(string_width,string_height);
}
void render(double x0, double y0)
{
FT_Error error;
FT_Vector start;
unsigned height = pixmap_.height();
start.x = unsigned(x0 * (1 << 6));
start.y = unsigned((height - y0) * (1 << 6));
// now render transformed glyphs
typename glyphs_t::iterator pos;
if (halo_radius_ > 0)
{
//render halo
for ( pos = glyphs_.begin(); pos != glyphs_.end();++pos)
{
FT_Glyph_Transform(pos->image,0,&start);
error = FT_Glyph_To_Bitmap( &(pos->image),FT_RENDER_MODE_NORMAL,0,1);
if ( ! error )
{
FT_BitmapGlyph bit = (FT_BitmapGlyph)pos->image;
render_halo(&bit->bitmap, halo_fill_.rgba(),
bit->left,
height - bit->top,halo_radius_);
}
}
}
//render actual text
for ( pos = glyphs_.begin(); pos != glyphs_.end();++pos)
{
FT_Glyph_Transform(pos->image,0,&start);
error = FT_Glyph_To_Bitmap( &(pos->image),FT_RENDER_MODE_NORMAL,0,1);
if ( ! error )
{
FT_BitmapGlyph bit = (FT_BitmapGlyph)pos->image;
render_bitmap(&bit->bitmap, fill_.rgba(),
bit->left,
height - bit->top);
}
}
}
private:
void render_halo(FT_Bitmap *bitmap,unsigned rgba,int x,int y,int radius)
{
int x_max=x+bitmap->width;
int y_max=y+bitmap->rows;
int i,p,j,q;
for (i=x,p=0;i<x_max;++i,++p)
{
for (j=y,q=0;j<y_max;++j,++q)
{
int gray = bitmap->buffer[q*bitmap->width+p];
if (gray)
{
for (int n=-halo_radius_; n <=halo_radius_; ++n)
for (int m=-halo_radius_;m <= halo_radius_; ++m)
pixmap_.blendPixel(i+m,j+n,rgba,gray);
}
}
}
}
void render_bitmap(FT_Bitmap *bitmap,unsigned rgba,int x,int y)
{
int x_max=x+bitmap->width;
int y_max=y+bitmap->rows;
int i,p,j,q;
for (i=x,p=0;i<x_max;++i,++p)
{
for (j=y,q=0;j<y_max;++j,++q)
{
int gray=bitmap->buffer[q*bitmap->width+p];
if (gray)
{
pixmap_.blendPixel(i,j,rgba,gray);
}
}
}
}
pixmap_type & pixmap_;
face_ptr face_;
Color fill_;
Color halo_fill_;
int halo_radius_;
float angle_;
glyphs_t glyphs_;
};
}
#endif // FONT_ENGINE_FREETYPE_HPP

View file

@ -24,8 +24,13 @@
#ifndef GEOM_UTIL_HPP
#define GEOM_UTIL_HPP
// stl
#include <cmath>
// boost
#include <boost/tuple/tuple.hpp>
// mapnik
#include <mapnik/envelope.hpp>
#include <mapnik/vertex.hpp>
namespace mapnik
{

View file

@ -26,15 +26,16 @@
#ifndef GEOMETRY_HPP
#define GEOMETRY_HPP
#include "vertex_vector.hpp"
#include "vertex_transform.hpp"
#include "ctrans.hpp"
#include "geom_util.hpp"
// boost
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
// mapnik
#include <mapnik/vertex_vector.hpp>
#include <mapnik/vertex_transform.hpp>
#include <mapnik/ctrans.hpp>
#include <mapnik/geom_util.hpp>
namespace mapnik
{
namespace mapnik {
enum {
Point = 1,
LineString = 2,

View file

@ -30,31 +30,31 @@
namespace mapnik
{
using namespace boost;
#define int2net(A) (int32_t) (((uint32_t) ((uint8_t) (A)[1])) |\
#define int2net(A) (int32_t) (((uint32_t) ((uint8_t) (A)[1])) | \
(((uint32_t) ((uint8_t) (A)[0])) << 8))
#define int4net(A) (int32_t) (((uint32_t) ((uint8_t) (A)[3])) |\
(((uint32_t) ((uint8_t) (A)[2])) << 8) |\
(((uint32_t) ((uint8_t) (A)[1])) << 16) |\
#define int4net(A) (int32_t) (((uint32_t) ((uint8_t) (A)[3])) | \
(((uint32_t) ((uint8_t) (A)[2])) << 8) | \
(((uint32_t) ((uint8_t) (A)[1])) << 16) | \
(((uint32_t) ((uint8_t) (A)[0])) << 24))
typedef char byte;
#define float8net(V,M) do { double def_temp;\
((byte*) &def_temp)[0]=(M)[7];\
((byte*) &def_temp)[1]=(M)[6];\
((byte*) &def_temp)[2]=(M)[5];\
((byte*) &def_temp)[3]=(M)[4];\
((byte*) &def_temp)[4]=(M)[3];\
((byte*) &def_temp)[5]=(M)[2];\
((byte*) &def_temp)[6]=(M)[1];\
((byte*) &def_temp)[7]=(M)[0];\
#define float8net(V,M) do { double def_temp; \
((byte*) &def_temp)[0]=(M)[7]; \
((byte*) &def_temp)[1]=(M)[6]; \
((byte*) &def_temp)[2]=(M)[5]; \
((byte*) &def_temp)[3]=(M)[4]; \
((byte*) &def_temp)[4]=(M)[3]; \
((byte*) &def_temp)[5]=(M)[2]; \
((byte*) &def_temp)[6]=(M)[1]; \
((byte*) &def_temp)[7]=(M)[0]; \
(V) = def_temp; } while(0)
#define float4net(V,M) do { float def_temp;\
((byte*) &def_temp)[0]=(M)[3];\
((byte*) &def_temp)[1]=(M)[2];\
((byte*) &def_temp)[2]=(M)[1];\
((byte*) &def_temp)[3]=(M)[0];\
#define float4net(V,M) do { float def_temp; \
((byte*) &def_temp)[0]=(M)[3]; \
((byte*) &def_temp)[1]=(M)[2]; \
((byte*) &def_temp)[2]=(M)[1]; \
((byte*) &def_temp)[3]=(M)[0]; \
(V)=def_temp; } while(0)
}

View file

@ -24,14 +24,15 @@
#ifndef GRAPHICS_HPP
#define GRAPHICS_HPP
// stl
#include <cmath>
#include <string>
#include <cassert>
#include "color.hpp"
#include "gamma.hpp"
#include "image_data.hpp"
#include "envelope.hpp"
// mapnik
#include <mapnik/color.hpp>
#include <mapnik/gamma.hpp>
#include <mapnik/image_data.hpp>
#include <mapnik/envelope.hpp>
namespace mapnik
{

View file

@ -1,36 +1,35 @@
/*****************************************************************************
*
* 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
*
*****************************************************************************/
*
* 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: image_reader.hpp 39 2005-04-10 20:39:53Z pavlenko $
#ifndef IMAGE_READER_HPP
#define IMAGE_READER_HPP
// stl
#include <stdexcept>
#include <string>
#include "image_data.hpp"
#include "config.hpp"
// mapnik
#include <mapnik/image_data.hpp>
#include <mapnik/config.hpp>
namespace mapnik
{
@ -60,7 +59,6 @@ namespace mapnik
bool register_image_reader(const std::string& type,ImageReader* (*)(const std::string&));
MAPNIK_DECL ImageReader* get_image_reader(const std::string& type,const std::string& file);
}
#endif //IMAGE_READER_HPP

View file

@ -25,15 +25,26 @@
#ifndef IMAGE_UTIL_HPP
#define IMAGE_UTIL_HPP
// stl
#include <string>
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/graphics.hpp>
namespace mapnik
{
class MAPNIK_DECL ImageUtils
{
public:
static void save_to_file(const std::string& filename,const std::string& type,const Image32& image);
static void save_to_file(const std::string& filename,
const std::string& type,
const Image32& image);
private:
static void save_as_png(const std::string& filename,const Image32& image);
static void save_as_jpeg(const std::string& filename,int quality, const Image32& image);
static void save_as_png(const std::string& filename,
const Image32& image);
static void save_as_jpeg(const std::string& filename,
int quality,
const Image32& image);
};
template <typename T>

View file

@ -24,9 +24,10 @@
#if !defined LABEL_COLLISION_DETECTOR
#define LABEL_COLLISION_DETECTOR
#include "quad_tree.hpp"
// stl
#include <vector>
// mapnik
#include <mapnik/quad_tree.hpp>
namespace mapnik
{

View file

@ -23,11 +23,13 @@
#ifndef LAYER_HPP
#define LAYER_HPP
// stl
#include <vector>
#include "feature.hpp"
#include "datasource.hpp"
// boost
#include <boost/shared_ptr.hpp>
// mapnik
#include <mapnik/feature.hpp>
#include <mapnik/datasource.hpp>
namespace mapnik
{
@ -40,12 +42,11 @@ namespace mapnik
double maxZoom_;
bool active_;
bool selectable_;
std::vector<std::string> styles_;
std::string selection_style_;
datasource_p ds_;
mutable std::vector<boost::shared_ptr<Feature> > selection_;
mutable datasource_p ds_;
public:
explicit Layer(std::string const& name);

View file

@ -25,7 +25,7 @@
#define LINE_PATTERN_SYMBOLIZER_HPP
#include <boost/shared_ptr.hpp>
#include "graphics.hpp"
#include <mapnik/graphics.hpp>
namespace mapnik
{

View file

@ -24,7 +24,7 @@
#ifndef LINE_SYMBOLIZER_HPP
#define LINE_SYMBOLIZER_HPP
#include "stroke.hpp"
#include <mapnik/stroke.hpp>
namespace mapnik
{

View file

@ -25,7 +25,7 @@
#define MAP_LOADER_HPP
#include <string>
#include "map.hpp"
#include <mapnik/map.hpp>
namespace mapnik
{

View file

@ -24,7 +24,7 @@
#ifndef LOGICAL_HPP
#define LOGICAL_HPP
#include "filter.hpp"
#include <mapnik/filter.hpp>
namespace mapnik
{

View file

@ -24,7 +24,7 @@
#ifndef MAP_HPP
#define MAP_HPP
#include "feature_type_style.hpp"
#include <mapnik/feature_type_style.hpp>
namespace mapnik
{

View file

@ -24,7 +24,7 @@
#ifndef MATH_EXPR_HPP
#define MATH_EXPR_HPP
#include "expression.hpp"
#include <mapnik/expression.hpp>
namespace mapnik
{

View file

@ -24,9 +24,11 @@
#ifndef PLUGIN_HPP
#define PLUGIN_HPP
// ltdl
#include <ltdl.h>
// stl
#include <string>
// boost
#include <boost/utility.hpp>
namespace mapnik

View file

@ -25,7 +25,7 @@
#define POINT_SYMBOLIZER_HPP
#include <boost/shared_ptr.hpp>
#include "graphics.hpp"
#include <mapnik/graphics.hpp>
namespace mapnik
{

View file

@ -25,7 +25,7 @@
#define POLYGON_PATTERN_SYMBOLIZER_HPP
#include <boost/shared_ptr.hpp>
#include "graphics.hpp"
#include <mapnik/graphics.hpp>
namespace mapnik
{

View file

@ -25,7 +25,7 @@
#ifndef POLYGON_SYMBOLIZER_HPP
#define POLYGON_SYMBOLIZER_HPP
#include "color.hpp"
#include <mapnik/color.hpp>
namespace mapnik
{

122
include/mapnik/pool.hpp Normal file
View file

@ -0,0 +1,122 @@
/*****************************************************************************
*
* 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: pool.hpp 39 2005-04-10 20:39:53Z pavlenko $
#ifndef POOL_HPP
#define POOL_HPP
// stl
#include <iostream>
#include <map>
#include <deque>
#include <ctime>
// boost
#include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/utility.hpp>
// mapnik
#include <mapnik/utils.hpp>
namespace mapnik
{
template <typename T, typename PoolT>
class PoolGuard
{
private:
const T& obj_;
PoolT& pool_;
public:
explicit PoolGuard(const T& ptr,PoolT& pool)
: obj_(ptr),
pool_(pool) {}
~PoolGuard()
{
pool_->returnObject(obj_);
}
private:
PoolGuard();
PoolGuard(const PoolGuard&);
PoolGuard& operator=(const PoolGuard&);
};
template <typename T,template <typename> class Creator>
class Pool : private boost::noncopyable
{
typedef boost::shared_ptr<T> HolderType;
typedef std::deque<HolderType> ContType;
Creator<T> creator_;
const int initialSize_;
const int maxSize_;
ContType usedPool_;
ContType unusedPool_;
boost::mutex mutex_;
public:
Pool(const Creator<T>& creator,int initialSize=5,int maxSize=20)
:creator_(creator),
initialSize_(initialSize),
maxSize_(maxSize)
{
for (int i=0;i<initialSize_;++i)
{
unusedPool_.push_back(HolderType(creator_()));
}
}
const HolderType& borrowObject()
{
mutex::scoped_lock lock(mutex_);
typename ContType::iterator itr=unusedPool_.begin();
if (itr!=unusedPool_.end())
{
std::clog<<"borrow "<<(*itr).get()<<"\n";
usedPool_.push_back(*itr);
itr=unusedPool_.erase(itr);
return usedPool_[usedPool_.size()-1];
}
static const HolderType defaultObj;
return defaultObj;
}
void returnObject(const HolderType& obj)
{
mutex::scoped_lock lock(mutex_);
typename ContType::iterator itr=usedPool_.begin();
while (itr != usedPool_.end())
{
if (obj.get()==(*itr).get())
{
std::clog<<"return "<<(*itr).get()<<"\n";
unusedPool_.push_back(*itr);
usedPool_.erase(itr);
return;
}
++itr;
}
}
};
}
#endif //POOL_HPP

View file

@ -23,12 +23,13 @@
#if !defined QUAD_TREE_HPP
#define QUAD_TREE_HPP
// stl
#include <vector>
// boost
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/noncopyable.hpp>
#include <vector>
#include "envelope.hpp"
// mapnik
#include <mapnik/envelope.hpp>
namespace mapnik
{

View file

@ -24,12 +24,13 @@
#ifndef QUERY_HPP
#define QUERY_HPP
// stl
#include <set>
#include <limits>
#include "filter.hpp"
#include "envelope.hpp"
#include "feature.hpp"
//mapnik
#include <mapnik/filter.hpp>
#include <mapnik/envelope.hpp>
#include <mapnik/feature.hpp>
namespace mapnik
{

View file

@ -24,10 +24,9 @@
#ifndef RASTER_HPP
#define RASTER_HPP
#include "graphics.hpp"
#include <mapnik/graphics.hpp>
namespace mapnik
{
namespace mapnik {
struct raster
{
Envelope<double> ext_;
@ -39,3 +38,4 @@ namespace mapnik
}
#endif //RASTER_HPP

View file

@ -24,12 +24,11 @@
#ifndef RASTER_SYMBOLIZER_HPP
#define RASTER_SYMBOLIZER_HPP
#include <boost/shared_ptr.hpp>
#include <config.hpp>
#include <mapnik/config.hpp>
namespace mapnik
{
struct MAPNIK_DECL raster_symbolizer { /* TODO */};
}
#endif //RASTER_SYMBOLIZER
#endif //RASTER_SYMBOLIZER_HPP

View file

@ -0,0 +1,81 @@
/* This file is part of Mapnik (c++ mapping toolkit)
* Copyright (C) 2005 Artem Pavlenko
*
* Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//$Id$
#ifndef REGEX_FILTER_HPP
#define REGEX_FILTER_HPP
// boost
#include <boost/regex.hpp>
#include <boost/algorithm/string.hpp>
// mapnik
#include <mapnik/filter.hpp>
#include <mapnik/expression.hpp>
namespace mapnik
{
template <typename FeatureT>
struct regex_filter : public filter<FeatureT>
{
regex_filter(expression<FeatureT> const& exp,
std::string const& pattern)
: filter<FeatureT>(),
exp_(exp.clone()),
pattern_(pattern) {}
regex_filter(regex_filter const& other)
: filter<FeatureT>(),
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<FeatureT>& v)
{
exp_->accept(v);
v.visit(*this);
}
filter<FeatureT>* 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<FeatureT>* exp_;
boost::regex pattern_;
};
}
#endif //REGEX_FILTER_HPP

View file

@ -22,20 +22,22 @@
#ifndef RULE_HPP
#define RULE_HPP
#include "line_symbolizer.hpp"
#include "line_pattern_symbolizer.hpp"
#include "polygon_symbolizer.hpp"
#include "polygon_pattern_symbolizer.hpp"
#include "point_symbolizer.hpp"
#include "raster_symbolizer.hpp"
#include "text_symbolizer.hpp"
#include "filter.hpp"
#include "filter_visitor.hpp"
#include <boost/shared_ptr.hpp>
#include <boost/variant.hpp>
// stl
#include <string>
#include <vector>
// boost
#include <boost/shared_ptr.hpp>
#include <boost/variant.hpp>
// mapnik
#include <mapnik/line_symbolizer.hpp>
#include <mapnik/line_pattern_symbolizer.hpp>
#include <mapnik/polygon_symbolizer.hpp>
#include <mapnik/polygon_pattern_symbolizer.hpp>
#include <mapnik/point_symbolizer.hpp>
#include <mapnik/raster_symbolizer.hpp>
#include <mapnik/text_symbolizer.hpp>
#include <mapnik/filter.hpp>
#include <mapnik/filter_visitor.hpp>
namespace mapnik
{
@ -89,6 +91,7 @@ namespace mapnik
typedef std::vector<symbolizer> symbolizers;
template <typename FeatureT> class all_filter;
template <typename FeatureT,template <typename> class Filter>

View file

@ -23,9 +23,10 @@
#ifndef SAVE_MAP_HPP
#define SAVE_MAP_HPP
// stl
#include <string>
#include "map.hpp"
// mapnik
#include <mapnik/map.hpp>
namespace mapnik
{

View file

@ -22,8 +22,8 @@
#ifndef SPATIAL_HPP
#define SPATIAL_HPP
#include "filter.hpp"
#include "filter_visitor.hpp"
#include <mapnik/filter.hpp>
#include <mapnik/filter_visitor.hpp>
namespace mapnik
{
@ -146,7 +146,6 @@ namespace mapnik
v.visit(*this);
}
virtual ~bbox() {}
};
}

Some files were not shown because too many files have changed in this diff Show more