From eb8b2552ef451e59492d3df99e7a9d2f07ea34eb Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 16 Jan 2013 12:42:20 +0000 Subject: [PATCH] + update xml_tree to use xml_attrinbute_cast and remove fast_cast --- src/xml_tree.cpp | 119 ++++------------------------------------------- 1 file changed, 10 insertions(+), 109 deletions(-) diff --git a/src/xml_tree.cpp b/src/xml_tree.cpp index fe3d36ade..127264de1 100644 --- a/src/xml_tree.cpp +++ b/src/xml_tree.cpp @@ -22,6 +22,7 @@ //mapnik #include +#include #include #include #include @@ -37,81 +38,9 @@ #include #include -//boost -#include - namespace mapnik { -template -inline boost::optional fast_cast(xml_tree const& tree, std::string const& value) -{ - try - { - return boost::lexical_cast(value); - } - catch (boost::bad_lexical_cast const& ex) - { - return boost::optional(); - } -} - -template <> -inline boost::optional fast_cast(xml_tree const& tree, std::string const& value) -{ - bool result; - if (mapnik::util::string2bool(value, result)) - return boost::optional(result); - return boost::optional(); -} - -template <> -inline boost::optional fast_cast(xml_tree const& tree, std::string const& value) -{ - int result; - if (mapnik::util::string2int(value, result)) - return boost::optional(result); - return boost::optional(); -} - -template <> -inline boost::optional fast_cast(xml_tree const& tree, std::string const& value) -{ - double result; - if (mapnik::util::string2double(value, result)) - return boost::optional(result); - return boost::optional(); -} - -template <> -inline boost::optional fast_cast(xml_tree const& tree, std::string const& value) -{ - float result; - if (mapnik::util::string2float(value, result)) - return boost::optional(result); - return boost::optional(); -} - -template <> -inline boost::optional fast_cast(xml_tree const& tree, std::string const& value) -{ - return value; -} - -template <> -inline boost::optional fast_cast(xml_tree const& tree, std::string const& value) -{ - return parse_color(value, tree.color_grammar); -} - -template <> -inline boost::optional fast_cast(xml_tree const& tree, std::string const& value) -{ - return parse_expression(value, tree.expr_grammar); -} - -/****************************************************************************/ - class boolean; template struct name_trait @@ -167,8 +96,6 @@ struct name_trait< mapnik::enumeration > } }; -/****************************************************************************/ - xml_tree::xml_tree(std::string const& encoding) : node_(*this, ""), file_(), @@ -202,30 +129,21 @@ const xml_node &xml_tree::root() const return node_; } -/****************************************************************************/ xml_attribute::xml_attribute(std::string const& value_) : value(value_), processed(false) { } -/****************************************************************************/ - node_not_found::node_not_found(std::string const& node_name) - : node_name_(node_name) -{ - -} + : node_name_(node_name) {} const char* node_not_found::what() const throw() { return ("Node "+node_name_+ "not found").c_str(); } -node_not_found::~node_not_found() throw() -{ - -} +node_not_found::~node_not_found() throw() {} attribute_not_found::attribute_not_found( @@ -233,48 +151,31 @@ attribute_not_found::attribute_not_found( std::string const& attribute_name) : node_name_(node_name), - attribute_name_(attribute_name) -{ - -} + attribute_name_(attribute_name) {} const char* attribute_not_found::what() const throw() { return ("Attribute '" + attribute_name_ +"' not found in node '"+node_name_+ "'").c_str(); } -attribute_not_found::~attribute_not_found() throw() -{ - -} +attribute_not_found::~attribute_not_found() throw() {} more_than_one_child::more_than_one_child(std::string const& node_name) - : node_name_(node_name) -{ - -} + : node_name_(node_name) {} const char* more_than_one_child::what() const throw() { return ("More than one child node in node '" + node_name_ +"'").c_str(); } -more_than_one_child::~more_than_one_child() throw() -{ - -} - -/****************************************************************************/ +more_than_one_child::~more_than_one_child() throw() {} xml_node::xml_node(xml_tree &tree, std::string const& name, unsigned line, bool is_text) : tree_(tree), name_(name), is_text_(is_text), line_(line), - processed_(false) -{ - -} + processed_(false) {} std::string xml_node::xml_text = ""; @@ -402,7 +303,7 @@ boost::optional xml_node::get_opt_attr(std::string const& name) const std::map::const_iterator itr = attributes_.find(name); if (itr == attributes_.end()) return boost::optional(); itr->second.processed = true; - boost::optional result = fast_cast(tree_, std::string(itr->second.value)); + boost::optional result = xml_attribute_cast(tree_, std::string(itr->second.value)); if (!result) { throw config_error(std::string("Failed to parse attribute '") + @@ -451,7 +352,7 @@ std::string xml_node::get_text() const template T xml_node::get_value() const { - boost::optional result = fast_cast(tree_, get_text()); + boost::optional result = xml_attribute_cast(tree_, get_text()); if (!result) { throw config_error(std::string("Failed to parse value. Expected ")