Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'new-xml'

Conflicts:
	include/mapnik/config_error.hpp
	include/mapnik/ptree_helpers.hpp
	src/formatting/text.cpp
	src/libxml2_loader.cpp
	src/load_map.cpp
	src/metawriter_factory.cpp
	src/text_placements/registry.cpp
	src/text_placements/simple.cpp
  • Loading branch information...
commit 2b68cea0a1039162e8d32b31755c3a127628b54c 2 parents fb6bf40 + 150de2a
@herm herm authored
Showing with 1,705 additions and 1,448 deletions.
  1. +90 −0 include/mapnik/boolean.hpp
  2. +8 −0 include/mapnik/color.hpp
  3. +6 −114 include/mapnik/color_factory.hpp
  4. +13 −16 include/mapnik/config_error.hpp
  5. +1 −1  include/mapnik/expression.hpp
  6. +2 −1  include/mapnik/formatting/base.hpp
  7. +2 −2 include/mapnik/formatting/expression.hpp
  8. +1 −1  include/mapnik/formatting/format.hpp
  9. +2 −2 include/mapnik/formatting/registry.hpp
  10. +1 −1  include/mapnik/formatting/text.hpp
  11. +17 −9 include/mapnik/internal/dump_xml.hpp
  12. +2 −1  include/mapnik/metawriter_factory.hpp
  13. +0 −1  include/mapnik/palette.hpp
  14. +0 −433 include/mapnik/ptree_helpers.hpp
  15. +0 −1  include/mapnik/raster_colorizer.hpp
  16. +1 −1  include/mapnik/symbolizer_helpers.hpp
  17. +1 −1  include/mapnik/text_placements/list.hpp
  18. +2 −2 include/mapnik/text_placements/registry.hpp
  19. +1 −1  include/mapnik/text_placements/simple.hpp
  20. +2 −2 include/mapnik/text_properties.hpp
  21. +0 −1  include/mapnik/value.hpp
  22. +3 −5 include/mapnik/{libxml2_loader.hpp → xml_loader.hpp}
  23. +137 −0 include/mapnik/xml_node.hpp
  24. +54 −0 include/mapnik/xml_tree.hpp
  25. +2 −1  plugins/input/csv/csv_datasource.cpp
  26. +1 −1  plugins/input/gdal/gdal_datasource.cpp
  27. +1 −1  plugins/input/geos/geos_datasource.cpp
  28. +1 −1  plugins/input/kismet/kismet_datasource.cpp
  29. +1 −1  plugins/input/occi/occi_datasource.cpp
  30. +1 −1  plugins/input/ogr/ogr_datasource.cpp
  31. +1 −1  plugins/input/postgis/postgis_datasource.cpp
  32. +1 −1  plugins/input/rasterlite/rasterlite_datasource.cpp
  33. +1 −1  plugins/input/sqlite/sqlite_datasource.cpp
  34. +0 −1  src/agg/agg_renderer.cpp
  35. +9 −1 src/build.py
  36. +0 −1  src/cairo_renderer.cpp
  37. +96 −0 src/color.cpp
  38. +55 −0 src/config_error.cpp
  39. +1 −0  src/expression.cpp
  40. +6 −5 src/formatting/base.cpp
  41. +5 −4 src/formatting/expression.cpp
  42. +13 −12 src/formatting/format.cpp
  43. +6 −3 src/formatting/registry.cpp
  44. +3 −7 src/formatting/text.cpp
  45. +0 −1  src/grid/grid_renderer.cpp
  46. +45 −68 src/libxml2_loader.cpp
  47. +355 −680 src/load_map.cpp
  48. +14 −11 src/metawriter_factory.cpp
  49. +1 −0  src/palette.cpp
  50. +25 −1 src/processed_text.cpp
  51. +171 −0 src/rapidxml_loader.cpp
  52. +1 −0  src/svg_parser.cpp
  53. +10 −6 src/text_placements/list.cpp
  54. +3 −2 src/text_placements/registry.cpp
  55. +3 −2 src/text_placements/simple.cpp
  56. +37 −35 src/text_properties.cpp
  57. +483 −0 src/xml_tree.cpp
  58. +5 −1 tests/visual_tests/compare.py
  59. +1 −1  tests/visual_tests/shieldsymbolizer-1.xml
  60. +1 −1  tests/visual_tests/test.py
