Skip to content

Commit

Permalink
Merge branch 'new-xml'
Browse files Browse the repository at this point in the history
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
herm committed Mar 13, 2012
2 parents fb6bf40 + 150de2a commit 2b68cea
Show file tree
Hide file tree
Showing 60 changed files with 1,705 additions and 1,448 deletions.
90 changes: 90 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions include/mapnik/color.hpp
Expand Up @@ -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;
}

}

Expand Down
120 changes: 6 additions & 114 deletions include/mapnik/color_factory.hpp
Expand Up @@ -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
29 changes: 13 additions & 16 deletions include/mapnik/config_error.hpp
Expand Up @@ -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
2 changes: 1 addition & 1 deletion include/mapnik/expression.hpp
Expand Up @@ -26,7 +26,6 @@
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/expression_node.hpp>
#include <mapnik/expression_grammar.hpp>

// stl
#include <string>
Expand All @@ -35,6 +34,7 @@ namespace mapnik
{

typedef boost::shared_ptr<expr_node> expression_ptr;
template <typename Iterator> struct expression_grammar;

class expression_factory
{
Expand Down
3 changes: 2 additions & 1 deletion include/mapnik/formatting/base.hpp
Expand Up @@ -36,6 +36,7 @@ namespace mapnik {

typedef std::set<expression_ptr> expression_set;
class processed_text;
class xml_node;
struct char_properties;

namespace formatting {
Expand All @@ -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;
};
Expand Down
4 changes: 2 additions & 2 deletions include/mapnik/formatting/expression.hpp
Expand Up @@ -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;

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/mapnik/formatting/format.hpp
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions include/mapnik/formatting/registry.hpp
Expand Up @@ -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
Expand All @@ -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_;
};
Expand Down
2 changes: 1 addition & 1 deletion include/mapnik/formatting/text.hpp
Expand Up @@ -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;

Expand Down

0 comments on commit 2b68cea

Please sign in to comment.