View
90 include/mapnik/boolean.hpp
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ *
+ * This file is part of Mapnik (c++ mapping toolkit)
+ *
+ * Copyright (C) 2011 Artem Pavlenko
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *****************************************************************************/
+#ifndef MAPNIK_BOOLEAN_HPP
+#define MAPNIK_BOOLEAN_HPP
+#include <istream>
+
+namespace mapnik
+{
+/** Helper for class bool */
+class boolean {
+public:
+ boolean(): b_(false) {}
+ boolean(bool b) : b_(b) {}
+ boolean(boolean const& b) : b_(b.b_) {}
+
+ operator bool() const
+ {
+ return b_;
+ }
+ boolean & operator = (boolean const& other)
+ {
+ b_ = other.b_;
+ return * this;
+ }
+ boolean & operator = (bool other)
+ {
+ b_ = other;
+ return * this;
+ }
+private:
+ bool b_;
+};
+
+/** Special stream input operator for boolean values */
+template <typename charT, typename traits>
+std::basic_istream<charT, traits> &
+operator >> ( std::basic_istream<charT, traits> & s, boolean & b )
+{
+ std::string word;
+ s >> word;
+ if ( s )
+ {
+ if ( word == "true" || word == "yes" || word == "on" ||
+ word == "1")
+ {
+ b = true;
+ }
+ else if ( word == "false" || word == "no" || word == "off" ||
+ word == "0")
+ {
+ b = false;
+ }
+ else
+ {
+ s.setstate( std::ios::failbit );
+ }
+ }
+ return s;
+}
+
+template <typename charT, typename traits>
+std::basic_ostream<charT, traits> &
+operator << ( std::basic_ostream<charT, traits> & s, boolean const& b )
+{
+ s << ( b ? "true" : "false" );
+ return s;
+}
+
+}
+
+#endif // MAPNIK_BOOLEAN_HPP
View
8 include/mapnik/color.hpp
@@ -137,6 +137,14 @@ class MAPNIK_DECL color
std::string to_hex_string() const;
};
+template <typename charT, typename traits>
+std::basic_ostream<charT, traits> &
+operator << ( std::basic_ostream<charT, traits> & s, mapnik::color const& c )
+{
+ std::string hex_string( c.to_string() );
+ s << hex_string;
+ return s;
+}
}
View
120 include/mapnik/color_factory.hpp
@@ -25,134 +25,26 @@
// mapnik
#include <mapnik/config.hpp>
-#include <mapnik/color.hpp>
-#include <mapnik/config_error.hpp>
// boost
#include <boost/utility.hpp>
-#include <boost/version.hpp>
-
-// boost 1.41 -> 1.44 compatibility, to be removed in mapnik 2.1 (dane)
-#if BOOST_VERSION >= 104500
-#include <mapnik/css_color_grammar.hpp>
namespace mapnik {
-class MAPNIK_DECL color_factory : boost::noncopyable
-{
-public:
-
- static void init_from_string(color & c, std::string const& css_color)
- {
- typedef std::string::const_iterator iterator_type;
- typedef mapnik::css_color_grammar<iterator_type> css_color_grammar;
-
- css_color_grammar g;
- iterator_type first = css_color.begin();
- iterator_type last = css_color.end();
- bool result =
- boost::spirit::qi::phrase_parse(first,
- last,
- g,
- boost::spirit::ascii::space,
- c);
- if (!result)
- {
- throw config_error(std::string("Failed to parse color value: ") +
- "Expected a CSS color, but got '" + css_color + "'");
- }
- }
-
- static bool parse_from_string(color & c, std::string const& css_color,
- mapnik::css_color_grammar<std::string::const_iterator> const& g)
- {
- std::string::const_iterator first = css_color.begin();
- std::string::const_iterator last = css_color.end();
- bool result =
- boost::spirit::qi::phrase_parse(first,
- last,
- g,
- boost::spirit::ascii::space,
- c);
- return result && (first == last);
- }
-
- static color from_string(std::string const& css_color)
- {
- color c;
- init_from_string(c,css_color);
- return c;
- }
-};
-}
-
-#else
-#include <mapnik/css_color_grammar_deprecated.hpp>
-
-namespace mapnik {
+class color;
+template <typename Iterator> struct css_color_grammar;
class MAPNIK_DECL color_factory : boost::noncopyable
{
public:
- static bool parse_from_string(color & c, std::string const& css_color,
- mapnik::css_color_grammar<std::string::const_iterator> const& g)
- {
- std::string::const_iterator first = css_color.begin();
- std::string::const_iterator last = css_color.end();
- mapnik::css css_;
- bool result =
- boost::spirit::qi::phrase_parse(first,
- last,
- g,
- boost::spirit::ascii::space,
- css_);
- if (result && (first == last))
- {
- c.set_red(css_.r);
- c.set_green(css_.g);
- c.set_blue(css_.b);
- c.set_alpha(css_.a);
- return true;
- }
- return false;
- }
-
- static void init_from_string(color & c, std::string const& css_color)
- {
- typedef std::string::const_iterator iterator_type;
- typedef mapnik::css_color_grammar<iterator_type> css_color_grammar;
+ static void init_from_string(color & c, std::string const& css_color);
- css_color_grammar g;
- iterator_type first = css_color.begin();
- iterator_type last = css_color.end();
- mapnik::css css_;
- bool result =
- boost::spirit::qi::phrase_parse(first,
- last,
- g,
- boost::spirit::ascii::space,
- css_);
- if (!result)
- {
- throw config_error(std::string("Failed to parse color value: ") +
- "Expected a CSS color, but got '" + css_color + "'");
- }
- c.set_red(css_.r);
- c.set_green(css_.g);
- c.set_blue(css_.b);
- c.set_alpha(css_.a);
- }
+ static bool parse_from_string(color & c, std::string const& css_color,
+ mapnik::css_color_grammar<std::string::const_iterator> const& g);
- static color from_string(std::string const& css_color)
- {
- color c;
- init_from_string(c,css_color);
- return c;
- }
+ static color from_string(std::string const& css_color);
};
}
-#endif
-
#endif // MAPNIK_COLOR_FACTORY_HPP
View
29 include/mapnik/config_error.hpp
@@ -28,31 +28,28 @@
namespace mapnik {
+class xml_node;
class config_error : public std::exception
{
public:
- config_error():
- what_() {}
-
- config_error( std::string const& what ) :
- what_( what )
- {
- }
+ config_error(std::string const& what);
+ config_error(std::string const& what, xml_node const& node);
+ config_error(std::string const& what, unsigned line_number, std::string const& filename);
virtual ~config_error() throw() {}
- virtual const char * what() const throw()
- {
- return what_.c_str();
- }
-
- void append_context(std::string const& ctx) const
- {
- what_ += " " + ctx;
- }
+ virtual const char * what() const throw();
+ void append_context(const std::string & ctx) const;
+ void append_context(const std::string & ctx, xml_node const& node) const;
+ void append_context(xml_node const& node) const;
protected:
mutable std::string what_;
+ mutable unsigned line_number_;
+ mutable std::string file_;
+ mutable std::string node_name_;
+ mutable std::string msg_;
};
+
}
#endif // MAPNIK_CONFIG_ERROR_HPP
View
2  include/mapnik/expression.hpp
@@ -26,7 +26,6 @@
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/expression_node.hpp>
-#include <mapnik/expression_grammar.hpp>
// stl
#include <string>
@@ -35,6 +34,7 @@ namespace mapnik
{
typedef boost::shared_ptr<expr_node> expression_ptr;
+template <typename Iterator> struct expression_grammar;
class expression_factory
{
View
3  include/mapnik/formatting/base.hpp
@@ -36,6 +36,7 @@ namespace mapnik {
typedef std::set<expression_ptr> expression_set;
class processed_text;
+class xml_node;
struct char_properties;
namespace formatting {
@@ -48,7 +49,7 @@ class node
public:
virtual ~node() {}
virtual void to_xml(boost::property_tree::ptree &xml) const;
- static node_ptr from_xml(boost::property_tree::ptree const& xml);
+ static node_ptr from_xml(xml_node const& xml);
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const = 0;
virtual void add_expressions(expression_set &output) const;
};
View
4 include/mapnik/formatting/expression.hpp
@@ -31,7 +31,7 @@ namespace formatting {
class expression_format: public node {
public:
void to_xml(boost::property_tree::ptree &xml) const;
- static node_ptr from_xml(boost::property_tree::ptree const& xml);
+ static node_ptr from_xml(xml_node const& xml);
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const;
virtual void add_expressions(expression_set &output) const;
@@ -51,7 +51,7 @@ class expression_format: public node {
private:
node_ptr child_;
- static expression_ptr get_expression(boost::property_tree::ptree const& xml, std::string name);
+ static expression_ptr get_expression(xml_node const& xml, std::string name);
};
} //ns formatting
} //ns mapnik
View
2  include/mapnik/formatting/format.hpp
@@ -31,7 +31,7 @@ namespace formatting {
class format_node: public node {
public:
void to_xml(boost::property_tree::ptree &xml) const;
- static node_ptr from_xml(boost::property_tree::ptree const& xml);
+ static node_ptr from_xml(xml_node const& xml);
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const;
virtual void add_expressions(expression_set &output) const;
View
4 include/mapnik/formatting/registry.hpp
@@ -38,7 +38,7 @@ namespace mapnik
namespace formatting
{
-typedef node_ptr (*from_xml_function_ptr)(boost::property_tree::ptree const& xml);
+typedef node_ptr (*from_xml_function_ptr)(xml_node const& xml);
class registry : public singleton<registry, CreateStatic>,
private boost::noncopyable
@@ -47,7 +47,7 @@ class registry : public singleton<registry, CreateStatic>,
registry();
~registry() {}
void register_name(std::string name, from_xml_function_ptr ptr, bool overwrite=false);
- node_ptr from_xml(std::string name, boost::property_tree::ptree const& xml);
+ node_ptr from_xml(xml_node const& xml);
private:
std::map<std::string, from_xml_function_ptr> map_;
};
View
2  include/mapnik/formatting/text.hpp
@@ -31,7 +31,7 @@ class text_node: public node {
text_node(expression_ptr text): node(), text_(text) {}
text_node(std::string text): node(), text_(parse_expression(text)) {}
void to_xml(boost::property_tree::ptree &xml) const;
- static node_ptr from_xml(boost::property_tree::ptree const& xml);
+ static node_ptr from_xml(xml_node const& xml);
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const;
virtual void add_expressions(expression_set &output) const;
View
26 include/mapnik/internal/dump_xml.hpp
@@ -1,26 +1,34 @@
#ifndef DUMP_XML_HPP
#define DUMP_XML_HPP
-#include <boost/property_tree/ptree.hpp>
+#include <mapnik/xml_node.hpp>
/* Debug dump ptree XML representation.
*/
-void dump_xml(boost::property_tree::ptree const& xml, unsigned level=0)
+void dump_xml(xml_node const& xml, unsigned level=0)
{
std::string indent;
- int i;
+ unsigned i;
for (i=0; i<level; i++)
{
indent += " ";
}
- if (xml.data().length()) std::cout << indent << "data: '" << xml.data() << "'\n";
- boost::property_tree::ptree::const_iterator itr = xml.begin();
- boost::property_tree::ptree::const_iterator end = xml.end();
+ xml_node::attribute_map const& attr = xml.get_attributes();
+ std::cerr << indent <<"[" << xml.name();
+ xml_node::attribute_map::const_iterator aitr = attr.begin();
+ xml_node::attribute_map::const_iterator aend = attr.end();
+ for (;aitr!=aend; aitr++)
+ {
+ std::cerr << " (" << aitr->first << ", " << aitr->second.value << ", " << aitr->second.processed << ")";
+ }
+ std::cerr << "]" << "\n";
+ if (xml.is_text()) std::cerr << indent << "text: '" << xml.text() << "'\n";
+ xml_node::const_iterator itr = xml.begin();
+ xml_node::const_iterator end = xml.end();
for (; itr!=end; itr++)
{
- std::cout << indent <<"[" << itr->first << "]" << "\n";
- dump_xml(itr->second, level+1);
- std::cout << indent << "[/" << itr->first << "]" << "\n";
+ dump_xml(*itr, level+1);
}
+ std::cerr << indent << "[/" << xml.name() << "]" << "\n";
}
View
3  include/mapnik/metawriter_factory.hpp
@@ -30,6 +30,7 @@
#include <boost/property_tree/ptree.hpp>
namespace mapnik {
+class xml_node;
/**
* Creates a metawriter with the properties specified in the property
@@ -37,7 +38,7 @@ namespace mapnik {
* metawriters, but should provide an easy point to make them a
* proper factory method if this is wanted in the future.
*/
-metawriter_ptr metawriter_create(const boost::property_tree::ptree &pt);
+metawriter_ptr metawriter_create(xml_node const& pt);
/**
* Writes properties into the given property tree representing the
View
1  include/mapnik/palette.hpp
@@ -26,7 +26,6 @@
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/global.hpp>
-#include <mapnik/config_error.hpp>
// boost
#include <boost/utility.hpp>
View
433 include/mapnik/ptree_helpers.hpp
@@ -23,450 +23,17 @@
#ifndef MAPNIK_PTREE_HELPERS_HPP
#define MAPNIK_PTREE_HELPERS_HPP
-// mapnik
-#include <mapnik/enumeration.hpp>
-#include <mapnik/config_error.hpp>
-#include <mapnik/color_factory.hpp>
-#include <mapnik/util/conversions.hpp>
// boost
#include <boost/property_tree/ptree.hpp>
-#include <boost/optional.hpp>
-#include <boost/lexical_cast.hpp>
-
-// stl
-#include <iostream>
-#include <sstream>
namespace mapnik {
template <typename T>
-inline boost::optional<T> fast_cast(std::string const& value);
-
-template <typename T>
-T get(boost::property_tree::ptree const& node, std::string const& name, bool is_attribute,
- T const& default_value);
-template <typename T>
-T get(boost::property_tree::ptree const& node, std::string const& name, bool is_attribute);
-template <typename T>
-T get_value(boost::property_tree::ptree const& node, std::string const& name);
-template <typename T>
-boost::optional<T> get_optional(boost::property_tree::ptree const& node, std::string const& name,
- bool is_attribute);
-
-template <typename T>
-boost::optional<T> get_opt_attr( boost::property_tree::ptree const& node,
- std::string const& name)
-{
- return get_optional<T>( node, name, true);
-}
-
-template <typename T>
-boost::optional<T> get_opt_child( boost::property_tree::ptree const& node,
- std::string const& name)
-{
- return get_optional<T>( node, name, false);
-}
-
-template <typename T>
-T get_attr( boost::property_tree::ptree const& node, std::string const& name,
- T const& default_value )
-{
- return get<T>( node, name, true, default_value);
-}
-
-template <typename T>
-T get_attr( boost::property_tree::ptree const& node, std::string const& name )
-{
- return get<T>( node, name, true );
-}
-
-
-template <typename charT, typename traits>
-std::basic_ostream<charT, traits> &
-operator << ( std::basic_ostream<charT, traits> & s, mapnik::color const& c )
-{
- std::string hex_string( c.to_string() );
- s << hex_string;
- return s;
-}
-
-/** Helper for class bool */
-class boolean {
-public:
- boolean() : b_(false) {}
- boolean(bool b) : b_(b) {}
- boolean(boolean const& b) : b_(b.b_) {}
-
- operator bool() const
- {
- return b_;
- }
- boolean & operator = (boolean const& other)
- {
- b_ = other.b_;
- return * this;
- }
- boolean & operator = (bool other)
- {
- b_ = other;
- return * this;
- }
-private:
- bool b_;
-};
-
-/** Special stream input operator for boolean values */
-template <typename charT, typename traits>
-std::basic_istream<charT, traits> &
-operator >> ( std::basic_istream<charT, traits> & s, boolean & b )
-{
- std::string word;
- s >> word;
- if ( s )
- {
- if ( word == "true" || word == "yes" || word == "on" ||
- word == "1")
- {
- b = true;
- }
- else if ( word == "false" || word == "no" || word == "off" ||
- word == "0")
- {
- b = false;
- }
- else
- {
- s.setstate( std::ios::failbit );
- }
- }
- return s;
-}
-
-template <typename charT, typename traits>
-std::basic_ostream<charT, traits> &
-operator << ( std::basic_ostream<charT, traits> & s, boolean const& b )
-{
- s << ( b ? "true" : "false" );
- return s;
-}
-
-template <typename T>
void set_attr(boost::property_tree::ptree & pt, std::string const& name, T const& v)
{
pt.put("<xmlattr>." + name, v);
}
-
-class boolean;
-
-template <typename T>
-struct name_trait
-{
- static std::string name()
- {
- return "<unknown>";
- }
- // missing name_trait for type ...
- // if you get here you are probably using a new type
- // in the XML file. Just add a name trait for the new
- // type below.
- BOOST_STATIC_ASSERT( sizeof(T) == 0 );
-};
-
-#define DEFINE_NAME_TRAIT( type, type_name ) \
- template <> \
- struct name_trait<type> \
- { \
- static std::string name() { return std::string("type ") + type_name; } \
- };
-
-
-DEFINE_NAME_TRAIT( double, "double")
-DEFINE_NAME_TRAIT( float, "float")
-DEFINE_NAME_TRAIT( unsigned, "unsigned")
-DEFINE_NAME_TRAIT( boolean, "boolean")
-DEFINE_NAME_TRAIT( int, "integer" )
-DEFINE_NAME_TRAIT( std::string, "string" )
-DEFINE_NAME_TRAIT( color, "color" )
-
-template <typename ENUM, int MAX>
-struct name_trait< mapnik::enumeration<ENUM, MAX> >
-{
- typedef enumeration<ENUM, MAX> Enum;
-
- static std::string name()
- {
- std::string value_list("one of [");
- for (unsigned i = 0; i < Enum::MAX; ++i)
- {
- value_list += Enum::get_string( i );
- if ( i + 1 < Enum::MAX ) value_list += ", ";
- }
- value_list += "]";
-
- return value_list;
- }
-};
-
-template <typename T>
-inline boost::optional<T> fast_cast(std::string const& value)
-{
- try
- {
- return boost::lexical_cast<T>( value );
- }
- catch (boost::bad_lexical_cast const& ex)
- {
- return boost::optional<T>();
- }
-
-}
-
-template <>
-inline boost::optional<int> fast_cast(std::string const& value)
-{
- int result;
- if (mapnik::conversions::string2int(value,result))
- return boost::optional<int>(result);
- return boost::optional<int>();
-}
-
-template <>
-inline boost::optional<double> fast_cast(std::string const& value)
-{
- double result;
- if (mapnik::conversions::string2double(value,result))
- return boost::optional<double>(result);
- return boost::optional<double>();
-}
-
-template <>
-inline boost::optional<float> fast_cast(std::string const& value)
-{
- float result;
- if (mapnik::conversions::string2float(value,result))
- return boost::optional<float>(result);
- return boost::optional<float>();
-}
-
-template <typename T>
-T get(boost::property_tree::ptree const& node,
- std::string const& name,
- bool is_attribute,
- T const& default_value)
-{
- boost::optional<std::string> str;
- if (is_attribute)
- {
- str = node.get_optional<std::string>( std::string("<xmlattr>.") + name );
- }
- else
- {
- str = node.get_optional<std::string>(name + ".<xmltext>");
- }
-
- if ( str )
- {
- boost::optional<T> result = fast_cast<T>(*str);
- if (result)
- {
- return *result;
- }
- else
- {
- throw config_error(std::string("Failed to parse ") +
- (is_attribute ? "attribute" : "child node") + " '" +
- name + "'. Expected " + name_trait<T>::name() +
- " but got '" + *str + "'");
- }
- }
- else
- {
- return default_value;
- }
-}
-
-template <>
-inline color get(boost::property_tree::ptree const& node,
- std::string const& name,
- bool is_attribute,
- color const& default_value)
-{
- boost::optional<std::string> str;
- if (is_attribute)
- {
- str = node.get_optional<std::string>( std::string("<xmlattr>.") + name );
- }
- else
- {
- str = node.get_optional<std::string>(name + ".<xmltext>");
- }
-
- if ( str )
- {
- try
- {
- return mapnik::color_factory::from_string((*str).c_str());
- }
- catch (...)
- {
- throw config_error(std::string("Failed to parse ") +
- (is_attribute ? "attribute" : "child node") + " '" +
- name + "'. Expected " + name_trait<color>::name() +
- " but got '" + *str + "'");
- }
- }
- else
- {
- return default_value;
- }
-}
-
-template <typename T>
-T get(boost::property_tree::ptree const& node, std::string const& name, bool is_attribute)
-{
- boost::optional<std::string> str;
- if (is_attribute)
- {
- str = node.get_optional<std::string>( std::string("<xmlattr>.") + name);
- }
- else
- {
- str = node.get_optional<std::string>(name + ".<xmltext>");
- }
-
- if ( ! str )
- {
- throw config_error(std::string("Required ") +
- (is_attribute ? "attribute " : "child node ") +
- "'" + name + "' is missing");
- }
- boost::optional<T> result = fast_cast<T>(*str);
- if (result)
- {
- return *result;
- }
- else
- {
- throw config_error(std::string("Failed to parse ") +
- (is_attribute ? "attribute" : "child node") + " '" +
- name + "'. Expected " + name_trait<T>::name() +
- " but got '" + *str + "'");
- }
-}
-
-template <typename T>
-T get_value(boost::property_tree::ptree const& node, std::string const& name)
-{
- try
- {
- /* NOTE: get_child works as long as there is only one child with that name.
- If this function is used this used this condition must always be satisfied.
- */
- return node.get_child("<xmltext>").get_value<T>();
- }
- catch (boost::property_tree::ptree_bad_path)
- {
- /* If the XML parser did not find any non-empty data element the is no
- <xmltext> node. But we don't want to fail here but simply return a
- default constructed value of the requested type.
- */
- return T();
- }
- catch (...)
- {
- throw config_error(std::string("Failed to parse ") +
- name + ". Expected " + name_trait<T>::name() +
- " but got '" + node.data() + "'");
- }
-}
-
-template <typename T>
-boost::optional<T> get_optional(boost::property_tree::ptree const& node,
- std::string const& name,
- bool is_attribute)
-{
- boost::optional<std::string> str;
- if (is_attribute)
- {
- str = node.get_optional<std::string>( std::string("<xmlattr>.") + name);
- }
- else
- {
- str = node.get_optional<std::string>(name + ".<xmltext>");
- }
-
- boost::optional<T> result;
- if ( str )
- {
- result = fast_cast<T>(*str);
- if (!result)
- {
- throw config_error(std::string("Failed to parse ") +
- (is_attribute ? "attribute" : "child node") + " '" +
- name + "'. Expected " + name_trait<T>::name() +
- " but got '" + *str + "'");
- }
- }
-
- return result;
-}
-
-template <>
-inline boost::optional<std::string> get_optional(boost::property_tree::ptree const& node,
- std::string const& name,
- bool is_attribute)
-{
- if (is_attribute)
- {
- return node.get_optional<std::string>( std::string("<xmlattr>.") + name);
- }
- else
- {
- return node.get_optional<std::string>(name + ".<xmltext>");
- }
-}
-
-template <>
-inline boost::optional<color> get_optional(boost::property_tree::ptree const& node,
- std::string const& name,
- bool is_attribute)
-{
- boost::optional<std::string> str;
- if (is_attribute)
- {
- str = node.get_optional<std::string>( std::string("<xmlattr>.") + name);
- }
- else
- {
- str = node.get_optional<std::string>(name + ".<xmltext>");
- }
-
- boost::optional<color> result;
- if ( str )
- {
- try
- {
- result = mapnik::color_factory::from_string((*str).c_str());
- }
- catch (...)
- {
- throw config_error(std::string("Failed to parse ") +
- (is_attribute ? "attribute" : "child node") + " '" +
- name + "'. Expected " + name_trait<color>::name() +
- " but got '" + *str + "'");
- }
- }
-
- return result;
-}
-
-static inline bool has_child(boost::property_tree::ptree const& node, std::string const& name)
-{
- boost::optional<std::string> str = node.get_optional<std::string>(name);
- return str;
-}
-
} // end of namespace mapnik
#endif // MAPNIK_PTREE_HELPERS_HPP
View
1  include/mapnik/raster_colorizer.hpp
@@ -39,7 +39,6 @@
// mapnik
#include <mapnik/config.hpp>
-#include <mapnik/config_error.hpp>
#include <mapnik/color.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/enumeration.hpp>
View
2  include/mapnik/symbolizer_helpers.hpp
@@ -65,11 +65,11 @@ class text_symbolizer_helper
detector_(detector),
writer_(sym.get_metawriter()),
dims_(0, 0, width, height),
+ query_extent_(query_extent),
text_(font_manager, scale_factor),
angle_(0.0),
placement_valid_(false),
points_on_line_(false),
- query_extent_(query_extent),
finder_()
{
initialize_geometries();
View
2  include/mapnik/text_placements/list.hpp
@@ -38,7 +38,7 @@ class text_placements_list: public text_placements
text_symbolizer_properties & add();
text_symbolizer_properties & get(unsigned i);
unsigned size() const;
- static text_placements_ptr from_xml(boost::property_tree::ptree const &xml, fontset_map const & fontsets);
+ static text_placements_ptr from_xml(xml_node const &xml, fontset_map const & fontsets);
private:
std::vector<text_symbolizer_properties> list_;
friend class text_placement_info_list;
View
4 include/mapnik/text_placements/registry.hpp
@@ -39,7 +39,7 @@ namespace placements
{
typedef text_placements_ptr (*from_xml_function_ptr)(
- boost::property_tree::ptree const& xml, fontset_map const & fontsets);
+ xml_node const& xml, fontset_map const & fontsets);
class registry : public singleton<registry, CreateStatic>,
private boost::noncopyable
@@ -49,7 +49,7 @@ class registry : public singleton<registry, CreateStatic>,
~registry() {}
void register_name(std::string name, from_xml_function_ptr ptr, bool overwrite=false);
text_placements_ptr from_xml(std::string name,
- boost::property_tree::ptree const& xml,
+ xml_node const& xml,
fontset_map const & fontsets);
private:
std::map<std::string, from_xml_function_ptr> map_;
View
2  include/mapnik/text_placements/simple.hpp
@@ -52,7 +52,7 @@ class text_placements_simple: public text_placements
text_placement_info_ptr get_placement_info(double scale_factor) const;
void set_positions(std::string positions);
std::string get_positions();
- static text_placements_ptr from_xml(boost::property_tree::ptree const &xml, fontset_map const & fontsets);
+ static text_placements_ptr from_xml(xml_node const &xml, fontset_map const & fontsets);
private:
std::string positions_;
std::vector<directions_t> direction_;
View
4 include/mapnik/text_properties.hpp
@@ -54,7 +54,7 @@ struct char_properties
{
char_properties();
/** Construct object from XML. */
- void from_xml(boost::property_tree::ptree const &sym, fontset_map const & fontsets);
+ void from_xml(xml_node const &sym, fontset_map const & fontsets);
/** Write object to XML ptree. */
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, char_properties const& dfl=char_properties()) const;
std::string face_name;
@@ -124,7 +124,7 @@ struct text_symbolizer_properties
{
text_symbolizer_properties();
/** Load all values from XML ptree. */
- void from_xml(boost::property_tree::ptree const &sym, fontset_map const & fontsets);
+ void from_xml(xml_node const &sym, fontset_map const & fontsets);
/** Save all values to XML ptree (but does not create a new parent node!). */
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, text_symbolizer_properties const &dfl=text_symbolizer_properties()) const;
View
1  include/mapnik/value.hpp
@@ -26,7 +26,6 @@
// mapnik
#include <mapnik/global.hpp>
#include <mapnik/unicode.hpp>
-#include <mapnik/config_error.hpp>
// boost
#include <boost/variant.hpp>
View
8 include/mapnik/libxml2_loader.hpp → include/mapnik/xml_loader.hpp
@@ -23,16 +23,14 @@
#ifndef MAPNIK_LIBXML2_LOADER_HPP
#define MAPNIK_LIBXML2_LOADER_HPP
-// boost
-#include <boost/property_tree/ptree.hpp>
-
// stl
#include <string>
namespace mapnik
{
-void read_xml2( std::string const & filename, boost::property_tree::ptree & pt);
-void read_xml2_string( std::string const & str, boost::property_tree::ptree & pt, std::string const & base_path="");
+class xml_node;
+void read_xml(std::string const & filename, xml_node &node);
+void read_xml_string(std::string const & str, xml_node &node, std::string const & base_path="");
}
#endif // MAPNIK_LIBXML2_LOADER_HPP
View
137 include/mapnik/xml_node.hpp
@@ -0,0 +1,137 @@
+/*****************************************************************************
+ *
+ * This file is part of Mapnik (c++ mapping toolkit)
+ *
+ * Copyright (C) 2012 Artem Pavlenko
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *****************************************************************************/
+
+#ifndef MAPNIK_XML_NODE_H
+#define MAPNIK_XML_NODE_H
+
+//mapnik
+#include <mapnik/boolean.hpp>
+
+
+//boost
+#include <boost/optional.hpp>
+
+//stl
+#include <list>
+#include <string>
+#include <map>
+#include <exception>
+
+namespace mapnik
+{
+class xml_tree;
+
+class xml_attribute
+{
+public:
+ xml_attribute(std::string const& value);
+ std::string value;
+ mutable bool processed;
+};
+
+class node_not_found: public std::exception
+{
+public:
+ node_not_found(std::string node_name);
+ virtual const char* what() const throw();
+ ~node_not_found() throw ();
+private:
+ std::string node_name_;
+};
+
+class attribute_not_found: public std::exception
+{
+public:
+ attribute_not_found(std::string const& node_name, std::string const& attribute_name);
+ virtual const char* what() const throw();
+ ~attribute_not_found() throw ();
+private:
+ std::string node_name_;
+ std::string attribute_name_;
+};
+
+class more_than_one_child: public std::exception
+{
+public:
+ more_than_one_child(std::string const& node_name);
+ virtual const char* what() const throw();
+ ~more_than_one_child() throw ();
+private:
+ std::string node_name_;
+};
+
+class xml_node
+{
+public:
+ typedef std::list<xml_node>::const_iterator const_iterator;
+ typedef std::map<std::string, xml_attribute> attribute_map;
+ xml_node(xml_tree &tree, std::string name, unsigned line=0, bool text_node = false);
+
+ std::string const& name() const;
+ std::string const& text() const;
+ std::string const& filename() const;
+ bool is_text() const;
+ bool is(std::string const& name) const;
+
+ xml_node &add_child(std::string const& name, unsigned line=0, bool text_node = false);
+ void add_attribute(std::string const& name, std::string const& value);
+ attribute_map const& get_attributes() const;
+
+ bool processed() const;
+ void set_processed(bool processed) const;
+
+ unsigned line() const;
+
+ const_iterator begin() const;
+ const_iterator end() const;
+
+ xml_node & get_child(std::string const& name);
+ xml_node const& get_child(std::string const& name) const;
+ xml_node const* get_opt_child(std::string const& name) const;
+ bool has_child(std::string const& name) const;
+
+ template <typename T>
+ boost::optional<T> get_opt_attr(std::string const& name) const;
+
+ template <typename T>
+ T get_attr(std::string const& name, T const& default_value) const;
+ template <typename T>
+ T get_attr(std::string const& name) const;
+
+ std::string get_text() const;
+
+ template <typename T>
+ T get_value() const;
+private:
+ xml_tree &tree_;
+ std::string name_;
+ std::list<xml_node> children_;
+ attribute_map attributes_;
+ bool text_node_;
+ unsigned line_;
+ mutable bool processed_;
+ static std::string xml_text;
+};
+
+} //ns mapnik
+
+#endif // MAPNIK_XML_NODE_H
View
54 include/mapnik/xml_tree.hpp
@@ -0,0 +1,54 @@
+/*****************************************************************************
+ *
+ * This file is part of Mapnik (c++ mapping toolkit)
+ *
+ * Copyright (C) 2012 Artem Pavlenko
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *****************************************************************************/
+
+#ifndef MAPNIK_XML_TREE_H
+#define MAPNIK_XML_TREE_H
+//mapnik
+#include <mapnik/xml_node.hpp>
+#include <mapnik/expression_grammar.hpp>
+#include <mapnik/css_color_grammar.hpp>
+
+//stl
+#include <string>
+
+
+namespace mapnik
+{
+class xml_tree
+{
+public:
+ xml_tree(std::string const& encoding="utf8");
+ void set_filename(std::string fn);
+ std::string const& filename() const;
+ xml_node &root();
+private:
+ xml_node node_;
+ std::string file_;
+ transcoder tr_;
+public:
+ mapnik::css_color_grammar<std::string::const_iterator> color_grammar;
+ mapnik::expression_grammar<std::string::const_iterator> expr_grammar;
+};
+
+} //ns mapnik
+
+#endif // MAPNIK_XML_TREE_H
View
3  plugins/input/csv/csv_datasource.cpp
@@ -6,6 +6,7 @@
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
// mapnik
#include <mapnik/feature_layer_desc.hpp>
@@ -14,7 +15,7 @@
#include <mapnik/memory_featureset.hpp>
#include <mapnik/wkt/wkt_factory.hpp>
#include <mapnik/util/geometry_to_ds_type.hpp>
-#include <mapnik/ptree_helpers.hpp> // mapnik::boolean
+#include <mapnik/boolean.hpp>
// stl
#include <sstream>
View
2  plugins/input/gdal/gdal_datasource.cpp
@@ -25,7 +25,7 @@
#include "gdal_featureset.hpp"
// mapnik
-#include <mapnik/ptree_helpers.hpp>
+#include <mapnik/boolean.hpp>
#include <mapnik/geom_util.hpp>
#include <gdal_version.h>
View
2  plugins/input/geos/geos_datasource.cpp
@@ -30,7 +30,7 @@
#include <cstdarg>
// mapnik
-#include <mapnik/ptree_helpers.hpp>
+#include <mapnik/boolean.hpp>
#include <mapnik/geom_util.hpp>
// boost
View
2  plugins/input/kismet/kismet_datasource.cpp
@@ -33,7 +33,7 @@
#include <cstdio>
// mapnik
-#include <mapnik/ptree_helpers.hpp>
+#include <mapnik/boolean.hpp>
// boost
#include <boost/algorithm/string.hpp>
View
2  plugins/input/occi/occi_datasource.cpp
@@ -25,7 +25,7 @@
#include "occi_featureset.hpp"
// mapnik
-#include <mapnik/ptree_helpers.hpp>
+#include <mapnik/boolean.hpp>
#include <mapnik/sql_utils.hpp>
// boost
View
2  plugins/input/ogr/ogr_datasource.cpp
@@ -33,7 +33,7 @@
#include <gdal_version.h>
// mapnik
-#include <mapnik/ptree_helpers.hpp>
+#include <mapnik/boolean.hpp>
#include <mapnik/geom_util.hpp>
// boost
View
2  plugins/input/postgis/postgis_datasource.cpp
@@ -26,7 +26,7 @@
// mapnik
#include <mapnik/global.hpp>
-#include <mapnik/ptree_helpers.hpp>
+#include <mapnik/boolean.hpp>
#include <mapnik/sql_utils.hpp>
#include <mapnik/util/conversions.hpp>
View
2  plugins/input/rasterlite/rasterlite_datasource.cpp
@@ -29,7 +29,7 @@
#include <boost/make_shared.hpp>
// mapnik
-#include <mapnik/ptree_helpers.hpp>
+#include <mapnik/boolean.hpp>
#include <mapnik/geom_util.hpp>
using mapnik::datasource;
View
2  plugins/input/sqlite/sqlite_datasource.cpp
@@ -26,7 +26,7 @@
#include "sqlite_utils.hpp"
// mapnik
-#include <mapnik/ptree_helpers.hpp>
+#include <mapnik/boolean.hpp>
#include <mapnik/sql_utils.hpp>
#include <mapnik/util/geometry_to_ds_type.hpp>
#include <mapnik/wkb.hpp>
View
1  src/agg/agg_renderer.cpp
@@ -27,7 +27,6 @@
#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/unicode.hpp>
-#include <mapnik/config_error.hpp>
#include <mapnik/font_set.hpp>
#include <mapnik/parse_path.hpp>
#include <mapnik/map.hpp>
View
10 src/build.py
@@ -178,6 +178,8 @@ def ldconfig(*args,**kwargs):
text_placements/list.cpp
text_placements/simple.cpp
text_properties.cpp
+ xml_tree.cpp
+ config_error.cpp
"""
)
@@ -299,7 +301,7 @@ def ldconfig(*args,**kwargs):
env2 = lib_env.Clone()
env2.Append(CXXFLAGS = '-DHAVE_LIBXML2')
libmapnik_cxxflags.append('-DHAVE_LIBXML2')
- fixup = ['load_map.cpp','libxml2_loader.cpp']
+ fixup = ['libxml2_loader.cpp']
for cpp in fixup:
if cpp in source:
source.remove(cpp)
@@ -307,6 +309,12 @@ def ldconfig(*args,**kwargs):
source.insert(0,env2.StaticObject(cpp))
else:
source.insert(0,env2.SharedObject(cpp))
+else:
+ source += Split(
+ """
+ rapidxml_loader.cpp
+ """
+ )
if env['CUSTOM_LDFLAGS']:
linkflags = '%s %s' % (env['CUSTOM_LDFLAGS'], mapnik_lib_link_flag)
View
1  src/cairo_renderer.cpp
@@ -29,7 +29,6 @@
#include <mapnik/unicode.hpp>
#include <mapnik/markers_placement.hpp>
#include <mapnik/arrow.hpp>
-#include <mapnik/config_error.hpp>
#include <mapnik/parse_path.hpp>
#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
View
96 src/color.cpp
@@ -25,11 +25,23 @@
// mapnik
#include <mapnik/color.hpp>
#include <mapnik/color_factory.hpp>
+#include <mapnik/config_error.hpp>
+
// boost
#include <boost/format.hpp>
+#include <boost/version.hpp>
+
// stl
#include <sstream>
+// boost 1.41 -> 1.44 compatibility, to be removed in mapnik 2.1 (dane)
+#if BOOST_VERSION >= 104500
+#include <mapnik/css_color_grammar.hpp>
+#else
+#include <mapnik/css_color_grammar_deprecated.hpp>
+#endif
+
+
namespace mapnik {
color::color( std::string const& css_string)
@@ -81,5 +93,89 @@ std::string color::to_hex_string() const
}
}
+
+/****************************************************************************/
+void color_factory::init_from_string(color & c, std::string const& css_color)
+{
+ typedef std::string::const_iterator iterator_type;
+ typedef mapnik::css_color_grammar<iterator_type> css_color_grammar;
+
+ css_color_grammar g;
+ iterator_type first = css_color.begin();
+ iterator_type last = css_color.end();
+ // boost 1.41 -> 1.44 compatibility, to be removed in mapnik 2.1 (dane)
+#if BOOST_VERSION >= 104500
+ bool result =
+ boost::spirit::qi::phrase_parse(first,
+ last,
+ g,
+ boost::spirit::ascii::space,
+ c);
+ if (!result)
+ {
+ throw config_error(std::string("Failed to parse color value: ") +
+ "Expected a CSS color, but got '" + css_color + "'");
+ }
+#else
+ mapnik::css css_;
+ bool result =
+ boost::spirit::qi::phrase_parse(first,
+ last,
+ g,
+ boost::spirit::ascii::space,
+ css_);
+ if (!result)
+ {
+ throw config_error(std::string("Failed to parse color value: ") +
+ "Expected a CSS color, but got '" + css_color + "'");
+ }
+ c.set_red(css_.r);
+ c.set_green(css_.g);
+ c.set_blue(css_.b);
+ c.set_alpha(css_.a);
+#endif
+}
+
+bool color_factory::parse_from_string(color & c, std::string const& css_color,
+ mapnik::css_color_grammar<std::string::const_iterator> const& g)
+{
+ std::string::const_iterator first = css_color.begin();
+ std::string::const_iterator last = css_color.end();
+ // boost 1.41 -> 1.44 compatibility, to be removed in mapnik 2.1 (dane)
+#if BOOST_VERSION >= 104500
+ bool result =
+ boost::spirit::qi::phrase_parse(first,
+ last,
+ g,
+ boost::spirit::ascii::space,
+ c);
+ return result && (first == last);
+#else
+ mapnik::css css_;
+ bool result =
+ boost::spirit::qi::phrase_parse(first,
+ last,
+ g,
+ boost::spirit::ascii::space,
+ css_);
+ if (result && (first == last))
+ {
+ c.set_red(css_.r);
+ c.set_green(css_.g);
+ c.set_blue(css_.b);
+ c.set_alpha(css_.a);
+ return true;
+ }
+#endif
+}
+
+
+color color_factory::from_string(std::string const& css_color)
+{
+ color c;
+ init_from_string(c, css_color);
+ return c;
+}
+
}
View
55 src/config_error.cpp
@@ -0,0 +1,55 @@
+#include <mapnik/config_error.hpp>
+#include <mapnik/xml_tree.hpp>
+
+namespace mapnik
+{
+
+config_error::config_error(std::string const& what)
+ : what_(what), line_number_(0), file_(), node_name_(), msg_()
+{
+}
+
+
+config_error::config_error(std::string const& what, xml_node const& node)
+ : what_(what), line_number_(node.line()), file_(node.filename()), node_name_(node.name()), msg_()
+{
+}
+
+
+config_error::config_error(std::string const& what, unsigned line_number, std::string const& filename)
+ : what_(what), line_number_(line_number), file_(filename), node_name_(), msg_()
+{
+
+}
+
+ char const* config_error::what() const throw()
+{
+ std::stringstream s;
+ s << file_;
+ if (line_number_ > 0) s << " line " << line_number_;
+ if (!node_name_.empty()) s << " in node "<< node_name_;
+ if (line_number_ > 0 || !file_.empty()) s << ": ";
+ s << what_;
+ msg_ = s.str(); //Avoid returning pointer to dead object
+ return msg_.c_str();
+}
+
+ void config_error::append_context(std::string const& ctx) const
+ {
+ what_ += " " + ctx;
+ }
+
+void config_error::append_context(std::string const& ctx, xml_node const& node) const
+{
+ append_context(ctx);
+ append_context(node);
+}
+
+void config_error::append_context(xml_node const& node) const
+{
+ if (!line_number_) line_number_ = node.line();
+ if (node_name_.empty()) node_name_ = node.name();
+ if (file_.empty()) file_ = node.filename();
+}
+
+}
View
1  src/expression.cpp
@@ -24,6 +24,7 @@
#include <mapnik/expression.hpp>
#include <mapnik/config_error.hpp>
#include <mapnik/unicode.hpp>
+#include <mapnik/expression_grammar.hpp>
// boost
#include <boost/algorithm/string.hpp>
View
11 src/formatting/base.cpp
@@ -23,6 +23,7 @@
#include <mapnik/formatting/base.hpp>
#include <mapnik/formatting/list.hpp>
#include <mapnik/formatting/registry.hpp>
+#include <mapnik/xml_node.hpp>
// boost
#include <boost/property_tree/ptree.hpp>
@@ -38,18 +39,18 @@ void node::to_xml(boost::property_tree::ptree &xml) const
#endif
}
-node_ptr node::from_xml(boost::property_tree::ptree const& xml)
+node_ptr node::from_xml(xml_node const& xml)
{
list_node *list = new list_node();
node_ptr list_ptr(list);
- boost::property_tree::ptree::const_iterator itr = xml.begin();
- boost::property_tree::ptree::const_iterator end = xml.end();
+ xml_node::const_iterator itr = xml.begin();
+ xml_node::const_iterator end = xml.end();
for (; itr != end; ++itr) {
- if (itr->first == "<xmlcomment>" || itr->first == "<xmlattr>" || itr->first == "Placement")
+ if (itr->name() == "Placement")
{
continue;
}
- node_ptr n = registry::instance()->from_xml(itr->first, itr->second);
+ node_ptr n = registry::instance()->from_xml(*itr);
if (n) list->push_back(n);
}
if (list->get_children().size() == 1) {
View
9 src/formatting/expression.cpp
@@ -27,6 +27,7 @@
#include <mapnik/expression_evaluator.hpp>
#include <mapnik/text_properties.hpp>
#include <mapnik/feature.hpp>
+#include <mapnik/xml_node.hpp>
// boost
@@ -37,7 +38,7 @@ namespace formatting
using boost::property_tree::ptree;
void expression_format::to_xml(boost::property_tree::ptree &xml) const
{
- ptree &new_node = xml.push_back(ptree::value_type("Format", ptree()))->second;
+ ptree &new_node = xml.push_back(ptree::value_type("ExpressionFormat", ptree()))->second;
if (face_name) set_attr(new_node, "face-name", to_expression_string(*face_name));
if (text_size) set_attr(new_node, "size", to_expression_string(*text_size));
if (character_spacing) set_attr(new_node, "character-spacing", to_expression_string*character_spacing);
@@ -51,7 +52,7 @@ void expression_format::to_xml(boost::property_tree::ptree &xml) const
if (child_) child_->to_xml(new_node);
}
-node_ptr expression_format::from_xml(ptree const& xml)
+node_ptr expression_format::from_xml(xml_node const& xml)
{
expression_format *n = new expression_format();
node_ptr np(n);
@@ -72,9 +73,9 @@ node_ptr expression_format::from_xml(ptree const& xml)
return np;
}
-expression_ptr expression_format::get_expression(ptree const& xml, std::string name)
+expression_ptr expression_format::get_expression(xml_node const& xml, std::string name)
{
- boost::optional<std::string> tmp = get_opt_attr<std::string>(xml, name);
+ boost::optional<std::string> tmp = xml.get_opt_attr<std::string>(name);
if (tmp) return parse_expression(*tmp);
return expression_ptr();
}
View
25 src/formatting/format.cpp
@@ -21,6 +21,7 @@
*****************************************************************************/
#include <mapnik/formatting/format.hpp>
#include <mapnik/ptree_helpers.hpp>
+#include <mapnik/xml_node.hpp>
namespace mapnik {
using boost::property_tree::ptree;
@@ -44,7 +45,7 @@ void format_node::to_xml(ptree &xml) const
}
-node_ptr format_node::from_xml(ptree const& xml)
+node_ptr format_node::from_xml(xml_node const& xml)
{
format_node *n = new format_node();
node_ptr np(n);
@@ -52,19 +53,19 @@ node_ptr format_node::from_xml(ptree const& xml)
node_ptr child = node::from_xml(xml);
n->set_child(child);
- n->face_name = get_opt_attr<std::string>(xml, "face-name");
+ n->face_name = xml.get_opt_attr<std::string>("face-name");
/*TODO: Fontset is problematic. We don't have the fontsets pointer here... */
- n->text_size = get_opt_attr<unsigned>(xml, "size");
- n->character_spacing = get_opt_attr<unsigned>(xml, "character-spacing");
- n->line_spacing = get_opt_attr<unsigned>(xml, "line-spacing");
- n->text_opacity = get_opt_attr<double>(xml, "opactity");
- boost::optional<boolean> wrap = get_opt_attr<boolean>(xml, "wrap-before");
+ n->text_size = xml.get_opt_attr<unsigned>("size");
+ n->character_spacing = xml.get_opt_attr<unsigned>("character-spacing");
+ n->line_spacing = xml.get_opt_attr<unsigned>("line-spacing");
+ n->text_opacity = xml.get_opt_attr<double>("opactity");
+ boost::optional<boolean> wrap = xml.get_opt_attr<boolean>("wrap-before");
if (wrap) n->wrap_before = *wrap;
- n->wrap_char = get_opt_attr<unsigned>(xml, "wrap-character");
- n->text_transform = get_opt_attr<text_transform_e>(xml, "text-transform");
- n->fill = get_opt_attr<color>(xml, "fill");
- n->halo_fill = get_opt_attr<color>(xml, "halo-fill");
- n->halo_radius = get_opt_attr<double>(xml, "halo-radius");
+ n->wrap_char = xml.get_opt_attr<unsigned>("wrap-character");
+ n->text_transform = xml.get_opt_attr<text_transform_e>("text-transform");
+ n->fill = xml.get_opt_attr<color>("fill");
+ n->halo_fill = xml.get_opt_attr<color>("halo-fill");
+ n->halo_radius = xml.get_opt_attr<double>("halo-radius");
return np;
}
View
9 src/formatting/registry.cpp
@@ -24,6 +24,8 @@
#include <mapnik/formatting/text.hpp>
#include <mapnik/formatting/format.hpp>
#include <mapnik/formatting/expression.hpp>
+#include <mapnik/xml_node.hpp>
+#include <mapnik/config_error.hpp>
namespace mapnik
{
@@ -46,10 +48,11 @@ void registry::register_name(std::string name, from_xml_function_ptr ptr, bool o
}
}
-node_ptr registry::from_xml(std::string name, const boost::property_tree::ptree &xml)
+node_ptr registry::from_xml(xml_node const& xml)
{
- std::map<std::string, from_xml_function_ptr>::const_iterator itr = map_.find(name);
- if (itr == map_.end()) throw config_error("Unknown element '" + name + "'");
+ std::map<std::string, from_xml_function_ptr>::const_iterator itr = map_.find(xml.name());
+ if (itr == map_.end()) throw config_error("Unknown element '" + xml.name() + "'", xml);
+ xml.set_processed(true);
return itr->second(xml);
}
} //ns formatting
View
10 src/formatting/text.cpp
@@ -26,10 +26,7 @@
#include <mapnik/feature.hpp>
#include <mapnik/text_properties.hpp>
#include <mapnik/processed_text.hpp>
-
-// boost
-#include <boost/algorithm/string.hpp>
-#include <boost/make_shared.hpp>
+#include <mapnik/xml_node.hpp>
namespace mapnik
{
@@ -46,10 +43,9 @@ void text_node::to_xml(ptree &xml) const
}
-node_ptr text_node::from_xml(boost::property_tree::ptree const& xml)
+node_ptr text_node::from_xml(xml_node const& xml)
{
- std::string data = xml.data();
- boost::trim(data);
+ std::string data = xml.text();
if (data.empty()) return node_ptr(); //No text
return boost::make_shared<text_node>(parse_expression(data, "utf8"));
}
View
1  src/grid/grid_renderer.cpp
@@ -32,7 +32,6 @@
#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/unicode.hpp>
-#include <mapnik/config_error.hpp>
#include <mapnik/font_set.hpp>
#include <mapnik/parse_path.hpp>
#include <mapnik/map.hpp>
View
113 src/libxml2_loader.cpp
@@ -22,26 +22,27 @@
#ifdef HAVE_LIBXML2
-#include <mapnik/libxml2_loader.hpp>
-
+// mapnik
+#include <mapnik/xml_loader.hpp>
+#include <mapnik/xml_node.hpp>
#include <mapnik/config_error.hpp>
+// boost
#include <boost/utility.hpp>
-#include <boost/property_tree/ptree.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/algorithm/string/trim.hpp>
+// libxml
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/parserInternals.h>
#include <libxml/xinclude.h>
+// stl
#include <iostream>
-using boost::property_tree::ptree;
using namespace std;
-//#define DEFAULT_OPTIONS (XML_PARSE_NOENT | XML_PARSE_NOBLANKS | XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA)
#define DEFAULT_OPTIONS (XML_PARSE_NOERROR | XML_PARSE_NOENT | XML_PARSE_NOBLANKS | XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA)
namespace mapnik
@@ -50,14 +51,14 @@ class libxml2_loader : boost::noncopyable
{
public:
libxml2_loader(const char *encoding = NULL, int options = DEFAULT_OPTIONS, const char *url = NULL) :
- ctx_( 0 ),
- encoding_( encoding ),
- options_( options ),
- url_( url )
+ ctx_(0),
+ encoding_(encoding),
+ options_(options),
+ url_(url)
{
LIBXML_TEST_VERSION;
ctx_ = xmlNewParserCtxt();
- if ( ! ctx_ )
+ if (!ctx_)
{
throw std::runtime_error("Failed to create parser context.");
}
@@ -71,19 +72,19 @@ class libxml2_loader : boost::noncopyable
}
}
- void load( std::string const& filename, ptree & pt )
+ void load(std::string const& filename, xml_node &node)
{
boost::filesystem::path path(filename);
- if ( !boost::filesystem::exists( path ) ) {
- throw config_error(string("Could not load map file '") +
- filename + "': File does not exist");
+ if (!boost::filesystem::exists(path))
+ {
+ throw config_error(string("Could not load map file: File does not exist"), 0, filename);
}
xmlDocPtr doc = xmlCtxtReadFile(ctx_, filename.c_str(), encoding_, options_);
- if ( !doc )
+ if (!doc)
{
- xmlError * error = xmlCtxtGetLastError( ctx_ );
+ xmlError * error = xmlCtxtGetLastError(ctx_);
if (error)
{
std::ostringstream os;
@@ -91,15 +92,7 @@ class libxml2_loader : boost::noncopyable
os << ": " << std::endl << error->message;
// remove CR
std::string msg = os.str().substr(0, os.str().size() - 1);
- config_error ex( msg );
-
- os.str("");
- os << "(encountered in file '" << error->file << "' at line "
- << error->line << ")";
-
- ex.append_context( os.str() );
-
- throw ex;
+ throw config_error(msg, error->line, error->file);
}
}
@@ -110,21 +103,21 @@ class libxml2_loader : boost::noncopyable
<< std::endl;
}
*/
- load(doc, pt);
+ load(doc, node);
}
- void load( const int fd, ptree & pt )
+ void load(const int fd, xml_node &node)
{
xmlDocPtr doc = xmlCtxtReadFd(ctx_, fd, url_, encoding_, options_);
- load(doc, pt);
+ load(doc, node);
}
- void load_string( std::string const& buffer, ptree & pt, std::string const & base_path )
+ void load_string(std::string const& buffer, xml_node &node, std::string const & base_path)
{
if (!base_path.empty())
{
boost::filesystem::path path(base_path);
- if ( ! boost::filesystem::exists( path ) ) {
+ if (!boost::filesystem::exists(path)) {
throw config_error(string("Could not locate base_path '") +
base_path + "': file or directory does not exist");
}
@@ -132,12 +125,12 @@ class libxml2_loader : boost::noncopyable
xmlDocPtr doc = xmlCtxtReadMemory(ctx_, buffer.data(), buffer.length(), base_path.c_str(), encoding_, options_);
- load(doc, pt);
+ load(doc, node);
}
- void load( const xmlDocPtr doc, ptree & pt )
+ void load(const xmlDocPtr doc, xml_node &node)
{
- if ( !doc )
+ if (!doc)
{
xmlError * error = xmlCtxtGetLastError( ctx_ );
std::ostringstream os;
@@ -146,10 +139,10 @@ class libxml2_loader : boost::noncopyable
{
os << ": " << std::endl << error->message;
}
- throw config_error(os.str());
+ throw config_error(os.str(), error->line, error->file);
}
- int iXIncludeReturn = xmlXIncludeProcessFlags( doc, options_ );
+ int iXIncludeReturn = xmlXIncludeProcessFlags(doc, options_);
if (iXIncludeReturn < 0)
{
@@ -157,63 +150,47 @@ class libxml2_loader : boost::noncopyable
throw config_error("XML XInclude error. One or more files failed to load.");
}
- xmlNode * root = xmlDocGetRootElement( doc );
- if ( ! root ) {
+ xmlNode * root = xmlDocGetRootElement(doc);
+ if (!root) {
xmlFreeDoc(doc);
throw config_error("XML document is empty.");
}
- populate_tree( root, pt );
+ populate_tree(root, node);
xmlFreeDoc(doc);
}
private:
- void append_attributes( xmlAttr * attributes, ptree & pt)
+ void append_attributes(xmlAttr *attributes, xml_node &node)
{
- if (attributes)
+ for (; attributes; attributes = attributes->next )
{
- ptree::iterator it = pt.push_back( ptree::value_type( "<xmlattr>", ptree() ));
- ptree & attr_list = it->second;
- xmlAttr * cur_attr = attributes;
- for (; cur_attr; cur_attr = cur_attr->next )
- {
- ptree::iterator it = attr_list.push_back(
- ptree::value_type( (char*)cur_attr->name, ptree() ));
- it->second.put_value( (char*) cur_attr->children->content );
- }
+ node.add_attribute((char *)attributes->name, (char *)attributes->children->content);
}
}
- void populate_tree( xmlNode * node, ptree & pt )
+ void populate_tree(xmlNode *cur_node, xml_node &node)
{
- xmlNode * cur_node = node;
-
for (; cur_node; cur_node = cur_node->next )
{
switch (cur_node->type)
{
case XML_ELEMENT_NODE:
{
- ptree::iterator it = pt.push_back( ptree::value_type(
- (char*)cur_node->name, ptree() ));
- append_attributes( cur_node->properties, it->second);
- populate_tree( cur_node->children, it->second );
+
+ xml_node &new_node = node.add_child((char *)cur_node->name, cur_node->line, false);
+ append_attributes(cur_node->properties, new_node);
+ populate_tree(cur_node->children, new_node);
}
break;
case XML_TEXT_NODE:
{
std::string trimmed = boost::algorithm::trim_copy(std::string((char*)cur_node->content));
- if (trimmed.empty()) break;
- ptree::iterator it = pt.push_back(ptree::value_type("<xmltext>", ptree()));
- it->second.put_value(trimmed);
+ if (trimmed.empty()) break; //Don't add empty text nodes
+ node.add_child(trimmed, cur_node->line, true);
}
break;
case XML_COMMENT_NODE:
- {
- ptree::iterator it = pt.push_back(
- ptree::value_type( "<xmlcomment>", ptree() ));
- it->second.put_value( (char*) cur_node->content );
- }
break;
default:
break;
@@ -228,15 +205,15 @@ class libxml2_loader : boost::noncopyable
const char *url_;
};
-void read_xml2( std::string const & filename, boost::property_tree::ptree & pt)
+void read_xml(std::string const & filename, xml_node &node)
{
libxml2_loader loader;
- loader.load( filename, pt );
+ loader.load(filename, node);
}
-void read_xml2_string( std::string const & str, boost::property_tree::ptree & pt, std::string const & base_path)
+void read_xml_string(std::string const & str, xml_node &node, std::string const & base_path)
{
libxml2_loader loader;
- loader.load_string( str, pt, base_path );
+ loader.load_string(str, node, base_path);
}
} // end of namespace mapnik
View
1,035 src/load_map.cpp
@@ -22,6 +22,7 @@
// mapnik
#include <mapnik/load_map.hpp>
+#include <mapnik/xml_tree.hpp>
#include <mapnik/version.hpp>
#include <mapnik/image_reader.hpp>
#include <mapnik/color.hpp>
@@ -33,11 +34,7 @@
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/font_set.hpp>
-
-#include <mapnik/ptree_helpers.hpp>
-#ifdef HAVE_LIBXML2
-#include <mapnik/libxml2_loader.hpp>
-#endif
+#include <mapnik/xml_loader.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/parse_path.hpp>
@@ -51,6 +48,7 @@
#include <mapnik/text_placements/dummy.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/rule.hpp>
+#include <mapnik/config_error.hpp>
// boost
#include <boost/optional.hpp>
@@ -68,13 +66,12 @@
// stl
#include <iostream>
+#include <sstream>
using boost::lexical_cast;
using boost::bad_lexical_cast;
using boost::tokenizer;
-using boost::property_tree::ptree;